Skip to content

Commit 350036a

Browse files
committed
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
1 parent 43c629e commit 350036a

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

clippy_lints/src/default_trait_access.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DefaultTraitAccess {
4848
then {
4949
match qpath {
5050
QPath::Resolved(..) => {
51+
if let ExprKind::Call(ref method, ref _args) = expr.node {
52+
if format!("{:?}", method).contains(" as Default>") {
53+
return
54+
}
55+
}
56+
57+
5158
// TODO: Work out a way to put "whatever the imported way of referencing
5259
// this type in this file" rather than a fully-qualified type.
5360
let expr_ty = cx.tables.expr_ty(expr);

tests/ui/default_trait_access.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,10 @@ fn main() {
4141

4242
let s18 = TupleStructDerivedDefault::default();
4343

44+
let s19 = <DerivedDefault as Default>::default();
45+
4446
println!(
45-
"[{}] [{}] [{}] [{}] [{}] [{}] [{}] [{}] [{}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}]",
47+
"[{}] [{}] [{}] [{}] [{}] [{}] [{}] [{}] [{}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}], [{:?}]",
4648
s1,
4749
s2,
4850
s3,
@@ -61,6 +63,7 @@ fn main() {
6163
s16,
6264
s17,
6365
s18,
66+
s19,
6467
);
6568
}
6669

0 commit comments

Comments
 (0)