@@ -121,6 +121,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue {
121
121
122
122
// Suggestion logic
123
123
let sugg = |db: & mut DiagnosticBuilder | {
124
+ let deref_span = spans_need_deref. get( & defid) ;
124
125
if_let_chain! { [
125
126
match_type( cx, ty, & paths:: VEC ) ,
126
127
let TyPath ( QPath :: Resolved ( _, ref path) ) = input. node,
@@ -132,20 +133,22 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue {
132
133
db. span_suggestion( input. span,
133
134
& format!( "consider changing the type to `{}`" , slice_ty) ,
134
135
slice_ty) ;
136
+ assert!( deref_span. is_none( ) ) ;
135
137
return ; // `Vec` and `String` cannot be destructured - no need for `*` suggestion
136
138
} }
137
139
138
140
if match_type( cx, ty, & paths:: STRING ) {
139
141
db. span_suggestion( input. span,
140
142
"consider changing the type to `&str`" ,
141
143
"&str" . to_string( ) ) ;
144
+ assert!( deref_span. is_none( ) ) ;
142
145
return ;
143
146
}
144
147
145
148
let mut spans = vec![ ( input. span, format!( "&{}" , snippet( cx, input. span, "_" ) ) ) ] ;
146
149
147
150
// Suggests adding `*` to dereference the added reference.
148
- if let Some ( deref_span) = spans_need_deref . get ( & defid ) {
151
+ if let Some ( deref_span) = deref_span {
149
152
spans. extend( deref_span. iter( ) . cloned( )
150
153
. map( |span| ( span, format!( "*{}" , snippet( cx, span, "<expr>" ) ) ) ) ) ;
151
154
spans. sort_by_key( |& ( span, _) | span) ;
0 commit comments