Open
Description
Given the following code:
fn bar(writer: &mut Writer) {
baz(writer.indent());
writer.write("world");
}
fn baz(writer: &mut Writer) {
writer.write("hello");
}
pub struct Writer<'a> {
target: &'a mut String,
indent: usize,
}
impl<'a> Writer<'a> {
fn indent(&'a mut self) -> &'a mut Self {
&mut Self {
target: self.target,
indent: self.indent + 1,
}
}
fn write(&mut self, s: &str) {
for _ in 0..self.indent {
self.target.push(' ');
}
self.target.push_str(s);
self.target.push('\n');
}
}
The current output is:
error[E0623]: lifetime mismatch
--> src/writer.rs:2:16
|
1 | fn bar(writer: &mut Writer) {
| -----------
| |
| these two types are declared with different lifetimes...
2 | baz(writer.indent());
| ^^^^^^ ...but data from `writer` flows into `writer` here
This is really confusing. The error mentions two types, but then it only points to one type. And then it says "data from writer
flows into writer
". What? The data flows into itself?
Metadata
Metadata
Assignees
Labels
Area: Messages for errors, warnings, and lintsArea: Lifetimes / regionsArea: Variance (https://doc.rust-lang.org/nomicon/subtyping.html)Diagnostics: Confusing error or lint that should be reworked.Diagnostics: Confusing error or lint; hard to understand for new users.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.