Fix borrowed_box lint for Box<Any>

This commit is contained in:
Stanislav Tkach 2017-08-14 23:04:56 +03:00 committed by Stanislav Tkach
parent 7cdaeae1b8
commit 45ff467c31
3 changed files with 63 additions and 1 deletions

View file

@ -10,7 +10,7 @@ use syntax::ast::{IntTy, UintTy, FloatTy};
use syntax::attr::IntType;
use syntax::codemap::Span;
use utils::{comparisons, higher, in_external_macro, in_macro, match_def_path, snippet, span_help_and_lint, span_lint,
span_lint_and_sugg, opt_def_id, last_path_segment, type_size};
span_lint_and_sugg, opt_def_id, last_path_segment, type_size, match_path_old};
use utils::paths;
/// Handles all the linting of funky types
@ -212,6 +212,17 @@ fn check_ty(cx: &LateContext, ast_ty: &hir::Ty, is_local: bool) {
let PathParameters::AngleBracketedParameters(ref ab_data) = bx.parameters,
let [ref inner] = *ab_data.types
], {
if_let_chain! {[
let TyTraitObject(ref traits, _) = inner.node,
traits.len() >= 1,
// Only Send/Sync can be used as additional traits, so it is enough to
// check only the first trait.
match_path_old(&traits[0].trait_ref.path, &paths::ANY_TRAIT)
], {
// Ignore `Box<Any>` types, see #1884 for details.
return;
}}
let ltopt = if lt.is_elided() {
"".to_owned()
} else {

View file

@ -1,6 +1,7 @@
//! This module contains paths to types and functions Clippy needs to know
//! about.
pub const ANY_TRAIT: [&'static str; 3] = ["std", "any", "Any"];
pub const ASMUT_TRAIT: [&'static str; 3] = ["core", "convert", "AsMut"];
pub const ASREF_TRAIT: [&'static str; 3] = ["core", "convert", "AsRef"];
pub const BEGIN_PANIC: [&'static str; 3] = ["std", "panicking", "begin_panic"];