summaryrefslogtreecommitdiff
path: root/compiler
diff options
context:
space:
mode:
authorNilstrieb <48135649+Nilstrieb@users.noreply.github.com>2023-05-16 11:39:38 +0200
committerGitHub <noreply@github.com>2023-05-16 11:39:38 +0200
commit87a0cd9a41c535aac1c8227da06e61f73a5a7f27 (patch)
tree6d2dfbb4ef0f86fe5e26ce3c177d52fc38946b0d /compiler
parentf65281534f99754d94388e705cdc40c047093dee (diff)
parenta5763ff8d3e67c156ebe8160de1db26a644d4c5d (diff)
downloadrust-87a0cd9a41c535aac1c8227da06e61f73a5a7f27.tar.gz
Rollup merge of #111449 - compiler-errors:recover-impl-generics-correctly, r=Nilstrieb
Recover `impl<T ?Sized>` correctly Fixes #111327 r? ````@Nilstrieb```` but you can re-roll Alternatively, happy to close this if we're okay with just saying "sorry #111327 is just a poor side-effect of parser ambiguity" 🤷
Diffstat (limited to 'compiler')
-rw-r--r--compiler/rustc_parse/src/parser/generics.rs5
1 files changed, 5 insertions, 0 deletions
diff --git a/compiler/rustc_parse/src/parser/generics.rs b/compiler/rustc_parse/src/parser/generics.rs
index e6d0f9fbc76..cd779b0b43e 100644
--- a/compiler/rustc_parse/src/parser/generics.rs
+++ b/compiler/rustc_parse/src/parser/generics.rs
@@ -453,6 +453,8 @@ impl<'a> Parser<'a> {
// `<` (LIFETIME|IDENT) `:` - generic parameter with bounds
// `<` (LIFETIME|IDENT) `=` - generic parameter with a default
// `<` 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
// `<` IDENT `>` `::` IDENT ...
// 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 + 2, |t| {
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]))
}