Open
Description
The following code:
struct A<'a> {
backref: Option<&'a mut A<'a>>,
value: String,
}
impl<'a> A<'a> {
fn child_with_value(&'a mut self, value: String) -> A<'a> {
A {
backref: Some(self),
value,
}
}
}
fn works(a: &mut A) {
println!("{}", a.value);
}
fn errors(a: &mut A) {
let mut b = a.child_with_value("foo".into());
errors(&mut b);
}
I expected to see this happen:
Given that the invocation should be legal, I expect this to compile without issues :)
Instead, this happened: Compiler error above. Note that the variable flows into itself, which seems strange
Meta
Tested both on stable and nightly:
rustc --version --verbose
:
rustc 1.50.0-nightly (f0f68778f 2020-12-09)
binary: rustc
commit-hash: f0f68778f798d6d34649745b41770829b17ba5b8
commit-date: 2020-12-09
host: x86_64-unknown-linux-gnu
release: 1.50.0-nightly
Backtrace not applicable I think?
Metadata
Metadata
Assignees
Labels
Area: Messages for errors, warnings, and lintsArea: Lifetimes / regionsArea: Suggestions generated by the compiler applied by `cargo fix`Category: This is a bug.Diagnostics: Confusing error or lint that should be reworked.Diagnostics: A diagnostic that is giving misleading or incorrect information.Diagnostics: An error or lint that doesn't give enough information about the problem at hand.Relevant to the compiler team, which will review and decide on the PR/issue.