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

Document the usage scenario of "as" keyword for trait coercion #86287

Open
cher-nov opened this issue Jun 14, 2021 · 1 comment
Open

Document the usage scenario of "as" keyword for trait coercion #86287

cher-nov opened this issue Jun 14, 2021 · 1 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.

Comments

@cher-nov
Copy link

I've just stumbled about such an error:

an `as` expression can only be used to convert between primitive types or to coerce to a specific trait object

It seems that the second part of it is about syntax like this:

<SomeType as Into<i32>>::into( ... ))

But these scenarios don't seem to be documented on the as page in the official docs:
https://doc.rust-lang.org/std/keyword.as.html

It states that as can be used only to "cast between types, or rename an import".

@memoryruins
Copy link
Contributor

The second part is about how as expressions can do coercions to trait objects. The reference page linked at the end of the rustdoc page mentions this, but it might help to mention it on the rustdoc page too.

For <SomeType as Into<i32>>, as is part of the syntax of qualified paths rather being about casts or renaming imports. A note could be added to the rustdoc page about this additional usage.

@rustbot label +A-docs +C-enhancement

@rustbot rustbot added 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. labels Jun 22, 2021
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

No branches or pull requests

3 participants