Add notes for all potentially missing std::ops traits
This commit is contained in:
parent
6c209d1cc4
commit
c154782435
@ -191,20 +191,28 @@ fn check_overloaded_binop<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
|
|||||||
"binary operation `{}` cannot be applied to type `{}`",
|
"binary operation `{}` cannot be applied to type `{}`",
|
||||||
hir_util::binop_to_string(op.node),
|
hir_util::binop_to_string(op.node),
|
||||||
lhs_ty);
|
lhs_ty);
|
||||||
match op.node {
|
let missing_trait = match op.node {
|
||||||
hir::BiEq =>
|
hir::BiAdd => Some("std::ops::Add"),
|
||||||
span_note!(fcx.tcx().sess, lhs_expr.span,
|
hir::BiSub => Some("std::ops::Sub"),
|
||||||
"an implementation of `std::cmp::PartialEq` might be \
|
hir::BiMul => Some("std::ops::Mul"),
|
||||||
missing for `{}` or one of its type paramters",
|
hir::BiDiv => Some("std::ops::Div"),
|
||||||
lhs_ty),
|
hir::BiRem => Some("std::ops::Rem"),
|
||||||
|
hir::BiBitAnd => Some("std::ops::BitAnd"),
|
||||||
|
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 =>
|
hir::BiLt | hir::BiLe | hir::BiGt | hir::BiGe =>
|
||||||
span_note!(fcx.tcx().sess, lhs_expr.span,
|
Some("std::cmp::PartialOrd"),
|
||||||
"an implementation of `std::cmp::PartialOrd` might be \
|
_ => None
|
||||||
missing for `{}` or one of its type paramters",
|
|
||||||
lhs_ty),
|
|
||||||
_ => ()
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if let Some(missing_trait) = missing_trait {
|
||||||
|
span_note!(fcx.tcx().sess, lhs_expr.span,
|
||||||
|
"an implementation of `{}` might be missing for `{}` \
|
||||||
|
or one of its type arguments",
|
||||||
|
missing_trait, lhs_ty);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fcx.tcx().types.err
|
fcx.tcx().types.err
|
||||||
|
@ -1,20 +1,60 @@
|
|||||||
|
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
|
||||||
|
// file at the top-level directory of this distribution and at
|
||||||
|
// http://rust-lang.org/COPYRIGHT.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||||
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||||
|
// option. This file may not be copied, modified, or distributed
|
||||||
|
// except according to those terms.
|
||||||
|
|
||||||
struct A;
|
struct A;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let a = A;
|
let a = A;
|
||||||
|
|
||||||
if a == a {} //~ ERROR binary operation `==` cannot be applied to type `A`
|
a + a; //~ ERROR binary operation `+` cannot be applied to type `A`
|
||||||
//^~ NOTE an implementation of `std::cmp::PartialEq` might be missing for `A` or one of
|
//~^ NOTE an implementation of `std::ops::Add` might be missing for `A` or
|
||||||
|
|
||||||
if a < a {} //~ ERROR binary operation `<` cannot be applied to type `A`
|
a - a; //~ ERROR binary operation `-` cannot be applied to type `A`
|
||||||
//^~ NOTE an implementation of `std::cmp::PartialOrd` might be missing for `A` or one of
|
//~^ NOTE an implementation of `std::ops::Sub` might be missing for `A` or one of
|
||||||
|
|
||||||
if a <= a {} //~ ERROR binary operation `<=` cannot be applied to type `A`
|
a * a; //~ ERROR binary operation `*` cannot be applied to type `A`
|
||||||
//^~ NOTE an implementation of `std::cmp::PartialOrd` might be missing for `A` or one of
|
//~^ NOTE an implementation of `std::ops::Mul` might be missing for `A` or one of
|
||||||
|
|
||||||
if a > a {} //~ ERROR binary operation `>` cannot be applied to type `A`
|
a / a; //~ ERROR binary operation `/` cannot be applied to type `A`
|
||||||
//^~ NOTE an implementation of `std::cmp::PartialOrd` might be missing for `A` or one of
|
//~^ NOTE an implementation of `std::ops::Div` might be missing for `A` or one of
|
||||||
|
|
||||||
if a >= a {} //~ ERROR binary operation `>=` cannot be applied to type `A`
|
a % a; //~ ERROR binary operation `%` cannot be applied to type `A`
|
||||||
//^~ NOTE an implementation of `std::cmp::PartialOrd` might be missing for `A` or one of
|
//~^ NOTE an implementation of `std::ops::Rem` might be missing for `A` or one of
|
||||||
|
|
||||||
|
a & a; //~ ERROR binary operation `&` cannot be applied to type `A`
|
||||||
|
//~^ NOTE an implementation of `std::ops::BitAnd` might be missing for `A` or one of
|
||||||
|
|
||||||
|
a | a; //~ ERROR binary operation `|` cannot be applied to type `A`
|
||||||
|
//~^ NOTE an implementation of `std::ops::BitOr` might be missing for `A` or one of
|
||||||
|
|
||||||
|
a << a; //~ ERROR binary operation `<<` cannot be applied to type `A`
|
||||||
|
//~^ NOTE an implementation of `std::ops::Shl` might be missing for `A` or one of
|
||||||
|
|
||||||
|
a >> a; //~ ERROR binary operation `>>` cannot be applied to type `A`
|
||||||
|
//~^ NOTE an implementation of `std::ops::Shr` might be missing for `A` or one of
|
||||||
|
|
||||||
|
a == a; //~ ERROR binary operation `==` cannot be applied to type `A`
|
||||||
|
//~^ NOTE an implementation of `std::cmp::PartialEq` might be missing for `A` or one of
|
||||||
|
|
||||||
|
a != a; //~ ERROR binary operation `!=` cannot be applied to type `A`
|
||||||
|
//~^ NOTE an implementation of `std::cmp::PartialEq` might be missing for `A` or one of
|
||||||
|
|
||||||
|
a < a; //~ ERROR binary operation `<` cannot be applied to type `A`
|
||||||
|
//~^ NOTE an implementation of `std::cmp::PartialOrd` might be missing for `A` or one of
|
||||||
|
|
||||||
|
a <= a; //~ ERROR binary operation `<=` cannot be applied to type `A`
|
||||||
|
//~^ NOTE an implementation of `std::cmp::PartialOrd` might be missing for `A` or one of
|
||||||
|
|
||||||
|
a > a; //~ ERROR binary operation `>` cannot be applied to type `A`
|
||||||
|
//~^ NOTE an implementation of `std::cmp::PartialOrd` might be missing for `A` or one of
|
||||||
|
|
||||||
|
a >= a; //~ ERROR binary operation `>=` cannot be applied to type `A`
|
||||||
|
//~^ NOTE an implementation of `std::cmp::PartialOrd` might be missing for `A` or one of
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user