@@ -246,7 +246,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
246
246
Err ( ( ) ) => {
247
247
// error types are considered "builtin"
248
248
if !lhs_ty. references_error ( ) {
249
- match is_assign{
249
+ let codemap = self . tcx . sess . codemap ( ) ;
250
+ match is_assign {
250
251
IsAssign :: Yes => {
251
252
let mut err = struct_span_err ! ( self . tcx. sess, expr. span, E0368 ,
252
253
"binary assignment operation `{}=` \
@@ -256,19 +257,6 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
256
257
err. span_label ( lhs_expr. span ,
257
258
format ! ( "cannot use `{}=` on type `{}`" ,
258
259
op. node. as_str( ) , lhs_ty) ) ;
259
- let missing_trait = match op. node {
260
- hir:: BiAdd => Some ( "std::ops::AddAssign" ) ,
261
- hir:: BiSub => Some ( "std::ops::SubAssign" ) ,
262
- hir:: BiMul => Some ( "std::ops::MulAssign" ) ,
263
- hir:: BiDiv => Some ( "std::ops::DivAssign" ) ,
264
- hir:: BiRem => Some ( "std::ops::RemAssign" ) ,
265
- hir:: BiBitAnd => Some ( "std::ops::BitAndAssign" ) ,
266
- hir:: BiBitXor => Some ( "std::ops::BitXorAssign" ) ,
267
- hir:: BiBitOr => Some ( "std::ops::BitOrAssign" ) ,
268
- hir:: BiShl => Some ( "std::ops::ShlAssign" ) ,
269
- hir:: BiShr => Some ( "std::ops::ShrAssign" ) ,
270
- _ => None
271
- } ;
272
260
let mut suggested_deref = false ;
273
261
if let TyRef ( _, ref ty_mut) = lhs_ty. sty {
274
262
if {
@@ -280,22 +268,31 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
280
268
Op :: Binary ( op, is_assign) )
281
269
. is_ok ( )
282
270
} {
283
- let codemap = self . tcx . sess . codemap ( ) ;
284
- match codemap. span_to_snippet ( lhs_expr. span ) {
285
- Ok ( lstring) =>{
286
- let msg = & format ! (
271
+ if let Ok ( lstring) = codemap. span_to_snippet ( lhs_expr. span ) {
272
+ let msg = & format ! (
287
273
"`{}=` can be used on '{}', you can \
288
274
dereference `{2}`: `*{2}`",
289
275
op. node. as_str( ) , ty_mut. ty, lstring) ;
290
- err. help ( msg) ;
291
- suggested_deref = true ;
292
- } ,
293
- _ => { }
294
- } ;
276
+ err. help ( msg) ;
277
+ suggested_deref = true ;
278
+ }
295
279
}
296
280
}
281
+ let missing_trait = match op. node {
282
+ hir:: BiAdd => Some ( "std::ops::AddAssign" ) ,
283
+ hir:: BiSub => Some ( "std::ops::SubAssign" ) ,
284
+ hir:: BiMul => Some ( "std::ops::MulAssign" ) ,
285
+ hir:: BiDiv => Some ( "std::ops::DivAssign" ) ,
286
+ hir:: BiRem => Some ( "std::ops::RemAssign" ) ,
287
+ hir:: BiBitAnd => Some ( "std::ops::BitAndAssign" ) ,
288
+ hir:: BiBitXor => Some ( "std::ops::BitXorAssign" ) ,
289
+ hir:: BiBitOr => Some ( "std::ops::BitOrAssign" ) ,
290
+ hir:: BiShl => Some ( "std::ops::ShlAssign" ) ,
291
+ hir:: BiShr => Some ( "std::ops::ShrAssign" ) ,
292
+ _ => None
293
+ } ;
297
294
if let Some ( missing_trait) = missing_trait {
298
- if missing_trait == "std::ops::AddAssign" &&
295
+ if op . node == hir :: BiAdd &&
299
296
self . check_str_addition ( expr, lhs_expr, rhs_expr, lhs_ty,
300
297
rhs_ty, & mut err) {
301
298
// This has nothing here because it means we did string
@@ -306,13 +303,11 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
306
303
err. note (
307
304
& format ! ( "`{}` might need a bound for `{}`" ,
308
305
lhs_ty, missing_trait) ) ;
309
- } else {
310
- if !suggested_deref{
311
- err. note (
312
- & format ! ( "an implementation of `{}` might \
313
- be missing for `{}`",
314
- missing_trait, lhs_ty) ) ;
315
- }
306
+ } else if !suggested_deref {
307
+ err. note (
308
+ & format ! ( "an implementation of `{}` might \
309
+ be missing for `{}`",
310
+ missing_trait, lhs_ty) ) ;
316
311
}
317
312
}
318
313
err. emit ( ) ;
@@ -322,22 +317,6 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
322
317
"binary operation `{}` cannot be applied to type `{}`" ,
323
318
op. node. as_str( ) ,
324
319
lhs_ty) ;
325
- let missing_trait = match op. node {
326
- hir:: BiAdd => Some ( "std::ops::Add" ) ,
327
- hir:: BiSub => Some ( "std::ops::Sub" ) ,
328
- hir:: BiMul => Some ( "std::ops::Mul" ) ,
329
- hir:: BiDiv => Some ( "std::ops::Div" ) ,
330
- hir:: BiRem => Some ( "std::ops::Rem" ) ,
331
- hir:: BiBitAnd => Some ( "std::ops::BitAnd" ) ,
332
- hir:: BiBitXor => Some ( "std::ops::BitXor" ) ,
333
- hir:: BiBitOr => Some ( "std::ops::BitOr" ) ,
334
- hir:: BiShl => Some ( "std::ops::Shl" ) ,
335
- hir:: BiShr => Some ( "std::ops::Shr" ) ,
336
- hir:: BiEq | hir:: BiNe => Some ( "std::cmp::PartialEq" ) ,
337
- hir:: BiLt | hir:: BiLe | hir:: BiGt | hir:: BiGe =>
338
- Some ( "std::cmp::PartialOrd" ) ,
339
- _ => None
340
- } ;
341
320
let mut suggested_deref = false ;
342
321
if let TyRef ( _, ref ty_mut) = lhs_ty. sty {
343
322
if {
@@ -349,22 +328,34 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
349
328
Op :: Binary ( op, is_assign) )
350
329
. is_ok ( )
351
330
} {
352
- let codemap = self . tcx . sess . codemap ( ) ;
353
- match codemap. span_to_snippet ( lhs_expr. span ) {
354
- Ok ( lstring) =>{
355
- let msg = & format ! (
331
+ if let Ok ( lstring) = codemap. span_to_snippet ( lhs_expr. span ) {
332
+ let msg = & format ! (
356
333
"`{}` can be used on '{}', you can \
357
334
dereference `{2}`: `*{2}`",
358
335
op. node. as_str( ) , ty_mut. ty, lstring) ;
359
- err. help ( msg) ;
360
- suggested_deref = true ;
361
- } ,
362
- _ =>{ }
336
+ err. help ( msg) ;
337
+ suggested_deref = true ;
363
338
}
364
339
}
365
340
}
341
+ let missing_trait = match op. node {
342
+ hir:: BiAdd => Some ( "std::ops::Add" ) ,
343
+ hir:: BiSub => Some ( "std::ops::Sub" ) ,
344
+ hir:: BiMul => Some ( "std::ops::Mul" ) ,
345
+ hir:: BiDiv => Some ( "std::ops::Div" ) ,
346
+ hir:: BiRem => Some ( "std::ops::Rem" ) ,
347
+ hir:: BiBitAnd => Some ( "std::ops::BitAnd" ) ,
348
+ hir:: BiBitXor => Some ( "std::ops::BitXor" ) ,
349
+ hir:: BiBitOr => Some ( "std::ops::BitOr" ) ,
350
+ hir:: BiShl => Some ( "std::ops::Shl" ) ,
351
+ hir:: BiShr => Some ( "std::ops::Shr" ) ,
352
+ hir:: BiEq | hir:: BiNe => Some ( "std::cmp::PartialEq" ) ,
353
+ hir:: BiLt | hir:: BiLe | hir:: BiGt | hir:: BiGe =>
354
+ Some ( "std::cmp::PartialOrd" ) ,
355
+ _ => None
356
+ } ;
366
357
if let Some ( missing_trait) = missing_trait {
367
- if missing_trait == "std::ops::Add" &&
358
+ if op . node == hir :: BiAdd &&
368
359
self . check_str_addition ( expr, lhs_expr, rhs_expr, lhs_ty,
369
360
rhs_ty, & mut err) {
370
361
// This has nothing here because it means we did string
@@ -375,13 +366,11 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
375
366
err. note (
376
367
& format ! ( "`{}` might need a bound for `{}`" ,
377
368
lhs_ty, missing_trait) ) ;
378
- } else {
379
- if !suggested_deref{
380
- err. note (
381
- & format ! ( "an implementation of `{}` might \
382
- be missing for `{}`",
383
- missing_trait, lhs_ty) ) ;
384
- }
369
+ } else if !suggested_deref {
370
+ err. note (
371
+ & format ! ( "an implementation of `{}` might \
372
+ be missing for `{}`",
373
+ missing_trait, lhs_ty) ) ;
385
374
}
386
375
}
387
376
err. emit ( ) ;
@@ -468,20 +457,18 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
468
457
op. as_str( ) , actual) ;
469
458
err. span_label ( ex. span , format ! ( "cannot apply unary \
470
459
operator `{}`", op. as_str( ) ) ) ;
471
- let missing_trait = match op {
472
- hir:: UnNeg => "std::ops::Neg" ,
473
- hir:: UnNot => "std::ops::Not" ,
474
- hir:: UnDeref => "std::ops::UnDerf"
475
- } ;
476
- match actual. sty {
477
- TyUint ( _) => {
478
- if op == hir:: UnNeg {
479
- err. note ( & format ! ( "unsigned values cannot be negated" ) ) ;
480
- }
460
+ match actual. sty {
461
+ TyUint ( _) if op == hir:: UnNeg => {
462
+ err. note ( & format ! ( "unsigned values cannot be negated" ) ) ;
481
463
} ,
482
464
TyStr | TyNever | TyChar | TyTuple ( _) | TyArray ( _, _) => { } ,
483
465
TyRef ( _, ref lty) if lty. ty . sty == TyStr => { } ,
484
466
_ => {
467
+ let missing_trait = match op {
468
+ hir:: UnNeg => "std::ops::Neg" ,
469
+ hir:: UnNot => "std::ops::Not" ,
470
+ hir:: UnDeref => "std::ops::UnDerf"
471
+ } ;
485
472
err. note ( & format ! ( "an implementation of `{}` might \
486
473
be missing for `{}`",
487
474
missing_trait, operand_ty) ) ;
0 commit comments