File tree 3 files changed +22
-3
lines changed
3 files changed +22
-3
lines changed Original file line number Diff line number Diff line change @@ -5518,6 +5518,7 @@ impl<'a> Parser<'a> {
5518
5518
} ;
5519
5519
5520
5520
// Parse both types and traits as a type, then reinterpret if necessary.
5521
+ let ty_first_interpolated = if self . token . is_ty ( ) { Some ( self . span ) } else { None } ;
5521
5522
let ty_first = self . parse_ty ( ) ?;
5522
5523
5523
5524
// If `for` is missing we try to recover.
@@ -5547,8 +5548,16 @@ impl<'a> Parser<'a> {
5547
5548
5548
5549
let ty_first = ty_first. into_inner ( ) ;
5549
5550
let path = match ty_first. node {
5550
- // This notably includes paths passed through `ty` macro fragments (#46438).
5551
- TyKind :: Path ( None , path) => path,
5551
+ TyKind :: Path ( None , path) => {
5552
+ if let Some ( span) = ty_first_interpolated {
5553
+ self . diagnostic ( )
5554
+ . struct_span_warn ( span, "expected a trait, found type" )
5555
+ . note ( "this warning will become a hard error in a future release" )
5556
+ . span_label ( span, "try using `path` instead of `ty` \
5557
+ for this macro fragment") . emit ( ) ;
5558
+ }
5559
+ path
5560
+ }
5552
5561
_ => {
5553
5562
self . span_err ( ty_first. span , "expected a trait, found type" ) ;
5554
5563
ast:: Path :: from_ident ( ty_first. span , keywords:: Invalid . ident ( ) )
Original file line number Diff line number Diff line change @@ -315,6 +315,16 @@ impl Token {
315
315
false
316
316
}
317
317
318
+ /// Returns `true` if the token is an interpolated type.
319
+ pub fn is_ty ( & self ) -> bool {
320
+ if let Interpolated ( ref nt) = * self {
321
+ if let NtTy ( ..) = nt. 0 {
322
+ return true ;
323
+ }
324
+ }
325
+ false
326
+ }
327
+
318
328
/// Returns a lifetime with the span and a dummy id if it is a lifetime,
319
329
/// or the original lifetime if it is an interpolated lifetime, ignoring
320
330
/// the span.
Original file line number Diff line number Diff line change 10
10
11
11
macro_rules! m {
12
12
( $my_type: ty) => {
13
- impl $my_type for u8 { }
13
+ impl $my_type for u8 { } //~ WARN expected a trait, found type
14
14
}
15
15
}
16
16
You can’t perform that action at this time.
0 commit comments