1
Fork 0

Rollup merge of #98610 - lcnr:emit_inference_failure_err-ice, r=estebank

fix `emit_inference_failure_err` ICE

fixes #98598

this fix doesn't make me too happy, but 🤷
This commit is contained in:
Matthias Krüger 2022-07-01 06:05:52 +02:00 committed by GitHub
commit 0d5636ce88
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 119 additions and 7 deletions

View file

@ -334,7 +334,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
let mut local_visitor = FindInferSourceVisitor::new(&self, typeck_results, arg);
if let Some(body_id) = body_id {
let expr = self.tcx.hir().expect_expr(body_id.hir_id);
debug!(?expr);
local_visitor.visit_expr(expr);
}
@ -550,6 +549,7 @@ impl<'tcx> InferSourceKind<'tcx> {
}
}
#[derive(Debug)]
struct InsertableGenericArgs<'tcx> {
insert_span: Span,
substs: SubstsRef<'tcx>,
@ -735,10 +735,20 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> {
return self.path_inferred_subst_iter(expr.hir_id, substs, path);
}
}
hir::ExprKind::Struct(path, _, _) => {
// FIXME(#98711): Ideally we would also deal with type relative
// paths here, even if that is quite rare.
//
// See the `need_type_info/expr-struct-type-relative-gat.rs` test
// for an example where that would be needed.
//
// However, the `type_dependent_def_id` for `Self::Output` in an
// impl is currently the `DefId` of `Output` in the trait definition
// which makes this somewhat difficult and prevents us from just
// using `self.path_inferred_subst_iter` here.
hir::ExprKind::Struct(&hir::QPath::Resolved(_self_ty, path), _, _) => {
if let Some(ty) = self.opt_node_type(expr.hir_id) {
if let ty::Adt(_, substs) = ty.kind() {
return self.path_inferred_subst_iter(expr.hir_id, substs, path);
return Box::new(self.resolved_path_inferred_subst_iter(path, substs));
}
}
}
@ -945,6 +955,7 @@ impl<'a, 'tcx> Visitor<'tcx> for FindInferSourceVisitor<'a, 'tcx> {
intravisit::walk_body(self, body);
}
#[instrument(level = "debug", skip(self))]
fn visit_expr(&mut self, expr: &'tcx Expr<'tcx>) {
let tcx = self.infcx.tcx;
match expr.kind {
@ -959,9 +970,9 @@ impl<'a, 'tcx> Visitor<'tcx> for FindInferSourceVisitor<'a, 'tcx> {
_ => intravisit::walk_expr(self, expr),
}
for InsertableGenericArgs { insert_span, substs, generics_def_id, def_id } in
self.expr_inferred_subst_iter(expr)
{
for args in self.expr_inferred_subst_iter(expr) {
debug!(?args);
let InsertableGenericArgs { insert_span, substs, generics_def_id, def_id } = args;
let generics = tcx.generics_of(generics_def_id);
if let Some(argument_index) =
generics.own_substs(substs).iter().position(|&arg| self.generic_arg_is_target(arg))