Skip to content

Commit a97c742

Browse files
authored
Rollup merge of rust-lang#104508 - compiler-errors:dyn-return, r=oli-obk
Check `dyn*` return type correctly In `check_fn`, if the declared return type is `dyn Trait`, then we check the return type separately to produce better diagnostics, because this is never valid -- however, when `dyn*` was introduced, this check was never adjusted to only account for *unsized* `dyn Trait` and not *sized* `dyn* Trait`. Fixes rust-lang#104501
2 parents 1641f55 + 75afb22 commit a97c742

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

compiler/rustc_hir_typeck/src/check.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ pub(super) fn check_fn<'a, 'tcx>(
102102

103103
inherited.typeck_results.borrow_mut().liberated_fn_sigs_mut().insert(fn_id, fn_sig);
104104

105-
if let ty::Dynamic(..) = declared_ret_ty.kind() {
105+
if let ty::Dynamic(_, _, ty::Dyn) = declared_ret_ty.kind() {
106106
// FIXME: We need to verify that the return type is `Sized` after the return expression has
107107
// been evaluated so that we have types available for all the nodes being returned, but that
108108
// requires the coerced evaluated type to be stored. Moving `check_return_expr` before this

src/test/ui/dyn-star/return.rs

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// check-pass
2+
3+
#![feature(dyn_star)]
4+
//~^ WARN the feature `dyn_star` is incomplete and may not be safe to use and/or cause compiler crashes
5+
6+
fn _foo() -> dyn* Unpin {
7+
4usize
8+
}
9+
10+
fn main() {}

src/test/ui/dyn-star/return.stderr

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
warning: the feature `dyn_star` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/return.rs:3:12
3+
|
4+
LL | #![feature(dyn_star)]
5+
| ^^^^^^^^
6+
|
7+
= note: see issue #91611 <https://github.com/rust-lang/rust/issues/91611> for more information
8+
= note: `#[warn(incomplete_features)]` on by default
9+
10+
warning: 1 warning emitted
11+

0 commit comments

Comments
 (0)