Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The note about missing implementation is absent for some operators #50151

Closed
dzamlo opened this issue Apr 22, 2018 · 1 comment
Closed

The note about missing implementation is absent for some operators #50151

dzamlo opened this issue Apr 22, 2018 · 1 comment

Comments

@dzamlo
Copy link
Contributor

dzamlo commented Apr 22, 2018

If you try to use an operator on a type that doesn't implement it, the error include an note similar to this one:

note: an implementation of `std::ops::Add` might be missing for `Foo`

But for three operator, this note is missing:

  • ^, BitXor
  • -, Neg (the unary negation)
  • !, Not

This note is also missing for all the *Assign version of the operators.

I've made a minimal example with the playground:
https://play.rust-lang.org/?gist=1df2a3964559faed35efb8427d9c3608&version=nightly

@zackmdavis
Copy link
Member

Relevant code seems to be

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::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
};

@ishitatsuyuki ishitatsuyuki changed the title The note about miising implementation is missing for some operators The note about missing implementation is absent for some operators Apr 22, 2018
alexcrichton added a commit to alexcrichton/rust that referenced this issue May 10, 2018
added missing implementation hint

Fixes [rust-lang#50151](rust-lang#50151).
Actually, i don't know, should following code
`let x = |ref x: isize| { x += 1; };`
emit
`note: an implementation of std::ops::AddAssign might be missing for &isize`
or
`note: this is a reference to a type that + can be applied to; you need to dereference this variable once for this operation to work`
or both
bors added a commit that referenced this issue May 11, 2018
added missing implementation hint

Fixes [#50151](#50151).
Actually, i don't know, should following code
`let x = |ref x: isize| { x += 1; };`
emit
`note: an implementation of std::ops::AddAssign might be missing for &isize`
or
`note: this is a reference to a type that + can be applied to; you need to dereference this variable once for this operation to work`
or both
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants