@@ -629,6 +629,35 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
629629 // `true` for `...::{self [as target]}` imports, `false` otherwise.
630630 let type_ns_only = nested && source. ident . name == kw:: SelfLower ;
631631
632+ if source. ident . name == kw:: SelfLower
633+ && let Some ( parent) = module_path. pop ( )
634+ {
635+ // Suggest `use prefix::{self};` for `use prefix::self;`
636+ if !type_ns_only
637+ && ( parent. ident . name != kw:: PathRoot
638+ || self . r . path_root_is_crate_root ( parent. ident ) )
639+ {
640+ let span_with_rename = match rename {
641+ Some ( rename) => source. ident . span . to ( rename. span ) ,
642+ None => source. ident . span ,
643+ } ;
644+
645+ self . r . report_error (
646+ parent. ident . span . shrink_to_hi ( ) . to ( source. ident . span ) ,
647+ ResolutionError :: SelfImportsOnlyAllowedWithin {
648+ root : parent. ident . name == kw:: PathRoot ,
649+ span_with_rename,
650+ } ,
651+ ) ;
652+ }
653+
654+ let self_span = source. ident . span ;
655+ source = parent;
656+ if rename. is_none ( ) {
657+ ident = Ident :: new ( source. ident . name , self_span) ;
658+ }
659+ }
660+
632661 match source. ident . name {
633662 kw:: DollarCrate => {
634663 if !module_path. is_empty ( ) {
@@ -664,45 +693,14 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
664693 return ;
665694 }
666695 }
667- kw:: SelfLower => {
668- if let Some ( parent) = module_path. pop ( ) {
669- // Suggest `use prefix::{self};` for `use prefix::self;`
670- if !type_ns_only
671- && ( parent. ident . name != kw:: PathRoot
672- || self . r . path_root_is_crate_root ( parent. ident ) )
673- {
674- let span_with_rename = match rename {
675- Some ( rename) => source. ident . span . to ( rename. span ) ,
676- None => source. ident . span ,
677- } ;
678-
679- self . r . report_error (
680- parent. ident . span . shrink_to_hi ( ) . to ( source. ident . span ) ,
681- ResolutionError :: SelfImportsOnlyAllowedWithin {
682- root : parent. ident . name == kw:: PathRoot ,
683- span_with_rename,
684- } ,
685- ) ;
686- }
687-
688- let self_span = source. ident . span ;
689- source = parent;
690- if rename. is_none ( ) {
691- ident = Ident :: new ( source. ident . name , self_span) ;
692- }
693- }
696+ // Deny `use ::{self};` after edition 2015
697+ kw:: PathRoot if !self . r . path_root_is_crate_root ( source. ident ) => {
698+ self . r . dcx ( ) . span_err ( use_tree. span , "extern prelude cannot be imported" ) ;
699+ return ;
694700 }
695701 _ => { }
696702 }
697703
698- // Deny `use ::{self};` after edition 2015
699- if source. ident . name == kw:: PathRoot
700- && !self . r . path_root_is_crate_root ( source. ident )
701- {
702- self . r . dcx ( ) . span_err ( use_tree. span , "extern prelude cannot be imported" ) ;
703- return ;
704- }
705-
706704 // Deny importing path-kw without renaming
707705 if rename. is_none ( ) && ident. is_path_segment_keyword ( ) {
708706 let ident = use_tree. ident ( ) ;
0 commit comments