Skip to content

Commit 766f09f

Browse files
committed
Auto merge of #7503 - flip1995:rustup, r=flip1995
Rustup r? `@ghost` changelog: none
2 parents 92ca25b + 80116f9 commit 766f09f

16 files changed

+70
-48
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "clippy"
3-
version = "0.1.55"
3+
version = "0.1.56"
44
authors = ["The Rust Clippy Developers"]
55
description = "A bunch of helpful lints to avoid common pitfalls in Rust"
66
repository = "https://github.com/rust-lang/rust-clippy"

clippy_lints/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "clippy_lints"
33
# begin automatic update
4-
version = "0.1.55"
4+
version = "0.1.56"
55
# end automatic update
66
authors = ["The Rust Clippy Developers"]
77
description = "A bunch of helpful lints to avoid common pitfalls in Rust"

clippy_lints/src/implicit_hasher.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::collections::BTreeMap;
33

44
use rustc_errors::DiagnosticBuilder;
55
use rustc_hir as hir;
6-
use rustc_hir::intravisit::{walk_body, walk_expr, walk_ty, NestedVisitorMap, Visitor};
6+
use rustc_hir::intravisit::{walk_body, walk_expr, walk_inf, walk_ty, NestedVisitorMap, Visitor};
77
use rustc_hir::{Body, Expr, ExprKind, GenericArg, Item, ItemKind, QPath, TyKind};
88
use rustc_lint::{LateContext, LateLintPass, LintContext};
99
use rustc_middle::hir::map::Map;
@@ -295,6 +295,14 @@ impl<'a, 'tcx> Visitor<'tcx> for ImplicitHasherTypeVisitor<'a, 'tcx> {
295295
walk_ty(self, t);
296296
}
297297

298+
fn visit_infer(&mut self, inf: &'tcx hir::InferArg) {
299+
if let Some(target) = ImplicitHasherType::new(self.cx, &inf.to_ty()) {
300+
self.found.push(target);
301+
}
302+
303+
walk_inf(self, inf);
304+
}
305+
298306
fn nested_visit_map(&mut self) -> NestedVisitorMap<Self::Map> {
299307
NestedVisitorMap::None
300308
}

clippy_lints/src/missing_doc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
121121

122122
fn check_crate(&mut self, cx: &LateContext<'tcx>, krate: &'tcx hir::Crate<'_>) {
123123
let attrs = cx.tcx.hir().attrs(hir::CRATE_HIR_ID);
124-
self.check_missing_docs_attrs(cx, attrs, krate.item.inner, "the", "crate");
124+
self.check_missing_docs_attrs(cx, attrs, krate.module().inner, "the", "crate");
125125
}
126126

