Skip to content

Document fully-qualified syntax in as' keyword doc #142670

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

fpdotmonkey
Copy link

No description provided.

@rustbot
Copy link
Collaborator

rustbot commented Jun 18, 2025

r? @ibraheemdev

rustbot has assigned @ibraheemdev.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jun 18, 2025
@@ -24,6 +24,13 @@
/// (`u8`, `bool`, `str`, pointers, ...) whereas `From` and `Into` also works with types like
/// `String` or `Vec`.
///
/// You'll also find with `From` and `Into`, and indeed all traits, that `as` is used for the
/// _fully qualified syntax_, a means of clarifying ambiguous method calls. If you have a type which
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would use fully qualified path here over syntax because that's more precise and what The Reference and rustc calls it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok I couldn't find it in the reference. It's called syntax in the rust book, but I certainly like path better.

@@ -24,6 +24,13 @@
/// (`u8`, `bool`, `str`, pointers, ...) whereas `From` and `Into` also works with types like
/// `String` or `Vec`.
///
/// You'll also find with `From` and `Into`, and indeed all traits, that `as` is used for the
/// _fully qualified syntax_, a means of clarifying ambiguous method calls. If you have a type which
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not just for method calls, it's for all three kinds of associated item: Function, constant and type.

@fpdotmonkey fpdotmonkey force-pushed the doc/as-fully-qualified-syntax branch from 7cfd0dd to a2d247b Compare June 18, 2025 13:32
/// _fully qualified path_, a means of clarifying ambiguous method calls, constants, and types.
/// If you have a type which implements two traits with identical method names (e.g.
/// `Into<u32>::into` and `Into<u64>::into`), you can clarify which method you'll use with
/// `<MyThing as Into<u32>>::into(my_thing)`. This is quite verbose, but fortunately, Rust's type
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there any other std traits where this is commonly needed? A small downside with this example is that this is something that should just be written u32::from(my_thing) 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants