@@ -417,19 +417,17 @@ impl<'a> Resolver<'a> {
417
417
}
418
418
419
419
assert ! ( force || !record_used) ; // `record_used` implies `force`
420
- let ident = orig_ident. modern ( ) ;
421
420
422
421
// Make sure `self`, `super` etc produce an error when passed to here.
423
- if ident . is_path_segment_keyword ( ) {
422
+ if orig_ident . is_path_segment_keyword ( ) {
424
423
return Err ( Determinacy :: Determined ) ;
425
424
}
426
425
427
- let rust_2015 = orig_ident. span . rust_2015 ( ) ;
428
- let ( ns, macro_kind, is_import, is_absolute_path) = match scope_set {
429
- ScopeSet :: Import ( ns) => ( ns, None , true , false ) ,
430
- ScopeSet :: AbsolutePath ( ns) => ( ns, None , false , true ) ,
431
- ScopeSet :: Macro ( macro_kind) => ( MacroNS , Some ( macro_kind) , false , false ) ,
432
- ScopeSet :: Module => ( TypeNS , None , false , false ) ,
426
+ let ( ns, macro_kind, is_import) = match scope_set {
427
+ ScopeSet :: Import ( ns) => ( ns, None , true ) ,
428
+ ScopeSet :: AbsolutePath ( ns) => ( ns, None , false ) ,
429
+ ScopeSet :: Macro ( macro_kind) => ( MacroNS , Some ( macro_kind) , false ) ,
430
+ ScopeSet :: Module => ( TypeNS , None , false ) ,
433
431
} ;
434
432
435
433
// This is *the* result, resolution from the scope closest to the resolved identifier.
@@ -444,11 +442,11 @@ impl<'a> Resolver<'a> {
444
442
// So we have to save the innermost solution and continue searching in outer scopes
445
443
// to detect potential ambiguities.
446
444
let mut innermost_result: Option < ( & NameBinding < ' _ > , Flags ) > = None ;
447
- let mut use_prelude = !parent_scope. module . no_implicit_prelude ;
448
445
let mut determinacy = Determinacy :: Determined ;
449
446
450
447
// Go through all the scopes and try to resolve the name.
451
- let break_result = self . visit_scopes ( scope_set, parent_scope, ident, |this, scope, ident| {
448
+ let break_result =
449
+ self . visit_scopes ( scope_set, parent_scope, orig_ident, |this, scope, ident| {
452
450
let result = match scope {
453
451
Scope :: DeriveHelpers => {
454
452
let mut result = Err ( Determinacy :: Determined ) ;
@@ -478,11 +476,11 @@ impl<'a> Resolver<'a> {
478
476
_ => Err ( Determinacy :: Determined ) ,
479
477
}
480
478
Scope :: CrateRoot => {
481
- let root_ident = Ident :: new ( kw:: PathRoot , orig_ident . span ) ;
479
+ let root_ident = Ident :: new ( kw:: PathRoot , ident . span ) ;
482
480
let root_module = this. resolve_crate_root ( root_ident) ;
483
481
let binding = this. resolve_ident_in_module_ext (
484
482
ModuleOrUniformRoot :: Module ( root_module) ,
485
- orig_ident ,
483
+ ident ,
486
484
ns,
487
485
None ,
488
486
record_used,
@@ -498,7 +496,6 @@ impl<'a> Resolver<'a> {
498
496
}
499
497
}
500
498
Scope :: Module ( module) => {
501
- use_prelude = !module. no_implicit_prelude ;
502
499
let orig_current_module = mem:: replace ( & mut this. current_module , module) ;
503
500
let binding = this. resolve_ident_in_module_unadjusted_ext (
504
501
ModuleOrUniformRoot :: Module ( module) ,
@@ -528,94 +525,69 @@ impl<'a> Resolver<'a> {
528
525
Err ( ( Determinacy :: Determined , _) ) => Err ( Determinacy :: Determined ) ,
529
526
}
530
527
}
531
- Scope :: MacroUsePrelude => {
532
- if use_prelude || rust_2015 {
533
- match this. macro_use_prelude . get ( & ident. name ) . cloned ( ) {
534
- Some ( binding) =>
535
- Ok ( ( binding, Flags :: PRELUDE | Flags :: MISC_FROM_PRELUDE ) ) ,
536
- None => Err ( Determinacy :: determined (
537
- this. graph_root . unresolved_invocations . borrow ( ) . is_empty ( )
538
- ) )
539
- }
540
- } else {
541
- Err ( Determinacy :: Determined )
542
- }
528
+ Scope :: MacroUsePrelude => match this. macro_use_prelude . get ( & ident. name ) . cloned ( ) {
529
+ Some ( binding) => Ok ( ( binding, Flags :: PRELUDE | Flags :: MISC_FROM_PRELUDE ) ) ,
530
+ None => Err ( Determinacy :: determined (
531
+ this. graph_root . unresolved_invocations . borrow ( ) . is_empty ( )
532
+ ) )
543
533
}
544
- Scope :: BuiltinMacros => {
545
- match this. builtin_macros . get ( & ident. name ) . cloned ( ) {
546
- Some ( binding) => Ok ( ( binding, Flags :: PRELUDE ) ) ,
547
- None => Err ( Determinacy :: Determined ) ,
548
- }
534
+ Scope :: BuiltinMacros => match this. builtin_macros . get ( & ident. name ) . cloned ( ) {
535
+ Some ( binding) => Ok ( ( binding, Flags :: PRELUDE ) ) ,
536
+ None => Err ( Determinacy :: Determined ) ,
549
537
}
550
- Scope :: BuiltinAttrs => {
551
- if is_builtin_attr_name ( ident. name ) {
552
- let binding = ( Res :: NonMacroAttr ( NonMacroAttrKind :: Builtin ) ,
553
- ty:: Visibility :: Public , DUMMY_SP , Mark :: root ( ) )
554
- . to_name_binding ( this. arenas ) ;
555
- Ok ( ( binding, Flags :: PRELUDE ) )
556
- } else {
557
- Err ( Determinacy :: Determined )
558
- }
538
+ Scope :: BuiltinAttrs => if is_builtin_attr_name ( ident. name ) {
539
+ let binding = ( Res :: NonMacroAttr ( NonMacroAttrKind :: Builtin ) ,
540
+ ty:: Visibility :: Public , DUMMY_SP , Mark :: root ( ) )
541
+ . to_name_binding ( this. arenas ) ;
542
+ Ok ( ( binding, Flags :: PRELUDE ) )
543
+ } else {
544
+ Err ( Determinacy :: Determined )
559
545
}
560
- Scope :: LegacyPluginHelpers => {
561
- if ( use_prelude || rust_2015) &&
562
- this. session . plugin_attributes . borrow ( ) . iter ( )
546
+ Scope :: LegacyPluginHelpers => if this. session . plugin_attributes . borrow ( ) . iter ( )
563
547
. any ( |( name, _) | ident. name == * name) {
564
- let binding = ( Res :: NonMacroAttr ( NonMacroAttrKind :: LegacyPluginHelper ) ,
565
- ty:: Visibility :: Public , DUMMY_SP , Mark :: root ( ) )
566
- . to_name_binding ( this. arenas ) ;
567
- Ok ( ( binding, Flags :: PRELUDE ) )
568
- } else {
569
- Err ( Determinacy :: Determined )
570
- }
548
+ let binding = ( Res :: NonMacroAttr ( NonMacroAttrKind :: LegacyPluginHelper ) ,
549
+ ty:: Visibility :: Public , DUMMY_SP , Mark :: root ( ) )
550
+ . to_name_binding ( this. arenas ) ;
551
+ Ok ( ( binding, Flags :: PRELUDE ) )
552
+ } else {
553
+ Err ( Determinacy :: Determined )
571
554
}
572
- Scope :: ExternPrelude => {
573
- if use_prelude || is_absolute_path {
574
- match this. extern_prelude_get ( ident, !record_used) {
575
- Some ( binding) => Ok ( ( binding, Flags :: PRELUDE ) ) ,
576
- None => Err ( Determinacy :: determined (
577
- this. graph_root . unresolved_invocations . borrow ( ) . is_empty ( )
578
- ) ) ,
579
- }
580
- } else {
581
- Err ( Determinacy :: Determined )
582
- }
555
+ Scope :: ExternPrelude => match this. extern_prelude_get ( ident, !record_used) {
556
+ Some ( binding) => Ok ( ( binding, Flags :: PRELUDE ) ) ,
557
+ None => Err ( Determinacy :: determined (
558
+ this. graph_root . unresolved_invocations . borrow ( ) . is_empty ( )
559
+ ) ) ,
583
560
}
584
- Scope :: ToolPrelude => {
585
- if use_prelude && KNOWN_TOOLS . contains ( & ident. name ) {
586
- let binding = ( Res :: ToolMod , ty:: Visibility :: Public ,
587
- DUMMY_SP , Mark :: root ( ) ) . to_name_binding ( this. arenas ) ;
588
- Ok ( ( binding, Flags :: PRELUDE ) )
589
- } else {
590
- Err ( Determinacy :: Determined )
591
- }
561
+ Scope :: ToolPrelude => if KNOWN_TOOLS . contains ( & ident. name ) {
562
+ let binding = ( Res :: ToolMod , ty:: Visibility :: Public , DUMMY_SP , Mark :: root ( ) )
563
+ . to_name_binding ( this. arenas ) ;
564
+ Ok ( ( binding, Flags :: PRELUDE ) )
565
+ } else {
566
+ Err ( Determinacy :: Determined )
592
567
}
593
568
Scope :: StdLibPrelude => {
594
569
let mut result = Err ( Determinacy :: Determined ) ;
595
- if use_prelude {
596
- if let Some ( prelude) = this. prelude {
597
- if let Ok ( binding) = this. resolve_ident_in_module_unadjusted (
598
- ModuleOrUniformRoot :: Module ( prelude) ,
599
- ident,
600
- ns,
601
- false ,
602
- path_span,
603
- ) {
604
- result = Ok ( ( binding, Flags :: PRELUDE | Flags :: MISC_FROM_PRELUDE ) ) ;
605
- }
570
+ if let Some ( prelude) = this. prelude {
571
+ if let Ok ( binding) = this. resolve_ident_in_module_unadjusted (
572
+ ModuleOrUniformRoot :: Module ( prelude) ,
573
+ ident,
574
+ ns,
575
+ false ,
576
+ path_span,
577
+ ) {
578
+ result = Ok ( ( binding, Flags :: PRELUDE | Flags :: MISC_FROM_PRELUDE ) ) ;
606
579
}
607
580
}
608
581
result
609
582
}
610
- Scope :: BuiltinTypes => {
611
- match this. primitive_type_table . primitive_types . get ( & ident. name ) . cloned ( ) {
612
- Some ( prim_ty) => {
613
- let binding = ( Res :: PrimTy ( prim_ty) , ty:: Visibility :: Public ,
614
- DUMMY_SP , Mark :: root ( ) ) . to_name_binding ( this. arenas ) ;
615
- Ok ( ( binding, Flags :: PRELUDE ) )
616
- }
617
- None => Err ( Determinacy :: Determined )
583
+ Scope :: BuiltinTypes => match this. primitive_type_table . primitive_types
584
+ . get ( & ident. name ) . cloned ( ) {
585
+ Some ( prim_ty) => {
586
+ let binding = ( Res :: PrimTy ( prim_ty) , ty:: Visibility :: Public ,
587
+ DUMMY_SP , Mark :: root ( ) ) . to_name_binding ( this. arenas ) ;
588
+ Ok ( ( binding, Flags :: PRELUDE ) )
618
589
}
590
+ None => Err ( Determinacy :: Determined )
619
591
}
620
592
} ;
621
593
@@ -712,7 +684,7 @@ impl<'a> Resolver<'a> {
712
684
// the last segment, so we are certainly working with a single-segment attribute here.)
713
685
assert ! ( ns == MacroNS ) ;
714
686
let binding = ( Res :: NonMacroAttr ( NonMacroAttrKind :: Custom ) ,
715
- ty:: Visibility :: Public , ident . span , Mark :: root ( ) )
687
+ ty:: Visibility :: Public , orig_ident . span , Mark :: root ( ) )
716
688
. to_name_binding ( self . arenas ) ;
717
689
Ok ( binding)
718
690
} else {
0 commit comments