@@ -2108,6 +2108,46 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
2108
2108
extend : impl Fn ( & mut DiagnosticBuilder < ' tcx , ErrorGuaranteed > ) ,
2109
2109
) -> bool {
2110
2110
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
+ } ;
2111
2151
2112
2152
let ( lt, ty, ct, inf) =
2113
2153
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 {
2143
2183
let ( kind, s) = match types[ ..] {
2144
2184
[ .., _, last] => (
2145
2185
format ! (
2146
- "{} and ` {last}` " ,
2186
+ "{} and {last}" ,
2147
2187
types[ ..types. len( ) - 1 ]
2148
2188
. iter( )
2149
2189
. map( |& x| x)
@@ -2161,9 +2201,12 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
2161
2201
self . tcx( ) . sess,
2162
2202
span,
2163
2203
E0109 ,
2164
- "{kind} arguments are not allowed for this type " ,
2204
+ "{kind} arguments are not allowed on {this_type} " ,
2165
2205
) ;
2166
2206
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
+ }
2167
2210
extend ( & mut err) ;
2168
2211
err. emit ( ) ;
2169
2212
emitted = true ;
0 commit comments