recover const Tr bounds (no ~)

This commit is contained in:
Maybe Waffle 2022-08-21 14:58:42 +04:00
parent 798016c2df
commit 5d5e451618
3 changed files with 20 additions and 11 deletions

View File

@ -809,6 +809,20 @@ impl<'a> Parser<'a> {
self.expect_keyword(kw::Const)?;
let span = tilde.to(self.prev_token.span);
self.sess.gated_spans.gate(sym::const_trait_impl, span);
Some(span)
} else if self.eat_keyword(kw::Const) {
let span = self.prev_token.span;
self.sess.gated_spans.gate(sym::const_trait_impl, span);
self.struct_span_err(span, "const bounds must start with `~`")
.span_suggestion(
span.shrink_to_lo(),
"add `~`",
"~",
Applicability::MachineApplicable,
)
.emit();
Some(span)
} else {
None

View File

@ -3,5 +3,4 @@
#![feature(const_trait_impl)]
struct S<T: const Tr>;
//~^ ERROR expected identifier, found keyword `const`
//~| ERROR expected one of `(`, `+`, `,`, `::`, `<`, `=`, or `>`, found `Tr`
//~^ ERROR const bounds must start with `~`

View File

@ -1,14 +1,10 @@
error: expected identifier, found keyword `const`
error: const bounds must start with `~`
--> $DIR/without-tilde.rs:5:13
|
LL | struct S<T: const Tr>;
| ^^^^^ expected identifier, found keyword
| -^^^^
| |
| help: add `~`: `~`
error: expected one of `(`, `+`, `,`, `::`, `<`, `=`, or `>`, found `Tr`
--> $DIR/without-tilde.rs:5:19
|
LL | struct S<T: const Tr>;
| ^^ expected one of 7 possible tokens
error: aborting due to 2 previous errors
error: aborting due to previous error