@@ -8,7 +8,7 @@ use std::cmp::Ordering;
8
8
use syntax:: ast:: { IntTy , UintTy , FloatTy } ;
9
9
use syntax:: attr:: IntType ;
10
10
use syntax:: codemap:: Span ;
11
- use utils:: { comparisons, higher, in_external_macro, in_macro, match_def_path, snippet, span_help_and_lint, span_lint,
11
+ use utils:: { comparisons, higher, in_external_macro, in_macro, match_def_path, snippet, span_help_and_lint, span_lint, span_lint_and_then ,
12
12
opt_def_id, last_path_segment, type_size} ;
13
13
use utils:: paths;
14
14
@@ -177,18 +177,40 @@ fn check_ty(cx: &LateContext, ast_ty: &hir::Ty) {
177
177
} ,
178
178
}
179
179
} ,
180
- TyRptr ( _ , MutTy { ref ty, .. } ) => {
180
+ TyRptr ( ref lt , MutTy { ref ty, ref mutbl } ) => {
181
181
match ty. node {
182
182
TyPath ( ref qpath) => {
183
183
let def = cx. tables . qpath_def ( qpath, ast_ty. id ) ;
184
184
if let Some ( def_id) = opt_def_id ( def) {
185
185
if Some ( def_id) == cx. tcx . lang_items . owned_box ( ) {
186
- span_help_and_lint ( cx,
187
- BORROWED_BOX ,
188
- ast_ty. span ,
189
- "you seem to be trying to use `&Box<T>`. Consider using just `&T`" ,
190
- "replace `&Box<T>` with simply `&T`" ) ;
191
- return ; // don't recurse into the type
186
+ if_let_chain ! { [
187
+ let & QPath :: Resolved ( None , ref path) = qpath,
188
+ let [ ref bx] = * path. segments,
189
+ let PathParameters :: AngleBracketedParameters ( ref ab_data) = bx. parameters,
190
+ let [ ref inner] = * ab_data. types
191
+ ] , {
192
+ let ltopt = if lt. is_elided( ) {
193
+ "" . to_owned( )
194
+ } else {
195
+ format!( "{} " , lt. name. as_str( ) )
196
+ } ;
197
+ let mutopt = if * mutbl == Mutability :: MutMutable {
198
+ "mut "
199
+ } else {
200
+ ""
201
+ } ;
202
+ span_lint_and_then( cx,
203
+ BORROWED_BOX ,
204
+ ast_ty. span,
205
+ "you seem to be trying to use `&Box<T>`. Consider using just `&T`" ,
206
+ |db| {
207
+ db. span_suggestion( ast_ty. span,
208
+ "try" ,
209
+ format!( "&{}{}{}" , ltopt, mutopt, & snippet( cx, inner. span, ".." ) ) ) ;
210
+ }
211
+ ) ;
212
+ return ; // don't recurse into the type
213
+ } } ;
192
214
}
193
215
}
194
216
check_ty ( cx, ty) ;
0 commit comments