Skip to content

Commit 645d478

Browse files
Revert "Prevent forbid from being ignored if overriden at the same level."
This reverts commit afa2a67.
1 parent 75a5adf commit 645d478

File tree

4 files changed

+5
-140
lines changed

4 files changed

+5
-140
lines changed

compiler/rustc_lint/src/levels.rs

Lines changed: 4 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use rustc_hir as hir;
1010
use rustc_hir::def_id::{CrateNum, LOCAL_CRATE};
1111
use rustc_hir::{intravisit, HirId};
1212
use rustc_middle::hir::map::Map;
13-
use rustc_middle::lint::LevelSource;
1413
use rustc_middle::lint::LintDiagnosticBuilder;
1514
use rustc_middle::lint::{struct_lint_level, LintLevelMap, LintLevelSets, LintSet, LintSource};
1615
use rustc_middle::ty::query::Providers;
@@ -97,44 +96,6 @@ impl<'s> LintLevelsBuilder<'s> {
9796
self.sets.list.push(LintSet::CommandLine { specs });
9897
}
9998

100-
/// Attempts to insert the `id` to `level_src` map entry. If unsuccessful
101-
/// (e.g. if a forbid was already inserted on the same scope), then emits a
102-
/// diagnostic with no change to `specs`.
103-
fn insert_spec(
104-
&mut self,
105-
specs: &mut FxHashMap<LintId, LevelSource>,
106-
id: LintId,
107-
(level, src): LevelSource,
108-
) {
109-
if let Some((old_level, old_src)) = specs.get(&id) {
110-
if old_level == &Level::Forbid && level != Level::Forbid {
111-
let mut diag_builder = struct_span_err!(
112-
self.sess,
113-
src.span(),
114-
E0453,
115-
"{}({}) incompatible with previous forbid in same scope",
116-
level.as_str(),
117-
src.name(),
118-
);
119-
match *old_src {
120-
LintSource::Default => {}
121-
LintSource::Node(_, forbid_source_span, reason) => {
122-
diag_builder.span_label(forbid_source_span, "`forbid` level set here");
123-
if let Some(rationale) = reason {
124-
diag_builder.note(&rationale.as_str());
125-
}
126-
}
127-
LintSource::CommandLine(_, _) => {
128-
diag_builder.note("`forbid` lint level was set on command line");
129-
}
130-
}
131-
diag_builder.emit();
132-
return;
133-
}
134-
}
135-
specs.insert(id, (level, src));
136-
}
137-
13899
/// Pushes a list of AST lint attributes onto this context.
139100
///
140101
/// This function will return a `BuilderPush` object which should be passed
@@ -149,7 +110,7 @@ impl<'s> LintLevelsBuilder<'s> {
149110
/// `#[allow]`
150111
///
151112
/// Don't forget to call `pop`!
152-
pub(crate) fn push(
113+
pub fn push(
153114
&mut self,
154115
attrs: &[ast::Attribute],
155116
store: &LintStore,
@@ -261,7 +222,7 @@ impl<'s> LintLevelsBuilder<'s> {
261222
let src = LintSource::Node(name, li.span(), reason);
262223
for &id in ids {
263224
self.check_gated_lint(id, attr.span);
264-
self.insert_spec(&mut specs, id, (level, src));
225+
specs.insert(id, (level, src));
265226
}
266227
}
267228

@@ -275,7 +236,7 @@ impl<'s> LintLevelsBuilder<'s> {
275236
reason,
276237
);
277238
for id in ids {
278-
self.insert_spec(&mut specs, *id, (level, src));
239+
specs.insert(*id, (level, src));
279240
}
280241
}
281242
Err((Some(ids), new_lint_name)) => {
@@ -312,7 +273,7 @@ impl<'s> LintLevelsBuilder<'s> {
312273
reason,
313274
);
314275
for id in ids {
315-
self.insert_spec(&mut specs, *id, (level, src));
276+
specs.insert(*id, (level, src));
316277
}
317278
}
318279
Err((None, _)) => {

compiler/rustc_middle/src/lint.rs

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_session::lint::{builtin, Level, Lint, LintId};
99
use rustc_session::{DiagnosticMessageId, Session};
1010
use rustc_span::hygiene::MacroKind;
1111
use rustc_span::source_map::{DesugaringKind, ExpnKind, MultiSpan};
12-
use rustc_span::{symbol, Span, Symbol, DUMMY_SP};
12+
use rustc_span::{Span, Symbol};
1313

1414
/// How a lint level was set.
1515
#[derive(Clone, Copy, PartialEq, Eq, HashStable)]
@@ -27,24 +27,6 @@ pub enum LintSource {
2727
CommandLine(Symbol, Level),
2828
}
2929

30-
impl LintSource {
31-
pub fn name(&self) -> Symbol {
32-
match *self {
33-
LintSource::Default => symbol::kw::Default,
34-
LintSource::Node(name, _, _) => name,
35-
LintSource::CommandLine(name, _) => name,
36-
}
37-
}
38-
39-
pub fn span(&self) -> Span {
40-
match *self {
41-
LintSource::Default => DUMMY_SP,
42-
LintSource::Node(_, span, _) => span,
43-
LintSource::CommandLine(_, _) => DUMMY_SP,
44-
}
45-
}
46-
}
47-
4830
pub type LevelSource = (Level, LintSource);
4931

5032
pub struct LintLevelSets {

src/test/ui/lint/issue-70819-dont-override-forbid-in-same-scope.rs

Lines changed: 0 additions & 49 deletions
This file was deleted.

src/test/ui/lint/issue-70819-dont-override-forbid-in-same-scope.stderr

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)