@@ -334,10 +334,51 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
334334 err. emit ( ) ;
335335 }
336336 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+ _ => ( format ! ( "binary operation `{}` cannot be applied to type `{}`" , op. node. as_str( ) , lhs_ty) , None )
379+ } ;
337380 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) ;
381+ "{}" , message. as_str( ) ) ;
341382
342383 let mut involves_fn = false ;
343384 if !lhs_expr. span . eq ( & rhs_expr. span ) {
@@ -382,25 +423,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
382423 }
383424 }
384425 }
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- } ;
404426 if let Some ( missing_trait) = missing_trait {
405427 if op. node == hir:: BinOpKind :: Add &&
406428 self . check_str_addition (
0 commit comments