Skip to content

Commit c6a577e

Browse files
committed
Merge remote-tracking branch 'upstream/master' into rustup
2 parents 53ce1dd + 295fe28 commit c6a577e

14 files changed

+110
-32
lines changed

clippy_lints/src/future_not_send.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,8 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend {
9292
|db| {
9393
cx.tcx.infer_ctxt().enter(|infcx| {
9494
for FulfillmentError { obligation, .. } in send_errors {
95-
infcx.maybe_note_obligation_cause_for_async_await(
96-
db,
97-
&obligation,
98-
);
99-
if let Trait(trait_pred, _) =
100-
obligation.predicate.skip_binders()
101-
{
95+
infcx.maybe_note_obligation_cause_for_async_await(db, &obligation);
96+
if let Trait(trait_pred, _) = obligation.predicate.skip_binders() {
10297
db.note(&format!(
10398
"`{}` doesn't implement `{}`",
10499
trait_pred.self_ty(),

clippy_lints/src/loops.rs

+33-1
Original file line numberDiff line numberDiff line change
@@ -2950,7 +2950,7 @@ fn check_needless_collect_indirect_usage<'tcx>(expr: &'tcx Expr<'_>, cx: &LateCo
29502950
for ref stmt in block.stmts {
29512951
if_chain! {
29522952
if let StmtKind::Local(
2953-
Local { pat: Pat { kind: PatKind::Binding(_, _, ident, .. ), .. },
2953+
Local { pat: Pat { hir_id: pat_id, kind: PatKind::Binding(_, _, ident, .. ), .. },
29542954
init: Some(ref init_expr), .. }
29552955
) = stmt.kind;
29562956
if let ExprKind::MethodCall(ref method_name, _, &[ref iter_source], ..) = init_expr.kind;
@@ -2964,6 +2964,16 @@ fn check_needless_collect_indirect_usage<'tcx>(expr: &'tcx Expr<'_>, cx: &LateCo
29642964
if let Some(iter_calls) = detect_iter_and_into_iters(block, *ident);
29652965
if iter_calls.len() == 1;
29662966
then {
2967+
let mut used_count_visitor = UsedCountVisitor {
2968+
cx,
2969+
id: *pat_id,
2970+
count: 0,
2971+
};
2972+
walk_block(&mut used_count_visitor, block);
2973+
if used_count_visitor.count > 1 {
2974+
return;
2975+
}
2976+
29672977
// Suggest replacing iter_call with iter_replacement, and removing stmt
29682978
let iter_call = &iter_calls[0];
29692979
span_lint_and_then(
@@ -3087,6 +3097,28 @@ impl<'tcx> Visitor<'tcx> for IterFunctionVisitor {
30873097
}
30883098
}
30893099

3100+
struct UsedCountVisitor<'a, 'tcx> {
3101+
cx: &'a LateContext<'tcx>,
3102+
id: HirId,
3103+
count: usize,
3104+
}
3105+
3106+
impl<'a, 'tcx> Visitor<'tcx> for UsedCountVisitor<'a, 'tcx> {
3107+
type Map = Map<'tcx>;
3108+
3109+
fn visit_expr(&mut self, expr: &'tcx Expr<'_>) {
3110+
if same_var(self.cx, expr, self.id) {
3111+
self.count += 1;
3112+
} else {
3113+
walk_expr(self, expr);
3114+
}
3115+
}
3116+
3117+
fn nested_visit_map(&mut self) -> NestedVisitorMap<Self::Map> {
3118+
NestedVisitorMap::OnlyBodies(self.cx.tcx.hir())
3119+
}
3120+
}
3121+
30903122
/// Detect the occurrences of calls to `iter` or `into_iter` for the
30913123
/// given identifier
30923124
fn detect_iter_and_into_iters<'tcx>(block: &'tcx Block<'tcx>, identifier: Ident) -> Option<Vec<IterFunction>> {

clippy_lints/src/types.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use if_chain::if_chain;
88
use rustc_ast::{FloatTy, IntTy, LitFloatType, LitIntType, LitKind, UintTy};
99
use rustc_errors::{Applicability, DiagnosticBuilder};
1010
use rustc_hir as hir;
11+
use rustc_hir::def::Res;
1112
use rustc_hir::intravisit::{walk_body, walk_expr, walk_ty, FnKind, NestedVisitorMap, Visitor};
1213
use rustc_hir::{
1314
BinOpKind, Block, Body, Expr, ExprKind, FnDecl, FnRetTy, FnSig, GenericArg, GenericBounds, GenericParamKind, HirId,
@@ -1632,7 +1633,14 @@ impl<'tcx> LateLintPass<'tcx> for Casts {
16321633
if expr.span.from_expansion() {
16331634
return;
16341635
}
1635-
if let ExprKind::Cast(ref ex, _) = expr.kind {
1636+
if let ExprKind::Cast(ref ex, cast_to) = expr.kind {
1637+
if let TyKind::Path(QPath::Resolved(_, path)) = cast_to.kind {
1638+
if let Res::Def(_, def_id) = path.res {
1639+
if cx.tcx.has_attr(def_id, sym::cfg) || cx.tcx.has_attr(def_id, sym::cfg_attr) {
1640+
return;
1641+
}
1642+
}
1643+
}
16361644
let (cast_from, cast_to) = (cx.typeck_results().expr_ty(ex), cx.typeck_results().expr_ty(expr));
16371645
lint_fn_to_numeric_cast(cx, expr, ex, cast_from, cast_to);
16381646
if let Some(lit) = get_numeric_literal(ex) {

tests/ui/as_conversions.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
1-
#[warn(clippy::as_conversions)]
1+
// aux-build:macro_rules.rs
2+
3+
#![warn(clippy::as_conversions)]
4+
5+
#[macro_use]
6+
extern crate macro_rules;
7+
8+
fn with_external_macro() {
9+
as_conv_with_arg!(0u32 as u64);
10+
as_conv!();
11+
}
212

313
fn main() {
414
let i = 0u32 as u64;
515

616
let j = &i as *const u64 as *mut u64;
17+
18+
with_external_macro();
719
}

tests/ui/as_conversions.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: using a potentially dangerous silent `as` conversion
2-
--> $DIR/as_conversions.rs:4:13
2+
--> $DIR/as_conversions.rs:14:13
33
|
44
LL | let i = 0u32 as u64;
55
| ^^^^^^^^^^^
@@ -8,15 +8,15 @@ LL | let i = 0u32 as u64;
88
= help: consider using a safe wrapper for this conversion
99

1010
error: using a potentially dangerous silent `as` conversion
11-
--> $DIR/as_conversions.rs:6:13
11+
--> $DIR/as_conversions.rs:16:13
1212
|
1313
LL | let j = &i as *const u64 as *mut u64;
1414
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1515
|
1616
= help: consider using a safe wrapper for this conversion
1717

1818
error: using a potentially dangerous silent `as` conversion
19-
--> $DIR/as_conversions.rs:6:13
19+
--> $DIR/as_conversions.rs:16:13
2020
|
2121
LL | let j = &i as *const u64 as *mut u64;
2222
| ^^^^^^^^^^^^^^^^

tests/ui/auxiliary/macro_rules.rs

+14
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,17 @@ macro_rules! ref_arg_function {
7070
fn fun_example(ref _x: usize) {}
7171
};
7272
}
73+
74+
#[macro_export]
75+
macro_rules! as_conv_with_arg {
76+
(0u32 as u64) => {
77+
()
78+
};
79+
}
80+
81+
#[macro_export]
82+
macro_rules! as_conv {
83+
() => {
84+
0u32 as u64
85+
};
86+
}

tests/ui/needless_collect_indirect.rs

+20
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,24 @@ fn main() {
2222
let sample = vec![a.clone(), "b".to_string(), "c".to_string()];
2323
let non_copy_contains = sample.into_iter().collect::<Vec<_>>();
2424
non_copy_contains.contains(&a);
25+
26+
// Fix #5991
27+
let vec_a = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
28+
let vec_b = vec_a.iter().collect::<Vec<_>>();
29+
if vec_b.len() > 3 {}
30+
let other_vec = vec![1, 3, 12, 4, 16, 2];
31+
let we_got_the_same_numbers = other_vec.iter().filter(|item| vec_b.contains(item)).collect::<Vec<_>>();
32+
33+
// Fix #6297
34+
let sample = [1; 5];
35+
let multiple_indirect = sample.iter().collect::<Vec<_>>();
36+
let sample2 = vec![2, 3];
37+
if multiple_indirect.is_empty() {
38+
// do something
39+
} else {
40+
let found = sample2
41+
.iter()
42+
.filter(|i| multiple_indirect.iter().any(|s| **s % **i == 0))
43+
.collect::<Vec<_>>();
44+
}
2545
}

tests/ui/temporary_assignment.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#![warn(clippy::temporary_assignment)]
2-
#![allow(const_item_mutation)]
32

43
use std::ops::{Deref, DerefMut};
54

tests/ui/temporary_assignment.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
error: assignment to temporary
2-
--> $DIR/temporary_assignment.rs:48:5
2+
--> $DIR/temporary_assignment.rs:47:5
33
|
44
LL | Struct { field: 0 }.field = 1;
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
77
= note: `-D clippy::temporary-assignment` implied by `-D warnings`
88

99
error: assignment to temporary
10-
--> $DIR/temporary_assignment.rs:49:5
10+
--> $DIR/temporary_assignment.rs:48:5
1111
|
1212
LL | / MultiStruct {
1313
LL | | structure: Struct { field: 0 },
@@ -17,13 +17,13 @@ LL | | .field = 1;
1717
| |______________^
1818

1919
error: assignment to temporary
20-
--> $DIR/temporary_assignment.rs:54:5
20+
--> $DIR/temporary_assignment.rs:53:5
2121
|
2222
LL | ArrayStruct { array: [0] }.array[0] = 1;
2323
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2424

2525
error: assignment to temporary
26-
--> $DIR/temporary_assignment.rs:55:5
26+
--> $DIR/temporary_assignment.rs:54:5
2727
|
2828
LL | (0, 0).0 = 1;
2929
| ^^^^^^^^^^^^

tests/ui/unnecessary_cast.rs

+3
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,7 @@ fn main() {
2020
foo!(a, i32);
2121
foo!(b, f32);
2222
foo!(c, f64);
23+
24+
// do not lint cast to cfg-dependant type
25+
1 as std::os::raw::c_char;
2326
}

tests/ui/wildcard_enum_match_arm.fixed

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
dead_code,
88
clippy::single_match,
99
clippy::wildcard_in_or_patterns,
10-
clippy::unnested_or_patterns, clippy::diverging_sub_expression
10+
clippy::unnested_or_patterns,
11+
clippy::diverging_sub_expression
1112
)]
1213

1314
use std::io::ErrorKind;

tests/ui/wildcard_enum_match_arm.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
dead_code,
88
clippy::single_match,
99
clippy::wildcard_in_or_patterns,
10-
clippy::unnested_or_patterns, clippy::diverging_sub_expression
10+
clippy::unnested_or_patterns,
11+
clippy::diverging_sub_expression
1112
)]
1213

1314
use std::io::ErrorKind;

tests/ui/wildcard_enum_match_arm.stderr

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: wildcard match will miss any future added variants
2-
--> $DIR/wildcard_enum_match_arm.rs:38:9
2+
--> $DIR/wildcard_enum_match_arm.rs:39:9
33
|
44
LL | _ => eprintln!("Not red"),
55
| ^ help: try this: `Color::Green | Color::Blue | Color::Rgb(..) | Color::Cyan`
@@ -11,25 +11,25 @@ LL | #![deny(clippy::wildcard_enum_match_arm)]
1111
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1212

1313
error: wildcard match will miss any future added variants
14-
--> $DIR/wildcard_enum_match_arm.rs:42:9
14+
--> $DIR/wildcard_enum_match_arm.rs:43:9
1515
|
1616
LL | _not_red => eprintln!("Not red"),
1717
| ^^^^^^^^ help: try this: `_not_red @ Color::Green | _not_red @ Color::Blue | _not_red @ Color::Rgb(..) | _not_red @ Color::Cyan`
1818

1919
error: wildcard match will miss any future added variants
20-
--> $DIR/wildcard_enum_match_arm.rs:46:9
20+
--> $DIR/wildcard_enum_match_arm.rs:47:9
2121
|
2222
LL | not_red => format!("{:?}", not_red),
2323
| ^^^^^^^ help: try this: `not_red @ Color::Green | not_red @ Color::Blue | not_red @ Color::Rgb(..) | not_red @ Color::Cyan`
2424

2525
error: wildcard match will miss any future added variants
26-
--> $DIR/wildcard_enum_match_arm.rs:62:9
26+
--> $DIR/wildcard_enum_match_arm.rs:63:9
2727
|
2828
LL | _ => "No red",
2929
| ^ help: try this: `Color::Red | Color::Green | Color::Blue | Color::Rgb(..) | Color::Cyan`
3030

3131
error: match on non-exhaustive enum doesn't explicitly match all known variants
32-
--> $DIR/wildcard_enum_match_arm.rs:79:9
32+
--> $DIR/wildcard_enum_match_arm.rs:80:9
3333
|
3434
LL | _ => {},
3535
| ^ help: try this: `std::io::ErrorKind::PermissionDenied | std::io::ErrorKind::ConnectionRefused | std::io::ErrorKind::ConnectionReset | std::io::ErrorKind::ConnectionAborted | std::io::ErrorKind::NotConnected | std::io::ErrorKind::AddrInUse | std::io::ErrorKind::AddrNotAvailable | std::io::ErrorKind::BrokenPipe | std::io::ErrorKind::AlreadyExists | std::io::ErrorKind::WouldBlock | std::io::ErrorKind::InvalidInput | std::io::ErrorKind::InvalidData | std::io::ErrorKind::TimedOut | std::io::ErrorKind::WriteZero | std::io::ErrorKind::Interrupted | std::io::ErrorKind::Other | std::io::ErrorKind::UnexpectedEof | _`

util/dev

-7
This file was deleted.

0 commit comments

Comments
 (0)