-
Notifications
You must be signed in to change notification settings - Fork 13.9k
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-lifetimesArea: Lifetimes / regionsArea: Lifetimes / regionsC-bugCategory: This is a bug.Category: This is a bug.D-papercutDiagnostics: An error or lint that needs small tweaks.Diagnostics: An error or lint that needs small tweaks.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.
Description
This code (which comes from a rustup PR I'm working on -- rust-lang/rustup#2540) produces a somewhat confusing lifetime error:
pub fn get_toolchains_from_glob(
&self,
pattern: &Pattern,
) -> Result<impl Iterator<Item = Toolchain<'_>>> {
Ok(self
.list_toolchains_iter()?
.filter(|toolchain| pattern.matches(toolchain))
.map(|toolchain| Toolchain::from(self, &toolchain).unwrap()))
}
fn list_toolchains_iter(&self) -> Result<Box<dyn Iterator<Item = String>>> {
if utils::is_directory(&self.toolchains_dir) {
Ok(Box::new(
utils::read_dir("toolchains", &self.toolchains_dir)?
.filter_map(io::Result::ok)
.filter(|e| e.file_type().map(|f| !f.is_file()).unwrap_or(false))
.filter_map(|e| e.file_name().into_string().ok()),
))
} else {
Ok(Box::new(iter::empty()))
}
}Errors:
error[E0623]: lifetime mismatch
--> src/config.rs:370:17
|
369 | pattern: &Pattern,
| -------- this parameter and the return type are declared with different lifetimes...
370 | ) -> Result<impl Iterator<Item = Toolchain<'_>>> {
| -------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
| |
| ...but data from `pattern` is returned here
But isn't the "...but data from" error supposed to point to the code that returns data from pattern, not the return type annotation?
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-lifetimesArea: Lifetimes / regionsArea: Lifetimes / regionsC-bugCategory: This is a bug.Category: This is a bug.D-papercutDiagnostics: An error or lint that needs small tweaks.Diagnostics: An error or lint that needs small tweaks.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.