diff options
| author | bors <bors@rust-lang.org> | 2023-12-18 06:03:53 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-12-18 06:03:53 +0000 |
| commit | cda4736f1eaad8af6f49388baa9b7e480df8e329 (patch) | |
| tree | 42a50495ab069a1198ed0b43bb5c417ec42ff02d /compiler/rustc_parse/src/parser | |
| parent | 8681e077b8afa99d60acf8f8470a012a3ce709a5 (diff) | |
| parent | 1e831e38ce8ba6fc93338247a7963b3a6b33e542 (diff) | |
| download | rust-cda4736f1eaad8af6f49388baa9b7e480df8e329.tar.gz rust-cda4736f1eaad8af6f49388baa9b7e480df8e329.zip | |
Auto merge of #119063 - nnethercote:dcx, r=compiler-errors
Consistent `Handler` naming This PR implements the renaming described in https://github.com/rust-lang/compiler-team/issues/699. r? `@compiler-errors`
Diffstat (limited to 'compiler/rustc_parse/src/parser')
| -rw-r--r-- | compiler/rustc_parse/src/parser/attr.rs | 4 | ||||
| -rw-r--r-- | compiler/rustc_parse/src/parser/attr_wrapper.rs | 5 | ||||
| -rw-r--r-- | compiler/rustc_parse/src/parser/diagnostics.rs | 26 | ||||
| -rw-r--r-- | compiler/rustc_parse/src/parser/expr.rs | 24 | ||||
| -rw-r--r-- | compiler/rustc_parse/src/parser/item.rs | 14 | ||||
| -rw-r--r-- | compiler/rustc_parse/src/parser/mod.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_parse/src/parser/nonterminal.rs | 11 | ||||
| -rw-r--r-- | compiler/rustc_parse/src/parser/pat.rs | 4 | ||||
| -rw-r--r-- | compiler/rustc_parse/src/parser/path.rs | 4 |
9 files changed, 46 insertions, 48 deletions
diff --git a/compiler/rustc_parse/src/parser/attr.rs b/compiler/rustc_parse/src/parser/attr.rs index c9ce896b868..56e52baf98b 100644 --- a/compiler/rustc_parse/src/parser/attr.rs +++ b/compiler/rustc_parse/src/parser/attr.rs @@ -55,7 +55,7 @@ impl<'a> Parser<'a> { } else if let token::DocComment(comment_kind, attr_style, data) = self.token.kind { if attr_style != ast::AttrStyle::Outer { let span = self.token.span; - let mut err = self.diagnostic().struct_span_err_with_code( + let mut err = self.dcx().struct_span_err_with_code( span, fluent::parse_inner_doc_comment_not_permitted, error_code!(E0753), @@ -417,7 +417,7 @@ impl<'a> Parser<'a> { } Err(InvalidMetaItem { span: self.token.span, token: self.token.clone() } - .into_diagnostic(self.diagnostic())) + .into_diagnostic(self.dcx())) } } diff --git a/compiler/rustc_parse/src/parser/attr_wrapper.rs b/compiler/rustc_parse/src/parser/attr_wrapper.rs index 5e8447030f1..2307f4cfffa 100644 --- a/compiler/rustc_parse/src/parser/attr_wrapper.rs +++ b/compiler/rustc_parse/src/parser/attr_wrapper.rs @@ -41,7 +41,7 @@ impl AttrWrapper { } pub(crate) fn take_for_recovery(self, sess: &ParseSess) -> AttrVec { - sess.span_diagnostic.span_delayed_bug( + sess.dcx.span_delayed_bug( self.attrs.get(0).map(|attr| attr.span).unwrap_or(DUMMY_SP), "AttrVec is taken for recovery but no error is produced", ); @@ -266,8 +266,7 @@ impl<'a> Parser<'a> { if let Some(attr_range) = self.capture_state.inner_attr_ranges.remove(&inner_attr.id) { inner_attr_replace_ranges.push(attr_range); } else { - self.diagnostic() - .span_delayed_bug(inner_attr.span, "Missing token range for attribute"); + self.dcx().span_delayed_bug(inner_attr.span, "Missing token range for attribute"); } } diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs index 221fc70d9ff..9e3637ea9f3 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, Diagnostic, DiagnosticBuilder, DiagnosticMessage, - ErrorGuaranteed, FatalError, Handler, IntoDiagnostic, MultiSpan, PResult, + pluralize, AddToDiagnostic, Applicability, DiagCtxt, Diagnostic, DiagnosticBuilder, + DiagnosticMessage, ErrorGuaranteed, FatalError, IntoDiagnostic, MultiSpan, PResult, }; use rustc_session::errors::ExprParenthesesNeeded; use rustc_span::source_map::Spanned; @@ -246,15 +246,15 @@ impl<'a> Parser<'a> { sp: S, m: impl Into<DiagnosticMessage>, ) -> DiagnosticBuilder<'a, ErrorGuaranteed> { - self.diagnostic().struct_span_err(sp, m) + self.dcx().struct_span_err(sp, m) } pub fn span_bug<S: Into<MultiSpan>>(&self, sp: S, msg: impl Into<DiagnosticMessage>) -> ! { - self.diagnostic().span_bug(sp, msg) + self.dcx().span_bug(sp, msg) } - pub(super) fn diagnostic(&self) -> &'a Handler { - &self.sess.span_diagnostic + pub(super) fn dcx(&self) -> &'a DiagCtxt { + &self.sess.dcx } /// Replace `self` with `snapshot.parser`. @@ -284,7 +284,7 @@ impl<'a> Parser<'a> { span: self.prev_token.span, missing_comma: None, } - .into_diagnostic(self.diagnostic())); + .into_diagnostic(self.dcx())); } let valid_follow = &[ @@ -347,7 +347,7 @@ impl<'a> Parser<'a> { suggest_remove_comma, help_cannot_start_number, }; - let mut err = err.into_diagnostic(self.diagnostic()); + let mut err = err.into_diagnostic(self.dcx()); // if the token we have is a `<` // it *might* be a misplaced generic @@ -1410,7 +1410,7 @@ impl<'a> Parser<'a> { // Not entirely sure now, but we bubble the error up with the // suggestion. self.restore_snapshot(snapshot); - Err(err.into_diagnostic(self.diagnostic())) + Err(err.into_diagnostic(self.dcx())) } } } else if token::OpenDelim(Delimiter::Parenthesis) == self.token.kind { @@ -1425,7 +1425,7 @@ impl<'a> Parser<'a> { } // Consume the fn call arguments. match self.consume_fn_args() { - Err(()) => Err(err.into_diagnostic(self.diagnostic())), + Err(()) => Err(err.into_diagnostic(self.dcx())), Ok(()) => { self.sess.emit_err(err); // FIXME: actually check that the two expressions in the binop are @@ -1451,7 +1451,7 @@ impl<'a> Parser<'a> { mk_err_expr(self, inner_op.span.to(self.prev_token.span)) } else { // These cases cause too many knock-down errors, bail out (#61329). - Err(err.into_diagnostic(self.diagnostic())) + Err(err.into_diagnostic(self.dcx())) } }; } @@ -2539,7 +2539,7 @@ impl<'a> Parser<'a> { Ok(Some(GenericArg::Const(self.parse_const_arg()?))) } else { let after_kw_const = self.token.span; - self.recover_const_arg(after_kw_const, err.into_diagnostic(self.diagnostic())).map(Some) + self.recover_const_arg(after_kw_const, err.into_diagnostic(self.dcx())).map(Some) } } @@ -2897,7 +2897,7 @@ impl<'a> Parser<'a> { span: path.span.shrink_to_hi(), between: between_span, } - .into_diagnostic(self.diagnostic())); + .into_diagnostic(self.dcx())); } } } diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index 509cef9826b..cd3e8b92f2f 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -1269,7 +1269,7 @@ impl<'a> Parser<'a> { .collect(), }, } - .into_diagnostic(self.diagnostic()); + .into_diagnostic(self.dcx()); replacement_err.emit(); let old_err = mem::replace(err, replacement_err); @@ -1693,8 +1693,7 @@ impl<'a> Parser<'a> { mk_lit_char: impl FnOnce(Symbol, Span) -> L, err: impl FnOnce(&Self) -> DiagnosticBuilder<'a, ErrorGuaranteed>, ) -> L { - if let Some(mut diag) = - self.diagnostic().steal_diagnostic(lifetime.span, StashKey::LifetimeIsChar) + if let Some(mut diag) = self.dcx().steal_diagnostic(lifetime.span, StashKey::LifetimeIsChar) { diag.span_suggestion_verbose( lifetime.span.shrink_to_hi(), @@ -1884,8 +1883,8 @@ impl<'a> Parser<'a> { self.bump(); // `#` let Some((ident, false)) = self.token.ident() else { - let err = errors::ExpectedBuiltinIdent { span: self.token.span } - .into_diagnostic(self.diagnostic()); + let err = + errors::ExpectedBuiltinIdent { span: self.token.span }.into_diagnostic(self.dcx()); return Err(err); }; self.sess.gated_spans.gate(sym::builtin_syntax, ident.span); @@ -1896,7 +1895,7 @@ impl<'a> Parser<'a> { Ok(res) } else { let err = errors::UnknownBuiltinConstruct { span: lo.to(ident.span), name: ident.name } - .into_diagnostic(self.diagnostic()); + .into_diagnostic(self.dcx()); return Err(err); }; self.expect(&TokenKind::CloseDelim(Delimiter::Parenthesis))?; @@ -1960,7 +1959,7 @@ impl<'a> Parser<'a> { && matches!(e.kind, ExprKind::Err) { let mut err = errors::InvalidInterpolatedExpression { span: self.token.span } - .into_diagnostic(self.diagnostic()); + .into_diagnostic(self.dcx()); err.downgrade_to_delayed_bug(); return Err(err); } @@ -2172,7 +2171,7 @@ impl<'a> Parser<'a> { return Err(errors::MissingSemicolonBeforeArray { open_delim: open_delim_span, semicolon: prev_span.shrink_to_hi(), - }.into_diagnostic(self.diagnostic())); + }.into_diagnostic(self.dcx())); } Ok(_) => (), Err(err) => err.cancel(), @@ -2320,7 +2319,7 @@ impl<'a> Parser<'a> { if self.check_keyword(kw::Async) { let move_async_span = self.token.span.with_lo(self.prev_token.span.data().lo); Err(errors::AsyncMoveOrderIncorrect { span: move_async_span } - .into_diagnostic(self.diagnostic())) + .into_diagnostic(self.dcx())) } else { Ok(CaptureBy::Value { move_kw: move_kw_span }) } @@ -2510,7 +2509,7 @@ impl<'a> Parser<'a> { }; if self.prev_token.kind == token::BinOp(token::Or) { // This was part of a closure, the that part of the parser recover. - return Err(err.into_diagnostic(self.diagnostic())); + return Err(err.into_diagnostic(self.dcx())); } else { Some(self.sess.emit_err(err)) } @@ -3194,8 +3193,7 @@ impl<'a> Parser<'a> { fn parse_try_block(&mut self, span_lo: Span) -> PResult<'a, P<Expr>> { let (attrs, body) = self.parse_inner_attrs_and_block()?; if self.eat_keyword(kw::Catch) { - Err(errors::CatchAfterTry { span: self.prev_token.span } - .into_diagnostic(self.diagnostic())) + Err(errors::CatchAfterTry { span: self.prev_token.span }.into_diagnostic(self.dcx())) } else { let span = span_lo.to(body.span); self.sess.gated_spans.gate(sym::try_blocks, span); @@ -3537,7 +3535,7 @@ impl<'a> Parser<'a> { ident_span: this.token.span, token: this.look_ahead(1, |t| t.clone()), } - .into_diagnostic(&self.sess.span_diagnostic)); + .into_diagnostic(&self.sess.dcx)); } let (ident, expr) = if is_shorthand { // Mimic `x: x` for the `x` field shorthand. diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs index fd7dad36c9d..bf619daba50 100644 --- a/compiler/rustc_parse/src/parser/item.rs +++ b/compiler/rustc_parse/src/parser/item.rs @@ -438,7 +438,7 @@ impl<'a> Parser<'a> { None }; - if let Some(err) = err { Err(err.into_diagnostic(self.diagnostic())) } else { Ok(()) } + if let Some(err) = err { Err(err.into_diagnostic(self.dcx())) } else { Ok(()) } } fn parse_item_builtin(&mut self) -> PResult<'a, Option<ItemInfo>> { @@ -759,7 +759,7 @@ impl<'a> Parser<'a> { if self.look_ahead(1, |tok| tok == &token::CloseDelim(Delimiter::Brace)) { // FIXME: merge with `DocCommentDoesNotDocumentAnything` (E0585) struct_span_err!( - self.diagnostic(), + self.dcx(), self.token.span, E0584, "found a documentation comment that doesn't document anything", @@ -1374,7 +1374,7 @@ impl<'a> Parser<'a> { let span = self.prev_token.span.shrink_to_hi(); let err: DiagnosticBuilder<'_, ErrorGuaranteed> = - errors::MissingConstType { span, colon, kind }.into_diagnostic(self.diagnostic()); + errors::MissingConstType { span, colon, kind }.into_diagnostic(self.dcx()); err.stash(span, StashKey::ItemNoType); // The user intended that the type be inferred, @@ -1391,7 +1391,7 @@ impl<'a> Parser<'a> { self.bump(); self.sess.emit_err(err); } else { - return Err(err.into_diagnostic(self.diagnostic())); + return Err(err.into_diagnostic(self.dcx())); } } @@ -1591,7 +1591,7 @@ impl<'a> Parser<'a> { } else { let err = errors::UnexpectedTokenAfterStructName::new(self.token.span, self.token.clone()); - return Err(err.into_diagnostic(self.diagnostic())); + return Err(err.into_diagnostic(self.dcx())); }; Ok((class_name, ItemKind::Struct(vdata, generics))) @@ -1787,7 +1787,7 @@ impl<'a> Parser<'a> { let sp = previous_span.shrink_to_hi(); err.missing_comma = Some(sp); } - return Err(err.into_diagnostic(self.diagnostic())); + return Err(err.into_diagnostic(self.dcx())); } } _ => { @@ -1837,7 +1837,7 @@ impl<'a> Parser<'a> { // Make sure an error was emitted (either by recovering an angle bracket, // or by finding an identifier as the next token), since we're // going to continue parsing - assert!(self.diagnostic().has_errors().is_some()); + assert!(self.dcx().has_errors().is_some()); } else { return Err(err); } diff --git a/compiler/rustc_parse/src/parser/mod.rs b/compiler/rustc_parse/src/parser/mod.rs index 2baedb2766f..b91432f10c8 100644 --- a/compiler/rustc_parse/src/parser/mod.rs +++ b/compiler/rustc_parse/src/parser/mod.rs @@ -1507,7 +1507,7 @@ pub(crate) fn make_unclosed_delims_error( opening_candidate: unmatched.candidate_span, unclosed: unmatched.unclosed_span, } - .into_diagnostic(&sess.span_diagnostic); + .into_diagnostic(&sess.dcx); Some(err) } diff --git a/compiler/rustc_parse/src/parser/nonterminal.rs b/compiler/rustc_parse/src/parser/nonterminal.rs index 4360a69e501..301a88cd077 100644 --- a/compiler/rustc_parse/src/parser/nonterminal.rs +++ b/compiler/rustc_parse/src/parser/nonterminal.rs @@ -114,8 +114,9 @@ impl<'a> Parser<'a> { NonterminalKind::Item => match self.parse_item(ForceCollect::Yes)? { Some(item) => NtItem(item), None => { - return Err(UnexpectedNonterminal::Item(self.token.span) - .into_diagnostic(self.diagnostic())); + return Err( + UnexpectedNonterminal::Item(self.token.span).into_diagnostic(self.dcx()) + ); } }, NonterminalKind::Block => { @@ -127,7 +128,7 @@ impl<'a> Parser<'a> { Some(s) => NtStmt(P(s)), None => { return Err(UnexpectedNonterminal::Statement(self.token.span) - .into_diagnostic(self.diagnostic())); + .into_diagnostic(self.dcx())); } }, NonterminalKind::PatParam { .. } | NonterminalKind::PatWithOr => { @@ -163,7 +164,7 @@ impl<'a> Parser<'a> { span: self.token.span, token: self.token.clone(), } - .into_diagnostic(self.diagnostic())); + .into_diagnostic(self.dcx())); } NonterminalKind::Path => { NtPath(P(self.collect_tokens_no_attrs(|this| this.parse_path(PathStyle::Type))?)) @@ -181,7 +182,7 @@ impl<'a> Parser<'a> { span: self.token.span, token: self.token.clone(), } - .into_diagnostic(self.diagnostic())); + .into_diagnostic(self.dcx())); } } }; diff --git a/compiler/rustc_parse/src/parser/pat.rs b/compiler/rustc_parse/src/parser/pat.rs index 020b66a985a..80233eddb9b 100644 --- a/compiler/rustc_parse/src/parser/pat.rs +++ b/compiler/rustc_parse/src/parser/pat.rs @@ -873,7 +873,7 @@ impl<'a> Parser<'a> { // will direct us over to `parse_enum_variant()`. if self.token == token::OpenDelim(Delimiter::Parenthesis) { return Err(EnumPatternInsteadOfIdentifier { span: self.prev_token.span } - .into_diagnostic(self.diagnostic())); + .into_diagnostic(self.dcx())); } Ok(PatKind::Ident(binding_annotation, ident, sub)) @@ -987,7 +987,7 @@ impl<'a> Parser<'a> { // check that a comma comes after every field if !ate_comma { let mut err = ExpectedCommaAfterPatternField { span: self.token.span } - .into_diagnostic(self.diagnostic()); + .into_diagnostic(self.dcx()); if let Some(mut delayed) = delayed_err { delayed.emit(); } diff --git a/compiler/rustc_parse/src/parser/path.rs b/compiler/rustc_parse/src/parser/path.rs index 0f4ba9617c6..3b92a911983 100644 --- a/compiler/rustc_parse/src/parser/path.rs +++ b/compiler/rustc_parse/src/parser/path.rs @@ -123,7 +123,7 @@ impl<'a> Parser<'a> { self.bump(); // colon - self.diagnostic() + self.dcx() .struct_span_err( self.prev_token.span, "found single colon before projection in qualified path", @@ -326,7 +326,7 @@ impl<'a> Parser<'a> { .is_nightly_build() .then_some(()), } - .into_diagnostic(self.diagnostic()); + .into_diagnostic(self.dcx()); } // Attempt to find places where a missing `>` might belong. else if let Some(arg) = args |
