From 75afb22331daececeba38a3efb0134348d6c14d9 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Wed, 16 Nov 2022 22:21:41 +0000 Subject: [PATCH] Check `dyn*` return type correctly --- compiler/rustc_hir_typeck/src/check.rs | 2 +- src/test/ui/dyn-star/return.rs | 10 ++++++++++ src/test/ui/dyn-star/return.stderr | 11 +++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 src/test/ui/dyn-star/return.rs create mode 100644 src/test/ui/dyn-star/return.stderr diff --git a/compiler/rustc_hir_typeck/src/check.rs b/compiler/rustc_hir_typeck/src/check.rs index 3c57e33f6f7..296cf00a687 100644 --- a/compiler/rustc_hir_typeck/src/check.rs +++ b/compiler/rustc_hir_typeck/src/check.rs @@ -100,7 +100,7 @@ pub(super) fn check_fn<'a, 'tcx>( inherited.typeck_results.borrow_mut().liberated_fn_sigs_mut().insert(fn_id, fn_sig); - if let ty::Dynamic(..) = declared_ret_ty.kind() { + if let ty::Dynamic(_, _, ty::Dyn) = declared_ret_ty.kind() { // FIXME: We need to verify that the return type is `Sized` after the return expression has // been evaluated so that we have types available for all the nodes being returned, but that // requires the coerced evaluated type to be stored. Moving `check_return_expr` before this diff --git a/src/test/ui/dyn-star/return.rs b/src/test/ui/dyn-star/return.rs new file mode 100644 index 00000000000..fa3d8d7d506 --- /dev/null +++ b/src/test/ui/dyn-star/return.rs @@ -0,0 +1,10 @@ +// check-pass + +#![feature(dyn_star)] +//~^ WARN the feature `dyn_star` is incomplete and may not be safe to use and/or cause compiler crashes + +fn _foo() -> dyn* Unpin { + 4usize +} + +fn main() {} diff --git a/src/test/ui/dyn-star/return.stderr b/src/test/ui/dyn-star/return.stderr new file mode 100644 index 00000000000..e000351a68f --- /dev/null +++ b/src/test/ui/dyn-star/return.stderr @@ -0,0 +1,11 @@ +warning: the feature `dyn_star` is incomplete and may not be safe to use and/or cause compiler crashes + --> $DIR/return.rs:3:12 + | +LL | #![feature(dyn_star)] + | ^^^^^^^^ + | + = note: see issue #91611 for more information + = note: `#[warn(incomplete_features)]` on by default + +warning: 1 warning emitted +