2022-02-09 22:24:51 +00:00
|
|
|
#![feature(allow_internal_unstable)]
|
2022-11-13 12:10:36 +00:00
|
|
|
#![feature(if_let_guard)]
|
2023-01-08 23:00:41 +00:00
|
|
|
#![feature(let_chains)]
|
2022-05-07 05:02:11 +00:00
|
|
|
#![feature(never_type)]
|
2022-04-26 10:59:45 +00:00
|
|
|
#![feature(proc_macro_diagnostic)]
|
2022-05-23 17:24:55 +00:00
|
|
|
#![feature(proc_macro_span)]
|
2023-10-25 18:20:07 +00:00
|
|
|
#![feature(proc_macro_tracked_env)]
|
2019-08-11 16:55:14 +00:00
|
|
|
#![allow(rustc::default_hash_types)]
|
2022-08-18 18:27:29 +00:00
|
|
|
#![deny(rustc::untranslatable_diagnostic)]
|
|
|
|
#![deny(rustc::diagnostic_outside_of_impl)]
|
2023-08-22 11:06:38 +00:00
|
|
|
#![allow(internal_features)]
|
2019-04-05 11:11:44 +00:00
|
|
|
#![recursion_limit = "128"]
|
|
|
|
|
2019-03-05 18:27:50 +00:00
|
|
|
use synstructure::decl_derive;
|
2018-12-03 00:14:35 +00:00
|
|
|
|
2018-12-03 00:14:35 +00:00
|
|
|
use proc_macro::TokenStream;
|
|
|
|
|
2023-10-27 00:18:21 +00:00
|
|
|
mod current_version;
|
2022-04-27 01:57:44 +00:00
|
|
|
mod diagnostics;
|
2018-12-03 00:14:35 +00:00
|
|
|
mod hash_stable;
|
2019-11-14 22:31:49 +00:00
|
|
|
mod lift;
|
2018-12-03 00:14:35 +00:00
|
|
|
mod query;
|
2020-06-11 14:49:57 +00:00
|
|
|
mod serialize;
|
2019-04-03 00:43:49 +00:00
|
|
|
mod symbols;
|
2019-11-13 19:47:41 +00:00
|
|
|
mod type_foldable;
|
2022-06-17 09:53:29 +00:00
|
|
|
mod type_visitable;
|
2018-12-03 00:14:35 +00:00
|
|
|
|
2023-11-08 06:05:44 +00:00
|
|
|
// Reads the rust version (e.g. "1.75.0") from the CFG_RELEASE env var and
|
|
|
|
// produces a `RustcVersion` literal containing that version (e.g.
|
|
|
|
// `RustcVersion { major: 1, minor: 75, patch: 0 }`).
|
2023-10-27 00:18:21 +00:00
|
|
|
#[proc_macro]
|
|
|
|
pub fn current_rustc_version(input: TokenStream) -> TokenStream {
|
|
|
|
current_version::current_version(input)
|
|
|
|
}
|
|
|
|
|
2018-12-03 00:14:35 +00:00
|
|
|
#[proc_macro]
|
|
|
|
pub fn rustc_queries(input: TokenStream) -> TokenStream {
|
|
|
|
query::rustc_queries(input)
|
|
|
|
}
|
2018-12-03 00:14:35 +00:00
|
|
|
|
2019-04-03 00:43:49 +00:00
|
|
|
#[proc_macro]
|
|
|
|
pub fn symbols(input: TokenStream) -> TokenStream {
|
Improve error handling in `symbols` proc-macro
This improves how the `symbols` proc-macro handles errors.
If it finds an error in its input, the macro does not panic.
Instead, it still produces an output token stream. That token
stream will contain `compile_error!(...)` macro invocations.
This will still cause compilation to fail (which is what we want),
but it will prevent meaningless errors caused by the output not
containing symbols that the macro normally generates.
This solves a small (but annoying) problem. When you're editing
rustc_span/src/symbol.rs, and you get something wrong (dup
symbol name, misordered symbol), you want to get only the errors
that are relevant, not a burst of errors that are irrelevant.
This change also uses the correct Span when reporting errors,
so you get errors that point to the correct place in
rustc_span/src/symbol.rs where something is wrong.
This also adds several unit tests which test the `symbols` proc-macro.
This commit also makes it easy to run the `symbols` proc-macro
as an ordinary Cargo test. Just run `cargo test`. This makes it
easier to do development on the macro itself, such as running it
under a debugger.
This commit also uses the `Punctuated` type in `syn` for parsing
comma-separated lists, rather than doing it manually.
The output of the macro is not changed at all by this commit,
so rustc should be completely unchanged. This just improves
quality of life during development.
2020-12-11 19:32:48 +00:00
|
|
|
symbols::symbols(input.into()).into()
|
2022-02-09 22:24:51 +00:00
|
|
|
}
|
|
|
|
|
2018-12-16 03:44:12 +00:00
|
|
|
decl_derive!([HashStable, attributes(stable_hasher)] => hash_stable::hash_stable_derive);
|
2019-11-09 19:34:55 +00:00
|
|
|
decl_derive!(
|
|
|
|
[HashStable_Generic, attributes(stable_hasher)] =>
|
|
|
|
hash_stable::hash_stable_generic_derive
|
|
|
|
);
|
|
|
|
|
2020-06-11 14:49:57 +00:00
|
|
|
decl_derive!([Decodable] => serialize::decodable_derive);
|
|
|
|
decl_derive!([Encodable] => serialize::encodable_derive);
|
|
|
|
decl_derive!([TyDecodable] => serialize::type_decodable_derive);
|
|
|
|
decl_derive!([TyEncodable] => serialize::type_encodable_derive);
|
|
|
|
decl_derive!([MetadataDecodable] => serialize::meta_decodable_derive);
|
|
|
|
decl_derive!([MetadataEncodable] => serialize::meta_encodable_derive);
|
2023-02-14 00:01:37 +00:00
|
|
|
decl_derive!(
|
|
|
|
[TypeFoldable, attributes(type_foldable)] =>
|
|
|
|
/// Derives `TypeFoldable` for the annotated `struct` or `enum` (`union` is not supported).
|
|
|
|
///
|
|
|
|
/// The fold will produce a value of the same struct or enum variant as the input, with
|
|
|
|
/// each field respectively folded using the `TypeFoldable` implementation for its type.
|
|
|
|
/// However, if a field of a struct or an enum variant is annotated with
|
|
|
|
/// `#[type_foldable(identity)]` then that field will retain its incumbent value (and its
|
|
|
|
/// type is not required to implement `TypeFoldable`).
|
|
|
|
type_foldable::type_foldable_derive
|
|
|
|
);
|
|
|
|
decl_derive!(
|
|
|
|
[TypeVisitable, attributes(type_visitable)] =>
|
|
|
|
/// Derives `TypeVisitable` for the annotated `struct` or `enum` (`union` is not supported).
|
|
|
|
///
|
|
|
|
/// Each field of the struct or enum variant will be visited in definition order, using the
|
|
|
|
/// `TypeVisitable` implementation for its type. However, if a field of a struct or an enum
|
|
|
|
/// variant is annotated with `#[type_visitable(ignore)]` then that field will not be
|
|
|
|
/// visited (and its type is not required to implement `TypeVisitable`).
|
|
|
|
type_visitable::type_visitable_derive
|
|
|
|
);
|
2019-11-14 22:31:49 +00:00
|
|
|
decl_derive!([Lift, attributes(lift)] => lift::lift_derive);
|
2020-08-27 10:00:21 +00:00
|
|
|
decl_derive!(
|
2022-09-18 15:46:56 +00:00
|
|
|
[Diagnostic, attributes(
|
2022-03-31 07:35:17 +00:00
|
|
|
// struct attributes
|
2022-08-19 13:02:10 +00:00
|
|
|
diag,
|
2022-03-31 11:10:00 +00:00
|
|
|
help,
|
2022-07-11 17:46:24 +00:00
|
|
|
note,
|
2022-08-24 15:57:10 +00:00
|
|
|
warning,
|
2022-03-31 07:35:17 +00:00
|
|
|
// field attributes
|
2022-03-31 08:02:31 +00:00
|
|
|
skip_arg,
|
2022-03-31 07:50:45 +00:00
|
|
|
primary_span,
|
2020-08-27 10:00:21 +00:00
|
|
|
label,
|
2022-04-27 04:59:48 +00:00
|
|
|
subdiagnostic,
|
2020-08-27 10:00:21 +00:00
|
|
|
suggestion,
|
|
|
|
suggestion_short,
|
|
|
|
suggestion_hidden,
|
2022-04-27 01:57:44 +00:00
|
|
|
suggestion_verbose)] => diagnostics::session_diagnostic_derive
|
2020-08-27 10:00:21 +00:00
|
|
|
);
|
2022-06-30 07:57:45 +00:00
|
|
|
decl_derive!(
|
|
|
|
[LintDiagnostic, attributes(
|
|
|
|
// struct attributes
|
2022-08-19 13:02:10 +00:00
|
|
|
diag,
|
2022-06-30 07:57:45 +00:00
|
|
|
help,
|
2022-07-11 17:46:24 +00:00
|
|
|
note,
|
2022-08-24 15:57:10 +00:00
|
|
|
warning,
|
2022-06-30 07:57:45 +00:00
|
|
|
// field attributes
|
|
|
|
skip_arg,
|
|
|
|
primary_span,
|
|
|
|
label,
|
|
|
|
subdiagnostic,
|
|
|
|
suggestion,
|
|
|
|
suggestion_short,
|
|
|
|
suggestion_hidden,
|
|
|
|
suggestion_verbose)] => diagnostics::lint_diagnostic_derive
|
|
|
|
);
|
2022-04-26 10:59:45 +00:00
|
|
|
decl_derive!(
|
2022-09-18 15:47:31 +00:00
|
|
|
[Subdiagnostic, attributes(
|
2022-04-26 10:59:45 +00:00
|
|
|
// struct/variant attributes
|
|
|
|
label,
|
|
|
|
help,
|
|
|
|
note,
|
2022-08-24 15:57:10 +00:00
|
|
|
warning,
|
2022-04-26 10:59:45 +00:00
|
|
|
suggestion,
|
|
|
|
suggestion_short,
|
|
|
|
suggestion_hidden,
|
|
|
|
suggestion_verbose,
|
2022-08-23 05:54:06 +00:00
|
|
|
multipart_suggestion,
|
|
|
|
multipart_suggestion_short,
|
|
|
|
multipart_suggestion_hidden,
|
|
|
|
multipart_suggestion_verbose,
|
2022-04-26 10:59:45 +00:00
|
|
|
// field attributes
|
|
|
|
skip_arg,
|
|
|
|
primary_span,
|
2022-08-23 05:54:06 +00:00
|
|
|
suggestion_part,
|
2022-04-27 01:57:44 +00:00
|
|
|
applicability)] => diagnostics::session_subdiagnostic_derive
|
2022-04-26 10:59:45 +00:00
|
|
|
);
|