Skip to content

Commit 001fa29

Browse files
committed
remove impl Field for fields of packed structs
1 parent a851bf1 commit 001fa29

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

compiler/rustc_middle/src/ty/adt.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,10 @@ impl<'tcx> rustc_type_ir::inherent::AdtDef<TyCtxt<'tcx>> for AdtDef<'tcx> {
247247
hir::Constness::NotConst => AdtDestructorKind::NotConst,
248248
})
249249
}
250+
251+
fn is_packed(self) -> bool {
252+
self.repr().packed()
253+
}
250254
}
251255

252256
#[derive(Copy, Clone, Debug, Eq, PartialEq, HashStable, TyEncodable, TyDecodable)]

compiler/rustc_next_trait_solver/src/solve/trait_goals.rs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//! Dealing with trait goals, i.e. `T: Trait<'a, U>`.
22
3+
use std::ops::ControlFlow;
4+
35
use rustc_type_ir::data_structures::IndexSet;
46
use rustc_type_ir::fast_reject::DeepRejectCtxt;
57
use rustc_type_ir::inherent::*;
@@ -852,9 +854,23 @@ where
852854
}
853855

854856
match goal.predicate.self_ty().kind() {
855-
ty::Field(..) => ecx
856-
.probe_builtin_trait_candidate(BuiltinImplSource::Misc)
857-
.enter(|ecx| ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)),
857+
ty::Field(container, field_path)
858+
if field_path
859+
.walk(ecx.cx(), container, |base, _, _, _| {
860+
if let ty::Adt(def, _) = base.kind()
861+
&& def.is_packed()
862+
{
863+
ControlFlow::Break(())
864+
} else {
865+
ControlFlow::Continue(())
866+
}
867+
})
868+
.is_none() =>
869+
{
870+
ecx.probe_builtin_trait_candidate(BuiltinImplSource::Misc).enter(|ecx| {
871+
ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
872+
})
873+
}
858874
_ => Err(NoSolution),
859875
}
860876
}

compiler/rustc_type_ir/src/inherent.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,8 @@ pub trait AdtDef<I: Interner>: Copy + Debug + Hash + Eq {
633633
fn is_fundamental(self) -> bool;
634634

635635
fn destructor(self, interner: I) -> Option<AdtDestructorKind>;
636+
637+
fn is_packed(self) -> bool;
636638
}
637639

638640
pub trait FieldPath<I: Interner>: Copy + Debug + Hash + Eq {

0 commit comments

Comments
 (0)