Skip to content

Commit 7f093eb

Browse files
authored
Merge pull request #1582 from N1ark/issue-1579-lift-assoc-implied
Lookup parent associated types when normalizing
2 parents 6112387 + 2964b21 commit 7f093eb

3 files changed

Lines changed: 93 additions & 0 deletions

File tree

‎charon/src/transform/normalize/expand_associated_types.rs‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,6 +1020,24 @@ impl UpdateItemBody<'_> {
10201020
}
10211021

10221022
fn lookup_path_on_trait_ref(&self, path: &AssocTypePath, tref: &TraitRef) -> Option<Ty> {
1023+
if let Some(ty) = self.lookup_path_in_env(path, tref) {
1024+
return Some(ty);
1025+
}
1026+
// The environment doesn't know this path. If the trait kept its associated types, it may
1027+
// have added a new associated type for that path. This is necessary for traits in a
1028+
// cycle: the environment only records facts up to the point where we detected the cycle,
1029+
// whereas paths through the cycle can be arbitrarily long.
1030+
let tmods = self
1031+
.item_modifications
1032+
.get(&GenericsSource::item(tref.trait_id()))?;
1033+
let (_, type_id) = tmods
1034+
.required_extra_assoc_types_with_ids()
1035+
.find(|(p, _)| *p == path)?;
1036+
Some(TyKind::TraitType(tref.clone(), type_id, GenericArgs::empty()).into_ty())
1037+
}
1038+
1039+
/// Look up the path using the facts available for this specific trait ref.
1040+
fn lookup_path_in_env(&self, path: &AssocTypePath, tref: &TraitRef) -> Option<Ty> {
10231041
assert!(path.tref.base.is_self_clause());
10241042
match &tref.kind {
10251043
TraitRefKind::TraitImpl(impl_ref) => {
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Final LLBC before serialization:
2+
3+
// Full name: core::marker::MetaSized
4+
#[fundamental]
5+
#[lang_item(MetaSized)]
6+
pub trait MetaSized<Self>
7+
8+
// Full name: core::marker::Sized
9+
#[fundamental]
10+
#[lang_item(Sized)]
11+
pub trait Sized<Self>
12+
{
13+
proof ImpliedClause0: (Self: MetaSized)
14+
non-dyn-compatible
15+
}
16+
17+
struct () {}
18+
19+
// Full name: test_crate::Lang
20+
pub trait Lang<Self, Self_B>
21+
{
22+
proof ImpliedClause0: (Self: MetaSized)
23+
proof ImpliedClause1: (Self_B: Sized)
24+
vtable: test_crate::Lang::{vtable}<Self_B>
25+
}
26+
27+
// Full name: test_crate::Values
28+
pub trait Values<Self>
29+
{
30+
proof ImpliedClause0: (Self: MetaSized)
31+
proof ImpliedClause1: (Self: Lang<Self::Self_Clause1_B>)
32+
proof ImpliedClause2: (Self::Self_Clause1_B: Typed<Self>)
33+
type Self_Clause1_B
34+
vtable: test_crate::Values::{vtable}<Self::Self_Clause1_B>
35+
}
36+
37+
// Full name: test_crate::Typed
38+
pub trait Typed<Self, Self_V>
39+
{
40+
proof ImpliedClause0: (Self: MetaSized)
41+
proof ImpliedClause1: (Self_V: Sized)
42+
proof ImpliedClause2: (Self_V: Values)
43+
vtable: test_crate::Typed::{vtable}<Self_V>
44+
}
45+
46+
// Full name: test_crate::f
47+
pub fn f<'_0, T, Clause1_V>(_1: &'_0 TraitClause1::ImpliedClause2::Self_Clause1_B)
48+
where
49+
TraitClause0: (T: Sized),
50+
TraitClause1: (T: Typed<Clause1_V>),
51+
Outlives0: (TraitClause1::ImpliedClause2::Self_Clause1_B: '_0),
52+
Outlives1: (T: '_0),
53+
Outlives2: (Clause1_V: '_0),
54+
{
55+
let _0: (); // return
56+
let _1: &'1 TraitClause1::ImpliedClause2::Self_Clause1_B; // arg #1
57+
58+
storage_live(_0)
59+
_0 = ()
60+
_0 = ()
61+
storage_dead(_1)
62+
return
63+
}
64+
65+
66+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//@ charon-args=--lift-associated-types=*
2+
pub trait Lang {
3+
type B;
4+
}
5+
pub trait Values: Lang<B: Typed<V = Self>> {}
6+
pub trait Typed {
7+
type V: Values;
8+
}
9+
pub fn f<T: Typed>(_: &<T::V as Lang>::B) {}

0 commit comments

Comments
 (0)