Depend on Mutability
ordering
This commit is contained in:
parent
8195e12dd9
commit
9b9c7d0ecc
5 changed files with 6 additions and 13 deletions
|
@ -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>,
|
let check_mutbl = |mt_a: ty::TypeAndMut<'tcx>,
|
||||||
mt_b: ty::TypeAndMut<'tcx>,
|
mt_b: ty::TypeAndMut<'tcx>,
|
||||||
mk_ptr: &dyn Fn(Ty<'tcx>) -> Ty<'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
|
infcx
|
||||||
.err_ctxt()
|
.err_ctxt()
|
||||||
.report_mismatched_types(
|
.report_mismatched_types(
|
||||||
|
|
|
@ -572,8 +572,5 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn arms_contain_ref_bindings<'tcx>(arms: &'tcx [hir::Arm<'tcx>]) -> Option<hir::Mutability> {
|
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 {
|
arms.iter().filter_map(|a| a.pat.contains_explicit_ref_binding()).max()
|
||||||
hir::Mutability::Mut => 1,
|
|
||||||
hir::Mutability::Not => 0,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -951,7 +951,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
|
||||||
m_cast: ty::TypeAndMut<'tcx>,
|
m_cast: ty::TypeAndMut<'tcx>,
|
||||||
) -> Result<CastKind, CastError> {
|
) -> Result<CastKind, CastError> {
|
||||||
// array-ptr-cast: allow mut-to-mut, mut-to-const, const-to-const
|
// 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() {
|
if let ty::Array(ety, _) = m_expr.ty.kind() {
|
||||||
// Due to the limitations of LLVM global constants,
|
// Due to the limitations of LLVM global constants,
|
||||||
// region pointers end up pointing at copies of
|
// region pointers end up pointing at copies of
|
||||||
|
|
|
@ -108,11 +108,7 @@ fn coerce_mutbls<'tcx>(
|
||||||
from_mutbl: hir::Mutability,
|
from_mutbl: hir::Mutability,
|
||||||
to_mutbl: hir::Mutability,
|
to_mutbl: hir::Mutability,
|
||||||
) -> RelateResult<'tcx, ()> {
|
) -> RelateResult<'tcx, ()> {
|
||||||
match (from_mutbl, to_mutbl) {
|
if from_mutbl >= to_mutbl { Ok(()) } else { Err(TypeError::Mutability) }
|
||||||
(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),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Do not require any adjustments, i.e. coerce `x -> x`.
|
/// Do not require any adjustments, i.e. coerce `x -> x`.
|
||||||
|
|
|
@ -1268,10 +1268,10 @@ declare_lint_pass!(MutableTransmutes => [MUTABLE_TRANSMUTES]);
|
||||||
|
|
||||||
impl<'tcx> LateLintPass<'tcx> for MutableTransmutes {
|
impl<'tcx> LateLintPass<'tcx> for MutableTransmutes {
|
||||||
fn check_expr(&mut self, cx: &LateContext<'_>, expr: &hir::Expr<'_>) {
|
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()))
|
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(
|
cx.struct_span_lint(
|
||||||
MUTABLE_TRANSMUTES,
|
MUTABLE_TRANSMUTES,
|
||||||
expr.span,
|
expr.span,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue