1
Fork 0

Add hir::Node::PreciseCapturingNonLifetimeArg

This commit is contained in:
Michael Goulet 2024-04-04 14:46:26 -04:00
parent 42ba57c013
commit 02d7317af2
14 changed files with 110 additions and 38 deletions

View file

@ -385,4 +385,21 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
fn visit_pattern_type_pattern(&mut self, p: &'hir hir::Pat<'hir>) {
self.visit_pat(p)
}
fn visit_precise_capturing_arg(
&mut self,
arg: &'hir PreciseCapturingArg<'hir>,
) -> Self::Result {
match arg {
PreciseCapturingArg::Lifetime(_) => {
// This is represented as a `Node::Lifetime`, intravisit will get to it below.
}
PreciseCapturingArg::Param(param) => self.insert(
param.ident.span,
param.hir_id,
Node::PreciseCapturingNonLifetimeArg(param),
),
}
intravisit::walk_precise_capturing_arg(self, arg);
}
}

View file

@ -1790,11 +1790,15 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
PreciseCapturingArg::Lifetime(lt) => {
hir::PreciseCapturingArg::Lifetime(self.lower_lifetime(lt))
}
PreciseCapturingArg::Arg(_, node_id) => {
PreciseCapturingArg::Arg(ident, node_id) => {
let res = self.resolver.get_partial_res(*node_id).map_or(Res::Err, |partial_res| {
partial_res.full_res().expect("no partial res expected for precise capture arg")
});
hir::PreciseCapturingArg::Param(self.lower_res(res), self.lower_node_id(*node_id))
hir::PreciseCapturingArg::Param(hir::PreciseCapturingNonLifetimeArg {
hir_id: self.lower_node_id(*node_id),
ident: self.lower_ident(*ident),
res: self.lower_res(res),
})
}
}))
}

View file

@ -2565,7 +2565,14 @@ pub struct OpaqueTy<'hir> {
pub enum PreciseCapturingArg<'hir> {
Lifetime(&'hir Lifetime),
/// Non-lifetime argument (type or const)
Param(Res, HirId),
Param(PreciseCapturingNonLifetimeArg),
}
#[derive(Debug, Clone, Copy, HashStable_Generic)]
pub struct PreciseCapturingNonLifetimeArg {
pub hir_id: HirId,
pub ident: Ident,
pub res: Res,
}
/// From whence the opaque type came.
@ -3544,6 +3551,7 @@ pub enum Node<'hir> {
WhereBoundPredicate(&'hir WhereBoundPredicate<'hir>),
// FIXME: Merge into `Node::Infer`.
ArrayLenInfer(&'hir InferArg),
PreciseCapturingNonLifetimeArg(&'hir PreciseCapturingNonLifetimeArg),
// Created by query feeding
Synthetic,
// Span by reference to minimize `Node`'s size
@ -3580,6 +3588,7 @@ impl<'hir> Node<'hir> {
Node::TypeBinding(b) => Some(b.ident),
Node::PatField(f) => Some(f.ident),
Node::ExprField(f) => Some(f.ident),
Node::PreciseCapturingNonLifetimeArg(a) => Some(a.ident),
Node::Param(..)
| Node::AnonConst(..)
| Node::ConstBlock(..)

View file

@ -1151,7 +1151,7 @@ pub fn walk_precise_capturing_arg<'v, V: Visitor<'v>>(
) -> V::Result {
match *arg {
PreciseCapturingArg::Lifetime(lt) => visitor.visit_lifetime(lt),
PreciseCapturingArg::Param(_, hir_id) => visitor.visit_id(hir_id),
PreciseCapturingArg::Param(param) => visitor.visit_id(param.hir_id),
}
}

View file

@ -487,7 +487,9 @@ fn check_opaque_precise_captures<'tcx>(tcx: TyCtxt<'tcx>, opaque_def_id: LocalDe
for arg in precise_capturing_args {
match *arg {
hir::PreciseCapturingArg::Lifetime(&hir::Lifetime { hir_id, .. })
| hir::PreciseCapturingArg::Param(_, hir_id) => match tcx.named_bound_var(hir_id) {
| hir::PreciseCapturingArg::Param(hir::PreciseCapturingNonLifetimeArg {
hir_id, ..
}) => match tcx.named_bound_var(hir_id) {
Some(ResolvedArg::EarlyBound(def_id)) => {
expected_captures.insert(def_id);
}

View file

@ -577,10 +577,10 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
});
}
},
hir::PreciseCapturingArg::Param(res, hir_id) => match res {
hir::PreciseCapturingArg::Param(param) => match param.res {
Res::Def(DefKind::TyParam | DefKind::ConstParam, def_id)
| Res::SelfTyParam { trait_: def_id } => {
self.resolve_type_ref(def_id.expect_local(), hir_id);
self.resolve_type_ref(def_id.expect_local(), param.hir_id);
}
Res::Err => {}
_ => {

View file

@ -99,6 +99,7 @@ impl<'a> State<'a> {
Node::PatField(a) => self.print_patfield(a),
Node::Arm(a) => self.print_arm(a),
Node::Infer(_) => self.word("_"),
Node::PreciseCapturingNonLifetimeArg(param) => self.print_ident(param.ident),
Node::Block(a) => {
// Containing cbox, will be closed by print-block at `}`.
self.cbox(INDENT_UNIT);

View file

@ -909,6 +909,7 @@ impl<'hir> Map<'hir> {
Node::Crate(item) => item.spans.inner_span,
Node::WhereBoundPredicate(pred) => pred.span,
Node::ArrayLenInfer(inf) => inf.span,
Node::PreciseCapturingNonLifetimeArg(param) => param.ident.span,
Node::Synthetic => unreachable!(),
Node::Err(span) => *span,
}
@ -1176,6 +1177,7 @@ fn hir_id_to_string(map: Map<'_>, id: HirId) -> String {
Node::ArrayLenInfer(_) => node_str("array len infer"),
Node::Synthetic => unreachable!(),
Node::Err(_) => node_str("error"),
Node::PreciseCapturingNonLifetimeArg(_param) => node_str("parameter"),
}
}