use rustc_middle::mir::*;
use rustc_middle::ty::cast::CastTy;
use rustc_middle::ty::subst::GenericArgKind;
-use rustc_middle::ty::{
- self, adjustment::PointerCast, Instance, InstanceDef, Ty, TyCtxt, TypeAndMut,
-};
+use rustc_middle::ty::{self, adjustment::PointerCast, Instance, InstanceDef, Ty, TyCtxt};
use rustc_middle::ty::{Binder, TraitPredicate, TraitRef};
use rustc_span::{sym, Span, Symbol};
use rustc_trait_selection::traits::error_reporting::InferCtxtExt;
}
fn check_static(&mut self, def_id: DefId, span: Span) {
- assert!(
- !self.tcx.is_thread_local_static(def_id),
- "tls access is checked in `Rvalue::ThreadLocalRef"
- );
+ if self.tcx.is_thread_local_static(def_id) {
+ self.tcx.sess.delay_span_bug(span, "tls access is checked in `Rvalue::ThreadLocalRef");
+ }
self.check_op_spanned(ops::StaticAccess, span)
}
_,
) => self.check_op(ops::FnPtrCast),
- Rvalue::Cast(CastKind::Pointer(PointerCast::Unsize), _, cast_ty) => {
- if let Some(TypeAndMut { ty, .. }) = cast_ty.builtin_deref(true) {
- let unsized_ty = self.tcx.struct_tail_erasing_lifetimes(ty, self.param_env);
-
- // Casting/coercing things to slices is fine.
- if let ty::Slice(_) | ty::Str = unsized_ty.kind() {
- return;
- }
- }
-
- self.check_op(ops::UnsizingCast);
+ Rvalue::Cast(CastKind::Pointer(PointerCast::Unsize), _, _) => {
+ // Nothing to check here (`check_local_or_return_ty` ensures no trait objects occur
+ // in the type of any local, which also excludes casts).
}
Rvalue::Cast(CastKind::Misc, ref operand, cast_ty) => {
| ProjectionElem::Field(..)
| ProjectionElem::Index(_) => {
let base_ty = Place::ty_from(place_local, proj_base, self.body, self.tcx).ty;
- match base_ty.ty_adt_def() {
- Some(def) if def.is_union() => {
- self.check_op(ops::UnionAccess);
- }
-
- _ => {}
+ if base_ty.is_union() {
+ self.check_op(ops::UnionAccess);
}
}
}