diff options
| author | Maybe Waffle <waffle.lapkin@gmail.com> | 2022-08-21 14:58:42 +0400 |
|---|---|---|
| committer | Maybe Waffle <waffle.lapkin@gmail.com> | 2022-08-21 14:58:42 +0400 |
| commit | 5d5e451618d3f364ce4a19d1d2c4f8903bc30dde (patch) | |
| tree | 17938856a35195a320759ed31d3ccc9f03a5e879 | |
| parent | 798016c2df3a15da739e8c6d0968ba0f7b54e303 (diff) | |
| download | rust-5d5e451618d3f364ce4a19d1d2c4f8903bc30dde.tar.gz rust-5d5e451618d3f364ce4a19d1d2c4f8903bc30dde.zip | |
recover `const Tr` bounds (no `~`)
| -rw-r--r-- | compiler/rustc_parse/src/parser/ty.rs | 14 | ||||
| -rw-r--r-- | src/test/ui/rfc-2632-const-trait-impl/without-tilde.rs | 3 | ||||
| -rw-r--r-- | src/test/ui/rfc-2632-const-trait-impl/without-tilde.stderr | 14 |
3 files changed, 20 insertions, 11 deletions
diff --git a/compiler/rustc_parse/src/parser/ty.rs b/compiler/rustc_parse/src/parser/ty.rs index b76ba8ff2d9..298198f2cf7 100644 --- a/compiler/rustc_parse/src/parser/ty.rs +++ b/compiler/rustc_parse/src/parser/ty.rs @@ -810,6 +810,20 @@ impl<'a> Parser<'a> { 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 }; diff --git a/src/test/ui/rfc-2632-const-trait-impl/without-tilde.rs b/src/test/ui/rfc-2632-const-trait-impl/without-tilde.rs index e0d3e0b497b..d63381b5f2c 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/without-tilde.rs +++ b/src/test/ui/rfc-2632-const-trait-impl/without-tilde.rs @@ -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 `~` diff --git a/src/test/ui/rfc-2632-const-trait-impl/without-tilde.stderr b/src/test/ui/rfc-2632-const-trait-impl/without-tilde.stderr index 243f0979509..31300354a57 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/without-tilde.stderr +++ b/src/test/ui/rfc-2632-const-trait-impl/without-tilde.stderr @@ -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 |
