Err(()) => {
// error types are considered "builtin"
if !lhs_ty.references_error() {
- match is_assign{
+ let codemap = self.tcx.sess.codemap();
+ match is_assign {
IsAssign::Yes => {
let mut err = struct_span_err!(self.tcx.sess, expr.span, E0368,
"binary assignment operation `{}=` \
err.span_label(lhs_expr.span,
format!("cannot use `{}=` on type `{}`",
op.node.as_str(), lhs_ty));
- let missing_trait = match op.node {
- hir::BiAdd => Some("std::ops::AddAssign"),
- hir::BiSub => Some("std::ops::SubAssign"),
- hir::BiMul => Some("std::ops::MulAssign"),
- hir::BiDiv => Some("std::ops::DivAssign"),
- hir::BiRem => Some("std::ops::RemAssign"),
- hir::BiBitAnd => Some("std::ops::BitAndAssign"),
- hir::BiBitXor => Some("std::ops::BitXorAssign"),
- hir::BiBitOr => Some("std::ops::BitOrAssign"),
- hir::BiShl => Some("std::ops::ShlAssign"),
- hir::BiShr => Some("std::ops::ShrAssign"),
- _ => None
- };
let mut suggested_deref = false;
if let TyRef(_, ref ty_mut) = lhs_ty.sty {
if {
Op::Binary(op, is_assign))
.is_ok()
} {
- let codemap = self.tcx.sess.codemap();
- match codemap.span_to_snippet(lhs_expr.span) {
- Ok(lstring) =>{
- let msg = &format!(
+ if let Ok(lstring) = codemap.span_to_snippet(lhs_expr.span) {
+ let msg = &format!(
"`{}=` can be used on '{}', you can \
dereference `{2}`: `*{2}`",
op.node.as_str(), ty_mut.ty, lstring);
- err.help(msg);
- suggested_deref = true;
- },
- _ => {}
- };
+ err.help(msg);
+ suggested_deref = true;
+ }
}
}
+ let missing_trait = match op.node {
+ hir::BiAdd => Some("std::ops::AddAssign"),
+ hir::BiSub => Some("std::ops::SubAssign"),
+ hir::BiMul => Some("std::ops::MulAssign"),
+ hir::BiDiv => Some("std::ops::DivAssign"),
+ hir::BiRem => Some("std::ops::RemAssign"),
+ hir::BiBitAnd => Some("std::ops::BitAndAssign"),
+ hir::BiBitXor => Some("std::ops::BitXorAssign"),
+ hir::BiBitOr => Some("std::ops::BitOrAssign"),
+ hir::BiShl => Some("std::ops::ShlAssign"),
+ hir::BiShr => Some("std::ops::ShrAssign"),
+ _ => None
+ };
if let Some(missing_trait) = missing_trait {
- if missing_trait == "std::ops::AddAssign" &&
+ if op.node == hir::BiAdd &&
self.check_str_addition(expr, lhs_expr, rhs_expr, lhs_ty,
rhs_ty, &mut err) {
// This has nothing here because it means we did string
err.note(
&format!("`{}` might need a bound for `{}`",
lhs_ty, missing_trait));
- } else {
- if !suggested_deref{
- err.note(
- &format!("an implementation of `{}` might \
- be missing for `{}`",
- missing_trait, lhs_ty));
- }
+ } else if !suggested_deref {
+ err.note(
+ &format!("an implementation of `{}` might \
+ be missing for `{}`",
+ missing_trait, lhs_ty));
}
}
err.emit();
"binary operation `{}` cannot be applied to type `{}`",
op.node.as_str(),
lhs_ty);
- let missing_trait = match op.node {
- hir::BiAdd => Some("std::ops::Add"),
- hir::BiSub => Some("std::ops::Sub"),
- hir::BiMul => Some("std::ops::Mul"),
- hir::BiDiv => Some("std::ops::Div"),
- hir::BiRem => Some("std::ops::Rem"),
- hir::BiBitAnd => Some("std::ops::BitAnd"),
- hir::BiBitXor => Some("std::ops::BitXor"),
- hir::BiBitOr => Some("std::ops::BitOr"),
- hir::BiShl => Some("std::ops::Shl"),
- hir::BiShr => Some("std::ops::Shr"),
- hir::BiEq | hir::BiNe => Some("std::cmp::PartialEq"),
- hir::BiLt | hir::BiLe | hir::BiGt | hir::BiGe =>
- Some("std::cmp::PartialOrd"),
- _ => None
- };
let mut suggested_deref = false;
if let TyRef(_, ref ty_mut) = lhs_ty.sty {
if {
Op::Binary(op, is_assign))
.is_ok()
} {
- let codemap = self.tcx.sess.codemap();
- match codemap.span_to_snippet(lhs_expr.span) {
- Ok(lstring) =>{
- let msg = &format!(
+ if let Ok(lstring) = codemap.span_to_snippet(lhs_expr.span) {
+ let msg = &format!(
"`{}` can be used on '{}', you can \
dereference `{2}`: `*{2}`",
op.node.as_str(), ty_mut.ty, lstring);
- err.help(msg);
- suggested_deref = true;
- },
- _ =>{}
+ err.help(msg);
+ suggested_deref = true;
}
}
}
+ let missing_trait = match op.node {
+ hir::BiAdd => Some("std::ops::Add"),
+ hir::BiSub => Some("std::ops::Sub"),
+ hir::BiMul => Some("std::ops::Mul"),
+ hir::BiDiv => Some("std::ops::Div"),
+ hir::BiRem => Some("std::ops::Rem"),
+ hir::BiBitAnd => Some("std::ops::BitAnd"),
+ hir::BiBitXor => Some("std::ops::BitXor"),
+ hir::BiBitOr => Some("std::ops::BitOr"),
+ hir::BiShl => Some("std::ops::Shl"),
+ hir::BiShr => Some("std::ops::Shr"),
+ hir::BiEq | hir::BiNe => Some("std::cmp::PartialEq"),
+ hir::BiLt | hir::BiLe | hir::BiGt | hir::BiGe =>
+ Some("std::cmp::PartialOrd"),
+ _ => None
+ };
if let Some(missing_trait) = missing_trait {
- if missing_trait == "std::ops::Add" &&
+ if op.node == hir::BiAdd &&
self.check_str_addition(expr, lhs_expr, rhs_expr, lhs_ty,
rhs_ty, &mut err) {
// This has nothing here because it means we did string
err.note(
&format!("`{}` might need a bound for `{}`",
lhs_ty, missing_trait));
- } else {
- if !suggested_deref{
- err.note(
- &format!("an implementation of `{}` might \
- be missing for `{}`",
- missing_trait, lhs_ty));
- }
+ } else if !suggested_deref {
+ err.note(
+ &format!("an implementation of `{}` might \
+ be missing for `{}`",
+ missing_trait, lhs_ty));
}
}
err.emit();
op.as_str(), actual);
err.span_label(ex.span, format!("cannot apply unary \
operator `{}`", op.as_str()));
- let missing_trait = match op {
- hir::UnNeg => "std::ops::Neg",
- hir::UnNot => "std::ops::Not",
- hir::UnDeref => "std::ops::UnDerf"
- };
- match actual.sty{
- TyUint(_) => {
- if op == hir::UnNeg{
- err.note(&format!("unsigned values cannot be negated"));
- }
+ match actual.sty {
+ TyUint(_) if op == hir::UnNeg => {
+ err.note(&format!("unsigned values cannot be negated"));
},
TyStr | TyNever | TyChar | TyTuple(_) | TyArray(_,_) => {},
TyRef(_, ref lty) if lty.ty.sty == TyStr => {},
_ => {
+ let missing_trait = match op {
+ hir::UnNeg => "std::ops::Neg",
+ hir::UnNot => "std::ops::Not",
+ hir::UnDeref => "std::ops::UnDerf"
+ };
err.note(&format!("an implementation of `{}` might \
be missing for `{}`",
missing_trait, operand_ty));