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

Potential name typo in borrowed pointer tutorial. #3876

Closed
nejucomo opened this issue Oct 27, 2012 · 1 comment
Closed

Potential name typo in borrowed pointer tutorial. #3876

nejucomo opened this issue Oct 27, 2012 · 1 comment

Comments

@nejucomo
Copy link

The following snippet confused me a bit. I believe "shape()" should be replaced with "select()" in the explanatory paragraph for the code snippet.

From commit 07edf90 tutorial-borrowed-ptr.md, line 674:

struct Point {x: float, y: float}; // as before

struct Size {w: float, h: float}; // as before

enum Shape {

Circle(Point, float), // origin, radius

Rectangle(Point, Size) // upper-left, dimensions

}

fn compute_area(shape: &Shape) -> float { 0f }

fn select(shape: &Shape, threshold: float,

a: &r/T, b: &r/T) -> &r/T {

if compute_area(shape) > threshold {a} else {b}

}

                                              // -+ r

fn select_based_on_unit_circle( // |-+ B
threshold: float, a: &r/T, b: &r/T) -> &r/T { // | |
// | |
let shape = Circle(Point {x: 0., y: 0.}, 1.); // | |
select(&shape, threshold, a, b) // | |
} // |-+
// -+


In this call to `select()`, the lifetime of the first parameter shape
is B, the function body. Both of the second two parameters `a` and `b`
share the same lifetime, `r`, which is a lifetime parameter of
`select_based_on_unit_circle()`. The caller will infer the
intersection of these two lifetimes as the lifetime of the returned
value, and hence the return value of `shape()` will be assigned a
lifetime of B. This will in turn lead to a compilation error, because
`select_based_on_unit_circle()` is supposed to return a value with the
lifetime `r`.

There is no function called "shape()", but "select()" would be consistent.

@nejucomo
Copy link
Author

Ack! github formatting ate this, but the relevant text is unmunged at the bottom of the block quote.

@brson brson closed this as completed in ed48e76 Oct 29, 2012
flip1995 pushed a commit to flip1995/rust that referenced this issue Aug 28, 2020
Don't use `to_string` in impl Display

fixes rust-lang#3876

this PR is derived from [Toxyxer's implementation](rust-lang/rust-clippy#5574).
changelog: add [`to_string_in_display`] lint
RalfJung pushed a commit to RalfJung/rust that referenced this issue Sep 17, 2024
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

2 participants