Skip to content

Commit a37adbb

Browse files
committed
Perform named lifetime resolution on AST.
1 parent 75d7906 commit a37adbb

File tree

3 files changed

+911
-282
lines changed

3 files changed

+911
-282
lines changed

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,39 @@ struct LoweringContext<'a, 'hir: 'a> {
164164
allow_gen_future: Option<Lrc<[Symbol]>>,
165165
}
166166

167+
/// Resolution for a lifetime appearing in a type.
168+
#[derive(Copy, Clone, Debug)]
169+
pub enum LifetimeRes {
170+
/// Successfully linked the lifetime to a generic parameter.
171+
Param {
172+
/// Id of the generic parameter that introduced it.
173+
param: NodeId,
174+
/// Id of the introducing place. That can be:
175+
/// - an item's id, for the item's generic parameters;
176+
/// - a TraitRef's ref_id, identifying the `for<...>` binder;
177+
/// - a BareFn type's id;
178+
/// - a Path's id when this path has parenthesized generic args.
179+
binder: NodeId,
180+
/// Whether this parameter was introduced as in-band.
181+
in_band: bool,
182+
/// Whether this parameter was created for anonymous lifetime.
183+
fresh: Option<usize>,
184+
},
185+
/// This will should follow implicit lifetime resolution later.
186+
Anonymous {
187+
/// Id of the introducing place. See `Param`.
188+
binder: NodeId,
189+
/// Whether this lifetime was spelled or elided.
190+
elided: bool,
191+
},
192+
/// Explicit `'static` lifetime.
193+
Static,
194+
/// Resolution failure.
195+
Error,
196+
/// HACK: This is used to recover the NodeId of an elided lifetime.
197+
ElidedAnchor { start: NodeId, end: NodeId },
198+
}
199+
167200
pub trait ResolverAstLowering {
168201
fn def_key(&mut self, id: DefId) -> DefKey;
169202

@@ -182,6 +215,9 @@ pub trait ResolverAstLowering {
182215
/// Obtains resolution for a label with the given `NodeId`.
183216
fn get_label_res(&mut self, id: NodeId) -> Option<NodeId>;
184217

218+
/// Obtains resolution for a lifetime with the given `NodeId`.
219+
fn get_lifetime_res(&mut self, id: NodeId) -> Option<LifetimeRes>;
220+
185221
/// We must keep the set of definitions up to date as we add nodes that weren't in the AST.
186222
/// This should only return `None` during testing.
187223
fn definitions(&mut self) -> &mut Definitions;

0 commit comments

Comments
 (0)