Skip to content

Commit 03b51f2

Browse files
committed
submodules: update clippy from b91ae16 to 2855b21
Changes: ```` Rustup to rust-lang/rust#69194 Rustup to rust-lang/rust#69181 Add `LOG2_10` and `LOG10_2` to `approx_const` lint Clean up imports Use `Vec::with_capacity()` as possible needless_doctest_main: False positive for async fn Remove use of `TyKind`. Use `if_chain`. Fix ICE. Add tests and improve checks. Add `Future` detection for `missing_errors_doc`. ```` Fixes #69269
1 parent 62ee7b5 commit 03b51f2

22 files changed

+165
-63
lines changed

clippy_lints/src/approx_const.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ declare_clippy_lint! {
3737
}
3838

3939
// Tuples are of the form (constant, name, min_digits)
40-
const KNOWN_CONSTS: [(f64, &str, usize); 16] = [
40+
const KNOWN_CONSTS: [(f64, &str, usize); 18] = [
4141
(f64::E, "E", 4),
4242
(f64::FRAC_1_PI, "FRAC_1_PI", 4),
4343
(f64::FRAC_1_SQRT_2, "FRAC_1_SQRT_2", 5),
@@ -52,6 +52,8 @@ const KNOWN_CONSTS: [(f64, &str, usize); 16] = [
5252
(f64::LN_2, "LN_2", 5),
5353
(f64::LOG10_E, "LOG10_E", 5),
5454
(f64::LOG2_E, "LOG2_E", 5),
55+
(f64::LOG2_10, "LOG2_10", 5),
56+
(f64::LOG10_2, "LOG10_2", 5),
5557
(f64::PI, "PI", 3),
5658
(f64::SQRT_2, "SQRT_2", 5),
5759
];

clippy_lints/src/booleans.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use crate::utils::{
55
use if_chain::if_chain;
66
use rustc::hir::map::Map;
77
use rustc_errors::Applicability;
8-
use rustc_hir::intravisit;
98
use rustc_hir::intravisit::*;
109
use rustc_hir::*;
1110
use rustc_lint::{LateContext, LateLintPass};
@@ -60,7 +59,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonminimalBool {
6059
fn check_fn(
6160
&mut self,
6261
cx: &LateContext<'a, 'tcx>,
63-
_: intravisit::FnKind<'tcx>,
62+
_: FnKind<'tcx>,
6463
_: &'tcx FnDecl<'_>,
6564
body: &'tcx Body<'_>,
6665
_: Span,
@@ -359,7 +358,7 @@ impl<'a, 'tcx> NonminimalBoolVisitor<'a, 'tcx> {
359358
}
360359
simplified.push(simple_negated);
361360
}
362-
let mut improvements = Vec::new();
361+
let mut improvements = Vec::with_capacity(simplified.len());
363362
'simplified: for suggestion in &simplified {
364363
let simplified_stats = terminal_stats(suggestion);
365364
let mut improvement = false;

clippy_lints/src/consts.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use rustc_hir::*;
1111
use rustc_lint::LateContext;
1212
use rustc_span::symbol::Symbol;
1313
use std::cmp::Ordering::{self, Equal};
14-
use std::cmp::PartialOrd;
1514
use std::convert::TryInto;
1615
use std::hash::{Hash, Hasher};
1716
use syntax::ast::{FloatTy, LitKind};
@@ -227,7 +226,7 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> {
227226
return self.ifthenelse(cond, then, otherwise);
228227
}
229228
match e.kind {
230-
ExprKind::Path(ref qpath) => self.fetch_path(qpath, e.hir_id),
229+
ExprKind::Path(ref qpath) => self.fetch_path(qpath, e.hir_id, self.tables.expr_ty(e)),
231230
ExprKind::Block(ref block, _) => self.block(block),
232231
ExprKind::Lit(ref lit) => Some(lit_to_constant(&lit.node, self.tables.expr_ty_opt(e))),
233232
ExprKind::Array(ref vec) => self.multi(vec).map(Constant::Vec),
@@ -320,7 +319,7 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> {
320319
}
321320

322321
/// Lookup a possibly constant expression from a `ExprKind::Path`.
323-
fn fetch_path(&mut self, qpath: &QPath<'_>, id: HirId) -> Option<Constant> {
322+
fn fetch_path(&mut self, qpath: &QPath<'_>, id: HirId, ty: Ty<'cc>) -> Option<Constant> {
324323
let res = self.tables.qpath_res(qpath, id);
325324
match res {
326325
Res::Def(DefKind::Const, def_id) | Res::Def(DefKind::AssocConst, def_id) => {
@@ -335,7 +334,8 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> {
335334
.lcx
336335
.tcx
337336
.const_eval_resolve(self.param_env, def_id, substs, None, None)
338-
.ok()?;
337+
.ok()
338+
.map(|val| rustc::ty::Const::from_value(self.lcx.tcx, val, ty))?;
339339
let result = miri_to_const(&result);
340340
if result.is_some() {
341341
self.needed_resolution = true;

clippy_lints/src/doc.rs

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
use crate::utils::{is_entrypoint_fn, match_type, paths, return_ty, span_lint};
1+
use crate::utils::{get_trait_def_id, implements_trait, is_entrypoint_fn, match_type, paths, return_ty, span_lint};
2+
use if_chain::if_chain;
23
use itertools::Itertools;
34
use rustc::lint::in_external_macro;
5+
use rustc::ty;
46
use rustc_data_structures::fx::FxHashSet;
57
use rustc_hir as hir;
68
use rustc_lint::{LateContext, LateLintPass};
@@ -152,11 +154,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DocMarkdown {
152154
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx hir::Item<'_>) {
153155
let headers = check_attrs(cx, &self.valid_idents, &item.attrs);
154156
match item.kind {
155-
hir::ItemKind::Fn(ref sig, ..) => {
157+
hir::ItemKind::Fn(ref sig, _, body_id) => {
156158
if !(is_entrypoint_fn(cx, cx.tcx.hir().local_def_id(item.hir_id))
157159
|| in_external_macro(cx.tcx.sess, item.span))
158160
{
159-
lint_for_missing_headers(cx, item.hir_id, item.span, sig, headers);
161+
lint_for_missing_headers(cx, item.hir_id, item.span, sig, headers, Some(body_id));
160162
}
161163
},
162164
hir::ItemKind::Impl {
@@ -179,7 +181,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DocMarkdown {
179181
let headers = check_attrs(cx, &self.valid_idents, &item.attrs);
180182
if let hir::TraitItemKind::Method(ref sig, ..) = item.kind {
181183
if !in_external_macro(cx.tcx.sess, item.span) {
182-
lint_for_missing_headers(cx, item.hir_id, item.span, sig, headers);
184+
lint_for_missing_headers(cx, item.hir_id, item.span, sig, headers, None);
183185
}
184186
}
185187
}
@@ -189,8 +191,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DocMarkdown {
189191
if self.in_trait_impl || in_external_macro(cx.tcx.sess, item.span) {
190192
return;
191193
}
192-
if let hir::ImplItemKind::Method(ref sig, ..) = item.kind {
193-
lint_for_missing_headers(cx, item.hir_id, item.span, sig, headers);
194+
if let hir::ImplItemKind::Method(ref sig, body_id) = item.kind {
195+
lint_for_missing_headers(cx, item.hir_id, item.span, sig, headers, Some(body_id));
194196
}
195197
}
196198
}
@@ -201,6 +203,7 @@ fn lint_for_missing_headers<'a, 'tcx>(
201203
span: impl Into<MultiSpan> + Copy,
202204
sig: &hir::FnSig<'_>,
203205
headers: DocHeaders,
206+
body_id: Option<hir::BodyId>,
204207
) {
205208
if !cx.access_levels.is_exported(hir_id) {
206209
return; // Private functions do not require doc comments
@@ -213,13 +216,36 @@ fn lint_for_missing_headers<'a, 'tcx>(
213216
"unsafe function's docs miss `# Safety` section",
214217
);
215218
}
216-
if !headers.errors && match_type(cx, return_ty(cx, hir_id), &paths::RESULT) {
217-
span_lint(
218-
cx,
219-
MISSING_ERRORS_DOC,
220-
span,
221-
"docs for function returning `Result` missing `# Errors` section",
222-
);
219+
if !headers.errors {
220+
if match_type(cx, return_ty(cx, hir_id), &paths::RESULT) {
221+
span_lint(
222+
cx,
223+
MISSING_ERRORS_DOC,
224+
span,
225+
"docs for function returning `Result` missing `# Errors` section",
226+
);
227+
} else {
228+
if_chain! {
229+
if let Some(body_id) = body_id;
230+
if let Some(future) = get_trait_def_id(cx, &paths::FUTURE);
231+
let def_id = cx.tcx.hir().body_owner_def_id(body_id);
232+
let mir = cx.tcx.optimized_mir(def_id);
233+
let ret_ty = mir.return_ty();
234+
if implements_trait(cx, ret_ty, future, &[]);
235+
if let ty::Opaque(_, subs) = ret_ty.kind;
236+
if let Some(gen) = subs.types().next();
237+
if let ty::Generator(_, subs, _) = gen.kind;
238+
if match_type(cx, subs.as_generator().return_ty(def_id, cx.tcx), &paths::RESULT);
239+
then {
240+
span_lint(
241+
cx,
242+
MISSING_ERRORS_DOC,
243+
span,
244+
"docs for function returning `Result` missing `# Errors` section",
245+
);
246+
}
247+
}
248+
}
223249
}
224250
}
225251

@@ -398,7 +424,7 @@ fn check_doc<'a, Events: Iterator<Item = (pulldown_cmark::Event<'a>, Range<usize
398424
headers
399425
}
400426

401-
static LEAVE_MAIN_PATTERNS: &[&str] = &["static", "fn main() {}", "extern crate"];
427+
static LEAVE_MAIN_PATTERNS: &[&str] = &["static", "fn main() {}", "extern crate", "async fn main() {"];
402428

403429
fn check_code(cx: &LateContext<'_, '_>, text: &str, span: Span) {
404430
if text.contains("fn main() {") && !LEAVE_MAIN_PATTERNS.iter().any(|p| text.contains(p)) {

clippy_lints/src/enum_clike.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnportableVariant {
4646
for var in def.variants {
4747
if let Some(anon_const) = &var.disr_expr {
4848
let def_id = cx.tcx.hir().body_owner_def_id(anon_const.body);
49-
let constant = cx.tcx.const_eval_poly(def_id).ok();
49+
let mut ty = cx.tcx.type_of(def_id);
50+
let constant = cx
51+
.tcx
52+
.const_eval_poly(def_id)
53+
.ok()
54+
.map(|val| rustc::ty::Const::from_value(cx.tcx, val, ty));
5055
if let Some(Constant::Int(val)) = constant.and_then(miri_to_const) {
51-
let mut ty = cx.tcx.type_of(def_id);
5256
if let ty::Adt(adt, _) = ty.kind {
5357
if adt.is_enum() {
5458
ty = adt.repr.discr_type().to_ty(cx.tcx);

clippy_lints/src/escape.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use rustc::ty::layout::LayoutOf;
22
use rustc::ty::{self, Ty};
3-
use rustc_hir::intravisit as visit;
4-
use rustc_hir::HirIdSet;
3+
use rustc_hir::intravisit;
54
use rustc_hir::{self, *};
65
use rustc_infer::infer::TyCtxtInferExt;
76
use rustc_lint::{LateContext, LateLintPass};
@@ -54,7 +53,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BoxedLocal {
5453
fn check_fn(
5554
&mut self,
5655
cx: &LateContext<'a, 'tcx>,
57-
_: visit::FnKind<'tcx>,
56+
_: intravisit::FnKind<'tcx>,
5857
_: &'tcx FnDecl<'_>,
5958
body: &'tcx Body<'_>,
6059
_: Span,

clippy_lints/src/excessive_bools.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ impl EarlyLintPass for ExcessiveBools {
162162
}
163163
| ItemKind::Trait(_, _, _, _, items) => {
164164
for item in items {
165-
if let AssocItemKind::Fn(fn_sig, _) = &item.kind {
165+
if let AssocItemKind::Fn(fn_sig, _, _) = &item.kind {
166166
self.check_fn_sig(cx, fn_sig, item.span);
167167
}
168168
}

clippy_lints/src/indexing_slicing.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
//! lint on indexing and slicing operations
22
33
use crate::consts::{constant, Constant};
4-
use crate::utils;
5-
use crate::utils::higher;
6-
use crate::utils::higher::Range;
4+
use crate::utils::{higher, span_lint, span_lint_and_help};
75
use rustc::ty;
86
use rustc_hir::*;
97
use rustc_lint::{LateContext, LateLintPass};
@@ -100,7 +98,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IndexingSlicing {
10098

10199
if let (Some(start), _) = const_range {
102100
if start > size {
103-
utils::span_lint(
101+
span_lint(
104102
cx,
105103
OUT_OF_BOUNDS_INDEXING,
106104
range.start.map_or(expr.span, |start| start.span),
@@ -112,7 +110,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IndexingSlicing {
112110

113111
if let (_, Some(end)) = const_range {
114112
if end > size {
115-
utils::span_lint(
113+
span_lint(
116114
cx,
117115
OUT_OF_BOUNDS_INDEXING,
118116
range.end.map_or(expr.span, |end| end.span),
@@ -136,7 +134,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IndexingSlicing {
136134
(None, None) => return, // [..] is ok.
137135
};
138136

139-
utils::span_lint_and_help(cx, INDEXING_SLICING, expr.span, "slicing may panic.", help_msg);
137+
span_lint_and_help(cx, INDEXING_SLICING, expr.span, "slicing may panic.", help_msg);
140138
} else {
141139
// Catchall non-range index, i.e., [n] or [n << m]
142140
if let ty::Array(..) = ty.kind {
@@ -147,7 +145,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IndexingSlicing {
147145
}
148146
}
149147

150-
utils::span_lint_and_help(
148+
span_lint_and_help(
151149
cx,
152150
INDEXING_SLICING,
153151
expr.span,
@@ -163,7 +161,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IndexingSlicing {
163161
/// the range. If the start or end is not constant, None is returned.
164162
fn to_const_range<'a, 'tcx>(
165163
cx: &LateContext<'a, 'tcx>,
166-
range: Range<'_>,
164+
range: higher::Range<'_>,
167165
array_size: u128,
168166
) -> (Option<u128>, Option<u128>) {
169167
let s = range.start.map(|expr| constant(cx, cx.tables, expr).map(|(c, _)| c));

clippy_lints/src/loops.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ use rustc::ty::{self, Ty};
1818
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
1919
use rustc_errors::Applicability;
2020
use rustc_hir::def::{DefKind, Res};
21-
use rustc_hir::def_id;
2221
use rustc_hir::intravisit::{walk_block, walk_expr, walk_pat, walk_stmt, NestedVisitorMap, Visitor};
2322
use rustc_hir::*;
2423
use rustc_infer::infer::TyCtxtInferExt;

clippy_lints/src/matches.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,7 @@ fn is_panic_block(block: &Block<'_>) -> bool {
724724

725725
fn check_match_ref_pats(cx: &LateContext<'_, '_>, ex: &Expr<'_>, arms: &[Arm<'_>], expr: &Expr<'_>) {
726726
if has_only_ref_pats(arms) {
727-
let mut suggs = Vec::new();
727+
let mut suggs = Vec::with_capacity(arms.len() + 1);
728728
let (title, msg) = if let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Not, ref inner) = ex.kind {
729729
let span = ex.span.source_callsite();
730730
suggs.push((span, Sugg::hir_with_macro_callsite(cx, inner, "..").to_string()));

clippy_lints/src/non_expressive_names.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ impl EarlyLintPass for NonExpressiveNames {
358358
}
359359

360360
fn check_impl_item(&mut self, cx: &EarlyContext<'_>, item: &AssocItem) {
361-
if let AssocItemKind::Fn(ref sig, Some(ref blk)) = item.kind {
361+
if let AssocItemKind::Fn(ref sig, _, Some(ref blk)) = item.kind {
362362
do_check(self, cx, &item.attrs, &sig.decl, blk);
363363
}
364364
}

clippy_lints/src/ptr.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use crate::utils::{
88
use if_chain::if_chain;
99
use rustc::ty;
1010
use rustc_errors::Applicability;
11-
use rustc_hir::QPath;
1211
use rustc_hir::*;
1312
use rustc_lint::{LateContext, LateLintPass};
1413
use rustc_session::{declare_lint_pass, declare_tool_lint};

clippy_lints/src/ptr_offset_with_cast.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::utils;
1+
use crate::utils::{snippet_opt, span_lint, span_lint_and_sugg};
22
use rustc_errors::Applicability;
33
use rustc_hir::{Expr, ExprKind};
44
use rustc_lint::{LateContext, LateLintPass};
@@ -59,7 +59,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for PtrOffsetWithCast {
5959

6060
let msg = format!("use of `{}` with a `usize` casted to an `isize`", method);
6161
if let Some(sugg) = build_suggestion(cx, method, receiver_expr, cast_lhs_expr) {
62-
utils::span_lint_and_sugg(
62+
span_lint_and_sugg(
6363
cx,
6464
PTR_OFFSET_WITH_CAST,
6565
expr.span,
@@ -69,7 +69,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for PtrOffsetWithCast {
6969
Applicability::MachineApplicable,
7070
);
7171
} else {
72-
utils::span_lint(cx, PTR_OFFSET_WITH_CAST, expr.span, &msg);
72+
span_lint(cx, PTR_OFFSET_WITH_CAST, expr.span, &msg);
7373
}
7474
}
7575
}
@@ -119,8 +119,8 @@ fn build_suggestion<'a, 'tcx>(
119119
receiver_expr: &Expr<'_>,
120120
cast_lhs_expr: &Expr<'_>,
121121
) -> Option<String> {
122-
let receiver = utils::snippet_opt(cx, receiver_expr.span)?;
123-
let cast_lhs = utils::snippet_opt(cx, cast_lhs_expr.span)?;
122+
let receiver = snippet_opt(cx, receiver_expr.span)?;
123+
let cast_lhs = snippet_opt(cx, cast_lhs_expr.span)?;
124124
Some(format!("{}.{}({})", receiver, method.suggestion(), cast_lhs))
125125
}
126126

clippy_lints/src/shadow.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Shadow {
101101
}
102102

103103
fn check_fn<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, decl: &'tcx FnDecl<'_>, body: &'tcx Body<'_>) {
104-
let mut bindings = Vec::new();
104+
let mut bindings = Vec::with_capacity(decl.inputs.len());
105105
for arg in iter_input_pats(decl, body) {
106106
if let PatKind::Binding(.., ident, _) = arg.pat.kind {
107107
bindings.push((ident.name, ident.span))

clippy_lints/src/temporary_assignment.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
use crate::utils::is_adjusted;
2-
use crate::utils::span_lint;
1+
use crate::utils::{is_adjusted, span_lint};
32
use rustc_hir::def::{DefKind, Res};
43
use rustc_hir::{Expr, ExprKind};
54
use rustc_lint::{LateContext, LateLintPass};

clippy_lints/src/utils/internal_lints.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,10 @@ use rustc_hir::def::{DefKind, Res};
1111
use rustc_hir::intravisit::{walk_expr, NestedVisitorMap, Visitor};
1212
use rustc_hir::*;
1313
use rustc_lint::{EarlyContext, EarlyLintPass, LateContext, LateLintPass};
14-
use rustc_session::declare_tool_lint;
15-
use rustc_session::{declare_lint_pass, impl_lint_pass};
14+
use rustc_session::{declare_lint_pass, declare_tool_lint, impl_lint_pass};
1615
use rustc_span::source_map::{Span, Spanned};
1716
use rustc_span::symbol::SymbolStr;
18-
use syntax::ast;
19-
use syntax::ast::{Crate as AstCrate, ItemKind, LitKind, Name};
17+
use syntax::ast::{Crate as AstCrate, ItemKind, LitKind, Name, NodeId};
2018
use syntax::visit::FnKind;
2119

2220
declare_clippy_lint! {
@@ -380,7 +378,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for OuterExpnDataPass {
380378
declare_lint_pass!(ProduceIce => [PRODUCE_ICE]);
381379

382380
impl EarlyLintPass for ProduceIce {
383-
fn check_fn(&mut self, _: &EarlyContext<'_>, fn_kind: FnKind<'_>, _: Span, _: ast::NodeId) {
381+
fn check_fn(&mut self, _: &EarlyContext<'_>, fn_kind: FnKind<'_>, _: Span, _: NodeId) {
384382
if is_trigger_fn(fn_kind) {
385383
panic!("Would you like some help with that?");
386384
}

0 commit comments

Comments
 (0)