Skip to content

Commit 4acbf3f

Browse files
committed
remove impl Field for fields of packed structs
1 parent 19c2c84 commit 4acbf3f

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::*;
@@ -856,9 +858,23 @@ where
856858
}
857859

858860
match goal.predicate.self_ty().kind() {
859-
ty::Field(..) => ecx
860-
.probe_builtin_trait_candidate(BuiltinImplSource::Misc)
861-
.enter(|ecx| ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)),
861+
ty::Field(container, field_path)
862+
if field_path
863+
.walk(ecx.cx(), container, |base, _, _, _| {
864+
if let ty::Adt(def, _) = base.kind()
865+
&& def.is_packed()
866+
{
867+
ControlFlow::Break(())
868+
} else {
869+
ControlFlow::Continue(())
870+
}
871+
})
872+
.is_none() =>
873+
{
874+
ecx.probe_builtin_trait_candidate(BuiltinImplSource::Misc).enter(|ecx| {
875+
ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
876+
})
877+
}
862878
_ => Err(NoSolution),
863879
}
864880
}

compiler/rustc_type_ir/src/inherent.rs

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

629629
fn destructor(self, interner: I) -> Option<AdtDestructorKind>;
630+
631+
fn is_packed(self) -> bool;
630632
}
631633

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

0 commit comments

Comments
 (0)