@@ -46,7 +46,6 @@ use rustc_data_structures::sync::Lrc;
46
46
use rustc_data_structures:: small_vec:: ExpectOne ;
47
47
48
48
crate struct FromPrelude ( bool ) ;
49
- crate struct FromExpansion ( bool ) ;
50
49
51
50
#[ derive( Clone ) ]
52
51
pub struct InvocationData < ' a > {
@@ -458,7 +457,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
458
457
}
459
458
460
459
let legacy_resolution = self . resolve_legacy_scope ( & invocation. legacy_scope , path[ 0 ] , false ) ;
461
- let result = if let Some ( ( legacy_binding, _ ) ) = legacy_resolution {
460
+ let result = if let Some ( legacy_binding) = legacy_resolution {
462
461
Ok ( legacy_binding. def ( ) )
463
462
} else {
464
463
match self . resolve_lexical_macro_path_segment ( path[ 0 ] , MacroNS , false , force,
@@ -765,7 +764,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
765
764
scope : & ' a Cell < LegacyScope < ' a > > ,
766
765
ident : Ident ,
767
766
record_used : bool )
768
- -> Option < ( & ' a NameBinding < ' a > , FromExpansion ) > {
767
+ -> Option < & ' a NameBinding < ' a > > {
769
768
let ident = ident. modern ( ) ;
770
769
771
770
// Names from inner scope that can't shadow names from outer scopes, e.g.
@@ -775,15 +774,14 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
775
774
// // the outer `mac` and we have and ambiguity error
776
775
// mac!();
777
776
// }
778
- let mut potentially_ambiguous_result: Option < ( & NameBinding , FromExpansion ) > = None ;
777
+ let mut potentially_ambiguous_result: Option < & NameBinding > = None ;
779
778
780
779
// Go through all the scopes and try to resolve the name.
781
780
let mut where_to_resolve = scope;
782
- let mut relative_depth = 0u32 ;
783
781
loop {
784
782
let result = match where_to_resolve. get ( ) {
785
783
LegacyScope :: Binding ( legacy_binding) => if ident == legacy_binding. ident {
786
- Some ( ( legacy_binding. binding , FromExpansion ( relative_depth > 0 ) ) )
784
+ Some ( legacy_binding. binding )
787
785
} else {
788
786
None
789
787
}
@@ -793,16 +791,11 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
793
791
macro_rules! continue_search { ( ) => {
794
792
where_to_resolve = match where_to_resolve. get( ) {
795
793
LegacyScope :: Binding ( binding) => & binding. parent,
796
- LegacyScope :: Invocation ( invocation) => {
797
- relative_depth = relative_depth. saturating_sub( 1 ) ;
798
- & invocation. legacy_scope
799
- }
794
+ LegacyScope :: Invocation ( invocation) => & invocation. legacy_scope,
800
795
LegacyScope :: Expansion ( invocation) => match invocation. expansion. get( ) {
801
796
LegacyScope :: Empty => & invocation. legacy_scope,
802
- LegacyScope :: Binding ( ..) | LegacyScope :: Expansion ( ..) => {
803
- relative_depth += 1 ;
804
- & invocation. expansion
805
- }
797
+ LegacyScope :: Binding ( ..) |
798
+ LegacyScope :: Expansion ( ..) => & invocation. expansion,
806
799
LegacyScope :: Invocation ( ..) => {
807
800
where_to_resolve. set( invocation. legacy_scope. get( ) ) ;
808
801
where_to_resolve
@@ -824,12 +817,12 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
824
817
// Push an ambiguity error for later reporting and
825
818
// return something for better recovery.
826
819
if let Some ( previous_result) = potentially_ambiguous_result {
827
- if result. 0 . def ( ) != previous_result. 0 . def ( ) {
820
+ if result. def ( ) != previous_result. def ( ) {
828
821
self . ambiguity_errors . push ( AmbiguityError {
829
822
span : ident. span ,
830
823
name : ident. name ,
831
- b1 : previous_result. 0 ,
832
- b2 : result. 0 ,
824
+ b1 : previous_result,
825
+ b2 : result,
833
826
} ) ;
834
827
return Some ( previous_result) ;
835
828
}
@@ -838,7 +831,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
838
831
// Found a solution that's not an ambiguity yet, but is "suspicious" and
839
832
// can participate in ambiguities later on.
840
833
// Remember it and go search for other solutions in outer scopes.
841
- if ( result. 1 ) . 0 {
834
+ if result. expansion != Mark :: root ( ) {
842
835
potentially_ambiguous_result = Some ( result) ;
843
836
844
837
continue_search ! ( ) ;
@@ -910,16 +903,16 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
910
903
self . suggest_macro_name ( & ident. as_str ( ) , kind, & mut err, span) ;
911
904
err. emit ( ) ;
912
905
} ,
913
- ( Some ( ( legacy_binding, FromExpansion ( _ ) ) ) , Ok ( ( binding, FromPrelude ( false ) ) ) ) |
914
- ( Some ( ( legacy_binding, FromExpansion ( true ) ) ) , Ok ( ( binding , FromPrelude ( true ) ) ) ) => {
906
+ ( Some ( legacy_binding) , Ok ( ( binding, FromPrelude ( from_prelude ) ) ) )
907
+ if !from_prelude || legacy_binding. expansion != Mark :: root ( ) => {
915
908
if legacy_binding. def_ignoring_ambiguity ( ) != binding. def_ignoring_ambiguity ( ) {
916
909
self . report_ambiguity_error ( ident. name , span, legacy_binding, binding) ;
917
910
}
918
911
} ,
919
- // OK, non-macro-expanded legacy wins over macro prelude even if defs are different
920
- ( Some ( ( legacy_binding, FromExpansion ( false ) ) ) , Ok ( ( _ , FromPrelude ( true ) ) ) ) |
912
+ // OK, non-macro-expanded legacy wins over prelude even if defs are different
913
+ ( Some ( legacy_binding) , Ok ( _ ) ) |
921
914
// OK, unambiguous resolution
922
- ( Some ( ( legacy_binding, _ ) ) , Err ( _) ) => {
915
+ ( Some ( legacy_binding) , Err ( _) ) => {
923
916
check_consistency ( self , legacy_binding. def ( ) ) ;
924
917
}
925
918
// OK, unambiguous resolution
0 commit comments