Skip to content

Commit e3426bf

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 e3426bf

17 files changed

+49
-52
lines changed

clippy_lints/src/functions.rs

+2-2
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

+10-10
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

+1-1
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

+1-1
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

+6-8
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

+2-2
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

+5-5
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

+3-4
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

+2-2
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

+3-3
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,

clippy_lints/src/needless_borrowed_ref.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessBorrowedRef {
6262

6363
if_chain! {
6464
// Only lint immutable refs, because `&mut ref T` may be useful.
65-
if let PatKind::Ref(ref sub_pat, Mutability::Immutable) = pat.kind;
65+
if let PatKind::Ref(ref sub_pat, Mutability::Not) = pat.kind;
6666

6767
// Check sub_pat got a `ref` keyword (excluding `ref mut`).
6868
if let PatKind::Binding(BindingAnnotation::Ref, .., spanned_name, _) = sub_pat.kind;

clippy_lints/src/ptr.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ fn check_fn(cx: &LateContext<'_, '_>, decl: &FnDecl, fn_id: HirId, opt_body_id:
151151
let fn_ty = sig.skip_binder();
152152

153153
for (idx, (arg, ty)) in decl.inputs.iter().zip(fn_ty.inputs()).enumerate() {
154-
if let ty::Ref(_, ty, Mutability::Immutable) = ty.kind {
154+
if let ty::Ref(_, ty, Mutability::Not) = ty.kind {
155155
if is_type_diagnostic_item(cx, ty, Symbol::intern("vec_type")) {
156156
let mut ty_snippet = None;
157157
if_chain! {
@@ -255,15 +255,15 @@ fn check_fn(cx: &LateContext<'_, '_>, decl: &FnDecl, fn_id: HirId, opt_body_id:
255255
}
256256

257257
if let FunctionRetTy::Return(ref ty) = decl.output {
258-
if let Some((out, Mutability::Mutable, _)) = get_rptr_lm(ty) {
258+
if let Some((out, Mutability::Mut, _)) = get_rptr_lm(ty) {
259259
let mut immutables = vec![];
260260
for (_, ref mutbl, ref argspan) in decl
261261
.inputs
262262
.iter()
263263
.filter_map(|ty| get_rptr_lm(ty))
264264
.filter(|&(lt, _, _)| lt.name == out.name)
265265
{
266-
if *mutbl == Mutability::Mutable {
266+
if *mutbl == Mutability::Mut {
267267
return;
268268
}
269269
immutables.push(*argspan);

clippy_lints/src/transmute.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute {
385385
),
386386
|db| {
387387
let arg = sugg::Sugg::hir(cx, &args[0], "..");
388-
let (deref, cast) = if mutbl == Mutability::Mutable {
388+
let (deref, cast) = if mutbl == Mutability::Mut {
389389
("&mut *", "*mut")
390390
} else {
391391
("&*", "*const")
@@ -433,7 +433,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute {
433433
if let ty::Uint(ast::UintTy::U8) = slice_ty.kind;
434434
if from_mutbl == to_mutbl;
435435
then {
436-
let postfix = if from_mutbl == Mutability::Mutable {
436+
let postfix = if from_mutbl == Mutability::Mut {
437437
"_mut"
438438
} else {
439439
""
@@ -473,7 +473,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute {
473473
let sugg_paren = arg
474474
.as_ty(cx.tcx.mk_ptr(ty_from_and_mut))
475475
.as_ty(cx.tcx.mk_ptr(ty_to_and_mut));
476-
let sugg = if to_mutbl == Mutability::Mutable {
476+
let sugg = if to_mutbl == Mutability::Mut {
477477
sugg_paren.mut_addr_deref()
478478
} else {
479479
sugg_paren.addr_deref()

clippy_lints/src/trivially_copy_pass_by_ref.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ impl<'a, 'tcx> TriviallyCopyPassByRef {
9898
}
9999

100100
if_chain! {
101-
if let ty::Ref(input_lt, ty, Mutability::Immutable) = ty.kind;
101+
if let ty::Ref(input_lt, ty, Mutability::Not) = ty.kind;
102102
if !output_lts.contains(&input_lt);
103103
if is_copy(cx, ty);
104104
if let Some(size) = cx.layout_of(ty).ok().map(|l| l.size.bytes());

clippy_lints/src/types.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ fn check_ty_rptr(cx: &LateContext<'_, '_>, hir_ty: &hir::Ty, is_local: bool, lt:
395395
} else {
396396
format!("{} ", lt.name.ident().as_str())
397397
};
398-
let mutopt = if mut_ty.mutbl == Mutability::Mutable {
398+
let mutopt = if mut_ty.mutbl == Mutability::Mut {
399399
"mut "
400400
} else {
401401
""
@@ -2387,9 +2387,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for RefToMut {
23872387
if_chain! {
23882388
if let ExprKind::Unary(UnOp::UnDeref, e) = &expr.kind;
23892389
if let ExprKind::Cast(e, t) = &e.kind;
2390-
if let TyKind::Ptr(MutTy { mutbl: Mutability::Mutable, .. }) = t.kind;
2390+
if let TyKind::Ptr(MutTy { mutbl: Mutability::Mut, .. }) = t.kind;
23912391
if let ExprKind::Cast(e, t) = &e.kind;
2392-
if let TyKind::Ptr(MutTy { mutbl: Mutability::Immutable, .. }) = t.kind;
2392+
if let TyKind::Ptr(MutTy { mutbl: Mutability::Not, .. }) = t.kind;
23932393
if let ty::Ref(..) = cx.tables.node_type(e.hir_id).kind;
23942394
then {
23952395
span_lint(

clippy_lints/src/utils/internal_lints.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ impl_lint_pass!(LintWithoutLintPass => [LINT_WITHOUT_LINT_PASS]);
166166

167167
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LintWithoutLintPass {
168168
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) {
169-
if let hir::ItemKind::Static(ref ty, Mutability::Immutable, _) = item.kind {
169+
if let hir::ItemKind::Static(ref ty, Mutability::Not, _) = item.kind {
170170
if is_lint_ref_type(cx, ty) {
171171
self.declared_lints.insert(item.ident.name, item.span);
172172
}
@@ -219,7 +219,7 @@ fn is_lint_ref_type<'tcx>(cx: &LateContext<'_, 'tcx>, ty: &Ty) -> bool {
219219
_,
220220
MutTy {
221221
ty: ref inner,
222-
mutbl: Mutability::Immutable,
222+
mutbl: Mutability::Not,
223223
},
224224
) = ty.kind
225225
{

tests/ui/author/for_loop.stdout

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ if_chain! {
2222
if let ExprKind::Path(ref path2) = func1.kind;
2323
if match_qpath(path2, &["{{root}}", "std", "iter", "Iterator", "next"]);
2424
if args1.len() == 1;
25-
if let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Mutable, ref inner) = args1[0].kind;
25+
if let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Mut, ref inner) = args1[0].kind;
2626
if let ExprKind::Path(ref path3) = inner.kind;
2727
if match_qpath(path3, &["iter"]);
2828
if arms1.len() == 2;

0 commit comments

Comments
 (0)