Skip to content

Commit b295b8e

Browse files
authored
Rollup merge of #80274 - pierwill:lintlevelsource, r=petrochenkov
Rename rustc_middle::lint::LintSource Rename [`rustc_middle::lint::LintSource`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/lint/enum.LintSource.html) to `rustc_middle::lint::LintLevelSource`. This enum represents the source of a *lint level*, not a lint. This should improve code readability. Update: Also documents `rustc_middle::lint::LevelSource` to clarify.
2 parents 299c2fc + d3900d3 commit b295b8e

File tree

5 files changed

+35
-32
lines changed

5 files changed

+35
-32
lines changed

compiler/rustc_lint/src/levels.rs

+12-10
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ use rustc_hir::{intravisit, HirId};
1212
use rustc_middle::hir::map::Map;
1313
use rustc_middle::lint::LevelSource;
1414
use rustc_middle::lint::LintDiagnosticBuilder;
15-
use rustc_middle::lint::{struct_lint_level, LintLevelMap, LintLevelSets, LintSet, LintSource};
15+
use rustc_middle::lint::{
16+
struct_lint_level, LintLevelMap, LintLevelSets, LintLevelSource, LintSet,
17+
};
1618
use rustc_middle::ty::query::Providers;
1719
use rustc_middle::ty::TyCtxt;
1820
use rustc_session::lint::{builtin, Level, Lint, LintId};
@@ -91,7 +93,7 @@ impl<'s> LintLevelsBuilder<'s> {
9193
};
9294
for id in ids {
9395
self.check_gated_lint(id, DUMMY_SP);
94-
let src = LintSource::CommandLine(lint_flag_val, orig_level);
96+
let src = LintLevelSource::CommandLine(lint_flag_val, orig_level);
9597
specs.insert(id, (level, src));
9698
}
9799
}
@@ -128,19 +130,19 @@ impl<'s> LintLevelsBuilder<'s> {
128130
);
129131
diag_builder.span_label(src.span(), "overruled by previous forbid");
130132
match old_src {
131-
LintSource::Default => {
133+
LintLevelSource::Default => {
132134
diag_builder.note(&format!(
133135
"`forbid` lint level is the default for {}",
134136
id.to_string()
135137
));
136138
}
137-
LintSource::Node(_, forbid_source_span, reason) => {
139+
LintLevelSource::Node(_, forbid_source_span, reason) => {
138140
diag_builder.span_label(forbid_source_span, "`forbid` level set here");
139141
if let Some(rationale) = reason {
140142
diag_builder.note(&rationale.as_str());
141143
}
142144
}
143-
LintSource::CommandLine(_, _) => {
145+
LintLevelSource::CommandLine(_, _) => {
144146
diag_builder.note("`forbid` lint level was set on command line");
145147
}
146148
}
@@ -276,7 +278,7 @@ impl<'s> LintLevelsBuilder<'s> {
276278
let name = meta_item.path.segments.last().expect("empty lint name").ident.name;
277279
match store.check_lint_name(&name.as_str(), tool_name) {
278280
CheckLintNameResult::Ok(ids) => {
279-
let src = LintSource::Node(name, li.span(), reason);
281+
let src = LintLevelSource::Node(name, li.span(), reason);
280282
for &id in ids {
281283
self.check_gated_lint(id, attr.span);
282284
self.insert_spec(&mut specs, id, (level, src));
@@ -287,7 +289,7 @@ impl<'s> LintLevelsBuilder<'s> {
287289
match result {
288290
Ok(ids) => {
289291
let complete_name = &format!("{}::{}", tool_name.unwrap(), name);
290-
let src = LintSource::Node(
292+
let src = LintLevelSource::Node(
291293
Symbol::intern(complete_name),
292294
li.span(),
293295
reason,
@@ -324,7 +326,7 @@ impl<'s> LintLevelsBuilder<'s> {
324326
},
325327
);
326328

327-
let src = LintSource::Node(
329+
let src = LintLevelSource::Node(
328330
Symbol::intern(&new_lint_name),
329331
li.span(),
330332
reason,
@@ -403,7 +405,7 @@ impl<'s> LintLevelsBuilder<'s> {
403405
}
404406

405407
let (lint_attr_name, lint_attr_span) = match *src {
406-
LintSource::Node(name, span, _) => (name, span),
408+
LintLevelSource::Node(name, span, _) => (name, span),
407409
_ => continue,
408410
};
409411

@@ -460,7 +462,7 @@ impl<'s> LintLevelsBuilder<'s> {
460462
}
461463

462464
/// Find the lint level for a lint.
463-
pub fn lint_level(&self, lint: &'static Lint) -> (Level, LintSource) {
465+
pub fn lint_level(&self, lint: &'static Lint) -> (Level, LintLevelSource) {
464466
self.sets.get_lint_level(lint, self.cur, None, self.sess)
465467
}
466468

compiler/rustc_middle/src/lint.rs

+17-16
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_span::{symbol, Span, Symbol, DUMMY_SP};
1313

1414
/// How a lint level was set.
1515
#[derive(Clone, Copy, PartialEq, Eq, HashStable)]
16-
pub enum LintSource {
16+
pub enum LintLevelSource {
1717
/// Lint is at the default level as declared
1818
/// in rustc or a plugin.
1919
Default,
@@ -27,25 +27,26 @@ pub enum LintSource {
2727
CommandLine(Symbol, Level),
2828
}
2929

30-
impl LintSource {
30+
impl LintLevelSource {
3131
pub fn name(&self) -> Symbol {
3232
match *self {
33-
LintSource::Default => symbol::kw::Default,
34-
LintSource::Node(name, _, _) => name,
35-
LintSource::CommandLine(name, _) => name,
33+
LintLevelSource::Default => symbol::kw::Default,
34+
LintLevelSource::Node(name, _, _) => name,
35+
LintLevelSource::CommandLine(name, _) => name,
3636
}
3737
}
3838

3939
pub fn span(&self) -> Span {
4040
match *self {
41-
LintSource::Default => DUMMY_SP,
42-
LintSource::Node(_, span, _) => span,
43-
LintSource::CommandLine(_, _) => DUMMY_SP,
41+
LintLevelSource::Default => DUMMY_SP,
42+
LintLevelSource::Node(_, span, _) => span,
43+
LintLevelSource::CommandLine(_, _) => DUMMY_SP,
4444
}
4545
}
4646
}
4747

48-
pub type LevelSource = (Level, LintSource);
48+
/// A tuple of a lint level and its source.
49+
pub type LevelSource = (Level, LintLevelSource);
4950

5051
pub struct LintLevelSets {
5152
pub list: Vec<LintSet>,
@@ -113,7 +114,7 @@ impl LintLevelSets {
113114
id: LintId,
114115
mut idx: u32,
115116
aux: Option<&FxHashMap<LintId, LevelSource>>,
116-
) -> (Option<Level>, LintSource) {
117+
) -> (Option<Level>, LintLevelSource) {
117118
if let Some(specs) = aux {
118119
if let Some(&(level, src)) = specs.get(&id) {
119120
return (Some(level), src);
@@ -125,7 +126,7 @@ impl LintLevelSets {
125126
if let Some(&(level, src)) = specs.get(&id) {
126127
return (Some(level), src);
127128
}
128-
return (None, LintSource::Default);
129+
return (None, LintLevelSource::Default);
129130
}
130131
LintSet::Node { ref specs, parent } => {
131132
if let Some(&(level, src)) = specs.get(&id) {
@@ -213,7 +214,7 @@ pub fn struct_lint_level<'s, 'd>(
213214
sess: &'s Session,
214215
lint: &'static Lint,
215216
level: Level,
216-
src: LintSource,
217+
src: LintLevelSource,
217218
span: Option<MultiSpan>,
218219
decorate: impl for<'a> FnOnce(LintDiagnosticBuilder<'a>) + 'd,
219220
) {
@@ -223,7 +224,7 @@ pub fn struct_lint_level<'s, 'd>(
223224
sess: &'s Session,
224225
lint: &'static Lint,
225226
level: Level,
226-
src: LintSource,
227+
src: LintLevelSource,
227228
span: Option<MultiSpan>,
228229
decorate: Box<dyn for<'b> FnOnce(LintDiagnosticBuilder<'b>) + 'd>,
229230
) {
@@ -274,14 +275,14 @@ pub fn struct_lint_level<'s, 'd>(
274275

275276
let name = lint.name_lower();
276277
match src {
277-
LintSource::Default => {
278+
LintLevelSource::Default => {
278279
sess.diag_note_once(
279280
&mut err,
280281
DiagnosticMessageId::from(lint),
281282
&format!("`#[{}({})]` on by default", level.as_str(), name),
282283
);
283284
}
284-
LintSource::CommandLine(lint_flag_val, orig_level) => {
285+
LintLevelSource::CommandLine(lint_flag_val, orig_level) => {
285286
let flag = match orig_level {
286287
Level::Warn => "-W",
287288
Level::Deny => "-D",
@@ -310,7 +311,7 @@ pub fn struct_lint_level<'s, 'd>(
310311
);
311312
}
312313
}
313-
LintSource::Node(lint_attr_name, src, reason) => {
314+
LintLevelSource::Node(lint_attr_name, src, reason) => {
314315
if let Some(rationale) = reason {
315316
err.note(&rationale.as_str());
316317
}

compiler/rustc_middle/src/ty/context.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::dep_graph::{self, DepGraph, DepKind, DepNode, DepNodeExt};
55
use crate::hir::exports::ExportMap;
66
use crate::ich::{NodeIdHashingMode, StableHashingContext};
77
use crate::infer::canonical::{Canonical, CanonicalVarInfo, CanonicalVarInfos};
8-
use crate::lint::{struct_lint_level, LintDiagnosticBuilder, LintSource};
8+
use crate::lint::{struct_lint_level, LintDiagnosticBuilder, LintLevelSource};
99
use crate::middle;
1010
use crate::middle::cstore::{CrateStoreDyn, EncodedMetadata};
1111
use crate::middle::resolve_lifetime::{self, ObjectLifetimeDefault};
@@ -2559,7 +2559,7 @@ impl<'tcx> TyCtxt<'tcx> {
25592559
self,
25602560
lint: &'static Lint,
25612561
mut id: hir::HirId,
2562-
) -> (Level, LintSource) {
2562+
) -> (Level, LintLevelSource) {
25632563
let sets = self.lint_levels(LOCAL_CRATE);
25642564
loop {
25652565
if let Some(pair) = sets.level_and_source(lint, id, self.sess) {

src/librustdoc/passes/calculate_doc_coverage.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::html::markdown::{find_testable_code, ErrorCodes};
55
use crate::passes::doc_test_lints::{should_have_doc_example, Tests};
66
use crate::passes::Pass;
77
use rustc_lint::builtin::MISSING_DOCS;
8-
use rustc_middle::lint::LintSource;
8+
use rustc_middle::lint::LintLevelSource;
99
use rustc_session::lint;
1010
use rustc_span::symbol::sym;
1111
use rustc_span::FileName;
@@ -254,7 +254,7 @@ impl<'a, 'b> fold::DocFolder for CoverageCalculator<'a, 'b> {
254254
// `missing_docs` is allow-by-default, so don't treat this as ignoring the item
255255
// unless the user had an explicit `allow`
256256
let should_have_docs =
257-
level != lint::Level::Allow || matches!(source, LintSource::Default);
257+
level != lint::Level::Allow || matches!(source, LintLevelSource::Default);
258258
debug!("counting {:?} {:?} in {}", i.type_(), i.name, filename);
259259
self.items.entry(filename).or_default().count_item(
260260
has_docs,

src/librustdoc/passes/doc_test_lints.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::clean::*;
99
use crate::core::DocContext;
1010
use crate::fold::DocFolder;
1111
use crate::html::markdown::{find_testable_code, ErrorCodes, Ignore, LangString};
12-
use rustc_middle::lint::LintSource;
12+
use rustc_middle::lint::LintLevelSource;
1313
use rustc_session::lint;
1414

1515
crate const CHECK_PRIVATE_ITEMS_DOC_TESTS: Pass = Pass {
@@ -77,7 +77,7 @@ crate fn should_have_doc_example(cx: &DocContext<'_>, item: &clean::Item) -> boo
7777
let hir_id = cx.tcx.hir().local_def_id_to_hir_id(item.def_id.expect_local());
7878
let (level, source) =
7979
cx.tcx.lint_level_at_node(lint::builtin::MISSING_DOC_CODE_EXAMPLES, hir_id);
80-
level != lint::Level::Allow || matches!(source, LintSource::Default)
80+
level != lint::Level::Allow || matches!(source, LintLevelSource::Default)
8181
}
8282

8383
crate fn look_for_tests<'tcx>(cx: &DocContext<'tcx>, dox: &str, item: &Item) {

0 commit comments

Comments
 (0)