127127
fn check_item(&mut self, cx: &LateContext<'tcx>, it: &'tcx hir::Item<'_>) {

clippy_lints/src/types/type_complexity.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use clippy_utils::diagnostics::span_lint;
22
use rustc_hir as hir;
3-
use rustc_hir::intravisit::{walk_ty, NestedVisitorMap, Visitor};
3+
use rustc_hir::intravisit::{walk_inf, walk_ty, NestedVisitorMap, Visitor};
44
use rustc_hir::{GenericParamKind, TyKind};
55
use rustc_lint::LateContext;
66
use rustc_middle::hir::map::Map;
@@ -39,6 +39,11 @@ struct TypeComplexityVisitor {
3939
impl<'tcx> Visitor<'tcx> for TypeComplexityVisitor {
4040
type Map = Map<'tcx>;
4141

42+
fn visit_infer(&mut self, inf: &'tcx hir::InferArg) {
43+
self.score += 1;
44+
walk_inf(self, inf);
45+
}
46+
4247
fn visit_ty(&mut self, ty: &'tcx hir::Ty<'_>) {
4348
let (add_score, sub_nest) = match ty.kind {
4449
// _, &x and *x have only small overhead; don't mess with nesting level

clippy_lints/src/use_self.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_hir::{
88
self as hir,
99
def::{CtorOf, DefKind, Res},
1010
def_id::LocalDefId,
11-
intravisit::{walk_ty, NestedVisitorMap, Visitor},
11+
intravisit::{walk_inf, walk_ty, NestedVisitorMap, Visitor},
1212
Expr, ExprKind, FnRetTy, FnSig, GenericArg, HirId, Impl, ImplItemKind, Item, ItemKind, Path, QPath, TyKind,
1313
};
1414
use rustc_lint::{LateContext, LateLintPass, LintContext};
@@ -264,6 +264,11 @@ struct SkipTyCollector {
264264
impl<'tcx> Visitor<'tcx> for SkipTyCollector {
265265
type Map = Map<'tcx>;
266266

267+
fn visit_infer(&mut self, inf: &hir::InferArg) {
268+
self.types_to_skip.push(inf.hir_id);
269+
270+
walk_inf(self, inf);
271+
}
267272
fn visit_ty(&mut self, hir_ty: &hir::Ty<'_>) {
268273
self.types_to_skip.push(hir_ty.hir_id);
269274

clippy_utils/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "clippy_utils"
3-
version = "0.1.55"
3+
version = "0.1.56"
44
authors = ["The Rust Clippy Developers"]
55
edition = "2018"
66
publish = false

clippy_utils/src/hir_utils.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ impl HirEqInterExpr<'_, '_, '_> {
288288
(GenericArg::Const(l), GenericArg::Const(r)) => self.eq_body(l.value.body, r.value.body),
289289
(GenericArg::Lifetime(l_lt), GenericArg::Lifetime(r_lt)) => Self::eq_lifetime(l_lt, r_lt),
290290
(GenericArg::Type(l_ty), GenericArg::Type(r_ty)) => self.eq_ty(l_ty, r_ty),
291+
(GenericArg::Infer(l_inf), GenericArg::Infer(r_inf)) => self.eq_ty(&l_inf.to_ty(), &r_inf.to_ty()),
291292
_ => false,
292293
}
293294
}
@@ -885,7 +886,11 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
885886

886887
pub fn hash_ty(&mut self, ty: &Ty<'_>) {
887888
std::mem::discriminant(&ty.kind).hash(&mut self.s);
888-
match ty.kind {
889+
self.hash_tykind(&ty.kind);
890+
}
891+
892+
pub fn hash_tykind(&mut self, ty: &TyKind<'_>) {
893+
match ty {
889894
TyKind::Slice(ty) => {
890895
self.hash_ty(ty);
891896
},
@@ -898,7 +903,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
898903
mut_ty.mutbl.hash(&mut self.s);
899904
},
900905
TyKind::Rptr(lifetime, ref mut_ty) => {
901-
self.hash_lifetime(lifetime);
906+
self.hash_lifetime(*lifetime);
902907
self.hash_ty(mut_ty.ty);
903908
mut_ty.mutbl.hash(&mut self.s);
904909
},
@@ -918,7 +923,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
918923
bfn.decl.c_variadic.hash(&mut self.s);
919924
},
920925
TyKind::Tup(ty_list) => {
921-
for ty in ty_list {
926+
for ty in *ty_list {
922927
self.hash_ty(ty);
923928
}
924929
},
@@ -927,7 +932,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
927932
self.hash_generic_args(arg_list);
928933
},
929934
TyKind::TraitObject(_, lifetime, _) => {
930-
self.hash_lifetime(lifetime);
935+
self.hash_lifetime(*lifetime);
931936
},
932937
TyKind::Typeof(anon_const) => {
933938
self.hash_body(anon_const.body);
@@ -949,6 +954,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
949954
GenericArg::Lifetime(l) => self.hash_lifetime(l),
950955
GenericArg::Type(ref ty) => self.hash_ty(ty),
951956
GenericArg::Const(ref ca) => self.hash_body(ca.value.body),
957+
GenericArg::Infer(ref inf) => self.hash_ty(&inf.to_ty()),
952958
}
953959
}
954960
}

clippy_utils/src/ty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool {
180180
}
181181

182182
// FIXME: Per https://doc.rust-lang.org/nightly/nightly-rustc/rustc_trait_selection/infer/at/struct.At.html#method.normalize
183-
// this function can be removed once the `normalizie` method does not panic when normalization does
183+
// this function can be removed once the `normalize` method does not panic when normalization does
184184
// not succeed
185185
/// Checks if `Ty` is normalizable. This function is useful
186186
/// to avoid crashes on `layout_of`.

rust-toolchain

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[toolchain]
2-
channel = "nightly-2021-07-19"
2+
channel = "nightly-2021-07-29"
33
components = ["llvm-tools-preview", "rustc-dev", "rust-src"]

tests/ui/future_not_send.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,11 @@ note: captured value is not `Send`
5555
LL | async fn private_future2(rc: Rc<[u8]>, cell: &Cell<usize>) -> bool {
5656
| ^^ has type `std::rc::Rc<[u8]>` which is not `Send`
5757
= note: `std::rc::Rc<[u8]>` doesn't implement `std::marker::Send`
58-
note: captured value is not `Send`
58+
note: captured value is not `Send` because `&` references cannot be sent unless their referent is `Sync`
5959
--> $DIR/future_not_send.rs:20:40
6060
|
6161
LL | async fn private_future2(rc: Rc<[u8]>, cell: &Cell<usize>) -> bool {
62-
| ^^^^ has type `&std::cell::Cell<usize>` which is not `Send`
62+
| ^^^^ has type `&std::cell::Cell<usize>` which is not `Send`, because `std::cell::Cell<usize>` is not `Sync`
6363
= note: `std::cell::Cell<usize>` doesn't implement `std::marker::Sync`
6464

6565
error: future cannot be sent between threads safely

tests/ui/needless_lifetimes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#![warn(clippy::needless_lifetimes)]
2-
#![allow(dead_code, clippy::needless_pass_by_value, clippy::unnecessary_wraps)]
2+
#![allow(dead_code, clippy::needless_pass_by_value, clippy::unnecessary_wraps, dyn_drop)]
33

44
fn distinct_lifetimes<'a, 'b>(_x: &'a u8, _y: &'b u8, _z: u8) {}
55

tests/ui/transmute.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#![feature(const_fn_transmute)]
21
#![allow(dead_code)]
32

43
extern crate core;

tests/ui/transmute.stderr

+24-24
Original file line numberDiff line numberDiff line change
@@ -1,155 +1,155 @@
11
error: transmute from a type (`&T`) to itself
2-
--> $DIR/transmute.rs:20:20
2+
--> $DIR/transmute.rs:19:20
33
|
44
LL | let _: &'a T = core::intrinsics::transmute(t);
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
77
= note: `-D clippy::useless-transmute` implied by `-D warnings`
88

99
error: transmute from a reference to a pointer
10-
--> $DIR/transmute.rs:24:23
10+
--> $DIR/transmute.rs:23:23
1111
|
1212
LL | let _: *const T = core::intrinsics::transmute(t);
1313
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `t as *const T`
1414

1515
error: transmute from a reference to a pointer
16-
--> $DIR/transmute.rs:26:21
16+
--> $DIR/transmute.rs:25:21
1717
|
1818
LL | let _: *mut T = core::intrinsics::transmute(t);
1919
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `t as *const T as *mut T`
2020

2121
error: transmute from a reference to a pointer
22-
--> $DIR/transmute.rs:28:23
22+
--> $DIR/transmute.rs:27:23
2323
|
2424
LL | let _: *const U = core::intrinsics::transmute(t);
2525
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `t as *const T as *const U`
2626

2727
error: transmute from a type (`std::vec::Vec<i32>`) to itself
28-
--> $DIR/transmute.rs:34:27
28+
--> $DIR/transmute.rs:33:27
2929
|
3030
LL | let _: Vec<i32> = core::intrinsics::transmute(my_vec());
3131
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3232

3333
error: transmute from a type (`std::vec::Vec<i32>`) to itself
34-
--> $DIR/transmute.rs:36:27
34+
--> $DIR/transmute.rs:35:27
3535
|
3636
LL | let _: Vec<i32> = core::mem::transmute(my_vec());
3737
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3838

3939
error: transmute from a type (`std::vec::Vec<i32>`) to itself
40-
--> $DIR/transmute.rs:38:27
40+
--> $DIR/transmute.rs:37:27
4141
|
4242
LL | let _: Vec<i32> = std::intrinsics::transmute(my_vec());
4343
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4444

4545
error: transmute from a type (`std::vec::Vec<i32>`) to itself
46-
--> $DIR/transmute.rs:40:27
46+
--> $DIR/transmute.rs:39:27
4747
|
4848
LL | let _: Vec<i32> = std::mem::transmute(my_vec());
4949
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5050

5151
error: transmute from a type (`std::vec::Vec<i32>`) to itself
52-
--> $DIR/transmute.rs:42:27
52+
--> $DIR/transmute.rs:41:27
5353
|
5454
LL | let _: Vec<i32> = my_transmute(my_vec());
5555
| ^^^^^^^^^^^^^^^^^^^^^^
5656

5757
error: transmute from an integer to a pointer
58-
--> $DIR/transmute.rs:44:31
58+
--> $DIR/transmute.rs:43:31
5959
|
6060
LL | let _: *const usize = std::mem::transmute(5_isize);
6161
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `5_isize as *const usize`
6262

6363
error: transmute from an integer to a pointer
64-
--> $DIR/transmute.rs:48:31
64+
--> $DIR/transmute.rs:47:31
6565
|
6666
LL | let _: *const usize = std::mem::transmute(1 + 1usize);
6767
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `(1 + 1usize) as *const usize`
6868

6969
error: transmute from a type (`*const Usize`) to the type that it points to (`Usize`)
70-
--> $DIR/transmute.rs:63:24
70+
--> $DIR/transmute.rs:62:24
7171
|
7272
LL | let _: Usize = core::intrinsics::transmute(int_const_ptr);
7373
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7474
|
7575
= note: `-D clippy::crosspointer-transmute` implied by `-D warnings`
7676

7777
error: transmute from a type (`*mut Usize`) to the type that it points to (`Usize`)
78-
--> $DIR/transmute.rs:65:24
78+
--> $DIR/transmute.rs:64:24
7979
|
8080
LL | let _: Usize = core::intrinsics::transmute(int_mut_ptr);
8181
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8282

8383
error: transmute from a type (`Usize`) to a pointer to that type (`*const Usize`)
84-
--> $DIR/transmute.rs:67:31
84+
--> $DIR/transmute.rs:66:31
8585
|
8686
LL | let _: *const Usize = core::intrinsics::transmute(my_int());
8787
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8888

8989
error: transmute from a type (`Usize`) to a pointer to that type (`*mut Usize`)
90-
--> $DIR/transmute.rs:69:29
90+
--> $DIR/transmute.rs:68:29
9191
|
9292
LL | let _: *mut Usize = core::intrinsics::transmute(my_int());
9393
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9494

9595
error: transmute from a `u32` to a `char`
96-
--> $DIR/transmute.rs:75:28
96+
--> $DIR/transmute.rs:74:28
9797
|
9898
LL | let _: char = unsafe { std::mem::transmute(0_u32) };
9999
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::char::from_u32(0_u32).unwrap()`
100100
|
101101
= note: `-D clippy::transmute-int-to-char` implied by `-D warnings`
102102

103103
error: transmute from a `i32` to a `char`
104-
--> $DIR/transmute.rs:76:28
104+
--> $DIR/transmute.rs:75:28
105105
|
106106
LL | let _: char = unsafe { std::mem::transmute(0_i32) };
107107
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::char::from_u32(0_i32 as u32).unwrap()`
108108

109109
error: transmute from a `u8` to a `bool`
110-
--> $DIR/transmute.rs:81:28
110+
--> $DIR/transmute.rs:80:28
111111
|
112112
LL | let _: bool = unsafe { std::mem::transmute(0_u8) };
113113
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `0_u8 != 0`
114114
|
115115
= note: `-D clippy::transmute-int-to-bool` implied by `-D warnings`
116116

117117
error: transmute from a `u32` to a `f32`
118-
--> $DIR/transmute.rs:87:31
118+
--> $DIR/transmute.rs:86:31
119119
|
120120
LL | let _: f32 = unsafe { std::mem::transmute(0_u32) };
121121
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `f32::from_bits(0_u32)`
122122
|
123123
= note: `-D clippy::transmute-int-to-float` implied by `-D warnings`
124124

125125
error: transmute from a `i32` to a `f32`
126-
--> $DIR/transmute.rs:88:31
126+
--> $DIR/transmute.rs:87:31
127127
|
128128
LL | let _: f32 = unsafe { std::mem::transmute(0_i32) };
129129
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `f32::from_bits(0_i32 as u32)`
130130

131131
error: transmute from a `u64` to a `f64`
132-
--> $DIR/transmute.rs:89:31
132+
--> $DIR/transmute.rs:88:31
133133
|
134134
LL | let _: f64 = unsafe { std::mem::transmute(0_u64) };
135135
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `f64::from_bits(0_u64)`
136136

137137
error: transmute from a `i64` to a `f64`
138-
--> $DIR/transmute.rs:90:31
138+
--> $DIR/transmute.rs:89:31
139139
|
140140
LL | let _: f64 = unsafe { std::mem::transmute(0_i64) };
141141
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `f64::from_bits(0_i64 as u64)`
142142

143143
error: transmute from a `&[u8]` to a `&str`
144-
--> $DIR/transmute.rs:108:28
144+
--> $DIR/transmute.rs:107:28
145145
|
146146
LL | let _: &str = unsafe { std::mem::transmute(b) };
147147
| ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::str::from_utf8(b).unwrap()`
148148
|
149149
= note: `-D clippy::transmute-bytes-to-str` implied by `-D warnings`
150150

151151
error: transmute from a `&mut [u8]` to a `&mut str`
152-
--> $DIR/transmute.rs:109:32
152+
--> $DIR/transmute.rs:108:32
153153
|
154154
LL | let _: &mut str = unsafe { std::mem::transmute(mb) };
155155
| ^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::str::from_utf8_mut(mb).unwrap()`

tests/ui/transmute_float_to_int.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#![feature(const_fn_transmute)]
21
#![warn(clippy::transmute_float_to_int)]
32

43
fn float_to_int() {

0 commit comments

Comments
 (0)