mirror of
https://gitee.com/openharmony/third_party_rust_syn
synced 2024-11-27 09:50:41 +00:00
Print line/column for codegen parse errors
This commit is contained in:
parent
2e16ee37a3
commit
87e995d296
@ -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"] }
|
||||
|
@ -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,
|
||||
})
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user