Skip to content

Suggest adding a lifetime parameter on "data from X flows into Y" #78312

Closed
@Aaron1011

Description

@Aaron1011

The following code:

fn foo(mut first: &u8, second: &u8) {
    first = second;
}

fn main() {}

produces the following error:

error[E0623]: lifetime mismatch
 --> src/lib.rs:2:13
  |
1 | fn foo(mut first: &u8, second: &u8) {
  |                   ---          --- these two types are declared with different lifetimes...
2 |     first = second;
  |             ^^^^^^ ...but data from `second` flows into `first` here

We could suggest changing the signature to fn foo<'a>(mut first: &'a u8, second: &'a u8)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-lifetimesArea: Lifetimes / regionsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`C-enhancementCategory: An issue proposing an enhancement or a PR with one.D-newcomer-roadblockDiagnostics: Confusing error or lint; hard to understand for new users.D-papercutDiagnostics: An error or lint that needs small tweaks.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions