diff options
| author | xFrednet <xFrednet@gmail.com> | 2022-06-05 12:33:45 +0200 |
|---|---|---|
| committer | xFrednet <xFrednet@gmail.com> | 2022-06-16 08:16:43 +0200 |
| commit | 8527a3d36985bed55de1832c3c1f3d470720bb0b (patch) | |
| tree | ad2f51bc362ba29e281ac832a2a8e62b7b9b8b2c /compiler/rustc_lint | |
| parent | ec55c61305eaf385fc1b93ac9a78284b4d887fe5 (diff) | |
| download | rust-8527a3d36985bed55de1832c3c1f3d470720bb0b.tar.gz rust-8527a3d36985bed55de1832c3c1f3d470720bb0b.zip | |
Support lint expectations for `--force-warn` lints (RFC 2383)
Diffstat (limited to 'compiler/rustc_lint')
| -rw-r--r-- | compiler/rustc_lint/src/context.rs | 4 | ||||
| -rw-r--r-- | compiler/rustc_lint/src/expect.rs | 16 | ||||
| -rw-r--r-- | compiler/rustc_lint/src/levels.rs | 22 |
3 files changed, 26 insertions, 16 deletions
diff --git a/compiler/rustc_lint/src/context.rs b/compiler/rustc_lint/src/context.rs index 2c6bdef361a..d1950ed9aee 100644 --- a/compiler/rustc_lint/src/context.rs +++ b/compiler/rustc_lint/src/context.rs @@ -324,7 +324,7 @@ impl LintStore { registered_tools: &RegisteredTools, ) { let (tool_name, lint_name_only) = parse_lint_and_tool_name(lint_name); - if lint_name_only == crate::WARNINGS.name_lower() && level == Level::ForceWarn { + if lint_name_only == crate::WARNINGS.name_lower() && matches!(level, Level::ForceWarn(_)) { struct_span_err!( sess, DUMMY_SP, @@ -375,7 +375,7 @@ impl LintStore { match level { Level::Allow => "-A", Level::Warn => "-W", - Level::ForceWarn => "--force-warn", + Level::ForceWarn(_) => "--force-warn", Level::Deny => "-D", Level::Forbid => "-F", Level::Expect(_) => { diff --git a/compiler/rustc_lint/src/expect.rs b/compiler/rustc_lint/src/expect.rs index dc48ac0a618..95e3125045d 100644 --- a/compiler/rustc_lint/src/expect.rs +++ b/compiler/rustc_lint/src/expect.rs @@ -19,16 +19,16 @@ fn check_expectations(tcx: TyCtxt<'_>, tool_filter: Option<Symbol>) { let lint_expectations = &tcx.lint_levels(()).lint_expectations; for (id, expectation) in lint_expectations { - if !fulfilled_expectations.contains(id) - && tool_filter.map_or(true, |filter| expectation.lint_tool == Some(filter)) - { - // This check will always be true, since `lint_expectations` only - // holds stable ids - if let LintExpectationId::Stable { hir_id, .. } = id { + // This check will always be true, since `lint_expectations` only + // holds stable ids + if let LintExpectationId::Stable { hir_id, .. } = id { + if !fulfilled_expectations.contains(&id) + && tool_filter.map_or(true, |filter| expectation.lint_tool == Some(filter)) + { emit_unfulfilled_expectation_lint(tcx, *hir_id, expectation); - } else { - unreachable!("at this stage all `LintExpectationId`s are stable"); } + } else { + unreachable!("at this stage all `LintExpectationId`s are stable"); } } } diff --git a/compiler/rustc_lint/src/levels.rs b/compiler/rustc_lint/src/levels.rs index 54f2c725279..0c7b9a7ccb0 100644 --- a/compiler/rustc_lint/src/levels.rs +++ b/compiler/rustc_lint/src/levels.rs @@ -117,7 +117,9 @@ impl<'s> LintLevelsBuilder<'s> { }; for id in ids { // ForceWarn and Forbid cannot be overridden - if let Some((Level::ForceWarn | Level::Forbid, _)) = self.current_specs().get(&id) { + if let Some((Level::ForceWarn(_) | Level::Forbid, _)) = + self.current_specs().get(&id) + { continue; } @@ -226,11 +228,18 @@ impl<'s> LintLevelsBuilder<'s> { return; } - if let Level::ForceWarn = old_level { - self.current_specs_mut().insert(id, (old_level, old_src)); - } else { - self.current_specs_mut().insert(id, (level, src)); - } + match (old_level, level) { + // If the new level is an expectation store it in `ForceWarn` + (Level::ForceWarn(_), Level::Expect(expectation_id)) => self + .current_specs_mut() + .insert(id, (Level::ForceWarn(Some(expectation_id)), old_src)), + // Keep `ForceWarn` level but drop the expectation + (Level::ForceWarn(_), _) => { + self.current_specs_mut().insert(id, (Level::ForceWarn(None), old_src)) + } + // Set the lint level as normal + _ => self.current_specs_mut().insert(id, (level, src)), + }; } /// Pushes a list of AST lint attributes onto this context. @@ -269,6 +278,7 @@ impl<'s> LintLevelsBuilder<'s> { let level = match Level::from_attr(attr) { None => continue, + // This is the only lint level with a `LintExpectationId` that can be created from an attribute Some(Level::Expect(unstable_id)) if let Some(hir_id) = source_hir_id => { let stable_id = self.create_stable_id(unstable_id, hir_id, attr_index); |
