Skip to content

2 hashmap examples#11150

Merged
bors merged 3 commits into
rust-lang:masterfrom
huonw:moar-docs
Dec 29, 2013
Merged

2 hashmap examples#11150
bors merged 3 commits into
rust-lang:masterfrom
huonw:moar-docs

Conversation

@huonw

@huonw huonw commented Dec 26, 2013

Copy link
Copy Markdown
Contributor

(I removed the fn main from the std::rand examples to make it consistent with the rest of the codebase.)

@alexcrichton

Copy link
Copy Markdown
Member

I definitely like the idea of examples for HashMap, but I'm not sure we want a complicated one for the module documentation. I would expect the module-level example to use the common functions like insert, find, remove, etc, and then the documentation on the methods themselves would contain examples of the more complicated functions find_or_insert_with and insert_or_update_with.

What do you think?

@huonw

huonw commented Dec 27, 2013

Copy link
Copy Markdown
Contributor Author

Sounds good; changed the example.

Comment thread src/libstd/hashmap.rs Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Let's drop these intermediate println statements because while they might make the output prettier they're cluttering up the code example a little bit.

@alexcrichton

Copy link
Copy Markdown
Member

Nice job! r=me with that change

bors added a commit that referenced this pull request Dec 29, 2013
(I removed the `fn main` from the `std::rand` examples to make it consistent with the rest of the codebase.)
@bors bors closed this Dec 29, 2013
@bors bors merged commit 8715736 into rust-lang:master Dec 29, 2013
@huonw huonw deleted the moar-docs branch February 25, 2014 05:28
matthiaskrgr pushed a commit to matthiaskrgr/rust that referenced this pull request Mar 21, 2024
…, r=Jarcho

lint when calling the blanket `Into` impl from a `From` impl

Closes rust-lang#11150
```
warning: function cannot return without recursing
  --> x.rs:9:9
   |
9  | /         fn from(value: f32) -> Self {
10 | |             value.into()
11 | |         }
   | |_________^
   |
note: recursive call site
  --> x.rs:10:13
   |
10 |             value.into()
   |             ^^^^^^^^^^^^
```

I'm also thinking that we can probably generalize this lint to rust-lang#11032 at some point (instead of hardcoding a bunch of impls), like how rustc's `unconditional_recursion` works, at least up to one indirect call, but this still seems useful for now :)

I've also noticed that we use `fn_def_id` in a bunch of lints and then try to get the node args of the call in a separate step, so I made a helper function that does both in one. I intend to refactor a bunch of uses of `fn_def_id` to use this later

I can add more test cases, but this is already using much of the same logic that exists for the other impls that this lint looks for (e.g. making sure that there are no conditional returns).

changelog: [`unconditional_recursion`]: emit a warning inside of `From::from` when unconditionally calling the blanket `.into()` impl
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

Successfully merging this pull request may close these issues.

3 participants