-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
'Dropping temporaries' prevents borrow check to succeed in match arm without shared ownership #76149
Copy link
Copy link
Open
Labels
A-destructorsArea: Destructors (`Drop`, …)Area: Destructors (`Drop`, …)A-lifetimesArea: Lifetimes / regionsArea: Lifetimes / regionsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`Area: Suggestions generated by the compiler applied by `cargo fix`C-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language teamRelevant to the language team
Metadata
Metadata
Assignees
Labels
A-destructorsArea: Destructors (`Drop`, …)Area: Destructors (`Drop`, …)A-lifetimesArea: Lifetimes / regionsArea: Lifetimes / regionsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`Area: Suggestions generated by the compiler applied by `cargo fix`C-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language teamRelevant to the language team
Type
Fields
Give feedbackNo fields configured for issues without a type.
I tried this code (playground link):
I expected to see this happen:
The code compiles. Especially it's possible to call
owner.do_something_else()in the match branch dealing with the error, which does not borrow fromowner.Instead, this happened:
According to The Rust Reference:Destructors I believe the drop scope should be relative to each match arm, not according to the outer scope. It appears that Rust still wants to drop the
Result<_, _>which is already dissolved in the match arm.Also, if no destructor is involved, the code compiles as expected.
The issue first occurred in
gitoxide, and here is theworkaround.Meta
rustc --version --verbose:rustc +nightly --version --verbose: