-
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
Add info about !
and impl Trait
#76099
Conversation
r? @sfackler (rust_highfive has picked a reviewer for you, use r? to override) |
Note that this is still very work-in-progress, I just wanted to write something down to see if it's roughly correct. |
Cc @jyn514 |
/// | ||
/// [#36375]: https://github.com/rust-lang/rust/issues/36375 | ||
/// | ||
/// As it turns out, though, most traits can have an `impl` for `!`. Take [`Debug`] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most -> all? Not sure if that's true but it seems like it should be.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's what I thought too; I would think you would be able to impl
any trait for !
since it can never :) exist. The body of it could just be panic!("This shouldn't happen!")
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or even simpler, *self
, yeah.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean because it can be coerced to any concrete type, so it can just return itself?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-> impl Trait
is not allowed in trait methods. So any trait it implemented would require returning some concrete type. Since ! can be coerced to any type, it would be coerced to the required type.
/// # trait Debug { | ||
/// # fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result; | ||
/// # fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result; | ||
/// # } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is Debug
defined here instead of imported?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm going to delete this redefinition and import it instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like it's because of the orphan rule or something, so I had to revert my change :(
I no longer say "polymorphic" since it's a bit ambiguous here.
This reverts commit 7e2548f. Now I know why it was redefined: it seems like it's potentially because of the orphan rule. Here are the error messages: error[E0119]: conflicting implementations of trait `std::fmt::Debug` for type `!`: --> src/primitive_docs.rs:236:1 | 6 | impl Debug for ! { | ^^^^^^^^^^^^^^^^ | = note: conflicting implementation in crate `core`: - impl std::fmt::Debug for !; error[E0117]: only traits defined in the current crate can be implemented for arbitrary types --> src/primitive_docs.rs:236:1 | 6 | impl Debug for ! { | ^^^^^^^^^^^^^^^- | | | | | `!` is not defined in the current crate | impl doesn't use only types from inside the current crate | = note: define and implement a trait or new type instead
Co-authored-by: Joshua Nelson <joshua@yottadb.com>
@bors r+ rollup Thanks for the PR! |
📌 Commit 913354b has been approved by |
Oh well, it looks like the line break commit didn't get through in time ;) |
@bors r+ rollup |
📌 Commit 55637f5 has been approved by |
Bors will automatically abort the merge if you push new commits. It will not however remove the S-waiting-on-bors tag :( |
⌛ Testing commit 55637f5 with merge c79747195683ac4842eaacf65e8e4cddac6f7e69... |
💔 Test failed - checks-azure |
Your PR failed (pretty log, raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem. Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
What a strange error ... Looks network related? @bors retry |
Rollup of 14 pull requests Successful merges: - rust-lang#74880 (Add trailing comma support to matches macro) - rust-lang#76074 (Add new `-Z dump-mir-spanview` option) - rust-lang#76088 (Add more examples to lexicographic cmp on Iterators.) - rust-lang#76099 (Add info about `!` and `impl Trait`) - rust-lang#76126 (Use "Fira Sans" for crate list font) - rust-lang#76132 (Factor out StmtKind::MacCall fields into `MacCallStmt` struct) - rust-lang#76143 (Give a better error message for duplicate built-in macros) - rust-lang#76158 (Stabilise link-self-contained option) - rust-lang#76201 (Move to intra-doc links for library/core/src/panic.rs) - rust-lang#76206 (Make all methods of `std::net::Ipv6Addr` const) - rust-lang#76207 (# Move to intra-doc links for library/core/src/clone.rs) - rust-lang#76212 (Document lint missing_doc_code_examples is nightly-only) - rust-lang#76218 (lexer: Tiny improvement to shebang detection) - rust-lang#76221 (Clean up header in `iter` docs for `for` loops) Failed merges: r? @ghost
Fixes #76094.
@rustbot modify labels: T-doc C-enhancement