Skip to content

Commit 6220dff

Browse files
committed
Auto merge of rust-lang#5922 - flip1995:rustup, r=flip1995
Rustup r? @ghost changelog: none
2 parents 9360ca6 + c680602 commit 6220dff

29 files changed

+138
-156
lines changed

clippy_lints/src/attrs.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ use crate::utils::{
55
span_lint_and_sugg, span_lint_and_then, without_block_comments,
66
};
77
use if_chain::if_chain;
8-
use rustc_ast::ast::{AttrKind, AttrStyle, Attribute, Lit, LitKind, MetaItemKind, NestedMetaItem};
98
use rustc_ast::util::lev_distance::find_best_match_for_name;
9+
use rustc_ast::{AttrKind, AttrStyle, Attribute, Lit, LitKind, MetaItemKind, NestedMetaItem};
1010
use rustc_errors::Applicability;
1111
use rustc_hir::{
1212
Block, Expr, ExprKind, ImplItem, ImplItemKind, Item, ItemKind, StmtKind, TraitFn, TraitItem, TraitItemKind,
@@ -570,7 +570,7 @@ declare_lint_pass!(EarlyAttributes => [
570570
]);
571571

572572
impl EarlyLintPass for EarlyAttributes {
573-
fn check_item(&mut self, cx: &EarlyContext<'_>, item: &rustc_ast::ast::Item) {
573+
fn check_item(&mut self, cx: &EarlyContext<'_>, item: &rustc_ast::Item) {
574574
check_empty_line_after_outer_attr(cx, item);
575575
}
576576

@@ -580,7 +580,7 @@ impl EarlyLintPass for EarlyAttributes {
580580
}
581581
}
582582

583-
fn check_empty_line_after_outer_attr(cx: &EarlyContext<'_>, item: &rustc_ast::ast::Item) {
583+
fn check_empty_line_after_outer_attr(cx: &EarlyContext<'_>, item: &rustc_ast::Item) {
584584
for attr in &item.attrs {
585585
let attr_item = if let AttrKind::Normal(ref attr) = attr.kind {
586586
attr

clippy_lints/src/default_trait_access.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ impl<'tcx> LateLintPass<'tcx> for DefaultTraitAccess {
6868
);
6969
}
7070
},
71-
QPath::TypeRelative(..) => {},
71+
QPath::TypeRelative(..) | QPath::LangItem(..) => {},
7272
}
7373
}
7474
}

clippy_lints/src/indexing_slicing.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ impl<'tcx> LateLintPass<'tcx> for IndexingSlicing {
8989
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
9090
if let ExprKind::Index(ref array, ref index) = &expr.kind {
9191
let ty = cx.typeck_results().expr_ty(array);
92-
if let Some(range) = higher::range(cx, index) {
92+
if let Some(range) = higher::range(index) {
9393
// Ranged indexes, i.e., &x[n..m], &x[n..], &x[..n] and &x[..]
9494
if let ty::Array(_, s) = ty.kind {
9595
let size: u128 = if let Some(size) = s.try_eval_usize(cx.tcx, cx.param_env) {

clippy_lints/src/infinite_iter.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ fn is_infinite(cx: &LateContext<'_>, expr: &Expr<'_>) -> Finiteness {
171171
Finite
172172
}
173173
},
174-
ExprKind::Struct(..) => higher::range(cx, expr).map_or(false, |r| r.end.is_none()).into(),
174+
ExprKind::Struct(..) => higher::range(expr).map_or(false, |r| r.end.is_none()).into(),
175175
_ => Finite,
176176
}
177177
}

clippy_lints/src/len_zero.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ fn check_len(
262262
fn has_is_empty(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
263263
/// Special case ranges until `range_is_empty` is stabilized. See issue 3807.
264264
fn should_skip_range(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
265-
higher::range(cx, expr).map_or(false, |_| {
265+
higher::range(expr).map_or(false, |_| {
266266
!cx.tcx
267267
.features()
268268
.declared_lib_features

clippy_lints/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ pub fn register_pre_expansion_lints(store: &mut rustc_lint::LintStore) {
341341
}
342342

343343
#[doc(hidden)]
344-
pub fn read_conf(args: &[rustc_ast::ast::NestedMetaItem], sess: &Session) -> Conf {
344+
pub fn read_conf(args: &[rustc_ast::NestedMetaItem], sess: &Session) -> Conf {
345345
use std::path::Path;
346346
match utils::conf::file_from_args(args) {
347347
Ok(file_name) => {

clippy_lints/src/loops.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1003,7 +1003,7 @@ fn detect_manual_memcpy<'tcx>(
10031003
start: Some(start),
10041004
end: Some(end),
10051005
limits,
1006-
}) = higher::range(cx, arg)
1006+
}) = higher::range(arg)
10071007
{
10081008
// the var must be a single name
10091009
if let PatKind::Binding(_, canonical_id, _, _) = pat.kind {
@@ -1197,7 +1197,7 @@ fn check_for_loop_range<'tcx>(
11971197
start: Some(start),
11981198
ref end,
11991199
limits,
1200-
}) = higher::range(cx, arg)
1200+
}) = higher::range(arg)
12011201
{
12021202
// the var must be a single name
12031203
if let PatKind::Binding(_, canonical_id, ident, _) = pat.kind {
@@ -1699,7 +1699,7 @@ fn check_for_mut_range_bound(cx: &LateContext<'_>, arg: &Expr<'_>, body: &Expr<'
16991699
start: Some(start),
17001700
end: Some(end),
17011701
..
1702-
}) = higher::range(cx, arg)
1702+
}) = higher::range(arg)
17031703
{
17041704
let mut_ids = vec![check_for_mutability(cx, start), check_for_mutability(cx, end)];
17051705
if mut_ids[0].is_some() || mut_ids[1].is_some() {

clippy_lints/src/match_on_vec_items.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
use crate::utils::{self, is_type_diagnostic_item, match_type, snippet, span_lint_and_sugg, walk_ptrs_ty};
1+
use crate::utils::walk_ptrs_ty;
2+
use crate::utils::{is_type_diagnostic_item, is_type_lang_item, snippet, span_lint_and_sugg};
23
use if_chain::if_chain;
34
use rustc_errors::Applicability;
4-
use rustc_hir::{Expr, ExprKind, MatchSource};
5+
use rustc_hir::{Expr, ExprKind, LangItem, MatchSource};
56
use rustc_lint::{LateContext, LateLintPass, LintContext};
67
use rustc_middle::lint::in_external_macro;
78
use rustc_session::{declare_lint_pass, declare_tool_lint};
@@ -96,5 +97,5 @@ fn is_vector(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
9697
fn is_full_range(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
9798
let ty = cx.typeck_results().expr_ty(expr);
9899
let ty = walk_ptrs_ty(ty);
99-
match_type(cx, ty, &utils::paths::RANGE_FULL)
100+
is_type_lang_item(cx, ty, LangItem::RangeFull)
100101
}

clippy_lints/src/methods/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2364,7 +2364,7 @@ fn lint_iter_next<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>, iter_
23642364
if_chain! {
23652365
if let hir::ExprKind::Index(ref caller_var, ref index_expr) = &caller_expr.kind;
23662366
if let Some(higher::Range { start: Some(start_expr), end: None, limits: ast::RangeLimits::HalfOpen })
2367-
= higher::range(cx, index_expr);
2367+
= higher::range(index_expr);
23682368
if let hir::ExprKind::Lit(ref start_lit) = &start_expr.kind;
23692369
if let ast::LitKind::Int(start_idx, _) = start_lit.node;
23702370
then {

clippy_lints/src/misc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ impl<'tcx> LateLintPass<'tcx> for MiscLints {
433433
return;
434434
}
435435
let binding = match expr.kind {
436-
ExprKind::Path(ref qpath) => {
436+
ExprKind::Path(ref qpath) if !matches!(qpath, hir::QPath::LangItem(..)) => {
437437
let binding = last_path_segment(qpath).ident.as_str();
438438
if binding.starts_with('_') &&
439439
!binding.starts_with("__") &&

clippy_lints/src/ranges.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ impl<'tcx> LateLintPass<'tcx> for Ranges {
147147
if let ExprKind::MethodCall(ref iter_path, _, ref iter_args , _) = *iter;
148148
if iter_path.ident.name == sym!(iter);
149149
// range expression in `.zip()` call: `0..x.len()`
150-
if let Some(higher::Range { start: Some(start), end: Some(end), .. }) = higher::range(cx, zip_arg);
150+
if let Some(higher::Range { start: Some(start), end: Some(end), .. }) = higher::range(zip_arg);
151151
if is_integer_const(cx, start, 0);
152152
// `.len()` call
153153
if let ExprKind::MethodCall(ref len_path, _, ref len_args, _) = end.kind;
@@ -180,7 +180,7 @@ fn check_exclusive_range_plus_one(cx: &LateContext<'_>, expr: &Expr<'_>) {
180180
start,
181181
end: Some(end),
182182
limits: RangeLimits::HalfOpen
183-
}) = higher::range(cx, expr);
183+
}) = higher::range(expr);
184184
if let Some(y) = y_plus_one(cx, end);
185185
then {
186186
let span = if expr.span.from_expansion() {
@@ -225,7 +225,7 @@ fn check_exclusive_range_plus_one(cx: &LateContext<'_>, expr: &Expr<'_>) {
225225
// inclusive range minus one: `x..=(y-1)`
226226
fn check_inclusive_range_minus_one(cx: &LateContext<'_>, expr: &Expr<'_>) {
227227
if_chain! {
228-
if let Some(higher::Range { start, end: Some(end), limits: RangeLimits::Closed }) = higher::range(cx, expr);
228+
if let Some(higher::Range { start, end: Some(end), limits: RangeLimits::Closed }) = higher::range(expr);
229229
if let Some(y) = y_minus_one(cx, end);
230230
then {
231231
span_lint_and_then(
@@ -279,7 +279,7 @@ fn check_reversed_empty_range(cx: &LateContext<'_>, expr: &Expr<'_>) {
279279
}
280280

281281
if_chain! {
282-
if let Some(higher::Range { start: Some(start), end: Some(end), limits }) = higher::range(cx, expr);
282+
if let Some(higher::Range { start: Some(start), end: Some(end), limits }) = higher::range(expr);
283283
let ty = cx.typeck_results().expr_ty(start);
284284
if let ty::Int(_) | ty::Uint(_) = ty.kind;
285285
if let Some((start_idx, _)) = constant(cx, cx.typeck_results(), start);

clippy_lints/src/single_component_path_imports.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::utils::{in_macro, span_lint_and_sugg};
22
use if_chain::if_chain;
3-
use rustc_ast::ast::{Item, ItemKind, UseTreeKind};
3+
use rustc_ast::{Item, ItemKind, UseTreeKind};
44
use rustc_errors::Applicability;
55
use rustc_lint::{EarlyContext, EarlyLintPass};
66
use rustc_session::{declare_lint_pass, declare_tool_lint};

clippy_lints/src/strings.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ declare_lint_pass!(StringLitAsBytes => [STRING_LIT_AS_BYTES]);
161161
impl<'tcx> LateLintPass<'tcx> for StringLitAsBytes {
162162
fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) {
163163
use crate::utils::{snippet, snippet_with_applicability};
164-
use rustc_ast::ast::LitKind;
164+
use rustc_ast::LitKind;
165165

166166
if_chain! {
167167
if let ExprKind::MethodCall(path, _, args, _) = &e.kind;

clippy_lints/src/transmute.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::utils::{
33
span_lint_and_then, sugg,
44
};
55
use if_chain::if_chain;
6-
use rustc_ast::ast;
6+
use rustc_ast as ast;
77
use rustc_errors::Applicability;
88
use rustc_hir::{Expr, ExprKind, GenericArg, Mutability, QPath, TyKind, UnOp};
99
use rustc_lint::{LateContext, LateLintPass};

clippy_lints/src/transmuting_null.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::consts::{constant_context, Constant};
22
use crate::utils::{match_qpath, paths, span_lint};
33
use if_chain::if_chain;
4-
use rustc_ast::ast::LitKind;
4+
use rustc_ast::LitKind;
55
use rustc_hir::{Expr, ExprKind};
66
use rustc_lint::{LateContext, LateLintPass, LintContext};
77
use rustc_middle::lint::in_external_macro;

clippy_lints/src/try_err.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::utils::{
44
};
55
use if_chain::if_chain;
66
use rustc_errors::Applicability;
7-
use rustc_hir::{Expr, ExprKind, MatchSource};
7+
use rustc_hir::{Expr, ExprKind, LangItem, MatchSource, QPath};
88
use rustc_lint::{LateContext, LateLintPass};
99
use rustc_middle::lint::in_external_macro;
1010
use rustc_middle::ty::{self, Ty};
@@ -62,7 +62,7 @@ impl<'tcx> LateLintPass<'tcx> for TryErr {
6262
if let ExprKind::Match(ref match_arg, _, MatchSource::TryDesugar) = expr.kind;
6363
if let ExprKind::Call(ref match_fun, ref try_args) = match_arg.kind;
6464
if let ExprKind::Path(ref match_fun_path) = match_fun.kind;
65-
if match_qpath(match_fun_path, &paths::TRY_INTO_RESULT);
65+
if matches!(match_fun_path, QPath::LangItem(LangItem::TryIntoResult, _));
6666
if let Some(ref try_arg) = try_args.get(0);
6767
if let ExprKind::Call(ref err_fun, ref err_args) = try_arg.kind;
6868
if let Some(ref err_arg) = err_args.get(0);

clippy_lints/src/types.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::cmp::Ordering;
55
use std::collections::BTreeMap;
66

77
use if_chain::if_chain;
8-
use rustc_ast::ast::{FloatTy, IntTy, LitFloatType, LitIntType, LitKind, UintTy};
8+
use rustc_ast::{FloatTy, IntTy, LitFloatType, LitIntType, LitKind, UintTy};
99
use rustc_errors::{Applicability, DiagnosticBuilder};
1010
use rustc_hir as hir;
1111
use rustc_hir::intravisit::{walk_body, walk_expr, walk_ty, FnKind, NestedVisitorMap, Visitor};
@@ -486,6 +486,7 @@ impl Types {
486486
}
487487
}
488488
},
489+
QPath::LangItem(..) => {},
489490
}
490491
},
491492
TyKind::Rptr(ref lt, ref mut_ty) => self.check_ty_rptr(cx, hir_ty, is_local, lt, mut_ty),

clippy_lints/src/unnested_or_patterns.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
use crate::utils::ast_utils::{eq_field_pat, eq_id, eq_pat, eq_path};
44
use crate::utils::{over, span_lint_and_then};
5-
use rustc_ast::ast::{self, Pat, PatKind, PatKind::*, DUMMY_NODE_ID};
65
use rustc_ast::mut_visit::*;
76
use rustc_ast::ptr::P;
7+
use rustc_ast::{self as ast, Pat, PatKind, PatKind::*, DUMMY_NODE_ID};
88
use rustc_ast_pretty::pprust;
99
use rustc_errors::Applicability;
1010
use rustc_lint::{EarlyContext, EarlyLintPass};

clippy_lints/src/unused_io_amount.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::utils::{is_try, match_qpath, match_trait_method, paths, span_lint};
1+
use crate::utils::{is_try, match_trait_method, paths, span_lint};
22
use rustc_hir as hir;
33
use rustc_lint::{LateContext, LateLintPass};
44
use rustc_session::{declare_lint_pass, declare_tool_lint};
@@ -42,10 +42,11 @@ impl<'tcx> LateLintPass<'tcx> for UnusedIoAmount {
4242
match expr.kind {
4343
hir::ExprKind::Match(ref res, _, _) if is_try(expr).is_some() => {
4444
if let hir::ExprKind::Call(ref func, ref args) = res.kind {
45-
if let hir::ExprKind::Path(ref path) = func.kind {
46-
if match_qpath(path, &paths::TRY_INTO_RESULT) && args.len() == 1 {
47-
check_method_call(cx, &args[0], expr);
48-
}
45+
if matches!(
46+
func.kind,
47+
hir::ExprKind::Path(hir::QPath::LangItem(hir::LangItem::TryIntoResult, _))
48+
) {
49+
check_method_call(cx, &args[0], expr);
4950
}
5051
} else {
5152
check_method_call(cx, res, expr);

clippy_lints/src/utils/ast_utils.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
#![allow(clippy::similar_names, clippy::wildcard_imports, clippy::enum_glob_use)]
66

77
use crate::utils::{both, over};
8-
use rustc_ast::ast::{self, *};
98
use rustc_ast::ptr::P;
9+
use rustc_ast::{self as ast, *};
1010
use rustc_span::symbol::Ident;
1111
use std::mem;
1212

clippy_lints/src/utils/author.rs

+11-3
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,16 @@ impl PrintVisitor {
175175
}
176176

177177
fn print_qpath(&mut self, path: &QPath<'_>) {
178-
print!(" if match_qpath({}, &[", self.current);
179-
print_path(path, &mut true);
180-
println!("]);");
178+
if let QPath::LangItem(lang_item, _) = *path {
179+
println!(
180+
" if matches!({}, QPath::LangItem(LangItem::{:?}, _));",
181+
self.current, lang_item,
182+
);
183+
} else {
184+
print!(" if match_qpath({}, &[", self.current);
185+
print_path(path, &mut true);
186+
println!("]);");
187+
}
181188
}
182189
}
183190

@@ -760,5 +767,6 @@ fn print_path(path: &QPath<'_>, first: &mut bool) {
760767
},
761768
ref other => print!("/* unimplemented: {:?}*/", other),
762769
},
770+
QPath::LangItem(..) => panic!("print_path: called for lang item qpath"),
763771
}
764772
}

0 commit comments

Comments
 (0)