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

Typo MaybeUnint doesn't suggest MaybeUninit #95462

Closed
scottmcm opened this issue Mar 30, 2022 · 1 comment · Fixed by #103706
Closed

Typo MaybeUnint doesn't suggest MaybeUninit #95462

scottmcm opened this issue Mar 30, 2022 · 1 comment · Fixed by #103706
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

@scottmcm
Copy link
Member

scottmcm commented Mar 30, 2022

Given the following code: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=3868d05aad2cfb9e962511b364e05077

use std::mem::MaybeUninit;

pub fn next_unsafe(x: &mut (usize, MaybeUninit<[u16; 8]>)) -> Option<[u16; 8]> {
    if x.0 > 0 {
        x.0 -= 1;
        Some(if x.0 > 0 {
            x.1.assume_init_ref().clone()
        } else {
            std::mem::replace(&mut x.1, MaybeUnint::uninit()).assume_init()
        })
    } else {
        None
    }
}

The current output is:

error[E0433]: failed to resolve: use of undeclared type `MaybeUnint`
 --> src/lib.rs:9:41
  |
9 |             std::mem::replace(&mut x.1, MaybeUnint::uninit()).assume_init()
  |                                         ^^^^^^^^^^ use of undeclared type `MaybeUnint`

For more information about this error, try `rustc --explain E0433`.

Ideally the output should look something like:

error[E0433]: failed to resolve: use of undeclared type `MaybeUnint`
 --> src/lib.rs:9:41
  |
9 |             std::mem::replace(&mut x.1, MaybeUnint::uninit()).assume_init()
  |                                         ^^^^^^^^^^ use of undeclared type `MaybeUnint`
  |                                         help: there is an in-scope type with a similar name: `MaybeUninit`

For more information about this error, try `rustc --explain E0433`.

Similar to how there's a suggestion when I typo the method name instead:

error[E0599]: no function or associated item named `unint` found for union `MaybeUninit` in the current scope
 --> src/lib.rs:9:54
  |
9 |             std::mem::replace(&mut x.1, MaybeUninit::unint()).assume_init()
  |                                                      ^^^^^
  |                                                      |
  |                                                      function or associated item not found in `MaybeUninit<_>`
  |                                                      help: there is an associated function with a similar name: `uninit`

For more information about this error, try `rustc --explain E0599`.

I can understand that searching the entire universe of paths on resolution might not be worth doing, but hopefully things that are used could be done reasonably, or something similar.

(That said, once it's already used it's also true that I'm in much less need of the help.)

@scottmcm scottmcm 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 Mar 30, 2022
@m-ysk
Copy link
Contributor

m-ysk commented May 6, 2022

@rustbot claim

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