2019-07-18 20:29:57 +00:00
|
|
|
//! This crate contains implementations of built-in macros and other code generating facilities
|
|
|
|
//! injecting code into the crate before it is lowered to HIR.
|
2015-12-10 14:23:14 +00:00
|
|
|
|
Use `tidy` to sort crate attributes for all compiler crates.
We already do this for a number of crates, e.g. `rustc_middle`,
`rustc_span`, `rustc_metadata`, `rustc_span`, `rustc_errors`.
For the ones we don't, in many cases the attributes are a mess.
- There is no consistency about order of attribute kinds (e.g.
`allow`/`deny`/`feature`).
- Within attribute kind groups (e.g. the `feature` attributes),
sometimes the order is alphabetical, and sometimes there is no
particular order.
- Sometimes the attributes of a particular kind aren't even grouped
all together, e.g. there might be a `feature`, then an `allow`, then
another `feature`.
This commit extends the existing sorting to all compiler crates,
increasing consistency. If any new attribute line is added there is now
only one place it can go -- no need for arbitrary decisions.
Exceptions:
- `rustc_log`, `rustc_next_trait_solver` and `rustc_type_ir_macros`,
because they have no crate attributes.
- `rustc_codegen_gcc`, because it's quasi-external to rustc (e.g. it's
ignored in `rustfmt.toml`).
2024-06-12 03:49:36 +00:00
|
|
|
// tidy-alphabetical-start
|
2023-11-13 12:39:17 +00:00
|
|
|
#![allow(internal_features)]
|
2024-02-05 22:51:39 +00:00
|
|
|
#![allow(rustc::diagnostic_outside_of_impl)]
|
|
|
|
#![allow(rustc::untranslatable_diagnostic)]
|
2024-10-11 17:13:31 +00:00
|
|
|
#![cfg_attr(not(bootstrap), feature(autodiff))]
|
2020-09-23 19:51:56 +00:00
|
|
|
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
|
Use `tidy` to sort crate attributes for all compiler crates.
We already do this for a number of crates, e.g. `rustc_middle`,
`rustc_span`, `rustc_metadata`, `rustc_span`, `rustc_errors`.
For the ones we don't, in many cases the attributes are a mess.
- There is no consistency about order of attribute kinds (e.g.
`allow`/`deny`/`feature`).
- Within attribute kind groups (e.g. the `feature` attributes),
sometimes the order is alphabetical, and sometimes there is no
particular order.
- Sometimes the attributes of a particular kind aren't even grouped
all together, e.g. there might be a `feature`, then an `allow`, then
another `feature`.
This commit extends the existing sorting to all compiler crates,
increasing consistency. If any new attribute line is added there is now
only one place it can go -- no need for arbitrary decisions.
Exceptions:
- `rustc_log`, `rustc_next_trait_solver` and `rustc_type_ir_macros`,
because they have no crate attributes.
- `rustc_codegen_gcc`, because it's quasi-external to rustc (e.g. it's
ignored in `rustfmt.toml`).
2024-06-12 03:49:36 +00:00
|
|
|
#![doc(rust_logo)]
|
2024-01-21 00:26:28 +00:00
|
|
|
#![feature(assert_matches)]
|
2021-01-29 07:31:08 +00:00
|
|
|
#![feature(box_patterns)]
|
2019-06-20 08:52:31 +00:00
|
|
|
#![feature(decl_macro)]
|
2022-06-15 10:37:40 +00:00
|
|
|
#![feature(if_let_guard)]
|
2022-08-20 18:40:08 +00:00
|
|
|
#![feature(let_chains)]
|
2019-08-19 23:26:40 +00:00
|
|
|
#![feature(proc_macro_internals)]
|
|
|
|
#![feature(proc_macro_quote)]
|
Use `tidy` to sort crate attributes for all compiler crates.
We already do this for a number of crates, e.g. `rustc_middle`,
`rustc_span`, `rustc_metadata`, `rustc_span`, `rustc_errors`.
For the ones we don't, in many cases the attributes are a mess.
- There is no consistency about order of attribute kinds (e.g.
`allow`/`deny`/`feature`).
- Within attribute kind groups (e.g. the `feature` attributes),
sometimes the order is alphabetical, and sometimes there is no
particular order.
- Sometimes the attributes of a particular kind aren't even grouped
all together, e.g. there might be a `feature`, then an `allow`, then
another `feature`.
This commit extends the existing sorting to all compiler crates,
increasing consistency. If any new attribute line is added there is now
only one place it can go -- no need for arbitrary decisions.
Exceptions:
- `rustc_log`, `rustc_next_trait_solver` and `rustc_type_ir_macros`,
because they have no crate attributes.
- `rustc_codegen_gcc`, because it's quasi-external to rustc (e.g. it's
ignored in `rustfmt.toml`).
2024-06-12 03:49:36 +00:00
|
|
|
#![feature(rustdoc_internals)]
|
2024-02-25 21:22:11 +00:00
|
|
|
#![feature(try_blocks)]
|
2024-07-06 12:08:04 +00:00
|
|
|
#![warn(unreachable_pub)]
|
Use `tidy` to sort crate attributes for all compiler crates.
We already do this for a number of crates, e.g. `rustc_middle`,
`rustc_span`, `rustc_metadata`, `rustc_span`, `rustc_errors`.
For the ones we don't, in many cases the attributes are a mess.
- There is no consistency about order of attribute kinds (e.g.
`allow`/`deny`/`feature`).
- Within attribute kind groups (e.g. the `feature` attributes),
sometimes the order is alphabetical, and sometimes there is no
particular order.
- Sometimes the attributes of a particular kind aren't even grouped
all together, e.g. there might be a `feature`, then an `allow`, then
another `feature`.
This commit extends the existing sorting to all compiler crates,
increasing consistency. If any new attribute line is added there is now
only one place it can go -- no need for arbitrary decisions.
Exceptions:
- `rustc_log`, `rustc_next_trait_solver` and `rustc_type_ir_macros`,
because they have no crate attributes.
- `rustc_codegen_gcc`, because it's quasi-external to rustc (e.g. it's
ignored in `rustfmt.toml`).
2024-06-12 03:49:36 +00:00
|
|
|
// tidy-alphabetical-end
|
2019-02-04 12:49:54 +00:00
|
|
|
|
2019-08-19 23:26:40 +00:00
|
|
|
extern crate proc_macro;
|
|
|
|
|
2021-01-10 11:36:30 +00:00
|
|
|
use rustc_expand::base::{MacroExpanderFn, ResolverExpand, SyntaxExtensionKind};
|
2019-12-29 14:23:55 +00:00
|
|
|
use rustc_expand::proc_macro::BangProcMacro;
|
2021-01-10 11:36:30 +00:00
|
|
|
use rustc_span::symbol::sym;
|
2019-06-20 08:52:31 +00:00
|
|
|
|
|
|
|
use crate::deriving::*;
|
2024-07-28 22:13:50 +00:00
|
|
|
|
2023-04-24 22:08:35 +00:00
|
|
|
mod alloc_error_handler;
|
2018-05-17 19:17:53 +00:00
|
|
|
mod assert;
|
2024-10-11 17:13:31 +00:00
|
|
|
mod autodiff;
|
2015-12-10 14:23:14 +00:00
|
|
|
mod cfg;
|
2020-03-09 21:56:20 +00:00
|
|
|
mod cfg_accessible;
|
2021-03-06 18:33:02 +00:00
|
|
|
mod cfg_eval;
|
2017-05-07 03:26:45 +00:00
|
|
|
mod compile_error;
|
2015-12-10 14:23:14 +00:00
|
|
|
mod concat;
|
2021-07-29 17:00:55 +00:00
|
|
|
mod concat_bytes;
|
2015-12-10 14:23:14 +00:00
|
|
|
mod concat_idents;
|
2020-11-14 11:47:14 +00:00
|
|
|
mod derive;
|
2019-07-18 18:02:34 +00:00
|
|
|
mod deriving;
|
2022-01-21 22:04:06 +00:00
|
|
|
mod edition_panic;
|
2015-12-10 14:23:14 +00:00
|
|
|
mod env;
|
2023-04-08 19:37:41 +00:00
|
|
|
mod errors;
|
2015-12-10 14:23:14 +00:00
|
|
|
mod format;
|
2016-11-11 04:23:15 +00:00
|
|
|
mod format_foreign;
|
2019-07-18 21:24:58 +00:00
|
|
|
mod global_allocator;
|
2015-12-10 14:23:14 +00:00
|
|
|
mod log_syntax;
|
2023-01-31 11:35:23 +00:00
|
|
|
mod pattern_type;
|
2019-07-17 22:49:10 +00:00
|
|
|
mod source_util;
|
2018-07-21 01:04:02 +00:00
|
|
|
mod test;
|
2018-09-16 09:20:47 +00:00
|
|
|
mod trace_macros;
|
2015-12-10 14:23:14 +00:00
|
|
|
|
2021-12-21 04:05:17 +00:00
|
|
|
pub mod asm;
|
2019-09-06 20:41:54 +00:00
|
|
|
pub mod cmdline_attrs;
|
2019-07-18 20:29:57 +00:00
|
|
|
pub mod proc_macro_harness;
|
2019-07-18 19:29:07 +00:00
|
|
|
pub mod standard_library_imports;
|
2019-07-18 18:29:15 +00:00
|
|
|
pub mod test_harness;
|
2024-04-25 22:44:23 +00:00
|
|
|
pub mod util;
|
2017-01-09 09:31:14 +00:00
|
|
|
|
2023-11-21 22:53:07 +00:00
|
|
|
rustc_fluent_macro::fluent_messages! { "../messages.ftl" }
|
2022-10-13 09:13:02 +00:00
|
|
|
|
2021-01-10 11:36:30 +00:00
|
|
|
pub fn register_builtin_macros(resolver: &mut dyn ResolverExpand) {
|
|
|
|
let mut register = |name, kind| resolver.register_builtin_macro(name, kind);
|
2019-06-20 08:52:31 +00:00
|
|
|
macro register_bang($($name:ident: $f:expr,)*) {
|
|
|
|
$(register(sym::$name, SyntaxExtensionKind::LegacyBang(Box::new($f as MacroExpanderFn)));)*
|
|
|
|
}
|
|
|
|
macro register_attr($($name:ident: $f:expr,)*) {
|
|
|
|
$(register(sym::$name, SyntaxExtensionKind::LegacyAttr(Box::new($f)));)*
|
2019-06-16 15:58:39 +00:00
|
|
|
}
|
2019-06-20 08:52:31 +00:00
|
|
|
macro register_derive($($name:ident: $f:expr,)*) {
|
|
|
|
$(register(sym::$name, SyntaxExtensionKind::LegacyDerive(Box::new(BuiltinDerive($f))));)*
|
2015-12-10 14:23:14 +00:00
|
|
|
}
|
|
|
|
|
2019-06-20 08:52:31 +00:00
|
|
|
register_bang! {
|
2023-10-13 13:22:33 +00:00
|
|
|
// tidy-alphabetical-start
|
2020-02-12 15:47:43 +00:00
|
|
|
asm: asm::expand_asm,
|
2019-06-20 08:52:31 +00:00
|
|
|
assert: assert::expand_assert,
|
2016-09-07 23:21:59 +00:00
|
|
|
cfg: cfg::expand_cfg,
|
2019-06-20 08:52:31 +00:00
|
|
|
column: source_util::expand_column,
|
|
|
|
compile_error: compile_error::expand_compile_error,
|
2023-10-13 13:22:33 +00:00
|
|
|
concat: concat::expand_concat,
|
2021-07-29 17:00:55 +00:00
|
|
|
concat_bytes: concat_bytes::expand_concat_bytes,
|
2019-09-03 14:43:25 +00:00
|
|
|
concat_idents: concat_idents::expand_concat_idents,
|
2023-10-13 13:22:33 +00:00
|
|
|
const_format_args: format::expand_format_args,
|
|
|
|
core_panic: edition_panic::expand_panic,
|
2016-09-07 23:21:59 +00:00
|
|
|
env: env::expand_env,
|
2019-06-20 08:52:31 +00:00
|
|
|
file: source_util::expand_file,
|
|
|
|
format_args: format::expand_format_args,
|
2023-10-13 13:22:33 +00:00
|
|
|
format_args_nl: format::expand_format_args_nl,
|
2021-04-11 19:51:28 +00:00
|
|
|
global_asm: asm::expand_global_asm,
|
2023-10-13 13:22:33 +00:00
|
|
|
include: source_util::expand_include,
|
2019-06-20 08:52:31 +00:00
|
|
|
include_bytes: source_util::expand_include_bytes,
|
|
|
|
include_str: source_util::expand_include_str,
|
|
|
|
line: source_util::expand_line,
|
2019-09-03 14:43:25 +00:00
|
|
|
log_syntax: log_syntax::expand_log_syntax,
|
2019-06-20 08:52:31 +00:00
|
|
|
module_path: source_util::expand_mod,
|
2024-09-09 10:47:40 +00:00
|
|
|
naked_asm: asm::expand_naked_asm,
|
2019-06-20 08:52:31 +00:00
|
|
|
option_env: env::expand_option_env,
|
2023-01-31 11:35:23 +00:00
|
|
|
pattern_type: pattern_type::expand,
|
2022-01-21 22:04:06 +00:00
|
|
|
std_panic: edition_panic::expand_panic,
|
2019-06-20 08:52:31 +00:00
|
|
|
stringify: source_util::expand_stringify,
|
2019-06-22 13:18:05 +00:00
|
|
|
trace_macros: trace_macros::expand_trace_macros,
|
2023-10-13 13:22:33 +00:00
|
|
|
unreachable: edition_panic::expand_unreachable,
|
|
|
|
// tidy-alphabetical-end
|
2019-06-16 15:58:39 +00:00
|
|
|
}
|
2018-07-21 01:04:02 +00:00
|
|
|
|
2019-06-20 08:52:31 +00:00
|
|
|
register_attr! {
|
2023-04-24 22:08:35 +00:00
|
|
|
alloc_error_handler: alloc_error_handler::expand,
|
2024-10-11 17:13:31 +00:00
|
|
|
autodiff: autodiff::expand,
|
2019-06-20 08:52:31 +00:00
|
|
|
bench: test::expand_bench,
|
2020-03-09 21:56:20 +00:00
|
|
|
cfg_accessible: cfg_accessible::Expander,
|
2021-03-06 18:33:02 +00:00
|
|
|
cfg_eval: cfg_eval::expand,
|
2024-04-25 05:16:10 +00:00
|
|
|
derive: derive::Expander { is_const: false },
|
|
|
|
derive_const: derive::Expander { is_const: true },
|
2019-06-20 08:52:31 +00:00
|
|
|
global_allocator: global_allocator::expand,
|
|
|
|
test: test::expand_test,
|
2019-07-18 18:29:15 +00:00
|
|
|
test_case: test::expand_test_case,
|
2019-06-20 08:52:31 +00:00
|
|
|
}
|
2016-09-07 23:21:59 +00:00
|
|
|
|
2019-06-20 08:52:31 +00:00
|
|
|
register_derive! {
|
|
|
|
Clone: clone::expand_deriving_clone,
|
|
|
|
Copy: bounds::expand_deriving_copy,
|
2023-05-16 17:40:02 +00:00
|
|
|
ConstParamTy: bounds::expand_deriving_const_param_ty,
|
2024-07-14 12:38:51 +00:00
|
|
|
UnsizedConstParamTy: bounds::expand_deriving_unsized_const_param_ty,
|
2019-06-20 08:52:31 +00:00
|
|
|
Debug: debug::expand_deriving_debug,
|
|
|
|
Default: default::expand_deriving_default,
|
|
|
|
Eq: eq::expand_deriving_eq,
|
|
|
|
Hash: hash::expand_deriving_hash,
|
|
|
|
Ord: ord::expand_deriving_ord,
|
|
|
|
PartialEq: partial_eq::expand_deriving_partial_eq,
|
|
|
|
PartialOrd: partial_ord::expand_deriving_partial_ord,
|
|
|
|
RustcDecodable: decodable::expand_deriving_rustc_decodable,
|
|
|
|
RustcEncodable: encodable::expand_deriving_rustc_encodable,
|
2024-10-05 09:44:53 +00:00
|
|
|
CoercePointee: coerce_pointee::expand_deriving_coerce_pointee,
|
2016-09-28 22:48:55 +00:00
|
|
|
}
|
2019-08-19 23:26:40 +00:00
|
|
|
|
|
|
|
let client = proc_macro::bridge::client::Client::expand1(proc_macro::quote);
|
2021-07-10 20:15:30 +00:00
|
|
|
register(sym::quote, SyntaxExtensionKind::Bang(Box::new(BangProcMacro { client })));
|
2015-12-10 14:23:14 +00:00
|
|
|
}
|