Merge pull request #3092 from illicitonion/issue-2879

default_trait_access skips <F as Default>::default()
This commit is contained in:
Philipp Hansch 2018-09-03 17:24:33 +02:00 committed by GitHub
commit c0513097ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 1 deletions

View File

@ -48,6 +48,17 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DefaultTraitAccess {
then { then {
match qpath { match qpath {
QPath::Resolved(..) => { QPath::Resolved(..) => {
if_chain! {
// Detect and ignore <Foo as Default>::default() because these calls do
// explicitly name the type.
if let ExprKind::Call(ref method, ref _args) = expr.node;
if let ExprKind::Path(ref p) = method.node;
if let QPath::Resolved(Some(_ty), _path) = p;
then {
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

@ -43,8 +43,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,
@ -63,6 +65,7 @@ fn main() {
s16, s16,
s17, s17,
s18, s18,
s19,
); );
} }