Skip to content

Confusing language when introducing lifetimes #2436

@tillulen

Description

@tillulen

In the section “Lifetime Annotations in Function Signatures” of chapter 10, there is the following description of listing 10-22:

fn longest<'a>(x: &'a str, y: &'a str) -> &'a str {
    if x.len() > y.len() {
        x
    } else {
        y
    }
}

The function signature now tells Rust that for some lifetime 'a, the function takes two parameters, both of which are string slices that live at least as long as lifetime 'a. The function signature also tells Rust that the string slice returned from the function will live at least as long as lifetime 'a. [Emphasis added]

Shouldn’t the last sentence read “the string slice returned from the function will live at most as long as lifetime 'a”?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions