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

Clarify docs for "! and traits" #76094

Closed
camelid opened this issue Aug 30, 2020 · 4 comments · Fixed by #76099
Closed

Clarify docs for "! and traits" #76094

camelid opened this issue Aug 30, 2020 · 4 comments · Fixed by #76099
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.

Comments

@camelid
Copy link
Member

camelid commented Aug 30, 2020

The section "! and traits" says:

When writing your own traits, ! should have an impl whenever there is an obvious impl which doesn't panic!.

Yet it doesn't explain why you should impl your traits for !. I think it would be good for someone who understands ! well to write up a sentence or two about why you should impl your traits for !. I myself don't quite understand what the reason for doing so is ;)

@rustbot modify labels: T-doc C-enhancement

@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
@jyn514
Copy link
Member

jyn514 commented Aug 30, 2020

I myself don't quite understand what the reason for doing so is ;)

// FIXME: Currently the `everybody_loops` transformation is not applied to:
// * `const fn`, due to issue #43636 that `loop` is not supported for const evaluation. We are
// waiting for miri to fix that.
// * `impl Trait`, due to issue #43869 that functions returning impl Trait cannot be diverging.
// Solving this may require `!` to implement every trait, which relies on the an even more
// ambitious form of the closed RFC #1637. See also [#34511].
//
// [#34511]: https://github.com/rust-lang/rust/issues/34511#issuecomment-322340401
might shed some light, especially the link to rust-lang/rfcs#1637

@camelid
Copy link
Member Author

camelid commented Aug 30, 2020

So does that mean that ! coerces to any concrete type, but not to an impl Trait?

@jyn514
Copy link
Member

jyn514 commented Aug 30, 2020

Correct. ! does not implement all traits, and if it does not implement Trait, then unimplemented!() as the body of a function returning impl Trait will be a type error.

@jyn514
Copy link
Member

jyn514 commented Aug 30, 2020

See also #65863 and related issues linked from there.

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.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants