@@ -613,7 +613,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Resolver<'a> {
613613 self . smart_resolve_path ( ty. id , qself. as_ref ( ) , path, PathSource :: Type ) ;
614614 } else if let TyKind :: ImplicitSelf = ty. node {
615615 let self_ty = keywords:: SelfType . ident ( ) ;
616- let def = self . resolve_ident_in_lexical_scope ( self_ty, TypeNS , Some ( ty. span ) )
616+ let def = self . resolve_ident_in_lexical_scope ( self_ty, TypeNS , true , ty. span )
617617 . map_or ( Def :: Err , |d| d. def ( ) ) ;
618618 self . record_def ( ty. id , PathResolution :: new ( def) ) ;
619619 } else if let TyKind :: Array ( ref element, ref length) = ty. node {
@@ -1267,11 +1267,11 @@ impl<'a> hir::lowering::Resolver for Resolver<'a> {
12671267 let namespace = if is_value { ValueNS } else { TypeNS } ;
12681268 let hir:: Path { ref segments, span, ref mut def } = * path;
12691269 let path: Vec < _ > = segments. iter ( ) . map ( |seg| Ident :: with_empty_ctxt ( seg. name ) ) . collect ( ) ;
1270- match self . resolve_path ( & path, Some ( namespace) , Some ( span) ) {
1270+ match self . resolve_path ( & path, Some ( namespace) , true , span) {
12711271 PathResult :: Module ( module) => * def = module. def ( ) . unwrap ( ) ,
12721272 PathResult :: NonModule ( path_res) if path_res. unresolved_segments ( ) == 0 =>
12731273 * def = path_res. base_def ( ) ,
1274- PathResult :: NonModule ( ..) => match self . resolve_path ( & path, None , Some ( span) ) {
1274+ PathResult :: NonModule ( ..) => match self . resolve_path ( & path, None , true , span) {
12751275 PathResult :: Failed ( msg, _) => {
12761276 resolve_error ( self , span, ResolutionError :: FailedToResolve ( & msg) ) ;
12771277 }
@@ -1502,7 +1502,8 @@ impl<'a> Resolver<'a> {
15021502 fn resolve_ident_in_lexical_scope ( & mut self ,
15031503 mut ident : Ident ,
15041504 ns : Namespace ,
1505- record_used : Option < Span > )
1505+ record_used : bool ,
1506+ path_span : Span )
15061507 -> Option < LexicalScopeBinding < ' a > > {
15071508 if ns == TypeNS {
15081509 ident = ident. unhygienize ( ) ;
@@ -1513,12 +1514,13 @@ impl<'a> Resolver<'a> {
15131514 if let Some ( def) = self . ribs [ ns] [ i] . bindings . get ( & ident) . cloned ( ) {
15141515 // The ident resolves to a type parameter or local variable.
15151516 return Some ( LexicalScopeBinding :: Def (
1516- self . adjust_local_def ( ns, i, def, record_used)
1517+ self . adjust_local_def ( ns, i, def, record_used, path_span )
15171518 ) ) ;
15181519 }
15191520
15201521 if let ModuleRibKind ( module) = self . ribs [ ns] [ i] . kind {
1521- let item = self . resolve_ident_in_module ( module, ident, ns, false , record_used) ;
1522+ let item = self . resolve_ident_in_module ( module, ident, ns, false ,
1523+ record_used, path_span) ;
15221524 if let Ok ( binding) = item {
15231525 // The ident resolves to an item.
15241526 return Some ( LexicalScopeBinding :: Item ( binding) ) ;
@@ -1527,7 +1529,8 @@ impl<'a> Resolver<'a> {
15271529 if let ModuleKind :: Block ( ..) = module. kind { // We can see through blocks
15281530 } else if !module. no_implicit_prelude {
15291531 return self . prelude . and_then ( |prelude| {
1530- self . resolve_ident_in_module ( prelude, ident, ns, false , None ) . ok ( )
1532+ self . resolve_ident_in_module ( prelude, ident, ns, false ,
1533+ false , path_span) . ok ( )
15311534 } ) . map ( LexicalScopeBinding :: Item )
15321535 } else {
15331536 return None ;
@@ -2147,7 +2150,8 @@ impl<'a> Resolver<'a> {
21472150 PatKind :: Ident ( bmode, ref ident, ref opt_pat) => {
21482151 // First try to resolve the identifier as some existing
21492152 // entity, then fall back to a fresh binding.
2150- let binding = self . resolve_ident_in_lexical_scope ( ident. node , ValueNS , None )
2153+ let binding = self . resolve_ident_in_lexical_scope ( ident. node , ValueNS ,
2154+ false , pat. span )
21512155 . and_then ( LexicalScopeBinding :: item) ;
21522156 let resolution = binding. map ( NameBinding :: def) . and_then ( |def| {
21532157 let always_binding = !pat_src. is_refutable ( ) || opt_pat. is_some ( ) ||
@@ -2253,7 +2257,7 @@ impl<'a> Resolver<'a> {
22532257 ( format ! ( "" ) , format ! ( "the crate root" ) )
22542258 } else {
22552259 let mod_path = & path[ ..path. len ( ) - 1 ] ;
2256- let mod_prefix = match this. resolve_path ( mod_path, Some ( TypeNS ) , None ) {
2260+ let mod_prefix = match this. resolve_path ( mod_path, Some ( TypeNS ) , false , span ) {
22572261 PathResult :: Module ( module) => module. def ( ) ,
22582262 _ => None ,
22592263 } . map_or ( format ! ( "" ) , |def| format ! ( "{} " , def. kind_name( ) ) ) ;
@@ -2303,9 +2307,9 @@ impl<'a> Resolver<'a> {
23032307 }
23042308 }
23052309 }
2306- if path. len ( ) == 1 && this. self_type_is_available ( ) {
2310+ if path. len ( ) == 1 && this. self_type_is_available ( span ) {
23072311 if let Some ( candidate) = this. lookup_assoc_candidate ( name, ns, is_expected) {
2308- let self_is_available = this. self_value_is_available ( path[ 0 ] . ctxt ) ;
2312+ let self_is_available = this. self_value_is_available ( path[ 0 ] . ctxt , span ) ;
23092313 match candidate {
23102314 AssocSuggestion :: Field => {
23112315 err. span_label ( span, format ! ( "did you mean `self.{}`?" , path_str) ) ;
@@ -2329,7 +2333,7 @@ impl<'a> Resolver<'a> {
23292333 let mut levenshtein_worked = false ;
23302334
23312335 // Try Levenshtein.
2332- if let Some ( candidate) = this. lookup_typo_candidate ( path, ns, is_expected) {
2336+ if let Some ( candidate) = this. lookup_typo_candidate ( path, ns, is_expected, span ) {
23332337 err. span_label ( ident_span, format ! ( "did you mean `{}`?" , candidate) ) ;
23342338 levenshtein_worked = true ;
23352339 }
@@ -2434,14 +2438,15 @@ impl<'a> Resolver<'a> {
24342438 resolution
24352439 }
24362440
2437- fn self_type_is_available ( & mut self ) -> bool {
2438- let binding = self . resolve_ident_in_lexical_scope ( keywords:: SelfType . ident ( ) , TypeNS , None ) ;
2441+ fn self_type_is_available ( & mut self , span : Span ) -> bool {
2442+ let binding = self . resolve_ident_in_lexical_scope ( keywords:: SelfType . ident ( ) ,
2443+ TypeNS , false , span) ;
24392444 if let Some ( LexicalScopeBinding :: Def ( def) ) = binding { def != Def :: Err } else { false }
24402445 }
24412446
2442- fn self_value_is_available ( & mut self , ctxt : SyntaxContext ) -> bool {
2447+ fn self_value_is_available ( & mut self , ctxt : SyntaxContext , span : Span ) -> bool {
24432448 let ident = Ident { name : keywords:: SelfValue . name ( ) , ctxt : ctxt } ;
2444- let binding = self . resolve_ident_in_lexical_scope ( ident, ValueNS , None ) ;
2449+ let binding = self . resolve_ident_in_lexical_scope ( ident, ValueNS , false , span ) ;
24452450 if let Some ( LexicalScopeBinding :: Def ( def) ) = binding { def != Def :: Err } else { false }
24462451 }
24472452
@@ -2505,7 +2510,7 @@ impl<'a> Resolver<'a> {
25052510 ) ) ;
25062511 }
25072512
2508- let result = match self . resolve_path ( & path, Some ( ns) , Some ( span) ) {
2513+ let result = match self . resolve_path ( & path, Some ( ns) , true , span) {
25092514 PathResult :: NonModule ( path_res) => path_res,
25102515 PathResult :: Module ( module) if !module. is_normal ( ) => {
25112516 PathResolution :: new ( module. def ( ) . unwrap ( ) )
@@ -2551,7 +2556,7 @@ impl<'a> Resolver<'a> {
25512556 if path. len ( ) > 1 && !global_by_default && result. base_def ( ) != Def :: Err &&
25522557 path[ 0 ] . name != keywords:: CrateRoot . name ( ) && path[ 0 ] . name != "$crate" {
25532558 let unqualified_result = {
2554- match self . resolve_path ( & [ * path. last ( ) . unwrap ( ) ] , Some ( ns) , None ) {
2559+ match self . resolve_path ( & [ * path. last ( ) . unwrap ( ) ] , Some ( ns) , false , span ) {
25552560 PathResult :: NonModule ( path_res) => path_res. base_def ( ) ,
25562561 PathResult :: Module ( module) => module. def ( ) . unwrap ( ) ,
25572562 _ => return Some ( result) ,
@@ -2569,7 +2574,8 @@ impl<'a> Resolver<'a> {
25692574 fn resolve_path ( & mut self ,
25702575 path : & [ Ident ] ,
25712576 opt_ns : Option < Namespace > , // `None` indicates a module path
2572- record_used : Option < Span > )
2577+ record_used : bool ,
2578+ path_span : Span )
25732579 -> PathResult < ' a > {
25742580 let mut module = None ;
25752581 let mut allow_super = true ;
@@ -2603,20 +2609,20 @@ impl<'a> Resolver<'a> {
26032609 }
26042610
26052611 let binding = if let Some ( module) = module {
2606- self . resolve_ident_in_module ( module, ident, ns, false , record_used)
2612+ self . resolve_ident_in_module ( module, ident, ns, false , record_used, path_span )
26072613 } else if opt_ns == Some ( MacroNS ) {
2608- self . resolve_lexical_macro_path_segment ( ident, ns, record_used)
2614+ self . resolve_lexical_macro_path_segment ( ident, ns, record_used, path_span )
26092615 . map ( MacroBinding :: binding)
26102616 } else {
2611- match self . resolve_ident_in_lexical_scope ( ident, ns, record_used) {
2617+ match self . resolve_ident_in_lexical_scope ( ident, ns, record_used, path_span ) {
26122618 Some ( LexicalScopeBinding :: Item ( binding) ) => Ok ( binding) ,
26132619 Some ( LexicalScopeBinding :: Def ( def) )
26142620 if opt_ns == Some ( TypeNS ) || opt_ns == Some ( ValueNS ) => {
26152621 return PathResult :: NonModule ( PathResolution :: with_unresolved_segments (
26162622 def, path. len ( ) - 1
26172623 ) ) ;
26182624 }
2619- _ => Err ( if record_used. is_some ( ) { Determined } else { Undetermined } ) ,
2625+ _ => Err ( if record_used { Determined } else { Undetermined } ) ,
26202626 }
26212627 } ;
26222628
@@ -2673,12 +2679,13 @@ impl<'a> Resolver<'a> {
26732679 ns : Namespace ,
26742680 rib_index : usize ,
26752681 mut def : Def ,
2676- record_used : Option < Span > ) -> Def {
2682+ record_used : bool ,
2683+ span : Span ) -> Def {
26772684 let ribs = & self . ribs [ ns] [ rib_index + 1 ..] ;
26782685
26792686 // An invalid forward use of a type parameter from a previous default.
26802687 if let ForwardTyParamBanRibKind = self . ribs [ ns] [ rib_index] . kind {
2681- if let Some ( span ) = record_used {
2688+ if record_used {
26822689 resolve_error ( self , span,
26832690 ResolutionError :: ForwardDeclaredTyParam ) ;
26842691 }
@@ -2688,7 +2695,7 @@ impl<'a> Resolver<'a> {
26882695
26892696 match def {
26902697 Def :: Upvar ( ..) => {
2691- span_bug ! ( record_used . unwrap_or ( DUMMY_SP ) , "unexpected {:?} in bindings" , def)
2698+ span_bug ! ( span , "unexpected {:?} in bindings" , def)
26922699 }
26932700 Def :: Local ( def_id) => {
26942701 for rib in ribs {
@@ -2714,7 +2721,7 @@ impl<'a> Resolver<'a> {
27142721 let depth = vec. len ( ) ;
27152722 def = Def :: Upvar ( def_id, depth, function_id) ;
27162723
2717- if let Some ( span ) = record_used {
2724+ if record_used {
27182725 vec. push ( Freevar {
27192726 def : prev_def,
27202727 span : span,
@@ -2726,15 +2733,15 @@ impl<'a> Resolver<'a> {
27262733 // This was an attempt to access an upvar inside a
27272734 // named function item. This is not allowed, so we
27282735 // report an error.
2729- if let Some ( span ) = record_used {
2736+ if record_used {
27302737 resolve_error ( self , span,
27312738 ResolutionError :: CannotCaptureDynamicEnvironmentInFnItem ) ;
27322739 }
27332740 return Def :: Err ;
27342741 }
27352742 ConstantItemRibKind => {
27362743 // Still doesn't deal with upvars
2737- if let Some ( span ) = record_used {
2744+ if record_used {
27382745 resolve_error ( self , span,
27392746 ResolutionError :: AttemptToUseNonConstantValueInConstant ) ;
27402747 }
@@ -2753,15 +2760,15 @@ impl<'a> Resolver<'a> {
27532760 ItemRibKind => {
27542761 // This was an attempt to use a type parameter outside
27552762 // its scope.
2756- if let Some ( span ) = record_used {
2763+ if record_used {
27572764 resolve_error ( self , span,
27582765 ResolutionError :: TypeParametersFromOuterFunction ) ;
27592766 }
27602767 return Def :: Err ;
27612768 }
27622769 ConstantItemRibKind => {
27632770 // see #9186
2764- if let Some ( span ) = record_used {
2771+ if record_used {
27652772 resolve_error ( self , span,
27662773 ResolutionError :: OuterTypeParameterContext ) ;
27672774 }
@@ -2857,7 +2864,8 @@ impl<'a> Resolver<'a> {
28572864 fn lookup_typo_candidate < FilterFn > ( & mut self ,
28582865 path : & [ Ident ] ,
28592866 ns : Namespace ,
2860- filter_fn : FilterFn )
2867+ filter_fn : FilterFn ,
2868+ span : Span )
28612869 -> Option < Symbol >
28622870 where FilterFn : Fn ( Def ) -> bool
28632871 {
@@ -2909,7 +2917,8 @@ impl<'a> Resolver<'a> {
29092917 } else {
29102918 // Search in module.
29112919 let mod_path = & path[ ..path. len ( ) - 1 ] ;
2912- if let PathResult :: Module ( module) = self . resolve_path ( mod_path, Some ( TypeNS ) , None ) {
2920+ if let PathResult :: Module ( module) = self . resolve_path ( mod_path, Some ( TypeNS ) ,
2921+ false , span) {
29132922 add_module_candidates ( module, & mut names) ;
29142923 }
29152924 }
@@ -3410,7 +3419,10 @@ impl<'a> Resolver<'a> {
34103419 continue
34113420 }
34123421 let ident = attr. path . segments [ 0 ] . identifier ;
3413- let result = self . resolve_lexical_macro_path_segment ( ident, MacroNS , None ) ;
3422+ let result = self . resolve_lexical_macro_path_segment ( ident,
3423+ MacroNS ,
3424+ false ,
3425+ attr. path . span ) ;
34143426 if let Ok ( binding) = result {
34153427 if let SyntaxExtension :: AttrProcMacro ( ..) = * binding. binding ( ) . get_macro ( self ) {
34163428 attr:: mark_known ( attr) ;
0 commit comments