Skip to content

Commit dab3a80

Browse files
committed
Auto merge of rust-lang#81761 - m-ou-se:rollup-xp7v07n, r=m-ou-se
Rollup of 9 pull requests Successful merges: - rust-lang#74304 (Stabilize the Wake trait) - rust-lang#79805 (Rename Iterator::fold_first to reduce and stabilize it) - rust-lang#81556 (introduce future-compatibility warning for forbidden lint groups) - rust-lang#81645 (Add lint for `panic!(123)` which is not accepted in Rust 2021.) - rust-lang#81710 (OsStr eq_ignore_ascii_case takes arg by value) - rust-lang#81711 (add #[inline] to all the public IpAddr functions) - rust-lang#81725 (Move test to be with the others) - rust-lang#81727 (Revert stabilizing integer::BITS.) - rust-lang#81745 (Stabilize poison API of Once, rename poisoned()) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 4f4656d + 6f014cd commit dab3a80

File tree

72 files changed

+1122
-355
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+1122
-355
lines changed

compiler/rustc_ast/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#![feature(const_fn_transmute)]
1515
#![feature(const_panic)]
1616
#![feature(crate_visibility_modifier)]
17-
#![feature(iterator_fold_self)]
1817
#![feature(label_break_value)]
1918
#![feature(nll)]
2019
#![feature(or_patterns)]

