11use rustc_ast:: { self as ast, NodeId } ;
2- use rustc_errors:: ErrorGuaranteed ;
2+ use rustc_errors:: { Applicability , ErrorGuaranteed } ;
33use rustc_hir:: def:: { DefKind , Namespace , NonMacroAttrKind , PartialRes , PerNS } ;
44use rustc_middle:: bug;
55use rustc_middle:: ty;
@@ -1483,9 +1483,42 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
14831483 continue ;
14841484 }
14851485 }
1486- return PathResult :: failed ( ident, false , finalize. is_some ( ) , module, || {
1487- ( "there are too many leading `super` keywords" . to_string ( ) , None )
1488- } ) ;
1486+ let mut item_type = "module" ;
1487+ if path. len ( ) == 1
1488+ && let Some ( ribs) = ribs
1489+ && let RibKind :: Normal = ribs[ ValueNS ] [ ribs[ ValueNS ] . len ( ) - 1 ] . kind
1490+ {
1491+ item_type = "item" ;
1492+ }
1493+ return PathResult :: failed (
1494+ ident,
1495+ false ,
1496+ finalize. is_some ( ) ,
1497+ module,
1498+ || {
1499+ let mut suggestion = None ;
1500+ let label = if path. len ( ) == 1
1501+ && let Some ( ribs) = ribs
1502+ && let RibKind :: Normal = ribs[ ValueNS ] [ ribs[ ValueNS ] . len ( ) - 1 ] . kind
1503+ {
1504+ suggestion = Some ( (
1505+ vec ! [ ( ident. span. shrink_to_lo( ) , "r#" . to_string( ) ) ] ,
1506+ "if you still want to call your identifier `super`, use the \
1507+ raw identifier format"
1508+ . to_string ( ) ,
1509+ Applicability :: MachineApplicable ,
1510+ ) ) ;
1511+ "can't use `super` as an identifier"
1512+ } else if segment_idx == 0 {
1513+ "can't use `super` on the crate root, there are no further modules \
1514+ to go \" up\" to"
1515+ } else {
1516+ "there are too many leading `super` keywords"
1517+ } ;
1518+ ( label. to_string ( ) , suggestion)
1519+ } ,
1520+ item_type,
1521+ ) ;
14891522 }
14901523 if segment_idx == 0 {
14911524 if name == kw:: SelfLower {
@@ -1517,19 +1550,26 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
15171550
15181551 // Report special messages for path segment keywords in wrong positions.
15191552 if ident. is_path_segment_keyword ( ) && segment_idx != 0 {
1520- return PathResult :: failed ( ident, false , finalize. is_some ( ) , module, || {
1521- let name_str = if name == kw:: PathRoot {
1522- "crate root" . to_string ( )
1523- } else {
1524- format ! ( "`{name}`" )
1525- } ;
1526- let label = if segment_idx == 1 && path[ 0 ] . ident . name == kw:: PathRoot {
1527- format ! ( "global paths cannot start with {name_str}" )
1528- } else {
1529- format ! ( "{name_str} in paths can only be used in start position" )
1530- } ;
1531- ( label, None )
1532- } ) ;
1553+ return PathResult :: failed (
1554+ ident,
1555+ false ,
1556+ finalize. is_some ( ) ,
1557+ module,
1558+ || {
1559+ let name_str = if name == kw:: PathRoot {
1560+ "crate root" . to_string ( )
1561+ } else {
1562+ format ! ( "`{name}`" )
1563+ } ;
1564+ let label = if segment_idx == 1 && path[ 0 ] . ident . name == kw:: PathRoot {
1565+ format ! ( "global paths cannot start with {name_str}" )
1566+ } else {
1567+ format ! ( "{name_str} in paths can only be used in start position" )
1568+ } ;
1569+ ( label, None )
1570+ } ,
1571+ "module" ,
1572+ ) ;
15331573 }
15341574
15351575 let binding = if let Some ( module) = module {
@@ -1625,6 +1665,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
16251665 ) ;
16261666 ( label, None )
16271667 } ,
1668+ "module" ,
16281669 ) ;
16291670 }
16301671 }
@@ -1639,18 +1680,29 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
16391680 }
16401681 }
16411682
1642- return PathResult :: failed ( ident, is_last, finalize. is_some ( ) , module, || {
1643- self . report_path_resolution_error (
1644- path,
1645- opt_ns,
1646- parent_scope,
1647- ribs,
1648- ignore_binding,
1649- module,
1650- segment_idx,
1651- ident,
1652- )
1653- } ) ;
1683+ return PathResult :: failed (
1684+ ident,
1685+ is_last,
1686+ finalize. is_some ( ) ,
1687+ module,
1688+ || {
1689+ self . report_path_resolution_error (
1690+ path,
1691+ opt_ns,
1692+ parent_scope,
1693+ ribs,
1694+ ignore_binding,
1695+ module,
1696+ segment_idx,
1697+ ident,
1698+ )
1699+ } ,
1700+ match opt_ns {
1701+ Some ( ValueNS ) if path. len ( ) == 1 => "item or value" ,
1702+ Some ( ns) if path. len ( ) - 1 == segment_idx => ns. descr ( ) ,
1703+ Some ( _) | None => "item" ,
1704+ } ,
1705+ ) ;
16541706 }
16551707 }
16561708 }
0 commit comments