Skip to content

Commit

Permalink
recover const Tr bounds (no ~)
Browse files Browse the repository at this point in the history
  • Loading branch information
WaffleLapkin committed Aug 21, 2022
1 parent 798016c commit 5d5e451
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
14 changes: 14 additions & 0 deletions compiler/rustc_parse/src/parser/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions src/test/ui/rfc-2632-const-trait-impl/without-tilde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 `~`
14 changes: 5 additions & 9 deletions src/test/ui/rfc-2632-const-trait-impl/without-tilde.stderr
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 5d5e451

Please sign in to comment.