-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Add rustc_on_unimplemented for Index implementation on slice #31071
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
is this error message testable? |
Oh right, I'll add test. Thanks for notifying me @oli-obk! |
de45724
to
30210fa
Compare
It's getting longer and more difficult because the |
a8d346c
to
9cf0aea
Compare
I'm facing an issue here. For example, for the following code: #![feature(on_unimplemented)]
fn main() {
let x : &[i32] = &[1, 2];
x[1u32];
} I cannot determine the impl trait used between:
How can I determine the good one? cc @pnkfelix, @nikomatsakis, @arielb1, @eddyb |
218bf8b
to
b3900ff
Compare
Well, the whole point is that this message is displayed in cases where is no impl to apply, so that's a bit tricky. But that said the new obligation forest does, in principle, keep some backtraces that might give us the "most likely" impl that was supposed to apply, so I guess we could find the best message to use by walking the backtrace. I know @arielb1 was working on a PR to improve error message that would make use of the backtrace, not sure of the status of that work though -- seems like it would be a precursor that would do some of the required refactoring for you. |
@nikomatsakis: That's a great news! Now, just have to wait that this functionality lands. |
@GuillaumeGomez for the record, the issue I was referring to is #30976 |
Still waiting to see how it'll be solved. Then I'll take their function. |
☔ The latest upstream changes (presumably #31979) made this pull request unmergeable. Please resolve the merge conflicts. |
…mpl, this message will be displayed instead
b3900ff
to
de2fb72
Compare
I talked with @pnkfelix this evening and he proposed (correct me if I'm wrong) that since there wasn't that much movement on the function I need, instead of doing a global one, it'll be a more specific one. So what I have in mind is the following:
I'll wait a few days then, if no ones has objection, I'll start to work on this. |
@GuillaumeGomez I don't quite understand what you are proposing -- what is this type whose size etc you are checking and so forth? I do agree though that it seems fine to add a bit of special-case logic for the error messages around indexing. |
Oh sorry, my message is a bit incomplete. So I was tried to explain was to "guess" what was the trait the user tried to use. So for example: let s = &[0, 1];
s[0i32]; will span an error because index is implemented for
It seems obvious for humans that is Now I guess I added the missing part of my previous explanation. Very sorry about this. |
@GuillaumeGomez I've edited your comment to add the |
@eddyb: Thanks! :) |
@GuillaumeGomez I think the size and "is primitive" checks could be replaced by the "flavor" of type - |
So remove my first point and keep the two others? Fine by me. |
☔ The latest upstream changes (presumably #32432) made this pull request unmergeable. Please resolve the merge conflicts. |
Yes, I agree with @eddyb -- checking the size seems like it may not be On Tue, Mar 22, 2016 at 11:01:06AM -0700, Guillaume Gomez wrote:
|
@GuillaumeGomez I'm going to close this PR for the time being. Please feel free to open another at some later point :) |
…pnkfelix Add rustc_on_unimplemented for Index implementation on slice Reopening of rust-lang#31071. It also extends the possibility of `#[rustc_on_unimplemented]` by providing a small type filter in order to find the ones which corresponds the most. r? @pnkfelix
Fixes #31062