mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00
Recover impl<T ?Sized>
correctly
This commit is contained in:
parent
2913ad6db0
commit
a5763ff8d3
@ -453,6 +453,8 @@ impl<'a> Parser<'a> {
|
|||||||
// `<` (LIFETIME|IDENT) `:` - generic parameter with bounds
|
// `<` (LIFETIME|IDENT) `:` - generic parameter with bounds
|
||||||
// `<` (LIFETIME|IDENT) `=` - generic parameter with a default
|
// `<` (LIFETIME|IDENT) `=` - generic parameter with a default
|
||||||
// `<` const - generic const parameter
|
// `<` const - generic const parameter
|
||||||
|
// `<` IDENT `?` - RECOVERY for `impl<T ?Bound` missing a `:`, meant to
|
||||||
|
// avoid the `T?` to `Option<T>` recovery for types.
|
||||||
// The only truly ambiguous case is
|
// The only truly ambiguous case is
|
||||||
// `<` IDENT `>` `::` IDENT ...
|
// `<` IDENT `>` `::` IDENT ...
|
||||||
// we disambiguate it in favor of generics (`impl<T> ::absolute::Path<T> { ... }`)
|
// we disambiguate it in favor of generics (`impl<T> ::absolute::Path<T> { ... }`)
|
||||||
@ -463,6 +465,9 @@ impl<'a> Parser<'a> {
|
|||||||
|| self.look_ahead(start + 1, |t| t.is_lifetime() || t.is_ident())
|
|| self.look_ahead(start + 1, |t| t.is_lifetime() || t.is_ident())
|
||||||
&& self.look_ahead(start + 2, |t| {
|
&& self.look_ahead(start + 2, |t| {
|
||||||
matches!(t.kind, token::Gt | token::Comma | token::Colon | token::Eq)
|
matches!(t.kind, token::Gt | token::Comma | token::Colon | token::Eq)
|
||||||
|
// Recovery-only branch -- this could be removed,
|
||||||
|
// since it only affects diagnostics currently.
|
||||||
|
|| matches!(t.kind, token::Question)
|
||||||
})
|
})
|
||||||
|| self.is_keyword_ahead(start + 1, &[kw::Const]))
|
|| self.is_keyword_ahead(start + 1, &[kw::Const]))
|
||||||
}
|
}
|
||||||
|
6
tests/ui/parser/impl-on-unsized-typo.rs
Normal file
6
tests/ui/parser/impl-on-unsized-typo.rs
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
trait Tr {}
|
||||||
|
|
||||||
|
impl<T ?Sized> Tr for T {}
|
||||||
|
//~^ ERROR expected one of `,`, `:`, `=`, or `>`, found `?`
|
||||||
|
|
||||||
|
fn main() {}
|
8
tests/ui/parser/impl-on-unsized-typo.stderr
Normal file
8
tests/ui/parser/impl-on-unsized-typo.stderr
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
error: expected one of `,`, `:`, `=`, or `>`, found `?`
|
||||||
|
--> $DIR/impl-on-unsized-typo.rs:3:8
|
||||||
|
|
|
||||||
|
LL | impl<T ?Sized> Tr for T {}
|
||||||
|
| ^ expected one of `,`, `:`, `=`, or `>`
|
||||||
|
|
||||||
|
error: aborting due to previous error
|
||||||
|
|
Loading…
Reference in New Issue
Block a user