Print line/column for codegen parse errors

This commit is contained in:
David Tolnay 2019-11-30 14:50:56 -08:00
parent 2e16ee37a3
commit 87e995d296
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82
2 changed files with 10 additions and 3 deletions

View File

@ -11,7 +11,7 @@ anyhow = "1.0"
color-backtrace = "0.2"
indexmap = { version = "1.0", features = ["serde-1"] }
inflections = "1.1"
proc-macro2 = "1.0"
proc-macro2 = { version = "1.0", features = ["span-locations"] }
quote = "1.0"
rustfmt = { package = "rustfmt-nightly", git = "https://github.com/dtolnay/rustfmt", branch = "error" }
semver = { version = "0.9", features = ["serde"] }

View File

@ -508,9 +508,11 @@ fn get_features(attrs: &[syn::Attribute], base: &[syn::Attribute]) -> Vec<syn::A
}
#[derive(Error, Debug)]
#[error("{path}: {error}")]
#[error("{path}:{line}:{column}: {error}")]
struct LoadFileError {
path: PathBuf,
line: usize,
column: usize,
error: syn::Error,
}
@ -524,9 +526,14 @@ fn load_file<P: AsRef<Path>>(
Some(error) => error,
};
let error = error.downcast::<syn::Error>()?;
let span = error.span().start();
bail!(LoadFileError {
path: name.as_ref().to_owned(),
error: error.downcast()?,
line: span.line,
column: span.column + 1,
error,
})
}