@@ -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 } ;
@@ -1364,7 +1364,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
13641364 }
13651365 } ;
13661366
1367- let is_last = i == path. len ( ) - 1 ;
1367+ let is_last = i + 1 == path. len ( ) ;
13681368 let ns = if is_last { opt_ns. unwrap_or ( TypeNS ) } else { TypeNS } ;
13691369 let name = ident. name ;
13701370
@@ -1501,16 +1501,12 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
15011501 if let Some ( next_module) = binding. module ( ) {
15021502 module = Some ( ModuleOrUniformRoot :: Module ( next_module) ) ;
15031503 record_segment_res ( self , res) ;
1504- } else if res == Res :: ToolMod && i + 1 != path . len ( ) {
1504+ } else if res == Res :: ToolMod && !is_last && opt_ns . is_some ( ) {
15051505 if binding. is_import ( ) {
1506- self . tcx
1507- . sess
1508- . struct_span_err (
1509- ident. span ,
1510- "cannot use a tool module through an import" ,
1511- )
1512- . span_note ( binding. span , "the tool module imported here" )
1513- . emit ( ) ;
1506+ self . tcx . sess . emit_err ( errors:: ToolModuleImported {
1507+ span : ident. span ,
1508+ import : binding. span ,
1509+ } ) ;
15141510 }
15151511 let res = Res :: NonMacroAttr ( NonMacroAttrKind :: Tool ) ;
15161512 return PathResult :: NonModule ( PartialRes :: new ( res) ) ;
0 commit comments