Skip to content

Commit 3c7e7db

Browse files
committed
Auto merge of #9257 - flip1995:rustup, r=flip1995
Rustup r? `@ghost` changelog: none
2 parents 70bca29 + 510effc commit 3c7e7db

24 files changed

+89
-88
lines changed

clippy_dev/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#![feature(let_chains)]
21
#![feature(let_else)]
32
#![feature(once_cell)]
43
#![feature(rustc_private)]

clippy_lints/src/format.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessFormat {
8282
then {
8383
let is_new_string = match value.kind {
8484
ExprKind::Binary(..) => true,
85-
ExprKind::MethodCall(path, ..) => path.ident.name.as_str() == "to_string",
85+
ExprKind::MethodCall(path, ..) => path.ident.name == sym::to_string,
8686
_ => false,
8787
};
8888
let sugg = if is_new_string {

clippy_lints/src/format_impl.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ fn check_to_string_in_display(cx: &LateContext<'_>, expr: &Expr<'_>) {
141141
// Get the hir_id of the object we are calling the method on
142142
if let ExprKind::MethodCall(path, [ref self_arg, ..], _) = expr.kind;
143143
// Is the method to_string() ?
144-
if path.ident.name == sym!(to_string);
144+
if path.ident.name == sym::to_string;
145145
// Is the method a part of the ToString trait? (i.e. not to_string() implemented
146146
// separately)
147147
if let Some(expr_def_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id);

clippy_lints/src/inherent_to_string.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ impl<'tcx> LateLintPass<'tcx> for InherentToString {
9898
if_chain! {
9999
// Check if item is a method, called to_string and has a parameter 'self'
100100
if let ImplItemKind::Fn(ref signature, _) = impl_item.kind;
101-
if impl_item.ident.name.as_str() == "to_string";
101+
if impl_item.ident.name == sym::to_string;
102102
let decl = &signature.decl;
103103
if decl.implicit_self.has_implicit_self();
104104
if decl.inputs.len() == 1;

clippy_lints/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#![feature(control_flow_enum)]
55
#![feature(drain_filter)]
66
#![feature(iter_intersperse)]
7-
#![feature(let_chains)]
87
#![feature(let_else)]
98
#![feature(lint_reasons)]
109
#![feature(never_type)]

clippy_lints/src/lifetimes.rs

+47-35
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ use rustc_hir::intravisit::{
99
use rustc_hir::FnRetTy::Return;
1010
use rustc_hir::{
1111
BareFnTy, BodyId, FnDecl, GenericArg, GenericBound, GenericParam, GenericParamKind, Generics, Impl, ImplItem,
12-
ImplItemKind, Item, ItemKind, LangItem, Lifetime, LifetimeName, LifetimeParamKind, ParamName, PolyTraitRef,
13-
PredicateOrigin, TraitBoundModifier, TraitFn, TraitItem, TraitItemKind, Ty, TyKind, WherePredicate,
12+
ImplItemKind, Item, ItemKind, LangItem, Lifetime, LifetimeName, ParamName, PolyTraitRef, PredicateOrigin,
13+
TraitBoundModifier, TraitFn, TraitItem, TraitItemKind, Ty, TyKind, WherePredicate,
1414
};
1515
use rustc_lint::{LateContext, LateLintPass};
1616
use rustc_middle::hir::nested_filter as middle_nested_filter;
17+
use rustc_middle::ty::TyCtxt;
1718
use rustc_session::{declare_lint_pass, declare_tool_lint};
19+
use rustc_span::def_id::LocalDefId;
1820
use rustc_span::source_map::Span;
1921
use rustc_span::symbol::{kw, Ident, Symbol};
2022

@@ -129,7 +131,7 @@ impl<'tcx> LateLintPass<'tcx> for Lifetimes {
129131
enum RefLt {
130132
Unnamed,
131133
Static,
132-
Named(Symbol),
134+
Named(LocalDefId),
133135
}
134136

135137
fn check_fn_inner<'tcx>(
@@ -232,7 +234,7 @@ fn could_use_elision<'tcx>(
232234
// level of the current item.
233235

234236
// check named LTs
235-
let allowed_lts = allowed_lts_from(named_generics);
237+
let allowed_lts = allowed_lts_from(cx.tcx, named_generics);
236238

237239
// these will collect all the lifetimes for references in arg/return types
238240
let mut input_visitor = RefVisitor::new(cx);
@@ -254,22 +256,6 @@ fn could_use_elision<'tcx>(
254256
return false;
255257
}
256258

257-
if allowed_lts
258-
.intersection(
259-
&input_visitor
260-
.nested_elision_site_lts
261-
.iter()
262-
.chain(output_visitor.nested_elision_site_lts.iter())
263-
.cloned()
264-
.filter(|v| matches!(v, RefLt::Named(_)))
265-
.collect(),
266-
)
267-
.next()
268-
.is_some()
269-
{
270-
return false;
271-
}
272-
273259
let input_lts = input_visitor.lts;
274260
let output_lts = output_visitor.lts;
275261

@@ -303,6 +289,31 @@ fn could_use_elision<'tcx>(
303289
}
304290
}
305291

292+
// check for higher-ranked trait bounds
293+
if !input_visitor.nested_elision_site_lts.is_empty() || !output_visitor.nested_elision_site_lts.is_empty() {
294+
let allowed_lts: FxHashSet<_> = allowed_lts
295+
.iter()
296+
.filter_map(|lt| match lt {
297+
RefLt::Named(def_id) => Some(cx.tcx.item_name(def_id.to_def_id())),
298+
_ => None,
299+
})
300+
.collect();
301+
for lt in input_visitor.nested_elision_site_lts {
302+
if let RefLt::Named(def_id) = lt {
303+
if allowed_lts.contains(&cx.tcx.item_name(def_id.to_def_id())) {
304+
return false;
305+
}
306+
}
307+
}
308+
for lt in output_visitor.nested_elision_site_lts {
309+
if let RefLt::Named(def_id) = lt {
310+
if allowed_lts.contains(&cx.tcx.item_name(def_id.to_def_id())) {
311+
return false;
312+
}
313+
}
314+
}
315+
}
316+
306317
// no input lifetimes? easy case!
307318
if input_lts.is_empty() {
308319
false
@@ -335,14 +346,11 @@ fn could_use_elision<'tcx>(
335346
}
336347
}
337348

338-
fn allowed_lts_from(named_generics: &[GenericParam<'_>]) -> FxHashSet<RefLt> {
349+
fn allowed_lts_from(tcx: TyCtxt<'_>, named_generics: &[GenericParam<'_>]) -> FxHashSet<RefLt> {
339350
let mut allowed_lts = FxHashSet::default();
340351
for par in named_generics.iter() {
341-
if let GenericParamKind::Lifetime {
342-
kind: LifetimeParamKind::Explicit,
343-
} = par.kind
344-
{
345-
allowed_lts.insert(RefLt::Named(par.name.ident().name));
352+
if let GenericParamKind::Lifetime { .. } = par.kind {
353+
allowed_lts.insert(RefLt::Named(tcx.hir().local_def_id(par.hir_id)));
346354
}
347355
}
348356
allowed_lts.insert(RefLt::Unnamed);
@@ -385,8 +393,10 @@ impl<'a, 'tcx> RefVisitor<'a, 'tcx> {
385393
self.lts.push(RefLt::Unnamed);
386394
} else if lt.is_elided() {
387395
self.lts.push(RefLt::Unnamed);
396+
} else if let LifetimeName::Param(def_id, _) = lt.name {
397+
self.lts.push(RefLt::Named(def_id));
388398
} else {
389-
self.lts.push(RefLt::Named(lt.name.ident().name));
399+
self.lts.push(RefLt::Unnamed);
390400
}
391401
} else {
392402
self.lts.push(RefLt::Unnamed);
@@ -434,18 +444,22 @@ impl<'a, 'tcx> Visitor<'tcx> for RefVisitor<'a, 'tcx> {
434444
TyKind::OpaqueDef(item, bounds) => {
435445
let map = self.cx.tcx.hir();
436446
let item = map.item(item);
447+
let len = self.lts.len();
437448
walk_item(self, item);
438-
walk_ty(self, ty);
449+
self.lts.truncate(len);
439450
self.lts.extend(bounds.iter().filter_map(|bound| match bound {
440-
GenericArg::Lifetime(l) => Some(RefLt::Named(l.name.ident().name)),
451+
GenericArg::Lifetime(l) => Some(if let LifetimeName::Param(def_id, _) = l.name {
452+
RefLt::Named(def_id)
453+
} else {
454+
RefLt::Unnamed
455+
}),
441456
_ => None,
442457
}));
443458
},
444459
TyKind::BareFn(&BareFnTy { decl, .. }) => {
445460
let mut sub_visitor = RefVisitor::new(self.cx);
446461
sub_visitor.visit_fn_decl(decl);
447462
self.nested_elision_site_lts.append(&mut sub_visitor.all_lts());
448-
return;
449463
},
450464
TyKind::TraitObject(bounds, ref lt, _) => {
451465
if !lt.is_elided() {
@@ -454,11 +468,9 @@ impl<'a, 'tcx> Visitor<'tcx> for RefVisitor<'a, 'tcx> {
454468
for bound in bounds {
455469
self.visit_poly_trait_ref(bound, TraitBoundModifier::None);
456470
}
457-
return;
458471
},
459-
_ => (),
472+
_ => walk_ty(self, ty),
460473
}
461-
walk_ty(self, ty);
462474
}
463475
}
464476

@@ -477,7 +489,7 @@ fn has_where_lifetimes<'tcx>(cx: &LateContext<'tcx>, generics: &'tcx Generics<'_
477489
return true;
478490
}
479491
// if the bounds define new lifetimes, they are fine to occur
480-
let allowed_lts = allowed_lts_from(pred.bound_generic_params);
492+
let allowed_lts = allowed_lts_from(cx.tcx, pred.bound_generic_params);
481493
// now walk the bounds
482494
for bound in pred.bounds.iter() {
483495
walk_param_bound(&mut visitor, bound);
@@ -601,7 +613,7 @@ struct BodyLifetimeChecker {
601613
impl<'tcx> Visitor<'tcx> for BodyLifetimeChecker {
602614
// for lifetimes as parameters of generics
603615
fn visit_lifetime(&mut self, lifetime: &'tcx Lifetime) {
604-
if lifetime.name.ident().name != kw::Empty && lifetime.name.ident().name != kw::StaticLifetime {
616+
if lifetime.name.ident().name != kw::UnderscoreLifetime && lifetime.name.ident().name != kw::StaticLifetime {
605617
self.lifetimes_used_in_body = true;
606618
}
607619
}

clippy_lints/src/manual_async_fn.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ fn captures_all_lifetimes(inputs: &[Ty<'_>], output_lifetimes: &[LifetimeName])
166166
// - There's only one output lifetime bound using `+ '_`
167167
// - All input lifetimes are explicitly bound to the output
168168
input_lifetimes.is_empty()
169-
|| (output_lifetimes.len() == 1 && matches!(output_lifetimes[0], LifetimeName::Underscore))
169+
|| (output_lifetimes.len() == 1 && matches!(output_lifetimes[0], LifetimeName::Infer))
170170
|| input_lifetimes
171171
.iter()
172172
.all(|in_lt| output_lifetimes.iter().any(|out_lt| in_lt == out_lt))

clippy_lints/src/methods/inefficient_to_string.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use super::INEFFICIENT_TO_STRING;
1414
/// Checks for the `INEFFICIENT_TO_STRING` lint
1515
pub fn check<'tcx>(cx: &LateContext<'tcx>, expr: &hir::Expr<'_>, method_name: Symbol, args: &[hir::Expr<'_>]) {
1616
if_chain! {
17-
if args.len() == 1 && method_name == sym!(to_string);
17+
if args.len() == 1 && method_name == sym::to_string;
1818
if let Some(to_string_meth_did) = cx.typeck_results().type_dependent_def_id(expr.hir_id);
1919
if match_def_path(cx, to_string_meth_did, &paths::TO_STRING_METHOD);
2020
if let Some(substs) = cx.typeck_results().node_substs_opt(expr.hir_id);

clippy_lints/src/methods/unnecessary_to_owned.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -427,5 +427,5 @@ fn is_cow_into_owned(cx: &LateContext<'_>, method_name: Symbol, method_def_id: D
427427

428428
/// Returns true if the named method is `ToString::to_string`.
429429
fn is_to_string(cx: &LateContext<'_>, method_name: Symbol, method_def_id: DefId) -> bool {
430-
method_name.as_str() == "to_string" && is_diag_trait_item(cx, method_def_id, sym::ToString)
430+
method_name == sym::to_string && is_diag_trait_item(cx, method_def_id, sym::ToString)
431431
}

clippy_lints/src/ptr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ impl fmt::Display for RefPrefix {
351351
name.fmt(f)?;
352352
f.write_char(' ')?;
353353
},
354-
LifetimeName::Underscore => f.write_str("'_ ")?,
354+
LifetimeName::Infer => f.write_str("'_ ")?,
355355
LifetimeName::Static => f.write_str("'static ")?,
356356
_ => (),
357357
}

clippy_lints/src/strings.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ impl<'tcx> LateLintPass<'tcx> for StrToString {
394394
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &Expr<'_>) {
395395
if_chain! {
396396
if let ExprKind::MethodCall(path, [self_arg, ..], _) = &expr.kind;
397-
if path.ident.name == sym!(to_string);
397+
if path.ident.name == sym::to_string;
398398
let ty = cx.typeck_results().expr_ty(self_arg);
399399
if let ty::Ref(_, ty, ..) = ty.kind();
400400
if *ty.kind() == ty::Str;
@@ -444,7 +444,7 @@ impl<'tcx> LateLintPass<'tcx> for StringToString {
444444
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &Expr<'_>) {
445445
if_chain! {
446446
if let ExprKind::MethodCall(path, [self_arg, ..], _) = &expr.kind;
447-
if path.ident.name == sym!(to_string);
447+
if path.ident.name == sym::to_string;
448448
let ty = cx.typeck_results().expr_ty(self_arg);
449449
if is_type_diagnostic_item(cx, ty, sym::String);
450450
then {

clippy_utils/src/lib.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#![feature(box_patterns)]
33
#![feature(control_flow_enum)]
44
#![feature(let_else)]
5-
#![feature(let_chains)]
65
#![feature(lint_reasons)]
76
#![feature(once_cell)]
87
#![feature(rustc_private)]
@@ -2142,7 +2141,7 @@ pub fn is_hir_ty_cfg_dependant(cx: &LateContext<'_>, ty: &hir::Ty<'_>) -> bool {
21422141

21432142
static TEST_ITEM_NAMES_CACHE: OnceLock<Mutex<FxHashMap<LocalDefId, Vec<Symbol>>>> = OnceLock::new();
21442143

2145-
fn with_test_item_names<'tcx>(tcx: TyCtxt<'tcx>, module: LocalDefId, f: impl Fn(&[Symbol]) -> bool) -> bool {
2144+
fn with_test_item_names(tcx: TyCtxt<'_>, module: LocalDefId, f: impl Fn(&[Symbol]) -> bool) -> bool {
21462145
let cache = TEST_ITEM_NAMES_CACHE.get_or_init(|| Mutex::new(FxHashMap::default()));
21472146
let mut map: MutexGuard<'_, FxHashMap<LocalDefId, Vec<Symbol>>> = cache.lock().unwrap();
21482147
let value = map.entry(module);

rust-toolchain

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[toolchain]
2-
channel = "nightly-2022-07-15"
2+
channel = "nightly-2022-07-28"
33
components = ["cargo", "llvm-tools-preview", "rust-src", "rust-std", "rustc", "rustc-dev", "rustfmt"]

src/driver.rs

+2
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ struct ClippyCallbacks {
9494
}
9595

9696
impl rustc_driver::Callbacks for ClippyCallbacks {
97+
// JUSTIFICATION: necessary in clippy driver to set `mir_opt_level`
98+
#[cfg_attr(not(bootstrap), allow(rustc::bad_opt_access))]
9799
fn config(&mut self, config: &mut interface::Config) {
98100
let previous = config.register_lints.take();
99101
let clippy_args_var = self.clippy_args_var.take();

tests/ui-internal/check_clippy_version_attribute.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ LL | #![deny(clippy::internal)]
1717
| ^^^^^^^^^^^^^^^^
1818
= note: `#[deny(clippy::invalid_clippy_version_attribute)]` implied by `#[deny(clippy::internal)]`
1919
= help: please use a valid sematic version, see `doc/adding_lints.md`
20-
= note: this error originates in the macro `$crate::declare_tool_lint` (in Nightly builds, run with -Z macro-backtrace for more info)
20+
= note: this error originates in the macro `$crate::declare_tool_lint` which comes from the expansion of the macro `declare_tool_lint` (in Nightly builds, run with -Z macro-backtrace for more info)
2121

2222
error: this item has an invalid `clippy::version` attribute
2323
--> $DIR/check_clippy_version_attribute.rs:48:1
@@ -32,7 +32,7 @@ LL | | }
3232
| |_^
3333
|
3434
= help: please use a valid sematic version, see `doc/adding_lints.md`
35-
= note: this error originates in the macro `$crate::declare_tool_lint` (in Nightly builds, run with -Z macro-backtrace for more info)
35+
= note: this error originates in the macro `$crate::declare_tool_lint` which comes from the expansion of the macro `declare_tool_lint` (in Nightly builds, run with -Z macro-backtrace for more info)
3636

3737
error: this lint is missing the `clippy::version` attribute or version value
3838
--> $DIR/check_clippy_version_attribute.rs:59:1
@@ -48,7 +48,7 @@ LL | | }
4848
|
4949
= note: `#[deny(clippy::missing_clippy_version_attribute)]` implied by `#[deny(clippy::internal)]`
5050
= help: please use a `clippy::version` attribute, see `doc/adding_lints.md`
51-
= note: this error originates in the macro `$crate::declare_tool_lint` (in Nightly builds, run with -Z macro-backtrace for more info)
51+
= note: this error originates in the macro `$crate::declare_tool_lint` which comes from the expansion of the macro `declare_tool_lint` (in Nightly builds, run with -Z macro-backtrace for more info)
5252

5353
error: this lint is missing the `clippy::version` attribute or version value
5454
--> $DIR/check_clippy_version_attribute.rs:67:1
@@ -62,7 +62,7 @@ LL | | }
6262
| |_^
6363
|
6464
= help: please use a `clippy::version` attribute, see `doc/adding_lints.md`
65-
= note: this error originates in the macro `$crate::declare_tool_lint` (in Nightly builds, run with -Z macro-backtrace for more info)
65+
= note: this error originates in the macro `$crate::declare_tool_lint` which comes from the expansion of the macro `declare_tool_lint` (in Nightly builds, run with -Z macro-backtrace for more info)
6666

6767
error: aborting due to 4 previous errors
6868

tests/ui-internal/default_lint.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ note: the lint level is defined here
1515
LL | #![deny(clippy::internal)]
1616
| ^^^^^^^^^^^^^^^^
1717
= note: `#[deny(clippy::default_lint)]` implied by `#[deny(clippy::internal)]`
18-
= note: this error originates in the macro `$crate::declare_tool_lint` (in Nightly builds, run with -Z macro-backtrace for more info)
18+
= note: this error originates in the macro `$crate::declare_tool_lint` which comes from the expansion of the macro `declare_tool_lint` (in Nightly builds, run with -Z macro-backtrace for more info)
1919

2020
error: aborting due to previous error
2121

tests/ui-internal/if_chain_style.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ LL | | }
5656
LL | | }
5757
| |_____^
5858
|
59-
= note: this error originates in the macro `__if_chain` (in Nightly builds, run with -Z macro-backtrace for more info)
59+
= note: this error originates in the macro `__if_chain` which comes from the expansion of the macro `if_chain` (in Nightly builds, run with -Z macro-backtrace for more info)
6060

6161
error: `let` expression should be above the `if_chain!`
6262
--> $DIR/if_chain_style.rs:40:9

tests/ui/crashes/ice-6252.stderr

+1-9
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,7 @@ LL | const VAL: T;
3030
LL | impl<N, M> TypeVal<usize> for Multiply<N, M> where N: TypeVal<VAL> {}
3131
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `VAL` in implementation
3232

33-
error: constant expression depends on a generic parameter
34-
--> $DIR/ice-6252.rs:13:9
35-
|
36-
LL | [1; <Multiply<Five, Five>>::VAL];
37-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
38-
|
39-
= note: this may fail depending on what value the parameter takes
40-
41-
error: aborting due to 4 previous errors
33+
error: aborting due to 3 previous errors
4234

4335
Some errors have detailed explanations: E0046, E0412.
4436
For more information about an error, try `rustc --explain E0046`.

tests/ui/diverging_sub_expression.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ error: sub-expression diverges
3636
LL | _ => true || panic!("boo"),
3737
| ^^^^^^^^^^^^^
3838
|
39-
= note: this error originates in the macro `$crate::panic::panic_2021` (in Nightly builds, run with -Z macro-backtrace for more info)
39+
= note: this error originates in the macro `$crate::panic::panic_2021` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
4040

4141
error: sub-expression diverges
4242
--> $DIR/diverging_sub_expression.rs:38:26

0 commit comments

Comments
 (0)