change error_reported to use Result instead of an option
This commit is contained in:
parent
7df9d818ab
commit
ab22f5521b
@ -1977,7 +1977,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||
}
|
||||
|
||||
err.emit()
|
||||
} else if let Some(reported) = qself_ty.error_reported() {
|
||||
} else if let Err(reported) = qself_ty.error_reported() {
|
||||
reported
|
||||
} else {
|
||||
// Don't print `TyErr` to the user.
|
||||
|
@ -23,9 +23,7 @@ pub(crate) fn orphan_check_impl(
|
||||
impl_def_id: LocalDefId,
|
||||
) -> Result<(), ErrorGuaranteed> {
|
||||
let trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap();
|
||||
if let Some(err) = trait_ref.error_reported() {
|
||||
return Err(err);
|
||||
}
|
||||
trait_ref.error_reported()?;
|
||||
|
||||
let ret = do_orphan_check_impl(tcx, trait_ref, impl_def_id);
|
||||
if tcx.trait_is_auto(trait_ref.def_id) {
|
||||
|
@ -92,10 +92,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
debug!("pointer_kind({:?}, {:?})", t, span);
|
||||
|
||||
let t = self.resolve_vars_if_possible(t);
|
||||
|
||||
if let Some(reported) = t.error_reported() {
|
||||
return Err(reported);
|
||||
}
|
||||
t.error_reported()?;
|
||||
|
||||
if self.type_is_sized_modulo_regions(self.param_env, t, span) {
|
||||
return Ok(Some(PointerKind::Thin));
|
||||
@ -220,7 +217,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
|
||||
match cast_ty.kind() {
|
||||
ty::Dynamic(_, _, ty::Dyn) | ty::Slice(..) => {
|
||||
let reported = check.report_cast_to_unsized_type(fcx);
|
||||
Err(reported)
|
||||
return Err(reported);
|
||||
}
|
||||
_ => Ok(check),
|
||||
}
|
||||
@ -611,10 +608,11 @@ impl<'a, 'tcx> CastCheck<'tcx> {
|
||||
}
|
||||
|
||||
fn report_cast_to_unsized_type(&self, fcx: &FnCtxt<'a, 'tcx>) -> ErrorGuaranteed {
|
||||
if let Some(reported) =
|
||||
self.cast_ty.error_reported().or_else(|| self.expr_ty.error_reported())
|
||||
{
|
||||
return reported;
|
||||
if let Err(err) = self.cast_ty.error_reported() {
|
||||
return err;
|
||||
}
|
||||
if let Err(err) = self.expr_ty.error_reported() {
|
||||
return err;
|
||||
}
|
||||
|
||||
let tstr = fcx.ty_to_string(self.cast_ty);
|
||||
|
@ -249,7 +249,7 @@ pub fn ancestors<'tcx>(
|
||||
|
||||
if let Some(reported) = specialization_graph.has_errored {
|
||||
Err(reported)
|
||||
} else if let Some(reported) = tcx.type_of(start_from_impl).error_reported() {
|
||||
} else if let Err(reported) = tcx.type_of(start_from_impl).error_reported() {
|
||||
Err(reported)
|
||||
} else {
|
||||
Ok(Ancestors {
|
||||
|
@ -1315,10 +1315,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||
msg: &str,
|
||||
) -> Const<'tcx> {
|
||||
let reported = self.sess.delay_span_bug(span, msg);
|
||||
self.mk_const(ty::ConstS {
|
||||
kind: ty::ConstKind::Error(reported),
|
||||
ty,
|
||||
})
|
||||
self.mk_const(ty::ConstS { kind: ty::ConstKind::Error(reported), ty })
|
||||
}
|
||||
|
||||
pub fn consider_optimizing<T: Fn() -> String>(self, msg: T) -> bool {
|
||||
|
@ -95,11 +95,11 @@ pub trait TypeVisitable<'tcx>: fmt::Debug + Clone {
|
||||
fn references_error(&self) -> bool {
|
||||
self.has_type_flags(TypeFlags::HAS_ERROR)
|
||||
}
|
||||
fn error_reported(&self) -> Option<ErrorGuaranteed> {
|
||||
fn error_reported(&self) -> Result<(), ErrorGuaranteed> {
|
||||
if self.references_error() {
|
||||
Some(ErrorGuaranteed::unchecked_claim_error_was_emitted())
|
||||
Err(ErrorGuaranteed::unchecked_claim_error_was_emitted())
|
||||
} else {
|
||||
None
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
fn has_non_region_param(&self) -> bool {
|
||||
|
@ -122,7 +122,7 @@ mod rustc {
|
||||
|
||||
let c = c.eval(tcx, param_env);
|
||||
|
||||
if let Some(err) = c.error_reported() {
|
||||
if let Err(err) = c.error_reported() {
|
||||
return Some(Self {
|
||||
alignment: true,
|
||||
lifetimes: true,
|
||||
|
Loading…
x
Reference in New Issue
Block a user