Skip to content

Commit 8894c90

Browse files
authored
Rollup merge of rust-lang#78663 - Aaron1011:fix/cap-future-compat, r=tmandry
Fix ICE when a future-incompat-report has its command-line level capped Fixes rust-lang#78660 With PR rust-lang#75534 merged, we now run more lint-related code for future-incompat-report, even when their final level is Allow. Some lint-related code was not expecting `Level::Allow`, and had an explicit panic. This PR explicitly tracks the lint level set on the command line before `--cap-lints` is applied. This is used to emit a more precise error note (e.g. we don't say that `-W lint-name` was specified on the command line just because a lint was capped to Warn). As a result, we can now correctly emit a note that `-A` was used if we got `Level::Allow` from the command line (before the cap is applied).
2 parents 416dd67 + 6c1f15f commit 8894c90

File tree

4 files changed

+34
-10
lines changed

4 files changed

+34
-10
lines changed

compiler/rustc_lint/src/levels.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ impl<'s> LintLevelsBuilder<'s> {
7474

7575
for &(ref lint_name, level) in &sess.opts.lint_opts {
7676
store.check_lint_name_cmdline(sess, &lint_name, level);
77+
let orig_level = level;
7778

7879
// If the cap is less than this specified level, e.g., if we've got
7980
// `--cap-lints allow` but we've also got `-D foo` then we ignore
@@ -88,7 +89,7 @@ impl<'s> LintLevelsBuilder<'s> {
8889
};
8990
for id in ids {
9091
self.check_gated_lint(id, DUMMY_SP);
91-
let src = LintSource::CommandLine(lint_flag_val);
92+
let src = LintSource::CommandLine(lint_flag_val, orig_level);
9293
specs.insert(id, (level, src));
9394
}
9495
}
@@ -123,7 +124,7 @@ impl<'s> LintLevelsBuilder<'s> {
123124
diag_builder.note(&rationale.as_str());
124125
}
125126
}
126-
LintSource::CommandLine(_) => {
127+
LintSource::CommandLine(_, _) => {
127128
diag_builder.note("`forbid` lint level was set on command line");
128129
}
129130
}
@@ -422,7 +423,7 @@ impl<'s> LintLevelsBuilder<'s> {
422423
let forbidden_lint_name = match forbid_src {
423424
LintSource::Default => id.to_string(),
424425
LintSource::Node(name, _, _) => name.to_string(),
425-
LintSource::CommandLine(name) => name.to_string(),
426+
LintSource::CommandLine(name, _) => name.to_string(),
426427
};
427428
let (lint_attr_name, lint_attr_span) = match *src {
428429
LintSource::Node(name, span, _) => (name, span),
@@ -446,7 +447,7 @@ impl<'s> LintLevelsBuilder<'s> {
446447
diag_builder.note(&rationale.as_str());
447448
}
448449
}
449-
LintSource::CommandLine(_) => {
450+
LintSource::CommandLine(_, _) => {
450451
diag_builder.note("`forbid` lint level was set on command line");
451452
}
452453
}

compiler/rustc_middle/src/lint.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,25 @@ pub enum LintSource {
2222
Node(Symbol, Span, Option<Symbol> /* RFC 2383 reason */),
2323

2424
/// Lint level was set by a command-line flag.
25-
CommandLine(Symbol),
25+
/// The provided `Level` is the level specified on the command line -
26+
/// the actual level may be lower due to `--cap-lints`
27+
CommandLine(Symbol, Level),
2628
}
2729

2830
impl LintSource {
2931
pub fn name(&self) -> Symbol {
3032
match *self {
3133
LintSource::Default => symbol::kw::Default,
3234
LintSource::Node(name, _, _) => name,
33-
LintSource::CommandLine(name) => name,
35+
LintSource::CommandLine(name, _) => name,
3436
}
3537
}
3638

3739
pub fn span(&self) -> Span {
3840
match *self {
3941
LintSource::Default => DUMMY_SP,
4042
LintSource::Node(_, span, _) => span,
41-
LintSource::CommandLine(_) => DUMMY_SP,
43+
LintSource::CommandLine(_, _) => DUMMY_SP,
4244
}
4345
}
4446
}
@@ -279,12 +281,12 @@ pub fn struct_lint_level<'s, 'd>(
279281
&format!("`#[{}({})]` on by default", level.as_str(), name),
280282
);
281283
}
282-
LintSource::CommandLine(lint_flag_val) => {
283-
let flag = match level {
284+
LintSource::CommandLine(lint_flag_val, orig_level) => {
285+
let flag = match orig_level {
284286
Level::Warn => "-W",
285287
Level::Deny => "-D",
286288
Level::Forbid => "-F",
287-
Level::Allow => panic!(),
289+
Level::Allow => "-A",
288290
};
289291
let hyphen_case_lint_name = name.replace("_", "-");
290292
if lint_flag_val.as_str() == name {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// compile-flags: -D warnings --cap-lints allow
2+
// check-pass
3+
4+
// Regression test for issue #78660
5+
// Tests that we don't ICE when a future-incompat-report lint has
6+
// has a command-line source, but is capped to allow
7+
8+
fn main() {
9+
["hi"].into_iter();
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Future incompatibility report: Future breakage date: None, diagnostic:
2+
warning: this method call currently resolves to `<&[T; N] as IntoIterator>::into_iter` (due to autoref coercions), but that might change in the future when `IntoIterator` impls for arrays are added.
3+
--> $DIR/issue-78660-cap-lints-future-compat.rs:9:12
4+
|
5+
LL | ["hi"].into_iter();
6+
| ^^^^^^^^^ help: use `.iter()` instead of `.into_iter()` to avoid ambiguity: `iter`
7+
|
8+
= note: `-D array-into-iter` implied by `-D warnings`
9+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
10+
= note: for more information, see issue #66145 <https://github.com/rust-lang/rust/issues/66145>
11+

0 commit comments

Comments
 (0)