Remove source path from parser errors (#9322)

## Summary

I always found it odd that we had to pass this in, since it's really
higher-level context for the error. The awkwardness is further evidenced
by the fact that we pass in fake values everywhere (even outside of
tests). The source path isn't actually used to display the error; it's
only accessed elsewhere to _re-display_ the error in certain cases. This
PR modifies to instead pass the path directly in those cases.
This commit is contained in:
Charlie Marsh 2023-12-30 16:33:05 -04:00 committed by GitHub
parent eb9a1bc5f1
commit e80260a3c5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
45 changed files with 623 additions and 714 deletions

View file

@ -300,22 +300,14 @@ fn ensure_unchanged_ast(
let source_type = options.source_type();
// Parse the unformatted code.
let mut unformatted_ast = parse(
unformatted_code,
source_type.as_mode(),
&input_path.to_string_lossy(),
)
.expect("Unformatted code to be valid syntax");
let mut unformatted_ast = parse(unformatted_code, source_type.as_mode())
.expect("Unformatted code to be valid syntax");
Normalizer.visit_module(&mut unformatted_ast);
let unformatted_ast = ComparableMod::from(&unformatted_ast);
// Parse the formatted code.
let mut formatted_ast = parse(
formatted_code,
source_type.as_mode(),
&input_path.to_string_lossy(),
)
.expect("Formatted code to be valid syntax");
let mut formatted_ast =
parse(formatted_code, source_type.as_mode()).expect("Formatted code to be valid syntax");
Normalizer.visit_module(&mut formatted_ast);
let formatted_ast = ComparableMod::from(&formatted_ast);