-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Deriving Debug on an enum with uninhabited type triggers warning #38885
Comments
Not seeing this in playground. Maybe it got fixed somewhere along the way? |
The code gives the following compiler output (with a
There's no warning about an unreachable pattern anymore. As such, proposing this be closed. |
cc @estebank |
@Havvy thanks for the heads up! Lets close with a test to avoid regressions from the current behavior. |
…ikomatsakis add test for deriving Debug on uninhabited enum Adds a test to close rust-lang#38885.
This problem resurfaced, but only when actually using #![feature(never_type)]
#[derive(Debug)]
pub struct Foo(!);
#[derive(Debug)]
pub struct Bar(Empty);
#[derive(Debug)]
pub enum Empty {} Leads to this output (with
So should we reopen this issue? |
Yes, reopen it or refile.
…On Thu, Feb 7, 2019, 4:03 PM Lukas Kalbertodt ***@***.***> wrote:
This problem resurfaced, but only when actually using !. This code (
Playground
<https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=76b116e886c0a1d1af7e87b52d1b33e6>
):
#![feature(never_type)]
#[derive(Debug)]pub struct Foo(!);
#[derive(Debug)]pub struct Bar(Empty);
#[derive(Debug)]pub enum Empty {}
Leads to this output (with nightly-2019-02-06):
warning: unreachable expression
--> src/lib.rs:5:16
|
5 | pub struct Foo(!);
| ^
|
= note: #[warn(unreachable_code)] on by default
So should we reopen this issue?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#38885 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABiDIhaypq1z1kmjXnqwRGQcMxTJYowEks5vLEAtgaJpZM4LdAcT>
.
|
What's the reasoning behind a type like The warning comes from the expanded macro: pub struct Foo(!);
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::std::fmt::Debug for Foo {
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
match *self {
Foo(ref __self_0_0) => {
let mut debug_trait_builder = f.debug_tuple("Foo");
let _ = debug_trait_builder.field(&&(*__self_0_0));
^^^^^^^^^^^^^^
warning: unreachable expression
debug_trait_builder.finish()
}
}
}
} |
Mainly some strange type level things. Adding a So to solve this one could simply add an If that solution is acceptable, I could prepare a PR I guess. The debug-derive definition is in this file. One would probably just need to add an attribute here. Creating the attribute is probably the most complicated part about this. Looks like |
I honestly don't understand enough about the But then why not just use
I'm new to |
Yeah, of course that's kinda strange. But you already provided a nice example! Generics is where you just want to derive I discovered this issue because I have a
Let's just hope someone else is also reading this :D But yeah, that's the reason I asked: maybe someone knows about potential real warnings that would wrongfully be suppressed. |
Well, stupid English language, wasn't sure if "you" means "you" singular or "you" plural 😄 There's some discussion on whether Either way, those were just my two cents 🙂 |
#63317 changes the output to be the following, which in my mind makes more sense than complaining about the non-use of
|
@rustbot claim |
@rustbot release-assignment |
I might try and take this up and investigate it but if my understanding of #2619 is correct this is currently the intended behavior. Currently I'm writing a compiler for school and I wanted to use phantom types to differentiate between 32-bit and 64-bit registers like so #[derive(Debug, Hash, PartialEq, Eq, Clone, Copy, EnumIter, Serialize)]
pub enum Register<T: Default> {
RAX,
RBX,
RCX,
RDX,
RDI,
RSI,
RBP,
RSP,
R8,
R9,
R10,
R11,
R12,
R13,
R14,
R15,
_Unreachable(PhantomData<T>),
} however I'd also like to make For now one work around is to implement your own never equivalent type
and then implementing your desired traits. |
@MilesConn Sounds like you might be more interested in serde-rs/serde#2073 than this issue? |
Yeah that's more on topic! Sorry I had a lot of tabs open when I was going down this rabbit hole. Ended up with a slightly different implementation but thank you. |
Possibly of interest: The pedantic Clippy lint |
Caused by #38069
The text was updated successfully, but these errors were encountered: