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
This commit is contained in:
commit
ad88831cd5
88 changed files with 888 additions and 240 deletions
|
@ -761,9 +761,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "compiler_builtins"
|
||||
version = "0.1.66"
|
||||
version = "0.1.67"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "191424db7756bbed2c4996959a0fbda94388abcf4f5a2728a8af17481ad9c4f7"
|
||||
checksum = "a68c69e9451f1df4b215c9588c621670c12286b53e60fb5ec4b59aaa1138d18e"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"rustc-std-workspace-core",
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
#![feature(box_patterns)]
|
||||
#![feature(never_type)]
|
||||
#![recursion_limit = "256"]
|
||||
#![cfg_attr(not(bootstrap), allow(rustc::potential_query_instability))]
|
||||
|
||||
use rustc_ast::token::{self, Token};
|
||||
use rustc_ast::tokenstream::{CanSynthesizeMissingTokens, TokenStream, TokenTree};
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#![feature(box_patterns)]
|
||||
#![feature(let_else)]
|
||||
#![recursion_limit = "256"]
|
||||
#![cfg_attr(not(bootstrap), allow(rustc::potential_query_instability))]
|
||||
|
||||
pub mod ast_validation;
|
||||
pub mod feature_gate;
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#![feature(trusted_step)]
|
||||
#![feature(try_blocks)]
|
||||
#![recursion_limit = "256"]
|
||||
#![cfg_attr(not(bootstrap), allow(rustc::potential_query_instability))]
|
||||
|
||||
#[macro_use]
|
||||
extern crate rustc_middle;
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#![feature(proc_macro_internals)]
|
||||
#![feature(proc_macro_quote)]
|
||||
#![recursion_limit = "256"]
|
||||
#![cfg_attr(not(bootstrap), allow(rustc::potential_query_instability))]
|
||||
|
||||
extern crate proc_macro;
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#![feature(extern_types)]
|
||||
#![feature(nll)]
|
||||
#![recursion_limit = "256"]
|
||||
#![cfg_attr(not(bootstrap), allow(rustc::potential_query_instability))]
|
||||
|
||||
use back::write::{create_informational_target_machine, create_target_machine};
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#![feature(nll)]
|
||||
#![feature(associated_type_bounds)]
|
||||
#![recursion_limit = "256"]
|
||||
#![cfg_attr(not(bootstrap), allow(rustc::potential_query_instability))]
|
||||
|
||||
//! This crate contains codegen code that is used by all codegen backends (LLVM and others).
|
||||
//! The backend-agnostic functions of this crate use functions defined in various traits that
|
||||
|
|
|
@ -22,6 +22,7 @@ Rust MIR: a lowered representation of Rust.
|
|||
#![feature(trusted_step)]
|
||||
#![feature(try_blocks)]
|
||||
#![recursion_limit = "256"]
|
||||
#![cfg_attr(not(bootstrap), allow(rustc::potential_query_instability))]
|
||||
|
||||
#[macro_use]
|
||||
extern crate tracing;
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#![feature(vec_into_raw_parts)]
|
||||
#![allow(rustc::default_hash_types)]
|
||||
#![deny(unaligned_references)]
|
||||
#![cfg_attr(not(bootstrap), allow(rustc::potential_query_instability))]
|
||||
|
||||
#[macro_use]
|
||||
extern crate tracing;
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#![feature(nll)]
|
||||
#![feature(once_cell)]
|
||||
#![recursion_limit = "256"]
|
||||
#![cfg_attr(not(bootstrap), allow(rustc::potential_query_instability))]
|
||||
|
||||
#[macro_use]
|
||||
extern crate tracing;
|
||||
|
@ -845,7 +846,7 @@ Available lint options:
|
|||
let builtin = sort_lints(sess, builtin);
|
||||
|
||||
let (plugin_groups, builtin_groups): (Vec<_>, _) =
|
||||
lint_store.get_lint_groups().iter().cloned().partition(|&(.., p)| p);
|
||||
lint_store.get_lint_groups().partition(|&(.., p)| p);
|
||||
let plugin_groups = sort_lint_groups(plugin_groups);
|
||||
let builtin_groups = sort_lint_groups(builtin_groups);
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#![feature(if_let_guard)]
|
||||
#![feature(let_else)]
|
||||
#![feature(nll)]
|
||||
#![cfg_attr(not(bootstrap), allow(rustc::potential_query_instability))]
|
||||
|
||||
#[macro_use]
|
||||
extern crate rustc_macros;
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#![feature(proc_macro_span)]
|
||||
#![feature(try_blocks)]
|
||||
#![recursion_limit = "256"]
|
||||
#![cfg_attr(not(bootstrap), allow(rustc::potential_query_instability))]
|
||||
|
||||
#[macro_use]
|
||||
extern crate rustc_macros;
|
||||
|
|
|
@ -581,6 +581,9 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
|
|||
rustc_attr!(
|
||||
rustc_trivial_field_reads, Normal, template!(Word), WarnFollowing, INTERNAL_UNSTABLE
|
||||
),
|
||||
// Used by the `rustc::potential_query_instability` lint to warn methods which
|
||||
// might not be stable during incremental compilation.
|
||||
rustc_attr!(rustc_lint_query_instability, Normal, template!(Word), WarnFollowing, INTERNAL_UNSTABLE),
|
||||
|
||||
// ==========================================================================
|
||||
// Internal attributes, Const related:
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#![feature(let_else)]
|
||||
#![feature(nll)]
|
||||
#![recursion_limit = "256"]
|
||||
#![cfg_attr(not(bootstrap), allow(rustc::potential_query_instability))]
|
||||
|
||||
#[macro_use]
|
||||
extern crate rustc_middle;
|
||||
|
|
|
@ -938,6 +938,12 @@ pub struct GrowableBitSet<T: Idx> {
|
|||
bit_set: BitSet<T>,
|
||||
}
|
||||
|
||||
impl<T: Idx> Default for GrowableBitSet<T> {
|
||||
fn default() -> Self {
|
||||
GrowableBitSet::new_empty()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Idx> GrowableBitSet<T> {
|
||||
/// Ensure that the set can hold at least `min_domain_size` elements.
|
||||
pub fn ensure(&mut self, min_domain_size: usize) {
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#![feature(min_specialization)]
|
||||
#![feature(label_break_value)]
|
||||
#![recursion_limit = "512"] // For rustdoc
|
||||
#![cfg_attr(not(bootstrap), allow(rustc::potential_query_instability))]
|
||||
|
||||
#[macro_use]
|
||||
extern crate rustc_macros;
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#![feature(nll)]
|
||||
#![feature(once_cell)]
|
||||
#![recursion_limit = "256"]
|
||||
#![cfg_attr(not(bootstrap), allow(rustc::potential_query_instability))]
|
||||
|
||||
mod callbacks;
|
||||
pub mod interface;
|
||||
|
|
|
@ -2833,7 +2833,7 @@ impl ClashingExternDeclarations {
|
|||
return true;
|
||||
}
|
||||
let tcx = cx.tcx;
|
||||
if a == b || rustc_middle::ty::TyS::same_type(a, b) {
|
||||
if a == b {
|
||||
// All nominally-same types are structurally same, too.
|
||||
true
|
||||
} else {
|
||||
|
|
|
@ -143,7 +143,11 @@ impl LintStore {
|
|||
&self.lints
|
||||
}
|
||||
|
||||
pub fn get_lint_groups<'t>(&'t self) -> Vec<(&'static str, Vec<LintId>, bool)> {
|
||||
pub fn get_lint_groups<'t>(
|
||||
&'t self,
|
||||
) -> impl Iterator<Item = (&'static str, Vec<LintId>, bool)> + 't {
|
||||
// This function is not used in a way which observes the order of lints.
|
||||
#[cfg_attr(not(bootstrap), allow(rustc::potential_query_instability))]
|
||||
self.lint_groups
|
||||
.iter()
|
||||
.filter(|(_, LintGroup { depr, .. })| {
|
||||
|
@ -153,7 +157,6 @@ impl LintStore {
|
|||
.map(|(k, LintGroup { lint_ids, from_plugin, .. })| {
|
||||
(*k, lint_ids.clone(), *from_plugin)
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub fn register_early_pass(
|
||||
|
|
|
@ -5,7 +5,8 @@ use crate::{EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintContext}
|
|||
use rustc_ast as ast;
|
||||
use rustc_errors::Applicability;
|
||||
use rustc_hir::def::Res;
|
||||
use rustc_hir::{GenericArg, HirId, Item, ItemKind, Node, Path, PathSegment, QPath, Ty, TyKind};
|
||||
use rustc_hir::{Expr, ExprKind, GenericArg, Path, PathSegment, QPath};
|
||||
use rustc_hir::{HirId, Item, ItemKind, Node, Ty, TyKind};
|
||||
use rustc_middle::ty;
|
||||
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
||||
use rustc_span::hygiene::{ExpnKind, MacroKind};
|
||||
|
@ -48,6 +49,63 @@ impl LateLintPass<'_> for DefaultHashTypes {
|
|||
}
|
||||
}
|
||||
|
||||
declare_tool_lint! {
|
||||
pub rustc::POTENTIAL_QUERY_INSTABILITY,
|
||||
Allow,
|
||||
"require explicit opt-in when using potentially unstable methods or functions",
|
||||
report_in_external_macro: true
|
||||
}
|
||||
|
||||
declare_lint_pass!(QueryStability => [POTENTIAL_QUERY_INSTABILITY]);
|
||||
|
||||
impl LateLintPass<'_> for QueryStability {
|
||||
fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) {
|
||||
// FIXME(rustdoc): This lint uses typecheck results, causing rustdoc to
|
||||
// error if there are resolution failures.
|
||||
//
|
||||
// As internal lints are currently always run if there are `unstable_options`,
|
||||
// they are added to the lint store of rustdoc. Internal lints are also
|
||||
// not used via the `lint_mod` query. Crate lints run outside of a query
|
||||
// so rustdoc currently doesn't disable them.
|
||||
//
|
||||
// Instead of relying on this, either change crate lints to a query disabled by
|
||||
// rustdoc, only run internal lints if the user is explicitly opting in
|
||||
// or figure out a different way to avoid running lints for rustdoc.
|
||||
if cx.tcx.sess.opts.actually_rustdoc {
|
||||
return;
|
||||
}
|
||||
|
||||
let (span, def_id, substs) = match expr.kind {
|
||||
ExprKind::MethodCall(segment, _, _)
|
||||
if let Some(def_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id) =>
|
||||
{
|
||||
(segment.ident.span, def_id, cx.typeck_results().node_substs(expr.hir_id))
|
||||
},
|
||||
_ => {
|
||||
let &ty::FnDef(def_id, substs) =
|
||||
cx.typeck_results()
|
||||
.node_type(expr.hir_id)
|
||||
.kind() else { return };
|
||||
(expr.span, def_id, substs)
|
||||
}
|
||||
};
|
||||
if let Ok(Some(instance)) = ty::Instance::resolve(cx.tcx, cx.param_env, def_id, substs) {
|
||||
let def_id = instance.def_id();
|
||||
if cx.tcx.has_attr(def_id, sym::rustc_lint_query_instability) {
|
||||
cx.struct_span_lint(POTENTIAL_QUERY_INSTABILITY, span, |lint| {
|
||||
let msg = format!(
|
||||
"using `{}` can result in unstable query results",
|
||||
cx.tcx.item_name(def_id)
|
||||
);
|
||||
lint.build(&msg)
|
||||
.note("if you believe this case to be fine, allow this lint and add a comment explaining your rationale")
|
||||
.emit();
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
declare_tool_lint! {
|
||||
pub rustc::USAGE_OF_TY_TYKIND,
|
||||
Allow,
|
||||
|
|
|
@ -30,12 +30,14 @@
|
|||
#![feature(bool_to_option)]
|
||||
#![feature(box_patterns)]
|
||||
#![feature(crate_visibility_modifier)]
|
||||
#![feature(if_let_guard)]
|
||||
#![feature(iter_order_by)]
|
||||
#![feature(let_else)]
|
||||
#![feature(never_type)]
|
||||
#![feature(nll)]
|
||||
#![feature(control_flow_enum)]
|
||||
#![recursion_limit = "256"]
|
||||
#![cfg_attr(not(bootstrap), allow(rustc::potential_query_instability))]
|
||||
|
||||
#[macro_use]
|
||||
extern crate rustc_middle;
|
||||
|
@ -493,6 +495,8 @@ fn register_internals(store: &mut LintStore) {
|
|||
store.register_early_pass(|| Box::new(LintPassImpl));
|
||||
store.register_lints(&DefaultHashTypes::get_lints());
|
||||
store.register_late_pass(|| Box::new(DefaultHashTypes));
|
||||
store.register_lints(&QueryStability::get_lints());
|
||||
store.register_late_pass(|| Box::new(QueryStability));
|
||||
store.register_lints(&ExistingDocKeyword::get_lints());
|
||||
store.register_late_pass(|| Box::new(ExistingDocKeyword));
|
||||
store.register_lints(&TyTyKind::get_lints());
|
||||
|
@ -505,6 +509,7 @@ fn register_internals(store: &mut LintStore) {
|
|||
None,
|
||||
vec![
|
||||
LintId::of(DEFAULT_HASH_TYPES),
|
||||
LintId::of(POTENTIAL_QUERY_INSTABILITY),
|
||||
LintId::of(USAGE_OF_TY_TYKIND),
|
||||
LintId::of(PASS_BY_VALUE),
|
||||
LintId::of(LINT_PASS_IMPL_WITHOUT_MACRO),
|
||||
|
|
|
@ -1793,6 +1793,10 @@ declare_lint! {
|
|||
Warn,
|
||||
"detects name collision with an existing but unstable method",
|
||||
@future_incompatible = FutureIncompatibleInfo {
|
||||
reason: FutureIncompatibilityReason::Custom(
|
||||
"once this associated item is added to the standard library, \
|
||||
the ambiguity may cause an error or change in behavior!"
|
||||
),
|
||||
reference: "issue #48919 <https://github.com/rust-lang/rust/issues/48919>",
|
||||
// Note: this item represents future incompatibility of all unstable functions in the
|
||||
// standard library, and thus should never be removed or changed to an error.
|
||||
|
@ -2335,6 +2339,10 @@ declare_lint! {
|
|||
Warn,
|
||||
"reservation of a two-phased borrow conflicts with other shared borrows",
|
||||
@future_incompatible = FutureIncompatibleInfo {
|
||||
reason: FutureIncompatibilityReason::Custom(
|
||||
"this borrowing pattern was not meant to be accepted, \
|
||||
and may become a hard error in the future"
|
||||
),
|
||||
reference: "issue #59159 <https://github.com/rust-lang/rust/issues/59159>",
|
||||
};
|
||||
}
|
||||
|
@ -3046,6 +3054,7 @@ declare_lint_pass! {
|
|||
DEREF_INTO_DYN_SUPERTRAIT,
|
||||
DEPRECATED_CFG_ATTR_CRATE_TYPE_NAME,
|
||||
DUPLICATE_MACRO_ATTRIBUTES,
|
||||
SUSPICIOUS_AUTO_TRAIT_IMPLS,
|
||||
]
|
||||
}
|
||||
|
||||
|
@ -3622,3 +3631,37 @@ declare_lint! {
|
|||
Warn,
|
||||
"duplicated attribute"
|
||||
}
|
||||
|
||||
declare_lint! {
|
||||
/// The `suspicious_auto_trait_impls` lint checks for potentially incorrect
|
||||
/// implementations of auto traits.
|
||||
///
|
||||
/// ### Example
|
||||
///
|
||||
/// ```rust
|
||||
/// struct Foo<T>(T);
|
||||
///
|
||||
/// unsafe impl<T> Send for Foo<*const T> {}
|
||||
/// ```
|
||||
///
|
||||
/// {{produces}}
|
||||
///
|
||||
/// ### Explanation
|
||||
///
|
||||
/// A type can implement auto traits, e.g. `Send`, `Sync` and `Unpin`,
|
||||
/// in two different ways: either by writing an explicit impl or if
|
||||
/// all fields of the type implement that auto trait.
|
||||
///
|
||||
/// The compiler disables the automatic implementation if an explicit one
|
||||
/// exists for given type constructor. The exact rules governing this
|
||||
/// are currently unsound and quite subtle and and will be modified in the future.
|
||||
/// This change will cause the automatic implementation to be disabled in more
|
||||
/// cases, potentially breaking some code.
|
||||
pub SUSPICIOUS_AUTO_TRAIT_IMPLS,
|
||||
Warn,
|
||||
"the rules governing auto traits will change in the future",
|
||||
@future_incompatible = FutureIncompatibleInfo {
|
||||
reason: FutureIncompatibilityReason::FutureReleaseSemanticsChange,
|
||||
reference: "issue #93367 <https://github.com/rust-lang/rust/issues/93367>",
|
||||
};
|
||||
}
|
||||
|
|
|
@ -163,12 +163,17 @@ pub enum FutureIncompatibilityReason {
|
|||
/// This will be an error in a future release, and
|
||||
/// Cargo should create a report even for dependencies
|
||||
FutureReleaseErrorReportNow,
|
||||
/// Code that changes meaning in some way in a
|
||||
/// future release.
|
||||
FutureReleaseSemanticsChange,
|
||||
/// Previously accepted code that will become an
|
||||
/// error in the provided edition
|
||||
EditionError(Edition),
|
||||
/// Code that changes meaning in some way in
|
||||
/// the provided edition
|
||||
EditionSemanticsChange(Edition),
|
||||
/// A custom reason.
|
||||
Custom(&'static str),
|
||||
}
|
||||
|
||||
impl FutureIncompatibilityReason {
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#![feature(try_blocks)]
|
||||
#![feature(never_type)]
|
||||
#![recursion_limit = "256"]
|
||||
#![cfg_attr(not(bootstrap), allow(rustc::potential_query_instability))]
|
||||
|
||||
extern crate proc_macro;
|
||||
|
||||
|
|
|
@ -56,6 +56,7 @@
|
|||
#![feature(nonzero_ops)]
|
||||
#![feature(unwrap_infallible)]
|
||||
#![recursion_limit = "512"]
|
||||
#![cfg_attr(not(bootstrap), allow(rustc::potential_query_instability))]
|
||||
|
||||
#[macro_use]
|
||||
extern crate bitflags;
|
||||
|
|
|
@ -221,7 +221,6 @@ pub fn struct_lint_level<'s, 'd>(
|
|||
decorate: Box<dyn for<'b> FnOnce(LintDiagnosticBuilder<'b>) + 'd>,
|
||||
) {
|
||||
// Check for future incompatibility lints and issue a stronger warning.
|
||||
let lint_id = LintId::of(lint);
|
||||
let future_incompatible = lint.future_incompatible;
|
||||
|
||||
let has_future_breakage = future_incompatible.map_or(
|
||||
|
@ -345,31 +344,29 @@ pub fn struct_lint_level<'s, 'd>(
|
|||
err.code(DiagnosticId::Lint { name, has_future_breakage, is_force_warn });
|
||||
|
||||
if let Some(future_incompatible) = future_incompatible {
|
||||
let explanation = if lint_id == LintId::of(builtin::UNSTABLE_NAME_COLLISIONS) {
|
||||
"once this associated item is added to the standard library, the ambiguity may \
|
||||
cause an error or change in behavior!"
|
||||
.to_owned()
|
||||
} else if lint_id == LintId::of(builtin::MUTABLE_BORROW_RESERVATION_CONFLICT) {
|
||||
"this borrowing pattern was not meant to be accepted, and may become a hard error \
|
||||
in the future"
|
||||
.to_owned()
|
||||
} else if let FutureIncompatibilityReason::EditionError(edition) =
|
||||
future_incompatible.reason
|
||||
{
|
||||
let current_edition = sess.edition();
|
||||
format!(
|
||||
"this is accepted in the current edition (Rust {}) but is a hard error in Rust {}!",
|
||||
current_edition, edition
|
||||
)
|
||||
} else if let FutureIncompatibilityReason::EditionSemanticsChange(edition) =
|
||||
future_incompatible.reason
|
||||
{
|
||||
format!("this changes meaning in Rust {}", edition)
|
||||
} else {
|
||||
"this was previously accepted by the compiler but is being phased out; \
|
||||
it will become a hard error in a future release!"
|
||||
.to_owned()
|
||||
let explanation = match future_incompatible.reason {
|
||||
FutureIncompatibilityReason::FutureReleaseError
|
||||
| FutureIncompatibilityReason::FutureReleaseErrorReportNow => {
|
||||
"this was previously accepted by the compiler but is being phased out; \
|
||||
it will become a hard error in a future release!"
|
||||
.to_owned()
|
||||
}
|
||||
FutureIncompatibilityReason::FutureReleaseSemanticsChange => {
|
||||
"this will change its meaning in a future release!".to_owned()
|
||||
}
|
||||
FutureIncompatibilityReason::EditionError(edition) => {
|
||||
let current_edition = sess.edition();
|
||||
format!(
|
||||
"this is accepted in the current edition (Rust {}) but is a hard error in Rust {}!",
|
||||
current_edition, edition
|
||||
)
|
||||
}
|
||||
FutureIncompatibilityReason::EditionSemanticsChange(edition) => {
|
||||
format!("this changes meaning in Rust {}", edition)
|
||||
}
|
||||
FutureIncompatibilityReason::Custom(reason) => reason.to_owned(),
|
||||
};
|
||||
|
||||
if future_incompatible.explain_reason {
|
||||
err.warn(&explanation);
|
||||
}
|
||||
|
|
|
@ -144,6 +144,23 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
});
|
||||
}
|
||||
|
||||
pub fn non_blanket_impls_for_ty(
|
||||
self,
|
||||
def_id: DefId,
|
||||
self_ty: Ty<'tcx>,
|
||||
) -> impl Iterator<Item = DefId> + 'tcx {
|
||||
let impls = self.trait_impls_of(def_id);
|
||||
if let Some(simp) =
|
||||
fast_reject::simplify_type(self, self_ty, SimplifyParams::No, StripReferences::No)
|
||||
{
|
||||
if let Some(impls) = impls.non_blanket_impls.get(&simp) {
|
||||
return impls.iter().copied();
|
||||
}
|
||||
}
|
||||
|
||||
[].iter().copied()
|
||||
}
|
||||
|
||||
/// Applies function to every impl that could possibly match the self type `self_ty` and returns
|
||||
/// the first non-none value.
|
||||
pub fn find_map_relevant_impl<T, F: FnMut(DefId) -> Option<T>>(
|
||||
|
|
|
@ -893,19 +893,6 @@ impl<'tcx> ty::TyS<'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn same_type(a: Ty<'tcx>, b: Ty<'tcx>) -> bool {
|
||||
match (&a.kind(), &b.kind()) {
|
||||
(&Adt(did_a, substs_a), &Adt(did_b, substs_b)) => {
|
||||
if did_a != did_b {
|
||||
return false;
|
||||
}
|
||||
|
||||
substs_a.types().zip(substs_b.types()).all(|(a, b)| Self::same_type(a, b))
|
||||
}
|
||||
_ => a == b,
|
||||
}
|
||||
}
|
||||
|
||||
/// Peel off all reference types in this type until there are none left.
|
||||
///
|
||||
/// This method is idempotent, i.e. `ty.peel_refs().peel_refs() == ty.peel_refs()`.
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#![feature(once_cell)]
|
||||
#![feature(min_specialization)]
|
||||
#![recursion_limit = "256"]
|
||||
#![cfg_attr(not(bootstrap), allow(rustc::potential_query_instability))]
|
||||
|
||||
#[macro_use]
|
||||
extern crate tracing;
|
||||
|
|
|
@ -6,7 +6,7 @@ use rustc_middle::mir::*;
|
|||
use rustc_middle::ty::{
|
||||
self,
|
||||
subst::{GenericArgKind, Subst, SubstsRef},
|
||||
PredicateKind, Ty, TyCtxt, TyS,
|
||||
PredicateKind, Ty, TyCtxt,
|
||||
};
|
||||
use rustc_session::lint::builtin::FUNCTION_ITEM_REFERENCES;
|
||||
use rustc_span::{symbol::sym, Span};
|
||||
|
@ -88,7 +88,7 @@ impl<'tcx> FunctionItemRefChecker<'_, 'tcx> {
|
|||
for generic_inner_ty in arg_def.walk() {
|
||||
if let GenericArgKind::Type(inner_ty) = generic_inner_ty.unpack() {
|
||||
// If the inner type matches the type bound by `Pointer`
|
||||
if TyS::same_type(inner_ty, bound_ty) {
|
||||
if inner_ty == bound_ty {
|
||||
// Do a substitution using the parameters from the callsite
|
||||
let subst_ty = inner_ty.subst(self.tcx, substs_ref);
|
||||
if let Some((fn_id, fn_substs)) =
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#![feature(trusted_step)]
|
||||
#![feature(try_blocks)]
|
||||
#![recursion_limit = "256"]
|
||||
#![cfg_attr(not(bootstrap), allow(rustc::potential_query_instability))]
|
||||
|
||||
#[macro_use]
|
||||
extern crate tracing;
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#![feature(control_flow_enum)]
|
||||
#![feature(let_else)]
|
||||
#![recursion_limit = "256"]
|
||||
#![cfg_attr(not(bootstrap), allow(rustc::potential_query_instability))]
|
||||
|
||||
#[macro_use]
|
||||
extern crate tracing;
|
||||
|
|
|
@ -62,7 +62,7 @@ impl CheckAttrVisitor<'_> {
|
|||
fn check_attributes(
|
||||
&self,
|
||||
hir_id: HirId,
|
||||
span: &Span,
|
||||
span: Span,
|
||||
target: Target,
|
||||
item: Option<ItemLike<'_>>,
|
||||
) {
|
||||
|
@ -81,7 +81,7 @@ impl CheckAttrVisitor<'_> {
|
|||
}
|
||||
sym::target_feature => self.check_target_feature(hir_id, attr, span, target),
|
||||
sym::track_caller => {
|
||||
self.check_track_caller(hir_id, &attr.span, attrs, span, target)
|
||||
self.check_track_caller(hir_id, attr.span, attrs, span, target)
|
||||
}
|
||||
sym::doc => self.check_doc_attrs(
|
||||
attr,
|
||||
|
@ -106,6 +106,9 @@ impl CheckAttrVisitor<'_> {
|
|||
sym::rustc_legacy_const_generics => {
|
||||
self.check_rustc_legacy_const_generics(&attr, span, target, item)
|
||||
}
|
||||
sym::rustc_lint_query_instability => {
|
||||
self.check_rustc_lint_query_instability(&attr, span, target)
|
||||
}
|
||||
sym::rustc_clean
|
||||
| sym::rustc_dirty
|
||||
| sym::rustc_if_this_changed
|
||||
|
@ -253,7 +256,7 @@ impl CheckAttrVisitor<'_> {
|
|||
}
|
||||
|
||||
/// Checks if an `#[inline]` is applied to a function or a closure. Returns `true` if valid.
|
||||
fn check_inline(&self, hir_id: HirId, attr: &Attribute, span: &Span, target: Target) -> bool {
|
||||
fn check_inline(&self, hir_id: HirId, attr: &Attribute, span: Span, target: Target) -> bool {
|
||||
match target {
|
||||
Target::Fn
|
||||
| Target::Closure
|
||||
|
@ -296,7 +299,7 @@ impl CheckAttrVisitor<'_> {
|
|||
E0518,
|
||||
"attribute should be applied to function or closure",
|
||||
)
|
||||
.span_label(*span, "not a function or closure")
|
||||
.span_label(span, "not a function or closure")
|
||||
.emit();
|
||||
false
|
||||
}
|
||||
|
@ -335,7 +338,7 @@ impl CheckAttrVisitor<'_> {
|
|||
}
|
||||
|
||||
/// Checks if `#[naked]` is applied to a function definition.
|
||||
fn check_naked(&self, hir_id: HirId, attr: &Attribute, span: &Span, target: Target) -> bool {
|
||||
fn check_naked(&self, hir_id: HirId, attr: &Attribute, span: Span, target: Target) -> bool {
|
||||
match target {
|
||||
Target::Fn
|
||||
| Target::Method(MethodKind::Trait { body: true } | MethodKind::Inherent) => true,
|
||||
|
@ -354,7 +357,7 @@ impl CheckAttrVisitor<'_> {
|
|||
attr.span,
|
||||
"attribute should be applied to a function definition",
|
||||
)
|
||||
.span_label(*span, "not a function definition")
|
||||
.span_label(span, "not a function definition")
|
||||
.emit();
|
||||
false
|
||||
}
|
||||
|
@ -362,7 +365,7 @@ impl CheckAttrVisitor<'_> {
|
|||
}
|
||||
|
||||
/// Checks if `#[cmse_nonsecure_entry]` is applied to a function definition.
|
||||
fn check_cmse_nonsecure_entry(&self, attr: &Attribute, span: &Span, target: Target) -> bool {
|
||||
fn check_cmse_nonsecure_entry(&self, attr: &Attribute, span: Span, target: Target) -> bool {
|
||||
match target {
|
||||
Target::Fn
|
||||
| Target::Method(MethodKind::Trait { body: true } | MethodKind::Inherent) => true,
|
||||
|
@ -373,7 +376,7 @@ impl CheckAttrVisitor<'_> {
|
|||
attr.span,
|
||||
"attribute should be applied to a function definition",
|
||||
)
|
||||
.span_label(*span, "not a function definition")
|
||||
.span_label(span, "not a function definition")
|
||||
.emit();
|
||||
false
|
||||
}
|
||||
|
@ -384,16 +387,16 @@ impl CheckAttrVisitor<'_> {
|
|||
fn check_track_caller(
|
||||
&self,
|
||||
hir_id: HirId,
|
||||
attr_span: &Span,
|
||||
attr_span: Span,
|
||||
attrs: &[Attribute],
|
||||
span: &Span,
|
||||
span: Span,
|
||||
target: Target,
|
||||
) -> bool {
|
||||
match target {
|
||||
_ if attrs.iter().any(|attr| attr.has_name(sym::naked)) => {
|
||||
struct_span_err!(
|
||||
self.tcx.sess,
|
||||
*attr_span,
|
||||
attr_span,
|
||||
E0736,
|
||||
"cannot use `#[track_caller]` with `#[naked]`",
|
||||
)
|
||||
|
@ -414,11 +417,11 @@ impl CheckAttrVisitor<'_> {
|
|||
_ => {
|
||||
struct_span_err!(
|
||||
self.tcx.sess,
|
||||
*attr_span,
|
||||
attr_span,
|
||||
E0739,
|
||||
"attribute should be applied to function"
|
||||
)
|
||||
.span_label(*span, "not a function")
|
||||
.span_label(span, "not a function")
|
||||
.emit();
|
||||
false
|
||||
}
|
||||
|
@ -430,7 +433,7 @@ impl CheckAttrVisitor<'_> {
|
|||
&self,
|
||||
hir_id: HirId,
|
||||
attr: &Attribute,
|
||||
span: &Span,
|
||||
span: Span,
|
||||
target: Target,
|
||||
) -> bool {
|
||||
match target {
|
||||
|
@ -450,7 +453,7 @@ impl CheckAttrVisitor<'_> {
|
|||
E0701,
|
||||
"attribute can only be applied to a struct or enum"
|
||||
)
|
||||
.span_label(*span, "not a struct or enum")
|
||||
.span_label(span, "not a struct or enum")
|
||||
.emit();
|
||||
false
|
||||
}
|
||||
|
@ -458,7 +461,7 @@ impl CheckAttrVisitor<'_> {
|
|||
}
|
||||
|
||||
/// Checks if the `#[marker]` attribute on an `item` is valid. Returns `true` if valid.
|
||||
fn check_marker(&self, hir_id: HirId, attr: &Attribute, span: &Span, target: Target) -> bool {
|
||||
fn check_marker(&self, hir_id: HirId, attr: &Attribute, span: Span, target: Target) -> bool {
|
||||
match target {
|
||||
Target::Trait => true,
|
||||
// FIXME(#80564): We permit struct fields, match arms and macro defs to have an
|
||||
|
@ -473,7 +476,7 @@ impl CheckAttrVisitor<'_> {
|
|||
self.tcx
|
||||
.sess
|
||||
.struct_span_err(attr.span, "attribute can only be applied to a trait")
|
||||
.span_label(*span, "not a trait")
|
||||
.span_label(span, "not a trait")
|
||||
.emit();
|
||||
false
|
||||
}
|
||||
|
@ -484,7 +487,7 @@ impl CheckAttrVisitor<'_> {
|
|||
fn check_rustc_must_implement_one_of(
|
||||
&self,
|
||||
attr: &Attribute,
|
||||
span: &Span,
|
||||
span: Span,
|
||||
target: Target,
|
||||
) -> bool {
|
||||
match target {
|
||||
|
@ -493,7 +496,7 @@ impl CheckAttrVisitor<'_> {
|
|||
self.tcx
|
||||
.sess
|
||||
.struct_span_err(attr.span, "attribute can only be applied to a trait")
|
||||
.span_label(*span, "not a trait")
|
||||
.span_label(span, "not a trait")
|
||||
.emit();
|
||||
false
|
||||
}
|
||||
|
@ -505,7 +508,7 @@ impl CheckAttrVisitor<'_> {
|
|||
&self,
|
||||
hir_id: HirId,
|
||||
attr: &Attribute,
|
||||
span: &Span,
|
||||
span: Span,
|
||||
target: Target,
|
||||
) -> bool {
|
||||
match target {
|
||||
|
@ -521,7 +524,7 @@ impl CheckAttrVisitor<'_> {
|
|||
being phased out; it will become a hard error in \
|
||||
a future release!",
|
||||
)
|
||||
.span_label(*span, "not a function")
|
||||
.span_label(span, "not a function")
|
||||
.emit();
|
||||
});
|
||||
true
|
||||
|
@ -538,7 +541,7 @@ impl CheckAttrVisitor<'_> {
|
|||
self.tcx
|
||||
.sess
|
||||
.struct_span_err(attr.span, "attribute should be applied to a function")
|
||||
.span_label(*span, "not a function")
|
||||
.span_label(span, "not a function")
|
||||
.emit();
|
||||
false
|
||||
}
|
||||
|
@ -1090,7 +1093,7 @@ impl CheckAttrVisitor<'_> {
|
|||
}
|
||||
|
||||
/// Warns against some misuses of `#[pass_by_value]`
|
||||
fn check_pass_by_value(&self, attr: &Attribute, span: &Span, target: Target) -> bool {
|
||||
fn check_pass_by_value(&self, attr: &Attribute, span: Span, target: Target) -> bool {
|
||||
match target {
|
||||
Target::Struct | Target::Enum | Target::TyAlias => true,
|
||||
_ => {
|
||||
|
@ -1100,7 +1103,7 @@ impl CheckAttrVisitor<'_> {
|
|||
attr.span,
|
||||
"`pass_by_value` attribute should be applied to a struct, enum or type alias.",
|
||||
)
|
||||
.span_label(*span, "is not a struct, enum or type alias")
|
||||
.span_label(span, "is not a struct, enum or type alias")
|
||||
.emit();
|
||||
false
|
||||
}
|
||||
|
@ -1108,13 +1111,7 @@ impl CheckAttrVisitor<'_> {
|
|||
}
|
||||
|
||||
/// Warns against some misuses of `#[must_use]`
|
||||
fn check_must_use(
|
||||
&self,
|
||||
hir_id: HirId,
|
||||
attr: &Attribute,
|
||||
span: &Span,
|
||||
_target: Target,
|
||||
) -> bool {
|
||||
fn check_must_use(&self, hir_id: HirId, attr: &Attribute, span: Span, _target: Target) -> bool {
|
||||
let node = self.tcx.hir().get(hir_id);
|
||||
if let Some(fn_node) = node.fn_kind() {
|
||||
if let rustc_hir::IsAsync::Async = fn_node.asyncness() {
|
||||
|
@ -1125,7 +1122,7 @@ impl CheckAttrVisitor<'_> {
|
|||
function, not the value within",
|
||||
)
|
||||
.span_label(
|
||||
*span,
|
||||
span,
|
||||
"this attribute does nothing, the `Future`s \
|
||||
returned by async functions are already `must_use`",
|
||||
)
|
||||
|
@ -1139,14 +1136,14 @@ impl CheckAttrVisitor<'_> {
|
|||
}
|
||||
|
||||
/// Checks if `#[must_not_suspend]` is applied to a function. Returns `true` if valid.
|
||||
fn check_must_not_suspend(&self, attr: &Attribute, span: &Span, target: Target) -> bool {
|
||||
fn check_must_not_suspend(&self, attr: &Attribute, span: Span, target: Target) -> bool {
|
||||
match target {
|
||||
Target::Struct | Target::Enum | Target::Union | Target::Trait => true,
|
||||
_ => {
|
||||
self.tcx
|
||||
.sess
|
||||
.struct_span_err(attr.span, "`must_not_suspend` attribute should be applied to a struct, enum, or trait")
|
||||
.span_label(*span, "is not a struct, enum, or trait")
|
||||
.span_label(span, "is not a struct, enum, or trait")
|
||||
.emit();
|
||||
false
|
||||
}
|
||||
|
@ -1154,7 +1151,7 @@ impl CheckAttrVisitor<'_> {
|
|||
}
|
||||
|
||||
/// Checks if `#[cold]` is applied to a non-function. Returns `true` if valid.
|
||||
fn check_cold(&self, hir_id: HirId, attr: &Attribute, span: &Span, target: Target) {
|
||||
fn check_cold(&self, hir_id: HirId, attr: &Attribute, span: Span, target: Target) {
|
||||
match target {
|
||||
Target::Fn | Target::Method(..) | Target::ForeignFn | Target::Closure => {}
|
||||
// FIXME(#80564): We permit struct fields, match arms and macro defs to have an
|
||||
|
@ -1174,7 +1171,7 @@ impl CheckAttrVisitor<'_> {
|
|||
being phased out; it will become a hard error in \
|
||||
a future release!",
|
||||
)
|
||||
.span_label(*span, "not a function")
|
||||
.span_label(span, "not a function")
|
||||
.emit();
|
||||
});
|
||||
}
|
||||
|
@ -1182,7 +1179,7 @@ impl CheckAttrVisitor<'_> {
|
|||
}
|
||||
|
||||
/// Checks if `#[link]` is applied to an item other than a foreign module.
|
||||
fn check_link(&self, hir_id: HirId, attr: &Attribute, span: &Span, target: Target) {
|
||||
fn check_link(&self, hir_id: HirId, attr: &Attribute, span: Span, target: Target) {
|
||||
match target {
|
||||
Target::ForeignMod => {}
|
||||
_ => {
|
||||
|
@ -1194,7 +1191,7 @@ impl CheckAttrVisitor<'_> {
|
|||
a future release!",
|
||||
);
|
||||
|
||||
diag.span_label(*span, "not an `extern` block");
|
||||
diag.span_label(span, "not an `extern` block");
|
||||
diag.emit();
|
||||
});
|
||||
}
|
||||
|
@ -1202,7 +1199,7 @@ impl CheckAttrVisitor<'_> {
|
|||
}
|
||||
|
||||
/// Checks if `#[link_name]` is applied to an item other than a foreign function or static.
|
||||
fn check_link_name(&self, hir_id: HirId, attr: &Attribute, span: &Span, target: Target) {
|
||||
fn check_link_name(&self, hir_id: HirId, attr: &Attribute, span: Span, target: Target) {
|
||||
match target {
|
||||
Target::ForeignFn | Target::ForeignStatic => {}
|
||||
// FIXME(#80564): We permit struct fields, match arms and macro defs to have an
|
||||
|
@ -1236,7 +1233,7 @@ impl CheckAttrVisitor<'_> {
|
|||
}
|
||||
}
|
||||
|
||||
diag.span_label(*span, "not a foreign function or static");
|
||||
diag.span_label(span, "not a foreign function or static");
|
||||
diag.emit();
|
||||
});
|
||||
}
|
||||
|
@ -1244,7 +1241,7 @@ impl CheckAttrVisitor<'_> {
|
|||
}
|
||||
|
||||
/// Checks if `#[no_link]` is applied to an `extern crate`. Returns `true` if valid.
|
||||
fn check_no_link(&self, hir_id: HirId, attr: &Attribute, span: &Span, target: Target) -> bool {
|
||||
fn check_no_link(&self, hir_id: HirId, attr: &Attribute, span: Span, target: Target) -> bool {
|
||||
match target {
|
||||
Target::ExternCrate => true,
|
||||
// FIXME(#80564): We permit struct fields, match arms and macro defs to have an
|
||||
|
@ -1262,7 +1259,7 @@ impl CheckAttrVisitor<'_> {
|
|||
attr.span,
|
||||
"attribute should be applied to an `extern crate` item",
|
||||
)
|
||||
.span_label(*span, "not an `extern crate` item")
|
||||
.span_label(span, "not an `extern crate` item")
|
||||
.emit();
|
||||
false
|
||||
}
|
||||
|
@ -1278,7 +1275,7 @@ impl CheckAttrVisitor<'_> {
|
|||
&self,
|
||||
hir_id: HirId,
|
||||
attr: &Attribute,
|
||||
span: &Span,
|
||||
span: Span,
|
||||
target: Target,
|
||||
) -> bool {
|
||||
match target {
|
||||
|
@ -1299,7 +1296,7 @@ impl CheckAttrVisitor<'_> {
|
|||
attr.span,
|
||||
"attribute should be applied to a free function, impl method or static",
|
||||
)
|
||||
.span_label(*span, "not a free function, impl method or static")
|
||||
.span_label(span, "not a free function, impl method or static")
|
||||
.emit();
|
||||
false
|
||||
}
|
||||
|
@ -1309,14 +1306,14 @@ impl CheckAttrVisitor<'_> {
|
|||
fn check_rustc_layout_scalar_valid_range(
|
||||
&self,
|
||||
attr: &Attribute,
|
||||
span: &Span,
|
||||
span: Span,
|
||||
target: Target,
|
||||
) -> bool {
|
||||
if target != Target::Struct {
|
||||
self.tcx
|
||||
.sess
|
||||
.struct_span_err(attr.span, "attribute should be applied to a struct")
|
||||
.span_label(*span, "not a struct")
|
||||
.span_label(span, "not a struct")
|
||||
.emit();
|
||||
return false;
|
||||
}
|
||||
|
@ -1341,7 +1338,7 @@ impl CheckAttrVisitor<'_> {
|
|||
fn check_rustc_legacy_const_generics(
|
||||
&self,
|
||||
attr: &Attribute,
|
||||
span: &Span,
|
||||
span: Span,
|
||||
target: Target,
|
||||
item: Option<ItemLike<'_>>,
|
||||
) -> bool {
|
||||
|
@ -1350,7 +1347,7 @@ impl CheckAttrVisitor<'_> {
|
|||
self.tcx
|
||||
.sess
|
||||
.struct_span_err(attr.span, "attribute should be applied to a function")
|
||||
.span_label(*span, "not a function")
|
||||
.span_label(span, "not a function")
|
||||
.emit();
|
||||
return false;
|
||||
}
|
||||
|
@ -1436,6 +1433,25 @@ impl CheckAttrVisitor<'_> {
|
|||
}
|
||||
}
|
||||
|
||||
fn check_rustc_lint_query_instability(
|
||||
&self,
|
||||
attr: &Attribute,
|
||||
span: Span,
|
||||
target: Target,
|
||||
) -> bool {
|
||||
let is_function = matches!(target, Target::Fn | Target::Method(..));
|
||||
if !is_function {
|
||||
self.tcx
|
||||
.sess
|
||||
.struct_span_err(attr.span, "attribute should be applied to a function")
|
||||
.span_label(span, "not a function")
|
||||
.emit();
|
||||
false
|
||||
} else {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
/// Checks that the dep-graph debugging attributes are only present when the query-dep-graph
|
||||
/// option is passed to the compiler.
|
||||
fn check_rustc_dirty_clean(&self, attr: &Attribute) -> bool {
|
||||
|
@ -1451,7 +1467,7 @@ impl CheckAttrVisitor<'_> {
|
|||
}
|
||||
|
||||
/// Checks if `#[link_section]` is applied to a function or static.
|
||||
fn check_link_section(&self, hir_id: HirId, attr: &Attribute, span: &Span, target: Target) {
|
||||
fn check_link_section(&self, hir_id: HirId, attr: &Attribute, span: Span, target: Target) {
|
||||
match target {
|
||||
Target::Static | Target::Fn | Target::Method(..) => {}
|
||||
// FIXME(#80564): We permit struct fields, match arms and macro defs to have an
|
||||
|
@ -1471,7 +1487,7 @@ impl CheckAttrVisitor<'_> {
|
|||
being phased out; it will become a hard error in \
|
||||
a future release!",
|
||||
)
|
||||
.span_label(*span, "not a function or static")
|
||||
.span_label(span, "not a function or static")
|
||||
.emit();
|
||||
});
|
||||
}
|
||||
|
@ -1479,7 +1495,7 @@ impl CheckAttrVisitor<'_> {
|
|||
}
|
||||
|
||||
/// Checks if `#[no_mangle]` is applied to a function or static.
|
||||
fn check_no_mangle(&self, hir_id: HirId, attr: &Attribute, span: &Span, target: Target) {
|
||||
fn check_no_mangle(&self, hir_id: HirId, attr: &Attribute, span: Span, target: Target) {
|
||||
match target {
|
||||
Target::Static | Target::Fn => {}
|
||||
Target::Method(..) if self.is_impl_item(hir_id) => {}
|
||||
|
@ -1509,7 +1525,7 @@ impl CheckAttrVisitor<'_> {
|
|||
being phased out; it will become a hard error in \
|
||||
a future release!",
|
||||
)
|
||||
.span_label(*span, format!("foreign {}", foreign_item_kind))
|
||||
.span_label(span, format!("foreign {}", foreign_item_kind))
|
||||
.note("symbol names in extern blocks are not mangled")
|
||||
.span_suggestion(
|
||||
attr.span,
|
||||
|
@ -1532,7 +1548,7 @@ impl CheckAttrVisitor<'_> {
|
|||
being phased out; it will become a hard error in \
|
||||
a future release!",
|
||||
)
|
||||
.span_label(*span, "not a free function, impl method or static")
|
||||
.span_label(span, "not a free function, impl method or static")
|
||||
.emit();
|
||||
});
|
||||
}
|
||||
|
@ -1543,7 +1559,7 @@ impl CheckAttrVisitor<'_> {
|
|||
fn check_repr(
|
||||
&self,
|
||||
attrs: &[Attribute],
|
||||
span: &Span,
|
||||
span: Span,
|
||||
target: Target,
|
||||
item: Option<ItemLike<'_>>,
|
||||
hir_id: HirId,
|
||||
|
@ -1677,7 +1693,7 @@ impl CheckAttrVisitor<'_> {
|
|||
"{}",
|
||||
&format!("attribute should be applied to {} {}", article, allowed_targets)
|
||||
)
|
||||
.span_label(*span, &format!("not {} {}", article, allowed_targets))
|
||||
.span_label(span, &format!("not {} {}", article, allowed_targets))
|
||||
.emit();
|
||||
}
|
||||
|
||||
|
@ -1740,7 +1756,7 @@ impl CheckAttrVisitor<'_> {
|
|||
&self,
|
||||
hir_id: HirId,
|
||||
attr: &Attribute,
|
||||
span: &Span,
|
||||
span: Span,
|
||||
target: Target,
|
||||
attrs: &[Attribute],
|
||||
) -> bool {
|
||||
|
@ -1773,7 +1789,7 @@ impl CheckAttrVisitor<'_> {
|
|||
self.tcx
|
||||
.sess
|
||||
.struct_span_err(attr.span, "attribute should be applied to a macro")
|
||||
.span_label(*span, "not a macro")
|
||||
.span_label(span, "not a macro")
|
||||
.emit();
|
||||
false
|
||||
}
|
||||
|
@ -1786,7 +1802,7 @@ impl CheckAttrVisitor<'_> {
|
|||
&self,
|
||||
hir_id: HirId,
|
||||
attr: &Attribute,
|
||||
span: &Span,
|
||||
span: Span,
|
||||
target: Target,
|
||||
) -> bool {
|
||||
match target {
|
||||
|
@ -1807,7 +1823,7 @@ impl CheckAttrVisitor<'_> {
|
|||
self.tcx
|
||||
.sess
|
||||
.struct_span_err(attr.span, "attribute should be applied to `const fn`")
|
||||
.span_label(*span, "not a `const fn`")
|
||||
.span_label(span, "not a `const fn`")
|
||||
.emit();
|
||||
false
|
||||
}
|
||||
|
@ -1818,7 +1834,7 @@ impl CheckAttrVisitor<'_> {
|
|||
fn check_default_method_body_is_const(
|
||||
&self,
|
||||
attr: &Attribute,
|
||||
span: &Span,
|
||||
span: Span,
|
||||
target: Target,
|
||||
) -> bool {
|
||||
match target {
|
||||
|
@ -1830,14 +1846,14 @@ impl CheckAttrVisitor<'_> {
|
|||
attr.span,
|
||||
"attribute should be applied to a trait method with body",
|
||||
)
|
||||
.span_label(*span, "not a trait method or missing a body")
|
||||
.span_label(span, "not a trait method or missing a body")
|
||||
.emit();
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn check_stability_promotable(&self, attr: &Attribute, _span: &Span, target: Target) -> bool {
|
||||
fn check_stability_promotable(&self, attr: &Attribute, _span: Span, target: Target) -> bool {
|
||||
match target {
|
||||
Target::Expression => {
|
||||
self.tcx
|
||||
|
@ -1850,7 +1866,7 @@ impl CheckAttrVisitor<'_> {
|
|||
}
|
||||
}
|
||||
|
||||
fn check_deprecated(&self, hir_id: HirId, attr: &Attribute, _span: &Span, target: Target) {
|
||||
fn check_deprecated(&self, hir_id: HirId, attr: &Attribute, _span: Span, target: Target) {
|
||||
match target {
|
||||
Target::Closure | Target::Expression | Target::Statement | Target::Arm => {
|
||||
self.tcx.struct_span_lint_hir(UNUSED_ATTRIBUTES, hir_id, attr.span, |lint| {
|
||||
|
@ -1912,29 +1928,29 @@ impl<'tcx> Visitor<'tcx> for CheckAttrVisitor<'tcx> {
|
|||
}
|
||||
|
||||
let target = Target::from_item(item);
|
||||
self.check_attributes(item.hir_id(), &item.span, target, Some(ItemLike::Item(item)));
|
||||
self.check_attributes(item.hir_id(), item.span, target, Some(ItemLike::Item(item)));
|
||||
intravisit::walk_item(self, item)
|
||||
}
|
||||
|
||||
fn visit_generic_param(&mut self, generic_param: &'tcx hir::GenericParam<'tcx>) {
|
||||
let target = Target::from_generic_param(generic_param);
|
||||
self.check_attributes(generic_param.hir_id, &generic_param.span, target, None);
|
||||
self.check_attributes(generic_param.hir_id, generic_param.span, target, None);
|
||||
intravisit::walk_generic_param(self, generic_param)
|
||||
}
|
||||
|
||||
fn visit_trait_item(&mut self, trait_item: &'tcx TraitItem<'tcx>) {
|
||||
let target = Target::from_trait_item(trait_item);
|
||||
self.check_attributes(trait_item.hir_id(), &trait_item.span, target, None);
|
||||
self.check_attributes(trait_item.hir_id(), trait_item.span, target, None);
|
||||
intravisit::walk_trait_item(self, trait_item)
|
||||
}
|
||||
|
||||
fn visit_field_def(&mut self, struct_field: &'tcx hir::FieldDef<'tcx>) {
|
||||
self.check_attributes(struct_field.hir_id, &struct_field.span, Target::Field, None);
|
||||
self.check_attributes(struct_field.hir_id, struct_field.span, Target::Field, None);
|
||||
intravisit::walk_field_def(self, struct_field);
|
||||
}
|
||||
|
||||
fn visit_arm(&mut self, arm: &'tcx hir::Arm<'tcx>) {
|
||||
self.check_attributes(arm.hir_id, &arm.span, Target::Arm, None);
|
||||
self.check_attributes(arm.hir_id, arm.span, Target::Arm, None);
|
||||
intravisit::walk_arm(self, arm);
|
||||
}
|
||||
|
||||
|
@ -1942,7 +1958,7 @@ impl<'tcx> Visitor<'tcx> for CheckAttrVisitor<'tcx> {
|
|||
let target = Target::from_foreign_item(f_item);
|
||||
self.check_attributes(
|
||||
f_item.hir_id(),
|
||||
&f_item.span,
|
||||
f_item.span,
|
||||
target,
|
||||
Some(ItemLike::ForeignItem(f_item)),
|
||||
);
|
||||
|
@ -1951,14 +1967,14 @@ impl<'tcx> Visitor<'tcx> for CheckAttrVisitor<'tcx> {
|
|||
|
||||
fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem<'tcx>) {
|
||||
let target = target_from_impl_item(self.tcx, impl_item);
|
||||
self.check_attributes(impl_item.hir_id(), &impl_item.span, target, None);
|
||||
self.check_attributes(impl_item.hir_id(), impl_item.span, target, None);
|
||||
intravisit::walk_impl_item(self, impl_item)
|
||||
}
|
||||
|
||||
fn visit_stmt(&mut self, stmt: &'tcx hir::Stmt<'tcx>) {
|
||||
// When checking statements ignore expressions, they will be checked later.
|
||||
if let hir::StmtKind::Local(ref l) = stmt.kind {
|
||||
self.check_attributes(l.hir_id, &stmt.span, Target::Statement, None);
|
||||
self.check_attributes(l.hir_id, stmt.span, Target::Statement, None);
|
||||
}
|
||||
intravisit::walk_stmt(self, stmt)
|
||||
}
|
||||
|
@ -1969,7 +1985,7 @@ impl<'tcx> Visitor<'tcx> for CheckAttrVisitor<'tcx> {
|
|||
_ => Target::Expression,
|
||||
};
|
||||
|
||||
self.check_attributes(expr.hir_id, &expr.span, target, None);
|
||||
self.check_attributes(expr.hir_id, expr.span, target, None);
|
||||
intravisit::walk_expr(self, expr)
|
||||
}
|
||||
|
||||
|
@ -1979,12 +1995,12 @@ impl<'tcx> Visitor<'tcx> for CheckAttrVisitor<'tcx> {
|
|||
generics: &'tcx hir::Generics<'tcx>,
|
||||
item_id: HirId,
|
||||
) {
|
||||
self.check_attributes(variant.id, &variant.span, Target::Variant, None);
|
||||
self.check_attributes(variant.id, variant.span, Target::Variant, None);
|
||||
intravisit::walk_variant(self, variant, generics, item_id)
|
||||
}
|
||||
|
||||
fn visit_param(&mut self, param: &'tcx hir::Param<'tcx>) {
|
||||
self.check_attributes(param.hir_id, ¶m.span, Target::Param, None);
|
||||
self.check_attributes(param.hir_id, param.span, Target::Param, None);
|
||||
|
||||
intravisit::walk_param(self, param);
|
||||
}
|
||||
|
@ -2076,7 +2092,7 @@ fn check_mod_attrs(tcx: TyCtxt<'_>, module_def_id: LocalDefId) {
|
|||
let check_attr_visitor = &mut CheckAttrVisitor { tcx };
|
||||
tcx.hir().visit_item_likes_in_module(module_def_id, &mut check_attr_visitor.as_deep_visitor());
|
||||
if module_def_id.is_top_level_module() {
|
||||
check_attr_visitor.check_attributes(CRATE_HIR_ID, &DUMMY_SP, Target::Mod, None);
|
||||
check_attr_visitor.check_attributes(CRATE_HIR_ID, DUMMY_SP, Target::Mod, None);
|
||||
check_invalid_crate_level_attr(tcx, tcx.hir().krate_attrs());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#![feature(nll)]
|
||||
#![feature(try_blocks)]
|
||||
#![recursion_limit = "256"]
|
||||
#![cfg_attr(not(bootstrap), allow(rustc::potential_query_instability))]
|
||||
|
||||
#[macro_use]
|
||||
extern crate rustc_middle;
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#![feature(try_blocks)]
|
||||
#![feature(associated_type_defaults)]
|
||||
#![recursion_limit = "256"]
|
||||
#![cfg_attr(not(bootstrap), allow(rustc::potential_query_instability))]
|
||||
|
||||
use rustc_ast::MacroDef;
|
||||
use rustc_attr as attr;
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#![feature(once_cell)]
|
||||
#![feature(rustc_attrs)]
|
||||
#![recursion_limit = "256"]
|
||||
#![cfg_attr(not(bootstrap), allow(rustc::potential_query_instability))]
|
||||
|
||||
#[macro_use]
|
||||
extern crate rustc_macros;
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#![feature(let_else)]
|
||||
#![feature(min_specialization)]
|
||||
#![feature(extern_types)]
|
||||
#![cfg_attr(not(bootstrap), allow(rustc::potential_query_instability))]
|
||||
|
||||
#[macro_use]
|
||||
extern crate tracing;
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#![feature(nll)]
|
||||
#![recursion_limit = "256"]
|
||||
#![allow(rustdoc::private_intra_doc_links)]
|
||||
#![cfg_attr(not(bootstrap), allow(rustc::potential_query_instability))]
|
||||
|
||||
#[macro_use]
|
||||
extern crate tracing;
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#![feature(if_let_guard)]
|
||||
#![feature(nll)]
|
||||
#![recursion_limit = "256"]
|
||||
#![cfg_attr(not(bootstrap), allow(rustc::potential_query_instability))]
|
||||
|
||||
mod dump_visitor;
|
||||
mod dumper;
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#![feature(min_specialization)]
|
||||
#![feature(once_cell)]
|
||||
#![recursion_limit = "256"]
|
||||
#![cfg_attr(not(bootstrap), allow(rustc::potential_query_instability))]
|
||||
|
||||
#[macro_use]
|
||||
extern crate rustc_macros;
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#![feature(negative_impls)]
|
||||
#![feature(nll)]
|
||||
#![feature(min_specialization)]
|
||||
#![cfg_attr(not(bootstrap), allow(rustc::potential_query_instability))]
|
||||
|
||||
#[macro_use]
|
||||
extern crate rustc_macros;
|
||||
|
|
|
@ -1171,6 +1171,7 @@ symbols! {
|
|||
rustc_layout_scalar_valid_range_end,
|
||||
rustc_layout_scalar_valid_range_start,
|
||||
rustc_legacy_const_generics,
|
||||
rustc_lint_query_instability,
|
||||
rustc_macro_transparency,
|
||||
rustc_main,
|
||||
rustc_mir,
|
||||
|
|
|
@ -91,6 +91,7 @@
|
|||
#![feature(never_type)]
|
||||
#![feature(nll)]
|
||||
#![recursion_limit = "256"]
|
||||
#![cfg_attr(not(bootstrap), allow(rustc::potential_query_instability))]
|
||||
|
||||
#[macro_use]
|
||||
extern crate rustc_middle;
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
// for a pre-z13 machine or using -mno-vx.
|
||||
|
||||
use crate::abi::call::{ArgAbi, FnAbi, Reg};
|
||||
use crate::abi::{self, HasDataLayout, TyAbiInterface, TyAndLayout};
|
||||
use crate::abi::{HasDataLayout, TyAbiInterface};
|
||||
|
||||
fn classify_ret<Ty>(ret: &mut ArgAbi<'_, Ty>) {
|
||||
if !ret.layout.is_aggregate() && ret.layout.size.bits() <= 64 {
|
||||
|
@ -12,24 +12,6 @@ fn classify_ret<Ty>(ret: &mut ArgAbi<'_, Ty>) {
|
|||
}
|
||||
}
|
||||
|
||||
fn is_single_fp_element<'a, Ty, C>(cx: &C, layout: TyAndLayout<'a, Ty>) -> bool
|
||||
where
|
||||
Ty: TyAbiInterface<'a, C>,
|
||||
C: HasDataLayout,
|
||||
{
|
||||
match layout.abi {
|
||||
abi::Abi::Scalar(scalar) => scalar.value.is_float(),
|
||||
abi::Abi::Aggregate { .. } => {
|
||||
if layout.fields.count() == 1 && layout.fields.offset(0).bytes() == 0 {
|
||||
is_single_fp_element(cx, layout.field(cx, 0))
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>)
|
||||
where
|
||||
Ty: TyAbiInterface<'a, C> + Copy,
|
||||
|
@ -40,7 +22,7 @@ where
|
|||
return;
|
||||
}
|
||||
|
||||
if is_single_fp_element(cx, arg.layout) {
|
||||
if arg.layout.is_single_fp_element(cx) {
|
||||
match arg.layout.size.bytes() {
|
||||
4 => arg.cast_to(Reg::f32()),
|
||||
8 => arg.cast_to(Reg::f64()),
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use crate::abi::call::{ArgAttribute, FnAbi, PassMode, Reg, RegKind};
|
||||
use crate::abi::{self, HasDataLayout, TyAbiInterface, TyAndLayout};
|
||||
use crate::abi::{HasDataLayout, TyAbiInterface};
|
||||
use crate::spec::HasTargetSpec;
|
||||
|
||||
#[derive(PartialEq)]
|
||||
|
@ -8,24 +8,6 @@ pub enum Flavor {
|
|||
Fastcall,
|
||||
}
|
||||
|
||||
fn is_single_fp_element<'a, Ty, C>(cx: &C, layout: TyAndLayout<'a, Ty>) -> bool
|
||||
where
|
||||
Ty: TyAbiInterface<'a, C> + Copy,
|
||||
C: HasDataLayout,
|
||||
{
|
||||
match layout.abi {
|
||||
abi::Abi::Scalar(scalar) => scalar.value.is_float(),
|
||||
abi::Abi::Aggregate { .. } => {
|
||||
if layout.fields.count() == 1 && layout.fields.offset(0).bytes() == 0 {
|
||||
is_single_fp_element(cx, layout.field(cx, 0))
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>, flavor: Flavor)
|
||||
where
|
||||
Ty: TyAbiInterface<'a, C> + Copy,
|
||||
|
@ -44,7 +26,7 @@ where
|
|||
if t.abi_return_struct_as_int {
|
||||
// According to Clang, everyone but MSVC returns single-element
|
||||
// float aggregates directly in a floating-point register.
|
||||
if !t.is_like_msvc && is_single_fp_element(cx, fn_abi.ret.layout) {
|
||||
if !t.is_like_msvc && fn_abi.ret.layout.is_single_fp_element(cx) {
|
||||
match fn_abi.ret.layout.size.bytes() {
|
||||
4 => fn_abi.ret.cast_to(Reg::f32()),
|
||||
8 => fn_abi.ret.cast_to(Reg::f64()),
|
||||
|
|
|
@ -1276,6 +1276,24 @@ impl<'a, Ty> TyAndLayout<'a, Ty> {
|
|||
{
|
||||
Ty::ty_and_layout_pointee_info_at(self, cx, offset)
|
||||
}
|
||||
|
||||
pub fn is_single_fp_element<C>(self, cx: &C) -> bool
|
||||
where
|
||||
Ty: TyAbiInterface<'a, C>,
|
||||
C: HasDataLayout,
|
||||
{
|
||||
match self.abi {
|
||||
Abi::Scalar(scalar) => scalar.value.is_float(),
|
||||
Abi::Aggregate { .. } => {
|
||||
if self.fields.count() == 1 && self.fields.offset(0).bytes() == 0 {
|
||||
self.field(cx, 0).is_single_fp_element(cx)
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, Ty> TyAndLayout<'a, Ty> {
|
||||
|
|
|
@ -7,6 +7,7 @@ pub fn target() -> Target {
|
|||
base.pre_link_args.entry(LinkerFlavor::Gcc).or_default().push("-m64".to_string());
|
||||
// don't use probe-stack=inline-asm until rust#83139 and rust#84667 are resolved
|
||||
base.stack_probes = StackProbeType::Call;
|
||||
base.static_position_independent_executables = true;
|
||||
base.supported_sanitizers = SanitizerSet::ADDRESS
|
||||
| SanitizerSet::CFI
|
||||
| SanitizerSet::LEAK
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#![feature(crate_visibility_modifier)]
|
||||
#![feature(control_flow_enum)]
|
||||
#![recursion_limit = "512"] // For rustdoc
|
||||
#![cfg_attr(not(bootstrap), allow(rustc::potential_query_instability))]
|
||||
|
||||
#[macro_use]
|
||||
extern crate rustc_macros;
|
||||
|
|
|
@ -1555,7 +1555,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
|||
// `erase_late_bound_regions`.
|
||||
let ty_erased = self.tcx.erase_late_bound_regions(ty);
|
||||
let ty_erased = self.tcx.erase_regions(ty_erased);
|
||||
let eq = ty::TyS::same_type(ty_erased, target_ty_erased);
|
||||
let eq = ty_erased == target_ty_erased;
|
||||
debug!(
|
||||
"maybe_note_obligation_cause_for_async_await: ty_erased={:?} \
|
||||
target_ty_erased={:?} eq={:?}",
|
||||
|
|
|
@ -322,7 +322,7 @@ fn is_type_structurally_recursive_inner<'tcx>(
|
|||
// struct Foo { Option<Option<Foo>> }
|
||||
|
||||
for &seen_adt in iter {
|
||||
if ty::TyS::same_type(ty, seen_adt) {
|
||||
if ty == seen_adt {
|
||||
debug!("ContainsRecursive: {:?} contains {:?}", seen_adt, ty);
|
||||
return Representability::ContainsRecursive;
|
||||
}
|
||||
|
|
|
@ -1,24 +1,33 @@
|
|||
//! Orphan checker: every impl either implements a trait defined in this
|
||||
//! crate or pertains to a type defined in this crate.
|
||||
|
||||
use rustc_data_structures::fx::FxHashSet;
|
||||
use rustc_errors::struct_span_err;
|
||||
use rustc_errors::ErrorReported;
|
||||
use rustc_hir as hir;
|
||||
use rustc_index::bit_set::GrowableBitSet;
|
||||
use rustc_infer::infer::TyCtxtInferExt;
|
||||
use rustc_middle::ty::{self, TyCtxt};
|
||||
use rustc_span::def_id::LocalDefId;
|
||||
use rustc_middle::ty::subst::{GenericArg, InternalSubsts};
|
||||
use rustc_middle::ty::{self, ImplPolarity, Ty, TyCtxt, TypeFoldable, TypeVisitor};
|
||||
use rustc_session::lint;
|
||||
use rustc_span::def_id::{DefId, LocalDefId};
|
||||
use rustc_span::Span;
|
||||
use rustc_trait_selection::traits;
|
||||
use std::ops::ControlFlow;
|
||||
|
||||
pub(super) fn orphan_check_crate(tcx: TyCtxt<'_>, (): ()) -> &[LocalDefId] {
|
||||
let mut errors = Vec::new();
|
||||
for (_trait, impls_of_trait) in tcx.all_local_trait_impls(()) {
|
||||
for (&trait_def_id, impls_of_trait) in tcx.all_local_trait_impls(()) {
|
||||
for &impl_of_trait in impls_of_trait {
|
||||
match orphan_check_impl(tcx, impl_of_trait) {
|
||||
Ok(()) => {}
|
||||
Err(ErrorReported) => errors.push(impl_of_trait),
|
||||
}
|
||||
}
|
||||
|
||||
if tcx.trait_is_auto(trait_def_id) {
|
||||
lint_auto_trait_impls(tcx, trait_def_id, impls_of_trait);
|
||||
}
|
||||
}
|
||||
tcx.arena.alloc_slice(&errors)
|
||||
}
|
||||
|
@ -265,3 +274,201 @@ fn emit_orphan_check_error<'tcx>(
|
|||
|
||||
Err(ErrorReported)
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
struct AreUniqueParamsVisitor {
|
||||
seen: GrowableBitSet<u32>,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
enum NotUniqueParam<'tcx> {
|
||||
DuplicateParam(GenericArg<'tcx>),
|
||||
NotParam(GenericArg<'tcx>),
|
||||
}
|
||||
|
||||
impl<'tcx> TypeVisitor<'tcx> for AreUniqueParamsVisitor {
|
||||
type BreakTy = NotUniqueParam<'tcx>;
|
||||
fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
|
||||
match t.kind() {
|
||||
ty::Param(p) => {
|
||||
if self.seen.insert(p.index) {
|
||||
ControlFlow::CONTINUE
|
||||
} else {
|
||||
ControlFlow::Break(NotUniqueParam::DuplicateParam(t.into()))
|
||||
}
|
||||
}
|
||||
_ => ControlFlow::Break(NotUniqueParam::NotParam(t.into())),
|
||||
}
|
||||
}
|
||||
fn visit_region(&mut self, r: ty::Region<'tcx>) -> ControlFlow<Self::BreakTy> {
|
||||
match r {
|
||||
ty::ReEarlyBound(p) => {
|
||||
if self.seen.insert(p.index) {
|
||||
ControlFlow::CONTINUE
|
||||
} else {
|
||||
ControlFlow::Break(NotUniqueParam::DuplicateParam(r.into()))
|
||||
}
|
||||
}
|
||||
_ => ControlFlow::Break(NotUniqueParam::NotParam(r.into())),
|
||||
}
|
||||
}
|
||||
fn visit_const(&mut self, c: &'tcx ty::Const<'tcx>) -> ControlFlow<Self::BreakTy> {
|
||||
match c.val {
|
||||
ty::ConstKind::Param(p) => {
|
||||
if self.seen.insert(p.index) {
|
||||
ControlFlow::CONTINUE
|
||||
} else {
|
||||
ControlFlow::Break(NotUniqueParam::DuplicateParam(c.into()))
|
||||
}
|
||||
}
|
||||
_ => ControlFlow::Break(NotUniqueParam::NotParam(c.into())),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Lint impls of auto traits if they are likely to have
|
||||
/// unsound or surprising effects on auto impls.
|
||||
fn lint_auto_trait_impls(tcx: TyCtxt<'_>, trait_def_id: DefId, impls: &[LocalDefId]) {
|
||||
let mut non_covering_impls = Vec::new();
|
||||
for &impl_def_id in impls {
|
||||
let trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap();
|
||||
if trait_ref.references_error() {
|
||||
return;
|
||||
}
|
||||
|
||||
if tcx.impl_polarity(impl_def_id) != ImplPolarity::Positive {
|
||||
return;
|
||||
}
|
||||
|
||||
assert_eq!(trait_ref.substs.len(), 1);
|
||||
let self_ty = trait_ref.self_ty();
|
||||
let (self_type_did, substs) = match self_ty.kind() {
|
||||
ty::Adt(def, substs) => (def.did, substs),
|
||||
_ => {
|
||||
// FIXME: should also lint for stuff like `&i32` but
|
||||
// considering that auto traits are unstable, that
|
||||
// isn't too important for now as this only affects
|
||||
// crates using `nightly`, and std.
|
||||
continue;
|
||||
}
|
||||
};
|
||||
|
||||
// Impls which completely cover a given root type are fine as they
|
||||
// disable auto impls entirely. So only lint if the substs
|
||||
// are not a permutation of the identity substs.
|
||||
match substs.visit_with(&mut AreUniqueParamsVisitor::default()) {
|
||||
ControlFlow::Continue(()) => {} // ok
|
||||
ControlFlow::Break(arg) => {
|
||||
// Ideally:
|
||||
//
|
||||
// - compute the requirements for the auto impl candidate
|
||||
// - check whether these are implied by the non covering impls
|
||||
// - if not, emit the lint
|
||||
//
|
||||
// What we do here is a bit simpler:
|
||||
//
|
||||
// - badly check if an auto impl candidate definitely does not apply
|
||||
// for the given simplified type
|
||||
// - if so, do not lint
|
||||
if fast_reject_auto_impl(tcx, trait_def_id, self_ty) {
|
||||
// ok
|
||||
} else {
|
||||
non_covering_impls.push((impl_def_id, self_type_did, arg));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for &(impl_def_id, self_type_did, arg) in &non_covering_impls {
|
||||
tcx.struct_span_lint_hir(
|
||||
lint::builtin::SUSPICIOUS_AUTO_TRAIT_IMPLS,
|
||||
tcx.hir().local_def_id_to_hir_id(impl_def_id),
|
||||
tcx.def_span(impl_def_id),
|
||||
|err| {
|
||||
let mut err = err.build(&format!(
|
||||
"cross-crate traits with a default impl, like `{}`, \
|
||||
should not be specialized",
|
||||
tcx.def_path_str(trait_def_id),
|
||||
));
|
||||
let item_span = tcx.def_span(self_type_did);
|
||||
let self_descr = tcx.def_kind(self_type_did).descr(self_type_did);
|
||||
err.span_note(
|
||||
item_span,
|
||||
&format!(
|
||||
"try using the same sequence of generic parameters as the {} definition",
|
||||
self_descr,
|
||||
),
|
||||
);
|
||||
match arg {
|
||||
NotUniqueParam::DuplicateParam(arg) => {
|
||||
err.note(&format!("`{}` is mentioned multiple times", arg));
|
||||
}
|
||||
NotUniqueParam::NotParam(arg) => {
|
||||
err.note(&format!("`{}` is not a generic parameter", arg));
|
||||
}
|
||||
}
|
||||
err.emit();
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
fn fast_reject_auto_impl<'tcx>(tcx: TyCtxt<'tcx>, trait_def_id: DefId, self_ty: Ty<'tcx>) -> bool {
|
||||
struct DisableAutoTraitVisitor<'tcx> {
|
||||
tcx: TyCtxt<'tcx>,
|
||||
trait_def_id: DefId,
|
||||
self_ty_root: Ty<'tcx>,
|
||||
seen: FxHashSet<DefId>,
|
||||
}
|
||||
|
||||
impl<'tcx> TypeVisitor<'tcx> for DisableAutoTraitVisitor<'tcx> {
|
||||
type BreakTy = ();
|
||||
fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
|
||||
let tcx = self.tcx;
|
||||
if t != self.self_ty_root {
|
||||
for impl_def_id in tcx.non_blanket_impls_for_ty(self.trait_def_id, t) {
|
||||
match tcx.impl_polarity(impl_def_id) {
|
||||
ImplPolarity::Negative => return ControlFlow::BREAK,
|
||||
ImplPolarity::Reservation => {}
|
||||
// FIXME(@lcnr): That's probably not good enough, idk
|
||||
//
|
||||
// We might just want to take the rustdoc code and somehow avoid
|
||||
// explicit impls for `Self`.
|
||||
ImplPolarity::Positive => return ControlFlow::CONTINUE,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
match t.kind() {
|
||||
ty::Adt(def, substs) => {
|
||||
// @lcnr: This is the only place where cycles can happen. We avoid this
|
||||
// by only visiting each `DefId` once.
|
||||
//
|
||||
// This will be is incorrect in subtle cases, but I don't care :)
|
||||
if self.seen.insert(def.did) {
|
||||
for ty in def.all_fields().map(|field| field.ty(tcx, substs)) {
|
||||
ty.visit_with(self)?;
|
||||
}
|
||||
}
|
||||
|
||||
ControlFlow::CONTINUE
|
||||
}
|
||||
_ => t.super_visit_with(self),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let self_ty_root = match self_ty.kind() {
|
||||
ty::Adt(def, _) => tcx.mk_adt(def, InternalSubsts::identity_for_item(tcx, def.did)),
|
||||
_ => unimplemented!("unexpected self ty {:?}", self_ty),
|
||||
};
|
||||
|
||||
self_ty_root
|
||||
.visit_with(&mut DisableAutoTraitVisitor {
|
||||
tcx,
|
||||
self_ty_root,
|
||||
trait_def_id,
|
||||
seen: FxHashSet::default(),
|
||||
})
|
||||
.is_break()
|
||||
}
|
||||
|
|
|
@ -69,6 +69,7 @@ This API is completely unstable and subject to change.
|
|||
#![feature(control_flow_enum)]
|
||||
#![feature(hash_drain_filter)]
|
||||
#![recursion_limit = "256"]
|
||||
#![cfg_attr(not(bootstrap), allow(rustc::potential_query_instability))]
|
||||
|
||||
#[macro_use]
|
||||
extern crate tracing;
|
||||
|
|
|
@ -43,6 +43,22 @@ impl RawWaker {
|
|||
pub const fn new(data: *const (), vtable: &'static RawWakerVTable) -> RawWaker {
|
||||
RawWaker { data, vtable }
|
||||
}
|
||||
|
||||
/// Get the `data` pointer used to create this `RawWaker`.
|
||||
#[inline]
|
||||
#[must_use]
|
||||
#[unstable(feature = "waker_getters", issue = "87021")]
|
||||
pub fn data(&self) -> *const () {
|
||||
self.data
|
||||
}
|
||||
|
||||
/// Get the `vtable` pointer used to create this `RawWaker`.
|
||||
#[inline]
|
||||
#[must_use]
|
||||
#[unstable(feature = "waker_getters", issue = "87021")]
|
||||
pub fn vtable(&self) -> &'static RawWakerVTable {
|
||||
self.vtable
|
||||
}
|
||||
}
|
||||
|
||||
/// A virtual function pointer table (vtable) that specifies the behavior
|
||||
|
@ -260,6 +276,14 @@ impl Waker {
|
|||
pub unsafe fn from_raw(waker: RawWaker) -> Waker {
|
||||
Waker { waker }
|
||||
}
|
||||
|
||||
/// Get a reference to the underlying [`RawWaker`].
|
||||
#[inline]
|
||||
#[must_use]
|
||||
#[unstable(feature = "waker_getters", issue = "87021")]
|
||||
pub fn as_raw(&self) -> &RawWaker {
|
||||
&self.waker
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "futures_api", since = "1.36.0")]
|
||||
|
|
|
@ -90,6 +90,7 @@
|
|||
#![feature(unzip_option)]
|
||||
#![feature(const_array_from_ref)]
|
||||
#![feature(const_slice_from_ref)]
|
||||
#![feature(waker_getters)]
|
||||
#![deny(unsafe_op_in_unsafe_fn)]
|
||||
|
||||
extern crate test;
|
||||
|
@ -131,3 +132,4 @@ mod task;
|
|||
mod time;
|
||||
mod tuple;
|
||||
mod unicode;
|
||||
mod waker;
|
||||
|
|
22
library/core/tests/waker.rs
Normal file
22
library/core/tests/waker.rs
Normal file
|
@ -0,0 +1,22 @@
|
|||
use std::ptr;
|
||||
use std::task::{RawWaker, RawWakerVTable, Waker};
|
||||
|
||||
#[test]
|
||||
fn test_waker_getters() {
|
||||
let raw_waker = RawWaker::new(42usize as *mut (), &WAKER_VTABLE);
|
||||
assert_eq!(raw_waker.data() as usize, 42);
|
||||
assert!(ptr::eq(raw_waker.vtable(), &WAKER_VTABLE));
|
||||
|
||||
let waker = unsafe { Waker::from_raw(raw_waker) };
|
||||
let waker2 = waker.clone();
|
||||
let raw_waker2 = waker2.as_raw();
|
||||
assert_eq!(raw_waker2.data() as usize, 43);
|
||||
assert!(ptr::eq(raw_waker2.vtable(), &WAKER_VTABLE));
|
||||
}
|
||||
|
||||
static WAKER_VTABLE: RawWakerVTable = RawWakerVTable::new(
|
||||
|data| RawWaker::new((data as usize + 1) as *mut (), &WAKER_VTABLE),
|
||||
|_| {},
|
||||
|_| {},
|
||||
|_| {},
|
||||
);
|
|
@ -16,7 +16,7 @@ panic_unwind = { path = "../panic_unwind", optional = true }
|
|||
panic_abort = { path = "../panic_abort" }
|
||||
core = { path = "../core" }
|
||||
libc = { version = "0.2.116", default-features = false, features = ['rustc-dep-of-std'] }
|
||||
compiler_builtins = { version = "0.1.66" }
|
||||
compiler_builtins = { version = "0.1.67" }
|
||||
profiler_builtins = { path = "../profiler_builtins", optional = true }
|
||||
unwind = { path = "../unwind" }
|
||||
hashbrown = { version = "0.12", default-features = false, features = ['rustc-dep-of-std'] }
|
||||
|
|
|
@ -371,6 +371,7 @@ impl<K, V, S> HashMap<K, V, S> {
|
|||
/// assert_eq!(vec, ["a", "b", "c"]);
|
||||
/// ```
|
||||
#[inline]
|
||||
#[cfg_attr(not(bootstrap), rustc_lint_query_instability)]
|
||||
#[stable(feature = "map_into_keys_values", since = "1.54.0")]
|
||||
pub fn into_keys(self) -> IntoKeys<K, V> {
|
||||
IntoKeys { inner: self.into_iter() }
|
||||
|
@ -448,6 +449,7 @@ impl<K, V, S> HashMap<K, V, S> {
|
|||
/// assert_eq!(vec, [1, 2, 3]);
|
||||
/// ```
|
||||
#[inline]
|
||||
#[cfg_attr(not(bootstrap), rustc_lint_query_instability)]
|
||||
#[stable(feature = "map_into_keys_values", since = "1.54.0")]
|
||||
pub fn into_values(self) -> IntoValues<K, V> {
|
||||
IntoValues { inner: self.into_iter() }
|
||||
|
@ -471,6 +473,7 @@ impl<K, V, S> HashMap<K, V, S> {
|
|||
/// println!("key: {} val: {}", key, val);
|
||||
/// }
|
||||
/// ```
|
||||
#[cfg_attr(not(bootstrap), rustc_lint_query_instability)]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub fn iter(&self) -> Iter<'_, K, V> {
|
||||
Iter { base: self.base.iter() }
|
||||
|
@ -500,6 +503,7 @@ impl<K, V, S> HashMap<K, V, S> {
|
|||
/// println!("key: {} val: {}", key, val);
|
||||
/// }
|
||||
/// ```
|
||||
#[cfg_attr(not(bootstrap), rustc_lint_query_instability)]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub fn iter_mut(&mut self) -> IterMut<'_, K, V> {
|
||||
IterMut { base: self.base.iter_mut() }
|
||||
|
@ -560,6 +564,7 @@ impl<K, V, S> HashMap<K, V, S> {
|
|||
/// assert!(a.is_empty());
|
||||
/// ```
|
||||
#[inline]
|
||||
#[cfg_attr(not(bootstrap), rustc_lint_query_instability)]
|
||||
#[stable(feature = "drain", since = "1.6.0")]
|
||||
pub fn drain(&mut self) -> Drain<'_, K, V> {
|
||||
Drain { base: self.base.drain() }
|
||||
|
@ -601,6 +606,7 @@ impl<K, V, S> HashMap<K, V, S> {
|
|||
/// assert_eq!(odds, vec![1, 3, 5, 7]);
|
||||
/// ```
|
||||
#[inline]
|
||||
#[cfg_attr(not(bootstrap), rustc_lint_query_instability)]
|
||||
#[unstable(feature = "hash_drain_filter", issue = "59618")]
|
||||
pub fn drain_filter<F>(&mut self, pred: F) -> DrainFilter<'_, K, V, F>
|
||||
where
|
||||
|
@ -624,6 +630,7 @@ impl<K, V, S> HashMap<K, V, S> {
|
|||
/// assert_eq!(map.len(), 4);
|
||||
/// ```
|
||||
#[inline]
|
||||
#[cfg_attr(not(bootstrap), rustc_lint_query_instability)]
|
||||
#[stable(feature = "retain_hash_collection", since = "1.18.0")]
|
||||
pub fn retain<F>(&mut self, f: F)
|
||||
where
|
||||
|
@ -1990,6 +1997,7 @@ impl<'a, K, V, S> IntoIterator for &'a HashMap<K, V, S> {
|
|||
type IntoIter = Iter<'a, K, V>;
|
||||
|
||||
#[inline]
|
||||
#[cfg_attr(not(bootstrap), rustc_lint_query_instability)]
|
||||
fn into_iter(self) -> Iter<'a, K, V> {
|
||||
self.iter()
|
||||
}
|
||||
|
@ -2001,6 +2009,7 @@ impl<'a, K, V, S> IntoIterator for &'a mut HashMap<K, V, S> {
|
|||
type IntoIter = IterMut<'a, K, V>;
|
||||
|
||||
#[inline]
|
||||
#[cfg_attr(not(bootstrap), rustc_lint_query_instability)]
|
||||
fn into_iter(self) -> IterMut<'a, K, V> {
|
||||
self.iter_mut()
|
||||
}
|
||||
|
@ -2030,6 +2039,7 @@ impl<K, V, S> IntoIterator for HashMap<K, V, S> {
|
|||
/// let vec: Vec<(&str, i32)> = map.into_iter().collect();
|
||||
/// ```
|
||||
#[inline]
|
||||
#[cfg_attr(not(bootstrap), rustc_lint_query_instability)]
|
||||
fn into_iter(self) -> IntoIter<K, V> {
|
||||
IntoIter { base: self.base.into_iter() }
|
||||
}
|
||||
|
|
|
@ -185,6 +185,7 @@ impl<T, S> HashSet<T, S> {
|
|||
/// }
|
||||
/// ```
|
||||
#[inline]
|
||||
#[cfg_attr(not(bootstrap), rustc_lint_query_instability)]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub fn iter(&self) -> Iter<'_, T> {
|
||||
Iter { base: self.base.iter() }
|
||||
|
@ -244,6 +245,7 @@ impl<T, S> HashSet<T, S> {
|
|||
/// assert!(set.is_empty());
|
||||
/// ```
|
||||
#[inline]
|
||||
#[cfg_attr(not(bootstrap), rustc_lint_query_instability)]
|
||||
#[stable(feature = "drain", since = "1.6.0")]
|
||||
pub fn drain(&mut self) -> Drain<'_, T> {
|
||||
Drain { base: self.base.drain() }
|
||||
|
@ -282,6 +284,7 @@ impl<T, S> HashSet<T, S> {
|
|||
/// assert_eq!(odds, vec![1, 3, 5, 7]);
|
||||
/// ```
|
||||
#[inline]
|
||||
#[cfg_attr(not(bootstrap), rustc_lint_query_instability)]
|
||||
#[unstable(feature = "hash_drain_filter", issue = "59618")]
|
||||
pub fn drain_filter<F>(&mut self, pred: F) -> DrainFilter<'_, T, F>
|
||||
where
|
||||
|
@ -304,6 +307,7 @@ impl<T, S> HashSet<T, S> {
|
|||
/// set.retain(|&k| k % 2 == 0);
|
||||
/// assert_eq!(set.len(), 3);
|
||||
/// ```
|
||||
#[cfg_attr(not(bootstrap), rustc_lint_query_instability)]
|
||||
#[stable(feature = "retain_hash_collection", since = "1.18.0")]
|
||||
pub fn retain<F>(&mut self, f: F)
|
||||
where
|
||||
|
@ -528,6 +532,7 @@ where
|
|||
/// assert_eq!(diff, [4].iter().collect());
|
||||
/// ```
|
||||
#[inline]
|
||||
#[cfg_attr(not(bootstrap), rustc_lint_query_instability)]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub fn difference<'a>(&'a self, other: &'a HashSet<T, S>) -> Difference<'a, T, S> {
|
||||
Difference { iter: self.iter(), other }
|
||||
|
@ -555,6 +560,7 @@ where
|
|||
/// assert_eq!(diff1, [1, 4].iter().collect());
|
||||
/// ```
|
||||
#[inline]
|
||||
#[cfg_attr(not(bootstrap), rustc_lint_query_instability)]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub fn symmetric_difference<'a>(
|
||||
&'a self,
|
||||
|
@ -582,6 +588,7 @@ where
|
|||
/// assert_eq!(intersection, [2, 3].iter().collect());
|
||||
/// ```
|
||||
#[inline]
|
||||
#[cfg_attr(not(bootstrap), rustc_lint_query_instability)]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub fn intersection<'a>(&'a self, other: &'a HashSet<T, S>) -> Intersection<'a, T, S> {
|
||||
if self.len() <= other.len() {
|
||||
|
@ -610,6 +617,7 @@ where
|
|||
/// assert_eq!(union, [1, 2, 3, 4].iter().collect());
|
||||
/// ```
|
||||
#[inline]
|
||||
#[cfg_attr(not(bootstrap), rustc_lint_query_instability)]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub fn union<'a>(&'a self, other: &'a HashSet<T, S>) -> Union<'a, T, S> {
|
||||
if self.len() >= other.len() {
|
||||
|
@ -1410,6 +1418,7 @@ impl<'a, T, S> IntoIterator for &'a HashSet<T, S> {
|
|||
type IntoIter = Iter<'a, T>;
|
||||
|
||||
#[inline]
|
||||
#[cfg_attr(not(bootstrap), rustc_lint_query_instability)]
|
||||
fn into_iter(self) -> Iter<'a, T> {
|
||||
self.iter()
|
||||
}
|
||||
|
@ -1441,6 +1450,7 @@ impl<T, S> IntoIterator for HashSet<T, S> {
|
|||
/// }
|
||||
/// ```
|
||||
#[inline]
|
||||
#[cfg_attr(not(bootstrap), rustc_lint_query_instability)]
|
||||
fn into_iter(self) -> IntoIter<T> {
|
||||
IntoIter { base: self.base.into_iter() }
|
||||
}
|
||||
|
|
|
@ -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
|
||||
# $ ./x.py test --target x86_64-unknown-linux-[musl,gnu] 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
|
||||
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
|
||||
|
|
20
src/test/run-make/static-pie/check_clang_version.sh
Executable file
20
src/test/run-make/static-pie/check_clang_version.sh
Executable file
|
@ -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
|
20
src/test/run-make/static-pie/check_gcc_version.sh
Executable file
20
src/test/run-make/static-pie/check_gcc_version.sh
Executable file
|
@ -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
|
24
src/test/ui-fulldeps/internal-lints/query_stability.rs
Normal file
24
src/test/ui-fulldeps/internal-lints/query_stability.rs
Normal file
|
@ -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`
|
||||
}
|
39
src/test/ui-fulldeps/internal-lints/query_stability.stderr
Normal file
39
src/test/ui-fulldeps/internal-lints/query_stability.stderr
Normal file
|
@ -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
|
||||
|
|
@ -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() {}
|
|
@ -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
|
||||
|
34
src/test/ui/auto-traits/suspicious-impls-lint.rs
Normal file
34
src/test/ui/auto-traits/suspicious-impls-lint.rs
Normal file
|
@ -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() {}
|
52
src/test/ui/auto-traits/suspicious-impls-lint.stderr
Normal file
52
src/test/ui/auto-traits/suspicious-impls-lint.stderr
Normal file
|
@ -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
|
||||
|
|
@ -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).
|
||||
|
|
|
@ -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> { }
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^-----------------
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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,
|
||||
};
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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"
|
||||
},
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
})
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#![warn(clippy::non_send_fields_in_send_ty)]
|
||||
#![allow(suspicious_auto_trait_impls)]
|
||||
#![feature(extern_types)]
|
||||
|
||||
use std::cell::UnsafeCell;
|
||||
|
|
|
@ -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,
|
||||
| ^^^^^^^^^
|
||||
|
|
Loading…
Add table
Reference in a new issue