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

Unhelpful suggestions trying to use array::set #96834

Closed
jdonszelmann opened this issue May 8, 2022 · 0 comments · Fixed by #98509
Closed

Unhelpful suggestions trying to use array::set #96834

jdonszelmann opened this issue May 8, 2022 · 0 comments · Fixed by #98509
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@jdonszelmann
Copy link
Contributor

Given the following code:
playground

fn main() {
    let mut a = [0u8; 1];
    a.set(0, 3);
}

The current output is:

/tmp/tmp.pvMJNmiDgb/bad_error/src (git)-[main] % cargo run
   Compiling bad_error v0.1.0 (/tmp/tmp.pvMJNmiDgb/bad_error)
error[E0599]: no method named `set` found for array `[u8; 1]` in the current scope
   --> src/main.rs:3:7
    |
3   |     a.set(0, 3);
    |       ^^^
    |
   ::: /home/jonathan/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/pin.rs:659:12
    |
659 |     pub fn set(&mut self, value: P::Target)
    |            --- the method is available for `Pin<&mut [u8; 1]>` here
    |
help: consider wrapping the receiver expression with the appropriate type
    |
3   |     Pin::new(&mut a).set(0, 3);
    |     +++++++++++++  +
help: there is an associated function with a similar name
    |
3   |     a.get(0, 3);
    |       ~~~

For more information about this error, try `rustc --explain E0599`.
error: could not compile `bad_error` due to previous error

image

I don't think suggesting to use Pin here helps users. I tried to use set, since there's also a get so it felt natural to me that set should also exist. It may be a different issue altogether if having no set on arrays is expected, but the error message really bothered me. I tried to do a, what felt to me, trivial operation on an array, and the first suggestion is to Pin it, something which I know is useless. However, unexperienced rust users may not know this. It also doesn't solve the issue. There would be a set method on pin, but it wouldn't do what you expect it to do.

@jdonszelmann jdonszelmann added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 8, 2022
@notriddle notriddle self-assigned this Jun 25, 2022
@bors bors closed this as completed in c3b2291 Jun 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants