@@ -2108,6 +2108,46 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
21082108 extend : impl Fn ( & mut DiagnosticBuilder < ' tcx , ErrorGuaranteed > ) ,
21092109 ) -> bool {
21102110 let args = segments. clone ( ) . flat_map ( |segment| segment. args ( ) . args ) ;
2111+ let types_and_spans: Vec < _ > = segments
2112+ . clone ( )
2113+ . flat_map ( |segment| {
2114+ segment. res . and_then ( |res| {
2115+ if segment. args ( ) . args . is_empty ( ) {
2116+ None
2117+ } else {
2118+ let mut desc = res. descr ( ) ;
2119+ if desc == "unresolved item" {
2120+ desc = "this type" ;
2121+ } ;
2122+
2123+ let name = match res {
2124+ Res :: PrimTy ( ty) => Some ( ty. name ( ) ) ,
2125+ Res :: Def ( _, def_id) => self . tcx ( ) . opt_item_name ( def_id) ,
2126+ _ => None ,
2127+ } ;
2128+ Some ( (
2129+ match name {
2130+ Some ( ty) => format ! ( "{desc} `{ty}`" ) ,
2131+ None => desc. to_string ( ) ,
2132+ } ,
2133+ segment. ident . span ,
2134+ ) )
2135+ }
2136+ } )
2137+ } )
2138+ . collect ( ) ;
2139+ let this_type = match & types_and_spans[ ..] {
2140+ [ .., _, ( last, _) ] => format ! (
2141+ "{} and {last}" ,
2142+ types_and_spans[ ..types_and_spans. len( ) - 1 ]
2143+ . iter( )
2144+ . map( |( x, _) | x. as_str( ) )
2145+ . intersperse( & ", " )
2146+ . collect:: <String >( )
2147+ ) ,
2148+ [ ( only, _) ] => only. to_string ( ) ,
2149+ [ ] => "this type" . to_string ( ) ,
2150+ } ;
21112151
21122152 let ( lt, ty, ct, inf) =
21132153 args. clone ( ) . fold ( ( false , false , false , false ) , |( lt, ty, ct, inf) , arg| match arg {
@@ -2143,7 +2183,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
21432183 let ( kind, s) = match types[ ..] {
21442184 [ .., _, last] => (
21452185 format ! (
2146- "{} and ` {last}` " ,
2186+ "{} and {last}" ,
21472187 types[ ..types. len( ) - 1 ]
21482188 . iter( )
21492189 . map( |& x| x)
@@ -2161,9 +2201,12 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
21612201 self . tcx( ) . sess,
21622202 span,
21632203 E0109 ,
2164- "{kind} arguments are not allowed for this type " ,
2204+ "{kind} arguments are not allowed on {this_type} " ,
21652205 ) ;
21662206 err. span_label ( last_span, format ! ( "{kind} argument{s} not allowed" ) ) ;
2207+ for ( _, span) in types_and_spans {
2208+ err. span_label ( span, "not allowed on this" ) ;
2209+ }
21672210 extend ( & mut err) ;
21682211 err. emit ( ) ;
21692212 emitted = true ;
0 commit comments