1
- use rustc_ast:: { self as ast, NodeId } ;
1
+ use rustc_ast as ast;
2
2
use rustc_feature:: is_builtin_attr_name;
3
3
use rustc_hir:: def:: { DefKind , Namespace , NonMacroAttrKind , PartialRes , PerNS } ;
4
4
use rustc_hir:: PrimTy ;
5
5
use rustc_middle:: bug;
6
6
use rustc_middle:: ty;
7
- use rustc_session:: lint:: builtin:: PROC_MACRO_DERIVE_RESOLUTION_FALLBACK ;
8
- use rustc_session:: lint:: BuiltinLintDiagnostics ;
9
7
use rustc_span:: def_id:: LocalDefId ;
10
8
use rustc_span:: edition:: Edition ;
11
9
use rustc_span:: hygiene:: { ExpnId , ExpnKind , LocalExpnId , MacroKind , SyntaxContext } ;
@@ -101,7 +99,7 @@ impl<'a> Resolver<'a> {
101
99
} ;
102
100
let mut scope = match ns {
103
101
_ if is_absolute_path => Scope :: CrateRoot ,
104
- TypeNS | ValueNS => Scope :: Module ( module, None ) ,
102
+ TypeNS | ValueNS => Scope :: Module ( module) ,
105
103
MacroNS => Scope :: DeriveHelpers ( parent_scope. expansion ) ,
106
104
} ;
107
105
let mut ctxt = ctxt. normalize_to_macros_2_0 ( ) ;
@@ -165,7 +163,7 @@ impl<'a> Resolver<'a> {
165
163
MacroRulesScope :: Invocation ( invoc_id) => {
166
164
Scope :: MacroRules ( self . invocation_parent_scopes [ & invoc_id] . macro_rules )
167
165
}
168
- MacroRulesScope :: Empty => Scope :: Module ( module, None ) ,
166
+ MacroRulesScope :: Empty => Scope :: Module ( module) ,
169
167
} ,
170
168
Scope :: CrateRoot => match ns {
171
169
TypeNS => {
@@ -174,16 +172,10 @@ impl<'a> Resolver<'a> {
174
172
}
175
173
ValueNS | MacroNS => break ,
176
174
} ,
177
- Scope :: Module ( module, prev_lint_id ) => {
175
+ Scope :: Module ( module) => {
178
176
use_prelude = !module. no_implicit_prelude ;
179
- let derive_fallback_lint_id = match scope_set {
180
- ScopeSet :: Late ( .., lint_id) => lint_id,
181
- _ => None ,
182
- } ;
183
- match self . hygienic_lexical_parent ( module, & mut ctxt, derive_fallback_lint_id) {
184
- Some ( ( parent_module, lint_id) ) => {
185
- Scope :: Module ( parent_module, lint_id. or ( prev_lint_id) )
186
- }
177
+ match self . hygienic_lexical_parent ( module, & mut ctxt) {
178
+ Some ( parent_module) => Scope :: Module ( parent_module) ,
187
179
None => {
188
180
ctxt. adjust ( ExpnId :: root ( ) ) ;
189
181
match ns {
@@ -215,45 +207,13 @@ impl<'a> Resolver<'a> {
215
207
& mut self ,
216
208
module : Module < ' a > ,
217
209
ctxt : & mut SyntaxContext ,
218
- derive_fallback_lint_id : Option < NodeId > ,
219
- ) -> Option < ( Module < ' a > , Option < NodeId > ) > {
210
+ ) -> Option < Module < ' a > > {
220
211
if !module. expansion . outer_expn_is_descendant_of ( * ctxt) {
221
- return Some ( ( self . expn_def_scope ( ctxt. remove_mark ( ) ) , None ) ) ;
212
+ return Some ( self . expn_def_scope ( ctxt. remove_mark ( ) ) ) ;
222
213
}
223
214
224
215
if let ModuleKind :: Block = module. kind {
225
- return Some ( ( module. parent . unwrap ( ) . nearest_item_scope ( ) , None ) ) ;
226
- }
227
-
228
- // We need to support the next case under a deprecation warning
229
- // ```
230
- // struct MyStruct;
231
- // ---- begin: this comes from a proc macro derive
232
- // mod implementation_details {
233
- // // Note that `MyStruct` is not in scope here.
234
- // impl SomeTrait for MyStruct { ... }
235
- // }
236
- // ---- end
237
- // ```
238
- // So we have to fall back to the module's parent during lexical resolution in this case.
239
- if derive_fallback_lint_id. is_some ( ) {
240
- if let Some ( parent) = module. parent {
241
- // Inner module is inside the macro, parent module is outside of the macro.
242
- if module. expansion != parent. expansion
243
- && module. expansion . is_descendant_of ( parent. expansion )
244
- {
245
- // The macro is a proc macro derive
246
- if let Some ( def_id) = module. expansion . expn_data ( ) . macro_def_id {
247
- let ext = self . get_macro_by_def_id ( def_id) . ext ;
248
- if ext. builtin_name . is_none ( )
249
- && ext. macro_kind ( ) == MacroKind :: Derive
250
- && parent. expansion . outer_expn_is_descendant_of ( * ctxt)
251
- {
252
- return Some ( ( parent, derive_fallback_lint_id) ) ;
253
- }
254
- }
255
- }
256
- }
216
+ return Some ( module. parent . unwrap ( ) . nearest_item_scope ( ) ) ;
257
217
}
258
218
259
219
None
@@ -510,7 +470,7 @@ impl<'a> Resolver<'a> {
510
470
Err ( ( Determinacy :: Determined , _) ) => Err ( Determinacy :: Determined ) ,
511
471
}
512
472
}
513
- Scope :: Module ( module, derive_fallback_lint_id ) => {
473
+ Scope :: Module ( module) => {
514
474
let adjusted_parent_scope = & ParentScope { module, ..* parent_scope } ;
515
475
let binding = this. resolve_ident_in_module_unadjusted_ext (
516
476
ModuleOrUniformRoot :: Module ( module) ,
@@ -523,21 +483,6 @@ impl<'a> Resolver<'a> {
523
483
) ;
524
484
match binding {
525
485
Ok ( binding) => {
526
- if let Some ( lint_id) = derive_fallback_lint_id {
527
- this. lint_buffer . buffer_lint_with_diagnostic (
528
- PROC_MACRO_DERIVE_RESOLUTION_FALLBACK ,
529
- lint_id,
530
- orig_ident. span ,
531
- & format ! (
532
- "cannot find {} `{}` in this scope" ,
533
- ns. descr( ) ,
534
- ident
535
- ) ,
536
- BuiltinLintDiagnostics :: ProcMacroDeriveResolutionFallback (
537
- orig_ident. span ,
538
- ) ,
539
- ) ;
540
- }
541
486
let misc_flags = if ptr:: eq ( module, this. graph_root ) {
542
487
Flags :: MISC_SUGGEST_CRATE
543
488
} else if module. is_normal ( ) {
0 commit comments