diff options
| author | bors <bors@rust-lang.org> | 2022-08-14 12:06:50 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-08-14 12:06:50 +0000 |
| commit | 4c5665583815a0f0f3e22516441efb43ea6dede2 (patch) | |
| tree | d63a94dc1432882fa5856a412d0c28d40e978cfd /compiler/rustc_parse/src/parser | |
| parent | 2fbc08e2ce64dee45a29cb6133da6b32366268aa (diff) | |
| parent | 9de9786ef84f09b367d99bcce6e59a4ed75acd64 (diff) | |
| download | rust-4c5665583815a0f0f3e22516441efb43ea6dede2.tar.gz rust-4c5665583815a0f0f3e22516441efb43ea6dede2.zip | |
Auto merge of #100525 - Dylan-DPC:rollup-4cp6nu0, r=Dylan-DPC
Rollup of 6 pull requests
Successful merges:
- #99582 (Delay a span bug if we see ty/const generic params during writeback)
- #99861 (orphan check: rationalize our handling of constants)
- #100026 (Add `Iterator::array_chunks` (take N+1))
- #100115 (Suggest removing `let` if `const let` or `let const` is used)
- #100126 (rustc_target: Update some old naming around self contained linking)
- #100487 (`assert_{inhabited,zero_valid,uninit_valid}` intrinsics are safe)
Failed merges:
r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_parse/src/parser')
| -rw-r--r-- | compiler/rustc_parse/src/parser/item.rs | 10 | ||||
| -rw-r--r-- | compiler/rustc_parse/src/parser/stmt.rs | 16 |
2 files changed, 26 insertions, 0 deletions
diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs index c6dd5e7fda3..83fab0829a1 100644 --- a/compiler/rustc_parse/src/parser/item.rs +++ b/compiler/rustc_parse/src/parser/item.rs @@ -1162,6 +1162,16 @@ impl<'a> Parser<'a> { Applicability::MaybeIncorrect, ) .emit(); + } else if self.eat_keyword(kw::Let) { + let span = self.prev_token.span; + self.struct_span_err(const_span.to(span), "`const` and `let` are mutually exclusive") + .span_suggestion( + const_span.to(span), + "remove `let`", + "const", + Applicability::MaybeIncorrect, + ) + .emit(); } } diff --git a/compiler/rustc_parse/src/parser/stmt.rs b/compiler/rustc_parse/src/parser/stmt.rs index 51bd9d2d386..6990d0782b7 100644 --- a/compiler/rustc_parse/src/parser/stmt.rs +++ b/compiler/rustc_parse/src/parser/stmt.rs @@ -247,6 +247,22 @@ impl<'a> Parser<'a> { /// Parses a local variable declaration. fn parse_local(&mut self, attrs: AttrVec) -> PResult<'a, P<Local>> { let lo = self.prev_token.span; + + if self.token.is_keyword(kw::Const) && self.look_ahead(1, |t| t.is_ident()) { + self.struct_span_err( + lo.to(self.token.span), + "`const` and `let` are mutually exclusive", + ) + .span_suggestion( + lo.to(self.token.span), + "remove `let`", + "const", + Applicability::MaybeIncorrect, + ) + .emit(); + self.bump(); + } + let (pat, colon) = self.parse_pat_before_ty(None, RecoverComma::Yes, "`let` bindings")?; let (err, ty) = if colon { |
