Skip to content

Commit cfce3a9

Browse files
authoredOct 5, 2023
Rollup merge of #116296 - compiler-errors:default-return, r=estebank
More accurately point to where default return type should go When getting the "default return type" span, instead of pointing to the low span of the next token, point to the high span of the previous token. This: 1. Makes forming return type suggestions more uniform, since we expect them all in the same place. 2. Arguably makes labels easier to understand, since we're pointing to where the implicit `-> ()` would've gone, rather than the starting brace or the semicolon. r? ```@estebank```
2 parents ea3454e + dd5f26c commit cfce3a9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+105
-89
lines changed
 

‎compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1189,7 +1189,7 @@ fn report_trait_method_mismatch<'tcx>(
11891189
let ap = Applicability::MachineApplicable;
11901190
match sig.decl.output {
11911191
hir::FnRetTy::DefaultReturn(sp) => {
1192-
let sugg = format!("-> {} ", trait_sig.output());
1192+
let sugg = format!(" -> {}", trait_sig.output());
11931193
diag.span_suggestion_verbose(sp, msg, sugg, ap);
11941194
}
11951195
hir::FnRetTy::Return(hir_ty) => {

‎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.

0 commit comments

Comments
 (0)
Please sign in to comment.