diff --git a/src/bin/rustfmt.rs b/src/bin/rustfmt.rs index 400ee907021..227ab849b3c 100644 --- a/src/bin/rustfmt.rs +++ b/src/bin/rustfmt.rs @@ -367,7 +367,16 @@ fn determine_operation(matches: &Matches) -> FmtResult { }); } - let files: Vec<_> = matches.free.iter().map(PathBuf::from).collect(); + let files: Vec<_> = matches + .free + .iter() + .map(|s| { + let p = PathBuf::from(s); + // we will do comparison later, so here tries to canonicalize first + // to get the expected behavior. + p.canonicalize().unwrap_or(p) + }) + .collect(); Ok(Operation::Format { files: files,