Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
aliemjay committed Sep 8, 2023
1 parent 1e746d7 commit edcb870
Show file tree
Hide file tree
Showing 105 changed files with 771 additions and 781 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ pub struct Lifetime {

impl fmt::Debug for Lifetime {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "lifetime({}: {})", self.id, self)
write!(f, "lifetime({}: {:?})", self.id, self.ident)
}
}

Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1327,7 +1327,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
} else {
self.next_node_id()
};
let span = self.tcx.sess.source_map().start_point(t.span).shrink_to_hi();
let span = self.tcx.sess.source_map().start_point(t.span);
Lifetime { ident: Ident::new(kw::UnderscoreLifetime, span), id }
});
let lifetime = self.lower_lifetime(&region);
Expand Down Expand Up @@ -1564,7 +1564,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
// in fn return position, like the `fn test<'a>() -> impl Debug + 'a`
// example, we only need to duplicate lifetimes that appear in the
// bounds, since those are the only ones that are captured by the opaque.
lifetime_collector::lifetimes_in_bounds(&self.resolver, bounds)
lifetime_collector::lifetimes_in_bounds(self.tcx, &self.resolver, bounds)
}
}
hir::OpaqueTyOrigin::AsyncFn(..) => {
Expand Down
19 changes: 11 additions & 8 deletions compiler/rustc_ast_lowering/src/lifetime_collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,20 @@ use rustc_ast::visit::{self, BoundKind, LifetimeCtxt, Visitor};
use rustc_ast::{GenericBounds, Lifetime, NodeId, PathSegment, PolyTraitRef, Ty, TyKind};
use rustc_hir::def::{DefKind, LifetimeRes, Res};
use rustc_middle::span_bug;
use rustc_middle::ty::ResolverAstLowering;
use rustc_middle::ty::{ResolverAstLowering, TyCtxt};
use rustc_span::symbol::{kw, Ident};
use rustc_span::Span;

struct LifetimeCollectVisitor<'ast> {
struct LifetimeCollectVisitor<'ast, 'tcx> {
tcx: TyCtxt<'tcx>,
resolver: &'ast ResolverAstLowering,
current_binders: Vec<NodeId>,
collected_lifetimes: Vec<Lifetime>,
}

impl<'ast> LifetimeCollectVisitor<'ast> {
fn new(resolver: &'ast ResolverAstLowering) -> Self {
Self { resolver, current_binders: Vec::new(), collected_lifetimes: Vec::new() }
impl<'ast, 'tcx> LifetimeCollectVisitor<'ast, 'tcx> {
fn new(tcx: TyCtxt<'tcx>, resolver: &'ast ResolverAstLowering) -> Self {
Self { tcx, resolver, current_binders: Vec::new(), collected_lifetimes: Vec::new() }
}

fn record_lifetime_use(&mut self, lifetime: Lifetime) {
Expand Down Expand Up @@ -58,7 +59,7 @@ impl<'ast> LifetimeCollectVisitor<'ast> {
}
}

impl<'ast> Visitor<'ast> for LifetimeCollectVisitor<'ast> {
impl<'ast> Visitor<'ast> for LifetimeCollectVisitor<'ast, '_> {
fn visit_lifetime(&mut self, lifetime: &'ast Lifetime, _: LifetimeCtxt) {
self.record_lifetime_use(*lifetime);
}
Expand Down Expand Up @@ -97,7 +98,8 @@ impl<'ast> Visitor<'ast> for LifetimeCollectVisitor<'ast> {
self.current_binders.pop();
}
TyKind::Ref(None, _) => {
self.record_elided_anchor(t.id, t.span);
let span = self.tcx.sess.source_map().start_point(t.span);
self.record_elided_anchor(t.id, span);
visit::walk_ty(self, t);
}
_ => {
Expand All @@ -108,10 +110,11 @@ impl<'ast> Visitor<'ast> for LifetimeCollectVisitor<'ast> {
}

pub fn lifetimes_in_bounds(
tcx: TyCtxt<'_>,
resolver: &ResolverAstLowering,
bounds: &GenericBounds,
) -> Vec<Lifetime> {
let mut visitor = LifetimeCollectVisitor::new(resolver);
let mut visitor = LifetimeCollectVisitor::new(tcx, resolver);
for bound in bounds {
visitor.visit_param_bound(bound, BoundKind::Bound);
}
Expand Down
6 changes: 4 additions & 2 deletions compiler/rustc_hir/src/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,10 @@ impl Lifetime {
}
} else if self.res == LifetimeName::ImplicitObjectLifetimeDefault {
(LifetimeSuggestionPosition::ObjectDefault, self.ident.span)
} else if self.ident.span.is_empty() {
(LifetimeSuggestionPosition::Ampersand, self.ident.span)
} else if self.ident.name == kw::UnderscoreLifetime
&& self.ident.span.hi() - self.ident.span.lo() == BytePos(1)
{
(LifetimeSuggestionPosition::Ampersand, self.ident.span.shrink_to_hi())
} else {
(LifetimeSuggestionPosition::Normal, self.ident.span)
}
Expand Down
Loading

0 comments on commit edcb870

Please sign in to comment.