@@ -35,14 +35,15 @@ impl<'tcx> LateLintPass<'tcx> for TrivialDefaultConstructedTypes {
3535 && let ExprKind :: Call ( call, _) = expr. kind
3636 && is_trait_item ( cx, call, sym:: Default )
3737 {
38+ let mut app = Applicability :: MachineApplicable ;
3839 let ret_ty = cx
3940 . typeck_results ( )
4041 . expr_ty ( call)
4142 . fn_sig ( cx. tcx )
4243 . output ( )
4344 . skip_binder ( )
4445 . peel_refs ( ) ;
45- if let Some ( default) = default_value ( cx, ret_ty) && !is_from_proc_macro ( cx, expr) {
46+ if let Some ( default) = default_value ( cx, ret_ty, & mut app ) && !is_from_proc_macro ( cx, expr) {
4647 span_lint_and_sugg (
4748 cx,
4849 TRIVIAL_DEFAULT_CONSTRUCTED_TYPES ,
@@ -55,7 +56,7 @@ impl<'tcx> LateLintPass<'tcx> for TrivialDefaultConstructedTypes {
5556 } else if let ty:: Tuple ( fields) = ret_ty. kind ( )
5657 && fields. len ( ) <= 3
5758 && let Some ( fields_default) = fields. iter ( )
58- . map ( |field| default_value ( cx, field) )
59+ . map ( |field| default_value ( cx, field, & mut app ) )
5960 . collect :: < Option < Vec < _ > > > ( )
6061 && !is_from_proc_macro ( cx, expr)
6162 {
@@ -79,7 +80,7 @@ impl<'tcx> LateLintPass<'tcx> for TrivialDefaultConstructedTypes {
7980 Applicability :: MachineApplicable ,
8081 ) ;
8182 } else if let ty:: Array ( ty, len) = ret_ty. kind ( )
82- && let Some ( default) = default_value ( cx, * ty)
83+ && let Some ( default) = default_value ( cx, * ty, & mut app )
8384 && !is_from_proc_macro ( cx, expr)
8485 {
8586 span_lint_and_sugg (
@@ -89,18 +90,21 @@ impl<'tcx> LateLintPass<'tcx> for TrivialDefaultConstructedTypes {
8990 "constructing a trivial array using `default`" ,
9091 "try" ,
9192 format ! ( "[{default}; {len}]" ) ,
92- Applicability :: MachineApplicable ,
93+ app ,
9394 ) ;
9495 }
9596 }
9697 }
9798}
9899
99100/// Gets the default value of `ty`.
100- fn default_value ( cx : & LateContext < ' _ > , ty : Ty < ' _ > ) -> Option < Cow < ' static , str > > {
101+ fn default_value ( cx : & LateContext < ' _ > , ty : Ty < ' _ > , app : & mut Applicability ) -> Option < Cow < ' static , str > > {
101102 match ty. kind ( ) {
102- ty:: Adt ( def, substs) if let [ subst] = substs. as_slice ( ) => {
103- is_lang_item_or_ctor ( cx, def. did ( ) , LangItem :: Option ) . then ( || format ! ( "None::<{subst}>" ) . into ( ) )
103+ ty:: Adt ( def, _) => {
104+ * app = Applicability :: HasPlaceholders ;
105+ // Checking if the generic argument is required would substantially increase the
106+ // complexity of this lint, for now, just use a placeholder (`_`).
107+ is_lang_item_or_ctor ( cx, def. did ( ) , LangItem :: Option ) . then ( || "None::<_>" . into ( ) )
104108 } ,
105109 ty:: Bool => Some ( "false" . into ( ) ) ,
106110 ty:: Str => Some ( r#""""# . into ( ) ) ,
0 commit comments