@@ -2064,52 +2064,64 @@ impl<'a> Resolver<'a> {
20642064 } ;
20652065 }
20662066
2067- let binding = if let Some ( module) = module {
2068- self . resolve_ident_in_module (
2069- module,
2070- ident,
2071- ns,
2072- parent_scope,
2073- record_used,
2074- path_span,
2075- )
2076- } else if ribs. is_none ( ) || opt_ns. is_none ( ) || opt_ns == Some ( MacroNS ) {
2077- let scopes = ScopeSet :: All ( ns, opt_ns. is_none ( ) ) ;
2078- self . early_resolve_ident_in_lexical_scope (
2079- ident,
2080- scopes,
2081- parent_scope,
2082- record_used,
2083- record_used,
2084- path_span,
2085- )
2086- } else {
2087- let record_used_id =
2088- if record_used { crate_lint. node_id ( ) . or ( Some ( CRATE_NODE_ID ) ) } else { None } ;
2089- match self . resolve_ident_in_lexical_scope (
2090- ident,
2091- ns,
2092- parent_scope,
2093- record_used_id,
2094- path_span,
2095- & ribs. unwrap ( ) [ ns] ,
2096- ) {
2097- // we found a locally-imported or available item/module
2098- Some ( LexicalScopeBinding :: Item ( binding) ) => Ok ( binding) ,
2099- // we found a local variable or type param
2100- Some ( LexicalScopeBinding :: Res ( res) )
2101- if opt_ns == Some ( TypeNS ) || opt_ns == Some ( ValueNS ) =>
2102- {
2103- record_segment_res ( self , res) ;
2104- return PathResult :: NonModule ( PartialRes :: with_unresolved_segments (
2105- res,
2106- path. len ( ) - 1 ,
2107- ) ) ;
2067+ enum FindBindingResult < ' a > {
2068+ Binding ( Result < & ' a NameBinding < ' a > , Determinacy > ) ,
2069+ PathResult ( PathResult < ' a > ) ,
2070+ }
2071+ let find_binding_in_ns = |this : & mut Self , ns| {
2072+ let binding = if let Some ( module) = module {
2073+ this. resolve_ident_in_module (
2074+ module,
2075+ ident,
2076+ ns,
2077+ parent_scope,
2078+ record_used,
2079+ path_span,
2080+ )
2081+ } else if ribs. is_none ( ) || opt_ns. is_none ( ) || opt_ns == Some ( MacroNS ) {
2082+ let scopes = ScopeSet :: All ( ns, opt_ns. is_none ( ) ) ;
2083+ this. early_resolve_ident_in_lexical_scope (
2084+ ident,
2085+ scopes,
2086+ parent_scope,
2087+ record_used,
2088+ record_used,
2089+ path_span,
2090+ )
2091+ } else {
2092+ let record_used_id = if record_used {
2093+ crate_lint. node_id ( ) . or ( Some ( CRATE_NODE_ID ) )
2094+ } else {
2095+ None
2096+ } ;
2097+ match this. resolve_ident_in_lexical_scope (
2098+ ident,
2099+ ns,
2100+ parent_scope,
2101+ record_used_id,
2102+ path_span,
2103+ & ribs. unwrap ( ) [ ns] ,
2104+ ) {
2105+ // we found a locally-imported or available item/module
2106+ Some ( LexicalScopeBinding :: Item ( binding) ) => Ok ( binding) ,
2107+ // we found a local variable or type param
2108+ Some ( LexicalScopeBinding :: Res ( res) )
2109+ if opt_ns == Some ( TypeNS ) || opt_ns == Some ( ValueNS ) =>
2110+ {
2111+ record_segment_res ( this, res) ;
2112+ return FindBindingResult :: PathResult ( PathResult :: NonModule (
2113+ PartialRes :: with_unresolved_segments ( res, path. len ( ) - 1 ) ,
2114+ ) ) ;
2115+ }
2116+ _ => Err ( Determinacy :: determined ( record_used) ) ,
21082117 }
2109- _ => Err ( Determinacy :: determined ( record_used) ) ,
2110- }
2118+ } ;
2119+ FindBindingResult :: Binding ( binding)
2120+ } ;
2121+ let binding = match find_binding_in_ns ( self , ns) {
2122+ FindBindingResult :: PathResult ( x) => return x,
2123+ FindBindingResult :: Binding ( binding) => binding,
21112124 } ;
2112-
21132125 match binding {
21142126 Ok ( binding) => {
21152127 if i == 1 {
@@ -2199,7 +2211,30 @@ impl<'a> Resolver<'a> {
21992211 } else if i == 0 {
22002212 ( format ! ( "use of undeclared type or module `{}`" , ident) , None )
22012213 } else {
2202- ( format ! ( "could not find `{}` in `{}`" , ident, path[ i - 1 ] . ident) , None )
2214+ let mut msg =
2215+ format ! ( "could not find `{}` in `{}`" , ident, path[ i - 1 ] . ident) ;
2216+ if ns == TypeNS {
2217+ if let FindBindingResult :: Binding ( Ok ( _) ) =
2218+ find_binding_in_ns ( self , ValueNS )
2219+ {
2220+ msg = format ! (
2221+ "`{}` in `{}` is a concrete value, not a module or Struct you specified" ,
2222+ ident,
2223+ path[ i - 1 ] . ident
2224+ ) ;
2225+ } ;
2226+ } else if ns == ValueNS {
2227+ if let FindBindingResult :: Binding ( Ok ( _) ) =
2228+ find_binding_in_ns ( self , TypeNS )
2229+ {
2230+ msg = format ! (
2231+ "`{}` in `{}` is a type, not a concrete value you specified" ,
2232+ ident,
2233+ path[ i - 1 ] . ident
2234+ ) ;
2235+ } ;
2236+ }
2237+ ( msg, None )
22032238 } ;
22042239 return PathResult :: Failed {
22052240 span : ident. span ,
0 commit comments