diff options
| author | Eduard-Mihai Burtescu <eddyb@lyken.rs> | 2022-01-27 09:44:25 +0000 |
|---|---|---|
| committer | Eduard-Mihai Burtescu <eddyb@lyken.rs> | 2022-02-23 06:38:52 +0000 |
| commit | b7e95dee65c35db8f8e07046d445b12d92cbae12 (patch) | |
| tree | af9131de515325e67c68ab9bbd3c514298ca57f4 /compiler/rustc_lint/src | |
| parent | 0b9d70cf6d47df456280f83b58c04c96aa58e89e (diff) | |
| download | rust-b7e95dee65c35db8f8e07046d445b12d92cbae12.tar.gz rust-b7e95dee65c35db8f8e07046d445b12d92cbae12.zip | |
rustc_errors: let `DiagnosticBuilder::emit` return a "guarantee of emission".
Diffstat (limited to 'compiler/rustc_lint/src')
| -rw-r--r-- | compiler/rustc_lint/src/context.rs | 22 | ||||
| -rw-r--r-- | compiler/rustc_lint/src/levels.rs | 25 |
2 files changed, 26 insertions, 21 deletions
diff --git a/compiler/rustc_lint/src/context.rs b/compiler/rustc_lint/src/context.rs index d8f55292ccd..c93028d621e 100644 --- a/compiler/rustc_lint/src/context.rs +++ b/compiler/rustc_lint/src/context.rs @@ -319,7 +319,7 @@ impl LintStore { ) { let (tool_name, lint_name_only) = parse_lint_and_tool_name(lint_name); if lint_name_only == crate::WARNINGS.name_lower() && level == Level::ForceWarn { - return struct_span_err!( + struct_span_err!( sess, DUMMY_SP, E0602, @@ -327,6 +327,7 @@ impl LintStore { crate::WARNINGS.name_lower() ) .emit(); + return; } let db = match self.check_lint_name(lint_name_only, tool_name, registered_tools) { CheckLintNameResult::Ok(_) => None, @@ -339,7 +340,7 @@ impl LintStore { err.help(&format!("did you mean: `{}`", suggestion)); } - Some(err) + Some(err.forget_guarantee()) } CheckLintNameResult::Tool(result) => match result { Err((Some(_), new_name)) => Some(sess.struct_warn(&format!( @@ -350,13 +351,16 @@ impl LintStore { ))), _ => None, }, - CheckLintNameResult::NoTool => Some(struct_span_err!( - sess, - DUMMY_SP, - E0602, - "unknown lint tool: `{}`", - tool_name.unwrap() - )), + CheckLintNameResult::NoTool => Some( + struct_span_err!( + sess, + DUMMY_SP, + E0602, + "unknown lint tool: `{}`", + tool_name.unwrap() + ) + .forget_guarantee(), + ), }; if let Some(mut db) = db { diff --git a/compiler/rustc_lint/src/levels.rs b/compiler/rustc_lint/src/levels.rs index 35c7d885e1d..d7cdb08d817 100644 --- a/compiler/rustc_lint/src/levels.rs +++ b/compiler/rustc_lint/src/levels.rs @@ -3,7 +3,7 @@ use crate::late::unerased_lint_store; use rustc_ast as ast; use rustc_ast_pretty::pprust; use rustc_data_structures::fx::FxHashMap; -use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder}; +use rustc_errors::{struct_span_err, Applicability, Diagnostic}; use rustc_hir as hir; use rustc_hir::{intravisit, HirId}; use rustc_middle::hir::nested_filter; @@ -150,29 +150,28 @@ impl<'s> LintLevelsBuilder<'s> { fcw_warning, specs, old_src, id_name ); - let decorate_diag_builder = |mut diag_builder: DiagnosticBuilder<'_>| { - diag_builder.span_label(src.span(), "overruled by previous forbid"); + let decorate_diag = |diag: &mut Diagnostic| { + diag.span_label(src.span(), "overruled by previous forbid"); match old_src { LintLevelSource::Default => { - diag_builder.note(&format!( + diag.note(&format!( "`forbid` lint level is the default for {}", id.to_string() )); } LintLevelSource::Node(_, forbid_source_span, reason) => { - diag_builder.span_label(forbid_source_span, "`forbid` level set here"); + diag.span_label(forbid_source_span, "`forbid` level set here"); if let Some(rationale) = reason { - diag_builder.note(rationale.as_str()); + diag.note(rationale.as_str()); } } LintLevelSource::CommandLine(_, _) => { - diag_builder.note("`forbid` lint level was set on command line"); + diag.note("`forbid` lint level was set on command line"); } } - diag_builder.emit(); }; if !fcw_warning { - let diag_builder = struct_span_err!( + let mut diag_builder = struct_span_err!( self.sess, src.span(), E0453, @@ -180,18 +179,20 @@ impl<'s> LintLevelsBuilder<'s> { level.as_str(), src.name(), ); - decorate_diag_builder(diag_builder); + decorate_diag(&mut diag_builder); + diag_builder.emit(); } else { self.struct_lint( FORBIDDEN_LINT_GROUPS, Some(src.span().into()), |diag_builder| { - let diag_builder = diag_builder.build(&format!( + let mut diag_builder = diag_builder.build(&format!( "{}({}) incompatible with previous forbid", level.as_str(), src.name(), )); - decorate_diag_builder(diag_builder); + decorate_diag(&mut diag_builder); + diag_builder.emit(); }, ); } |
