@@ -17,7 +17,7 @@ use crate::late::{
1717 ConstantHasGenerics , ConstantItemKind , HasGenericParams , PathSource , Rib , RibKind ,
1818} ;
1919use crate :: macros:: { sub_namespace_match, MacroRulesScope } ;
20- use crate :: { AmbiguityError , AmbiguityErrorMisc , AmbiguityKind , Determinacy , Finalize } ;
20+ use crate :: { errors , AmbiguityError , AmbiguityErrorMisc , AmbiguityKind , Determinacy , Finalize } ;
2121use crate :: { Import , ImportKind , LexicalScopeBinding , Module , ModuleKind , ModuleOrUniformRoot } ;
2222use crate :: { NameBinding , NameBindingKind , ParentScope , PathResult , PrivacyError , Res } ;
2323use crate :: { ResolutionError , Resolver , Scope , ScopeSet , Segment , ToNameBinding , Weak } ;
@@ -1357,7 +1357,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
13571357 }
13581358 } ;
13591359
1360- let is_last = i == path. len ( ) - 1 ;
1360+ let is_last = i + 1 == path. len ( ) ;
13611361 let ns = if is_last { opt_ns. unwrap_or ( TypeNS ) } else { TypeNS } ;
13621362 let name = ident. name ;
13631363
@@ -1494,16 +1494,12 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
14941494 if let Some ( next_module) = binding. module ( ) {
14951495 module = Some ( ModuleOrUniformRoot :: Module ( next_module) ) ;
14961496 record_segment_res ( self , res) ;
1497- } else if res == Res :: ToolMod && i + 1 != path . len ( ) {
1497+ } else if res == Res :: ToolMod && !is_last && opt_ns . is_some ( ) {
14981498 if binding. is_import ( ) {
1499- self . tcx
1500- . sess
1501- . struct_span_err (
1502- ident. span ,
1503- "cannot use a tool module through an import" ,
1504- )
1505- . span_note ( binding. span , "the tool module imported here" )
1506- . emit ( ) ;
1499+ self . tcx . sess . emit_err ( errors:: ToolModuleImported {
1500+ span : ident. span ,
1501+ import : binding. span ,
1502+ } ) ;
15071503 }
15081504 let res = Res :: NonMacroAttr ( NonMacroAttrKind :: Tool ) ;
15091505 return PathResult :: NonModule ( PartialRes :: new ( res) ) ;
0 commit comments