@@ -334,10 +334,70 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
334
334
err. emit ( ) ;
335
335
}
336
336
IsAssign :: No => {
337
+ let ( message, missing_trait) = match op. node {
338
+ hir:: BinOpKind :: Add => {
339
+ ( format ! ( "cannot add `{}` to `{}`" , rhs_ty, lhs_ty) ,
340
+ Some ( "std::ops::Add" ) )
341
+ } ,
342
+ hir:: BinOpKind :: Sub => {
343
+ ( format ! ( "cannot substract `{}` from `{}`" , rhs_ty, lhs_ty) ,
344
+ Some ( "std::ops::Sub" ) )
345
+ } ,
346
+ hir:: BinOpKind :: Mul => {
347
+ ( format ! ( "cannot multiply `{}` to `{}`" , rhs_ty, lhs_ty) ,
348
+ Some ( "std::ops::Mul" ) )
349
+ } ,
350
+ hir:: BinOpKind :: Div => {
351
+ ( format ! ( "cannot divide `{}` by `{}`" , lhs_ty, rhs_ty) ,
352
+ Some ( "std::ops::Div" ) )
353
+ } ,
354
+ hir:: BinOpKind :: Rem => {
355
+ ( format ! ( "cannot mod `{}` by `{}`" , lhs_ty, rhs_ty) ,
356
+ Some ( "std::ops::Rem" ) )
357
+ } ,
358
+ hir:: BinOpKind :: BitAnd => {
359
+ ( format ! ( "no implementation for `{} & {}`" , lhs_ty, rhs_ty) ,
360
+ Some ( "std::ops::BitAnd" ) )
361
+ } ,
362
+ hir:: BinOpKind :: BitXor => {
363
+ ( format ! ( "no implementation for `{} ^ {}`" , lhs_ty, rhs_ty) ,
364
+ Some ( "std::ops::BitXor" ) )
365
+ } ,
366
+ hir:: BinOpKind :: BitOr => {
367
+ ( format ! ( "no implementation for `{} | {}`" , lhs_ty, rhs_ty) ,
368
+ Some ( "std::ops::BitOr" ) )
369
+ } ,
370
+ hir:: BinOpKind :: Shl => {
371
+ ( format ! ( "no implementation for `{} << {}`" , lhs_ty, rhs_ty) ,
372
+ Some ( "std::ops::Shl" ) )
373
+ } ,
374
+ hir:: BinOpKind :: Shr => {
375
+ ( format ! ( "no implementation for `{} >> {}`" , lhs_ty, rhs_ty) ,
376
+ Some ( "std::ops::Shr" ) )
377
+ } ,
378
+ hir:: BinOpKind :: Eq |
379
+ hir:: BinOpKind :: Ne => {
380
+ ( format ! (
381
+ "binary operation `{}` cannot be applied to type `{}`" ,
382
+ op. node. as_str( ) , lhs_ty) ,
383
+ Some ( "std::cmp::PartialEq" ) )
384
+ } ,
385
+ hir:: BinOpKind :: Lt |
386
+ hir:: BinOpKind :: Le |
387
+ hir:: BinOpKind :: Gt |
388
+ hir:: BinOpKind :: Ge => {
389
+ ( format ! (
390
+ "binary operation `{}` cannot be applied to type `{}`" ,
391
+ op. node. as_str( ) , lhs_ty) ,
392
+ Some ( "std::cmp::PartialOrd" ) )
393
+ }
394
+ _ => ( format ! (
395
+ "binary operation `{}` cannot be applied to type `{}`" ,
396
+ op. node. as_str( ) , lhs_ty) ,
397
+ None )
398
+ } ;
337
399
let mut err = struct_span_err ! ( self . tcx. sess, op. span, E0369 ,
338
- "binary operation `{}` cannot be applied to type `{}`" ,
339
- op. node. as_str( ) ,
340
- lhs_ty) ;
400
+ "{}" , message. as_str( ) ) ;
341
401
342
402
let mut involves_fn = false ;
343
403
if !lhs_expr. span . eq ( & rhs_expr. span ) {
@@ -382,25 +442,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
382
442
}
383
443
}
384
444
}
385
- let missing_trait = match op. node {
386
- hir:: BinOpKind :: Add => Some ( "std::ops::Add" ) ,
387
- hir:: BinOpKind :: Sub => Some ( "std::ops::Sub" ) ,
388
- hir:: BinOpKind :: Mul => Some ( "std::ops::Mul" ) ,
389
- hir:: BinOpKind :: Div => Some ( "std::ops::Div" ) ,
390
- hir:: BinOpKind :: Rem => Some ( "std::ops::Rem" ) ,
391
- hir:: BinOpKind :: BitAnd => Some ( "std::ops::BitAnd" ) ,
392
- hir:: BinOpKind :: BitXor => Some ( "std::ops::BitXor" ) ,
393
- hir:: BinOpKind :: BitOr => Some ( "std::ops::BitOr" ) ,
394
- hir:: BinOpKind :: Shl => Some ( "std::ops::Shl" ) ,
395
- hir:: BinOpKind :: Shr => Some ( "std::ops::Shr" ) ,
396
- hir:: BinOpKind :: Eq |
397
- hir:: BinOpKind :: Ne => Some ( "std::cmp::PartialEq" ) ,
398
- hir:: BinOpKind :: Lt |
399
- hir:: BinOpKind :: Le |
400
- hir:: BinOpKind :: Gt |
401
- hir:: BinOpKind :: Ge => Some ( "std::cmp::PartialOrd" ) ,
402
- _ => None
403
- } ;
404
445
if let Some ( missing_trait) = missing_trait {
405
446
if op. node == hir:: BinOpKind :: Add &&
406
447
self . check_str_addition (
0 commit comments