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

Add info about ! and impl Trait #76099

Merged
merged 13 commits into from
Sep 2, 2020
Merged

Add info about ! and impl Trait #76099

merged 13 commits into from
Sep 2, 2020

Conversation

camelid
Copy link
Member

@camelid camelid commented Aug 30, 2020

Fixes #76094.

@rustbot modify labels: T-doc C-enhancement

@rust-highfive
Copy link
Collaborator

r? @sfackler

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 30, 2020
@rustbot rustbot added C-enhancement Category: An issue proposing an enhancement or a PR with one. A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools labels Aug 30, 2020
@camelid
Copy link
Member Author

camelid commented Aug 30, 2020

Note that this is still very work-in-progress, I just wanted to write something down to see if it's roughly correct.

@camelid
Copy link
Member Author

camelid commented Aug 30, 2020

Cc @jyn514

library/std/src/primitive_docs.rs Outdated Show resolved Hide resolved
library/std/src/primitive_docs.rs Outdated Show resolved Hide resolved
library/std/src/primitive_docs.rs Outdated Show resolved Hide resolved
///
/// [#36375]: https://github.com/rust-lang/rust/issues/36375
///
/// As it turns out, though, most traits can have an `impl` for `!`. Take [`Debug`]
Copy link
Member

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.

Copy link
Member Author

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!").

Copy link
Member

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.

Copy link
Member Author

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?

Copy link
Member

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.

Comment on lines 236 to 238
/// # trait Debug {
/// # fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result;
/// # fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result;
/// # }
Copy link
Member Author

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?

Copy link
Member Author

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.

Copy link
Member Author

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 :(

@camelid camelid marked this pull request as ready for review August 31, 2020 23:35
library/std/src/primitive_docs.rs Outdated Show resolved Hide resolved
library/std/src/primitive_docs.rs Outdated Show resolved Hide resolved
camelid and others added 3 commits August 31, 2020 19:33
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>
@jyn514
Copy link
Member

jyn514 commented Sep 1, 2020

@bors r+ rollup

Thanks for the PR!

@bors
Copy link
Contributor

bors commented Sep 1, 2020

📌 Commit 913354b has been approved by jyn514

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 1, 2020
@camelid
Copy link
Member Author

camelid commented Sep 1, 2020

Oh well, it looks like the line break commit didn't get through in time ;)

@jyn514
Copy link
Member

jyn514 commented Sep 1, 2020

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Sep 1, 2020

📌 Commit 55637f5 has been approved by jyn514

@jyn514
Copy link
Member

jyn514 commented Sep 1, 2020

Oh well, it looks like the line break commit didn't get through in time ;)

Bors will automatically abort the merge if you push new commits. It will not however remove the S-waiting-on-bors tag :(

@bors
Copy link
Contributor

bors commented Sep 1, 2020

⌛ Testing commit 55637f5 with merge c79747195683ac4842eaacf65e8e4cddac6f7e69...

@bors
Copy link
Contributor

bors commented Sep 1, 2020

💔 Test failed - checks-azure

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Sep 1, 2020
@rust-log-analyzer
Copy link
Collaborator

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.
##[group]Run exit 1
exit 1
shell: /bin/bash --noprofile --norc -e -o pipefail {0}
##[endgroup]
##[error]Process completed with exit code 1.

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 @rust-lang/infra. (Feature Requests)

@jyn514
Copy link
Member

jyn514 commented Sep 1, 2020

curl: (56) SSLRead() return error -9806
clang+llvm-10.0.0-x86_64-apple-darwin/lib/clang/10.0.0/lib/darwin/libclang_rt.tsan_ios_dynamic.dylib: Lzma library error:  No progress is possible
tar: Error exit delayed from previous errors.

##[error]Bash exited with code '1'.
Finishing: Install clang

What a strange error ... Looks network related?

@bors retry

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 1, 2020
bors added a commit to rust-lang-ci/rust that referenced this pull request Sep 2, 2020
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
@bors bors merged commit 34c8b7a into rust-lang:master Sep 2, 2020
@camelid camelid deleted the patch-8 branch September 2, 2020 03:33
@cuviper cuviper added this to the 1.48.0 milestone Nov 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools C-enhancement Category: An issue proposing an enhancement or a PR with one. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Clarify docs for "! and traits"
8 participants