@@ -32,7 +32,7 @@ use rustc_span::edit_distance::find_best_match_for_name;
3232use rustc_span:: edition:: Edition ;
3333use rustc_span:: hygiene:: MacroKind ;
3434use rustc_span:: source_map:: { SourceMap , Spanned } ;
35- use rustc_span:: { BytePos , Ident , Span , Symbol , SyntaxContext , kw, sym} ;
35+ use rustc_span:: { BytePos , Ident , RemapPathScopeComponents , Span , Symbol , SyntaxContext , kw, sym} ;
3636use thin_vec:: { ThinVec , thin_vec} ;
3737use tracing:: { debug, instrument} ;
3838
@@ -908,7 +908,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
908908 err. help ( msg) ;
909909 return err;
910910 }
911- err. multipart_suggestion ( msg, suggestions, applicability) ;
911+ err. multipart_suggestion_verbose ( msg, suggestions, applicability) ;
912912 }
913913
914914 let module = match module {
@@ -2635,32 +2635,40 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
26352635 // }
26362636 // ```
26372637 Some ( LateDecl :: RibDef ( Res :: Local ( id) ) ) => {
2638- Some ( * self . pat_span_map . get ( & id) . unwrap ( ) )
2638+ Some ( ( * self . pat_span_map . get ( & id) . unwrap ( ) , "a" , "local binding" ) )
26392639 }
26402640 // Name matches item from a local name binding
26412641 // created by `use` declaration. For example:
26422642 // ```
2643- // pub Foo: &str = "";
2643+ // pub const Foo: &str = "";
26442644 //
26452645 // mod submod {
26462646 // use super::Foo;
26472647 // println!("{}", Foo::Bar); // Name refers to local
26482648 // // binding `Foo`.
26492649 // }
26502650 // ```
2651- Some ( LateDecl :: Decl ( name_binding) ) => Some ( name_binding. span ) ,
2651+ Some ( LateDecl :: Decl ( name_binding) ) => Some ( (
2652+ name_binding. span ,
2653+ name_binding. res ( ) . article ( ) ,
2654+ name_binding. res ( ) . descr ( ) ,
2655+ ) ) ,
26522656 _ => None ,
26532657 } ;
2654- let suggestion = match_span. map ( |span| {
2655- (
2656- vec ! [ ( span, String :: from( "" ) ) ] ,
2657- format ! ( "`{ident}` is defined here, but is not a type" ) ,
2658- Applicability :: MaybeIncorrect ,
2659- )
2660- } ) ;
26612658
26622659 let message = format ! ( "cannot find type `{ident}` in {scope}" ) ;
2663- ( message, format ! ( "use of undeclared type `{ident}`" ) , suggestion)
2660+ let label = if let Some ( ( span, article, descr) ) = match_span {
2661+ format ! (
2662+ "`{ident}` is declared as {article} {descr} at `{}`, not a type" ,
2663+ self . tcx
2664+ . sess
2665+ . source_map( )
2666+ . span_to_short_string( span, RemapPathScopeComponents :: DIAGNOSTICS )
2667+ )
2668+ } else {
2669+ format ! ( "use of undeclared type `{ident}`" )
2670+ } ;
2671+ ( message, label, None )
26642672 } else {
26652673 let mut suggestion = None ;
26662674 if ident. name == sym:: alloc {
0 commit comments