Auto merge of #40565 - estebank:binops-help, r=arielb1
Explicit help message for binop type mismatch When trying to do `1 + Some(2)`, or some other binary operation on two types different types without an appropriate trait implementation, provide an explicit help message: ```rust help: `{integer} + std::option::Option<{integer}>` has no implementation ``` Re: #39579, #38564, #37626, #39942, #34698.
This commit is contained in:
commit
730e5ad04e
@ -102,6 +102,7 @@ use self::Ordering::*;
|
|||||||
/// ```
|
/// ```
|
||||||
#[lang = "eq"]
|
#[lang = "eq"]
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
#[rustc_on_unimplemented = "can't compare `{Self}` with `{Rhs}`"]
|
||||||
pub trait PartialEq<Rhs: ?Sized = Self> {
|
pub trait PartialEq<Rhs: ?Sized = Self> {
|
||||||
/// This method tests for `self` and `other` values to be equal, and is used
|
/// This method tests for `self` and `other` values to be equal, and is used
|
||||||
/// by `==`.
|
/// by `==`.
|
||||||
@ -550,6 +551,7 @@ impl PartialOrd for Ordering {
|
|||||||
/// ```
|
/// ```
|
||||||
#[lang = "ord"]
|
#[lang = "ord"]
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
#[rustc_on_unimplemented = "can't compare `{Self}` with `{Rhs}`"]
|
||||||
pub trait PartialOrd<Rhs: ?Sized = Self>: PartialEq<Rhs> {
|
pub trait PartialOrd<Rhs: ?Sized = Self>: PartialEq<Rhs> {
|
||||||
/// This method returns an ordering between `self` and `other` values if one exists.
|
/// This method returns an ordering between `self` and `other` values if one exists.
|
||||||
///
|
///
|
||||||
|
@ -242,6 +242,7 @@ pub trait Drop {
|
|||||||
/// [std::time::SystemTime]: ../../std/time/struct.SystemTime.html
|
/// [std::time::SystemTime]: ../../std/time/struct.SystemTime.html
|
||||||
#[lang = "add"]
|
#[lang = "add"]
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
#[rustc_on_unimplemented = "no implementation for `{Self} + {RHS}`"]
|
||||||
pub trait Add<RHS=Self> {
|
pub trait Add<RHS=Self> {
|
||||||
/// The resulting type after applying the `+` operator
|
/// The resulting type after applying the `+` operator
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
@ -315,6 +316,7 @@ add_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f32 f64 }
|
|||||||
/// [std::time::SystemTime]: ../../std/time/struct.SystemTime.html
|
/// [std::time::SystemTime]: ../../std/time/struct.SystemTime.html
|
||||||
#[lang = "sub"]
|
#[lang = "sub"]
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
#[rustc_on_unimplemented = "no implementation for `{Self} - {RHS}`"]
|
||||||
pub trait Sub<RHS=Self> {
|
pub trait Sub<RHS=Self> {
|
||||||
/// The resulting type after applying the `-` operator
|
/// The resulting type after applying the `-` operator
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
@ -437,6 +439,7 @@ sub_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f32 f64 }
|
|||||||
/// ```
|
/// ```
|
||||||
#[lang = "mul"]
|
#[lang = "mul"]
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
#[rustc_on_unimplemented = "no implementation for `{Self} * {RHS}`"]
|
||||||
pub trait Mul<RHS=Self> {
|
pub trait Mul<RHS=Self> {
|
||||||
/// The resulting type after applying the `*` operator
|
/// The resulting type after applying the `*` operator
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
@ -565,6 +568,7 @@ mul_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f32 f64 }
|
|||||||
/// ```
|
/// ```
|
||||||
#[lang = "div"]
|
#[lang = "div"]
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
#[rustc_on_unimplemented = "no implementation for `{Self} / {RHS}`"]
|
||||||
pub trait Div<RHS=Self> {
|
pub trait Div<RHS=Self> {
|
||||||
/// The resulting type after applying the `/` operator
|
/// The resulting type after applying the `/` operator
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
@ -644,6 +648,7 @@ div_impl_float! { f32 f64 }
|
|||||||
/// ```
|
/// ```
|
||||||
#[lang = "rem"]
|
#[lang = "rem"]
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
#[rustc_on_unimplemented = "no implementation for `{Self} % {RHS}`"]
|
||||||
pub trait Rem<RHS=Self> {
|
pub trait Rem<RHS=Self> {
|
||||||
/// The resulting type after applying the `%` operator
|
/// The resulting type after applying the `%` operator
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
@ -883,6 +888,7 @@ not_impl! { bool usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 }
|
|||||||
/// ```
|
/// ```
|
||||||
#[lang = "bitand"]
|
#[lang = "bitand"]
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
#[rustc_on_unimplemented = "no implementation for `{Self} & {RHS}`"]
|
||||||
pub trait BitAnd<RHS=Self> {
|
pub trait BitAnd<RHS=Self> {
|
||||||
/// The resulting type after applying the `&` operator
|
/// The resulting type after applying the `&` operator
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
@ -966,6 +972,7 @@ bitand_impl! { bool usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 }
|
|||||||
/// ```
|
/// ```
|
||||||
#[lang = "bitor"]
|
#[lang = "bitor"]
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
#[rustc_on_unimplemented = "no implementation for `{Self} | {RHS}`"]
|
||||||
pub trait BitOr<RHS=Self> {
|
pub trait BitOr<RHS=Self> {
|
||||||
/// The resulting type after applying the `|` operator
|
/// The resulting type after applying the `|` operator
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
@ -1052,6 +1059,7 @@ bitor_impl! { bool usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 }
|
|||||||
/// ```
|
/// ```
|
||||||
#[lang = "bitxor"]
|
#[lang = "bitxor"]
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
#[rustc_on_unimplemented = "no implementation for `{Self} ^ {RHS}`"]
|
||||||
pub trait BitXor<RHS=Self> {
|
pub trait BitXor<RHS=Self> {
|
||||||
/// The resulting type after applying the `^` operator
|
/// The resulting type after applying the `^` operator
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
@ -1134,6 +1142,7 @@ bitxor_impl! { bool usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 }
|
|||||||
/// ```
|
/// ```
|
||||||
#[lang = "shl"]
|
#[lang = "shl"]
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
#[rustc_on_unimplemented = "no implementation for `{Self} << {RHS}`"]
|
||||||
pub trait Shl<RHS> {
|
pub trait Shl<RHS> {
|
||||||
/// The resulting type after applying the `<<` operator
|
/// The resulting type after applying the `<<` operator
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
@ -1237,6 +1246,7 @@ shl_impl_all! { u8 u16 u32 u64 u128 usize i8 i16 i32 i64 isize i128 }
|
|||||||
/// ```
|
/// ```
|
||||||
#[lang = "shr"]
|
#[lang = "shr"]
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
#[rustc_on_unimplemented = "no implementation for `{Self} >> {RHS}`"]
|
||||||
pub trait Shr<RHS> {
|
pub trait Shr<RHS> {
|
||||||
/// The resulting type after applying the `>>` operator
|
/// The resulting type after applying the `>>` operator
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
@ -1321,6 +1331,7 @@ shr_impl_all! { u8 u16 u32 u64 u128 usize i8 i16 i32 i64 i128 isize }
|
|||||||
/// ```
|
/// ```
|
||||||
#[lang = "add_assign"]
|
#[lang = "add_assign"]
|
||||||
#[stable(feature = "op_assign_traits", since = "1.8.0")]
|
#[stable(feature = "op_assign_traits", since = "1.8.0")]
|
||||||
|
#[rustc_on_unimplemented = "no implementation for `{Self} += {Rhs}`"]
|
||||||
pub trait AddAssign<Rhs=Self> {
|
pub trait AddAssign<Rhs=Self> {
|
||||||
/// The method for the `+=` operator
|
/// The method for the `+=` operator
|
||||||
#[stable(feature = "op_assign_traits", since = "1.8.0")]
|
#[stable(feature = "op_assign_traits", since = "1.8.0")]
|
||||||
@ -1377,6 +1388,7 @@ add_assign_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f32 f64 }
|
|||||||
/// ```
|
/// ```
|
||||||
#[lang = "sub_assign"]
|
#[lang = "sub_assign"]
|
||||||
#[stable(feature = "op_assign_traits", since = "1.8.0")]
|
#[stable(feature = "op_assign_traits", since = "1.8.0")]
|
||||||
|
#[rustc_on_unimplemented = "no implementation for `{Self} -= {Rhs}`"]
|
||||||
pub trait SubAssign<Rhs=Self> {
|
pub trait SubAssign<Rhs=Self> {
|
||||||
/// The method for the `-=` operator
|
/// The method for the `-=` operator
|
||||||
#[stable(feature = "op_assign_traits", since = "1.8.0")]
|
#[stable(feature = "op_assign_traits", since = "1.8.0")]
|
||||||
@ -1422,6 +1434,7 @@ sub_assign_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f32 f64 }
|
|||||||
/// ```
|
/// ```
|
||||||
#[lang = "mul_assign"]
|
#[lang = "mul_assign"]
|
||||||
#[stable(feature = "op_assign_traits", since = "1.8.0")]
|
#[stable(feature = "op_assign_traits", since = "1.8.0")]
|
||||||
|
#[rustc_on_unimplemented = "no implementation for `{Self} *= {Rhs}`"]
|
||||||
pub trait MulAssign<Rhs=Self> {
|
pub trait MulAssign<Rhs=Self> {
|
||||||
/// The method for the `*=` operator
|
/// The method for the `*=` operator
|
||||||
#[stable(feature = "op_assign_traits", since = "1.8.0")]
|
#[stable(feature = "op_assign_traits", since = "1.8.0")]
|
||||||
@ -1467,6 +1480,7 @@ mul_assign_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f32 f64 }
|
|||||||
/// ```
|
/// ```
|
||||||
#[lang = "div_assign"]
|
#[lang = "div_assign"]
|
||||||
#[stable(feature = "op_assign_traits", since = "1.8.0")]
|
#[stable(feature = "op_assign_traits", since = "1.8.0")]
|
||||||
|
#[rustc_on_unimplemented = "no implementation for `{Self} /= {Rhs}`"]
|
||||||
pub trait DivAssign<Rhs=Self> {
|
pub trait DivAssign<Rhs=Self> {
|
||||||
/// The method for the `/=` operator
|
/// The method for the `/=` operator
|
||||||
#[stable(feature = "op_assign_traits", since = "1.8.0")]
|
#[stable(feature = "op_assign_traits", since = "1.8.0")]
|
||||||
@ -1511,6 +1525,7 @@ div_assign_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f32 f64 }
|
|||||||
/// ```
|
/// ```
|
||||||
#[lang = "rem_assign"]
|
#[lang = "rem_assign"]
|
||||||
#[stable(feature = "op_assign_traits", since = "1.8.0")]
|
#[stable(feature = "op_assign_traits", since = "1.8.0")]
|
||||||
|
#[rustc_on_unimplemented = "no implementation for `{Self} %= {Rhs}`"]
|
||||||
pub trait RemAssign<Rhs=Self> {
|
pub trait RemAssign<Rhs=Self> {
|
||||||
/// The method for the `%=` operator
|
/// The method for the `%=` operator
|
||||||
#[stable(feature = "op_assign_traits", since = "1.8.0")]
|
#[stable(feature = "op_assign_traits", since = "1.8.0")]
|
||||||
@ -1597,6 +1612,7 @@ rem_assign_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f32 f64 }
|
|||||||
/// ```
|
/// ```
|
||||||
#[lang = "bitand_assign"]
|
#[lang = "bitand_assign"]
|
||||||
#[stable(feature = "op_assign_traits", since = "1.8.0")]
|
#[stable(feature = "op_assign_traits", since = "1.8.0")]
|
||||||
|
#[rustc_on_unimplemented = "no implementation for `{Self} &= {Rhs}`"]
|
||||||
pub trait BitAndAssign<Rhs=Self> {
|
pub trait BitAndAssign<Rhs=Self> {
|
||||||
/// The method for the `&=` operator
|
/// The method for the `&=` operator
|
||||||
#[stable(feature = "op_assign_traits", since = "1.8.0")]
|
#[stable(feature = "op_assign_traits", since = "1.8.0")]
|
||||||
@ -1641,6 +1657,7 @@ bitand_assign_impl! { bool usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 }
|
|||||||
/// ```
|
/// ```
|
||||||
#[lang = "bitor_assign"]
|
#[lang = "bitor_assign"]
|
||||||
#[stable(feature = "op_assign_traits", since = "1.8.0")]
|
#[stable(feature = "op_assign_traits", since = "1.8.0")]
|
||||||
|
#[rustc_on_unimplemented = "no implementation for `{Self} |= {Rhs}`"]
|
||||||
pub trait BitOrAssign<Rhs=Self> {
|
pub trait BitOrAssign<Rhs=Self> {
|
||||||
/// The method for the `|=` operator
|
/// The method for the `|=` operator
|
||||||
#[stable(feature = "op_assign_traits", since = "1.8.0")]
|
#[stable(feature = "op_assign_traits", since = "1.8.0")]
|
||||||
@ -1685,6 +1702,7 @@ bitor_assign_impl! { bool usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 }
|
|||||||
/// ```
|
/// ```
|
||||||
#[lang = "bitxor_assign"]
|
#[lang = "bitxor_assign"]
|
||||||
#[stable(feature = "op_assign_traits", since = "1.8.0")]
|
#[stable(feature = "op_assign_traits", since = "1.8.0")]
|
||||||
|
#[rustc_on_unimplemented = "no implementation for `{Self} ^= {Rhs}`"]
|
||||||
pub trait BitXorAssign<Rhs=Self> {
|
pub trait BitXorAssign<Rhs=Self> {
|
||||||
/// The method for the `^=` operator
|
/// The method for the `^=` operator
|
||||||
#[stable(feature = "op_assign_traits", since = "1.8.0")]
|
#[stable(feature = "op_assign_traits", since = "1.8.0")]
|
||||||
@ -1729,6 +1747,7 @@ bitxor_assign_impl! { bool usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 }
|
|||||||
/// ```
|
/// ```
|
||||||
#[lang = "shl_assign"]
|
#[lang = "shl_assign"]
|
||||||
#[stable(feature = "op_assign_traits", since = "1.8.0")]
|
#[stable(feature = "op_assign_traits", since = "1.8.0")]
|
||||||
|
#[rustc_on_unimplemented = "no implementation for `{Self} <<= {Rhs}`"]
|
||||||
pub trait ShlAssign<Rhs> {
|
pub trait ShlAssign<Rhs> {
|
||||||
/// The method for the `<<=` operator
|
/// The method for the `<<=` operator
|
||||||
#[stable(feature = "op_assign_traits", since = "1.8.0")]
|
#[stable(feature = "op_assign_traits", since = "1.8.0")]
|
||||||
@ -1794,6 +1813,7 @@ shl_assign_impl_all! { u8 u16 u32 u64 u128 usize i8 i16 i32 i64 i128 isize }
|
|||||||
/// ```
|
/// ```
|
||||||
#[lang = "shr_assign"]
|
#[lang = "shr_assign"]
|
||||||
#[stable(feature = "op_assign_traits", since = "1.8.0")]
|
#[stable(feature = "op_assign_traits", since = "1.8.0")]
|
||||||
|
#[rustc_on_unimplemented = "no implementation for `{Self} >>= {Rhs}`"]
|
||||||
pub trait ShrAssign<Rhs=Self> {
|
pub trait ShrAssign<Rhs=Self> {
|
||||||
/// The method for the `>>=` operator
|
/// The method for the `>>=` operator
|
||||||
#[stable(feature = "op_assign_traits", since = "1.8.0")]
|
#[stable(feature = "op_assign_traits", since = "1.8.0")]
|
||||||
|
@ -524,15 +524,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
|||||||
"the trait bound `{}` is not satisfied{}",
|
"the trait bound `{}` is not satisfied{}",
|
||||||
trait_ref.to_predicate(),
|
trait_ref.to_predicate(),
|
||||||
post_message);
|
post_message);
|
||||||
err.span_label(span,
|
|
||||||
&format!("{}the trait `{}` is not \
|
|
||||||
implemented for `{}`",
|
|
||||||
pre_message,
|
|
||||||
trait_ref,
|
|
||||||
trait_ref.self_ty()));
|
|
||||||
|
|
||||||
// Try to report a help message
|
// Try to report a help message
|
||||||
|
|
||||||
if !trait_ref.has_infer_types() &&
|
if !trait_ref.has_infer_types() &&
|
||||||
self.predicate_can_apply(trait_ref) {
|
self.predicate_can_apply(trait_ref) {
|
||||||
// If a where-clause may be useful, remind the
|
// If a where-clause may be useful, remind the
|
||||||
@ -544,17 +537,21 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
|||||||
// which is somewhat confusing.
|
// which is somewhat confusing.
|
||||||
err.help(&format!("consider adding a `where {}` bound",
|
err.help(&format!("consider adding a `where {}` bound",
|
||||||
trait_ref.to_predicate()));
|
trait_ref.to_predicate()));
|
||||||
} else if let Some(s) = self.on_unimplemented_note(trait_ref,
|
} else if let Some(s) = self.on_unimplemented_note(trait_ref, obligation) {
|
||||||
obligation) {
|
|
||||||
// If it has a custom "#[rustc_on_unimplemented]"
|
// If it has a custom "#[rustc_on_unimplemented]"
|
||||||
// error message, let's display it!
|
// error message, let's display it!
|
||||||
err.note(&s);
|
err.note(&s);
|
||||||
} else {
|
} else {
|
||||||
// If we can't show anything useful, try to find
|
// Can't show anything else useful, try to find similar impls.
|
||||||
// similar impls.
|
|
||||||
let impl_candidates = self.find_similar_impl_candidates(trait_ref);
|
let impl_candidates = self.find_similar_impl_candidates(trait_ref);
|
||||||
self.report_similar_impl_candidates(impl_candidates, &mut err);
|
self.report_similar_impl_candidates(impl_candidates, &mut err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err.span_label(span,
|
||||||
|
&format!("{}the trait `{}` is not implemented for `{}`",
|
||||||
|
pre_message,
|
||||||
|
trait_ref,
|
||||||
|
trait_ref.self_ty()));
|
||||||
err
|
err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -997,3 +994,4 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
|||||||
suggested_limit));
|
suggested_limit));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ fn sum_to(n: u32) -> impl Foo {
|
|||||||
0
|
0
|
||||||
} else {
|
} else {
|
||||||
n + sum_to(n - 1)
|
n + sum_to(n - 1)
|
||||||
//~^ ERROR the trait bound `u32: std::ops::Add<impl Foo>` is not satisfied
|
//~^ ERROR no implementation for `u32 + impl Foo`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
55
src/test/ui/impl-trait/equality.stderr
Normal file
55
src/test/ui/impl-trait/equality.stderr
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
error[E0308]: mismatched types
|
||||||
|
--> $DIR/equality.rs:25:5
|
||||||
|
|
|
||||||
|
25 | 0_u32
|
||||||
|
| ^^^^^ expected i32, found u32
|
||||||
|
|
|
||||||
|
= note: expected type `i32`
|
||||||
|
found type `u32`
|
||||||
|
|
||||||
|
error[E0277]: the trait bound `u32: std::ops::Add<impl Foo>` is not satisfied
|
||||||
|
--> $DIR/equality.rs:34:9
|
||||||
|
|
|
||||||
|
34 | n + sum_to(n - 1)
|
||||||
|
| ^^^^^^^^^^^^^^^^^ the trait `std::ops::Add<impl Foo>` is not implemented for `u32`
|
||||||
|
|
|
||||||
|
= note: no implementation for `u32 + impl Foo`
|
||||||
|
|
||||||
|
error[E0308]: mismatched types
|
||||||
|
--> $DIR/equality.rs:53:18
|
||||||
|
|
|
||||||
|
53 | let _: u32 = hide(0_u32);
|
||||||
|
| ^^^^^^^^^^^ expected u32, found anonymized type
|
||||||
|
|
|
||||||
|
= note: expected type `u32`
|
||||||
|
found type `impl Foo`
|
||||||
|
|
||||||
|
error[E0308]: mismatched types
|
||||||
|
--> $DIR/equality.rs:59:18
|
||||||
|
|
|
||||||
|
59 | let _: i32 = Leak::leak(hide(0_i32));
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^ expected i32, found associated type
|
||||||
|
|
|
||||||
|
= note: expected type `i32`
|
||||||
|
found type `<impl Foo as Leak>::T`
|
||||||
|
|
||||||
|
error[E0308]: mismatched types
|
||||||
|
--> $DIR/equality.rs:66:10
|
||||||
|
|
|
||||||
|
66 | x = (x.1,
|
||||||
|
| ^^^ expected u32, found i32
|
||||||
|
|
|
||||||
|
= note: expected type `impl Foo` (u32)
|
||||||
|
found type `impl Foo` (i32)
|
||||||
|
|
||||||
|
error[E0308]: mismatched types
|
||||||
|
--> $DIR/equality.rs:69:10
|
||||||
|
|
|
||||||
|
69 | x.0);
|
||||||
|
| ^^^ expected i32, found u32
|
||||||
|
|
|
||||||
|
= note: expected type `impl Foo` (i32)
|
||||||
|
found type `impl Foo` (u32)
|
||||||
|
|
||||||
|
error: aborting due to 6 previous errors
|
||||||
|
|
18
src/test/ui/mismatched_types/binops.rs
Normal file
18
src/test/ui/mismatched_types/binops.rs
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
// Copyright 2017 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.
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
1 + Some(1);
|
||||||
|
2 as usize - Some(1);
|
||||||
|
3 * ();
|
||||||
|
4 / "";
|
||||||
|
5 < String::new();
|
||||||
|
6 == Ok(1);
|
||||||
|
}
|
58
src/test/ui/mismatched_types/binops.stderr
Normal file
58
src/test/ui/mismatched_types/binops.stderr
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
error[E0277]: the trait bound `{integer}: std::ops::Add<std::option::Option<{integer}>>` is not satisfied
|
||||||
|
--> $DIR/binops.rs:12:5
|
||||||
|
|
|
||||||
|
12 | 1 + Some(1);
|
||||||
|
| ^^^^^^^^^^^ the trait `std::ops::Add<std::option::Option<{integer}>>` is not implemented for `{integer}`
|
||||||
|
|
|
||||||
|
= note: no implementation for `{integer} + std::option::Option<{integer}>`
|
||||||
|
|
||||||
|
error[E0277]: the trait bound `usize: std::ops::Sub<std::option::Option<{integer}>>` is not satisfied
|
||||||
|
--> $DIR/binops.rs:13:5
|
||||||
|
|
|
||||||
|
13 | 2 as usize - Some(1);
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^ the trait `std::ops::Sub<std::option::Option<{integer}>>` is not implemented for `usize`
|
||||||
|
|
|
||||||
|
= note: no implementation for `usize - std::option::Option<{integer}>`
|
||||||
|
|
||||||
|
error[E0277]: the trait bound `{integer}: std::ops::Mul<()>` is not satisfied
|
||||||
|
--> $DIR/binops.rs:14:5
|
||||||
|
|
|
||||||
|
14 | 3 * ();
|
||||||
|
| ^^^^^^ the trait `std::ops::Mul<()>` is not implemented for `{integer}`
|
||||||
|
|
|
||||||
|
= note: no implementation for `{integer} * ()`
|
||||||
|
|
||||||
|
error[E0277]: the trait bound `{integer}: std::ops::Div<&str>` is not satisfied
|
||||||
|
--> $DIR/binops.rs:15:5
|
||||||
|
|
|
||||||
|
15 | 4 / "";
|
||||||
|
| ^^^^^^ the trait `std::ops::Div<&str>` is not implemented for `{integer}`
|
||||||
|
|
|
||||||
|
= note: no implementation for `{integer} / &str`
|
||||||
|
|
||||||
|
error[E0277]: the trait bound `{integer}: std::cmp::PartialEq<std::string::String>` is not satisfied
|
||||||
|
--> $DIR/binops.rs:16:5
|
||||||
|
|
|
||||||
|
16 | 5 < String::new();
|
||||||
|
| ^^^^^^^^^^^^^^^^^ the trait `std::cmp::PartialEq<std::string::String>` is not implemented for `{integer}`
|
||||||
|
|
|
||||||
|
= note: can't compare `{integer}` with `std::string::String`
|
||||||
|
|
||||||
|
error[E0277]: the trait bound `{integer}: std::cmp::PartialOrd<std::string::String>` is not satisfied
|
||||||
|
--> $DIR/binops.rs:16:5
|
||||||
|
|
|
||||||
|
16 | 5 < String::new();
|
||||||
|
| ^^^^^^^^^^^^^^^^^ the trait `std::cmp::PartialOrd<std::string::String>` is not implemented for `{integer}`
|
||||||
|
|
|
||||||
|
= note: can't compare `{integer}` with `std::string::String`
|
||||||
|
|
||||||
|
error[E0277]: the trait bound `{integer}: std::cmp::PartialEq<std::result::Result<{integer}, _>>` is not satisfied
|
||||||
|
--> $DIR/binops.rs:17:5
|
||||||
|
|
|
||||||
|
17 | 6 == Ok(1);
|
||||||
|
| ^^^^^^^^^^ the trait `std::cmp::PartialEq<std::result::Result<{integer}, _>>` is not implemented for `{integer}`
|
||||||
|
|
|
||||||
|
= note: can't compare `{integer}` with `std::result::Result<{integer}, _>`
|
||||||
|
|
||||||
|
error: aborting due to 7 previous errors
|
||||||
|
|
@ -9,11 +9,7 @@ error[E0277]: the trait bound `u32: std::ops::Add<()>` is not satisfied
|
|||||||
27 | | y),
|
27 | | y),
|
||||||
| |______________^ ...ending here: the trait `std::ops::Add<()>` is not implemented for `u32`
|
| |______________^ ...ending here: the trait `std::ops::Add<()>` is not implemented for `u32`
|
||||||
|
|
|
|
||||||
= help: the following implementations were found:
|
= note: no implementation for `u32 + ()`
|
||||||
<u32 as std::ops::Add>
|
|
||||||
<&'a u32 as std::ops::Add<u32>>
|
|
||||||
<u32 as std::ops::Add<&'a u32>>
|
|
||||||
<&'b u32 as std::ops::Add<&'a u32>>
|
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user