Skip to content

Commit cfb3320

Browse files
committed
Auto merge of #4932 - lzutao:rustup-67355, r=matthiaskrgr
rustup "Merge `ast::Mutability` and `mir::Mutability`" cc rust-lang/rust#67355 changelog: none
2 parents 961c1a5 + d1ca5f1 commit cfb3320

17 files changed

+49
-52
lines changed

clippy_lints/src/functions.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ fn is_mutable_ty<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: Ty<'tcx>, span: Span,
553553
Tuple(ref substs) => substs.types().any(|ty| is_mutable_ty(cx, ty, span, tys)),
554554
Array(ty, _) | Slice(ty) => is_mutable_ty(cx, ty, span, tys),
555555
RawPtr(ty::TypeAndMut { ty, mutbl }) | Ref(_, ty, mutbl) => {
556-
mutbl == hir::Mutability::Mutable || is_mutable_ty(cx, ty, span, tys)
556+
mutbl == hir::Mutability::Mut || is_mutable_ty(cx, ty, span, tys)
557557
},
558558
// calling something constitutes a side effect, so return true on all callables
559559
// also never calls need not be used, so return true for them, too
@@ -658,7 +658,7 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for StaticMutVisitor<'a, 'tcx> {
658658
tys.clear();
659659
}
660660
},
661-
Assign(ref target, _) | AssignOp(_, ref target, _) | AddrOf(_, hir::Mutability::Mutable, ref target) => {
661+
Assign(ref target, _) | AssignOp(_, ref target, _) | AddrOf(_, hir::Mutability::Mut, ref target) => {
662662
self.mutates_static |= is_mutated_static(self.cx, target)
663663
},
664664
_ => {},

clippy_lints/src/loops.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1507,8 +1507,8 @@ fn make_iterator_snippet(cx: &LateContext<'_, '_>, arg: &Expr, applic_ref: &mut
15071507
if has_iter_method(cx, cx.tables.expr_ty(&arg_inner)).is_some() =>
15081508
{
15091509
let meth_name = match mutability {
1510-
Mutability::Mutable => "iter_mut",
1511-
Mutability::Immutable => "iter",
1510+
Mutability::Mut => "iter_mut",
1511+
Mutability::Not => "iter",
15121512
};
15131513
format!(
15141514
"{}.{}()",
@@ -1540,14 +1540,14 @@ fn check_for_loop_over_map_kv<'a, 'tcx>(
15401540
let (new_pat_span, kind, ty, mutbl) = match cx.tables.expr_ty(arg).kind {
15411541
ty::Ref(_, ty, mutbl) => match (&pat[0].kind, &pat[1].kind) {
15421542
(key, _) if pat_is_wild(key, body) => (pat[1].span, "value", ty, mutbl),
1543-
(_, value) if pat_is_wild(value, body) => (pat[0].span, "key", ty, Mutability::Immutable),
1543+
(_, value) if pat_is_wild(value, body) => (pat[0].span, "key", ty, Mutability::Not),
15441544
_ => return,
15451545
},
15461546
_ => return,
15471547
};
15481548
let mutbl = match mutbl {
1549-
Mutability::Immutable => "",
1550-
Mutability::Mutable => "_mut",
1549+
Mutability::Not => "",
1550+
Mutability::Mut => "_mut",
15511551
};
15521552
let arg = match arg.kind {
15531553
ExprKind::AddrOf(BorrowKind::Ref, _, ref expr) => &**expr,
@@ -1868,7 +1868,7 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> {
18681868
self.visit_expr(rhs);
18691869
},
18701870
ExprKind::AddrOf(BorrowKind::Ref, mutbl, ref expr) => {
1871-
if mutbl == Mutability::Mutable {
1871+
if mutbl == Mutability::Mut {
18721872
self.prefer_mutable = true;
18731873
}
18741874
self.visit_expr(expr);
@@ -1879,7 +1879,7 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> {
18791879
let ty = self.cx.tables.expr_ty_adjusted(expr);
18801880
self.prefer_mutable = false;
18811881
if let ty::Ref(_, _, mutbl) = ty.kind {
1882-
if mutbl == Mutability::Mutable {
1882+
if mutbl == Mutability::Mut {
18831883
self.prefer_mutable = true;
18841884
}
18851885
}
@@ -1891,7 +1891,7 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> {
18911891
for (ty, expr) in self.cx.tcx.fn_sig(def_id).inputs().skip_binder().iter().zip(args) {
18921892
self.prefer_mutable = false;
18931893
if let ty::Ref(_, _, mutbl) = ty.kind {
1894-
if mutbl == Mutability::Mutable {
1894+
if mutbl == Mutability::Mut {
18951895
self.prefer_mutable = true;
18961896
}
18971897
}
@@ -2084,7 +2084,7 @@ impl<'a, 'tcx> Visitor<'tcx> for IncrementVisitor<'a, 'tcx> {
20842084
}
20852085
},
20862086
ExprKind::Assign(ref lhs, _) if lhs.hir_id == expr.hir_id => *state = VarState::DontWarn,
2087-
ExprKind::AddrOf(BorrowKind::Ref, mutability, _) if mutability == Mutability::Mutable => {
2087+
ExprKind::AddrOf(BorrowKind::Ref, mutability, _) if mutability == Mutability::Mut => {
20882088
*state = VarState::DontWarn
20892089
},
20902090
_ => (),
@@ -2168,7 +2168,7 @@ impl<'a, 'tcx> Visitor<'tcx> for InitializeVisitor<'a, 'tcx> {
21682168
VarState::DontWarn
21692169
}
21702170
},
2171-
ExprKind::AddrOf(BorrowKind::Ref, mutability, _) if mutability == Mutability::Mutable => {
2171+
ExprKind::AddrOf(BorrowKind::Ref, mutability, _) if mutability == Mutability::Mut => {
21722172
self.state = VarState::DontWarn
21732173
},
21742174
_ => (),

clippy_lints/src/matches.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ fn is_panic_block(block: &Block) -> bool {
571571
fn check_match_ref_pats(cx: &LateContext<'_, '_>, ex: &Expr, arms: &[Arm], expr: &Expr) {
572572
if has_only_ref_pats(arms) {
573573
let mut suggs = Vec::new();
574-
let (title, msg) = if let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Immutable, ref inner) = ex.kind {
574+
let (title, msg) = if let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Not, ref inner) = ex.kind {
575575
let span = ex.span.source_callsite();
576576
suggs.push((span, Sugg::hir_with_macro_callsite(cx, inner, "..").to_string()));
577577
(

clippy_lints/src/mem_replace.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MemReplace {
9191
// argument's type. All that's left is to get
9292
// replacee's path.
9393
let replaced_path = match func_args[0].kind {
94-
ExprKind::AddrOf(BorrowKind::Ref, Mutability::Mutable, ref replaced) => {
94+
ExprKind::AddrOf(BorrowKind::Ref, Mutability::Mut, ref replaced) => {
9595
if let ExprKind::Path(QPath::Resolved(None, ref replaced_path)) = replaced.kind {
9696
replaced_path
9797
} else {

clippy_lints/src/methods/mod.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2824,8 +2824,8 @@ fn ty_has_iter_method(cx: &LateContext<'_, '_>, self_ref_ty: Ty<'_>) -> Option<(
28242824
_ => unreachable!(),
28252825
};
28262826
let method_name = match mutbl {
2827-
hir::Mutability::Immutable => "iter",
2828-
hir::Mutability::Mutable => "iter_mut",
2827+
hir::Mutability::Not => "iter",
2828+
hir::Mutability::Mut => "iter_mut",
28292829
};
28302830
(ty_name, method_name)
28312831
})
@@ -3015,8 +3015,8 @@ impl SelfKind {
30153015
}
30163016

30173017
let trait_path = match mutability {
3018-
hir::Mutability::Immutable => &paths::ASREF_TRAIT,
3019-
hir::Mutability::Mutable => &paths::ASMUT_TRAIT,
3018+
hir::Mutability::Not => &paths::ASREF_TRAIT,
3019+
hir::Mutability::Mut => &paths::ASMUT_TRAIT,
30203020
};
30213021

30223022
let trait_def_id = match get_trait_def_id(cx, trait_path) {
@@ -3028,10 +3028,8 @@ impl SelfKind {
30283028

30293029
match self {
30303030
Self::Value => matches_value(parent_ty, ty),
3031-
Self::Ref => {
3032-
matches_ref(cx, hir::Mutability::Immutable, parent_ty, ty) || ty == parent_ty && is_copy(cx, ty)
3033-
},
3034-
Self::RefMut => matches_ref(cx, hir::Mutability::Mutable, parent_ty, ty),
3031+
Self::Ref => matches_ref(cx, hir::Mutability::Not, parent_ty, ty) || ty == parent_ty && is_copy(cx, ty),
3032+
Self::RefMut => matches_ref(cx, hir::Mutability::Mut, parent_ty, ty),
30353033
Self::No => ty != parent_ty,
30363034
}
30373035
}

clippy_lints/src/misc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -632,8 +632,8 @@ fn check_cast(cx: &LateContext<'_, '_>, span: Span, e: &Expr, ty: &Ty) {
632632
if !in_constant(cx, e.hir_id);
633633
then {
634634
let (msg, sugg_fn) = match mut_ty.mutbl {
635-
Mutability::Mutable => ("`0 as *mut _` detected", "std::ptr::null_mut"),
636-
Mutability::Immutable => ("`0 as *const _` detected", "std::ptr::null"),
635+
Mutability::Mut => ("`0 as *mut _` detected", "std::ptr::null_mut"),
636+
Mutability::Not => ("`0 as *const _` detected", "std::ptr::null"),
637637
};
638638

639639
let (sugg, appl) = if let TyKind::Infer = mut_ty.ty.kind {

clippy_lints/src/mut_mut.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,15 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for MutVisitor<'a, 'tcx> {
5858
// Let's ignore the generated code.
5959
intravisit::walk_expr(self, arg);
6060
intravisit::walk_expr(self, body);
61-
} else if let hir::ExprKind::AddrOf(hir::BorrowKind::Ref, hir::Mutability::Mutable, ref e) = expr.kind {
62-
if let hir::ExprKind::AddrOf(hir::BorrowKind::Ref, hir::Mutability::Mutable, _) = e.kind {
61+
} else if let hir::ExprKind::AddrOf(hir::BorrowKind::Ref, hir::Mutability::Mut, ref e) = expr.kind {
62+
if let hir::ExprKind::AddrOf(hir::BorrowKind::Ref, hir::Mutability::Mut, _) = e.kind {
6363
span_lint(
6464
self.cx,
6565
MUT_MUT,
6666
expr.span,
6767
"generally you want to avoid `&mut &mut _` if possible",
6868
);
69-
} else if let ty::Ref(_, _, hir::Mutability::Mutable) = self.cx.tables.expr_ty(e).kind {
69+
} else if let ty::Ref(_, _, hir::Mutability::Mut) = self.cx.tables.expr_ty(e).kind {
7070
span_lint(
7171
self.cx,
7272
MUT_MUT,
@@ -82,14 +82,14 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for MutVisitor<'a, 'tcx> {
8282
_,
8383
hir::MutTy {
8484
ty: ref pty,
85-
mutbl: hir::Mutability::Mutable,
85+
mutbl: hir::Mutability::Mut,
8686
},
8787
) = ty.kind
8888
{
8989
if let hir::TyKind::Rptr(
9090
_,
9191
hir::MutTy {
92-
mutbl: hir::Mutability::Mutable,
92+
mutbl: hir::Mutability::Mut,
9393
..
9494
},
9595
) = pty.kind

clippy_lints/src/mut_reference.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,11 @@ fn check_arguments<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, arguments: &[Expr], typ
5656
let parameters = type_definition.fn_sig(cx.tcx).skip_binder().inputs();
5757
for (argument, parameter) in arguments.iter().zip(parameters.iter()) {
5858
match parameter.kind {
59-
ty::Ref(_, _, Mutability::Immutable)
59+
ty::Ref(_, _, Mutability::Not)
6060
| ty::RawPtr(ty::TypeAndMut {
61-
mutbl: Mutability::Immutable,
62-
..
61+
mutbl: Mutability::Not, ..
6362
}) => {
64-
if let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Mutable, _) = argument.kind {
63+
if let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Mut, _) = argument.kind {
6564
span_lint(
6665
cx,
6766
UNNECESSARY_MUT_PASSED,

clippy_lints/src/mutable_debug_assertion.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,15 +129,15 @@ impl<'a, 'tcx> MutArgVisitor<'a, 'tcx> {
129129
impl<'a, 'tcx> Visitor<'tcx> for MutArgVisitor<'a, 'tcx> {
130130
fn visit_expr(&mut self, expr: &'tcx Expr) {
131131
match expr.kind {
132-
ExprKind::AddrOf(BorrowKind::Ref, Mutability::Mutable, _) => {
132+
ExprKind::AddrOf(BorrowKind::Ref, Mutability::Mut, _) => {
133133
self.found = true;
134134
return;
135135
},
136136
ExprKind::Path(_) => {
137137
if let Some(adj) = self.cx.tables.adjustments().get(expr.hir_id) {
138138
if adj
139139
.iter()
140-
.any(|a| matches!(a.target.kind, ty::Ref(_, _, Mutability::Mutable)))
140+
.any(|a| matches!(a.target.kind, ty::Ref(_, _, Mutability::Mut)))
141141
{
142142
self.found = true;
143143
return;

clippy_lints/src/needless_borrow.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessBorrow {
4242
if e.span.from_expansion() || self.derived_item.is_some() {
4343
return;
4444
}
45-
if let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Immutable, ref inner) = e.kind {
45+
if let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Not, ref inner) = e.kind {
4646
if let ty::Ref(..) = cx.tables.expr_ty(inner).kind {
4747
for adj3 in cx.tables.expr_adjustments(e).windows(3) {
4848
if let [Adjustment {
@@ -83,10 +83,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessBorrow {
8383
if_chain! {
8484
if let PatKind::Binding(BindingAnnotation::Ref, .., name, _) = pat.kind;
8585
if let ty::Ref(_, tam, mutbl) = cx.tables.pat_ty(pat).kind;
86-
if mutbl == Mutability::Immutable;
86+
if mutbl == Mutability::Not;
8787
if let ty::Ref(_, _, mutbl) = tam.kind;
8888
// only lint immutable refs, because borrowed `&mut T` cannot be moved out
89-
if mutbl == Mutability::Immutable;
89+
if mutbl == Mutability::Not;
9090
then {
9191
span_lint_and_then(
9292
cx,

0 commit comments

Comments
 (0)