Skip to content

Commit abc59bb

Browse files
committed
Auto merge of #8656 - flip1995:rustup, r=flip1995
Rustup r? `@ghost` changelog: none
2 parents 574bf88 + a2fdbb5 commit abc59bb

34 files changed

+196
-157
lines changed

CHANGELOG.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ document.
88

99
[57b3c4b...master](https://github.com/rust-lang/rust-clippy/compare/57b3c4b...master)
1010

11-
## Rust 1.60 (beta)
11+
## Rust 1.60
1212

13-
Current beta, release 2022-04-07
13+
Current stable, released 2022-04-07
1414

1515
[0eff589...57b3c4b](https://github.com/rust-lang/rust-clippy/compare/0eff589...57b3c4b)
1616

@@ -142,7 +142,7 @@ Current beta, release 2022-04-07
142142

143143
## Rust 1.59
144144

145-
Current stable, release 2022-02-24
145+
Released 2022-02-24
146146

147147
[e181011...0eff589](https://github.com/rust-lang/rust-clippy/compare/e181011...0eff589)
148148

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "clippy"
3-
version = "0.1.61"
3+
version = "0.1.62"
44
description = "A bunch of helpful lints to avoid common pitfalls in Rust"
55
repository = "https://github.com/rust-lang/rust-clippy"
66
readme = "README.md"

clippy_lints/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "clippy_lints"
3-
version = "0.1.61"
3+
version = "0.1.62"
44
description = "A bunch of helpful lints to avoid common pitfalls in Rust"
55
repository = "https://github.com/rust-lang/rust-clippy"
66
readme = "README.md"

clippy_lints/src/arithmetic.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,11 @@ impl<'tcx> LateLintPass<'tcx> for Arithmetic {
139139
}
140140

141141
fn check_body(&mut self, cx: &LateContext<'_>, body: &hir::Body<'_>) {
142-
let body_owner = cx.tcx.hir().body_owner(body.id());
142+
let body_owner = cx.tcx.hir().body_owner_def_id(body.id());
143143

144144
match cx.tcx.hir().body_owner_kind(body_owner) {
145145
hir::BodyOwnerKind::Static(_) | hir::BodyOwnerKind::Const => {
146-
let body_span = cx.tcx.hir().span(body_owner);
146+
let body_span = cx.tcx.def_span(body_owner);
147147

148148
if let Some(span) = self.const_span {
149149
if span.contains(body_span) {

clippy_lints/src/collapsible_match.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ use clippy_utils::higher::IfLetOrMatch;
33
use clippy_utils::visitors::is_local_used;
44
use clippy_utils::{is_lang_ctor, is_unit_expr, path_to_local, peel_blocks_with_stmt, peel_ref_operators, SpanlessEq};
55
use if_chain::if_chain;
6+
use rustc_errors::MultiSpan;
67
use rustc_hir::LangItem::OptionNone;
78
use rustc_hir::{Arm, Expr, Guard, HirId, Pat, PatKind};
89
use rustc_lint::{LateContext, LateLintPass};
910
use rustc_session::{declare_lint_pass, declare_tool_lint};
10-
use rustc_span::{MultiSpan, Span};
11+
use rustc_span::Span;
1112

1213
declare_clippy_lint! {
1314
/// ### What it does
@@ -129,8 +130,8 @@ fn check_arm<'tcx>(
129130
&msg,
130131
|diag| {
131132
let mut help_span = MultiSpan::from_spans(vec![binding_span, inner_then_pat.span]);
132-
help_span.push_span_label(binding_span, "replace this binding".into());
133-
help_span.push_span_label(inner_then_pat.span, "with this pattern".into());
133+
help_span.push_span_label(binding_span, "replace this binding");
134+
help_span.push_span_label(inner_then_pat.span, "with this pattern");
134135
diag.span_help(help_span, "the outer pattern can be modified to include the inner pattern");
135136
},
136137
);

clippy_lints/src/doc.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc_ast::token::CommentKind;
1111
use rustc_data_structures::fx::FxHashSet;
1212
use rustc_data_structures::sync::Lrc;
1313
use rustc_errors::emitter::EmitterWriter;
14-
use rustc_errors::{Applicability, Handler, SuggestionStyle};
14+
use rustc_errors::{Applicability, Handler, MultiSpan, SuggestionStyle};
1515
use rustc_hir as hir;
1616
use rustc_hir::intravisit::{self, Visitor};
1717
use rustc_hir::{AnonConst, Expr};
@@ -25,7 +25,7 @@ use rustc_session::parse::ParseSess;
2525
use rustc_session::{declare_tool_lint, impl_lint_pass};
2626
use rustc_span::def_id::LocalDefId;
2727
use rustc_span::edition::Edition;
28-
use rustc_span::source_map::{BytePos, FilePathMapping, MultiSpan, SourceMap, Span};
28+
use rustc_span::source_map::{BytePos, FilePathMapping, SourceMap, Span};
2929
use rustc_span::{sym, FileName, Pos};
3030
use std::io;
3131
use std::ops::Range;
@@ -621,7 +621,19 @@ fn check_code(cx: &LateContext<'_>, text: &str, edition: Edition, span: Span) {
621621
let filename = FileName::anon_source_code(&code);
622622

623623
let sm = Lrc::new(SourceMap::new(FilePathMapping::empty()));
624-
let emitter = EmitterWriter::new(Box::new(io::sink()), None, false, false, false, None, false);
624+
let fallback_bundle =
625+
rustc_errors::fallback_fluent_bundle(false).expect("failed to load fallback fluent bundle");
626+
let emitter = EmitterWriter::new(
627+
Box::new(io::sink()),
628+
None,
629+
None,
630+
fallback_bundle,
631+
false,
632+
false,
633+
false,
634+
None,
635+
false,
636+
);
625637
let handler = Handler::with_emitter(false, None, Box::new(emitter));
626638
let sess = ParseSess::with_span_handler(handler, sm);
627639

clippy_lints/src/implicit_saturating_sub.rs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use clippy_utils::{higher, peel_blocks_with_stmt, SpanlessEq};
33
use if_chain::if_chain;
44
use rustc_ast::ast::LitKind;
55
use rustc_errors::Applicability;
6-
use rustc_hir::{lang_items::LangItem, BinOpKind, Expr, ExprKind, QPath};
6+
use rustc_hir::{BinOpKind, Expr, ExprKind, QPath};
77
use rustc_lint::{LateContext, LateLintPass};
88
use rustc_session::{declare_lint_pass, declare_tool_lint};
99

@@ -82,14 +82,6 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitSaturatingSub {
8282

8383
// Get the variable name
8484
let var_name = ares_path.segments[0].ident.name.as_str();
85-
const INT_TYPES: [LangItem; 5] = [
86-
LangItem::I8,
87-
LangItem::I16,
88-
LangItem::I32,
89-
LangItem::I64,
90-
LangItem::Isize
91-
];
92-
9385
match cond_num_val.kind {
9486
ExprKind::Lit(ref cond_lit) => {
9587
// Check if the constant is zero
@@ -105,8 +97,8 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitSaturatingSub {
10597
if name.ident.as_str() == "MIN";
10698
if let Some(const_id) = cx.typeck_results().type_dependent_def_id(cond_num_val.hir_id);
10799
if let Some(impl_id) = cx.tcx.impl_of_method(const_id);
108-
let mut int_ids = INT_TYPES.iter().filter_map(|&ty| cx.tcx.lang_items().require(ty).ok());
109-
if int_ids.any(|int_id| int_id == impl_id);
100+
if let None = cx.tcx.impl_trait_ref(impl_id); // An inherent impl
101+
if cx.tcx.type_of(impl_id).is_integral();
110102
then {
111103
print_lint_and_sugg(cx, var_name, expr)
112104
}
@@ -118,8 +110,8 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitSaturatingSub {
118110
if name.ident.as_str() == "min_value";
119111
if let Some(func_id) = cx.typeck_results().type_dependent_def_id(func.hir_id);
120112
if let Some(impl_id) = cx.tcx.impl_of_method(func_id);
121-
let mut int_ids = INT_TYPES.iter().filter_map(|&ty| cx.tcx.lang_items().require(ty).ok());
122-
if int_ids.any(|int_id| int_id == impl_id);
113+
if let None = cx.tcx.impl_trait_ref(impl_id); // An inherent impl
114+
if cx.tcx.type_of(impl_id).is_integral();
123115
then {
124116
print_lint_and_sugg(cx, var_name, expr)
125117
}

clippy_lints/src/loops/needless_collect.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ use clippy_utils::ty::is_type_diagnostic_item;
66
use clippy_utils::{can_move_expr_to_closure, is_trait_method, path_to_local, path_to_local_id, CaptureKind};
77
use if_chain::if_chain;
88
use rustc_data_structures::fx::FxHashMap;
9-
use rustc_errors::Applicability;
9+
use rustc_errors::{Applicability, MultiSpan};
1010
use rustc_hir::intravisit::{walk_block, walk_expr, Visitor};
1111
use rustc_hir::{Block, Expr, ExprKind, HirId, HirIdSet, Local, Mutability, Node, PatKind, Stmt, StmtKind};
1212
use rustc_lint::LateContext;
1313
use rustc_middle::hir::nested_filter;
1414
use rustc_middle::ty::subst::GenericArgKind;
1515
use rustc_middle::ty::{self, Ty};
1616
use rustc_span::sym;
17-
use rustc_span::{MultiSpan, Span};
17+
use rustc_span::Span;
1818

1919
const NEEDLESS_COLLECT_MSG: &str = "avoid using `collect()` when not needed";
2020

@@ -102,7 +102,7 @@ fn check_needless_collect_indirect_usage<'tcx>(expr: &'tcx Expr<'_>, cx: &LateCo
102102

103103
// Suggest replacing iter_call with iter_replacement, and removing stmt
104104
let mut span = MultiSpan::from_span(method_name.ident.span);
105-
span.push_span_label(iter_call.span, "the iterator could be used here instead".into());
105+
span.push_span_label(iter_call.span, "the iterator could be used here instead");
106106
span_lint_hir_and_then(
107107
cx,
108108
super::NEEDLESS_COLLECT,

clippy_lints/src/loops/needless_range_loop.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ impl<'a, 'tcx> VarVisitor<'a, 'tcx> {
273273
}
274274
return false; // no need to walk further *on the variable*
275275
}
276-
Res::Def(DefKind::Static | DefKind::Const, ..) => {
276+
Res::Def(DefKind::Static (_)| DefKind::Const, ..) => {
277277
if index_used_directly {
278278
self.indexed_directly.insert(
279279
seqvar.segments[0].ident.name,

clippy_lints/src/loops/while_immutable_condition.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ impl<'a, 'tcx> VarCollectorVisitor<'a, 'tcx> {
104104
Res::Local(hir_id) => {
105105
self.ids.insert(hir_id);
106106
},
107-
Res::Def(DefKind::Static, def_id) => {
107+
Res::Def(DefKind::Static(_), def_id) => {
108108
let mutable = self.cx.tcx.is_mutable_static(def_id);
109109
self.def_ids.insert(def_id, mutable);
110110
},

clippy_lints/src/methods/expect_fun_call.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ pub(super) fn check<'tcx>(
9393
},
9494
hir::ExprKind::Path(ref p) => matches!(
9595
cx.qpath_res(p, arg.hir_id),
96-
hir::def::Res::Def(hir::def::DefKind::Const | hir::def::DefKind::Static, _)
96+
hir::def::Res::Def(hir::def::DefKind::Const | hir::def::DefKind::Static(_), _)
9797
),
9898
_ => false,
9999
}

clippy_lints/src/methods/implicit_clone.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,11 @@ pub fn is_clone_like(cx: &LateContext<'_>, method_name: &str, method_def_id: hir
4848
"to_os_string" => is_diag_item_method(cx, method_def_id, sym::OsStr),
4949
"to_owned" => is_diag_trait_item(cx, method_def_id, sym::ToOwned),
5050
"to_path_buf" => is_diag_item_method(cx, method_def_id, sym::Path),
51-
"to_vec" => {
52-
cx.tcx
53-
.impl_of_method(method_def_id)
54-
.map(|impl_did| Some(impl_did) == cx.tcx.lang_items().slice_alloc_impl())
55-
== Some(true)
56-
},
51+
"to_vec" => cx
52+
.tcx
53+
.impl_of_method(method_def_id)
54+
.filter(|&impl_did| cx.tcx.type_of(impl_did).is_slice() && cx.tcx.impl_trait_ref(impl_did).is_none())
55+
.is_some(),
5756
_ => false,
5857
}
5958
}

clippy_lints/src/methods/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2488,7 +2488,6 @@ fn check_methods<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, msrv: Optio
24882488
Some(("err", [recv], err_span)) => err_expect::check(cx, expr, recv, msrv, span, err_span),
24892489
_ => expect_used::check(cx, expr, recv),
24902490
},
2491-
24922491
("extend", [arg]) => {
24932492
string_extend_chars::check(cx, expr, recv, arg);
24942493
extend_with_drain::check(cx, expr, recv, arg);
@@ -2630,7 +2629,6 @@ fn check_methods<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, msrv: Optio
26302629
unnecessary_lazy_eval::check(cx, expr, recv, u_arg, "unwrap_or");
26312630
},
26322631
},
2633-
26342632
_ => {},
26352633
}
26362634
}

clippy_lints/src/methods/suspicious_splitn.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ pub(super) fn check(cx: &LateContext<'_>, method_name: &str, expr: &Expr<'_>, se
1212
if count <= 1;
1313
if let Some(call_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id);
1414
if let Some(impl_id) = cx.tcx.impl_of_method(call_id);
15-
let lang_items = cx.tcx.lang_items();
16-
if lang_items.slice_impl() == Some(impl_id) || lang_items.str_impl() == Some(impl_id);
15+
if cx.tcx.impl_trait_ref(impl_id).is_none();
16+
let self_ty = cx.tcx.type_of(impl_id);
17+
if self_ty.is_slice() || self_ty.is_str();
1718
then {
1819
// Ignore empty slice and string literals when used with a literal count.
1920
if matches!(self_arg.kind, ExprKind::Array([]))
2021
|| matches!(self_arg.kind, ExprKind::Lit(Spanned { node: LitKind::Str(s, _), .. }) if s.is_empty())
21-
2222
{
2323
return;
2424
}
@@ -28,7 +28,7 @@ pub(super) fn check(cx: &LateContext<'_>, method_name: &str, expr: &Expr<'_>, se
2828
"the resulting iterator will always return `None`")
2929
} else {
3030
(format!("`{}` called with `1` split", method_name),
31-
if lang_items.slice_impl() == Some(impl_id) {
31+
if self_ty.is_slice() {
3232
"the resulting iterator will always return the entire slice followed by `None`"
3333
} else {
3434
"the resulting iterator will always return the entire string followed by `None`"

clippy_lints/src/missing_const_for_fn.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingConstForFn {
148148

149149
if let Err((span, err)) = is_min_const_fn(cx.tcx, mir, self.msrv.as_ref()) {
150150
if cx.tcx.is_const_fn_raw(def_id.to_def_id()) {
151-
cx.tcx.sess.span_err(span, &err);
151+
cx.tcx.sess.span_err(span, err.as_ref());
152152
}
153153
} else {
154154
span_lint(cx, MISSING_CONST_FOR_FN, span, "this could be a `const fn`");

clippy_lints/src/needless_pass_by_value.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,11 +235,12 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue {
235235
for (span, suggestion) in clone_spans {
236236
diag.span_suggestion(
237237
span,
238-
&snippet_opt(cx, span)
238+
snippet_opt(cx, span)
239239
.map_or(
240240
"change the call to".into(),
241241
|x| Cow::from(format!("change `{}` to", x)),
242-
),
242+
)
243+
.as_ref(),
243244
suggestion.into(),
244245
Applicability::Unspecified,
245246
);
@@ -264,11 +265,12 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue {
264265
for (span, suggestion) in clone_spans {
265266
diag.span_suggestion(
266267
span,
267-
&snippet_opt(cx, span)
268+
snippet_opt(cx, span)
268269
.map_or(
269270
"change the call to".into(),
270271
|x| Cow::from(format!("change `{}` to", x))
271-
),
272+
)
273+
.as_ref(),
272274
suggestion.into(),
273275
Applicability::Unspecified,
274276
);

clippy_lints/src/ptr.rs

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use clippy_utils::source::snippet_opt;
55
use clippy_utils::ty::expr_sig;
66
use clippy_utils::{get_expr_use_or_unification_node, is_lint_allowed, path_def_id, path_to_local, paths};
77
use if_chain::if_chain;
8-
use rustc_errors::Applicability;
8+
use rustc_errors::{Applicability, MultiSpan};
99
use rustc_hir::def_id::DefId;
1010
use rustc_hir::hir_id::HirIdMap;
1111
use rustc_hir::intravisit::{walk_expr, Visitor};
@@ -16,11 +16,11 @@ use rustc_hir::{
1616
};
1717
use rustc_lint::{LateContext, LateLintPass};
1818
use rustc_middle::hir::nested_filter;
19-
use rustc_middle::ty::{self, AssocItems, AssocKind, Ty};
19+
use rustc_middle::ty::{self, Ty};
2020
use rustc_session::{declare_lint_pass, declare_tool_lint};
2121
use rustc_span::source_map::Span;
22+
use rustc_span::sym;
2223
use rustc_span::symbol::Symbol;
23-
use rustc_span::{sym, MultiSpan};
2424
use std::fmt;
2525
use std::iter;
2626

@@ -308,7 +308,6 @@ struct PtrArg<'tcx> {
308308
method_renames: &'static [(&'static str, &'static str)],
309309
ref_prefix: RefPrefix,
310310
deref_ty: DerefTy<'tcx>,
311-
deref_assoc_items: Option<(DefId, &'tcx AssocItems<'tcx>)>,
312311
}
313312
impl PtrArg<'_> {
314313
fn build_msg(&self) -> String {
@@ -411,7 +410,7 @@ fn check_fn_args<'cx, 'tcx: 'cx>(
411410
if params.get(i).map_or(true, |p| !is_lint_allowed(cx, PTR_ARG, p.hir_id));
412411

413412
then {
414-
let (method_renames, deref_ty, deref_impl_id) = match cx.tcx.get_diagnostic_name(adt.did()) {
413+
let (method_renames, deref_ty) = match cx.tcx.get_diagnostic_name(adt.did()) {
415414
Some(sym::Vec) => (
416415
[("clone", ".to_owned()")].as_slice(),
417416
DerefTy::Slice(
@@ -424,17 +423,14 @@ fn check_fn_args<'cx, 'tcx: 'cx>(
424423
}),
425424
substs.type_at(0),
426425
),
427-
cx.tcx.lang_items().slice_impl()
428426
),
429427
Some(sym::String) => (
430428
[("clone", ".to_owned()"), ("as_str", "")].as_slice(),
431429
DerefTy::Str,
432-
cx.tcx.lang_items().str_impl()
433430
),
434431
Some(sym::PathBuf) => (
435432
[("clone", ".to_path_buf()"), ("as_path", "")].as_slice(),
436433
DerefTy::Path,
437-
None,
438434
),
439435
Some(sym::Cow) if mutability == Mutability::Not => {
440436
let ty_name = name.args
@@ -470,7 +466,6 @@ fn check_fn_args<'cx, 'tcx: 'cx>(
470466
mutability,
471467
},
472468
deref_ty,
473-
deref_assoc_items: deref_impl_id.map(|id| (id, cx.tcx.associated_items(id))),
474469
});
475470
}
476471
}
@@ -606,16 +601,7 @@ fn check_ptr_arg_usage<'tcx>(cx: &LateContext<'tcx>, body: &'tcx Body<'_>, args:
606601
},
607602
// If the types match check for methods which exist on both types. e.g. `Vec::len` and
608603
// `slice::len`
609-
ty::Adt(def, _)
610-
if def.did() == args.ty_did
611-
&& (i != 0
612-
|| self.cx.tcx.trait_of_item(id).is_some()
613-
|| !args.deref_assoc_items.map_or(false, |(id, items)| {
614-
items
615-
.find_by_name_and_kind(self.cx.tcx, name.ident, AssocKind::Fn, id)
616-
.is_some()
617-
})) =>
618-
{
604+
ty::Adt(def, _) if def.did() == args.ty_did => {
619605
set_skip_flag();
620606
},
621607
_ => (),

0 commit comments

Comments
 (0)