Skip to content

Commit 8dd1bce

Browse files
committed
Auto merge of rust-lang#7994 - flip1995:rustup, r=flip1995
Rustup r? `@ghost` changelog: none
2 parents 8536647 + 4bccd59 commit 8dd1bce

40 files changed

+262
-139
lines changed

clippy_lints/src/doc.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use clippy_utils::ty::{implements_trait, is_type_diagnostic_item};
55
use clippy_utils::{is_entrypoint_fn, is_expn_of, match_panic_def_id, method_chain_args, return_ty};
66
use if_chain::if_chain;
77
use itertools::Itertools;
8-
use rustc_ast::ast::{Async, AttrKind, Attribute, FnKind, FnRetTy, ItemKind};
8+
use rustc_ast::ast::{Async, AttrKind, Attribute, Fn, FnRetTy, ItemKind};
99
use rustc_ast::token::CommentKind;
1010
use rustc_data_structures::fx::FxHashSet;
1111
use rustc_data_structures::sync::Lrc;
@@ -644,7 +644,9 @@ fn check_code(cx: &LateContext<'_>, text: &str, edition: Edition, span: Span) {
644644
| ItemKind::ExternCrate(..)
645645
| ItemKind::ForeignMod(..) => return false,
646646
// We found a main function ...
647-
ItemKind::Fn(box FnKind(_, sig, _, Some(block))) if item.ident.name == sym::main => {
647+
ItemKind::Fn(box Fn {
648+
sig, body: Some(block), ..
649+
}) if item.ident.name == sym::main => {
648650
let is_async = matches!(sig.header.asyncness, Async::Yes { .. });
649651
let returns_nothing = match &sig.decl.output {
650652
FnRetTy::Default(..) => true,

clippy_lints/src/excessive_bools.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use clippy_utils::diagnostics::span_lint_and_help;
2-
use rustc_ast::ast::{AssocItemKind, Extern, FnKind, FnSig, ImplKind, Item, ItemKind, TraitKind, Ty, TyKind};
2+
use rustc_ast::ast::{AssocItemKind, Extern, Fn, FnSig, Impl, Item, ItemKind, Trait, Ty, TyKind};
33
use rustc_lint::{EarlyContext, EarlyLintPass};
44
use rustc_session::{declare_tool_lint, impl_lint_pass};
55
use rustc_span::{sym, Span};
@@ -163,17 +163,17 @@ impl EarlyLintPass for ExcessiveBools {
163163
);
164164
}
165165
},
166-
ItemKind::Impl(box ImplKind {
166+
ItemKind::Impl(box Impl {
167167
of_trait: None, items, ..
168168
})
169-
| ItemKind::Trait(box TraitKind(.., items)) => {
169+
| ItemKind::Trait(box Trait { items, .. }) => {
170170
for item in items {
171-
if let AssocItemKind::Fn(box FnKind(_, fn_sig, _, _)) = &item.kind {
172-
self.check_fn_sig(cx, fn_sig, item.span);
171+
if let AssocItemKind::Fn(box Fn { sig, .. }) = &item.kind {
172+
self.check_fn_sig(cx, sig, item.span);
173173
}
174174
}
175175
},
176-
ItemKind::Fn(box FnKind(_, fn_sig, _, _)) => self.check_fn_sig(cx, fn_sig, item.span),
176+
ItemKind::Fn(box Fn { sig, .. }) => self.check_fn_sig(cx, sig, item.span),
177177
_ => (),
178178
}
179179
}

clippy_lints/src/future_not_send.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,13 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend {
7878
if is_future {
7979
let send_trait = cx.tcx.get_diagnostic_item(sym::Send).unwrap();
8080
let span = decl.output.span();
81-
let send_result = cx.tcx.infer_ctxt().enter(|infcx| {
81+
let send_errors = cx.tcx.infer_ctxt().enter(|infcx| {
8282
let cause = traits::ObligationCause::misc(span, hir_id);
8383
let mut fulfillment_cx = traits::FulfillmentContext::new();
8484
fulfillment_cx.register_bound(&infcx, cx.param_env, ret_ty, send_trait, cause);
8585
fulfillment_cx.select_all_or_error(&infcx)
8686
});
87-
if let Err(send_errors) = send_result {
87+
if !send_errors.is_empty() {
8888
span_lint_and_then(
8989
cx,
9090
FUTURE_NOT_SEND,

clippy_lints/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
#![feature(box_patterns)]
44
#![feature(drain_filter)]
5-
#![feature(format_args_capture)]
65
#![feature(in_band_lifetimes)]
76
#![feature(iter_zip)]
87
#![feature(once_cell)]

clippy_lints/src/matches.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1073,7 +1073,10 @@ fn check_wild_enum_match(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>])
10731073
PatKind::Path(path) => {
10741074
#[allow(clippy::match_same_arms)]
10751075
let id = match cx.qpath_res(path, pat.hir_id) {
1076-
Res::Def(DefKind::Const | DefKind::ConstParam | DefKind::AnonConst, _) => return,
1076+
Res::Def(
1077+
DefKind::Const | DefKind::ConstParam | DefKind::AnonConst | DefKind::InlineConst,
1078+
_,
1079+
) => return,
10771080
Res::Def(_, id) => id,
10781081
_ => return,
10791082
};

clippy_lints/src/non_expressive_names.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use clippy_utils::diagnostics::{span_lint, span_lint_and_then};
22
use rustc_ast::ast::{
3-
Arm, AssocItem, AssocItemKind, Attribute, Block, FnDecl, FnKind, Item, ItemKind, Local, Pat, PatKind,
3+
self, Arm, AssocItem, AssocItemKind, Attribute, Block, FnDecl, Item, ItemKind, Local, Pat, PatKind,
44
};
55
use rustc_ast::visit::{walk_block, walk_expr, walk_pat, Visitor};
66
use rustc_lint::{EarlyContext, EarlyLintPass};
@@ -360,7 +360,12 @@ impl EarlyLintPass for NonExpressiveNames {
360360
return;
361361
}
362362

363-
if let ItemKind::Fn(box FnKind(_, ref sig, _, Some(ref blk))) = item.kind {
363+
if let ItemKind::Fn(box ast::Fn {
364+
ref sig,
365+
body: Some(ref blk),
366+
..
367+
}) = item.kind
368+
{
364369
do_check(self, cx, &item.attrs, &sig.decl, blk);
365370
}
366371
}
@@ -370,7 +375,12 @@ impl EarlyLintPass for NonExpressiveNames {
370375
return;
371376
}
372377

373-
if let AssocItemKind::Fn(box FnKind(_, ref sig, _, Some(ref blk))) = item.kind {
378+
if let AssocItemKind::Fn(box ast::Fn {
379+
ref sig,
380+
body: Some(ref blk),
381+
..
382+
}) = item.kind
383+
{
374384
do_check(self, cx, &item.attrs, &sig.decl, blk);
375385
}
376386
}

clippy_lints/src/write.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::ops::{Deref, Range};
44

55
use clippy_utils::diagnostics::{span_lint, span_lint_and_sugg, span_lint_and_then};
66
use clippy_utils::source::{snippet_opt, snippet_with_applicability};
7-
use rustc_ast::ast::{Expr, ExprKind, ImplKind, Item, ItemKind, MacCall, Path, StrLit, StrStyle};
7+
use rustc_ast::ast::{Expr, ExprKind, Impl, Item, ItemKind, MacCall, Path, StrLit, StrStyle};
88
use rustc_ast::token::{self, LitKind};
99
use rustc_ast::tokenstream::TokenStream;
1010
use rustc_errors::Applicability;
@@ -252,7 +252,7 @@ impl_lint_pass!(Write => [
252252

253253
impl EarlyLintPass for Write {
254254
fn check_item(&mut self, _: &EarlyContext<'_>, item: &Item) {
255-
if let ItemKind::Impl(box ImplKind {
255+
if let ItemKind::Impl(box Impl {
256256
of_trait: Some(trait_ref),
257257
..
258258
}) = &item.kind

clippy_utils/src/ast_utils.rs

Lines changed: 103 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -243,14 +243,28 @@ pub fn eq_item<K>(l: &Item<K>, r: &Item<K>, mut eq_kind: impl FnMut(&K, &K) -> b
243243
eq_id(l.ident, r.ident) && over(&l.attrs, &r.attrs, eq_attr) && eq_vis(&l.vis, &r.vis) && eq_kind(&l.kind, &r.kind)
244244
}
245245

246+
#[allow(clippy::too_many_lines)] // Just a big match statement
246247
pub fn eq_item_kind(l: &ItemKind, r: &ItemKind) -> bool {
247248
use ItemKind::*;
248249
match (l, r) {
249250
(ExternCrate(l), ExternCrate(r)) => l == r,
250251
(Use(l), Use(r)) => eq_use_tree(l, r),
251252
(Static(lt, lm, le), Static(rt, rm, re)) => lm == rm && eq_ty(lt, rt) && eq_expr_opt(le, re),
252253
(Const(ld, lt, le), Const(rd, rt, re)) => eq_defaultness(*ld, *rd) && eq_ty(lt, rt) && eq_expr_opt(le, re),
253-
(Fn(box FnKind(ld, lf, lg, lb)), Fn(box FnKind(rd, rf, rg, rb))) => {
254+
(
255+
Fn(box ast::Fn {
256+
defaultness: ld,
257+
sig: lf,
258+
generics: lg,
259+
body: lb,
260+
}),
261+
Fn(box ast::Fn {
262+
defaultness: rd,
263+
sig: rf,
264+
generics: rg,
265+
body: rb,
266+
}),
267+
) => {
254268
eq_defaultness(*ld, *rd) && eq_fn_sig(lf, rf) && eq_generics(lg, rg) && both(lb, rb, |l, r| eq_block(l, r))
255269
},
256270
(Mod(lu, lmk), Mod(ru, rmk)) => {
@@ -266,7 +280,20 @@ pub fn eq_item_kind(l: &ItemKind, r: &ItemKind) -> bool {
266280
(ForeignMod(l), ForeignMod(r)) => {
267281
both(&l.abi, &r.abi, eq_str_lit) && over(&l.items, &r.items, |l, r| eq_item(l, r, eq_foreign_item_kind))
268282
},
269-
(TyAlias(box TyAliasKind(ld, lg, lb, lt)), TyAlias(box TyAliasKind(rd, rg, rb, rt))) => {
283+
(
284+
TyAlias(box ast::TyAlias {
285+
defaultness: ld,
286+
generics: lg,
287+
bounds: lb,
288+
ty: lt,
289+
}),
290+
TyAlias(box ast::TyAlias {
291+
defaultness: rd,
292+
generics: rg,
293+
bounds: rb,
294+
ty: rt,
295+
}),
296+
) => {
270297
eq_defaultness(*ld, *rd)
271298
&& eq_generics(lg, rg)
272299
&& over(lb, rb, eq_generic_bound)
@@ -276,7 +303,22 @@ pub fn eq_item_kind(l: &ItemKind, r: &ItemKind) -> bool {
276303
(Struct(lv, lg), Struct(rv, rg)) | (Union(lv, lg), Union(rv, rg)) => {
277304
eq_variant_data(lv, rv) && eq_generics(lg, rg)
278305
},
279-
(Trait(box TraitKind(la, lu, lg, lb, li)), Trait(box TraitKind(ra, ru, rg, rb, ri))) => {
306+
(
307+
Trait(box ast::Trait {
308+
is_auto: la,
309+
unsafety: lu,
310+
generics: lg,
311+
bounds: lb,
312+
items: li,
313+
}),
314+
Trait(box ast::Trait {
315+
is_auto: ra,
316+
unsafety: ru,
317+
generics: rg,
318+
bounds: rb,
319+
items: ri,
320+
}),
321+
) => {
280322
la == ra
281323
&& matches!(lu, Unsafe::No) == matches!(ru, Unsafe::No)
282324
&& eq_generics(lg, rg)
@@ -285,7 +327,7 @@ pub fn eq_item_kind(l: &ItemKind, r: &ItemKind) -> bool {
285327
},
286328
(TraitAlias(lg, lb), TraitAlias(rg, rb)) => eq_generics(lg, rg) && over(lb, rb, eq_generic_bound),
287329
(
288-
Impl(box ImplKind {
330+
Impl(box ast::Impl {
289331
unsafety: lu,
290332
polarity: lp,
291333
defaultness: ld,
@@ -295,7 +337,7 @@ pub fn eq_item_kind(l: &ItemKind, r: &ItemKind) -> bool {
295337
self_ty: lst,
296338
items: li,
297339
}),
298-
Impl(box ImplKind {
340+
Impl(box ast::Impl {
299341
unsafety: ru,
300342
polarity: rp,
301343
defaultness: rd,
@@ -325,10 +367,36 @@ pub fn eq_foreign_item_kind(l: &ForeignItemKind, r: &ForeignItemKind) -> bool {
325367
use ForeignItemKind::*;
326368
match (l, r) {
327369
(Static(lt, lm, le), Static(rt, rm, re)) => lm == rm && eq_ty(lt, rt) && eq_expr_opt(le, re),
328-
(Fn(box FnKind(ld, lf, lg, lb)), Fn(box FnKind(rd, rf, rg, rb))) => {
370+
(
371+
Fn(box ast::Fn {
372+
defaultness: ld,
373+
sig: lf,
374+
generics: lg,
375+
body: lb,
376+
}),
377+
Fn(box ast::Fn {
378+
defaultness: rd,
379+
sig: rf,
380+
generics: rg,
381+
body: rb,
382+
}),
383+
) => {
329384
eq_defaultness(*ld, *rd) && eq_fn_sig(lf, rf) && eq_generics(lg, rg) && both(lb, rb, |l, r| eq_block(l, r))
330385
},
331-
(TyAlias(box TyAliasKind(ld, lg, lb, lt)), TyAlias(box TyAliasKind(rd, rg, rb, rt))) => {
386+
(
387+
TyAlias(box ast::TyAlias {
388+
defaultness: ld,
389+
generics: lg,
390+
bounds: lb,
391+
ty: lt,
392+
}),
393+
TyAlias(box ast::TyAlias {
394+
defaultness: rd,
395+
generics: rg,
396+
bounds: rb,
397+
ty: rt,
398+
}),
399+
) => {
332400
eq_defaultness(*ld, *rd)
333401
&& eq_generics(lg, rg)
334402
&& over(lb, rb, eq_generic_bound)
@@ -343,10 +411,36 @@ pub fn eq_assoc_item_kind(l: &AssocItemKind, r: &AssocItemKind) -> bool {
343411
use AssocItemKind::*;
344412
match (l, r) {
345413
(Const(ld, lt, le), Const(rd, rt, re)) => eq_defaultness(*ld, *rd) && eq_ty(lt, rt) && eq_expr_opt(le, re),
346-
(Fn(box FnKind(ld, lf, lg, lb)), Fn(box FnKind(rd, rf, rg, rb))) => {
414+
(
415+
Fn(box ast::Fn {
416+
defaultness: ld,
417+
sig: lf,
418+
generics: lg,
419+
body: lb,
420+
}),
421+
Fn(box ast::Fn {
422+
defaultness: rd,
423+
sig: rf,
424+
generics: rg,
425+
body: rb,
426+
}),
427+
) => {
347428
eq_defaultness(*ld, *rd) && eq_fn_sig(lf, rf) && eq_generics(lg, rg) && both(lb, rb, |l, r| eq_block(l, r))
348429
},
349-
(TyAlias(box TyAliasKind(ld, lg, lb, lt)), TyAlias(box TyAliasKind(rd, rg, rb, rt))) => {
430+
(
431+
TyAlias(box ast::TyAlias {
432+
defaultness: ld,
433+
generics: lg,
434+
bounds: lb,
435+
ty: lt,
436+
}),
437+
TyAlias(box ast::TyAlias {
438+
defaultness: rd,
439+
generics: rg,
440+
bounds: rb,
441+
ty: rt,
442+
}),
443+
) => {
350444
eq_defaultness(*ld, *rd)
351445
&& eq_generics(lg, rg)
352446
&& over(lb, rb, eq_generic_bound)

clippy_utils/src/higher.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
#![deny(clippy::missing_docs_in_private_items)]
44

55
use crate::ty::is_type_diagnostic_item;
6-
use crate::{is_expn_of, last_path_segment, match_def_path, path_to_local_id, paths};
6+
use crate::{is_expn_of, last_path_segment, match_def_path, paths};
77
use if_chain::if_chain;
88
use rustc_ast::ast::{self, LitKind};
99
use rustc_hir as hir;
1010
use rustc_hir::{
11-
Arm, Block, BorrowKind, Expr, ExprKind, HirId, LoopSource, MatchSource, Node, Pat, PatKind, QPath, StmtKind, UnOp,
11+
Arm, Block, BorrowKind, Expr, ExprKind, HirId, LoopSource, MatchSource, Node, Pat, QPath, StmtKind, UnOp,
1212
};
1313
use rustc_lint::LateContext;
1414
use rustc_span::{sym, symbol, ExpnKind, Span, Symbol};
@@ -513,8 +513,6 @@ pub struct FormatArgsExpn<'tcx> {
513513
pub format_string_parts: &'tcx [Expr<'tcx>],
514514
/// Symbols corresponding to [`Self::format_string_parts`]
515515
pub format_string_symbols: Vec<Symbol>,
516-
/// Match arm patterns, the `arg0`, etc. from the next field `args`
517-
pub arg_names: &'tcx [Pat<'tcx>],
518516
/// Expressions like `ArgumentV1::new(arg0, Debug::fmt)`
519517
pub args: &'tcx [Expr<'tcx>],
520518
/// The final argument passed to `Arguments::new_v1_formatted`, if applicable
@@ -559,15 +557,13 @@ impl FormatArgsExpn<'tcx> {
559557
_ => None,
560558
})
561559
.collect();
562-
if let PatKind::Tuple(arg_names, None) = arm.pat.kind;
563560
if let ExprKind::Array(args) = arm.body.kind;
564561
then {
565562
Some(FormatArgsExpn {
566563
format_string_span: strs_ref.span,
567564
value_args,
568565
format_string_parts,
569566
format_string_symbols,
570-
arg_names,
571567
args,
572568
fmt_expr,
573569
})
@@ -594,10 +590,8 @@ impl FormatArgsExpn<'tcx> {
594590
if let Ok(i) = usize::try_from(position);
595591
let arg = &self.args[i];
596592
if let ExprKind::Call(_, [arg_name, _]) = arg.kind;
597-
if let Some(j) = self
598-
.arg_names
599-
.iter()
600-
.position(|pat| path_to_local_id(arg_name, pat.hir_id));
593+
if let ExprKind::Field(_, j) = arg_name.kind;
594+
if let Ok(j) = j.name.as_str().parse::<usize>();
601595
then {
602596
Some(FormatArgsArg { value: self.value_args[j], arg, fmt: Some(fmt) })
603597
} else {

rust-toolchain

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[toolchain]
2-
channel = "nightly-2021-11-04"
2+
channel = "nightly-2021-11-18"
33
components = ["llvm-tools-preview", "rustc-dev", "rust-src", "rustfmt"]

tests/ui-toml/lint_decimal_readability/test.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![allow(clippy::excessive_precision)]
12
#[deny(clippy::unreadable_literal)]
23

34
fn allow_inconsistent_digit_grouping() {

tests/ui-toml/lint_decimal_readability/test.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: digits grouped inconsistently by underscores
2-
--> $DIR/test.rs:18:18
2+
--> $DIR/test.rs:19:18
33
|
44
LL | let _fail1 = 100_200_300.123456789;
55
| ^^^^^^^^^^^^^^^^^^^^^ help: consider: `100_200_300.123_456_789`

tests/ui/deref_addrof.fixed

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,14 @@ macro_rules! m_mut {
5252
};
5353
}
5454

55+
#[derive(Copy, Clone)]
5556
pub struct S;
5657
impl S {
5758
pub fn f(&self) -> &Self {
5859
m!(self)
5960
}
60-
pub fn f_mut(&self) -> &Self {
61+
#[allow(unused_mut)] // mut will be unused, once the macro is fixed
62+
pub fn f_mut(mut self) -> Self {
6163
m_mut!(self)
6264
}
6365
}

0 commit comments

Comments
 (0)