You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
Don't use `to_string` in impl Display
fixesrust-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
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}
}
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) // | |
} // |-+
// -+
There is no function called "shape()", but "select()" would be consistent.
The text was updated successfully, but these errors were encountered: