Skip to content

Commit 5275d02

Browse files
committed
Use Vec for expectations to have a constant order (RFC-2383)
1 parent defc056 commit 5275d02

File tree

6 files changed

+26
-28
lines changed

6 files changed

+26
-28
lines changed

compiler/rustc_lint/src/expect.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use crate::builtin;
2-
use rustc_data_structures::fx::FxHashMap;
32
use rustc_hir::HirId;
43
use rustc_middle::{lint::LintExpectation, ty::TyCtxt};
54
use rustc_session::lint::LintExpectationId;
@@ -11,8 +10,7 @@ pub fn check_expectations(tcx: TyCtxt<'_>) {
1110
}
1211

1312
let fulfilled_expectations = tcx.sess.diagnostic().steal_fulfilled_expectation_ids();
14-
let lint_expectations: &FxHashMap<LintExpectationId, LintExpectation> =
15-
&tcx.lint_levels(()).lint_expectations;
13+
let lint_expectations = &tcx.lint_levels(()).lint_expectations;
1614

1715
for (id, expectation) in lint_expectations {
1816
if !fulfilled_expectations.contains(id) {

compiler/rustc_lint/src/levels.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ fn lint_levels(tcx: TyCtxt<'_>, (): ()) -> LintLevelMap {
4545

4646
pub struct LintLevelsBuilder<'s> {
4747
sess: &'s Session,
48-
lint_expectations: FxHashMap<LintExpectationId, LintExpectation>,
48+
lint_expectations: Vec<(LintExpectationId, LintExpectation)>,
4949
/// Each expectation has a stable and an unstable identifier. This map
5050
/// is used to map from unstable to stable [`LintExpectationId`]s.
5151
expectation_id_map: FxHashMap<LintExpectationId, LintExpectationId>,
@@ -355,7 +355,7 @@ impl<'s> LintLevelsBuilder<'s> {
355355
}
356356
if let Level::Expect(expect_id) = level {
357357
self.lint_expectations
358-
.insert(expect_id, LintExpectation::new(reason, sp));
358+
.push((expect_id, LintExpectation::new(reason, sp)));
359359
}
360360
}
361361

@@ -374,7 +374,7 @@ impl<'s> LintLevelsBuilder<'s> {
374374
}
375375
if let Level::Expect(expect_id) = level {
376376
self.lint_expectations
377-
.insert(expect_id, LintExpectation::new(reason, sp));
377+
.push((expect_id, LintExpectation::new(reason, sp)));
378378
}
379379
}
380380
Err((Some(ids), ref new_lint_name)) => {
@@ -414,7 +414,7 @@ impl<'s> LintLevelsBuilder<'s> {
414414
}
415415
if let Level::Expect(expect_id) = level {
416416
self.lint_expectations
417-
.insert(expect_id, LintExpectation::new(reason, sp));
417+
.push((expect_id, LintExpectation::new(reason, sp)));
418418
}
419419
}
420420
Err((None, _)) => {
@@ -511,7 +511,7 @@ impl<'s> LintLevelsBuilder<'s> {
511511
}
512512
if let Level::Expect(expect_id) = level {
513513
self.lint_expectations
514-
.insert(expect_id, LintExpectation::new(reason, sp));
514+
.push((expect_id, LintExpectation::new(reason, sp)));
515515
}
516516
} else {
517517
panic!("renamed lint does not exist: {}", new_name);

compiler/rustc_middle/src/lint.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ pub struct LintLevelMap {
159159
///
160160
/// The [`LintExpectationId`] is stored as a part of the [`Expect`](Level::Expect)
161161
/// lint level.
162-
pub lint_expectations: FxHashMap<LintExpectationId, LintExpectation>,
162+
pub lint_expectations: Vec<(LintExpectationId, LintExpectation)>,
163163
pub sets: LintLevelSets,
164164
pub id_to_set: FxHashMap<HirId, LintStackIndex>,
165165
}

src/test/ui/lint/rfc-2383-lint-reason/expect_multiple_lints.stderr

+14-14
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ LL | #[expect(unused_variables, unused_mut, while_true)]
77
= note: `#[warn(unfulfilled_lint_expectations)]` on by default
88

99
warning: this lint expectation is unfulfilled
10-
--> $DIR/expect_multiple_lints.rs:28:10
10+
--> $DIR/expect_multiple_lints.rs:10:40
1111
|
1212
LL | #[expect(unused_variables, unused_mut, while_true)]
13-
| ^^^^^^^^^^^^^^^^
13+
| ^^^^^^^^^^
1414

1515
warning: this lint expectation is unfulfilled
1616
--> $DIR/expect_multiple_lints.rs:19:10
@@ -19,34 +19,34 @@ LL | #[expect(unused_variables, unused_mut, while_true)]
1919
| ^^^^^^^^^^^^^^^^
2020

2121
warning: this lint expectation is unfulfilled
22-
--> $DIR/expect_multiple_lints.rs:28:28
22+
--> $DIR/expect_multiple_lints.rs:19:40
2323
|
2424
LL | #[expect(unused_variables, unused_mut, while_true)]
25-
| ^^^^^^^^^^
25+
| ^^^^^^^^^^
2626

2727
warning: this lint expectation is unfulfilled
28-
--> $DIR/expect_multiple_lints.rs:36:18
28+
--> $DIR/expect_multiple_lints.rs:28:10
2929
|
30-
LL | #[expect(unused, while_true)]
31-
| ^^^^^^^^^^
30+
LL | #[expect(unused_variables, unused_mut, while_true)]
31+
| ^^^^^^^^^^^^^^^^
3232

3333
warning: this lint expectation is unfulfilled
34-
--> $DIR/expect_multiple_lints.rs:19:40
34+
--> $DIR/expect_multiple_lints.rs:28:28
3535
|
3636
LL | #[expect(unused_variables, unused_mut, while_true)]
37-
| ^^^^^^^^^^
37+
| ^^^^^^^^^^
3838

3939
warning: this lint expectation is unfulfilled
40-
--> $DIR/expect_multiple_lints.rs:45:10
40+
--> $DIR/expect_multiple_lints.rs:36:18
4141
|
4242
LL | #[expect(unused, while_true)]
43-
| ^^^^^^
43+
| ^^^^^^^^^^
4444

4545
warning: this lint expectation is unfulfilled
46-
--> $DIR/expect_multiple_lints.rs:10:40
46+
--> $DIR/expect_multiple_lints.rs:45:10
4747
|
48-
LL | #[expect(unused_variables, unused_mut, while_true)]
49-
| ^^^^^^^^^^
48+
LL | #[expect(unused, while_true)]
49+
| ^^^^^^
5050

5151
warning: 8 warnings emitted
5252

src/test/ui/lint/rfc-2383-lint-reason/expect_nested_lint_levels.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#[expect(
77
unused_mut,
88
//~^ WARNING this lint expectation is unfulfilled [unfulfilled_lint_expectations]
9+
//~| NOTE `#[warn(unfulfilled_lint_expectations)]` on by default
910
//~| NOTE this `expect` is overridden by a `allow` attribute before the `unused_mut` lint is triggered
1011
reason = "this `expect` is overridden by a `allow` attribute before the `unused_mut` lint is triggered"
1112
)]
@@ -22,7 +23,6 @@ mod foo {
2223
#[expect(
2324
unused_mut,
2425
//~^ WARNING this lint expectation is unfulfilled [unfulfilled_lint_expectations]
25-
//~| NOTE `#[warn(unfulfilled_lint_expectations)]` on by default
2626
//~| NOTE this `expect` is overridden by a `warn` attribute before the `unused_mut` lint is triggered
2727
reason = "this `expect` is overridden by a `warn` attribute before the `unused_mut` lint is triggered"
2828
)]

src/test/ui/lint/rfc-2383-lint-reason/expect_nested_lint_levels.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,21 @@ LL | unused_mut,
2626
| ^^^^^^^^^^
2727

2828
warning: this lint expectation is unfulfilled
29-
--> $DIR/expect_nested_lint_levels.rs:23:5
29+
--> $DIR/expect_nested_lint_levels.rs:7:5
3030
|
3131
LL | unused_mut,
3232
| ^^^^^^^^^^
3333
|
3434
= note: `#[warn(unfulfilled_lint_expectations)]` on by default
35-
= note: this `expect` is overridden by a `warn` attribute before the `unused_mut` lint is triggered
35+
= note: this `expect` is overridden by a `allow` attribute before the `unused_mut` lint is triggered
3636

3737
warning: this lint expectation is unfulfilled
38-
--> $DIR/expect_nested_lint_levels.rs:7:5
38+
--> $DIR/expect_nested_lint_levels.rs:24:5
3939
|
4040
LL | unused_mut,
4141
| ^^^^^^^^^^
4242
|
43-
= note: this `expect` is overridden by a `allow` attribute before the `unused_mut` lint is triggered
43+
= note: this `expect` is overridden by a `warn` attribute before the `unused_mut` lint is triggered
4444

4545
warning: this lint expectation is unfulfilled
4646
--> $DIR/expect_nested_lint_levels.rs:43:10

0 commit comments

Comments
 (0)