Skip to content

Commit 7b8e829

Browse files
committed
Auto merge of #4846 - flip1995:rustup, r=Manishearth
Rustup to rustc 1.41.0-nightly (e87a205 2019-11-27) Rustups: - #66671 (Ast address-of) - #64856 (Scope format! temporaries) - http://github.com/rust-lang/rust/pull/66719 changelog: none
2 parents 29777b5 + 40c91ec commit 7b8e829

30 files changed

+99
-84
lines changed

Diff for: clippy_lints/src/bytecount.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,9 @@ fn check_arg(name: Name, arg: Name, needle: &Expr) -> bool {
101101

102102
fn get_path_name(expr: &Expr) -> Option<Name> {
103103
match expr.kind {
104-
ExprKind::Box(ref e) | ExprKind::AddrOf(_, ref e) | ExprKind::Unary(UnOp::UnDeref, ref e) => get_path_name(e),
104+
ExprKind::Box(ref e) | ExprKind::AddrOf(BorrowKind::Ref, _, ref e) | ExprKind::Unary(UnOp::UnDeref, ref e) => {
105+
get_path_name(e)
106+
},
105107
ExprKind::Block(ref b, _) => {
106108
if b.stmts.is_empty() {
107109
b.expr.as_ref().and_then(|p| get_path_name(p))

Diff for: clippy_lints/src/entry.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ fn check_cond<'a, 'tcx, 'b>(
105105
if let ExprKind::MethodCall(ref path, _, ref params) = check.kind;
106106
if params.len() >= 2;
107107
if path.ident.name == sym!(contains_key);
108-
if let ExprKind::AddrOf(_, ref key) = params[1].kind;
108+
if let ExprKind::AddrOf(BorrowKind::Ref, _, ref key) = params[1].kind;
109109
then {
110110
let map = &params[0];
111111
let obj_ty = walk_ptrs_ty(cx.tables.expr_ty(map));

Diff for: clippy_lints/src/eq_op.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp {
8686
// do not suggest to dereference literals
8787
(&ExprKind::Lit(..), _) | (_, &ExprKind::Lit(..)) => {},
8888
// &foo == &bar
89-
(&ExprKind::AddrOf(_, ref l), &ExprKind::AddrOf(_, ref r)) => {
89+
(&ExprKind::AddrOf(BorrowKind::Ref, _, ref l), &ExprKind::AddrOf(BorrowKind::Ref, _, ref r)) => {
9090
let lty = cx.tables.expr_ty(l);
9191
let rty = cx.tables.expr_ty(r);
9292
let lcpy = is_copy(cx, lty);
@@ -143,7 +143,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp {
143143
}
144144
},
145145
// &foo == bar
146-
(&ExprKind::AddrOf(_, ref l), _) => {
146+
(&ExprKind::AddrOf(BorrowKind::Ref, _, ref l), _) => {
147147
let lty = cx.tables.expr_ty(l);
148148
let lcpy = is_copy(cx, lty);
149149
if (requires_ref || lcpy)
@@ -161,7 +161,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp {
161161
}
162162
},
163163
// foo == &bar
164-
(_, &ExprKind::AddrOf(_, ref r)) => {
164+
(_, &ExprKind::AddrOf(BorrowKind::Ref, _, ref r)) => {
165165
let rty = cx.tables.expr_ty(r);
166166
let rcpy = is_copy(cx, rty);
167167
if (requires_ref || rcpy)

Diff for: clippy_lints/src/eval_order_dependence.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ReadVisitor<'a, 'tcx> {
328328
// ```
329329
//
330330
// TODO: fix this
331-
ExprKind::AddrOf(_, _) => {
331+
ExprKind::AddrOf(_, _, _) => {
332332
return;
333333
}
334334
_ => {}

Diff for: clippy_lints/src/explicit_write.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ fn write_output_string(write_args: &HirVec<Expr>) -> Option<String> {
135135
if write_args.len() > 1;
136136
if let ExprKind::Call(_, ref output_args) = write_args[1].kind;
137137
if output_args.len() > 0;
138-
if let ExprKind::AddrOf(_, ref output_string_expr) = output_args[0].kind;
138+
if let ExprKind::AddrOf(BorrowKind::Ref, _, ref output_string_expr) = output_args[0].kind;
139139
if let ExprKind::Array(ref string_exprs) = output_string_expr.kind;
140140
// we only want to provide an automatic suggestion for simple (non-format) strings
141141
if string_exprs.len() == 1;

Diff for: clippy_lints/src/format.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ fn span_useless_format<T: LintContext>(cx: &T, span: Span, help: &str, mut sugg:
7373

7474
fn on_argumentv1_new<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr, arms: &'tcx [Arm]) -> Option<String> {
7575
if_chain! {
76-
if let ExprKind::AddrOf(_, ref format_args) = expr.kind;
76+
if let ExprKind::AddrOf(BorrowKind::Ref, _, ref format_args) = expr.kind;
7777
if let ExprKind::Array(ref elems) = arms[0].body.kind;
7878
if elems.len() == 1;
7979
if let Some(args) = match_function_call(cx, &elems[0], &paths::FMT_ARGUMENTV1_NEW);
@@ -115,13 +115,13 @@ fn on_new_v1<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) -> Option<S
115115
if let Some(args) = match_function_call(cx, expr, &paths::FMT_ARGUMENTS_NEW_V1);
116116
if args.len() == 2;
117117
// Argument 1 in `new_v1()`
118-
if let ExprKind::AddrOf(_, ref arr) = args[0].kind;
118+
if let ExprKind::AddrOf(BorrowKind::Ref, _, ref arr) = args[0].kind;
119119
if let ExprKind::Array(ref pieces) = arr.kind;
120120
if pieces.len() == 1;
121121
if let ExprKind::Lit(ref lit) = pieces[0].kind;
122122
if let LitKind::Str(ref s, _) = lit.node;
123123
// Argument 2 in `new_v1()`
124-
if let ExprKind::AddrOf(_, ref arg1) = args[1].kind;
124+
if let ExprKind::AddrOf(BorrowKind::Ref, _, ref arg1) = args[1].kind;
125125
if let ExprKind::Match(ref matchee, ref arms, MatchSource::Normal) = arg1.kind;
126126
if arms.len() == 1;
127127
if let ExprKind::Tup(ref tup) = matchee.kind;
@@ -143,13 +143,13 @@ fn on_new_v1_fmt<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) -> Opti
143143
if args.len() == 3;
144144
if check_unformatted(&args[2]);
145145
// Argument 1 in `new_v1_formatted()`
146-
if let ExprKind::AddrOf(_, ref arr) = args[0].kind;
146+
if let ExprKind::AddrOf(BorrowKind::Ref, _, ref arr) = args[0].kind;
147147
if let ExprKind::Array(ref pieces) = arr.kind;
148148
if pieces.len() == 1;
149149
if let ExprKind::Lit(ref lit) = pieces[0].kind;
150150
if let LitKind::Str(..) = lit.node;
151151
// Argument 2 in `new_v1_formatted()`
152-
if let ExprKind::AddrOf(_, ref arg1) = args[1].kind;
152+
if let ExprKind::AddrOf(BorrowKind::Ref, _, ref arg1) = args[1].kind;
153153
if let ExprKind::Match(ref matchee, ref arms, MatchSource::Normal) = arg1.kind;
154154
if arms.len() == 1;
155155
if let ExprKind::Tup(ref tup) = matchee.kind;
@@ -173,7 +173,7 @@ fn on_new_v1_fmt<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) -> Opti
173173
/// ```
174174
fn check_unformatted(expr: &Expr) -> bool {
175175
if_chain! {
176-
if let ExprKind::AddrOf(_, ref expr) = expr.kind;
176+
if let ExprKind::AddrOf(BorrowKind::Ref, _, ref expr) = expr.kind;
177177
if let ExprKind::Array(ref exprs) = expr.kind;
178178
if exprs.len() == 1;
179179
// struct `core::fmt::rt::v1::Argument`

Diff for: clippy_lints/src/functions.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,7 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for StaticMutVisitor<'a, 'tcx> {
656656
tys.clear();
657657
}
658658
},
659-
Assign(ref target, _) | AssignOp(_, ref target, _) | AddrOf(hir::Mutability::Mutable, ref target) => {
659+
Assign(ref target, _) | AssignOp(_, ref target, _) | AddrOf(_, hir::Mutability::Mutable, ref target) => {
660660
self.mutates_static |= is_mutated_static(self.cx, target)
661661
},
662662
_ => {},

Diff for: clippy_lints/src/infinite_iter.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ fn is_infinite(cx: &LateContext<'_, '_>, expr: &Expr) -> Finiteness {
163163
Finite
164164
},
165165
ExprKind::Block(ref block, _) => block.expr.as_ref().map_or(Finite, |e| is_infinite(cx, e)),
166-
ExprKind::Box(ref e) | ExprKind::AddrOf(_, ref e) => is_infinite(cx, e),
166+
ExprKind::Box(ref e) | ExprKind::AddrOf(BorrowKind::Ref, _, ref e) => is_infinite(cx, e),
167167
ExprKind::Call(ref path, _) => {
168168
if let ExprKind::Path(ref qpath) = path.kind {
169169
match_qpath(qpath, &paths::REPEAT).into()

Diff for: clippy_lints/src/loops.rs

+11-7
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,7 @@ fn never_loop_expr(expr: &Expr, main_loop_id: HirId) -> NeverLoopResult {
674674
| ExprKind::Cast(ref e, _)
675675
| ExprKind::Type(ref e, _)
676676
| ExprKind::Field(ref e, _)
677-
| ExprKind::AddrOf(_, ref e)
677+
| ExprKind::AddrOf(_, _, ref e)
678678
| ExprKind::Struct(_, _, Some(ref e))
679679
| ExprKind::Repeat(ref e, _)
680680
| ExprKind::DropTemps(ref e) => never_loop_expr(e, main_loop_id),
@@ -1504,7 +1504,9 @@ fn make_iterator_snippet(cx: &LateContext<'_, '_>, arg: &Expr, applic_ref: &mut
15041504
// (&x).into_iter() ==> x.iter()
15051505
// (&mut x).into_iter() ==> x.iter_mut()
15061506
match &arg.kind {
1507-
ExprKind::AddrOf(mutability, arg_inner) if has_iter_method(cx, cx.tables.expr_ty(&arg_inner)).is_some() => {
1507+
ExprKind::AddrOf(BorrowKind::Ref, mutability, arg_inner)
1508+
if has_iter_method(cx, cx.tables.expr_ty(&arg_inner)).is_some() =>
1509+
{
15081510
let meth_name = match mutability {
15091511
Mutability::Mutable => "iter_mut",
15101512
Mutability::Immutable => "iter",
@@ -1514,7 +1516,7 @@ fn make_iterator_snippet(cx: &LateContext<'_, '_>, arg: &Expr, applic_ref: &mut
15141516
sugg::Sugg::hir_with_applicability(cx, &arg_inner, "_", applic_ref).maybe_par(),
15151517
meth_name,
15161518
)
1517-
},
1519+
}
15181520
_ => format!(
15191521
"{}.into_iter()",
15201522
sugg::Sugg::hir_with_applicability(cx, arg, "_", applic_ref).maybe_par()
@@ -1549,7 +1551,7 @@ fn check_for_loop_over_map_kv<'a, 'tcx>(
15491551
Mutability::Mutable => "_mut",
15501552
};
15511553
let arg = match arg.kind {
1552-
ExprKind::AddrOf(_, ref expr) => &**expr,
1554+
ExprKind::AddrOf(BorrowKind::Ref, _, ref expr) => &**expr,
15531555
_ => arg,
15541556
};
15551557

@@ -1873,7 +1875,7 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> {
18731875
self.prefer_mutable = false;
18741876
self.visit_expr(rhs);
18751877
},
1876-
ExprKind::AddrOf(mutbl, ref expr) => {
1878+
ExprKind::AddrOf(BorrowKind::Ref, mutbl, ref expr) => {
18771879
if mutbl == Mutability::Mutable {
18781880
self.prefer_mutable = true;
18791881
}
@@ -2090,7 +2092,9 @@ impl<'a, 'tcx> Visitor<'tcx> for IncrementVisitor<'a, 'tcx> {
20902092
}
20912093
},
20922094
ExprKind::Assign(ref lhs, _) if lhs.hir_id == expr.hir_id => *state = VarState::DontWarn,
2093-
ExprKind::AddrOf(mutability, _) if mutability == Mutability::Mutable => *state = VarState::DontWarn,
2095+
ExprKind::AddrOf(BorrowKind::Ref, mutability, _) if mutability == Mutability::Mutable => {
2096+
*state = VarState::DontWarn
2097+
},
20942098
_ => (),
20952099
}
20962100
}
@@ -2172,7 +2176,7 @@ impl<'a, 'tcx> Visitor<'tcx> for InitializeVisitor<'a, 'tcx> {
21722176
VarState::DontWarn
21732177
}
21742178
},
2175-
ExprKind::AddrOf(mutability, _) if mutability == Mutability::Mutable => {
2179+
ExprKind::AddrOf(BorrowKind::Ref, mutability, _) if mutability == Mutability::Mutable => {
21762180
self.state = VarState::DontWarn
21772181
},
21782182
_ => (),

Diff for: clippy_lints/src/matches.rs

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

Diff for: clippy_lints/src/mem_discriminant.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::utils::{match_def_path, paths, snippet, span_lint_and_then, walk_ptrs_ty_depth};
22
use if_chain::if_chain;
3-
use rustc::hir::{Expr, ExprKind};
3+
use rustc::hir::{BorrowKind, Expr, ExprKind};
44
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
55
use rustc::{declare_lint_pass, declare_tool_lint};
66
use rustc_errors::Applicability;
@@ -57,7 +57,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MemDiscriminant {
5757
let mut derefs_needed = ptr_depth;
5858
let mut cur_expr = param;
5959
while derefs_needed > 0 {
60-
if let ExprKind::AddrOf(_, ref inner_expr) = cur_expr.kind {
60+
if let ExprKind::AddrOf(BorrowKind::Ref, _, ref inner_expr) = cur_expr.kind {
6161
derefs_needed -= 1;
6262
cur_expr = inner_expr;
6363
} else {

Diff for: clippy_lints/src/mem_replace.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::utils::{
22
match_def_path, match_qpath, paths, snippet_with_applicability, span_help_and_lint, span_lint_and_sugg,
33
};
44
use if_chain::if_chain;
5-
use rustc::hir::{Expr, ExprKind, Mutability, QPath};
5+
use rustc::hir::{BorrowKind, Expr, ExprKind, Mutability, QPath};
66
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
77
use rustc::{declare_lint_pass, declare_tool_lint};
88
use rustc_errors::Applicability;
@@ -90,7 +90,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MemReplace {
9090
// argument's type. All that's left is to get
9191
// replacee's path.
9292
let replaced_path = match func_args[0].kind {
93-
ExprKind::AddrOf(Mutability::Mutable, ref replaced) => {
93+
ExprKind::AddrOf(BorrowKind::Ref, Mutability::Mutable, ref replaced) => {
9494
if let ExprKind::Path(QPath::Resolved(None, ref replaced_path)) = replaced.kind {
9595
replaced_path
9696
} else {

Diff for: clippy_lints/src/methods/mod.rs

+27-22
Original file line numberDiff line numberDiff line change
@@ -1519,7 +1519,7 @@ fn lint_expect_fun_call(cx: &LateContext<'_, '_>, expr: &hir::Expr, method_span:
15191519
let mut arg_root = arg;
15201520
loop {
15211521
arg_root = match &arg_root.kind {
1522-
hir::ExprKind::AddrOf(_, expr) => expr,
1522+
hir::ExprKind::AddrOf(hir::BorrowKind::Ref, _, expr) => expr,
15231523
hir::ExprKind::MethodCall(method_name, _, call_args) => {
15241524
if call_args.len() == 1
15251525
&& (method_name.ident.name == sym!(as_str) || method_name.ident.name == sym!(as_ref))
@@ -1561,7 +1561,7 @@ fn lint_expect_fun_call(cx: &LateContext<'_, '_>, expr: &hir::Expr, method_span:
15611561
applicability: &mut Applicability,
15621562
) -> Vec<String> {
15631563
if_chain! {
1564-
if let hir::ExprKind::AddrOf(_, ref format_arg) = a.kind;
1564+
if let hir::ExprKind::AddrOf(hir::BorrowKind::Ref, _, ref format_arg) = a.kind;
15651565
if let hir::ExprKind::Match(ref format_arg_expr, _, _) = format_arg.kind;
15661566
if let hir::ExprKind::Tup(ref format_arg_expr_tup) = format_arg_expr.kind;
15671567

@@ -1578,7 +1578,7 @@ fn lint_expect_fun_call(cx: &LateContext<'_, '_>, expr: &hir::Expr, method_span:
15781578

15791579
fn is_call(node: &hir::ExprKind) -> bool {
15801580
match node {
1581-
hir::ExprKind::AddrOf(_, expr) => {
1581+
hir::ExprKind::AddrOf(hir::BorrowKind::Ref, _, expr) => {
15821582
is_call(&expr.kind)
15831583
},
15841584
hir::ExprKind::Call(..)
@@ -1610,30 +1610,35 @@ fn lint_expect_fun_call(cx: &LateContext<'_, '_>, expr: &hir::Expr, method_span:
16101610
let mut applicability = Applicability::MachineApplicable;
16111611

16121612
//Special handling for `format!` as arg_root
1613-
if let hir::ExprKind::Call(ref inner_fun, ref inner_args) = arg_root.kind {
1614-
if is_expn_of(inner_fun.span, "format").is_some() && inner_args.len() == 1 {
1615-
if let hir::ExprKind::Call(_, format_args) = &inner_args[0].kind {
1616-
let fmt_spec = &format_args[0];
1617-
let fmt_args = &format_args[1];
1613+
if_chain! {
1614+
if let hir::ExprKind::Block(block, None) = &arg_root.kind;
1615+
if block.stmts.len() == 1;
1616+
if let hir::StmtKind::Local(local) = &block.stmts[0].kind;
1617+
if let Some(arg_root) = &local.init;
1618+
if let hir::ExprKind::Call(ref inner_fun, ref inner_args) = arg_root.kind;
1619+
if is_expn_of(inner_fun.span, "format").is_some() && inner_args.len() == 1;
1620+
if let hir::ExprKind::Call(_, format_args) = &inner_args[0].kind;
1621+
then {
1622+
let fmt_spec = &format_args[0];
1623+
let fmt_args = &format_args[1];
16181624

1619-
let mut args = vec![snippet(cx, fmt_spec.span, "..").into_owned()];
1625+
let mut args = vec![snippet(cx, fmt_spec.span, "..").into_owned()];
16201626

1621-
args.extend(generate_format_arg_snippet(cx, fmt_args, &mut applicability));
1627+
args.extend(generate_format_arg_snippet(cx, fmt_args, &mut applicability));
16221628

1623-
let sugg = args.join(", ");
1629+
let sugg = args.join(", ");
16241630

1625-
span_lint_and_sugg(
1626-
cx,
1627-
EXPECT_FUN_CALL,
1628-
span_replace_word,
1629-
&format!("use of `{}` followed by a function call", name),
1630-
"try this",
1631-
format!("unwrap_or_else({} panic!({}))", closure_args, sugg),
1632-
applicability,
1633-
);
1631+
span_lint_and_sugg(
1632+
cx,
1633+
EXPECT_FUN_CALL,
1634+
span_replace_word,
1635+
&format!("use of `{}` followed by a function call", name),
1636+
"try this",
1637+
format!("unwrap_or_else({} panic!({}))", closure_args, sugg),
1638+
applicability,
1639+
);
16341640

1635-
return;
1636-
}
1641+
return;
16371642
}
16381643
}
16391644

Diff for: clippy_lints/src/mut_mut.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for MutVisitor<'a, 'tcx> {
5757
// Let's ignore the generated code.
5858
intravisit::walk_expr(self, arg);
5959
intravisit::walk_expr(self, body);
60-
} else if let hir::ExprKind::AddrOf(hir::Mutability::Mutable, ref e) = expr.kind {
61-
if let hir::ExprKind::AddrOf(hir::Mutability::Mutable, _) = e.kind {
60+
} else if let hir::ExprKind::AddrOf(hir::BorrowKind::Ref, hir::Mutability::Mutable, ref e) = expr.kind {
61+
if let hir::ExprKind::AddrOf(hir::BorrowKind::Ref, hir::Mutability::Mutable, _) = e.kind {
6262
span_lint(
6363
self.cx,
6464
MUT_MUT,

Diff for: clippy_lints/src/mut_reference.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ fn check_arguments<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, arguments: &[Expr], typ
6060
mutbl: Mutability::Immutable,
6161
..
6262
}) => {
63-
if let ExprKind::AddrOf(Mutability::Mutable, _) = argument.kind {
63+
if let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Mutable, _) = argument.kind {
6464
span_lint(
6565
cx,
6666
UNNECESSARY_MUT_PASSED,

0 commit comments

Comments
 (0)