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

#[allow(unstable_name_collisions)] doesn't work at block scope #81522

Closed
digama0 opened this issue Jan 29, 2021 · 1 comment · Fixed by #81922
Closed

#[allow(unstable_name_collisions)] doesn't work at block scope #81522

digama0 opened this issue Jan 29, 2021 · 1 comment · Fixed by #81922
Assignees
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug.

Comments

@digama0
Copy link
Contributor

digama0 commented Jan 29, 2021

This code gives a warning on the latest nightly:

trait OptionExt<T> {
    unsafe fn unwrap_unchecked(self) -> T;
}

impl<T> OptionExt<T> for Option<T> {
    unsafe fn unwrap_unchecked(self) -> T {
        self.unwrap_or_else(|| std::hint::unreachable_unchecked())
    }
}

fn main() {
    #[allow(unstable_name_collisions)] {
        println!("{}", unsafe { Some("hello").unwrap_unchecked() });
    }
}
warning: a method with this name may be added to the standard library in the future
  --> src/main.rs:13:47
   |
13 |         println!("{}", unsafe { Some("hello").unwrap_unchecked() });
   |                                               ^^^^^^^^^^^^^^^^
   |
   = note: `#[warn(unstable_name_collisions)]` on by default
   = warning: once this method is added to the standard library, the ambiguity may cause an error or change in behavior!
   = note: for more information, see issue #48919 <https://github.com/rust-lang/rust/issues/48919>
   = help: call with fully qualified syntax `OptionExt::unwrap_unchecked(...)` to keep using the current method
   = help: add `#![feature(option_result_unwrap_unchecked)]` to the crate attributes to enable `Option::<T>::unwrap_unchecked`

The warning is correct: #81383 added Option::unwrap_unchecked so this code is a future incompatibility hazard. The bug is that #[allow(unstable_name_collisions)] does not suppress the lint, although it works at function scope.

rustc --version --verbose:

rustc 1.51.0-nightly (d1aed50ab 2021-01-26)
binary: rustc
commit-hash: d1aed50ab81df3140977c610c5a7d00f36dc519f
commit-date: 2021-01-26
host: x86_64-unknown-linux-gnu
release: 1.51.0-nightly
LLVM version: 11.0.1
@digama0 digama0 added the C-bug Category: This is a bug. label Jan 29, 2021
@jonas-schievink jonas-schievink added the A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. label Jan 29, 2021
@magurotuna
Copy link
Contributor

I'd like to investigate it and see if I can fix it.
@rustbot claim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants