Skip to content

Commit 5d5e451

Browse files
committed
recover const Tr bounds (no ~)
1 parent 798016c commit 5d5e451

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

compiler/rustc_parse/src/parser/ty.rs

+14
Original file line numberDiff line numberDiff line change
@@ -809,6 +809,20 @@ impl<'a> Parser<'a> {
809809
self.expect_keyword(kw::Const)?;
810810
let span = tilde.to(self.prev_token.span);
811811
self.sess.gated_spans.gate(sym::const_trait_impl, span);
812+
Some(span)
813+
} else if self.eat_keyword(kw::Const) {
814+
let span = self.prev_token.span;
815+
self.sess.gated_spans.gate(sym::const_trait_impl, span);
816+
817+
self.struct_span_err(span, "const bounds must start with `~`")
818+
.span_suggestion(
819+
span.shrink_to_lo(),
820+
"add `~`",
821+
"~",
822+
Applicability::MachineApplicable,
823+
)
824+
.emit();
825+
812826
Some(span)
813827
} else {
814828
None

src/test/ui/rfc-2632-const-trait-impl/without-tilde.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,4 @@
33
#![feature(const_trait_impl)]
44

55
struct S<T: const Tr>;
6-
//~^ ERROR expected identifier, found keyword `const`
7-
//~| ERROR expected one of `(`, `+`, `,`, `::`, `<`, `=`, or `>`, found `Tr`
6+
//~^ ERROR const bounds must start with `~`
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
1-
error: expected identifier, found keyword `const`
1+
error: const bounds must start with `~`
22
--> $DIR/without-tilde.rs:5:13
33
|
44
LL | struct S<T: const Tr>;
5-
| ^^^^^ expected identifier, found keyword
5+
| -^^^^
6+
| |
7+
| help: add `~`: `~`
68

7-
error: expected one of `(`, `+`, `,`, `::`, `<`, `=`, or `>`, found `Tr`
8-
--> $DIR/without-tilde.rs:5:19
9-
|
10-
LL | struct S<T: const Tr>;
11-
| ^^ expected one of 7 possible tokens
12-
13-
error: aborting due to 2 previous errors
9+
error: aborting due to previous error
1410

0 commit comments

Comments
 (0)