@@ -17,7 +17,7 @@ use crate::late::{
17
17
ConstantHasGenerics , ConstantItemKind , HasGenericParams , PathSource , Rib , RibKind ,
18
18
} ;
19
19
use crate :: macros:: { sub_namespace_match, MacroRulesScope } ;
20
- use crate :: { AmbiguityError , AmbiguityErrorMisc , AmbiguityKind , Determinacy , Finalize } ;
20
+ use crate :: { errors , AmbiguityError , AmbiguityErrorMisc , AmbiguityKind , Determinacy , Finalize } ;
21
21
use crate :: { Import , ImportKind , LexicalScopeBinding , Module , ModuleKind , ModuleOrUniformRoot } ;
22
22
use crate :: { NameBinding , NameBindingKind , ParentScope , PathResult , PrivacyError , Res } ;
23
23
use crate :: { ResolutionError , Resolver , Scope , ScopeSet , Segment , ToNameBinding , Weak } ;
@@ -1357,7 +1357,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1357
1357
}
1358
1358
} ;
1359
1359
1360
- let is_last = i == path. len ( ) - 1 ;
1360
+ let is_last = i + 1 == path. len ( ) ;
1361
1361
let ns = if is_last { opt_ns. unwrap_or ( TypeNS ) } else { TypeNS } ;
1362
1362
let name = ident. name ;
1363
1363
@@ -1494,16 +1494,12 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1494
1494
if let Some ( next_module) = binding. module ( ) {
1495
1495
module = Some ( ModuleOrUniformRoot :: Module ( next_module) ) ;
1496
1496
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 ( ) {
1498
1498
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
+ } ) ;
1507
1503
}
1508
1504
let res = Res :: NonMacroAttr ( NonMacroAttrKind :: Tool ) ;
1509
1505
return PathResult :: NonModule ( PartialRes :: new ( res) ) ;
0 commit comments