diff options
| author | bors <bors@rust-lang.org> | 2023-12-05 16:00:27 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-12-05 16:00:27 +0000 |
| commit | ec94480d9877e9c7ccf1255ab592dfc85d07ec50 (patch) | |
| tree | 305ec848dc1710e3263070be77e2f4ca0426b05a /compiler/rustc_parse/src | |
| parent | 8a7b2035f816f6d27003a9326d6bd3a3d739fcc3 (diff) | |
| parent | d367db22f6c2c801ea1f00a1dcb3fd34f102e127 (diff) | |
| download | rust-ec94480d9877e9c7ccf1255ab592dfc85d07ec50.tar.gz rust-ec94480d9877e9c7ccf1255ab592dfc85d07ec50.zip | |
Auto merge of #118646 - matthiaskrgr:rollup-jnscl9z, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - #117922 (Tweak unclosed generics errors) - #118471 (Fix typos in README.md) - #118594 (Remove mention of rust to make the error message generic.) - #118598 (Remove the `precise_pointer_size_matching` feature gate) - #118606 (Fix `x` not to quit after `x` prints `settings.json`) - #118608 (Use default params until effects in desugaring) - #118614 (Update books) - #118637 (rustc_symbol_mangling,rustc_interface,rustc_driver_impl: Enforce `rustc::potential_query_instability` lint) r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_parse/src')
| -rw-r--r-- | compiler/rustc_parse/src/parser/diagnostics.rs | 43 | ||||
| -rw-r--r-- | compiler/rustc_parse/src/parser/generics.rs | 2 |
2 files changed, 35 insertions, 10 deletions
diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs index 98e68e682ab..7ab0d3f35ea 100644 --- a/compiler/rustc_parse/src/parser/diagnostics.rs +++ b/compiler/rustc_parse/src/parser/diagnostics.rs @@ -673,15 +673,6 @@ impl<'a> Parser<'a> { ); } - // Add suggestion for a missing closing angle bracket if '>' is included in expected_tokens - // there are unclosed angle brackets - if self.unmatched_angle_bracket_count > 0 - && self.token.kind == TokenKind::Eq - && expected.iter().any(|tok| matches!(tok, TokenType::Token(TokenKind::Gt))) - { - err.span_label(self.prev_token.span, "maybe try to close unmatched angle bracket"); - } - let sp = if self.token == token::Eof { // This is EOF; don't want to point at the following char, but rather the last token. self.prev_token.span @@ -811,6 +802,7 @@ impl<'a> Parser<'a> { } err.emit(); } + fn check_too_many_raw_str_terminators(&mut self, err: &mut Diagnostic) -> bool { let sm = self.sess.source_map(); match (&self.prev_token.kind, &self.token.kind) { @@ -1986,6 +1978,39 @@ impl<'a> Parser<'a> { } } + /// When trying to close a generics list and encountering code like + /// ```text + /// impl<S: Into<std::borrow::Cow<'static, str>> From<S> for Canonical {} + /// // ^ missing > here + /// ``` + /// we provide a structured suggestion on the error from `expect_gt`. + pub(super) fn expect_gt_or_maybe_suggest_closing_generics( + &mut self, + params: &[ast::GenericParam], + ) -> PResult<'a, ()> { + let Err(mut err) = self.expect_gt() else { + return Ok(()); + }; + // Attempt to find places where a missing `>` might belong. + if let [.., ast::GenericParam { bounds, .. }] = params + && let Some(poly) = bounds + .iter() + .filter_map(|bound| match bound { + ast::GenericBound::Trait(poly, _) => Some(poly), + _ => None, + }) + .last() + { + err.span_suggestion_verbose( + poly.span.shrink_to_hi(), + "you might have meant to end the type parameters here", + ">", + Applicability::MaybeIncorrect, + ); + } + Err(err) + } + pub(super) fn recover_seq_parse_error( &mut self, delim: Delimiter, diff --git a/compiler/rustc_parse/src/parser/generics.rs b/compiler/rustc_parse/src/parser/generics.rs index 242c9d332bb..20f67b284b2 100644 --- a/compiler/rustc_parse/src/parser/generics.rs +++ b/compiler/rustc_parse/src/parser/generics.rs @@ -279,7 +279,7 @@ impl<'a> Parser<'a> { let span_lo = self.token.span; let (params, span) = if self.eat_lt() { let params = self.parse_generic_params()?; - self.expect_gt()?; + self.expect_gt_or_maybe_suggest_closing_generics(¶ms)?; (params, span_lo.to(self.prev_token.span)) } else { (ThinVec::new(), self.prev_token.span.shrink_to_hi()) |
