From 899cb40809a85eb9d89f6da3268713b83175360a Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Fri, 23 Feb 2024 10:20:45 +1100 Subject: Rename `DiagnosticBuilder` as `Diag`. Much better! Note that this involves renaming (and updating the value of) `DIAGNOSTIC_BUILDER` in clippy. --- compiler/rustc_parse/src/errors.rs | 14 +++++----- compiler/rustc_parse/src/lexer/diagnostics.rs | 9 ++---- compiler/rustc_parse/src/lexer/mod.rs | 4 +-- compiler/rustc_parse/src/lib.rs | 11 ++++---- compiler/rustc_parse/src/parser/attr.rs | 4 +-- compiler/rustc_parse/src/parser/diagnostics.rs | 38 ++++++++++---------------- compiler/rustc_parse/src/parser/expr.rs | 8 +++--- compiler/rustc_parse/src/parser/mod.rs | 6 ++-- compiler/rustc_parse/src/parser/pat.rs | 12 +++----- compiler/rustc_parse/src/parser/stmt.rs | 7 ++--- 10 files changed, 47 insertions(+), 66 deletions(-) (limited to 'compiler/rustc_parse') diff --git a/compiler/rustc_parse/src/errors.rs b/compiler/rustc_parse/src/errors.rs index 2c76e55a46d..6c506a8efe0 100644 --- a/compiler/rustc_parse/src/errors.rs +++ b/compiler/rustc_parse/src/errors.rs @@ -3,8 +3,8 @@ use std::borrow::Cow; use rustc_ast::token::Token; use rustc_ast::{Path, Visibility}; use rustc_errors::{ - codes::*, AddToDiagnostic, Applicability, DiagCtxt, DiagnosticBuilder, EmissionGuarantee, - IntoDiagnostic, Level, SubdiagnosticMessageOp, + codes::*, AddToDiagnostic, Applicability, Diag, DiagCtxt, EmissionGuarantee, IntoDiagnostic, + Level, SubdiagnosticMessageOp, }; use rustc_macros::{Diagnostic, Subdiagnostic}; use rustc_session::errors::ExprParenthesesNeeded; @@ -1075,10 +1075,10 @@ pub(crate) struct ExpectedIdentifier { impl<'a, G: EmissionGuarantee> IntoDiagnostic<'a, G> for ExpectedIdentifier { #[track_caller] - fn into_diagnostic(self, dcx: &'a DiagCtxt, level: Level) -> DiagnosticBuilder<'a, G> { + fn into_diagnostic(self, dcx: &'a DiagCtxt, level: Level) -> Diag<'a, G> { let token_descr = TokenDescription::from_token(&self.token); - let mut diag = DiagnosticBuilder::new( + let mut diag = Diag::new( dcx, level, match token_descr { @@ -1135,10 +1135,10 @@ pub(crate) struct ExpectedSemi { impl<'a, G: EmissionGuarantee> IntoDiagnostic<'a, G> for ExpectedSemi { #[track_caller] - fn into_diagnostic(self, dcx: &'a DiagCtxt, level: Level) -> DiagnosticBuilder<'a, G> { + fn into_diagnostic(self, dcx: &'a DiagCtxt, level: Level) -> Diag<'a, G> { let token_descr = TokenDescription::from_token(&self.token); - let mut diag = DiagnosticBuilder::new( + let mut diag = Diag::new( dcx, level, match token_descr { @@ -1477,7 +1477,7 @@ pub(crate) struct FnTraitMissingParen { impl AddToDiagnostic for FnTraitMissingParen { fn add_to_diagnostic_with>( self, - diag: &mut DiagnosticBuilder<'_, G>, + diag: &mut Diag<'_, G>, _: F, ) { diag.span_label(self.span, crate::fluent_generated::parse_fn_trait_missing_paren); diff --git a/compiler/rustc_parse/src/lexer/diagnostics.rs b/compiler/rustc_parse/src/lexer/diagnostics.rs index 52a029b20f6..993ff1b97f5 100644 --- a/compiler/rustc_parse/src/lexer/diagnostics.rs +++ b/compiler/rustc_parse/src/lexer/diagnostics.rs @@ -1,6 +1,6 @@ use super::UnmatchedDelim; use rustc_ast::token::Delimiter; -use rustc_errors::DiagnosticBuilder; +use rustc_errors::Diag; use rustc_span::source_map::SourceMap; use rustc_span::Span; @@ -30,10 +30,7 @@ pub fn same_indentation_level(sm: &SourceMap, open_sp: Span, close_sp: Span) -> // When we get a `)` or `]` for `{`, we should emit help message here // it's more friendly compared to report `unmatched error` in later phase -pub fn report_missing_open_delim( - err: &mut DiagnosticBuilder<'_>, - unmatched_delims: &[UnmatchedDelim], -) -> bool { +pub fn report_missing_open_delim(err: &mut Diag<'_>, unmatched_delims: &[UnmatchedDelim]) -> bool { let mut reported_missing_open = false; for unmatch_brace in unmatched_delims.iter() { if let Some(delim) = unmatch_brace.found_delim @@ -55,7 +52,7 @@ pub fn report_missing_open_delim( } pub fn report_suspicious_mismatch_block( - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, diag_info: &TokenTreeDiagInfo, sm: &SourceMap, delim: Delimiter, diff --git a/compiler/rustc_parse/src/lexer/mod.rs b/compiler/rustc_parse/src/lexer/mod.rs index dc9f5bad765..e728575ab2d 100644 --- a/compiler/rustc_parse/src/lexer/mod.rs +++ b/compiler/rustc_parse/src/lexer/mod.rs @@ -7,7 +7,7 @@ use rustc_ast::ast::{self, AttrStyle}; use rustc_ast::token::{self, CommentKind, Delimiter, IdentIsRaw, Token, TokenKind}; use rustc_ast::tokenstream::TokenStream; use rustc_ast::util::unicode::contains_text_flow_control_chars; -use rustc_errors::{codes::*, Applicability, DiagCtxt, DiagnosticBuilder, StashKey}; +use rustc_errors::{codes::*, Applicability, Diag, DiagCtxt, StashKey}; use rustc_lexer::unescape::{self, EscapeError, Mode}; use rustc_lexer::{Base, DocStyle, RawStrError}; use rustc_lexer::{Cursor, LiteralKind}; @@ -47,7 +47,7 @@ pub(crate) fn parse_token_trees<'sess, 'src>( mut src: &'src str, mut start_pos: BytePos, override_span: Option, -) -> Result>> { +) -> Result>> { // Skip `#!`, if present. if let Some(shebang_len) = rustc_lexer::strip_shebang(src) { src = &src[shebang_len..]; diff --git a/compiler/rustc_parse/src/lib.rs b/compiler/rustc_parse/src/lib.rs index 5bd8bb72bd6..53bcb35101e 100644 --- a/compiler/rustc_parse/src/lib.rs +++ b/compiler/rustc_parse/src/lib.rs @@ -18,7 +18,7 @@ use rustc_ast::tokenstream::TokenStream; use rustc_ast::{AttrItem, Attribute, MetaItem}; use rustc_ast_pretty::pprust; use rustc_data_structures::sync::Lrc; -use rustc_errors::{DiagnosticBuilder, FatalError, PResult}; +use rustc_errors::{Diag, FatalError, PResult}; use rustc_session::parse::ParseSess; use rustc_span::{FileName, SourceFile, Span}; @@ -41,8 +41,7 @@ rustc_fluent_macro::fluent_messages! { "../messages.ftl" } // uses a HOF to parse anything, and includes file and // `source_str`. -/// A variant of 'panictry!' that works on a `Vec` instead of a single -/// `DiagnosticBuilder`. +/// A variant of 'panictry!' that works on a `Vec` instead of a single `Diag`. macro_rules! panictry_buffer { ($e:expr) => {{ use std::result::Result::{Err, Ok}; @@ -108,7 +107,7 @@ pub fn maybe_new_parser_from_source_str( sess: &ParseSess, name: FileName, source: String, -) -> Result, Vec>> { +) -> Result, Vec>> { maybe_source_file_to_parser(sess, sess.source_map().new_source_file(name, source)) } @@ -132,7 +131,7 @@ pub fn new_parser_from_file<'a>(sess: &'a ParseSess, path: &Path, sp: Option, -) -> Result, Vec>> { +) -> Result, Vec>> { let end_pos = source_file.end_position(); let stream = maybe_file_to_stream(sess, source_file, None)?; let mut parser = stream_to_parser(sess, stream, None); @@ -160,7 +159,7 @@ fn maybe_file_to_stream<'sess>( sess: &'sess ParseSess, source_file: Lrc, override_span: Option, -) -> Result>> { +) -> Result>> { let src = source_file.src.as_ref().unwrap_or_else(|| { sess.dcx.bug(format!( "cannot lex `source_file` without source: {}", diff --git a/compiler/rustc_parse/src/parser/attr.rs b/compiler/rustc_parse/src/parser/attr.rs index 6545429b95b..685af6546f5 100644 --- a/compiler/rustc_parse/src/parser/attr.rs +++ b/compiler/rustc_parse/src/parser/attr.rs @@ -8,7 +8,7 @@ use super::{AttrWrapper, Capturing, FnParseMode, ForceCollect, Parser, PathStyle use rustc_ast as ast; use rustc_ast::attr; use rustc_ast::token::{self, Delimiter, Nonterminal}; -use rustc_errors::{codes::*, DiagnosticBuilder, PResult}; +use rustc_errors::{codes::*, Diag, PResult}; use rustc_span::{sym, BytePos, Span}; use thin_vec::ThinVec; use tracing::debug; @@ -141,7 +141,7 @@ impl<'a> Parser<'a> { fn annotate_following_item_if_applicable( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, span: Span, attr_type: OuterAttributeType, ) -> Option { diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs index 995e140b329..2a8cb74337b 100644 --- a/compiler/rustc_parse/src/parser/diagnostics.rs +++ b/compiler/rustc_parse/src/parser/diagnostics.rs @@ -36,8 +36,8 @@ use rustc_ast::{ use rustc_ast_pretty::pprust; use rustc_data_structures::fx::FxHashSet; use rustc_errors::{ - pluralize, AddToDiagnostic, Applicability, DiagCtxt, DiagnosticBuilder, ErrorGuaranteed, - FatalError, PErr, PResult, + pluralize, AddToDiagnostic, Applicability, Diag, DiagCtxt, ErrorGuaranteed, FatalError, PErr, + PResult, }; use rustc_session::errors::ExprParenthesesNeeded; use rustc_span::source_map::Spanned; @@ -210,11 +210,11 @@ struct MultiSugg { } impl MultiSugg { - fn emit(self, err: &mut DiagnosticBuilder<'_>) { + fn emit(self, err: &mut Diag<'_>) { err.multipart_suggestion(self.msg, self.patches, self.applicability); } - fn emit_verbose(self, err: &mut DiagnosticBuilder<'_>) { + fn emit_verbose(self, err: &mut Diag<'_>) { err.multipart_suggestion_verbose(self.msg, self.patches, self.applicability); } } @@ -401,7 +401,7 @@ impl<'a> Parser<'a> { } } - pub(super) fn expected_ident_found_err(&mut self) -> DiagnosticBuilder<'a> { + pub(super) fn expected_ident_found_err(&mut self) -> Diag<'a> { self.expected_ident_found(false).unwrap_err() } @@ -849,7 +849,7 @@ impl<'a> Parser<'a> { err.emit() } - fn check_too_many_raw_str_terminators(&mut self, err: &mut DiagnosticBuilder<'_>) -> bool { + fn check_too_many_raw_str_terminators(&mut self, err: &mut Diag<'_>) -> bool { let sm = self.sess.source_map(); match (&self.prev_token.kind, &self.token.kind) { ( @@ -983,7 +983,7 @@ impl<'a> Parser<'a> { pub(super) fn recover_closure_body( &mut self, - mut err: DiagnosticBuilder<'a>, + mut err: Diag<'a>, before: token::Token, prev: token::Token, token: token::Token, @@ -1214,7 +1214,7 @@ impl<'a> Parser<'a> { /// encounter a parse error when encountering the first `,`. pub(super) fn check_mistyped_turbofish_with_multiple_type_params( &mut self, - mut e: DiagnosticBuilder<'a>, + mut e: Diag<'a>, expr: &mut P, ) -> PResult<'a, ErrorGuaranteed> { if let ExprKind::Binary(binop, _, _) = &expr.kind @@ -1262,7 +1262,7 @@ impl<'a> Parser<'a> { /// Suggest add the missing `let` before the identifier in stmt /// `a: Ty = 1` -> `let a: Ty = 1` - pub(super) fn suggest_add_missing_let_for_stmt(&mut self, err: &mut DiagnosticBuilder<'a>) { + pub(super) fn suggest_add_missing_let_for_stmt(&mut self, err: &mut Diag<'a>) { if self.token == token::Colon { let prev_span = self.prev_token.span.shrink_to_lo(); let snapshot = self.create_snapshot_for_diagnostic(); @@ -1683,7 +1683,7 @@ impl<'a> Parser<'a> { ); err.span_label(op_span, format!("not a valid {} operator", kind.fixity)); - let help_base_case = |mut err: DiagnosticBuilder<'_, _>, base| { + let help_base_case = |mut err: Diag<'_, _>, base| { err.help(format!("use `{}= 1` instead", kind.op.chr())); err.emit(); Ok(base) @@ -1844,7 +1844,7 @@ impl<'a> Parser<'a> { } } - /// Creates a `DiagnosticBuilder` for an unexpected token `t` and tries to recover if it is a + /// Creates a `Diag` for an unexpected token `t` and tries to recover if it is a /// closing delimiter. pub(super) fn unexpected_try_recover(&mut self, t: &TokenKind) -> PResult<'a, Recovered> { let token_str = pprust::token_kind_to_string(t); @@ -2188,7 +2188,7 @@ impl<'a> Parser<'a> { pub(super) fn parameter_without_type( &mut self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diag<'_>, pat: P, require_name: bool, first_param: bool, @@ -2345,7 +2345,7 @@ impl<'a> Parser<'a> { } } - pub(super) fn expected_expression_found(&self) -> DiagnosticBuilder<'a> { + pub(super) fn expected_expression_found(&self) -> Diag<'a> { let (span, msg) = match (&self.token.kind, self.subparser_name) { (&token::Eof, Some(origin)) => { let sp = self.prev_token.span.shrink_to_hi(); @@ -2595,11 +2595,7 @@ impl<'a> Parser<'a> { /// When encountering code like `foo::< bar + 3 >` or `foo::< bar - baz >` we suggest /// `foo::<{ bar + 3 }>` and `foo::<{ bar - baz }>`, respectively. We only provide a suggestion /// if we think that the resulting expression would be well formed. - pub fn recover_const_arg( - &mut self, - start: Span, - mut err: DiagnosticBuilder<'a>, - ) -> PResult<'a, GenericArg> { + pub fn recover_const_arg(&mut self, start: Span, mut err: Diag<'a>) -> PResult<'a, GenericArg> { let is_op_or_dot = AssocOp::from_token(&self.token) .and_then(|op| { if let AssocOp::Greater @@ -2700,11 +2696,7 @@ impl<'a> Parser<'a> { } /// Creates a dummy const argument, and reports that the expression must be enclosed in braces - pub fn dummy_const_arg_needs_braces( - &self, - mut err: DiagnosticBuilder<'a>, - span: Span, - ) -> GenericArg { + pub fn dummy_const_arg_needs_braces(&self, mut err: Diag<'a>, span: Span) -> GenericArg { err.multipart_suggestion( "expressions must be enclosed in braces to be used as const generic \ arguments", diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index f5d4f4f57b9..f5a7bfd42ff 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -26,7 +26,7 @@ use rustc_ast::{Arm, BlockCheckMode, Expr, ExprKind, Label, Movability, RangeLim use rustc_ast::{ClosureBinder, MetaItemLit, StmtKind}; use rustc_ast_pretty::pprust; use rustc_data_structures::stack::ensure_sufficient_stack; -use rustc_errors::{AddToDiagnostic, Applicability, DiagnosticBuilder, PResult, StashKey}; +use rustc_errors::{AddToDiagnostic, Applicability, Diag, PResult, StashKey}; use rustc_lexer::unescape::unescape_char; use rustc_macros::Subdiagnostic; use rustc_session::errors::{report_lit_error, ExprParenthesesNeeded}; @@ -866,7 +866,7 @@ impl<'a> Parser<'a> { ); let mut err = self.dcx().struct_span_err(span, msg); - let suggest_parens = |err: &mut DiagnosticBuilder<'_>| { + let suggest_parens = |err: &mut Diag<'_>| { let suggestions = vec![ (span.shrink_to_lo(), "(".to_string()), (span.shrink_to_hi(), ")".to_string()), @@ -1759,7 +1759,7 @@ impl<'a> Parser<'a> { &self, ident: Ident, mk_lit_char: impl FnOnce(Symbol, Span) -> L, - err: impl FnOnce(&Self) -> DiagnosticBuilder<'a>, + err: impl FnOnce(&Self) -> Diag<'a>, ) -> L { assert!(could_be_unclosed_char_literal(ident)); if let Some(diag) = self.dcx().steal_diagnostic(ident.span, StashKey::LifetimeIsChar) { @@ -3447,7 +3447,7 @@ impl<'a> Parser<'a> { let mut recovered_async = None; let in_if_guard = self.restrictions.contains(Restrictions::IN_IF_GUARD); - let async_block_err = |e: &mut DiagnosticBuilder<'_>, span: Span| { + let async_block_err = |e: &mut Diag<'_>, span: Span| { errors::AsyncBlockIn2015 { span }.add_to_diagnostic(e); errors::HelpUseLatestEdition::new().add_to_diagnostic(e); }; diff --git a/compiler/rustc_parse/src/parser/mod.rs b/compiler/rustc_parse/src/parser/mod.rs index 29dd2eeb56a..8542ea62310 100644 --- a/compiler/rustc_parse/src/parser/mod.rs +++ b/compiler/rustc_parse/src/parser/mod.rs @@ -33,7 +33,7 @@ use rustc_ast::{HasAttrs, HasTokens, Unsafe, Visibility, VisibilityKind}; use rustc_ast_pretty::pprust; use rustc_data_structures::fx::FxHashMap; use rustc_errors::PResult; -use rustc_errors::{Applicability, DiagnosticBuilder, FatalError, MultiSpan}; +use rustc_errors::{Applicability, Diag, FatalError, MultiSpan}; use rustc_session::parse::ParseSess; use rustc_span::symbol::{kw, sym, Ident, Symbol}; use rustc_span::{Span, DUMMY_SP}; @@ -934,7 +934,7 @@ impl<'a> Parser<'a> { fn recover_missing_braces_around_closure_body( &mut self, closure_spans: ClosureSpans, - mut expect_err: DiagnosticBuilder<'_>, + mut expect_err: Diag<'_>, ) -> PResult<'a, ()> { let initial_semicolon = self.token.span; @@ -1522,7 +1522,7 @@ impl<'a> Parser<'a> { pub(crate) fn make_unclosed_delims_error( unmatched: UnmatchedDelim, sess: &ParseSess, -) -> Option> { +) -> Option> { // `None` here means an `Eof` was found. We already emit those errors elsewhere, we add them to // `unmatched_delims` only for error recovery in the `Parser`. let found_delim = unmatched.found_delim?; diff --git a/compiler/rustc_parse/src/parser/pat.rs b/compiler/rustc_parse/src/parser/pat.rs index 9bff5b93092..7aeab6488a5 100644 --- a/compiler/rustc_parse/src/parser/pat.rs +++ b/compiler/rustc_parse/src/parser/pat.rs @@ -20,7 +20,7 @@ use rustc_ast::{ PatField, PatFieldsRest, PatKind, Path, QSelf, RangeEnd, RangeSyntax, }; use rustc_ast_pretty::pprust; -use rustc_errors::{Applicability, DiagnosticBuilder, PResult}; +use rustc_errors::{Applicability, Diag, PResult}; use rustc_session::errors::ExprParenthesesNeeded; use rustc_span::source_map::{respan, Spanned}; use rustc_span::symbol::{kw, sym, Ident}; @@ -832,7 +832,7 @@ impl<'a> Parser<'a> { fn fatal_unexpected_non_pat( &mut self, - err: DiagnosticBuilder<'a>, + err: Diag<'a>, expected: Option, ) -> PResult<'a, P> { err.cancel(); @@ -1153,7 +1153,7 @@ impl<'a> Parser<'a> { let mut fields = ThinVec::new(); let mut etc = PatFieldsRest::None; let mut ate_comma = true; - let mut delayed_err: Option> = None; + let mut delayed_err: Option> = None; let mut first_etc_and_maybe_comma_span = None; let mut last_non_comma_dotdot_span = None; @@ -1316,11 +1316,7 @@ impl<'a> Parser<'a> { /// If the user writes `S { ref field: name }` instead of `S { field: ref name }`, we suggest /// the correct code. - fn recover_misplaced_pattern_modifiers( - &self, - fields: &ThinVec, - err: &mut DiagnosticBuilder<'a>, - ) { + fn recover_misplaced_pattern_modifiers(&self, fields: &ThinVec, err: &mut Diag<'a>) { if let Some(last) = fields.iter().last() && last.is_shorthand && let PatKind::Ident(binding, ident, None) = last.pat.kind diff --git a/compiler/rustc_parse/src/parser/stmt.rs b/compiler/rustc_parse/src/parser/stmt.rs index 55d6f7d6281..9fe74e80a2b 100644 --- a/compiler/rustc_parse/src/parser/stmt.rs +++ b/compiler/rustc_parse/src/parser/stmt.rs @@ -20,7 +20,7 @@ use rustc_ast::util::classify; use rustc_ast::{AttrStyle, AttrVec, LocalKind, MacCall, MacCallStmt, MacStmtStyle}; use rustc_ast::{Block, BlockCheckMode, Expr, ExprKind, HasAttrs, Local, Stmt}; use rustc_ast::{StmtKind, DUMMY_NODE_ID}; -use rustc_errors::{Applicability, DiagnosticBuilder, PResult}; +use rustc_errors::{Applicability, Diag, PResult}; use rustc_span::symbol::{kw, sym, Ident}; use rustc_span::{BytePos, ErrorGuaranteed, Span}; @@ -447,10 +447,7 @@ impl<'a> Parser<'a> { Ok(block) } - fn error_block_no_opening_brace_msg( - &mut self, - msg: Cow<'static, str>, - ) -> DiagnosticBuilder<'a> { + fn error_block_no_opening_brace_msg(&mut self, msg: Cow<'static, str>) -> Diag<'a> { let sp = self.token.span; let mut e = self.dcx().struct_span_err(sp, msg); let do_not_suggest_help = self.token.is_keyword(kw::In) || self.token == token::Colon; -- cgit 1.4.1-3-g733a5