Skip to content

Commit

Permalink
submodules: update clippy from b91ae16 to 2855b21
Browse files Browse the repository at this point in the history
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
  • Loading branch information
matthiaskrgr committed Feb 19, 2020
1 parent 62ee7b5 commit 03b51f2
Show file tree
Hide file tree
Showing 22 changed files with 165 additions and 63 deletions.
4 changes: 3 additions & 1 deletion clippy_lints/src/approx_const.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ declare_clippy_lint! {
}

// Tuples are of the form (constant, name, min_digits)
const KNOWN_CONSTS: [(f64, &str, usize); 16] = [
const KNOWN_CONSTS: [(f64, &str, usize); 18] = [
(f64::E, "E", 4),
(f64::FRAC_1_PI, "FRAC_1_PI", 4),
(f64::FRAC_1_SQRT_2, "FRAC_1_SQRT_2", 5),
Expand All @@ -52,6 +52,8 @@ const KNOWN_CONSTS: [(f64, &str, usize); 16] = [
(f64::LN_2, "LN_2", 5),
(f64::LOG10_E, "LOG10_E", 5),
(f64::LOG2_E, "LOG2_E", 5),
(f64::LOG2_10, "LOG2_10", 5),
(f64::LOG10_2, "LOG10_2", 5),
(f64::PI, "PI", 3),
(f64::SQRT_2, "SQRT_2", 5),
];
Expand Down
5 changes: 2 additions & 3 deletions clippy_lints/src/booleans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use crate::utils::{
use if_chain::if_chain;
use rustc::hir::map::Map;
use rustc_errors::Applicability;
use rustc_hir::intravisit;
use rustc_hir::intravisit::*;
use rustc_hir::*;
use rustc_lint::{LateContext, LateLintPass};
Expand Down Expand Up @@ -60,7 +59,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonminimalBool {
fn check_fn(
&mut self,
cx: &LateContext<'a, 'tcx>,
_: intravisit::FnKind<'tcx>,
_: FnKind<'tcx>,
_: &'tcx FnDecl<'_>,
body: &'tcx Body<'_>,
_: Span,
Expand Down Expand Up @@ -359,7 +358,7 @@ impl<'a, 'tcx> NonminimalBoolVisitor<'a, 'tcx> {
}
simplified.push(simple_negated);
}
let mut improvements = Vec::new();
let mut improvements = Vec::with_capacity(simplified.len());
'simplified: for suggestion in &simplified {
let simplified_stats = terminal_stats(suggestion);
let mut improvement = false;
Expand Down
8 changes: 4 additions & 4 deletions clippy_lints/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use rustc_hir::*;
use rustc_lint::LateContext;
use rustc_span::symbol::Symbol;
use std::cmp::Ordering::{self, Equal};
use std::cmp::PartialOrd;
use std::convert::TryInto;
use std::hash::{Hash, Hasher};
use syntax::ast::{FloatTy, LitKind};
Expand Down Expand Up @@ -227,7 +226,7 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> {
return self.ifthenelse(cond, then, otherwise);
}
match e.kind {
ExprKind::Path(ref qpath) => self.fetch_path(qpath, e.hir_id),
ExprKind::Path(ref qpath) => self.fetch_path(qpath, e.hir_id, self.tables.expr_ty(e)),
ExprKind::Block(ref block, _) => self.block(block),
ExprKind::Lit(ref lit) => Some(lit_to_constant(&lit.node, self.tables.expr_ty_opt(e))),
ExprKind::Array(ref vec) => self.multi(vec).map(Constant::Vec),
Expand Down Expand Up @@ -320,7 +319,7 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> {
}

/// Lookup a possibly constant expression from a `ExprKind::Path`.
fn fetch_path(&mut self, qpath: &QPath<'_>, id: HirId) -> Option<Constant> {
fn fetch_path(&mut self, qpath: &QPath<'_>, id: HirId, ty: Ty<'cc>) -> Option<Constant> {
let res = self.tables.qpath_res(qpath, id);
match res {
Res::Def(DefKind::Const, def_id) | Res::Def(DefKind::AssocConst, def_id) => {
Expand All @@ -335,7 +334,8 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> {
.lcx
.tcx
.const_eval_resolve(self.param_env, def_id, substs, None, None)
.ok()?;
.ok()
.map(|val| rustc::ty::Const::from_value(self.lcx.tcx, val, ty))?;
let result = miri_to_const(&result);
if result.is_some() {
self.needed_resolution = true;
Expand Down
54 changes: 40 additions & 14 deletions clippy_lints/src/doc.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use crate::utils::{is_entrypoint_fn, match_type, paths, return_ty, span_lint};
use crate::utils::{get_trait_def_id, implements_trait, is_entrypoint_fn, match_type, paths, return_ty, span_lint};
use if_chain::if_chain;
use itertools::Itertools;
use rustc::lint::in_external_macro;
use rustc::ty;
use rustc_data_structures::fx::FxHashSet;
use rustc_hir as hir;
use rustc_lint::{LateContext, LateLintPass};
Expand Down Expand Up @@ -152,11 +154,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DocMarkdown {
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx hir::Item<'_>) {
let headers = check_attrs(cx, &self.valid_idents, &item.attrs);
match item.kind {
hir::ItemKind::Fn(ref sig, ..) => {
hir::ItemKind::Fn(ref sig, _, body_id) => {
if !(is_entrypoint_fn(cx, cx.tcx.hir().local_def_id(item.hir_id))
|| in_external_macro(cx.tcx.sess, item.span))
{
lint_for_missing_headers(cx, item.hir_id, item.span, sig, headers);
lint_for_missing_headers(cx, item.hir_id, item.span, sig, headers, Some(body_id));
}
},
hir::ItemKind::Impl {
Expand All @@ -179,7 +181,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DocMarkdown {
let headers = check_attrs(cx, &self.valid_idents, &item.attrs);
if let hir::TraitItemKind::Method(ref sig, ..) = item.kind {
if !in_external_macro(cx.tcx.sess, item.span) {
lint_for_missing_headers(cx, item.hir_id, item.span, sig, headers);
lint_for_missing_headers(cx, item.hir_id, item.span, sig, headers, None);
}
}
}
Expand All @@ -189,8 +191,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DocMarkdown {
if self.in_trait_impl || in_external_macro(cx.tcx.sess, item.span) {
return;
}
if let hir::ImplItemKind::Method(ref sig, ..) = item.kind {
lint_for_missing_headers(cx, item.hir_id, item.span, sig, headers);
if let hir::ImplItemKind::Method(ref sig, body_id) = item.kind {
lint_for_missing_headers(cx, item.hir_id, item.span, sig, headers, Some(body_id));
}
}
}
Expand All @@ -201,6 +203,7 @@ fn lint_for_missing_headers<'a, 'tcx>(
span: impl Into<MultiSpan> + Copy,
sig: &hir::FnSig<'_>,
headers: DocHeaders,
body_id: Option<hir::BodyId>,
) {
if !cx.access_levels.is_exported(hir_id) {
return; // Private functions do not require doc comments
Expand All @@ -213,13 +216,36 @@ fn lint_for_missing_headers<'a, 'tcx>(
"unsafe function's docs miss `# Safety` section",
);
}
if !headers.errors && match_type(cx, return_ty(cx, hir_id), &paths::RESULT) {
span_lint(
cx,
MISSING_ERRORS_DOC,
span,
"docs for function returning `Result` missing `# Errors` section",
);
if !headers.errors {
if match_type(cx, return_ty(cx, hir_id), &paths::RESULT) {
span_lint(
cx,
MISSING_ERRORS_DOC,
span,
"docs for function returning `Result` missing `# Errors` section",
);
} else {
if_chain! {
if let Some(body_id) = body_id;
if let Some(future) = get_trait_def_id(cx, &paths::FUTURE);
let def_id = cx.tcx.hir().body_owner_def_id(body_id);
let mir = cx.tcx.optimized_mir(def_id);
let ret_ty = mir.return_ty();
if implements_trait(cx, ret_ty, future, &[]);
if let ty::Opaque(_, subs) = ret_ty.kind;
if let Some(gen) = subs.types().next();
if let ty::Generator(_, subs, _) = gen.kind;
if match_type(cx, subs.as_generator().return_ty(def_id, cx.tcx), &paths::RESULT);
then {
span_lint(
cx,
MISSING_ERRORS_DOC,
span,
"docs for function returning `Result` missing `# Errors` section",
);
}
}
}
}
}

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

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

fn check_code(cx: &LateContext<'_, '_>, text: &str, span: Span) {
if text.contains("fn main() {") && !LEAVE_MAIN_PATTERNS.iter().any(|p| text.contains(p)) {
Expand Down
8 changes: 6 additions & 2 deletions clippy_lints/src/enum_clike.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnportableVariant {
for var in def.variants {
if let Some(anon_const) = &var.disr_expr {
let def_id = cx.tcx.hir().body_owner_def_id(anon_const.body);
let constant = cx.tcx.const_eval_poly(def_id).ok();
let mut ty = cx.tcx.type_of(def_id);
let constant = cx
.tcx
.const_eval_poly(def_id)
.ok()
.map(|val| rustc::ty::Const::from_value(cx.tcx, val, ty));
if let Some(Constant::Int(val)) = constant.and_then(miri_to_const) {
let mut ty = cx.tcx.type_of(def_id);
if let ty::Adt(adt, _) = ty.kind {
if adt.is_enum() {
ty = adt.repr.discr_type().to_ty(cx.tcx);
Expand Down
5 changes: 2 additions & 3 deletions clippy_lints/src/escape.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use rustc::ty::layout::LayoutOf;
use rustc::ty::{self, Ty};
use rustc_hir::intravisit as visit;
use rustc_hir::HirIdSet;
use rustc_hir::intravisit;
use rustc_hir::{self, *};
use rustc_infer::infer::TyCtxtInferExt;
use rustc_lint::{LateContext, LateLintPass};
Expand Down Expand Up @@ -54,7 +53,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BoxedLocal {
fn check_fn(
&mut self,
cx: &LateContext<'a, 'tcx>,
_: visit::FnKind<'tcx>,
_: intravisit::FnKind<'tcx>,
_: &'tcx FnDecl<'_>,
body: &'tcx Body<'_>,
_: Span,
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/excessive_bools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ impl EarlyLintPass for ExcessiveBools {
}
| ItemKind::Trait(_, _, _, _, items) => {
for item in items {
if let AssocItemKind::Fn(fn_sig, _) = &item.kind {
if let AssocItemKind::Fn(fn_sig, _, _) = &item.kind {
self.check_fn_sig(cx, fn_sig, item.span);
}
}
Expand Down
14 changes: 6 additions & 8 deletions clippy_lints/src/indexing_slicing.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
//! lint on indexing and slicing operations

use crate::consts::{constant, Constant};
use crate::utils;
use crate::utils::higher;
use crate::utils::higher::Range;
use crate::utils::{higher, span_lint, span_lint_and_help};
use rustc::ty;
use rustc_hir::*;
use rustc_lint::{LateContext, LateLintPass};
Expand Down Expand Up @@ -100,7 +98,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IndexingSlicing {

if let (Some(start), _) = const_range {
if start > size {
utils::span_lint(
span_lint(
cx,
OUT_OF_BOUNDS_INDEXING,
range.start.map_or(expr.span, |start| start.span),
Expand All @@ -112,7 +110,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IndexingSlicing {

if let (_, Some(end)) = const_range {
if end > size {
utils::span_lint(
span_lint(
cx,
OUT_OF_BOUNDS_INDEXING,
range.end.map_or(expr.span, |end| end.span),
Expand All @@ -136,7 +134,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IndexingSlicing {
(None, None) => return, // [..] is ok.
};

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

utils::span_lint_and_help(
span_lint_and_help(
cx,
INDEXING_SLICING,
expr.span,
Expand All @@ -163,7 +161,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IndexingSlicing {
/// the range. If the start or end is not constant, None is returned.
fn to_const_range<'a, 'tcx>(
cx: &LateContext<'a, 'tcx>,
range: Range<'_>,
range: higher::Range<'_>,
array_size: u128,
) -> (Option<u128>, Option<u128>) {
let s = range.start.map(|expr| constant(cx, cx.tables, expr).map(|(c, _)| c));
Expand Down
1 change: 0 additions & 1 deletion clippy_lints/src/loops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use rustc::ty::{self, Ty};
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_errors::Applicability;
use rustc_hir::def::{DefKind, Res};
use rustc_hir::def_id;
use rustc_hir::intravisit::{walk_block, walk_expr, walk_pat, walk_stmt, NestedVisitorMap, Visitor};
use rustc_hir::*;
use rustc_infer::infer::TyCtxtInferExt;
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/matches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@ fn is_panic_block(block: &Block<'_>) -> bool {

fn check_match_ref_pats(cx: &LateContext<'_, '_>, ex: &Expr<'_>, arms: &[Arm<'_>], expr: &Expr<'_>) {
if has_only_ref_pats(arms) {
let mut suggs = Vec::new();
let mut suggs = Vec::with_capacity(arms.len() + 1);
let (title, msg) = if let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Not, ref inner) = ex.kind {
let span = ex.span.source_callsite();
suggs.push((span, Sugg::hir_with_macro_callsite(cx, inner, "..").to_string()));
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/non_expressive_names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ impl EarlyLintPass for NonExpressiveNames {
}

fn check_impl_item(&mut self, cx: &EarlyContext<'_>, item: &AssocItem) {
if let AssocItemKind::Fn(ref sig, Some(ref blk)) = item.kind {
if let AssocItemKind::Fn(ref sig, _, Some(ref blk)) = item.kind {
do_check(self, cx, &item.attrs, &sig.decl, blk);
}
}
Expand Down
1 change: 0 additions & 1 deletion clippy_lints/src/ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use crate::utils::{
use if_chain::if_chain;
use rustc::ty;
use rustc_errors::Applicability;
use rustc_hir::QPath;
use rustc_hir::*;
use rustc_lint::{LateContext, LateLintPass};
use rustc_session::{declare_lint_pass, declare_tool_lint};
Expand Down
10 changes: 5 additions & 5 deletions clippy_lints/src/ptr_offset_with_cast.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::utils;
use crate::utils::{snippet_opt, span_lint, span_lint_and_sugg};
use rustc_errors::Applicability;
use rustc_hir::{Expr, ExprKind};
use rustc_lint::{LateContext, LateLintPass};
Expand Down Expand Up @@ -59,7 +59,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for PtrOffsetWithCast {

let msg = format!("use of `{}` with a `usize` casted to an `isize`", method);
if let Some(sugg) = build_suggestion(cx, method, receiver_expr, cast_lhs_expr) {
utils::span_lint_and_sugg(
span_lint_and_sugg(
cx,
PTR_OFFSET_WITH_CAST,
expr.span,
Expand All @@ -69,7 +69,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for PtrOffsetWithCast {
Applicability::MachineApplicable,
);
} else {
utils::span_lint(cx, PTR_OFFSET_WITH_CAST, expr.span, &msg);
span_lint(cx, PTR_OFFSET_WITH_CAST, expr.span, &msg);
}
}
}
Expand Down Expand Up @@ -119,8 +119,8 @@ fn build_suggestion<'a, 'tcx>(
receiver_expr: &Expr<'_>,
cast_lhs_expr: &Expr<'_>,
) -> Option<String> {
let receiver = utils::snippet_opt(cx, receiver_expr.span)?;
let cast_lhs = utils::snippet_opt(cx, cast_lhs_expr.span)?;
let receiver = snippet_opt(cx, receiver_expr.span)?;
let cast_lhs = snippet_opt(cx, cast_lhs_expr.span)?;
Some(format!("{}.{}({})", receiver, method.suggestion(), cast_lhs))
}

Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/shadow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Shadow {
}

fn check_fn<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, decl: &'tcx FnDecl<'_>, body: &'tcx Body<'_>) {
let mut bindings = Vec::new();
let mut bindings = Vec::with_capacity(decl.inputs.len());
for arg in iter_input_pats(decl, body) {
if let PatKind::Binding(.., ident, _) = arg.pat.kind {
bindings.push((ident.name, ident.span))
Expand Down
3 changes: 1 addition & 2 deletions clippy_lints/src/temporary_assignment.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::utils::is_adjusted;
use crate::utils::span_lint;
use crate::utils::{is_adjusted, span_lint};
use rustc_hir::def::{DefKind, Res};
use rustc_hir::{Expr, ExprKind};
use rustc_lint::{LateContext, LateLintPass};
Expand Down
8 changes: 3 additions & 5 deletions clippy_lints/src/utils/internal_lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@ use rustc_hir::def::{DefKind, Res};
use rustc_hir::intravisit::{walk_expr, NestedVisitorMap, Visitor};
use rustc_hir::*;
use rustc_lint::{EarlyContext, EarlyLintPass, LateContext, LateLintPass};
use rustc_session::declare_tool_lint;
use rustc_session::{declare_lint_pass, impl_lint_pass};
use rustc_session::{declare_lint_pass, declare_tool_lint, impl_lint_pass};
use rustc_span::source_map::{Span, Spanned};
use rustc_span::symbol::SymbolStr;
use syntax::ast;
use syntax::ast::{Crate as AstCrate, ItemKind, LitKind, Name};
use syntax::ast::{Crate as AstCrate, ItemKind, LitKind, Name, NodeId};
use syntax::visit::FnKind;

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

impl EarlyLintPass for ProduceIce {
fn check_fn(&mut self, _: &EarlyContext<'_>, fn_kind: FnKind<'_>, _: Span, _: ast::NodeId) {
fn check_fn(&mut self, _: &EarlyContext<'_>, fn_kind: FnKind<'_>, _: Span, _: NodeId) {
if is_trigger_fn(fn_kind) {
panic!("Would you like some help with that?");
}
Expand Down
Loading

0 comments on commit 03b51f2

Please sign in to comment.