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