@@ -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 {
@@ -2633,32 +2633,40 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
26332633 // }
26342634 // ```
26352635 Some ( LateDecl :: RibDef ( Res :: Local ( id) ) ) => {
2636- Some ( * self . pat_span_map . get ( & id) . unwrap ( ) )
2636+ Some ( ( * self . pat_span_map . get ( & id) . unwrap ( ) , "a" , "local binding" ) )
26372637 }
26382638 // Name matches item from a local name binding
26392639 // created by `use` declaration. For example:
26402640 // ```
2641- // pub Foo: &str = "";
2641+ // pub const Foo: &str = "";
26422642 //
26432643 // mod submod {
26442644 // use super::Foo;
26452645 // println!("{}", Foo::Bar); // Name refers to local
26462646 // // binding `Foo`.
26472647 // }
26482648 // ```
2649- Some ( LateDecl :: Decl ( name_binding) ) => Some ( name_binding. span ) ,
2649+ Some ( LateDecl :: Decl ( name_binding) ) => Some ( (
2650+ name_binding. span ,
2651+ name_binding. res ( ) . article ( ) ,
2652+ name_binding. res ( ) . descr ( ) ,
2653+ ) ) ,
26502654 _ => None ,
26512655 } ;
2652- let suggestion = match_span. map ( |span| {
2653- (
2654- vec ! [ ( span, String :: from( "" ) ) ] ,
2655- format ! ( "`{ident}` is defined here, but is not a type" ) ,
2656- Applicability :: MaybeIncorrect ,
2657- )
2658- } ) ;
26592656
26602657 let message = format ! ( "cannot find type `{ident}` in {scope}" ) ;
2661- ( message, format ! ( "use of undeclared type `{ident}`" ) , suggestion)
2658+ let label = if let Some ( ( span, article, descr) ) = match_span {
2659+ format ! (
2660+ "`{ident}` is declared as {article} {descr} at `{}`, not a type" ,
2661+ self . tcx
2662+ . sess
2663+ . source_map( )
2664+ . span_to_short_string( span, RemapPathScopeComponents :: DIAGNOSTICS )
2665+ )
2666+ } else {
2667+ format ! ( "use of undeclared type `{ident}`" )
2668+ } ;
2669+ ( message, label, None )
26622670 } else {
26632671 let mut suggestion = None ;
26642672 if ident. name == sym:: alloc {
0 commit comments