Skip to content

Commit c114443

Browse files
committed
Make synstructure underscore_const(true) the default
since otherwise it will trigger the non_local_definitions lint
1 parent bccb9bb commit c114443

File tree

6 files changed

+24
-4
lines changed

6 files changed

+24
-4
lines changed

compiler/rustc_macros/src/diagnostics/mod.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ use synstructure::Structure;
5555
///
5656
/// See rustc dev guide for more examples on using the `#[derive(Diagnostic)]`:
5757
/// <https://rustc-dev-guide.rust-lang.org/diagnostics/diagnostic-structs.html>
58-
pub fn session_diagnostic_derive(s: Structure<'_>) -> TokenStream {
58+
pub fn session_diagnostic_derive(mut s: Structure<'_>) -> TokenStream {
59+
s.underscore_const(true);
5960
DiagnosticDerive::new(s).into_tokens()
6061
}
6162

@@ -101,7 +102,8 @@ pub fn session_diagnostic_derive(s: Structure<'_>) -> TokenStream {
101102
///
102103
/// See rustc dev guide for more examples on using the `#[derive(LintDiagnostic)]`:
103104
/// <https://rustc-dev-guide.rust-lang.org/diagnostics/diagnostic-structs.html#reference>
104-
pub fn lint_diagnostic_derive(s: Structure<'_>) -> TokenStream {
105+
pub fn lint_diagnostic_derive(mut s: Structure<'_>) -> TokenStream {
106+
s.underscore_const(true);
105107
LintDiagnosticDerive::new(s).into_tokens()
106108
}
107109

@@ -151,6 +153,7 @@ pub fn lint_diagnostic_derive(s: Structure<'_>) -> TokenStream {
151153
///
152154
/// diag.subdiagnostic(RawIdentifierSuggestion { span, applicability, ident });
153155
/// ```
154-
pub fn session_subdiagnostic_derive(s: Structure<'_>) -> TokenStream {
156+
pub fn session_subdiagnostic_derive(mut s: Structure<'_>) -> TokenStream {
157+
s.underscore_const(true);
155158
SubdiagnosticDeriveBuilder::new().into_tokens(s)
156159
}

compiler/rustc_macros/src/hash_stable.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ fn hash_stable_derive_with_mode(
7474
HashStableMode::Generic | HashStableMode::NoContext => parse_quote!(__CTX),
7575
};
7676

77+
s.underscore_const(true);
78+
7779
// no_context impl is able to derive by-field, which is closer to a perfect derive.
7880
s.add_bounds(match mode {
7981
HashStableMode::Normal | HashStableMode::Generic => synstructure::AddBounds::Generics,

compiler/rustc_macros/src/lift.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use syn::parse_quote;
44
pub fn lift_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::TokenStream {
55
s.add_bounds(synstructure::AddBounds::Generics);
66
s.bind_with(|_| synstructure::BindStyle::Move);
7+
s.underscore_const(true);
78

89
let tcx: syn::Lifetime = parse_quote!('tcx);
910
let newtcx: syn::GenericParam = parse_quote!('__lifted);

compiler/rustc_macros/src/serialize.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ pub fn type_decodable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2:
1515

1616
s.add_impl_generic(parse_quote! {#decoder_ty: ::rustc_type_ir::codec::TyDecoder #bound });
1717
s.add_bounds(synstructure::AddBounds::Fields);
18+
s.underscore_const(true);
1819

1920
decodable_body(s, decoder_ty)
2021
}
@@ -26,6 +27,7 @@ pub fn meta_decodable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2:
2627
s.add_impl_generic(parse_quote! { '__a });
2728
let decoder_ty = quote! { DecodeContext<'__a, 'tcx> };
2829
s.add_bounds(synstructure::AddBounds::Generics);
30+
s.underscore_const(true);
2931

3032
decodable_body(s, decoder_ty)
3133
}
@@ -34,6 +36,7 @@ pub fn decodable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::Toke
3436
let decoder_ty = quote! { __D };
3537
s.add_impl_generic(parse_quote! {#decoder_ty: ::rustc_span::SpanDecoder});
3638
s.add_bounds(synstructure::AddBounds::Generics);
39+
s.underscore_const(true);
3740

3841
decodable_body(s, decoder_ty)
3942
}
@@ -42,12 +45,13 @@ pub fn decodable_generic_derive(mut s: synstructure::Structure<'_>) -> proc_macr
4245
let decoder_ty = quote! { __D };
4346
s.add_impl_generic(parse_quote! {#decoder_ty: ::rustc_serialize::Decoder});
4447
s.add_bounds(synstructure::AddBounds::Generics);
48+
s.underscore_const(true);
4549

4650
decodable_body(s, decoder_ty)
4751
}
4852

4953
fn decodable_body(
50-
s: synstructure::Structure<'_>,
54+
mut s: synstructure::Structure<'_>,
5155
decoder_ty: TokenStream,
5256
) -> proc_macro2::TokenStream {
5357
if let syn::Data::Union(_) = s.ast().data {
@@ -93,6 +97,7 @@ fn decodable_body(
9397
}
9498
}
9599
};
100+
s.underscore_const(true);
96101

97102
s.bound_impl(
98103
quote!(::rustc_serialize::Decodable<#decoder_ty>),
@@ -130,6 +135,7 @@ pub fn type_encodable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2:
130135
let encoder_ty = quote! { __E };
131136
s.add_impl_generic(parse_quote! {#encoder_ty: ::rustc_type_ir::codec::TyEncoder #bound });
132137
s.add_bounds(synstructure::AddBounds::Fields);
138+
s.underscore_const(true);
133139

134140
encodable_body(s, encoder_ty, false)
135141
}
@@ -141,6 +147,7 @@ pub fn meta_encodable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2:
141147
s.add_impl_generic(parse_quote! { '__a });
142148
let encoder_ty = quote! { EncodeContext<'__a, 'tcx> };
143149
s.add_bounds(synstructure::AddBounds::Generics);
150+
s.underscore_const(true);
144151

145152
encodable_body(s, encoder_ty, true)
146153
}
@@ -149,6 +156,7 @@ pub fn encodable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::Toke
149156
let encoder_ty = quote! { __E };
150157
s.add_impl_generic(parse_quote! { #encoder_ty: ::rustc_span::SpanEncoder});
151158
s.add_bounds(synstructure::AddBounds::Generics);
159+
s.underscore_const(true);
152160

153161
encodable_body(s, encoder_ty, false)
154162
}
@@ -157,6 +165,7 @@ pub fn encodable_generic_derive(mut s: synstructure::Structure<'_>) -> proc_macr
157165
let encoder_ty = quote! { __E };
158166
s.add_impl_generic(parse_quote! { #encoder_ty: ::rustc_serialize::Encoder});
159167
s.add_bounds(synstructure::AddBounds::Generics);
168+
s.underscore_const(true);
160169

161170
encodable_body(s, encoder_ty, false)
162171
}
@@ -170,6 +179,7 @@ fn encodable_body(
170179
panic!("cannot derive on union")
171180
}
172181

182+
s.underscore_const(true);
173183
s.bind_with(|binding| {
174184
// Handle the lack of a blanket reference impl.
175185
if let syn::Type::Reference(_) = binding.ast().ty {

compiler/rustc_macros/src/type_foldable.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ pub fn type_foldable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::
66
panic!("cannot derive on union")
77
}
88

9+
s.underscore_const(true);
10+
911
if !s.ast().generics.lifetimes().any(|lt| lt.lifetime.ident == "tcx") {
1012
s.add_impl_generic(parse_quote! { 'tcx });
1113
}

compiler/rustc_macros/src/type_visitable.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ pub fn type_visitable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2:
66
panic!("cannot derive on union")
77
}
88

9+
s.underscore_const(true);
10+
911
// ignore fields with #[type_visitable(ignore)]
1012
s.filter(|bi| {
1113
let mut ignored = false;

0 commit comments

Comments
 (0)