Skip to content

Commit ddf220c

Browse files
committed
use ErrorGuaranteed
1 parent 69c7bbb commit ddf220c

2 files changed

Lines changed: 19 additions & 21 deletions

File tree

compiler/rustc_hir_analysis/src/check/entry.rs

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,23 @@ use rustc_infer::infer::TyCtxtInferExt;
88
use rustc_middle::span_bug;
99
use rustc_middle::ty::{self, TyCtxt, TypingMode};
1010
use rustc_session::config::EntryFnType;
11-
use rustc_span::Span;
1211
use rustc_span::def_id::{CRATE_DEF_ID, DefId, LocalDefId};
12+
use rustc_span::{ErrorGuaranteed, Span};
1313
use rustc_trait_selection::error_reporting::InferCtxtErrorExt;
1414
use rustc_trait_selection::regions::InferCtxtRegionExt;
1515
use rustc_trait_selection::traits::{self, ObligationCause, ObligationCauseCode};
1616

1717
use super::check_function_signature;
1818
use crate::errors;
1919

20-
pub(crate) fn check_for_entry_fn(tcx: TyCtxt<'_>) {
20+
pub(crate) fn check_for_entry_fn(tcx: TyCtxt<'_>) -> Result<(), ErrorGuaranteed> {
2121
match tcx.entry_fn(()) {
2222
Some((def_id, EntryFnType::Main { .. })) => check_main_fn_ty(tcx, def_id),
23-
_ => {}
23+
_ => Ok(()),
2424
}
2525
}
2626

27-
fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: DefId) {
27+
fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: DefId) -> Result<(), ErrorGuaranteed> {
2828
let main_fnsig = tcx.fn_sig(main_def_id).instantiate_identity();
2929
let main_span = tcx.def_span(main_def_id);
3030

@@ -117,7 +117,7 @@ fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: DefId) {
117117
}
118118

119119
if error {
120-
return;
120+
return Ok(());
121121
}
122122

123123
// Main should have no WC, so empty param env is OK here.
@@ -128,7 +128,7 @@ fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: DefId) {
128128
let return_ty_span = main_fn_return_type_span(tcx, main_def_id).unwrap_or(main_span);
129129
let Some(return_ty) = return_ty.no_bound_vars() else {
130130
tcx.dcx().emit_err(errors::MainFunctionReturnTypeGeneric { span: return_ty_span });
131-
return;
131+
return Ok(());
132132
};
133133
let infcx = tcx.infer_ctxt().build(TypingMode::non_body_analysis());
134134
let cause = traits::ObligationCause::new(
@@ -141,16 +141,16 @@ fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: DefId) {
141141
ocx.register_bound(cause, param_env, norm_return_ty, term_did);
142142
let errors = ocx.evaluate_obligations_error_on_ambiguity();
143143
if !errors.is_empty() {
144-
infcx.err_ctxt().report_fulfillment_errors(errors);
145-
error = true;
144+
return Err(infcx.err_ctxt().report_fulfillment_errors(errors));
146145
}
147146

148147
let region_errors =
149-
infcx.resolve_regions(main_diagnostics_def_id, param_env, tcx.mk_type_list(&[]));
148+
infcx.resolve_regions(main_diagnostics_def_id, param_env, ty::List::empty());
150149

151150
if !region_errors.is_empty() {
152-
infcx.err_ctxt().report_region_errors(main_diagnostics_def_id, &region_errors);
153-
error = true;
151+
return Err(infcx
152+
.err_ctxt()
153+
.report_region_errors(main_diagnostics_def_id, &region_errors));
154154
}
155155
// now we can take the return type of the given main function
156156
expected_return_type = norm_return_ty;
@@ -159,10 +159,6 @@ fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: DefId) {
159159
expected_return_type = tcx.types.unit;
160160
}
161161

162-
if error {
163-
return;
164-
}
165-
166162
let expected_sig = ty::Binder::dummy(tcx.mk_fn_sig(
167163
[],
168164
expected_return_type,
@@ -183,23 +179,25 @@ fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: DefId) {
183179
)
184180
.is_err()
185181
{
186-
return;
182+
return Ok(());
187183
}
188184

189185
let main_fn_generics = tcx.generics_of(main_def_id);
190186
let main_fn_predicates = tcx.predicates_of(main_def_id);
191187
if main_fn_generics.count() != 0 || !main_fnsig.bound_vars().is_empty() {
192188
let generics_param_span = main_fn_generics_params_span(tcx, main_def_id);
193-
tcx.dcx().emit_err(errors::MainFunctionGenericParameters {
189+
return Err(tcx.dcx().emit_err(errors::MainFunctionGenericParameters {
194190
span: generics_param_span.unwrap_or(main_span),
195191
label_span: generics_param_span,
196-
});
192+
}));
197193
} else if !main_fn_predicates.predicates.is_empty() {
198194
// generics may bring in implicit predicates, so we skip this check if generics is present.
199195
let generics_where_clauses_span = main_fn_where_clauses_span(tcx, main_def_id);
200-
tcx.dcx().emit_err(errors::WhereClauseOnMain {
196+
return Err(tcx.dcx().emit_err(errors::WhereClauseOnMain {
201197
span: generics_where_clauses_span.unwrap_or(main_span),
202198
generics_span: generics_where_clauses_span,
203-
});
199+
}));
204200
}
201+
202+
Ok(())
205203
}

compiler/rustc_hir_analysis/src/check/wfcheck.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2314,7 +2314,7 @@ pub(super) fn check_type_wf(tcx: TyCtxt<'_>, (): ()) -> Result<(), ErrorGuarante
23142314
)
23152315
.and(items.par_nested_bodies(|item| tcx.ensure_ok().check_well_formed(item)))
23162316
.and(items.par_opaques(|item| tcx.ensure_ok().check_well_formed(item)));
2317-
super::entry::check_for_entry_fn(tcx);
2317+
super::entry::check_for_entry_fn(tcx)?;
23182318

23192319
res
23202320
}

0 commit comments

Comments
 (0)