Skip to content

Commit a946b8d

Browse files
committed
save-analysis: Process bounds in impl trait only in argument position
1 parent 30e39e8 commit a946b8d

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

src/librustc_save_analysis/dump_visitor.rs

+18-1
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,12 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
385385
}
386386

387387
if let ast::FunctionRetTy::Ty(ref ret_ty) = decl.output {
388-
v.visit_ty(&ret_ty);
388+
if let ast::TyKind::ImplTrait(..) = ret_ty.node {
389+
// FIXME: Opaque type desugaring prevents us from easily
390+
// processing trait bounds. See `visit_ty` for more details.
391+
} else {
392+
v.visit_ty(&ret_ty);
393+
}
389394
}
390395

391396
v.visit_block(&body);
@@ -1439,6 +1444,18 @@ impl<'l, 'tcx> Visitor<'l> for DumpVisitor<'l, 'tcx> {
14391444
self.visit_ty(element);
14401445
self.nest_tables(length.id, |v| v.visit_expr(&length.value));
14411446
}
1447+
ast::TyKind::ImplTrait(id, ref bounds) => {
1448+
// FIXME: As of writing, the opaque type lowering introduces
1449+
// another DefPath scope/segment (used to declare the resulting
1450+
// opaque type item).
1451+
// However, the synthetic scope does *not* have associated
1452+
// typeck tables, which means we can't nest it and we fire an
1453+
// assertion when resolving the qualified type paths in trait
1454+
// bounds...
1455+
// This will panic if called on return type `impl Trait`, which
1456+
// we guard against in `process_fn`.
1457+
self.nest_tables(id, |v| v.process_bounds(bounds));
1458+
}
14421459
_ => visit::walk_ty(self, t),
14431460
}
14441461
}

src/test/ui/save-analysis/issue-63663.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
// check-pass
22
// compile-flags: -Zsave-analysis
33

4-
// Check that this doesn't ICE when processing associated const in formal
5-
// argument and return type of functions defined inside function/method scope.
6-
74
pub trait Trait {
85
type Assoc;
96
}
107

118
pub struct A;
129

10+
trait Generic<T> {}
11+
impl<T> Generic<T> for () {}
12+
13+
// Don't ICE when resolving type paths in return type `impl Trait`
14+
fn assoc_in_opaque_type_bounds<U: Trait>() -> impl Generic<U::Assoc> {}
15+
16+
// Check that this doesn't ICE when processing associated const in formal
17+
// argument and return type of functions defined inside function/method scope.
1318
pub fn func() {
1419
fn _inner1<U: Trait>(_: U::Assoc) {}
1520
fn _inner2<U: Trait>() -> U::Assoc { unimplemented!() }

0 commit comments

Comments
 (0)