@@ -56,39 +56,6 @@ impl LateLintPass<'_> for RcCloneInVecInit {
56
56
}
57
57
}
58
58
59
- struct LintSuggestion {
60
- message : String ,
61
- snippet : String ,
62
- }
63
-
64
- fn construct_lint_suggestions (
65
- cx : & LateContext < ' _ > ,
66
- span : Span ,
67
- symbol_name : & str ,
68
- elem : & Expr < ' _ > ,
69
- len : & Expr < ' _ > ,
70
- ) -> Vec < LintSuggestion > {
71
- let len_snippet = snippet ( cx, len. span , ".." ) ;
72
- let elem_snippet = elem_snippet ( cx, elem, symbol_name) ;
73
- let indentation = indent_of ( cx, span) . unwrap_or ( 0 ) ;
74
- let indentation = " " . repeat ( indentation) ;
75
- let loop_init_suggestion = loop_init_suggestion ( & elem_snippet, len_snippet. as_ref ( ) , & indentation) ;
76
- let extract_suggestion = extract_suggestion ( & elem_snippet, len_snippet. as_ref ( ) , & indentation) ;
77
-
78
- vec ! [
79
- LintSuggestion {
80
- message: format!( "consider initializing each `{symbol_name}` element individually" ) ,
81
- snippet: loop_init_suggestion,
82
- } ,
83
- LintSuggestion {
84
- message: format!(
85
- "or if this is intentional, consider extracting the `{symbol_name}` initialization to a variable"
86
- ) ,
87
- snippet: extract_suggestion,
88
- } ,
89
- ]
90
- }
91
-
92
59
fn elem_snippet ( cx : & LateContext < ' _ > , elem : & Expr < ' _ > , symbol_name : & str ) -> String {
93
60
let elem_snippet = snippet ( cx, elem. span , ".." ) . to_string ( ) ;
94
61
if elem_snippet. contains ( '\n' ) {
@@ -131,17 +98,27 @@ fn emit_lint(cx: &LateContext<'_>, symbol: Symbol, lint_span: Span, elem: &Expr<
131
98
lint_span,
132
99
& format ! ( "calling `{symbol_name}::new` in `vec![elem; len]`" ) ,
133
100
|diag| {
134
- let suggestions = construct_lint_suggestions ( cx, lint_span, symbol_name, elem, len) ;
101
+ let len_snippet = snippet ( cx, len. span , ".." ) ;
102
+ let elem_snippet = elem_snippet ( cx, elem, symbol_name) ;
103
+ let indentation = " " . repeat ( indent_of ( cx, lint_span) . unwrap_or ( 0 ) ) ;
104
+ let loop_init_suggestion = loop_init_suggestion ( & elem_snippet, len_snippet. as_ref ( ) , & indentation) ;
105
+ let extract_suggestion = extract_suggestion ( & elem_snippet, len_snippet. as_ref ( ) , & indentation) ;
135
106
136
107
diag. note ( format ! ( "each element will point to the same `{symbol_name}` instance" ) ) ;
137
- for suggestion in suggestions {
138
- diag. span_suggestion (
139
- lint_span,
140
- & suggestion. message ,
141
- & suggestion. snippet ,
142
- Applicability :: Unspecified ,
143
- ) ;
144
- }
108
+ diag. span_suggestion (
109
+ lint_span,
110
+ format ! ( "consider initializing each `{symbol_name}` element individually" ) ,
111
+ loop_init_suggestion,
112
+ Applicability :: Unspecified ,
113
+ ) ;
114
+ diag. span_suggestion (
115
+ lint_span,
116
+ format ! (
117
+ "or if this is intentional, consider extracting the `{symbol_name}` initialization to a variable"
118
+ ) ,
119
+ extract_suggestion,
120
+ Applicability :: Unspecified ,
121
+ ) ;
145
122
} ,
146
123
) ;
147
124
}
0 commit comments