Skip to content

Commit

Permalink
save-analysis: Process bounds in impl trait only in argument position
Browse files Browse the repository at this point in the history
  • Loading branch information
Xanewok committed Sep 14, 2019
1 parent 30e39e8 commit a946b8d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
19 changes: 18 additions & 1 deletion src/librustc_save_analysis/dump_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,12 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
}

if let ast::FunctionRetTy::Ty(ref ret_ty) = decl.output {
v.visit_ty(&ret_ty);
if let ast::TyKind::ImplTrait(..) = ret_ty.node {
// FIXME: Opaque type desugaring prevents us from easily
// processing trait bounds. See `visit_ty` for more details.
} else {
v.visit_ty(&ret_ty);
}
}

v.visit_block(&body);
Expand Down Expand Up @@ -1439,6 +1444,18 @@ impl<'l, 'tcx> Visitor<'l> for DumpVisitor<'l, 'tcx> {
self.visit_ty(element);
self.nest_tables(length.id, |v| v.visit_expr(&length.value));
}
ast::TyKind::ImplTrait(id, ref bounds) => {
// FIXME: As of writing, the opaque type lowering introduces
// another DefPath scope/segment (used to declare the resulting
// opaque type item).
// However, the synthetic scope does *not* have associated
// typeck tables, which means we can't nest it and we fire an
// assertion when resolving the qualified type paths in trait
// bounds...
// This will panic if called on return type `impl Trait`, which
// we guard against in `process_fn`.
self.nest_tables(id, |v| v.process_bounds(bounds));
}
_ => visit::walk_ty(self, t),
}
}
Expand Down
11 changes: 8 additions & 3 deletions src/test/ui/save-analysis/issue-63663.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
// check-pass
// compile-flags: -Zsave-analysis

// Check that this doesn't ICE when processing associated const in formal
// argument and return type of functions defined inside function/method scope.

pub trait Trait {
type Assoc;
}

pub struct A;

trait Generic<T> {}
impl<T> Generic<T> for () {}

// Don't ICE when resolving type paths in return type `impl Trait`
fn assoc_in_opaque_type_bounds<U: Trait>() -> impl Generic<U::Assoc> {}

// Check that this doesn't ICE when processing associated const in formal
// argument and return type of functions defined inside function/method scope.
pub fn func() {
fn _inner1<U: Trait>(_: U::Assoc) {}
fn _inner2<U: Trait>() -> U::Assoc { unimplemented!() }
Expand Down

0 comments on commit a946b8d

Please sign in to comment.