diff options
| author | bors <bors@rust-lang.org> | 2024-12-10 13:16:09 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-12-10 13:16:09 +0000 |
| commit | 33c245b9e98bc91e18ea1c5033824f4c6f92766f (patch) | |
| tree | df8f972b248d000977d31545af32eed5fa259ebf /compiler/rustc_trait_selection/src | |
| parent | 499605271718bceaa629f0b954502c0040e4456b (diff) | |
| parent | c42c248009747366e646a3ad1ce6e8f815ea7db2 (diff) | |
| download | rust-33c245b9e98bc91e18ea1c5033824f4c6f92766f.tar.gz rust-33c245b9e98bc91e18ea1c5033824f4c6f92766f.zip | |
Auto merge of #134125 - fmease:rollup-u38o3ob, r=fmease
Rollup of 11 pull requests Successful merges: - #133478 (jsondocck: Parse, don't validate commands.) - #133967 ([AIX] Pass -bnoipath when adding rust upstream dynamic crates) - #133970 ([AIX] Replace sa_sigaction with sa_union.__su_sigaction for AIX) - #133980 ([AIX] Remove option "-n" from AIX "ln" command) - #134008 (Make `Copy` unsafe to implement for ADTs with `unsafe` fields) - #134017 (Don't use `AsyncFnOnce::CallOnceFuture` bounds for signature deduction) - #134023 (handle cygwin environment in `install::sanitize_sh`) - #134041 (Use SourceMap to load debugger visualizer files) - #134065 (Move `write_graphviz_results`) - #134106 (Add compiler-maintainers who requested to be on review rotation) - #134123 (bootstrap: Forward cargo JSON output to stdout, not stderr) Failed merges: - #134120 (Remove Felix from ping groups and review rotation) r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_trait_selection/src')
| -rw-r--r-- | compiler/rustc_trait_selection/src/traits/misc.rs | 10 | ||||
| -rw-r--r-- | compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs | 2 |
2 files changed, 10 insertions, 2 deletions
diff --git a/compiler/rustc_trait_selection/src/traits/misc.rs b/compiler/rustc_trait_selection/src/traits/misc.rs index 3b17fa6b032..d216ae72913 100644 --- a/compiler/rustc_trait_selection/src/traits/misc.rs +++ b/compiler/rustc_trait_selection/src/traits/misc.rs @@ -18,6 +18,7 @@ pub enum CopyImplementationError<'tcx> { InfringingFields(Vec<(&'tcx ty::FieldDef, Ty<'tcx>, InfringingFieldsReason<'tcx>)>), NotAnAdt, HasDestructor, + HasUnsafeFields, } pub enum ConstParamTyImplementationError<'tcx> { @@ -39,11 +40,16 @@ pub enum InfringingFieldsReason<'tcx> { /// /// If it's not an ADT, int ty, `bool`, float ty, `char`, raw pointer, `!`, /// a reference or an array returns `Err(NotAnAdt)`. +/// +/// If the impl is `Safe`, `self_type` must not have unsafe fields. When used to +/// generate suggestions in lints, `Safe` should be supplied so as to not +/// suggest implementing `Copy` for types with unsafe fields. pub fn type_allowed_to_implement_copy<'tcx>( tcx: TyCtxt<'tcx>, param_env: ty::ParamEnv<'tcx>, self_type: Ty<'tcx>, parent_cause: ObligationCause<'tcx>, + impl_safety: hir::Safety, ) -> Result<(), CopyImplementationError<'tcx>> { let (adt, args) = match self_type.kind() { // These types used to have a builtin impl. @@ -78,6 +84,10 @@ pub fn type_allowed_to_implement_copy<'tcx>( return Err(CopyImplementationError::HasDestructor); } + if impl_safety == hir::Safety::Safe && self_type.has_unsafe_fields() { + return Err(CopyImplementationError::HasUnsafeFields); + } + Ok(()) } diff --git a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs index 3e2c8467d32..5e27fd43789 100644 --- a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs +++ b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs @@ -795,8 +795,6 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { | ty::Never | ty::Tuple(_) | ty::CoroutineWitness(..) => { - use rustc_type_ir::inherent::*; - // Only consider auto impls of unsafe traits when there are // no unsafe fields. if self.tcx().trait_is_unsafe(def_id) && self_ty.has_unsafe_fields() { |
