Skip to content

Commit 39c98c7

Browse files
authored
Rollup merge of rust-lang#138610 - oli-obk:no-sort-hir-ids, r=compiler-errors
impl !PartialOrd for HirId revive of rust-lang#92233 Another checkbox of rust-lang#90317, another small step in making incremental less likely to die in horrible ways
2 parents eaaf3ab + ea97148 commit 39c98c7

File tree

9 files changed

+46
-27
lines changed

9 files changed

+46
-27
lines changed

clippy_lints/src/booleans.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ fn check_simplify_not(cx: &LateContext<'_>, msrv: Msrv, expr: &Expr<'_>) {
199199
&& !expr.span.from_expansion()
200200
&& !inner.span.from_expansion()
201201
&& let Some(suggestion) = simplify_not(cx, msrv, inner)
202-
&& cx.tcx.lint_level_at_node(NONMINIMAL_BOOL, expr.hir_id).0 != Level::Allow
202+
&& cx.tcx.lint_level_at_node(NONMINIMAL_BOOL, expr.hir_id).level != Level::Allow
203203
{
204204
use clippy_utils::sugg::{Sugg, has_enclosing_paren};
205205
let maybe_par = if let Some(sug) = Sugg::hir_opt(cx, inner) {
@@ -605,7 +605,7 @@ impl<'tcx> NonminimalBoolVisitor<'_, 'tcx> {
605605
}
606606
}
607607
let nonminimal_bool_lint = |mut suggestions: Vec<_>| {
608-
if self.cx.tcx.lint_level_at_node(NONMINIMAL_BOOL, e.hir_id).0 != Level::Allow {
608+
if self.cx.tcx.lint_level_at_node(NONMINIMAL_BOOL, e.hir_id).level != Level::Allow {
609609
suggestions.sort();
610610
span_lint_hir_and_then(
611611
self.cx,

clippy_lints/src/disallowed_script_idents.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ impl EarlyLintPass for DisallowedScriptIdents {
6969
// Implementation is heavily inspired by the implementation of [`non_ascii_idents`] lint:
7070
// https://github.com/rust-lang/rust/blob/master/compiler/rustc_lint/src/non_ascii_idents.rs
7171

72-
let check_disallowed_script_idents = cx.builder.lint_level(DISALLOWED_SCRIPT_IDENTS).0 != Level::Allow;
72+
let check_disallowed_script_idents = cx.builder.lint_level(DISALLOWED_SCRIPT_IDENTS).level != Level::Allow;
7373
if !check_disallowed_script_idents {
7474
return;
7575
}

clippy_lints/src/duplicate_mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use clippy_utils::diagnostics::span_lint_and_help;
22
use rustc_ast::ast::{Crate, Inline, Item, ItemKind, ModKind};
33
use rustc_errors::MultiSpan;
44
use rustc_lint::{EarlyContext, EarlyLintPass, Level, LintContext};
5+
use rustc_middle::lint::LevelAndSource;
56
use rustc_session::impl_lint_pass;
67
use rustc_span::{FileName, Span};
78
use std::collections::BTreeMap;
@@ -45,11 +46,10 @@ declare_clippy_lint! {
4546
"file loaded as module multiple times"
4647
}
4748

48-
#[derive(PartialOrd, Ord, PartialEq, Eq)]
4949
struct Modules {
5050
local_path: PathBuf,
5151
spans: Vec<Span>,
52-
lint_levels: Vec<Level>,
52+
lint_levels: Vec<LevelAndSource>,
5353
}
5454

5555
#[derive(Default)]
@@ -95,11 +95,11 @@ impl EarlyLintPass for DuplicateMod {
9595
.iter()
9696
.zip(lint_levels)
9797
.filter_map(|(span, lvl)| {
98-
if let Some(id) = lvl.get_expectation_id() {
98+
if let Some(id) = lvl.lint_id {
9999
cx.fulfill_expectation(id);
100100
}
101101

102-
(!matches!(lvl, Level::Allow | Level::Expect(_))).then_some(*span)
102+
(!matches!(lvl.level, Level::Allow | Level::Expect)).then_some(*span)
103103
})
104104
.collect();
105105

clippy_lints/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -408,9 +408,9 @@ mod zombie_processes;
408408

409409
use clippy_config::{Conf, get_configuration_metadata, sanitize_explanation};
410410
use clippy_utils::macros::FormatArgsStorage;
411-
use utils::attr_collector::{AttrCollector, AttrStorage};
412411
use rustc_data_structures::fx::FxHashSet;
413412
use rustc_lint::{Lint, LintId};
413+
use utils::attr_collector::{AttrCollector, AttrStorage};
414414

415415
/// Register all pre expansion lints
416416
///

clippy_lints/src/macro_use.rs

+28-10
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,15 @@ impl LateLintPass<'_> for MacroUseImports {
153153
[] | [_] => return,
154154
[root, item] => {
155155
if !check_dup.contains(&(*item).to_string()) {
156-
used.entry(((*root).to_string(), span, hir_id))
157-
.or_insert_with(Vec::new)
158-
.push((*item).to_string());
156+
used.entry((
157+
(*root).to_string(),
158+
span,
159+
hir_id.local_id,
160+
cx.tcx.def_path_hash(hir_id.owner.def_id.into()),
161+
))
162+
.or_insert_with(|| (vec![], hir_id))
163+
.0
164+
.push((*item).to_string());
159165
check_dup.push((*item).to_string());
160166
}
161167
},
@@ -171,15 +177,27 @@ impl LateLintPass<'_> for MacroUseImports {
171177
}
172178
})
173179
.collect::<Vec<_>>();
174-
used.entry(((*root).to_string(), span, hir_id))
175-
.or_insert_with(Vec::new)
176-
.push(filtered.join("::"));
180+
used.entry((
181+
(*root).to_string(),
182+
span,
183+
hir_id.local_id,
184+
cx.tcx.def_path_hash(hir_id.owner.def_id.into()),
185+
))
186+
.or_insert_with(|| (vec![], hir_id))
187+
.0
188+
.push(filtered.join("::"));
177189
check_dup.extend(filtered);
178190
} else {
179191
let rest = rest.to_vec();
180-
used.entry(((*root).to_string(), span, hir_id))
181-
.or_insert_with(Vec::new)
182-
.push(rest.join("::"));
192+
used.entry((
193+
(*root).to_string(),
194+
span,
195+
hir_id.local_id,
196+
cx.tcx.def_path_hash(hir_id.owner.def_id.into()),
197+
))
198+
.or_insert_with(|| (vec![], hir_id))
199+
.0
200+
.push(rest.join("::"));
183201
check_dup.extend(rest.iter().map(ToString::to_string));
184202
}
185203
},
@@ -190,7 +208,7 @@ impl LateLintPass<'_> for MacroUseImports {
190208
// If mac_refs is not empty we have encountered an import we could not handle
191209
// such as `std::prelude::v1::foo` or some other macro that expands to an import.
192210
if self.mac_refs.is_empty() {
193-
for ((root, span, hir_id), path) in used {
211+
for ((root, span, ..), (path, hir_id)) in used {
194212
let import = if let [single] = &path[..] {
195213
format!("{root}::{single}")
196214
} else {

clippy_lints/src/module_style.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ impl_lint_pass!(ModStyle => [MOD_MODULE_FILES, SELF_NAMED_MODULE_FILES]);
7373

7474
impl EarlyLintPass for ModStyle {
7575
fn check_crate(&mut self, cx: &EarlyContext<'_>, _: &ast::Crate) {
76-
if cx.builder.lint_level(MOD_MODULE_FILES).0 == Level::Allow
77-
&& cx.builder.lint_level(SELF_NAMED_MODULE_FILES).0 == Level::Allow
76+
if cx.builder.lint_level(MOD_MODULE_FILES).level == Level::Allow
77+
&& cx.builder.lint_level(SELF_NAMED_MODULE_FILES).level == Level::Allow
7878
{
7979
return;
8080
}

clippy_lints/src/raw_strings.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ impl RawStrings {
138138
);
139139
},
140140
);
141-
if !matches!(cx.get_lint_level(NEEDLESS_RAW_STRINGS), rustc_lint::Allow) {
141+
if !matches!(cx.get_lint_level(NEEDLESS_RAW_STRINGS).level, rustc_lint::Allow) {
142142
return;
143143
}
144144
}

clippy_lints/src/returns.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ fn check_final_expr<'tcx>(
404404
match cx.tcx.hir_attrs(expr.hir_id) {
405405
[] => {},
406406
[attr] => {
407-
if matches!(Level::from_attr(attr), Some(Level::Expect(_)))
407+
if matches!(Level::from_attr(attr), Some((Level::Expect, _)))
408408
&& let metas = attr.meta_item_list()
409409
&& let Some(lst) = metas
410410
&& let [MetaItemInner::MetaItem(meta_item), ..] = lst.as_slice()

clippy_utils/src/lib.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ use rustc_hir::{
114114
use rustc_lexer::{TokenKind, tokenize};
115115
use rustc_lint::{LateContext, Level, Lint, LintContext};
116116
use rustc_middle::hir::place::PlaceBase;
117+
use rustc_middle::lint::LevelAndSource;
117118
use rustc_middle::mir::{AggregateKind, Operand, RETURN_PLACE, Rvalue, StatementKind, TerminatorKind};
118119
use rustc_middle::ty::adjustment::{Adjust, Adjustment, AutoBorrow};
119120
use rustc_middle::ty::fast_reject::SimplifiedType;
@@ -1976,14 +1977,14 @@ pub fn fulfill_or_allowed(cx: &LateContext<'_>, lint: &'static Lint, ids: impl I
19761977
let mut suppress_lint = false;
19771978

19781979
for id in ids {
1979-
let (level, _) = cx.tcx.lint_level_at_node(lint, id);
1980-
if let Some(expectation) = level.get_expectation_id() {
1980+
let LevelAndSource { level, lint_id, .. } = cx.tcx.lint_level_at_node(lint, id);
1981+
if let Some(expectation) = lint_id {
19811982
cx.fulfill_expectation(expectation);
19821983
}
19831984

19841985
match level {
1985-
Level::Allow | Level::Expect(_) => suppress_lint = true,
1986-
Level::Warn | Level::ForceWarn(_) | Level::Deny | Level::Forbid => {},
1986+
Level::Allow | Level::Expect => suppress_lint = true,
1987+
Level::Warn | Level::ForceWarn | Level::Deny | Level::Forbid => {},
19871988
}
19881989
}
19891990

@@ -1998,7 +1999,7 @@ pub fn fulfill_or_allowed(cx: &LateContext<'_>, lint: &'static Lint, ids: impl I
19981999
/// make sure to use `span_lint_hir` functions to emit the lint. This ensures that
19992000
/// expectations at the checked nodes will be fulfilled.
20002001
pub fn is_lint_allowed(cx: &LateContext<'_>, lint: &'static Lint, id: HirId) -> bool {
2001-
cx.tcx.lint_level_at_node(lint, id).0 == Level::Allow
2002+
cx.tcx.lint_level_at_node(lint, id).level == Level::Allow
20022003
}
20032004

20042005
pub fn strip_pat_refs<'hir>(mut pat: &'hir Pat<'hir>) -> &'hir Pat<'hir> {

0 commit comments

Comments
 (0)