rustc_error: make ErrorReported impossible to construct
There are a few places were we have to construct it, though, and a few places that are more invasive to change. To do this, we create a constructor with a long obvious name.
This commit is contained in:
parent
461e807801
commit
bb8d4307eb
104 changed files with 705 additions and 550 deletions
|
@ -118,7 +118,9 @@ fn mir_build(tcx: TyCtxt<'_>, def: ty::WithOptConstParam<LocalDefId>) -> Body<'_
|
|||
};
|
||||
|
||||
let body = tcx.hir().body(body_id);
|
||||
let (thir, expr) = tcx.thir_body(def);
|
||||
let (thir, expr) = tcx
|
||||
.thir_body(def)
|
||||
.unwrap_or_else(|_| (tcx.alloc_steal_thir(Thir::new()), ExprId::from_u32(0)));
|
||||
// We ran all queries that depended on THIR at the beginning
|
||||
// of `mir_build`, so now we can steal it
|
||||
let thir = thir.steal();
|
||||
|
@ -229,7 +231,9 @@ fn mir_build(tcx: TyCtxt<'_>, def: ty::WithOptConstParam<LocalDefId>) -> Body<'_
|
|||
|
||||
let return_ty = typeck_results.node_type(id);
|
||||
|
||||
let (thir, expr) = tcx.thir_body(def);
|
||||
let (thir, expr) = tcx
|
||||
.thir_body(def)
|
||||
.unwrap_or_else(|_| (tcx.alloc_steal_thir(Thir::new()), ExprId::from_u32(0)));
|
||||
// We ran all queries that depended on THIR at the beginning
|
||||
// of `mir_build`, so now we can steal it
|
||||
let thir = thir.steal();
|
||||
|
|
|
@ -405,7 +405,9 @@ impl<'a, 'tcx> Visitor<'a, 'tcx> for UnsafetyVisitor<'a, 'tcx> {
|
|||
} else {
|
||||
ty::WithOptConstParam::unknown(closure_id)
|
||||
};
|
||||
let (closure_thir, expr) = self.tcx.thir_body(closure_def);
|
||||
let (closure_thir, expr) = self.tcx.thir_body(closure_def).unwrap_or_else(|_| {
|
||||
(self.tcx.alloc_steal_thir(Thir::new()), ExprId::from_u32(0))
|
||||
});
|
||||
let closure_thir = &closure_thir.borrow();
|
||||
let hir_context = self.tcx.hir().local_def_id_to_hir_id(closure_id);
|
||||
let mut closure_visitor =
|
||||
|
@ -606,7 +608,10 @@ pub fn check_unsafety<'tcx>(tcx: TyCtxt<'tcx>, def: ty::WithOptConstParam<LocalD
|
|||
return;
|
||||
}
|
||||
|
||||
let (thir, expr) = tcx.thir_body(def);
|
||||
let (thir, expr) = match tcx.thir_body(def) {
|
||||
Ok(body) => body,
|
||||
Err(_) => return,
|
||||
};
|
||||
let thir = &thir.borrow();
|
||||
// If `thir` is empty, a type error occurred, skip this body.
|
||||
if thir.exprs.is_empty() {
|
||||
|
|
|
@ -7,6 +7,7 @@ use crate::thir::util::UserAnnotatedTyHelpers;
|
|||
|
||||
use rustc_ast as ast;
|
||||
use rustc_data_structures::steal::Steal;
|
||||
use rustc_errors::ErrorGuaranteed;
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def_id::{DefId, LocalDefId};
|
||||
use rustc_hir::HirId;
|
||||
|
@ -20,22 +21,25 @@ use rustc_span::Span;
|
|||
crate fn thir_body<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
owner_def: ty::WithOptConstParam<LocalDefId>,
|
||||
) -> (&'tcx Steal<Thir<'tcx>>, ExprId) {
|
||||
) -> Result<(&'tcx Steal<Thir<'tcx>>, ExprId), ErrorGuaranteed> {
|
||||
let hir = tcx.hir();
|
||||
let body = hir.body(hir.body_owned_by(hir.local_def_id_to_hir_id(owner_def.did)));
|
||||
let mut cx = Cx::new(tcx, owner_def);
|
||||
if cx.typeck_results.tainted_by_errors.is_some() {
|
||||
return (tcx.alloc_steal_thir(Thir::new()), ExprId::from_u32(0));
|
||||
if let Some(reported) = cx.typeck_results.tainted_by_errors {
|
||||
return Err(reported);
|
||||
}
|
||||
let expr = cx.mirror_expr(&body.value);
|
||||
(tcx.alloc_steal_thir(cx.thir), expr)
|
||||
Ok((tcx.alloc_steal_thir(cx.thir), expr))
|
||||
}
|
||||
|
||||
crate fn thir_tree<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
owner_def: ty::WithOptConstParam<LocalDefId>,
|
||||
) -> String {
|
||||
format!("{:#?}", thir_body(tcx, owner_def).0.steal())
|
||||
match thir_body(tcx, owner_def) {
|
||||
Ok((thir, _)) => format!("{:#?}", thir.steal()),
|
||||
Err(_) => "error".into(),
|
||||
}
|
||||
}
|
||||
|
||||
struct Cx<'tcx> {
|
||||
|
|
|
@ -194,7 +194,9 @@ impl<'a, 'tcx> ConstToPat<'a, 'tcx> {
|
|||
lint::builtin::INDIRECT_STRUCTURAL_MATCH,
|
||||
self.id,
|
||||
self.span,
|
||||
|lint| lint.build(&msg).emit(),
|
||||
|lint| {
|
||||
lint.build(&msg).emit();
|
||||
},
|
||||
);
|
||||
} else {
|
||||
debug!(
|
||||
|
@ -272,7 +274,9 @@ impl<'a, 'tcx> ConstToPat<'a, 'tcx> {
|
|||
lint::builtin::ILLEGAL_FLOATING_POINT_LITERAL_PATTERN,
|
||||
id,
|
||||
span,
|
||||
|lint| lint.build("floating-point types cannot be used in patterns").emit(),
|
||||
|lint| {
|
||||
lint.build("floating-point types cannot be used in patterns").emit();
|
||||
},
|
||||
);
|
||||
}
|
||||
PatKind::Constant { value: cv }
|
||||
|
@ -284,7 +288,7 @@ impl<'a, 'tcx> ConstToPat<'a, 'tcx> {
|
|||
if self.include_lint_checks {
|
||||
tcx.sess.span_err(span, msg);
|
||||
} else {
|
||||
tcx.sess.delay_span_bug(span, msg)
|
||||
tcx.sess.delay_span_bug(span, msg);
|
||||
}
|
||||
PatKind::Wild
|
||||
}
|
||||
|
@ -301,7 +305,7 @@ impl<'a, 'tcx> ConstToPat<'a, 'tcx> {
|
|||
if self.include_lint_checks {
|
||||
tcx.sess.span_err(self.span, &msg);
|
||||
} else {
|
||||
tcx.sess.delay_span_bug(self.span, &msg)
|
||||
tcx.sess.delay_span_bug(self.span, &msg);
|
||||
}
|
||||
PatKind::Wild
|
||||
}
|
||||
|
@ -331,7 +335,7 @@ impl<'a, 'tcx> ConstToPat<'a, 'tcx> {
|
|||
cv.ty(),
|
||||
cv.ty(),
|
||||
);
|
||||
lint.build(&msg).emit()
|
||||
lint.build(&msg).emit();
|
||||
},
|
||||
);
|
||||
}
|
||||
|
@ -356,7 +360,7 @@ impl<'a, 'tcx> ConstToPat<'a, 'tcx> {
|
|||
if self.include_lint_checks {
|
||||
tcx.sess.span_err(span, &msg);
|
||||
} else {
|
||||
tcx.sess.delay_span_bug(span, &msg)
|
||||
tcx.sess.delay_span_bug(span, &msg);
|
||||
}
|
||||
PatKind::Wild
|
||||
}
|
||||
|
@ -393,7 +397,7 @@ impl<'a, 'tcx> ConstToPat<'a, 'tcx> {
|
|||
if self.include_lint_checks {
|
||||
tcx.sess.span_err(span, &msg);
|
||||
} else {
|
||||
tcx.sess.delay_span_bug(span, &msg)
|
||||
tcx.sess.delay_span_bug(span, &msg);
|
||||
}
|
||||
PatKind::Wild
|
||||
}
|
||||
|
@ -471,7 +475,7 @@ impl<'a, 'tcx> ConstToPat<'a, 'tcx> {
|
|||
lint::builtin::INDIRECT_STRUCTURAL_MATCH,
|
||||
self.id,
|
||||
self.span,
|
||||
|lint| lint.build(&msg).emit(),
|
||||
|lint| {lint.build(&msg).emit();},
|
||||
);
|
||||
}
|
||||
PatKind::Constant { value: cv }
|
||||
|
@ -482,7 +486,7 @@ impl<'a, 'tcx> ConstToPat<'a, 'tcx> {
|
|||
if self.include_lint_checks {
|
||||
tcx.sess.span_err(span, &msg);
|
||||
} else {
|
||||
tcx.sess.delay_span_bug(span, &msg)
|
||||
tcx.sess.delay_span_bug(span, &msg);
|
||||
}
|
||||
}
|
||||
PatKind::Wild
|
||||
|
@ -539,7 +543,9 @@ impl<'a, 'tcx> ConstToPat<'a, 'tcx> {
|
|||
lint::builtin::POINTER_STRUCTURAL_MATCH,
|
||||
id,
|
||||
span,
|
||||
|lint| lint.build(&msg).emit(),
|
||||
|lint| {
|
||||
lint.build(&msg).emit();
|
||||
},
|
||||
);
|
||||
}
|
||||
PatKind::Constant { value: cv }
|
||||
|
@ -550,7 +556,7 @@ impl<'a, 'tcx> ConstToPat<'a, 'tcx> {
|
|||
if self.include_lint_checks {
|
||||
tcx.sess.span_err(span, &msg);
|
||||
} else {
|
||||
tcx.sess.delay_span_bug(span, &msg)
|
||||
tcx.sess.delay_span_bug(span, &msg);
|
||||
}
|
||||
PatKind::Wild
|
||||
}
|
||||
|
@ -575,7 +581,9 @@ impl<'a, 'tcx> ConstToPat<'a, 'tcx> {
|
|||
lint::builtin::NONTRIVIAL_STRUCTURAL_MATCH,
|
||||
id,
|
||||
span,
|
||||
|lint| lint.build(&msg).emit(),
|
||||
|lint| {
|
||||
lint.build(&msg).emit();
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue