mirror of
https://github.com/rust-lang/cargo.git
synced 2025-09-28 11:20:36 +00:00
refactor(frontmatter): Clarify the span
This commit is contained in:
parent
b6326d3255
commit
42027af706
@ -286,14 +286,14 @@ fn is_whitespace(c: char) -> bool {
|
||||
#[derive(Debug)]
|
||||
pub struct FrontmatterError {
|
||||
message: String,
|
||||
span: Span,
|
||||
primary_span: Span,
|
||||
}
|
||||
|
||||
impl FrontmatterError {
|
||||
pub fn new(message: impl Into<String>, span: Span) -> Self {
|
||||
Self {
|
||||
message: message.into(),
|
||||
span,
|
||||
primary_span: span,
|
||||
}
|
||||
}
|
||||
|
||||
@ -301,8 +301,8 @@ impl FrontmatterError {
|
||||
self.message.as_str()
|
||||
}
|
||||
|
||||
pub fn span(&self) -> Span {
|
||||
self.span.clone()
|
||||
pub fn primary_span(&self) -> Span {
|
||||
self.primary_span.clone()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2783,7 +2783,7 @@ fn emit_frontmatter_diagnostic(
|
||||
manifest_file: &Path,
|
||||
gctx: &GlobalContext,
|
||||
) -> anyhow::Error {
|
||||
let span = e.span();
|
||||
let primary_span = e.primary_span();
|
||||
|
||||
// Get the path to the manifest, relative to the cwd
|
||||
let manifest_path = diff_paths(manifest_file, gctx.cwd())
|
||||
@ -2793,7 +2793,7 @@ fn emit_frontmatter_diagnostic(
|
||||
let group = Group::with_title(Level::ERROR.primary_title(e.message())).element(
|
||||
Snippet::source(contents)
|
||||
.path(manifest_path)
|
||||
.annotation(AnnotationKind::Primary.span(span)),
|
||||
.annotation(AnnotationKind::Primary.span(primary_span)),
|
||||
);
|
||||
|
||||
if let Err(err) = gctx.shell().print_report(&[group], true) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user