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

Guide: lifetimes error example compiles successfully #16117

Closed
mprobinson opened this issue Jul 30, 2014 · 0 comments
Closed

Guide: lifetimes error example compiles successfully #16117

mprobinson opened this issue Jul 30, 2014 · 0 comments

Comments

@mprobinson
Copy link
Contributor

http://doc.rust-lang.org/guide-lifetimes.html#returning-references

struct Point {x: f64, y: f64}
fn get_x_sh(p: &Point) -> &f64 {
    &p.x // Error reported here
}

Thanks to lifetime elision this example now compiles successfully.

steveklabnik added a commit to steveklabnik/rust that referenced this issue Jul 30, 2014
This now works because of elision.

Fixes rust-lang#16117
bors added a commit to rust-lang-ci/rust that referenced this issue Feb 18, 2024
feat: completion list suggests constructor like & builder methods first

When typing `MyType::` the completion items' order could be re-ordered based on how likely we want to select those:
* Constructors: `new` like functions to be able to create the type,
* Constructors that take args: Any other function that creates `Self`,
* Builder Methods: any builder methods available,
* Regular methods & associated functions (no change there)

![image](https://github.com/rust-lang/rust-analyzer/assets/1546896/54593b91-07b3-455a-8a71-8d203d4eaf4a)

In this photo, the order is:
* `new` constructor is first
* `new_builder` second is a builder method
* `aaaanew` is a constructor that takes arguments, is third  and is irrespective of its alphabetical order among names.

---

Another Example using actix `HttpServer` shows preferring constructor without `self` arg first (the `new` method)

![image](https://github.com/rust-lang/rust-analyzer/assets/1546896/938d3fb0-3d7a-4427-ae2f-ec02a834ccbe)

![image](https://github.com/rust-lang/rust-analyzer/assets/1546896/2c13860c-efd1-459d-b25e-df8adb61bbd0)

I've dropped my previous idea of highlighting these functions in the rustdoc (rust-lang#107926)
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 a pull request may close this issue.

1 participant