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

The Rust Guide should mention [0u, ..5] initializer syntax #16696

Closed
Screwtapello opened this issue Aug 23, 2014 · 2 comments
Closed

The Rust Guide should mention [0u, ..5] initializer syntax #16696

Screwtapello opened this issue Aug 23, 2014 · 2 comments

Comments

@Screwtapello
Copy link
Contributor

I'm trying to learn Rust, I'm trying to write a function to calculate the frequency of letters in a string. I figure I'll start with a mutable 256-element array initialised to zeroes and increment the correct field as I go along.

Reading the "Vectors" section of the Rust Guide, it tells me how to create a literal array:

let nums = [1i, 2i, 3i];

...and even mentions the abbreviated syntax for the type of such an array:

let nums: [int, ..3] = [1i, 2i, 3i];

...but it doesn't mention that there's an abbreviated syntax for initialising an array.

It's possible the Guide is not the right place for this information, but it also wasn't mentioned in Rust By Example. It is mentioned in the language Reference Manual, but that document isn't necessarily aimed at beginners, and I didn't find it until I'd asked in #rust, found out the answer, and then searched for it specifically.

@nmsmith
Copy link

nmsmith commented Aug 23, 2014

cc @steveklabnik

@steveklabnik
Copy link
Member

The guide is not intended to be comprehensive. It's intended to get you going. I left this out intentionally.

bors added a commit to rust-lang-ci/rust that referenced this issue Mar 3, 2024
…ykril

fix: Goto definition for `deref_mut`

Fixes rust-lang#16520

https://github.com/rust-lang/rust-analyzer/blob/a3236be9d7a8179ac4a997858138a4d6c260a451/crates/hir/src/source_analyzer.rs#L375-L393

As we can see from the above, current implementation routes all dereferencing prefix operations to `Deref::deref` implementation, not regarding mutabilities.

https://github.com/rust-lang/rust-analyzer/blob/a3236be9d7a8179ac4a997858138a4d6c260a451/crates/hir-ty/src/infer/mutability.rs#L134-L151

Since we are resolving them already in mutability inferences, we can use those results for proper `deref` / `deref_mut` routing.
bors added a commit to rust-lang-ci/rust that referenced this issue Mar 3, 2024
…ykril

fix: Goto definition for `index_mut`

Mostly same with rust-lang#16696.
https://github.com/rust-lang/rust-analyzer/blob/0ac05c05271f31c43d31017cbd288e8737a0edb0/crates/hir-ty/src/infer/mutability.rs#L103-L133
Thankfully, we are doing similar method resolutions so we can use them like the mentioned PR.
As there are only three `LangItem`s having `Mut` in there names; `FnMut`, `DerefMut` and `IndexMut`, I think that this is the last one 😄
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants