From 29a41f0d86b82c2731cc2ab8c8a26272e773e4c3 Mon Sep 17 00:00:00 2001 From: csmoe Date: Mon, 11 May 2020 14:24:57 +0800 Subject: [PATCH] add ui test for issue-69276 --- src/librustc_typeck/check/mod.rs | 6 +++++- src/test/ui/async-await/issue-69276.rs | 12 ++++++++++++ src/test/ui/async-await/issue-69276.stderr | 8 ++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 src/test/ui/async-await/issue-69276.rs create mode 100644 src/test/ui/async-await/issue-69276.stderr diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 956e09ec52b4..57fdb03250e7 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -1659,6 +1659,7 @@ fn check_opaque_for_inheriting_lifetimes(tcx: TyCtxt<'tcx>, def_id: LocalDefId, let prohibit_opaque = match item.kind { ItemKind::OpaqueTy(hir::OpaqueTy { + bounds, origin: hir::OpaqueTyOrigin::AsyncFn | hir::OpaqueTyOrigin::FnReturn, .. }) => { @@ -1671,6 +1672,9 @@ fn check_opaque_for_inheriting_lifetimes(tcx: TyCtxt<'tcx>, def_id: LocalDefId, }; debug!("check_opaque_for_inheriting_lifetimes: visitor={:?}", visitor); + for bound in bounds { + debug!("check_opaque_for_inheriting_lifetimes: {:?}", bound.trait_ref()); + } tcx.predicates_of(def_id) .predicates .iter() @@ -1695,7 +1699,7 @@ fn check_opaque_for_inheriting_lifetimes(tcx: TyCtxt<'tcx>, def_id: LocalDefId, "`{}` return type cannot contain a projection or `Self` that references lifetimes from \ a parent scope", if is_async { "async fn" } else { "impl Trait" }, - ), + ) ); } } diff --git a/src/test/ui/async-await/issue-69276.rs b/src/test/ui/async-await/issue-69276.rs new file mode 100644 index 000000000000..224b76e2d903 --- /dev/null +++ b/src/test/ui/async-await/issue-69276.rs @@ -0,0 +1,12 @@ +// edition:2018 + +struct S<'a>(&'a i32); + +impl<'a> S<'a> { + async fn new(i: &'a i32) -> Self { + //~^ ERROR `async fn` return type cannot contain a projection or `Self` that references lifetimes from a parent scope + S(&22) + } +} + +fn main() {} diff --git a/src/test/ui/async-await/issue-69276.stderr b/src/test/ui/async-await/issue-69276.stderr new file mode 100644 index 000000000000..1ebfdfa8b54c --- /dev/null +++ b/src/test/ui/async-await/issue-69276.stderr @@ -0,0 +1,8 @@ +error: `async fn` return type cannot contain a projection or `Self` that references lifetimes from a parent scope + --> $DIR/issue-69276.rs:6:33 + | +LL | async fn new(i: &'a i32) -> Self { + | ^^^^ + +error: aborting due to previous error +