@@ -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 > {
@@ -481,7 +480,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
481
480
}
482
481
483
482
let legacy_resolution = self . resolve_legacy_scope ( & invocation. legacy_scope , path[ 0 ] , false ) ;
484
- let result = if let Some ( ( legacy_binding, _ ) ) = legacy_resolution {
483
+ let result = if let Some ( legacy_binding) = legacy_resolution {
485
484
Ok ( legacy_binding. def ( ) )
486
485
} else {
487
486
match self . resolve_lexical_macro_path_segment ( path[ 0 ] , MacroNS , false , force,
@@ -788,7 +787,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
788
787
scope : & ' a Cell < LegacyScope < ' a > > ,
789
788
ident : Ident ,
790
789
record_used : bool )
791
- -> Option < ( & ' a NameBinding < ' a > , FromExpansion ) > {
790
+ -> Option < & ' a NameBinding < ' a > > {
792
791
let ident = ident. modern ( ) ;
793
792
794
793
// Names from inner scope that can't shadow names from outer scopes, e.g.
@@ -798,15 +797,14 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
798
797
// // the outer `mac` and we have and ambiguity error
799
798
// mac!();
800
799
// }
801
- let mut potentially_ambiguous_result: Option < ( & NameBinding , FromExpansion ) > = None ;
800
+ let mut potentially_ambiguous_result: Option < & NameBinding > = None ;
802
801
803
802
// Go through all the scopes and try to resolve the name.
804
803
let mut where_to_resolve = scope;
805
- let mut relative_depth = 0u32 ;
806
804
loop {
807
805
let result = match where_to_resolve. get ( ) {
808
806
LegacyScope :: Binding ( legacy_binding) => if ident == legacy_binding. ident {
809
- Some ( ( legacy_binding. binding , FromExpansion ( relative_depth > 0 ) ) )
807
+ Some ( legacy_binding. binding )
810
808
} else {
811
809
None
812
810
}
@@ -816,16 +814,11 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
816
814
macro_rules! continue_search { ( ) => {
817
815
where_to_resolve = match where_to_resolve. get( ) {
818
816
LegacyScope :: Binding ( binding) => & binding. parent,
819
- LegacyScope :: Invocation ( invocation) => {
820
- relative_depth = relative_depth. saturating_sub( 1 ) ;
821
- & invocation. legacy_scope
822
- }
817
+ LegacyScope :: Invocation ( invocation) => & invocation. legacy_scope,
823
818
LegacyScope :: Expansion ( invocation) => match invocation. expansion. get( ) {
824
819
LegacyScope :: Empty => & invocation. legacy_scope,
825
- LegacyScope :: Binding ( ..) | LegacyScope :: Expansion ( ..) => {
826
- relative_depth += 1 ;
827
- & invocation. expansion
828
- }
820
+ LegacyScope :: Binding ( ..) |
821
+ LegacyScope :: Expansion ( ..) => & invocation. expansion,
829
822
LegacyScope :: Invocation ( ..) => {
830
823
where_to_resolve. set( invocation. legacy_scope. get( ) ) ;
831
824
where_to_resolve
@@ -847,12 +840,12 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
847
840
// Push an ambiguity error for later reporting and
848
841
// return something for better recovery.
849
842
if let Some ( previous_result) = potentially_ambiguous_result {
850
- if result. 0 . def ( ) != previous_result. 0 . def ( ) {
843
+ if result. def ( ) != previous_result. def ( ) {
851
844
self . ambiguity_errors . push ( AmbiguityError {
852
845
span : ident. span ,
853
846
name : ident. name ,
854
- b1 : previous_result. 0 ,
855
- b2 : result. 0 ,
847
+ b1 : previous_result,
848
+ b2 : result,
856
849
} ) ;
857
850
return Some ( previous_result) ;
858
851
}
@@ -861,7 +854,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
861
854
// Found a solution that's not an ambiguity yet, but is "suspicious" and
862
855
// can participate in ambiguities later on.
863
856
// Remember it and go search for other solutions in outer scopes.
864
- if ( result. 1 ) . 0 {
857
+ if result. expansion != Mark :: root ( ) {
865
858
potentially_ambiguous_result = Some ( result) ;
866
859
867
860
continue_search ! ( ) ;
@@ -933,16 +926,16 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
933
926
self . suggest_macro_name ( & ident. as_str ( ) , kind, & mut err, span) ;
934
927
err. emit ( ) ;
935
928
} ,
936
- ( Some ( ( legacy_binding, FromExpansion ( _ ) ) ) , Ok ( ( binding, FromPrelude ( false ) ) ) ) |
937
- ( Some ( ( legacy_binding, FromExpansion ( true ) ) ) , Ok ( ( binding , FromPrelude ( true ) ) ) ) => {
929
+ ( Some ( legacy_binding) , Ok ( ( binding, FromPrelude ( from_prelude ) ) ) )
930
+ if !from_prelude || legacy_binding. expansion != Mark :: root ( ) => {
938
931
if legacy_binding. def_ignoring_ambiguity ( ) != binding. def_ignoring_ambiguity ( ) {
939
932
self . report_ambiguity_error ( ident. name , span, legacy_binding, binding) ;
940
933
}
941
934
} ,
942
- // OK, non-macro-expanded legacy wins over macro prelude even if defs are different
943
- ( Some ( ( legacy_binding, FromExpansion ( false ) ) ) , Ok ( ( _ , FromPrelude ( true ) ) ) ) |
935
+ // OK, non-macro-expanded legacy wins over prelude even if defs are different
936
+ ( Some ( legacy_binding) , Ok ( _ ) ) |
944
937
// OK, unambiguous resolution
945
- ( Some ( ( legacy_binding, _ ) ) , Err ( _) ) => {
938
+ ( Some ( legacy_binding) , Err ( _) ) => {
946
939
check_consistency ( self , legacy_binding. def ( ) ) ;
947
940
}
948
941
// OK, unambiguous resolution
0 commit comments