Skip to content
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

add span to desugar and conv_resolved_lifetime #972

Merged
merged 2 commits into from
Jan 24, 2025
Merged
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
6 changes: 5 additions & 1 deletion crates/flux-desugar/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,11 @@ pub fn desugar<'genv>(
nodes.insert(def_id, fhir::Node::AnonConst);
}
node => {
bug!("unsupported node: {node:?}");
if let Some(ident) = node.ident() {
span_bug!(ident.span, "unsupported node: {node:?}");
} else {
bug!("unsupported node: {node:?}");
}
}
}
Ok(nodes)
Expand Down
32 changes: 20 additions & 12 deletions crates/flux-fhir-analysis/src/conv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -927,7 +927,7 @@ impl<'genv, 'tcx: 'genv, P: ConvPhase<'genv, 'tcx>> ConvCtxt<P> {
}
}
fhir::GenericBound::Outlives(lft) => {
let re = self.conv_lifetime(env, *lft);
let re = self.conv_lifetime(env, *lft, bounded_ty_span);
clauses.push(rty::Clause::new(
List::empty(),
rty::ClauseKind::TypeOutlives(rty::OutlivesPredicate(
Expand Down Expand Up @@ -1068,12 +1068,12 @@ impl<'genv, 'tcx: 'genv, P: ConvPhase<'genv, 'tcx>> ConvCtxt<P> {
}
}
fhir::TyKind::StrgRef(lft, loc, ty) => {
let re = self.conv_lifetime(env, *lft);
let re = self.conv_lifetime(env, *lft, ty.span);
let ty = self.conv_ty(env, ty)?;
Ok(rty::Ty::strg_ref(re, env.lookup(loc).to_path(), ty))
}
fhir::TyKind::Ref(lft, fhir::MutTy { ty, mutbl }) => {
let region = self.conv_lifetime(env, *lft);
let region = self.conv_lifetime(env, *lft, ty.span);
Ok(rty::Ty::mk_ref(region, self.conv_ty(env, ty)?, *mutbl))
}
fhir::TyKind::BareFn(bare_fn) => {
Expand Down Expand Up @@ -1112,10 +1112,10 @@ impl<'genv, 'tcx: 'genv, P: ConvPhase<'genv, 'tcx>> ConvCtxt<P> {
rty::Expr::unit(),
))
}
fhir::TyKind::OpaqueDef(opaque_ty) => self.conv_opaque_def(env, opaque_ty),
fhir::TyKind::OpaqueDef(opaque_ty) => self.conv_opaque_def(env, opaque_ty, ty.span),
fhir::TyKind::TraitObject(trait_bounds, lft, syn) => {
if matches!(syn, rustc_ast::TraitObjectSyntax::Dyn) {
self.conv_trait_object(env, trait_bounds, *lft)
self.conv_trait_object(env, trait_bounds, *lft, ty.span)
} else {
span_bug!(ty.span, "dyn* traits not supported yet")
}
Expand All @@ -1129,6 +1129,7 @@ impl<'genv, 'tcx: 'genv, P: ConvPhase<'genv, 'tcx>> ConvCtxt<P> {
&mut self,
env: &mut Env,
opaque_ty: &fhir::OpaqueTy,
span: Span,
) -> QueryResult<rty::Ty> {
let def_id = opaque_ty.def_id;

Expand All @@ -1142,7 +1143,7 @@ impl<'genv, 'tcx: 'genv, P: ConvPhase<'genv, 'tcx>> ConvCtxt<P> {
let args = rty::GenericArg::for_item(self.genv(), def_id.resolved_id(), |param, _| {
if let Some(i) = (param.index as usize).checked_sub(offset) {
let (lifetime, _) = lifetimes[i];
rty::GenericArg::Lifetime(self.conv_resolved_lifetime(env, lifetime))
rty::GenericArg::Lifetime(self.conv_resolved_lifetime(env, lifetime, span))
} else {
rty::GenericArg::from_param_def(param)
}
Expand All @@ -1168,6 +1169,7 @@ impl<'genv, 'tcx: 'genv, P: ConvPhase<'genv, 'tcx>> ConvCtxt<P> {
env: &mut Env,
trait_bounds: &[fhir::PolyTraitRef],
lifetime: fhir::Lifetime,
span: Span,
) -> QueryResult<rty::Ty> {
// We convert all the trait bounds into existential predicates. Some combinations won't yield
// valid rust types (e.g., only one regular (non-auto) trait is allowed). We don't detect those
Expand Down Expand Up @@ -1252,7 +1254,7 @@ impl<'genv, 'tcx: 'genv, P: ConvPhase<'genv, 'tcx>> ConvCtxt<P> {
List::from_vec(v)
};

let region = self.conv_lifetime(env, lifetime);
let region = self.conv_lifetime(env, lifetime, span);
Ok(rty::Ty::dynamic(existential_predicates, region))
}

Expand Down Expand Up @@ -1424,15 +1426,15 @@ impl<'genv, 'tcx: 'genv, P: ConvPhase<'genv, 'tcx>> ConvCtxt<P> {
Ok(bound)
}

fn conv_lifetime(&mut self, env: &Env, lft: fhir::Lifetime) -> rty::Region {
fn conv_lifetime(&mut self, env: &Env, lft: fhir::Lifetime, span: Span) -> rty::Region {
let res = match lft {
fhir::Lifetime::Hole(_) => return rty::Region::ReVar(self.next_region_vid()),
fhir::Lifetime::Resolved(res) => res,
};
self.conv_resolved_lifetime(env, res)
self.conv_resolved_lifetime(env, res, span)
}

fn conv_resolved_lifetime(&mut self, env: &Env, res: ResolvedArg) -> rty::Region {
fn conv_resolved_lifetime(&mut self, env: &Env, res: ResolvedArg, span: Span) -> rty::Region {
let tcx = self.tcx();
let lifetime_name = |def_id| tcx.item_name(def_id);
match res {
Expand All @@ -1443,7 +1445,9 @@ impl<'genv, 'tcx: 'genv, P: ConvPhase<'genv, 'tcx>> ConvCtxt<P> {
rty::ReEarlyParam(rty::EarlyParamRegion { index, name })
}
ResolvedArg::LateBound(_, index, def_id) => {
let depth = env.depth().checked_sub(1).unwrap();
let Some(depth) = env.depth().checked_sub(1) else {
span_bug!(span, "late-bound variable at depth 0")
};
let name = lifetime_name(def_id.to_def_id());
let kind = rty::BoundRegionKind::BrNamed(def_id.to_def_id(), name);
let var = BoundVar::from_u32(index);
Expand Down Expand Up @@ -1628,7 +1632,11 @@ impl<'genv, 'tcx: 'genv, P: ConvPhase<'genv, 'tcx>> ConvCtxt<P> {
let param = generics.param_at(idx + len, self.genv())?;
match arg {
fhir::GenericArg::Lifetime(lft) => {
into.push(rty::GenericArg::Lifetime(self.conv_lifetime(env, *lft)));
into.push(rty::GenericArg::Lifetime(self.conv_lifetime(
env,
*lft,
segment.ident.span,
)));
}
fhir::GenericArg::Type(ty) => {
into.push(self.conv_ty_to_generic_arg(env, &param, ty)?);
Expand Down
Loading