default_trait_access skips <F as Default>::default()

This includes the type name, so is clear, and may be necessary.

There doesn't seem to be an obviously cleaner way to pull out the
literal text of the named type here.

Fixes #2879
This commit is contained in:
Daniel Wagner-Hall 2018-08-27 23:22:07 +01:00
parent 43c629ebac
commit 350036a0c7
2 changed files with 11 additions and 1 deletions

View file

@ -48,6 +48,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DefaultTraitAccess {
then { then {
match qpath { match qpath {
QPath::Resolved(..) => { QPath::Resolved(..) => {
if let ExprKind::Call(ref method, ref _args) = expr.node {
if format!("{:?}", method).contains(" as Default>") {
return
}
}
// TODO: Work out a way to put "whatever the imported way of referencing // TODO: Work out a way to put "whatever the imported way of referencing
// this type in this file" rather than a fully-qualified type. // this type in this file" rather than a fully-qualified type.
let expr_ty = cx.tables.expr_ty(expr); let expr_ty = cx.tables.expr_ty(expr);

View file

@ -41,8 +41,10 @@ fn main() {
let s18 = TupleStructDerivedDefault::default(); let s18 = TupleStructDerivedDefault::default();
let s19 = <DerivedDefault as Default>::default();
println!( println!(
"[{}] [{}] [{}] [{}] [{}] [{}] [{}] [{}] [{}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}]", "[{}] [{}] [{}] [{}] [{}] [{}] [{}] [{}] [{}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}], [{:?}]",
s1, s1,
s2, s2,
s3, s3,
@ -61,6 +63,7 @@ fn main() {
s16, s16,
s17, s17,
s18, s18,
s19,
); );
} }