diff options
| author | Nicholas Nethercote <n.nethercote@gmail.com> | 2023-12-18 21:09:22 +1100 |
|---|---|---|
| committer | Nicholas Nethercote <n.nethercote@gmail.com> | 2023-12-24 07:48:47 +1100 |
| commit | ec9af0d6cb6386c7be6056a71366d275d5ca3e1e (patch) | |
| tree | bc1f47d1b6ffcd24303a9572161c463408f5e0e5 /compiler/rustc_parse | |
| parent | d86a48278f7bcd069a56870a70c6376e77bd4ee5 (diff) | |
| download | rust-ec9af0d6cb6386c7be6056a71366d275d5ca3e1e.tar.gz rust-ec9af0d6cb6386c7be6056a71366d275d5ca3e1e.zip | |
Remove `Parser` methods that duplicate `DiagCtxt` methods.
Diffstat (limited to 'compiler/rustc_parse')
| -rw-r--r-- | compiler/rustc_parse/src/lexer/tokentrees.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_parse/src/parser/attr.rs | 6 | ||||
| -rw-r--r-- | compiler/rustc_parse/src/parser/diagnostics.rs | 38 | ||||
| -rw-r--r-- | compiler/rustc_parse/src/parser/expr.rs | 6 | ||||
| -rw-r--r-- | compiler/rustc_parse/src/parser/generics.rs | 4 | ||||
| -rw-r--r-- | compiler/rustc_parse/src/parser/item.rs | 22 | ||||
| -rw-r--r-- | compiler/rustc_parse/src/parser/pat.rs | 6 | ||||
| -rw-r--r-- | compiler/rustc_parse/src/parser/path.rs | 16 | ||||
| -rw-r--r-- | compiler/rustc_parse/src/parser/stmt.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_parse/src/parser/ty.rs | 11 |
10 files changed, 53 insertions, 60 deletions
diff --git a/compiler/rustc_parse/src/lexer/tokentrees.rs b/compiler/rustc_parse/src/lexer/tokentrees.rs index 2bc2789a4f7..b6cccd275ee 100644 --- a/compiler/rustc_parse/src/lexer/tokentrees.rs +++ b/compiler/rustc_parse/src/lexer/tokentrees.rs @@ -257,7 +257,7 @@ impl<'a> TokenTreesReader<'a> { // This might be the beginning of the `if`/`while` body (i.e., the end of the condition) in_cond = false; } else if maybe_andand == token::AndAnd && maybe_let.is_keyword(kw::Let) { - let mut err = parser.struct_span_err( + let mut err = parser.dcx().struct_span_err( parser.token.span, "found a `{` in the middle of a let-chain", ); diff --git a/compiler/rustc_parse/src/parser/attr.rs b/compiler/rustc_parse/src/parser/attr.rs index 53b29eccc2c..b41ee81c4e5 100644 --- a/compiler/rustc_parse/src/parser/attr.rs +++ b/compiler/rustc_parse/src/parser/attr.rs @@ -200,7 +200,7 @@ impl<'a> Parser<'a> { if let InnerAttrPolicy::Forbidden(reason) = policy { let mut diag = match reason.as_ref().copied() { Some(InnerAttrForbiddenReason::AfterOuterDocComment { prev_doc_comment_span }) => { - let mut diag = self.struct_span_err( + let mut diag = self.dcx().struct_span_err( attr_sp, fluent::parse_inner_attr_not_permitted_after_outer_doc_comment, ); @@ -209,7 +209,7 @@ impl<'a> Parser<'a> { diag } Some(InnerAttrForbiddenReason::AfterOuterAttribute { prev_outer_attr_sp }) => { - let mut diag = self.struct_span_err( + let mut diag = self.dcx().struct_span_err( attr_sp, fluent::parse_inner_attr_not_permitted_after_outer_attr, ); @@ -218,7 +218,7 @@ impl<'a> Parser<'a> { diag } Some(InnerAttrForbiddenReason::InCodeBlock) | None => { - self.struct_span_err(attr_sp, fluent::parse_inner_attr_not_permitted) + self.dcx().struct_span_err(attr_sp, fluent::parse_inner_attr_not_permitted) } }; diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs index 4d557e495d8..a5ce89a09bf 100644 --- a/compiler/rustc_parse/src/parser/diagnostics.rs +++ b/compiler/rustc_parse/src/parser/diagnostics.rs @@ -34,8 +34,8 @@ use rustc_ast::{ use rustc_ast_pretty::pprust; use rustc_data_structures::fx::FxHashSet; use rustc_errors::{ - pluralize, AddToDiagnostic, Applicability, DiagCtxt, Diagnostic, DiagnosticBuilder, - DiagnosticMessage, FatalError, MultiSpan, PResult, + pluralize, AddToDiagnostic, Applicability, DiagCtxt, Diagnostic, DiagnosticBuilder, FatalError, + PResult, }; use rustc_session::errors::ExprParenthesesNeeded; use rustc_span::source_map::Spanned; @@ -239,21 +239,7 @@ impl<'a> DerefMut for SnapshotParser<'a> { } impl<'a> Parser<'a> { - #[rustc_lint_diagnostics] - #[track_caller] - pub fn struct_span_err<S: Into<MultiSpan>>( - &self, - sp: S, - m: impl Into<DiagnosticMessage>, - ) -> DiagnosticBuilder<'a> { - self.dcx().struct_span_err(sp, m) - } - - pub fn span_bug<S: Into<MultiSpan>>(&self, sp: S, msg: impl Into<DiagnosticMessage>) -> ! { - self.dcx().span_bug(sp, msg) - } - - pub(super) fn dcx(&self) -> &'a DiagCtxt { + pub fn dcx(&self) -> &'a DiagCtxt { &self.sess.dcx } @@ -610,7 +596,7 @@ impl<'a> Parser<'a> { }; self.last_unexpected_token_span = Some(self.token.span); // FIXME: translation requires list formatting (for `expect`) - let mut err = self.struct_span_err(self.token.span, msg_exp); + let mut err = self.dcx().struct_span_err(self.token.span, msg_exp); if let TokenKind::Ident(symbol, _) = &self.prev_token.kind { if ["def", "fun", "func", "function"].contains(&symbol.as_str()) { @@ -1647,7 +1633,7 @@ impl<'a> Parser<'a> { kind: IncDecRecovery, op_span: Span, ) -> PResult<'a, P<Expr>> { - let mut err = self.struct_span_err( + let mut err = self.dcx().struct_span_err( op_span, format!("Rust has no {} {} operator", kind.fixity, kind.op.name()), ); @@ -1843,7 +1829,7 @@ impl<'a> Parser<'a> { _ => this_token_str, }, ); - let mut err = self.struct_span_err(sp, msg); + let mut err = self.dcx().struct_span_err(sp, msg); let label_exp = format!("expected `{token_str}`"); let sm = self.sess.source_map(); if !sm.is_multiline(prev_sp.until(sp)) { @@ -1978,7 +1964,7 @@ impl<'a> Parser<'a> { self.consume_block(Delimiter::Parenthesis, ConsumeClosingDelim::No); //eat the block let hi = self.token.span; self.bump(); //remove ) - let mut err = self.struct_span_err(lo.to(hi), "use of deprecated `try` macro"); + let mut err = self.dcx().struct_span_err(lo.to(hi), "use of deprecated `try` macro"); err.note("in the 2018 edition `try` is a reserved keyword, and the `try!()` macro is deprecated"); let prefix = if is_empty { "" } else { "alternatively, " }; if !is_empty { @@ -2328,7 +2314,7 @@ impl<'a> Parser<'a> { format!("expected expression, found {}", super::token_descr(&self.token)), ), }; - let mut err = self.struct_span_err(span, msg); + let mut err = self.dcx().struct_span_err(span, msg); let sp = self.sess.source_map().start_point(self.token.span); if let Some(sp) = self.sess.ambiguous_block_expr_parse.borrow().get(&sp) { err.subdiagnostic(ExprParenthesesNeeded::surrounding(*sp)); @@ -2450,7 +2436,7 @@ impl<'a> Parser<'a> { // We are causing this error here exclusively in case that a `const` expression // could be recovered from the current parser state, even if followed by more // arguments after a comma. - let mut err = self.struct_span_err( + let mut err = self.dcx().struct_span_err( self.token.span, format!("expected one of `,` or `>`, found {}", super::token_descr(&self.token)), ); @@ -2840,7 +2826,7 @@ impl<'a> Parser<'a> { let label = self.eat_label().expect("just checked if a label exists"); self.bump(); // eat `:` let span = label.ident.span.to(self.prev_token.span); - let mut err = self.struct_span_err(span, "block label not supported here"); + let mut err = self.dcx().struct_span_err(span, "block label not supported here"); err.span_label(span, "not supported here"); err.tool_only_span_suggestion( label.ident.span.until(self.token.span), @@ -2875,7 +2861,7 @@ impl<'a> Parser<'a> { err.cancel(); } let seq_span = lo.to(self.prev_token.span); - let mut err = self.struct_span_err(comma_span, "unexpected `,` in pattern"); + let mut err = self.dcx().struct_span_err(comma_span, "unexpected `,` in pattern"); if let Ok(seq_snippet) = self.span_to_snippet(seq_span) { err.multipart_suggestion( format!( @@ -2970,7 +2956,7 @@ impl<'a> Parser<'a> { } self.bump(); } - let mut err = self.struct_span_err(spans, "encountered diff marker"); + let mut err = self.dcx().struct_span_err(spans, "encountered diff marker"); err.span_label(start, "after this is the code before the merge"); if let Some(middle) = middlediff3 { err.span_label(middle, ""); diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index a6783eaf8d4..1017a5d02da 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -370,7 +370,7 @@ impl<'a> Parser<'a> { self.mk_expr(span, aopexpr) } AssocOp::As | AssocOp::DotDot | AssocOp::DotDotEq => { - self.span_bug(span, "AssocOp should have been handled by special case") + self.dcx().span_bug(span, "AssocOp should have been handled by special case") } }; @@ -857,7 +857,7 @@ impl<'a> Parser<'a> { _ => unreachable!("parse_dot_or_call_expr_with_ shouldn't produce this"), } ); - let mut err = self.struct_span_err(span, msg); + let mut err = self.dcx().struct_span_err(span, msg); let suggest_parens = |err: &mut Diagnostic| { let suggestions = vec