compiler/rustc_ast/src/mut_visit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub trait ExpectOne<A: Array> {
2828

2929
impl<A: Array> ExpectOne<A> for SmallVec<A> {
3030
fn expect_one(self, err: &'static str) -> A::Item {
31-
assert!(self.len() == 1, err);
31+
assert!(self.len() == 1, "{}", err);
3232
self.into_iter().next().unwrap()
3333
}
3434
}

compiler/rustc_data_structures/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#![feature(unboxed_closures)]
1414
#![feature(generator_trait)]
1515
#![feature(fn_traits)]
16+
#![feature(int_bits_const)]
1617
#![feature(min_specialization)]
1718
#![feature(auto_traits)]
1819
#![feature(nll)]

compiler/rustc_errors/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -901,7 +901,7 @@ impl HandlerInner {
901901

902902
fn span_bug(&mut self, sp: impl Into<MultiSpan>, msg: &str) -> ! {
903903
self.emit_diag_at_span(Diagnostic::new(Bug, msg), sp);
904-
panic!(ExplicitBug);
904+
panic::panic_any(ExplicitBug);
905905
}
906906

907907
fn emit_diag_at_span(&mut self, mut diag: Diagnostic, sp: impl Into<MultiSpan>) {
@@ -955,7 +955,7 @@ impl HandlerInner {
955955

956956
fn bug(&mut self, msg: &str) -> ! {
957957
self.emit_diagnostic(&Diagnostic::new(Bug, msg));
958-
panic!(ExplicitBug);
958+
panic::panic_any(ExplicitBug);
959959
}
960960

961961
fn delay_as_bug(&mut self, diagnostic: Diagnostic) {

compiler/rustc_hir/src/hir.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ impl GenericArgs<'_> {
358358
.iter()
359359
.filter(|arg| !arg.is_synthetic())
360360
.map(|arg| arg.span())
361-
.fold_first(|span1, span2| span1.to(span2))
361+
.reduce(|span1, span2| span1.to(span2))
362362
}
363363

364364
/// Returns span encompassing arguments and their surrounding `<>` or `()`

compiler/rustc_hir/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#![feature(const_fn)] // For the unsizing cast on `&[]`
77
#![feature(const_panic)]
88
#![feature(in_band_lifetimes)]
9-
#![feature(iterator_fold_self)]
109
#![feature(once_cell)]
1110
#![feature(or_patterns)]
1211
#![recursion_limit = "256"]

compiler/rustc_lint/src/context.rs

+15
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ use rustc_session::SessionLintStore;
3939
use rustc_span::lev_distance::find_best_match_for_name;
4040
use rustc_span::{symbol::Symbol, MultiSpan, Span, DUMMY_SP};
4141
use rustc_target::abi::LayoutOf;
42+
use tracing::debug;
4243

4344
use std::cell::Cell;
4445
use std::slice;
@@ -336,6 +337,20 @@ impl LintStore {
336337
}
337338
}
338339

340+
/// True if this symbol represents a lint group name.
341+
pub fn is_lint_group(&self, lint_name: Symbol) -> bool {
342+
debug!(
343+
"is_lint_group(lint_name={:?}, lint_groups={:?})",
344+
lint_name,
345+
self.lint_groups.keys().collect::<Vec<_>>()
346+
);
347+
let lint_name_str = &*lint_name.as_str();
348+
self.lint_groups.contains_key(&lint_name_str) || {
349+
let warnings_name_str = crate::WARNINGS.name_lower();
350+
lint_name_str == &*warnings_name_str
351+
}
352+
}
353+
339354
/// Checks the name of a lint for its existence, and whether it was
340355
/// renamed or removed. Generates a DiagnosticBuilder containing a
341356
/// warning for renamed and removed lints. This is over both lint

compiler/rustc_lint/src/levels.rs

+73-28
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rustc_ast::attr;
55
use rustc_ast::unwrap_or;
66
use rustc_ast_pretty::pprust;
77
use rustc_data_structures::fx::FxHashMap;
8-
use rustc_errors::{struct_span_err, Applicability};
8+
use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder};
99
use rustc_hir as hir;
1010
use rustc_hir::def_id::{CrateNum, LOCAL_CRATE};
1111
use rustc_hir::{intravisit, HirId};
@@ -17,11 +17,15 @@ use rustc_middle::lint::{
1717
};
1818
use rustc_middle::ty::query::Providers;
1919
use rustc_middle::ty::TyCtxt;
20-
use rustc_session::lint::{builtin, Level, Lint, LintId};
20+
use rustc_session::lint::{
21+
builtin::{self, FORBIDDEN_LINT_GROUPS},
22+
Level, Lint, LintId,
23+
};
2124
use rustc_session::parse::feature_err;
2225
use rustc_session::Session;
2326
use rustc_span::symbol::{sym, Symbol};
2427
use rustc_span::{source_map::MultiSpan, Span, DUMMY_SP};
28+
use tracing::debug;
2529

2630
use std::cmp;
2731

@@ -51,6 +55,7 @@ pub struct LintLevelsBuilder<'s> {
5155
id_to_set: FxHashMap<HirId, u32>,
5256
cur: u32,
5357
warn_about_weird_lints: bool,
58+
store: &'s LintStore,
5459
}
5560

5661
pub struct BuilderPush {
@@ -59,13 +64,14 @@ pub struct BuilderPush {
5964
}
6065

6166
impl<'s> LintLevelsBuilder<'s> {
62-
pub fn new(sess: &'s Session, warn_about_weird_lints: bool, store: &LintStore) -> Self {
67+
pub fn new(sess: &'s Session, warn_about_weird_lints: bool, store: &'s LintStore) -> Self {
6368
let mut builder = LintLevelsBuilder {
6469
sess,
6570
sets: LintLevelSets::new(),
6671
cur: 0,
6772
id_to_set: Default::default(),
6873
warn_about_weird_lints,
74+
store,
6975
};
7076
builder.process_command_line(sess, store);
7177
assert_eq!(builder.sets.list.len(), 1);
@@ -120,36 +126,75 @@ impl<'s> LintLevelsBuilder<'s> {
120126
if let (Level::Forbid, old_src) =
121127
self.sets.get_lint_level(id.lint, self.cur, Some(&specs), &self.sess)
122128
{
123-
let mut diag_builder = struct_span_err!(
124-
self.sess,
125-
src.span(),
126-
E0453,
127-
"{}({}) incompatible with previous forbid",
128-
level.as_str(),
129-
src.name(),
129+
// Backwards compatibility check:
130+
//
131+
// We used to not consider `forbid(lint_group)`
132+
// as preventing `allow(lint)` for some lint `lint` in
133+
// `lint_group`. For now, issue a future-compatibility
134+
// warning for this case.
135+
let id_name = id.lint.name_lower();
136+
let fcw_warning = match old_src {
137+
LintLevelSource::Default => false,
138+
LintLevelSource::Node(symbol, _, _) => self.store.is_lint_group(symbol),
139+
LintLevelSource::CommandLine(symbol, _) => self.store.is_lint_group(symbol),
140+
};
141+
debug!(
142+
"fcw_warning={:?}, specs.get(&id) = {:?}, old_src={:?}, id_name={:?}",
143+
fcw_warning, specs, old_src, id_name
130144
);
131-
diag_builder.span_label(src.span(), "overruled by previous forbid");
132-
match old_src {
133-
LintLevelSource::Default => {
134-
diag_builder.note(&format!(
135-
"`forbid` lint level is the default for {}",
136-
id.to_string()
137-
));
138-
}
139-
LintLevelSource::Node(_, forbid_source_span, reason) => {
140-
diag_builder.span_label(forbid_source_span, "`forbid` level set here");
141-
if let Some(rationale) = reason {
142-
diag_builder.note(&rationale.as_str());
145+
146+
let decorate_diag_builder = |mut diag_builder: DiagnosticBuilder<'_>| {
147+
diag_builder.span_label(src.span(), "overruled by previous forbid");
148+
match old_src {
149+
LintLevelSource::Default => {
150+
diag_builder.note(&format!(
151+
"`forbid` lint level is the default for {}",
152+
id.to_string()
153+
));
154+
}
155+
LintLevelSource::Node(_, forbid_source_span, reason) => {
156+
diag_builder.span_label(forbid_source_span, "`forbid` level set here");
157+
if let Some(rationale) = reason {
158+
diag_builder.note(&rationale.as_str());
159+
}
160+
}
161+
LintLevelSource::CommandLine(_, _) => {
162+
diag_builder.note("`forbid` lint level was set on command line");
143163
}
144164
}
145-
LintLevelSource::CommandLine(_, _) => {
146-
diag_builder.note("`forbid` lint level was set on command line");
147-
}
165+
diag_builder.emit();
166+
};
167+
if !fcw_warning {
168+
let diag_builder = struct_span_err!(
169+
self.sess,
170+
src.span(),
171+
E0453,
172+
"{}({}) incompatible with previous forbid",
173+
level.as_str(),
174+
src.name(),
175+
);
176+
decorate_diag_builder(diag_builder);
177+
} else {
178+
self.struct_lint(
179+
FORBIDDEN_LINT_GROUPS,
180+
Some(src.span().into()),
181+
|diag_builder| {
182+
let diag_builder = diag_builder.build(&format!(
183+
"{}({}) incompatible with previous forbid",
184+
level.as_str(),
185+
src.name(),
186+
));
187+
decorate_diag_builder(diag_builder);
188+
},
189+
);
148190
}
149-
diag_builder.emit();
150191

151-
// Retain the forbid lint level
152-
return;
192+
// Retain the forbid lint level, unless we are
193+
// issuing a FCW. In the FCW case, we want to
194+
// respect the new setting.
195+
if !fcw_warning {
196+
return;
197+
}
153198
}
154199
}
155200
specs.insert(id, (level, src));

compiler/rustc_lint/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ mod late;
5555
mod levels;
5656
mod methods;
5757
mod non_ascii_idents;
58+
mod non_fmt_panic;
5859
mod nonstandard_style;
59-
mod panic_fmt;
6060
mod passes;
6161
mod redundant_semicolon;
6262
mod traits;
@@ -81,8 +81,8 @@ use builtin::*;
8181
use internal::*;
8282
use methods::*;
8383
use non_ascii_idents::*;
84+
use non_fmt_panic::NonPanicFmt;
8485
use nonstandard_style::*;
85-
use panic_fmt::PanicFmt;
8686
use redundant_semicolon::*;
8787
use traits::*;
8888
use types::*;
@@ -169,7 +169,7 @@ macro_rules! late_lint_passes {
169169
ClashingExternDeclarations: ClashingExternDeclarations::new(),
170170
DropTraitConstraints: DropTraitConstraints,
171171
TemporaryCStringAsPtr: TemporaryCStringAsPtr,
172-
PanicFmt: PanicFmt,
172+
NonPanicFmt: NonPanicFmt,
173173
]
174174
);
175175
};

0 commit comments

Comments
 (0)