Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

don't do Sized and other return type checks on RPIT's real type #97431

Merged
merged 1 commit into from
May 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions compiler/rustc_typeck/src/check/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,6 @@ pub(super) fn check_fn<'a, 'tcx>(
DUMMY_SP,
param_env,
));
// HACK(oli-obk): we rewrite the declared return type, too, so that we don't end up inferring all
// unconstrained RPIT to have `()` as their hidden type. This would happen because further down we
// compare the ret_coercion with declared_ret_ty, and anything uninferred would be inferred to the
// opaque type itself. That again would cause writeback to assume we have a recursive call site
// and do the sadly stabilized fallback to `()`.
let declared_ret_ty = ret_ty;
fcx.ret_coercion = Some(RefCell::new(CoerceMany::new(ret_ty)));
fcx.ret_type_span = Some(decl.output.span());

Expand Down Expand Up @@ -252,7 +246,12 @@ pub(super) fn check_fn<'a, 'tcx>(
fcx.next_ty_var(TypeVariableOrigin { kind: TypeVariableOriginKind::DynReturnFn, span });
debug!("actual_return_ty replaced with {:?}", actual_return_ty);
}
fcx.demand_suptype(span, declared_ret_ty, actual_return_ty);

// HACK(oli-obk, compiler-errors): We should be comparing this against
// `declared_ret_ty`, but then anything uninferred would be inferred to
// the opaque type itself. That again would cause writeback to assume
// we have a recursive call site and do the sadly stabilized fallback to `()`.
fcx.demand_suptype(span, ret_ty, actual_return_ty);

// Check that a function marked as `#[panic_handler]` has signature `fn(&PanicInfo) -> !`
if let Some(panic_impl_did) = tcx.lang_items().panic_impl()
Expand Down
6 changes: 6 additions & 0 deletions src/test/ui/impl-trait/rpit-not-sized.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
fn foo() -> impl ?Sized {
//~^ ERROR the size for values of type `impl ?Sized` cannot be known at compilation time
()
}

fn main() {}
12 changes: 12 additions & 0 deletions src/test/ui/impl-trait/rpit-not-sized.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
error[E0277]: the size for values of type `impl ?Sized` cannot be known at compilation time
--> $DIR/rpit-not-sized.rs:1:13
|
LL | fn foo() -> impl ?Sized {
| ^^^^^^^^^^^ doesn't have a size known at compile-time
|
= help: the trait `Sized` is not implemented for `impl ?Sized`
= note: the return type of a function must have a statically known size

error: aborting due to previous error

For more information about this error, try `rustc --explain E0277`.