Skip to content

Commit ab22f55

Browse files
committed
change error_reported to use Result instead of an option
1 parent 7df9d81 commit ab22f55

File tree

7 files changed

+15
-22
lines changed

7 files changed

+15
-22
lines changed

compiler/rustc_hir_analysis/src/astconv/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1977,7 +1977,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
19771977
}
19781978

19791979
err.emit()
1980-
} else if let Some(reported) = qself_ty.error_reported() {
1980+
} else if let Err(reported) = qself_ty.error_reported() {
19811981
reported
19821982
} else {
19831983
// Don't print `TyErr` to the user.

compiler/rustc_hir_analysis/src/coherence/orphan.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ pub(crate) fn orphan_check_impl(
2323
impl_def_id: LocalDefId,
2424
) -> Result<(), ErrorGuaranteed> {
2525
let trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap();
26-
if let Some(err) = trait_ref.error_reported() {
27-
return Err(err);
28-
}
26+
trait_ref.error_reported()?;
2927

3028
let ret = do_orphan_check_impl(tcx, trait_ref, impl_def_id);
3129
if tcx.trait_is_auto(trait_ref.def_id) {

compiler/rustc_hir_typeck/src/cast.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
9292
debug!("pointer_kind({:?}, {:?})", t, span);
9393

9494
let t = self.resolve_vars_if_possible(t);
95-
96-
if let Some(reported) = t.error_reported() {
97-
return Err(reported);
98-
}
95+
t.error_reported()?;
9996

10097
if self.type_is_sized_modulo_regions(self.param_env, t, span) {
10198
return Ok(Some(PointerKind::Thin));
@@ -220,7 +217,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
220217
match cast_ty.kind() {
221218
ty::Dynamic(_, _, ty::Dyn) | ty::Slice(..) => {
222219
let reported = check.report_cast_to_unsized_type(fcx);
223-
Err(reported)
220+
return Err(reported);
224221
}
225222
_ => Ok(check),
226223
}
@@ -611,10 +608,11 @@ impl<'a, 'tcx> CastCheck<'tcx> {
611608
}
612609

613610
fn report_cast_to_unsized_type(&self, fcx: &FnCtxt<'a, 'tcx>) -> ErrorGuaranteed {
614-
if let Some(reported) =
615-
self.cast_ty.error_reported().or_else(|| self.expr_ty.error_reported())
616-
{
617-
return reported;
611+
if let Err(err) = self.cast_ty.error_reported() {
612+
return err;
613+
}
614+
if let Err(err) = self.expr_ty.error_reported() {
615+
return err;
618616
}
619617

620618
let tstr = fcx.ty_to_string(self.cast_ty);

compiler/rustc_middle/src/traits/specialization_graph.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ pub fn ancestors<'tcx>(
249249

250250
if let Some(reported) = specialization_graph.has_errored {
251251
Err(reported)
252-
} else if let Some(reported) = tcx.type_of(start_from_impl).error_reported() {
252+
} else if let Err(reported) = tcx.type_of(start_from_impl).error_reported() {
253253
Err(reported)
254254
} else {
255255
Ok(Ancestors {

compiler/rustc_middle/src/ty/context.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1315,10 +1315,7 @@ impl<'tcx> TyCtxt<'tcx> {
13151315
msg: &str,
13161316
) -> Const<'tcx> {
13171317
let reported = self.sess.delay_span_bug(span, msg);
1318-
self.mk_const(ty::ConstS {
1319-
kind: ty::ConstKind::Error(reported),
1320-
ty,
1321-
})
1318+
self.mk_const(ty::ConstS { kind: ty::ConstKind::Error(reported), ty })
13221319
}
13231320

13241321
pub fn consider_optimizing<T: Fn() -> String>(self, msg: T) -> bool {

compiler/rustc_middle/src/ty/visit.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,11 @@ pub trait TypeVisitable<'tcx>: fmt::Debug + Clone {
9595
fn references_error(&self) -> bool {
9696
self.has_type_flags(TypeFlags::HAS_ERROR)
9797
}
98-
fn error_reported(&self) -> Option<ErrorGuaranteed> {
98+
fn error_reported(&self) -> Result<(), ErrorGuaranteed> {
9999
if self.references_error() {
100-
Some(ErrorGuaranteed::unchecked_claim_error_was_emitted())
100+
Err(ErrorGuaranteed::unchecked_claim_error_was_emitted())
101101
} else {
102-
None
102+
Ok(())
103103
}
104104
}
105105
fn has_non_region_param(&self) -> bool {

compiler/rustc_transmute/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ mod rustc {
122122

123123
let c = c.eval(tcx, param_env);
124124

125-
if let Some(err) = c.error_reported() {
125+
if let Err(err) = c.error_reported() {
126126
return Some(Self {
127127
alignment: true,
128128
lifetimes: true,

0 commit comments

Comments
 (0)