Depend on Mutability
ordering
This commit is contained in:
parent
8195e12dd9
commit
9b9c7d0ecc
@ -370,7 +370,7 @@ pub fn coerce_unsized_info<'tcx>(tcx: TyCtxt<'tcx>, impl_did: DefId) -> CoerceUn
|
||||
let check_mutbl = |mt_a: ty::TypeAndMut<'tcx>,
|
||||
mt_b: ty::TypeAndMut<'tcx>,
|
||||
mk_ptr: &dyn Fn(Ty<'tcx>) -> Ty<'tcx>| {
|
||||
if (mt_a.mutbl, mt_b.mutbl) == (hir::Mutability::Not, hir::Mutability::Mut) {
|
||||
if mt_a.mutbl < mt_b.mutbl {
|
||||
infcx
|
||||
.err_ctxt()
|
||||
.report_mismatched_types(
|
||||
|
@ -572,8 +572,5 @@ pub(crate) fn opt_suggest_box_span(
|
||||
}
|
||||
|
||||
fn arms_contain_ref_bindings<'tcx>(arms: &'tcx [hir::Arm<'tcx>]) -> Option<hir::Mutability> {
|
||||
arms.iter().filter_map(|a| a.pat.contains_explicit_ref_binding()).max_by_key(|m| match *m {
|
||||
hir::Mutability::Mut => 1,
|
||||
hir::Mutability::Not => 0,
|
||||
})
|
||||
arms.iter().filter_map(|a| a.pat.contains_explicit_ref_binding()).max()
|
||||
}
|
||||
|
@ -951,7 +951,7 @@ fn check_ref_cast(
|
||||
m_cast: ty::TypeAndMut<'tcx>,
|
||||
) -> Result<CastKind, CastError> {
|
||||
// array-ptr-cast: allow mut-to-mut, mut-to-const, const-to-const
|
||||
if m_expr.mutbl == hir::Mutability::Mut || m_cast.mutbl == hir::Mutability::Not {
|
||||
if m_expr.mutbl >= m_cast.mutbl {
|
||||
if let ty::Array(ety, _) = m_expr.ty.kind() {
|
||||
// Due to the limitations of LLVM global constants,
|
||||
// region pointers end up pointing at copies of
|
||||
|
@ -108,11 +108,7 @@ fn coerce_mutbls<'tcx>(
|
||||
from_mutbl: hir::Mutability,
|
||||
to_mutbl: hir::Mutability,
|
||||
) -> RelateResult<'tcx, ()> {
|
||||
match (from_mutbl, to_mutbl) {
|
||||
(hir::Mutability::Mut, hir::Mutability::Mut | hir::Mutability::Not)
|
||||
| (hir::Mutability::Not, hir::Mutability::Not) => Ok(()),
|
||||
(hir::Mutability::Not, hir::Mutability::Mut) => Err(TypeError::Mutability),
|
||||
}
|
||||
if from_mutbl >= to_mutbl { Ok(()) } else { Err(TypeError::Mutability) }
|
||||
}
|
||||
|
||||
/// Do not require any adjustments, i.e. coerce `x -> x`.
|
||||
|
@ -1268,10 +1268,10 @@ fn check_item(&mut self, cx: &LateContext<'_>, it: &hir::Item<'_>) {
|
||||
|
||||
impl<'tcx> LateLintPass<'tcx> for MutableTransmutes {
|
||||
fn check_expr(&mut self, cx: &LateContext<'_>, expr: &hir::Expr<'_>) {
|
||||
if let Some((&ty::Ref(_, _, from_mt), &ty::Ref(_, _, to_mt))) =
|
||||
if let Some((&ty::Ref(_, _, from_mutbl), &ty::Ref(_, _, to_mutbl))) =
|
||||
get_transmute_from_to(cx, expr).map(|(ty1, ty2)| (ty1.kind(), ty2.kind()))
|
||||
{
|
||||
if to_mt == hir::Mutability::Mut && from_mt == hir::Mutability::Not {
|
||||
if from_mutbl < to_mutbl {
|
||||
cx.struct_span_lint(
|
||||
MUTABLE_TRANSMUTES,
|
||||
expr.span,
|
||||
|
Loading…
Reference in New Issue
Block a user