@@ -76,43 +76,37 @@ pub(super) fn check(
76
76
&& !usage:: BindingUsageFinder :: are_params_used ( cx, body_hir)
77
77
&& let Some ( count) = extract_count_with_applicability ( cx, range, & mut applicability)
78
78
{
79
+ let method_to_use_name;
80
+ let new_span;
81
+
79
82
if eager_or_lazy:: switch_to_eager_eval ( cx, body_expr) {
83
+ method_to_use_name = "repeat" ;
80
84
let body_snippet = snippet_with_applicability ( cx, body_expr. span , ".." , & mut applicability) ;
81
- span_lint_and_then (
82
- cx,
83
- MAP_WITH_UNUSED_ARGUMENT_OVER_RANGES ,
84
- ex. span ,
85
- "map of a closure that does not depend on its parameter over a range" ,
86
- |diag| {
87
- diag. multipart_suggestion (
88
- "remove the explicit range and use `repeat` and `take`" ,
89
- vec ! [
90
- ( receiver. span. to( method_call_span) , "std::iter::repeat" . to_owned( ) ) ,
91
- ( arg. span, body_snippet. to_string( ) ) ,
92
- ( ex. span. shrink_to_hi( ) , format!( ".take({count})" ) ) ,
93
- ] ,
94
- applicability,
95
- ) ;
96
- } ,
97
- ) ;
85
+ new_span = ( arg. span , body_snippet. to_string ( ) ) ;
98
86
} else {
99
- span_lint_and_then (
100
- cx,
101
- MAP_WITH_UNUSED_ARGUMENT_OVER_RANGES ,
102
- ex. span ,
103
- "map of a closure that does not depend on its parameter over a range" ,
104
- |diag| {
105
- diag. multipart_suggestion (
106
- "remove the explicit range and use `repeat_with` and `take`" ,
107
- vec ! [
108
- ( receiver. span. to( method_call_span) , "std::iter::repeat_with" . to_owned( ) ) ,
109
- ( param. span, String :: new( ) ) ,
110
- ( ex. span. shrink_to_hi( ) , format!( ".take({count})" ) ) ,
111
- ] ,
112
- applicability,
113
- ) ;
114
- } ,
115
- ) ;
87
+ method_to_use_name = "repeat_with" ;
88
+ new_span = ( param. span , String :: new ( ) ) ;
116
89
}
90
+
91
+ span_lint_and_then (
92
+ cx,
93
+ MAP_WITH_UNUSED_ARGUMENT_OVER_RANGES ,
94
+ ex. span ,
95
+ "map of a closure that does not depend on its parameter over a range" ,
96
+ |diag| {
97
+ diag. multipart_suggestion (
98
+ format ! ( "remove the explicit range and use `{method_to_use_name}` and `take`" ) ,
99
+ vec ! [
100
+ (
101
+ receiver. span. to( method_call_span) ,
102
+ format!( "std::iter::{method_to_use_name}" ) ,
103
+ ) ,
104
+ new_span,
105
+ ( ex. span. shrink_to_hi( ) , format!( ".take({count})" ) ) ,
106
+ ] ,
107
+ applicability,
108
+ ) ;
109
+ } ,
110
+ ) ;
117
111
}
118
112
}
0 commit comments