From a946b8d6e1ff39f22e3f9f1c46ba81898901d907 Mon Sep 17 00:00:00 2001 From: Igor Matuszewski Date: Sun, 15 Sep 2019 00:42:18 +0200 Subject: [PATCH] save-analysis: Process bounds in impl trait only in argument position --- src/librustc_save_analysis/dump_visitor.rs | 19 ++++++++++++++++++- src/test/ui/save-analysis/issue-63663.rs | 11 ++++++++--- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/librustc_save_analysis/dump_visitor.rs b/src/librustc_save_analysis/dump_visitor.rs index c43e07a8c74..55f6b91e714 100644 --- a/src/librustc_save_analysis/dump_visitor.rs +++ b/src/librustc_save_analysis/dump_visitor.rs @@ -385,7 +385,12 @@ fn process_fn( } 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); @@ -1439,6 +1444,18 @@ fn visit_ty(&mut self, t: &'l ast::Ty) { 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), } } diff --git a/src/test/ui/save-analysis/issue-63663.rs b/src/test/ui/save-analysis/issue-63663.rs index ccbe13f1a1b..92e85884f66 100644 --- a/src/test/ui/save-analysis/issue-63663.rs +++ b/src/test/ui/save-analysis/issue-63663.rs @@ -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 {} +impl Generic for () {} + +// Don't ICE when resolving type paths in return type `impl Trait` +fn assoc_in_opaque_type_bounds() -> impl Generic {} + +// 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::Assoc) {} fn _inner2() -> U::Assoc { unimplemented!() } -- 2.44.0