Skip to content

Commit a4a3363

Browse files
committed
add lifetimes to trait objects
1 parent 69529c1 commit a4a3363

File tree

8 files changed

+140
-65
lines changed

8 files changed

+140
-65
lines changed

chalk-integration/src/lowering.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1307,7 +1307,10 @@ impl LowerTy for Ty {
13071307
}
13081308
})
13091309
}
1310-
Ty::Dyn { ref bounds } => Ok(chalk_ir::TyData::Dyn(chalk_ir::DynTy {
1310+
Ty::Dyn {
1311+
ref bounds,
1312+
ref lifetime,
1313+
} => Ok(chalk_ir::TyData::Dyn(chalk_ir::DynTy {
13111314
bounds: env.in_binders(
13121315
// FIXME: Figure out a proper name for this type parameter
13131316
Some(chalk_ir::WithKind::new(
@@ -1330,6 +1333,7 @@ impl LowerTy for Ty {
13301333
))
13311334
},
13321335
)?,
1336+
lifetime: lifetime.lower(env)?,
13331337
})
13341338
.intern(interner)),
13351339

chalk-ir/src/debug.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,8 @@ impl Debug for DebruijnIndex {
206206

207207
impl<I: Interner> Debug for DynTy<I> {
208208
fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> {
209-
let DynTy { bounds } = self;
210-
write!(fmt, "dyn {:?}", bounds)
209+
let DynTy { bounds, lifetime } = self;
210+
write!(fmt, "dyn {:?} + {:?}", bounds, lifetime)
211211
}
212212
}
213213

chalk-ir/src/lib.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -680,32 +680,33 @@ impl DebruijnIndex {
680680
}
681681
}
682682

683-
/// A "DynTy" could be either a `dyn Trait` or an (opaque) `impl
684-
/// Trait`. Both of them are conceptually very related to a
685-
/// "existential type" of the form `exists<T> { T: Trait }`. The
686-
/// `DynTy` type represents those bounds.
683+
/// A "DynTy" represents a trait object (`dyn Trait`). Trait objects
684+
/// are conceptually very related to an "existential type" of the form
685+
/// `exists<T> { T: Trait }` (another exaple of such type is `impl Trait`).
686+
/// `DynTy` represents the bounds on that type.
687687
///
688688
/// The "binder" here represents the unknown self type. So, a type like
689-
/// `impl for<'a> Fn(&'a u32)` would be represented with two-levels of
689+
/// `dyn for<'a> Fn(&'a u32)` would be represented with two-levels of
690690
/// binder, as "depicted" here:
691691
///
692692
/// ```notrust
693693
/// exists<type> {
694694
/// vec![
695695
/// // A QuantifiedWhereClause:
696-
/// forall<region> { ^1: Fn(&^0 u32) }
696+
/// forall<region> { ^1.0: Fn(&^0.0 u32) }
697697
/// ]
698698
/// }
699699
/// ```
700700
///
701701
/// The outer `exists<type>` binder indicates that there exists
702702
/// some type that meets the criteria within, but that type is not
703-
/// known. It is referenced within the type using `^1`, indicating
703+
/// known. It is referenced within the type using `^1.0`, indicating
704704
/// a bound type with debruijn index 1 (i.e., skipping through one
705705
/// level of binder).
706706
#[derive(Clone, PartialEq, Eq, Hash, Fold, Visit, HasInterner, Zip)]
707707
pub struct DynTy<I: Interner> {
708708
pub bounds: Binders<QuantifiedWhereClauses<I>>,
709+
pub lifetime: Lifetime<I>,
709710
}
710711

711712
#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]

chalk-parse/src/ast.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ pub enum Ty {
199199
},
200200
Dyn {
201201
bounds: Vec<QuantifiedInlineBound>,
202+
lifetime: Lifetime,
202203
},
203204
Apply {
204205
name: Identifier,

chalk-parse/src/parser.lalrpop

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,9 @@ TyWithoutId: Ty = {
231231
lifetime_names: vec![],
232232
ty: Box::new(t)
233233
},
234-
"dyn" <b:Plus<QuantifiedInlineBound>> => Ty::Dyn {
234+
"dyn" <b:Plus<QuantifiedInlineBound>> "+" <l:Lifetime> => Ty::Dyn {
235235
bounds: b,
236+
lifetime: l,
236237
},
237238
<n:Id> "<" <a:Comma<GenericArg>> ">" => Ty::Apply { name: n, args: a },
238239
<p:ProjectionTy> => Ty::Projection { proj: p },

0 commit comments

Comments
 (0)