-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.D-verboseDiagnostics: Too much output caused by a single piece of incorrect code.Diagnostics: Too much output caused by a single piece of incorrect code.P-lowLow priorityLow priorityT-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
The following code produces a quite unhelpful error from the compiler:
use std::io;
use std::fs;
use std::path::{Path, PathBuf};
pub fn build<P: AsRef<Path>>(path: P) -> Result<Vec<PathBuf>, io::Error> {
let entries = fs::read_dir(path)?;
let filevec = entries.map(| res | res.map(| e | e.path()))
.collect::<Result<Vec<_>, io::Error>>?;
Ok(filevec)
}
The error in question being .collect::<Result<Vec<_>, io::Error>>?;
instead of .collect::<Result<Vec<_>, io::Error>>()?;
.
Compiler output:
Compiling playground v0.0.1 (/playground)
error: field expressions may not have generic arguments
--> src/lib.rs:9:36
|
9 | .collect::<Result<Vec<_>, io::Error>>?;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to previous error
error: could not compile `playground`.
To learn more, run the command again with --verbose.
It's quite a simple mistake, but I got confused by the error message and tried different type-related fixes which didn't work (obviously).
This might be related to #54521
joseluis, rben01 and Gowee
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.D-verboseDiagnostics: Too much output caused by a single piece of incorrect code.Diagnostics: Too much output caused by a single piece of incorrect code.P-lowLow priorityLow priorityT-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.