From 5fc61a24c4db217d7a9d3954134a6e544a0a6650 Mon Sep 17 00:00:00 2001 From: Esteban Kuber Date: Thu, 25 Nov 2021 18:39:32 +0000 Subject: [PATCH 1/6] Fix clippy test --- tests/ui/crashes/ice-6250.stderr | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/ui/crashes/ice-6250.stderr b/tests/ui/crashes/ice-6250.stderr index 439884b7d274..0d7713aa9a27 100644 --- a/tests/ui/crashes/ice-6250.stderr +++ b/tests/ui/crashes/ice-6250.stderr @@ -24,6 +24,9 @@ LL | | } error[E0308]: mismatched types --> $DIR/ice-6250.rs:12:14 | +LL | for reference in vec![1, 2, 3] { + | --------- expected due to the type of this binding +... LL | Some(reference) = cache.data.get(key) { | ^^^^^^^^^ expected integer, found `&i32` | From 9274ec56911e4136278f7fb186fc22ec3f697ae3 Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Wed, 24 Nov 2021 17:20:52 -0600 Subject: [PATCH 2/6] Visit `param_env` field in Obligation's `TypeFoldable` impl This oversight appears to have gone unnoticed for a long time without causing issues, but it should still be fixed. --- tests/ui/crashes/ice-6252.stderr | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/tests/ui/crashes/ice-6252.stderr b/tests/ui/crashes/ice-6252.stderr index c8239897f3ab..abca7af30a00 100644 --- a/tests/ui/crashes/ice-6252.stderr +++ b/tests/ui/crashes/ice-6252.stderr @@ -21,16 +21,15 @@ LL | impl TypeVal for Multiply where N: TypeVal {} | | | help: you might be missing a type parameter: `, VAL` -error[E0046]: not all trait items implemented, missing: `VAL` - --> $DIR/ice-6252.rs:10:1 +error[E0283]: type annotations needed + --> $DIR/ice-6252.rs:10:12 | -LL | const VAL: T; - | ------------- `VAL` from trait -... LL | impl TypeVal for Multiply where N: TypeVal {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `VAL` in implementation + | ^^^^^^^^^^^^^^ cannot infer type for struct `Multiply` + | + = note: cannot satisfy `Multiply: TypeVal` error: aborting due to 3 previous errors -Some errors have detailed explanations: E0046, E0412. -For more information about an error, try `rustc --explain E0046`. +Some errors have detailed explanations: E0283, E0412. +For more information about an error, try `rustc --explain E0283`. From 3c8b644d0d7d6fcd56db2184d4b5622d9e50ca37 Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Fri, 26 Nov 2021 09:14:16 -0600 Subject: [PATCH 3/6] Only check for errors in predicate when skipping impl assembly Prior to PR #91205, checking for errors in the overall obligation would check checking the `ParamEnv`, due to an incorrect `super_visit_with` impl. With this bug fixed, we will now bail out of impl candidate assembly if the `ParamEnv` contains any error types. In practice, this appears to be overly conservative - when an error occurs early in compilation, we end up giving up early for some predicates that we could have successfully evaluated without overflow. By only checking for errors in the predicate itself, we avoid causing additional spurious 'type annotations needed' errors after a 'real' error has already occurred. With this PR, the diagnostic changes caused by PR #91205 are reverted. --- tests/ui/crashes/ice-6252.stderr | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/tests/ui/crashes/ice-6252.stderr b/tests/ui/crashes/ice-6252.stderr index abca7af30a00..c8239897f3ab 100644 --- a/tests/ui/crashes/ice-6252.stderr +++ b/tests/ui/crashes/ice-6252.stderr @@ -21,15 +21,16 @@ LL | impl TypeVal for Multiply where N: TypeVal {} | | | help: you might be missing a type parameter: `, VAL` -error[E0283]: type annotations needed - --> $DIR/ice-6252.rs:10:12 +error[E0046]: not all trait items implemented, missing: `VAL` + --> $DIR/ice-6252.rs:10:1 | +LL | const VAL: T; + | ------------- `VAL` from trait +... LL | impl TypeVal for Multiply where N: TypeVal {} - | ^^^^^^^^^^^^^^ cannot infer type for struct `Multiply` - | - = note: cannot satisfy `Multiply: TypeVal` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `VAL` in implementation error: aborting due to 3 previous errors -Some errors have detailed explanations: E0283, E0412. -For more information about an error, try `rustc --explain E0283`. +Some errors have detailed explanations: E0046, E0412. +For more information about an error, try `rustc --explain E0046`. From 56533d9e872084454bb5dbfacb49df64f145fa9d Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Wed, 20 Oct 2021 22:38:10 +0200 Subject: [PATCH 4/6] Take a LocalDefId in expect_*item. --- clippy_lints/src/derive.rs | 8 +------- clippy_lints/src/methods/mod.rs | 2 +- clippy_lints/src/non_copy_const.rs | 4 ++-- clippy_lints/src/self_named_constructors.rs | 2 +- clippy_lints/src/unused_self.rs | 2 +- 5 files changed, 6 insertions(+), 12 deletions(-) diff --git a/clippy_lints/src/derive.rs b/clippy_lints/src/derive.rs index 24ac5917dcb0..94b35ad88af2 100644 --- a/clippy_lints/src/derive.rs +++ b/clippy_lints/src/derive.rs @@ -3,7 +3,6 @@ use clippy_utils::paths; use clippy_utils::ty::{implements_trait, is_copy}; use clippy_utils::{get_trait_def_id, is_automatically_derived, is_lint_allowed, match_def_path}; use if_chain::if_chain; -use rustc_hir::def_id::DefId; use rustc_hir::intravisit::{walk_expr, walk_fn, walk_item, FnKind, NestedVisitorMap, Visitor}; use rustc_hir::{ BlockCheckMode, BodyId, Expr, ExprKind, FnDecl, HirId, Impl, Item, ItemKind, TraitRef, UnsafeSource, Unsafety, @@ -343,11 +342,6 @@ fn check_unsafe_derive_deserialize<'tcx>( trait_ref: &TraitRef<'_>, ty: Ty<'tcx>, ) { - fn item_from_def_id<'tcx>(cx: &LateContext<'tcx>, def_id: DefId) -> &'tcx Item<'tcx> { - let hir_id = cx.tcx.hir().local_def_id_to_hir_id(def_id.expect_local()); - cx.tcx.hir().expect_item(hir_id) - } - fn has_unsafe<'tcx>(cx: &LateContext<'tcx>, item: &'tcx Item<'_>) -> bool { let mut visitor = UnsafeVisitor { cx, has_unsafe: false }; walk_item(&mut visitor, item); @@ -363,7 +357,7 @@ fn check_unsafe_derive_deserialize<'tcx>( if !is_lint_allowed(cx, UNSAFE_DERIVE_DESERIALIZE, adt_hir_id); if cx.tcx.inherent_impls(def.did) .iter() - .map(|imp_did| item_from_def_id(cx, *imp_did)) + .map(|imp_did| cx.tcx.hir().expect_item(imp_did.expect_local())) .any(|imp| has_unsafe(cx, imp)); then { span_lint_and_help( diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index 26c29fbb289c..e46739fea34b 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -1939,7 +1939,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods { return; } let name = impl_item.ident.name.as_str(); - let parent = cx.tcx.hir().get_parent_item(impl_item.hir_id()); + let parent = cx.tcx.hir().get_parent_did(impl_item.hir_id()); let item = cx.tcx.hir().expect_item(parent); let self_ty = cx.tcx.type_of(item.def_id); diff --git a/clippy_lints/src/non_copy_const.rs b/clippy_lints/src/non_copy_const.rs index 2a85a67fa099..2ea97eb88f78 100644 --- a/clippy_lints/src/non_copy_const.rs +++ b/clippy_lints/src/non_copy_const.rs @@ -279,8 +279,8 @@ impl<'tcx> LateLintPass<'tcx> for NonCopyConst { fn check_impl_item(&mut self, cx: &LateContext<'tcx>, impl_item: &'tcx ImplItem<'_>) { if let ImplItemKind::Const(hir_ty, body_id) = &impl_item.kind { - let item_hir_id = cx.tcx.hir().get_parent_node(impl_item.hir_id()); - let item = cx.tcx.hir().expect_item(item_hir_id); + let item_def_id = cx.tcx.hir().get_parent_did(impl_item.hir_id()); + let item = cx.tcx.hir().expect_item(item_def_id); match &item.kind { ItemKind::Impl(Impl { diff --git a/clippy_lints/src/self_named_constructors.rs b/clippy_lints/src/self_named_constructors.rs index 4ba5e1a0f535..9390378d789c 100644 --- a/clippy_lints/src/self_named_constructors.rs +++ b/clippy_lints/src/self_named_constructors.rs @@ -50,7 +50,7 @@ impl<'tcx> LateLintPass<'tcx> for SelfNamedConstructors { _ => return, } - let parent = cx.tcx.hir().get_parent_item(impl_item.hir_id()); + let parent = cx.tcx.hir().get_parent_did(impl_item.hir_id()); let item = cx.tcx.hir().expect_item(parent); let self_ty = cx.tcx.type_of(item.def_id); let ret_ty = return_ty(cx, impl_item.hir_id()); diff --git a/clippy_lints/src/unused_self.rs b/clippy_lints/src/unused_self.rs index e7e249c79a2f..c961f9956679 100644 --- a/clippy_lints/src/unused_self.rs +++ b/clippy_lints/src/unused_self.rs @@ -41,7 +41,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedSelf { if impl_item.span.from_expansion() { return; } - let parent = cx.tcx.hir().get_parent_item(impl_item.hir_id()); + let parent = cx.tcx.hir().get_parent_did(impl_item.hir_id()); let parent_item = cx.tcx.hir().expect_item(parent); let assoc_item = cx.tcx.associated_item(impl_item.def_id); if_chain! { From 782b1a846edd321f2d2193d251e3e30c7fccfdc4 Mon Sep 17 00:00:00 2001 From: flip1995 Date: Thu, 2 Dec 2021 09:32:38 +0000 Subject: [PATCH 5/6] Bump nightly version -> 2021-12-02 --- rust-toolchain | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-toolchain b/rust-toolchain index f02d0b18ddc7..27969b0d655d 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,3 +1,3 @@ [toolchain] -channel = "nightly-2021-11-23" +channel = "nightly-2021-12-02" components = ["cargo", "llvm-tools-preview", "rust-src", "rust-std", "rustc", "rustc-dev", "rustfmt"] From ec57cc1455b25c8eff76e56b23c692f177cfb6c7 Mon Sep 17 00:00:00 2001 From: flip1995 Date: Thu, 2 Dec 2021 09:32:47 +0000 Subject: [PATCH 6/6] Bump Clippy Version -> 0.1.59 --- Cargo.toml | 2 +- clippy_lints/Cargo.toml | 2 +- clippy_utils/Cargo.toml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index fdafdffca643..8661a8677588 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "clippy" -version = "0.1.58" +version = "0.1.59" description = "A bunch of helpful lints to avoid common pitfalls in Rust" repository = "https://github.com/rust-lang/rust-clippy" readme = "README.md" diff --git a/clippy_lints/Cargo.toml b/clippy_lints/Cargo.toml index 281480b8d949..0661c2803864 100644 --- a/clippy_lints/Cargo.toml +++ b/clippy_lints/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "clippy_lints" -version = "0.1.58" +version = "0.1.59" description = "A bunch of helpful lints to avoid common pitfalls in Rust" repository = "https://github.com/rust-lang/rust-clippy" readme = "README.md" diff --git a/clippy_utils/Cargo.toml b/clippy_utils/Cargo.toml index d99a3d9359e1..0ba0b59ed13d 100644 --- a/clippy_utils/Cargo.toml +++ b/clippy_utils/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "clippy_utils" -version = "0.1.58" +version = "0.1.59" edition = "2021" publish = false