Skip to content

Commit 1f079cf

Browse files
Point to closure return instead of output if defaulted
1 parent 89b14ae commit 1f079cf

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

compiler/rustc_hir_typeck/src/check.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,11 @@ pub(super) fn check_fn<'a, 'tcx>(
113113

114114
fcx.typeck_results.borrow_mut().liberated_fn_sigs_mut().insert(fn_id, fn_sig);
115115

116-
fcx.require_type_is_sized(declared_ret_ty, decl.output.span(), traits::SizedReturnType);
116+
let return_or_body_span = match decl.output {
117+
hir::FnRetTy::DefaultReturn(_) => body.value.span,
118+
hir::FnRetTy::Return(ty) => ty.span,
119+
};
120+
fcx.require_type_is_sized(declared_ret_ty, return_or_body_span, traits::SizedReturnType);
117121
fcx.check_return_expr(&body.value, false);
118122

119123
// We insert the deferred_generator_interiors entry after visiting the body.

src/tools/clippy/tests/ui/crashes/ice-6251.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ LL | fn bug<T>() -> impl Iterator<Item = [(); { |x: &[u8]| x }]> {
1212
| +
1313

1414
error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
15-
--> $DIR/ice-6251.rs:4:53
15+
--> $DIR/ice-6251.rs:4:54
1616
|
1717
LL | fn bug<T>() -> impl Iterator<Item = [(); { |x: [u8]| x }]> {
18-
| ^ doesn't have a size known at compile-time
18+
| ^ doesn't have a size known at compile-time
1919
|
2020
= help: the trait `std::marker::Sized` is not implemented for `[u8]`
2121
= note: the return type of a function must have a statically known size

0 commit comments

Comments
 (0)