forked from rust-lang/rust
-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#5993 - taiki-e:default_trait_access, r=phansch
default_trait_access: Fix wrong suggestion rust-lang/rust-clippy#5975 (comment) > I think the underlying problem is clippy suggests code with complete parameters, not clippy triggers this lint even for complex types. AFAIK, If code compiles with `Default::default`, it doesn't need to specify any parameters, as type inference is working. (So, in this case, `default_trait_access` should suggest `RefCell::default`.) Fixes rust-lang#5975 Fixes rust-lang#5990 changelog: `default_trait_access`: fixed wrong suggestion
- Loading branch information
Showing
4 changed files
with
127 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
// run-rustfix | ||
|
||
#![allow(unused_imports)] | ||
#![deny(clippy::default_trait_access)] | ||
|
||
use std::default; | ||
use std::default::Default as D2; | ||
use std::string; | ||
|
||
fn main() { | ||
let s1: String = std::string::String::default(); | ||
|
||
let s2 = String::default(); | ||
|
||
let s3: String = std::string::String::default(); | ||
|
||
let s4: String = std::string::String::default(); | ||
|
||
let s5 = string::String::default(); | ||
|
||
let s6: String = std::string::String::default(); | ||
|
||
let s7 = std::string::String::default(); | ||
|
||
let s8: String = DefaultFactory::make_t_badly(); | ||
|
||
let s9: String = DefaultFactory::make_t_nicely(); | ||
|
||
let s10 = DerivedDefault::default(); | ||
|
||
let s11: GenericDerivedDefault<String> = GenericDerivedDefault::default(); | ||
|
||
let s12 = GenericDerivedDefault::<String>::default(); | ||
|
||
let s13 = TupleDerivedDefault::default(); | ||
|
||
let s14: TupleDerivedDefault = TupleDerivedDefault::default(); | ||
|
||
let s15: ArrayDerivedDefault = ArrayDerivedDefault::default(); | ||
|
||
let s16 = ArrayDerivedDefault::default(); | ||
|
||
let s17: TupleStructDerivedDefault = TupleStructDerivedDefault::default(); | ||
|
||
let s18 = TupleStructDerivedDefault::default(); | ||
|
||
let s19 = <DerivedDefault as Default>::default(); | ||
|
||
println!( | ||
"[{}] [{}] [{}] [{}] [{}] [{}] [{}] [{}] [{}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}], [{:?}]", | ||
s1, | ||
s2, | ||
s3, | ||
s4, | ||
s5, | ||
s6, | ||
s7, | ||
s8, | ||
s9, | ||
s10, | ||
s11, | ||
s12, | ||
s13, | ||
s14, | ||
s15, | ||
s16, | ||
s17, | ||
s18, | ||
s19, | ||
); | ||
} | ||
|
||
struct DefaultFactory; | ||
|
||
impl DefaultFactory { | ||
pub fn make_t_badly<T: Default>() -> T { | ||
Default::default() | ||
} | ||
|
||
pub fn make_t_nicely<T: Default>() -> T { | ||
T::default() | ||
} | ||
} | ||
|
||
#[derive(Debug, Default)] | ||
struct DerivedDefault { | ||
pub s: String, | ||
} | ||
|
||
#[derive(Debug, Default)] | ||
struct GenericDerivedDefault<T: Default + std::fmt::Debug> { | ||
pub s: T, | ||
} | ||
|
||
#[derive(Debug, Default)] | ||
struct TupleDerivedDefault { | ||
pub s: (String, String), | ||
} | ||
|
||
#[derive(Debug, Default)] | ||
struct ArrayDerivedDefault { | ||
pub s: [String; 10], | ||
} | ||
|
||
#[derive(Debug, Default)] | ||
struct TupleStructDerivedDefault(String); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters