Skip to content

Move object lifetime default computation #97839

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion compiler/rustc_middle/src/middle/resolve_lifetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,13 @@ impl<T: PartialEq> Set1<T> {
}
}

pub type ObjectLifetimeDefault = Set1<Region>;
#[derive(Copy, Clone, Debug, HashStable, Encodable, Decodable)]
pub enum ObjectLifetimeDefault {
Empty,
Static,
Ambiguous,
Param(DefId),
}

/// Maps the id of each lifetime reference to the lifetime decl
/// that it corresponds to.
Expand Down
12 changes: 10 additions & 2 deletions compiler/rustc_middle/src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1591,8 +1591,16 @@ rustc_queries! {
/// for each parameter if a trait object were to be passed for that parameter.
/// For example, for `struct Foo<'a, T, U>`, this would be `['static, 'static]`.
/// For `struct Foo<'a, T: 'a, U>`, this would instead be `['a, 'static]`.
query object_lifetime_defaults(_: LocalDefId) -> Option<&'tcx [ObjectLifetimeDefault]> {
desc { "looking up lifetime defaults for a region on an item" }
query object_lifetime_defaults(def_id: LocalDefId) -> Option<&'tcx [ObjectLifetimeDefault]> {
desc { "computing object lifetime defaults for `{:?}`'s generic parameters", def_id }
}
/// Fetch the lifetimes for all the trait objects in an item-like. This query uses
/// `object_lifetime_defaults` which returns a map `GenericParam -> ObjectLifetimeDefault`,
/// and build a map from each `dyn Trait` type to the implicit lifetime `'a`, so that
/// `dyn Trait` should be understood as `dyn Trait + 'a`
query object_lifetime_map(def_id: LocalDefId) -> FxHashMap<ItemLocalId, Region> {
storage(ArenaCacheSelector<'tcx>)
desc { "looking up lifetime for trait-object types inside `{:?}`", def_id }
}
query late_bound_vars_map(_: LocalDefId)
-> Option<&'tcx FxHashMap<ItemLocalId, Vec<ty::BoundVariableKind>>> {
Expand Down
Loading