Skip to content

Commit 126ef8e

Browse files
don't do Sized/other fn signature checks on RPIT's real type
1 parent fa70b89 commit 126ef8e

File tree

3 files changed

+24
-7
lines changed

3 files changed

+24
-7
lines changed

compiler/rustc_typeck/src/check/check.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,6 @@ pub(super) fn check_fn<'a, 'tcx>(
103103
DUMMY_SP,
104104
param_env,
105105
));
106-
// HACK(oli-obk): we rewrite the declared return type, too, so that we don't end up inferring all
107-
// unconstrained RPIT to have `()` as their hidden type. This would happen because further down we
108-
// compare the ret_coercion with declared_ret_ty, and anything uninferred would be inferred to the
109-
// opaque type itself. That again would cause writeback to assume we have a recursive call site
110-
// and do the sadly stabilized fallback to `()`.
111-
let declared_ret_ty = ret_ty;
112106
fcx.ret_coercion = Some(RefCell::new(CoerceMany::new(ret_ty)));
113107
fcx.ret_type_span = Some(decl.output.span());
114108

@@ -252,7 +246,12 @@ pub(super) fn check_fn<'a, 'tcx>(
252246
fcx.next_ty_var(TypeVariableOrigin { kind: TypeVariableOriginKind::DynReturnFn, span });
253247
debug!("actual_return_ty replaced with {:?}", actual_return_ty);
254248
}
255-
fcx.demand_suptype(span, declared_ret_ty, actual_return_ty);
249+
250+
// HACK(oli-obk, compiler-errors): We should be comparing this against
251+
// `declared_ret_ty`, but then anything uninferred would be inferred to
252+
// the opaque type itself. That again would cause writeback to assume
253+
// we have a recursive call site and do the sadly stabilized fallback to `()`.
254+
fcx.demand_suptype(span, ret_ty, actual_return_ty);
256255

257256
// Check that a function marked as `#[panic_handler]` has signature `fn(&PanicInfo) -> !`
258257
if let Some(panic_impl_did) = tcx.lang_items().panic_impl()
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
fn foo() -> impl ?Sized {
2+
//~^ ERROR the size for values of type `impl ?Sized` cannot be known at compilation time
3+
()
4+
}
5+
6+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0277]: the size for values of type `impl ?Sized` cannot be known at compilation time
2+
--> $DIR/rpit-not-sized.rs:1:13
3+
|
4+
LL | fn foo() -> impl ?Sized {
5+
| ^^^^^^^^^^^ doesn't have a size known at compile-time
6+
|
7+
= help: the trait `Sized` is not implemented for `impl ?Sized`
8+
= note: the return type of a function must have a statically known size
9+
10+
error: aborting due to previous error
11+
12+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)