diff options
| author | bors <bors@rust-lang.org> | 2022-02-01 16:55:43 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-02-01 16:55:43 +0000 |
| commit | ad88831cd50ffe9cb9006bbdcb7fc9d97142e410 (patch) | |
| tree | d39d094b6d22bd659711d300b460c7aedf2962d5 /src | |
| parent | 686663a49e57870c78a4cd047f23a44175fc67a4 (diff) | |
| parent | 019c140244b83b9ebb177e74345237844e88a26b (diff) | |
Auto merge of #93548 - matthiaskrgr:rollup-f7dkn3p, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - #86374 (Enable combining `+crt-static` and `relocation-model=pic` on `x86_64-unknown-linux-gnu`) - #91828 (Implement `RawWaker` and `Waker` getters for underlying pointers) - #92021 (Eliminate duplicate codes of is_single_fp_element) - #92584 (add rustc lint, warning when iterating over hashmaps 2) - #93267 (implement a lint for suspicious auto trait impls) - #93290 (remove `TyS::same_type`) - #93436 (Update compiler_builtins to fix duplicate symbols in `armv7-linux-androideabi` rlib) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'src')
30 files changed, 292 insertions, 73 deletions
diff --git a/src/test/run-make/static-pie/Makefile b/src/test/run-make/static-pie/Makefile index 1d3cc821389..945ec1724ac 100644 --- a/src/test/run-make/static-pie/Makefile +++ b/src/test/run-make/static-pie/Makefile @@ -1,15 +1,18 @@ -include ../../run-make-fulldeps/tools.mk -# only-x86_64-unknown-linux-musl +# only-x86_64 +# only-linux +# ignore-gnux32 # How to manually run this -# $ ./x.py test --target x86_64-unknown-linux-musl src/test/run-make/static-pie - -all: - $(RUSTC) --target $(TARGET) -C target-feature=+crt-static test-aslr.rs - # Check that no dynamic interpreter is set - ! readelf -l $(call RUN_BINFILE,test-aslr) | $(CGREP) INTERP - # Check that we have a dynamic executable - readelf -l $(call RUN_BINFILE,test-aslr) | $(CGREP) DYNAMIC - # Check for address space layout randomization - $(call RUN,test-aslr) --test-aslr +# $ ./x.py test --target x86_64-unknown-linux-[musl,gnu] src/test/run-make/static-pie + +all: test-clang test-gcc + +test-%: + if ./check_$*_version.sh; then\ + ${RUSTC} -Clinker=$* -Clinker-flavor=gcc --target ${TARGET} -C target-feature=+crt-static test-aslr.rs; \ + ! readelf -l $(call RUN_BINFILE,test-aslr) | $(CGREP) INTERP; \ + readelf -l $(call RUN_BINFILE,test-aslr) | $(CGREP) DYNAMIC; \ + $(call RUN,test-aslr) --test-aslr; \ + fi diff --git a/src/test/run-make/static-pie/check_clang_version.sh b/src/test/run-make/static-pie/check_clang_version.sh new file mode 100755 index 00000000000..b8e97c3da7d --- /dev/null +++ b/src/test/run-make/static-pie/check_clang_version.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +set -euo pipefail + +if command -v clang > /dev/null +then + CLANG_VERSION=$(echo __clang_major__ | clang -E -x c - | grep -v -e '^#' ) + echo "clang version $CLANG_VERSION detected" + if (( $CLANG_VERSION >= 9 )) + then + echo "clang supports -static-pie" + exit 0 + else + echo "clang too old to support -static-pie, skipping test" + exit 1 + fi +else + echo "No clang version detected" + exit 2 +fi diff --git a/src/test/run-make/static-pie/check_gcc_version.sh b/src/test/run-make/static-pie/check_gcc_version.sh new file mode 100755 index 00000000000..d07e1d151df --- /dev/null +++ b/src/test/run-make/static-pie/check_gcc_version.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +set -euo pipefail + +if command -v gcc > /dev/null +then + GCC_VERSION=$(echo __GNUC__ | gcc -E -x c - | grep -v -e '^#' ) + echo "gcc version $GCC_VERSION detected" + if (( $GCC_VERSION >= 8 )) + then + echo "gcc supports -static-pie" + exit 0 + else + echo "gcc too old to support -static-pie, skipping test" + exit 1 + fi +else + echo "No gcc version detected" + exit 2 +fi diff --git a/src/test/ui-fulldeps/internal-lints/query_stability.rs b/src/test/ui-fulldeps/internal-lints/query_stability.rs new file mode 100644 index 00000000000..560675b4486 --- /dev/null +++ b/src/test/ui-fulldeps/internal-lints/query_stability.rs @@ -0,0 +1,24 @@ +// compile-flags: -Z unstable-options + +#![feature(rustc_private)] +#![deny(rustc::potential_query_instability)] + +extern crate rustc_data_structures; + +use rustc_data_structures::fx::{FxHashMap, FxHashSet}; + +fn main() { + let mut x = FxHashMap::<u32, i32>::default(); + + for _ in x.drain() {} + //~^ ERROR using `drain` can result in unstable + + for _ in x.iter() {} + //~^ ERROR using `iter` + + for _ in Some(&mut x).unwrap().iter_mut() {} + //~^ ERROR using `iter_mut` + + for _ in x {} + //~^ ERROR using `into_iter` +} diff --git a/src/test/ui-fulldeps/internal-lints/query_stability.stderr b/src/test/ui-fulldeps/internal-lints/query_stability.stderr new file mode 100644 index 00000000000..7e8b448f41a --- /dev/null +++ b/src/test/ui-fulldeps/internal-lints/query_stability.stderr @@ -0,0 +1,39 @@ +error: using `drain` can result in unstable query results + --> $DIR/query_stability.rs:13:16 + | +LL | for _ in x.drain() {} + | ^^^^^ + | +note: the lint level is defined here + --> $DIR/query_stability.rs:4:9 + | +LL | #![deny(rustc::potential_query_instability)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + = note: if you believe this case to be fine, allow this lint and add a comment explaining your rationale + +error: using `iter` can result in unstable query results + --> $DIR/query_stability.rs:16:16 + | +LL | for _ in x.iter() {} + | ^^^^ + | + = note: if you believe this case to be fine, allow this lint and add a comment explaining your rationale + +error: using `iter_mut` can result in unstable query results + --> $DIR/query_stability.rs:19:36 + | +LL | for _ in Some(&mut x).unwrap().iter_mut() {} + | ^^^^^^^^ + | + = note: if you believe this case to be fine, allow this lint and add a comment explaining your rationale + +error: using `into_iter` can result in unstable query results + --> $DIR/query_stability.rs:22:14 + | +LL | for _ in x {} + | ^ + | + = note: if you believe this case to be fine, allow this lint and add a comment explaining your rationale + +error: aborting due to 4 previous errors + diff --git a/src/test/ui-fulldeps/internal-lints/query_stability_incorrect.rs b/src/test/ui-fulldeps/internal-lints/query_stability_incorrect.rs new file mode 100644 index 00000000000..f478b73329e --- /dev/null +++ b/src/test/ui-fulldeps/internal-lints/query_stability_incorrect.rs @@ -0,0 +1,15 @@ +// compile-flags: -Z unstable-options + +#![feature(rustc_attrs)] + +#[rustc_lint_query_instability] +//~^ ERROR attribute should be applied to a function +struct Foo; + +impl Foo { + #[rustc_lint_query_instability(a)] + //~^ ERROR malformed `rustc_lint_query_instability` + fn bar() {} +} + +fn main() {} diff --git a/src/test/ui-fulldeps/internal-lints/query_stability_incorrect.stderr b/src/test/ui-fulldeps/internal-lints/query_stability_incorrect.stderr new file mode 100644 index 00000000000..b5156f2ac59 --- /dev/null +++ b/src/test/ui-fulldeps/internal-lints/query_stability_incorrect.stderr @@ -0,0 +1,17 @@ +error: malformed `rustc_lint_query_instability` attribute input + --> $DIR/query_stability_incorrect.rs:10:5 + | +LL | #[rustc_lint_query_instability(a)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: must be of the form: `#[rustc_lint_query_instability]` + +error: attribute should be applied to a function + --> $DIR/query_stability_incorrect.rs:5:1 + | +LL | #[rustc_lint_query_instability] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | struct Foo; + | ----------- not a function + +error: aborting due to 2 previous errors + diff --git a/src/test/ui/auto-traits/suspicious-impls-lint.rs b/src/test/ui/auto-traits/suspicious-impls-lint.rs new file mode 100644 index 00000000000..1026a35a455 --- /dev/null +++ b/src/test/ui/auto-traits/suspicious-impls-lint.rs @@ -0,0 +1,34 @@ +#![deny(suspicious_auto_trait_impls)] + +struct MayImplementSendOk<T>(T); +unsafe impl<T: Send> Send for MayImplementSendOk<T> {} // ok + +struct MayImplementSendErr<T>(T); +unsafe impl<T: Send> Send for MayImplementSendErr<&T> {} +//~^ ERROR +//~| WARNING this will change its meaning + +struct ContainsNonSendDirect<T>(*const T); +unsafe impl<T: Send> Send for ContainsNonSendDirect<&T> {} // ok + +struct ContainsPtr<T>(*const T); +struct ContainsIndirectNonSend<T>(ContainsPtr<T>); +unsafe impl<T: Send> Send for ContainsIndirectNonSend<&T> {} // ok + +struct ContainsVec<T>(Vec<T>); +unsafe impl Send for ContainsVec<i32> {} +//~^ ERROR +//~| WARNING this will change its meaning + +struct TwoParams<T, U>(T, U); +unsafe impl<T: Send, U: Send> Send for TwoParams<T, U> {} // ok + +struct TwoParamsFlipped<T, U>(T, U); +unsafe impl<T: Send, U: Send> Send for TwoParamsFlipped<U, T> {} // ok + +struct TwoParamsSame<T, U>(T, U); +unsafe impl<T: Send> Send for TwoParamsSame<T, T> {} +//~^ ERROR +//~| WARNING this will change its meaning + +fn main() {} diff --git a/src/test/ui/auto-traits/suspicious-impls-lint.stderr b/src/test/ui/auto-traits/suspicious-impls-lint.stderr new file mode 100644 index 00000000000..f91aa862271 --- /dev/null +++ b/src/test/ui/auto-traits/suspicious-impls-lint.stderr @@ -0,0 +1,52 @@ +error: cross-crate traits with a default impl, like `Send`, should not be specialized + --> $DIR/suspicious-impls-lint.rs:7:1 + | +LL | unsafe impl<T: Send> Send for MayImplementSendErr<&T> {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +note: the lint level is defined here + --> $DIR/suspicious-impls-lint.rs:1:9 + | +LL | #![deny(suspicious_auto_trait_impls)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + = warning: this will change its meaning in a future release! + = note: for more information, see issue #93367 <https://github.com/rust-lang/rust/issues/93367> +note: try using the same sequence of generic parameters as the struct definition + --> $DIR/suspicious-impls-lint.rs:6:1 + | +LL | struct MayImplementSendErr<T>(T); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + = note: `&T` is not a generic parameter + +error: cross-crate traits with a default impl, like `Send`, should not be specialized + --> $DIR/suspicious-impls-lint.rs:19:1 + | +LL | unsafe impl Send for ContainsVec<i32> {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = warning: this will change its meaning in a future release! + = note: for more information, see issue #93367 <https://github.com/rust-lang/rust/issues/93367> +note: try using the same sequence of generic parameters as the struct definition + --> $DIR/suspicious-impls-lint.rs:18:1 + | +LL | struct ContainsVec<T>(Vec<T>); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + = note: `i32` is not a generic parameter + +error: cross-crate traits with a default impl, like `Send`, should not be specialized + --> $DIR/suspicious-impls-lint.rs:30:1 + | +LL | unsafe impl<T: Send> Send for TwoParamsSame<T, T> {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = warning: this will change its meaning in a future release! + = note: for more information, see issue #93367 <https://github.com/rust-lang/rust/issues/93367> +note: try using the same sequence of generic parameters as the struct definition + --> $DIR/suspicious-impls-lint.rs:29:1 + | +LL | struct TwoParamsSame<T, U>(T, U); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + = note: `T` is mentioned multiple times + +error: aborting due to 3 previous errors + diff --git a/src/test/ui/typeck/typeck-default-trait-impl-cross-crate-coherence.rs b/src/test/ui/typeck/typeck-default-trait-impl-cross-crate-coherence.rs index 772ac322032..cc75cd4909a 100644 --- a/src/test/ui/typeck/typeck-default-trait-impl-cross-crate-coherence.rs +++ b/src/test/ui/typeck/typeck-default-trait-impl-cross-crate-coherence.rs @@ -1,4 +1,5 @@ // aux-build:tdticc_coherence_lib.rs +#![allow(suspicious_auto_trait_impls)] // Test that we do not consider associated types to be sendable without // some applicable trait bound (and we don't ICE). diff --git a/src/test/ui/typeck/typeck-default-trait-impl-cross-crate-coherence.stderr b/src/test/ui/typeck/typeck-default-trait-impl-cross-crate-coherence.stderr index 90ab5be016c..cf5c15df705 100644 --- a/src/test/ui/typeck/typeck-default-trait-impl-cross-crate-coherence.stderr +++ b/src/test/ui/typeck/typeck-default-trait-impl-cross-crate-coherence.stderr @@ -1,5 +1,5 @@ error[E0117]: only traits defined in the current crate can be implemented for arbitrary types - --> $DIR/typeck-default-trait-impl-cross-crate-coherence.rs:13:1 + --> $DIR/typeck-default-trait-impl-cross-crate-coherence.rs:14:1 | LL | impl DefaultedTrait for (A,) { } | ^^^^^^^^^^^^^^^^^^^^^^^^---- @@ -10,7 +10,7 @@ LL | impl DefaultedTrait for (A,) { } = note: define and implement a trait or new type instead error[E0117]: only traits defined in the current crate can be implemented for arbitrary types - --> $DIR/typeck-default-trait-impl-cross-crate-coherence.rs:16:1 + --> $DIR/typeck-default-trait-impl-cross-crate-coherence.rs:17:1 | LL | impl !DefaultedTrait for (B,) { } | ^^^^^^^^^^^^^^^^^^^^^^^^^---- @@ -21,13 +21,13 @@ LL | impl !DefaultedTrait for (B,) { } = note: define and implement a trait or new type instead error[E0321]: cross-crate traits with a default impl, like `DefaultedTrait`, can only be implemented for a struct/enum type defined in the current crate - --> $DIR/typeck-default-trait-impl-cross-crate-coherence.rs:20:1 + --> $DIR/typeck-default-trait-impl-cross-crate-coherence.rs:21:1 | LL | impl DefaultedTrait for Box<C> { } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't implement cross-crate trait for type in another crate error[E0117]: only traits defined in the current crate can be implemented for arbitrary types - --> $DIR/typeck-default-trait-impl-cross-crate-coherence.rs:21:1 + --> $DIR/typeck-default-trait-impl-cross-crate-coherence.rs:22:1 | LL | impl DefaultedTrait for lib::Something<C> { } | ^^^^^^^^^^^^^^^^^^^^^^^^----------------- diff --git a/src/tools/clippy/clippy_lints/src/dereference.rs b/src/tools/clippy/clippy_lints/src/dereference.rs index c0adab790f0..6d0851d804c 100644 --- a/src/tools/clippy/clippy_lints/src/dereference.rs +++ b/src/tools/clippy/clippy_lints/src/dereference.rs @@ -12,7 +12,7 @@ use rustc_hir::{ }; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::adjustment::{Adjust, Adjustment, AutoBorrow, AutoBorrowMutability}; -use rustc_middle::ty::{self, Ty, TyCtxt, TyS, TypeckResults}; +use rustc_middle::ty::{self, Ty, TyCtxt, TypeckResults}; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::{symbol::sym, Span}; @@ -448,7 +448,7 @@ fn try_parse_ref_op<'tcx>( // the reference. fn deref_method_same_type(result_ty: Ty<'_>, arg_ty: Ty<'_>) -> bool { match (result_ty.kind(), arg_ty.kind()) { - (ty::Ref(_, result_ty, _), ty::Ref(_, arg_ty, _)) => TyS::same_type(result_ty, arg_ty), + (ty::Ref(_, result_ty, _), ty::Ref(_, arg_ty, _)) => result_ty == arg_ty, // The result type for a deref method is always a reference // Not matching the previous pattern means the argument type is not a reference diff --git a/src/tools/clippy/clippy_lints/src/implicit_hasher.rs b/src/tools/clippy/clippy_lints/src/implicit_hasher.rs index eed25e9bc0e..a2f943b03ef 100644 --- a/src/tools/clippy/clippy_lints/src/implicit_hasher.rs +++ b/src/tools/clippy/clippy_lints/src/implicit_hasher.rs @@ -8,7 +8,7 @@ use rustc_hir::{Body, Expr, ExprKind, GenericArg, Item, ItemKind, QPath, TyKind} use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_middle::hir::nested_filter; use rustc_middle::lint::in_external_macro; -use rustc_middle::ty::{Ty, TyS, TypeckResults}; +use rustc_middle::ty::{Ty, TypeckResults}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::Span; use rustc_span::symbol::sym; @@ -346,7 +346,7 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for ImplicitHasherConstructorVisitor<'a, 'b, 't if let TyKind::Path(QPath::Resolved(None, ty_path)) = ty.kind; if let Some(ty_did) = ty_path.res.opt_def_id(); then { - if !TyS::same_type(self.target.ty(), self.maybe_typeck_results.unwrap().expr_ty(e)) { + if self.target.ty() != self.maybe_typeck_results.unwrap().expr_ty(e) { return; } diff --git a/src/tools/clippy/clippy_lints/src/len_zero.rs b/src/tools/clippy/clippy_lints/src/len_zero.rs index 530b0a90ebd..3418d276c53 100644 --- a/src/tools/clippy/clippy_lints/src/len_zero.rs +++ b/src/tools/clippy/clippy_lints/src/len_zero.rs @@ -10,7 +10,7 @@ use rustc_hir::{ ItemKind, Mutability, Node, TraitItemRef, TyKind, }; use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty::{self, AssocKind, FnSig, Ty, TyS}; +use rustc_middle::ty::{self, AssocKind, FnSig, Ty}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::{ source_map::{Span, Spanned, Symbol}, @@ -265,7 +265,7 @@ impl LenOutput<'_> { (_, &ty::Bool) => true, (Self::Option(id), &ty::Adt(adt, subs)) if id == adt.did => subs.type_at(0).is_bool(), (Self::Result(id, err_ty), &ty::Adt(adt, subs)) if id == adt.did => { - subs.type_at(0).is_bool() && TyS::same_type(subs.type_at(1), err_ty) + subs.type_at(0).is_bool() && subs.type_at(1) == err_ty }, _ => false, } diff --git a/src/tools/clippy/clippy_lints/src/loops/explicit_into_iter_loop.rs b/src/tools/clippy/clippy_lints/src/loops/explicit_into_iter_loop.rs index 17246cc5426..175e2b382e3 100644 --- a/src/tools/clippy/clippy_lints/src/loops/explicit_into_iter_loop.rs +++ b/src/tools/clippy/clippy_lints/src/loops/explicit_into_iter_loop.rs @@ -5,13 +5,12 @@ use clippy_utils::source::snippet_with_applicability; use rustc_errors::Applicability; use rustc_hir::Expr; use rustc_lint::LateContext; -use rustc_middle::ty::TyS; use rustc_span::symbol::sym; pub(super) fn check(cx: &LateContext<'_>, self_arg: &Expr<'_>, call_expr: &Expr<'_>) { let self_ty = cx.typeck_results().expr_ty(self_arg); let self_ty_adjusted = cx.typeck_results().expr_ty_adjusted(self_arg); - if !(TyS::same_type(self_ty, self_ty_adjusted) && is_trait_method(cx, call_expr, sym::IntoIterator)) { + if !(self_ty == self_ty_adjusted && is_trait_method(cx, call_expr, sym::IntoIterator)) { return; } diff --git a/src/tools/clippy/clippy_lints/src/loops/explicit_iter_loop.rs b/src/tools/clippy/clippy_lints/src/loops/explicit_iter_loop.rs index 5ac69d106ce..5f5beccd030 100644 --- a/src/tools/clippy/clippy_lints/src/loops/explicit_iter_loop.rs +++ b/src/tools/clippy/clippy_lints/src/loops/explicit_iter_loop.rs @@ -6,7 +6,7 @@ use clippy_utils::ty::is_type_diagnostic_item; use rustc_errors::Applicability; use rustc_hir::{Expr, Mutability}; use rustc_lint::LateContext; -use rustc_middle::ty::{self, Ty, TyS}; +use rustc_middle::ty::{self, Ty}; use rustc_span::sym; pub(super) fn check(cx: &LateContext<'_>, self_arg: &Expr<'_>, arg: &Expr<'_>, method_name: &str) { @@ -22,7 +22,7 @@ pub(super) fn check(cx: &LateContext<'_>, self_arg: &Expr<'_>, arg: &Expr<'_>, m mutbl: Mutability::Not, }, ); - TyS::same_type(receiver_ty_adjusted, ref_receiver_ty) + receiver_ty_adjusted == ref_receiver_ty }, _ => false, }; diff --git a/src/tools/clippy/clippy_lints/src/matches.rs b/src/tools/clippy/clippy_lints/src/matches.rs index 2579404fb18..e61cb4d2273 100644 --- a/src/tools/clippy/clippy_lints/src/matches.rs +++ b/src/tools/clippy/clippy_lints/src/matches.rs @@ -26,7 +26,7 @@ use rustc_hir::{ }; use rustc_hir::{HirIdMap, HirIdSet}; use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty::{self, Ty, TyS, VariantDef}; +use rustc_middle::ty::{self, Ty, VariantDef}; use rustc_semver::RustcVersion; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::source_map::{Span, Spanned}; @@ -2262,7 +2262,7 @@ fn lint_match_arms<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>) { }; // the names technically don't have to match; this makes the lint more conservative if cx.tcx.hir().name(a_id) == cx.tcx.hir().name(b_id); - if TyS::same_type(cx.typeck_results().expr_ty(a), cx.typeck_results().expr_ty(b)); + if cx.typeck_results().expr_ty(a) == cx.typeck_results().expr_ty(b); if pat_contains_local(lhs.pat, a_id); if pat_contains_local(rhs.pat, b_id); then { diff --git a/src/tools/clippy/clippy_lints/src/methods/filter_map.rs b/src/tools/clippy/clippy_lints/src/methods/filter_map.rs index ba1af9f3d62..30c68186b3a 100644 --- a/src/tools/clippy/clippy_lints/src/methods/filter_map.rs +++ b/src/tools/clippy/clippy_lints/src/methods/filter_map.rs @@ -8,7 +8,6 @@ use rustc_hir as hir; use rustc_hir::def::Res; use rustc_hir::{Expr, ExprKind, PatKind, QPath, UnOp}; use rustc_lint::LateContext; -use rustc_middle::ty::TyS; use rustc_span::source_map::Span; use rustc_span::symbol::{sym, Symbol}; use std::borrow::Cow; @@ -149,7 +148,7 @@ pub(super) fn check<'tcx>( if_chain! { if path_to_local_id(a_path, filter_param_id); if path_to_local_id(b, map_param_id); - if TyS::same_type(cx.typeck_results().expr_ty_adjusted(a), cx.typeck_results().expr_ty_adjusted(b)); + if cx.typeck_results().expr_ty_adjusted(a) == cx.typeck_results().expr_ty_adjusted(b); then { return true; } diff --git a/src/tools/clippy/clippy_lints/src/methods/implicit_clone.rs b/src/tools/clippy/clippy_lints/src/methods/implicit_clone.rs index 865e7702b71..7a255baffd7 100644 --- a/src/tools/clippy/clippy_lints/src/methods/implicit_clone.rs +++ b/src/tools/clippy/clippy_lints/src/methods/implicit_clone.rs @@ -6,7 +6,6 @@ use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir as hir; use rustc_lint::LateContext; -use rustc_middle::ty::TyS; use rustc_span::sym; use super::IMPLICIT_CLONE; @@ -19,7 +18,7 @@ pub fn check(cx: &LateContext<'_>, method_name: &str, expr: &hir::Expr<'_>, recv let input_type = cx.typeck_results().expr_ty(recv); let (input_type, ref_count) = peel_mid_ty_refs(input_type); if let Some(ty_name) = input_type.ty_adt_def().map(|adt_def| cx.tcx.item_name(adt_def.did)); - if TyS::same_type(return_type, input_type); + if return_type == input_type; then { let mut app = Applicability::MachineApplicable; let recv_snip = snippet_with_context(cx, recv.span, expr.span.ctxt(), "..", &mut app).0; diff --git a/src/tools/clippy/clippy_lints/src/methods/mod.rs b/src/tools/clippy/clippy_lints/src/methods/mod.rs index 4b43448bf7b..80e1eb86e6c 100644 --- a/src/tools/clippy/clippy_lints/src/methods/mod.rs +++ b/src/tools/clippy/clippy_lints/src/methods/mod.rs @@ -78,7 +78,7 @@ use rustc_hir::def::Res; use rustc_hir::{Expr, ExprKind, PrimTy, QPath, TraitItem, TraitItemKind}; use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_middle::lint::in_external_macro; -use rustc_middle::ty::{self, TraitRef, Ty, TyS}; +use rustc_middle::ty::{self, TraitRef, Ty}; use rustc_semver::RustcVersion; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::{sym, Span}; @@ -2195,7 +2195,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods { } } - if name == "new" && !TyS::same_type(ret_ty, self_ty) { + if name == "new" && ret_ty != self_ty { span_lint( cx, NEW_RET_NO_SELF, diff --git a/src/tools/clippy/clippy_lints/src/methods/unnecessary_filter_map.rs b/src/tools/clippy/clippy_lints/src/methods/unnecessary_filter_map.rs index 784014f0d87..ccfce31713f 100644 --- a/src/tools/clippy/clippy_lints/src/methods/unnecessary_filter_map.rs +++ b/src/tools/clippy/clippy_lints/src/methods/unnecessary_filter_map.rs @@ -5,7 +5,7 @@ use rustc_hir as hir; use rustc_hir::intravisit::{walk_expr, Visitor}; use rustc_hir::LangItem::{OptionNone, OptionSome}; use rustc_lint::LateContext; -use rustc_middle::ty::{self, TyS}; +use rustc_middle::ty; use rustc_span::sym; use super::UNNECESSARY_FILTER_MAP; @@ -34,7 +34,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, arg: &hir::Expr< let in_ty = cx.typeck_results().node_type(body.params[0].hir_id); match cx.typeck_results().expr_ty(&body.value).kind() { ty::Adt(adt, subst) - if cx.tcx.is_diagnostic_item(sym::Option, adt.did) && TyS::same_type(in_ty, subst.type_at(0)) => + if cx.tcx.is_diagnostic_item(sym::Option, adt.did) && in_ty == subst.type_at(0) => { "filter" }, diff --git a/src/tools/clippy/clippy_lints/src/needless_option_as_deref.rs b/src/tools/clippy/clippy_lints/src/needless_option_as_deref.rs index 21d8263390a..9d3d7d1f24c 100644 --- a/src/tools/clippy/clippy_lints/src/needless_option_as_deref.rs +++ b/src/tools/clippy/clippy_lints/src/needless_option_as_deref.rs @@ -4,7 +4,6 @@ use clippy_utils::ty::is_type_diagnostic_item; use rustc_errors::Applicability; use rustc_hir::{Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty::TyS; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::symbol::sym; @@ -49,7 +48,7 @@ impl<'tcx> LateLintPass<'tcx> for OptionNeedlessDeref { if let ExprKind::MethodCall(path, [sub_expr], _) = expr.kind; let symbol = path.ident.as_str(); if symbol == "as_deref" || symbol == "as_deref_mut"; - if TyS::same_type( outer_ty, typeck.expr_ty(sub_expr) ); + if outer_ty == typeck.expr_ty(sub_expr); then{ span_lint_and_sugg( cx, diff --git a/src/tools/clippy/clippy_lints/src/needless_question_mark.rs b/src/tools/clippy/clippy_lints/src/needless_question_mark.rs index d4c823d1c1a..8f85b00596c 100644 --- a/src/tools/clippy/clippy_lints/src/needless_question_mark.rs +++ b/src/tools/clippy/clippy_lints/src/needless_question_mark.rs @@ -6,7 +6,6 @@ use rustc_errors::Applicability; use rustc_hir::LangItem::{OptionSome, ResultOk}; use rustc_hir::{AsyncGeneratorKind, Block, Body, Expr, ExprKind, GeneratorKind, LangItem, MatchSource, QPath}; use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty::TyS; use rustc_session::{declare_lint_pass, declare_tool_lint}; declare_clippy_lint! { @@ -128,7 +127,7 @@ fn check(cx: &LateContext<'_>, expr: &Expr<'_>) { if expr.span.ctxt() == inner_expr.span.ctxt(); let expr_ty = cx.typeck_results().expr_ty(expr); let inner_ty = cx.typeck_results().expr_ty(inner_expr); - if TyS::same_type(expr_ty, inner_ty); + if expr_ty == inner_ty; then { span_lint_and_sugg( cx, diff --git a/src/tools/clippy/clippy_lints/src/new_without_default.rs b/src/tools/clippy/clippy_lints/src/new_without_default.rs index aec95530bba..f86af7a7bb6 100644 --- a/src/tools/clippy/clippy_lints/src/new_without_default.rs +++ b/src/tools/clippy/clippy_lints/src/new_without_default.rs @@ -8,7 +8,6 @@ use rustc_hir as hir; use rustc_hir::HirIdSet; use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_middle::lint::in_external_macro; -use rustc_middle::ty::TyS; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::sym; @@ -103,7 +102,7 @@ impl<'tcx> LateLintPass<'tcx> for NewWithoutDefault { if cx.access_levels.is_reachable(impl_item.def_id); let self_def_id = cx.tcx.hir().get_parent_item(id); let self_ty = cx.tcx.type_of(self_def_id); - if TyS::same_type(self_ty, return_ty(cx, id)); + if self_ty == return_ty(cx, id); if let Some(default_trait_id) = cx.tcx.get_diagnostic_item(sym::Default); then { if self.impling_types.is_none() { diff --git a/src/tools/clippy/clippy_lints/src/redundant_slicing.rs b/src/tools/clippy/clippy_lints/src/redundant_slicing.rs index 7c88b42ea31..cd3aee55655 100644 --- a/src/tools/clippy/clippy_lints/src/redundant_slicing.rs +++ b/src/tools/clippy/clippy_lints/src/redundant_slicing.rs @@ -6,7 +6,6 @@ use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir::{BorrowKind, Expr, ExprKind, LangItem, Mutability}; use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty::TyS; use rustc_session::{declare_lint_pass, declare_tool_lint}; declare_clippy_lint! { @@ -54,7 +53,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantSlicing { if addressee.span.ctxt() == ctxt; if let ExprKind::Index(indexed, range) = addressee.kind; if is_type_lang_item(cx, cx.typeck_results().expr_ty_adjusted(range), LangItem::RangeFull); - if TyS::same_type(cx.typeck_results().expr_ty(expr), cx.typeck_results().expr_ty(indexed)); + if cx.typeck_results().expr_ty(expr) == cx.typeck_results().expr_ty(indexed); then { let mut app = Applicability::MachineApplicable; let snip = snippet_with_context(cx, indexed.span, ctxt, "..", &mut app).0; diff --git a/src/tools/clippy/clippy_lints/src/size_of_in_element_count.rs b/src/tools/clippy/clippy_lints/src/size_of_in_element_count.rs index c7c57ab426d..971729e5c54 100644 --- a/src/tools/clippy/clippy_lints/src/size_of_in_element_count.rs +++ b/src/tools/clippy/clippy_lints/src/size_of_in_element_count.rs @@ -7,7 +7,7 @@ use if_chain::if_chain; use rustc_hir::BinOpKind; use rustc_hir::{Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty::{self, Ty, TyS, TypeAndMut}; +use rustc_middle::ty::{self, Ty, TypeAndMut}; use rustc_session::{declare_lint_pass, declare_tool_lint}; declare_clippy_lint! { @@ -138,7 +138,7 @@ impl<'tcx> LateLintPass<'tcx> for SizeOfInElementCount { // Find a size_of call in the count parameter expression and // check that it's the same type if let Some(ty_used_for_size_of) = get_size_of_ty(cx, count_expr, false); - if TyS::same_type(pointee_ty, ty_used_for_size_of); + if pointee_ty == ty_used_for_size_of; then { span_lint_and_help( cx, diff --git a/src/tools/clippy/clippy_utils/src/hir_utils.rs b/src/tools/clippy/clippy_utils/src/hir_utils.rs index ed573ad9056..7b5c5af8f79 100644 --- a/src/tools/clippy/clippy_utils/src/hir_utils.rs +++ b/src/tools/clippy/clippy_utils/src/hir_utils.rs @@ -102,7 +102,7 @@ impl HirEqInterExpr<'_, '_, '_> { if let Some(typeck) = self.inner.maybe_typeck_results { let l_ty = typeck.pat_ty(l.pat); let r_ty = typeck.pat_ty(r.pat); - if !rustc_middle::ty::TyS::same_type(l_ty, r_ty) { + if l_ty != r_ty { return false; } } diff --git a/src/tools/clippy/clippy_utils/src/ty.rs b/src/tools/clippy/clippy_utils/src/ty.rs index d057da73302..819ff917b63 100644 --- a/src/tools/clippy/clippy_utils/src/ty.rs +++ b/src/tools/clippy/clippy_utils/src/ty.rs @@ -42,7 +42,7 @@ pub fn can_partially_move_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool /// Walks into `ty` and returns `true` if any inner type is the same as `other_ty` pub fn contains_ty(ty: Ty<'_>, other_ty: Ty<'_>) -> bool { ty.walk().any(|inner| match inner.unpack() { - GenericArgKind::Type(inner_ty) => ty::TyS::same_type(other_ty, inner_ty), + GenericArgKind::Type(inner_ty) => other_ty == inner_ty, GenericArgKind::Lifetime(_) | GenericArgKind::Const(_) => false, }) } diff --git a/src/tools/clippy/tests/ui/non_send_fields_in_send_ty.rs b/src/tools/clippy/tests/ui/non_send_fields_in_send_ty.rs index 828248d922f..514fb25c8cf 100644 --- a/src/tools/clippy/tests/ui/non_send_fields_in_send_ty.rs +++ b/src/tools/clippy/tests/ui/non_send_fields_in_send_ty.rs @@ -1,4 +1,5 @@ #![warn(clippy::non_send_fields_in_send_ty)] +#![allow(suspicious_auto_trait_impls)] #![feature(extern_types)] use std::cell::UnsafeCell; diff --git a/src/tools/clippy/tests/ui/non_send_fields_in_send_ty.stderr b/src/tools/clippy/tests/ui/non_send_fields_in_send_ty.stderr index 60df4e226e4..b6c904a147a 100644 --- a/src/tools/clippy/tests/ui/non_send_fields_in_send_ty.stderr +++ b/src/tools/clippy/tests/ui/non_send_fields_in_send_ty.stderr @@ -1,167 +1,167 @@ error: some fields in `RingBuffer<T>` are not safe to be sent to another thread - --> $DIR/non_send_fields_in_send_ty.rs:16:1 + --> $DIR/non_send_fields_in_send_ty.rs:17:1 | LL | unsafe impl<T> Send for RingBuffer<T> {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::non-send-fields-in-send-ty` implied by `-D warnings` note: it is not safe to send field `data` to another thread - --> $DIR/non_send_fields_in_send_ty.rs:11:5 + --> $DIR/non_send_fields_in_send_ty.rs:12:5 | LL | data: Vec<UnsafeCell<T>>, | ^^^^^^^^^^^^^^^^^^^^^^^^ = help: add bounds on type parameter `T` that satisfy `Vec<UnsafeCell<T>>: Send` error: some fields in `MvccRwLock<T>` are not safe to be sent to another thread - --> $DIR/non_send_fields_in_send_ty.rs:24:1 + --> $DIR/non_send_fields_in_send_ty.rs:25:1 | LL | unsafe impl<T> Send for MvccRwLock<T> {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: it is not safe to send field `lock` to another thread - --> $DIR/non_send_fields_in_send_ty.rs:21:5 + --> $DIR/non_send_fields_in_send_ty.rs:22:5 | LL | lock: Mutex<Box<T>>, | ^^^^^^^^^^^^^^^^^^^ = help: add bounds on type parameter `T` that satisfy `Mutex<Box<T>>: Send` error: some fields in `ArcGuard<RC, T>` are not safe to be sent to another thread - --> $DIR/non_send_fields_in_send_ty.rs:32:1 + --> $DIR/non_send_fields_in_send_ty.rs:33:1 | LL | unsafe impl<RC, T: Send> Send for ArcGuard<RC, T> {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: it is not safe to send field `head` to another thread - --> $DIR/non_send_fields_in_send_ty.rs:29:5 + --> $DIR/non_send_fields_in_send_ty.rs:30:5 | LL | head: Arc<RC>, | ^^^^^^^^^^^^^ = help: add bounds on type parameter `RC` that satisfy `Arc<RC>: Send` error: some fields in `DeviceHandle<T>` are not safe to be sent to another thread - --> $DIR/non_send_fields_in_send_ty.rs:48:1 + --> $DIR/non_send_fields_in_send_ty.rs:49:1 | LL | unsafe impl<T: UsbContext> Send for DeviceHandle<T> {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: it is not safe to send field `context` to another thread - --> $DIR/non_send_fields_in_send_ty.rs:44:5 + --> $DIR/non_send_fields_in_send_ty.rs:45:5 | LL | context: T, | ^^^^^^^^^^ = help: add `T: Send` bound in `Send` impl error: some fields in `NoGeneric` are not safe to be sent to another thread - --> $DIR/non_send_fields_in_send_ty.rs:55:1 + --> $DIR/non_send_fields_in_send_ty.rs:56:1 | LL | unsafe impl Send for NoGeneric {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: it is not safe to send field `rc_is_not_send` to another thread - --> $DIR/non_send_fields_in_send_ty.rs:52:5 + --> $DIR/non_send_fields_in_send_ty.rs:53:5 | LL | rc_is_not_send: Rc<String>, | ^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: use a thread-safe type that implements `Send` error: some fields in `MultiField<T>` are not safe to be sent to another thread - --> $DIR/non_send_fields_in_send_ty.rs:63:1 + --> $DIR/non_send_fields_in_send_ty.rs:64:1 | LL | unsafe impl<T> Send for MultiField<T> {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: it is not safe to send field `field1` to another thread - --> $DIR/non_send_fields_in_send_ty.rs:58:5 + --> $DIR/non_send_fields_in_send_ty.rs:59:5 | LL | field1: T, | ^^^^^^^^^ = help: add `T: Send` bound in `Send` impl note: it is not safe to send field `field2` to another thread - --> $DIR/non_send_fields_in_send_ty.rs:59:5 + --> $DIR/non_send_fields_in_send_ty.rs:60:5 | LL | field2: T, | ^^^^^^^^^ = help: add `T: Send` bound in `Send` impl note: it is not safe to send field `field3` to another thread - --> $DIR/non_send_fields_in_send_ty.rs:60:5 + --> $DIR/non_send_fields_in_send_ty.rs:61:5 | LL | field3: T, | ^^^^^^^^^ = help: add `T: Send` bound in `Send` impl error: some fields in `MyOption<T>` are not safe to be sent to another thread - --> $DIR/non_send_fields_in_send_ty.rs:70:1 + --> $DIR/non_send_fields_in_send_ty.rs:71:1 | LL | unsafe impl<T> Send for MyOption<T> {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: it is not safe to send field `0` to another thread - --> $DIR/non_send_fields_in_send_ty.rs:66:12 + --> $DIR/non_send_fields_in_send_ty.rs:67:12 | LL | MySome(T), | ^ = help: add `T: Send` bound in `Send` impl error: some fields in `MultiParam<A, B>` are not safe to be sent to another thread - --> $DIR/non_send_fields_in_send_ty.rs:82:1 + --> $DIR/non_send_fields_in_send_ty.rs:83:1 | LL | unsafe impl<A, B> Send for MultiParam<A, B> {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: it is not safe to send field `vec` to another thread - --> $DIR/non_send_fields_in_send_ty.rs:79:5 + --> $DIR/non_send_fields_in_send_ty.rs:80:5 | LL | vec: Vec<(A, B)>, | ^^^^^^^^^^^^^^^^ = help: add bounds on type parameters `A, B` that satisfy `Vec<(A, B)>: Send` error: some fields in `HeuristicTest` are not safe to be sent to another thread - --> $DIR/non_send_fields_in_send_ty.rs:100:1 + --> $DIR/non_send_fields_in_send_ty.rs:101:1 | LL | unsafe impl Send for HeuristicTest {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: it is not safe to send field `field4` to another thread - --> $DIR/non_send_fields_in_send_ty.rs:95:5 + --> $DIR/non_send_fields_in_send_ty.rs:96:5 | LL | field4: (*const NonSend, Rc<u8>), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: use a thread-safe type that implements `Send` error: some fields in `AttrTest3<T>` are not safe to be sent to another thread - --> $DIR/non_send_fields_in_send_ty.rs:119:1 + --> $DIR/non_send_fields_in_send_ty.rs:120:1 | LL | unsafe impl<T> Send for AttrTest3<T> {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: it is not safe to send field `0` to another thread - --> $DIR/non_send_fields_in_send_ty.rs:114:11 + --> $DIR/non_send_fields_in_send_ty.rs:115:11 | LL | Enum2(T), | ^ = help: add `T: Send` bound in `Send` impl error: some fields in `Complex<P, u32>` are not safe to be sent to another thread - --> $DIR/non_send_fields_in_send_ty.rs:127:1 + --> $DIR/non_send_fields_in_send_ty.rs:128:1 | LL | unsafe impl<P> Send for Complex<P, u32> {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: it is not safe to send field `field1` to another thread - --> $DIR/non_send_fields_in_send_ty.rs:123:5 + --> $DIR/non_send_fields_in_send_ty.rs:124:5 | LL | field1: A, | ^^^^^^^^^ = help: add `P: Send` bound in `Send` impl error: some fields in `Complex<Q, MutexGuard<'static, bool>>` are not safe to be sent to another thread - --> $DIR/non_send_fields_in_send_ty.rs:130:1 + --> $DIR/non_send_fields_in_send_ty.rs:131:1 | LL | unsafe impl<Q: Send> Send for Complex<Q, MutexGuard<'static, bool>> {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: it is not safe to send field `field2` to another thread - --> $DIR/non_send_fields_in_send_ty.rs:124:5 + --> $DIR/non_send_fields_in_send_ty.rs:125:5 | LL | field2: B, | ^^^^^^^^^ |
