Skip to content

Commit 3719b08

Browse files
committed
Migrate derivable diagnostics in check_attr.rs
1 parent 49ce855 commit 3719b08

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

compiler/rustc_error_messages/locales/en-US/passes.ftl

+2
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,8 @@ passes_debug_visualizer_invalid = invalid argument
217217
.note_2 = OR
218218
.note_3 = expected: `gdb_script_file = "..."`
219219
220+
passes_debug_visualizer_unreadable = couldn't read {$file}: {$error}
221+
220222
passes_rustc_allow_const_fn_unstable = attribute should be applied to `const fn`
221223
.label = not a `const fn`
222224

compiler/rustc_passes/src/check_attr.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//! conflicts between multiple such attributes attached to the same
55
//! item.
66
7-
use crate::errors;
7+
use crate::errors::{self, DebugVisualizerUnreadable};
88
use rustc_ast::{ast, AttrStyle, Attribute, Lit, LitKind, MetaItemKind, NestedMetaItem};
99
use rustc_data_structures::fx::FxHashMap;
1010
use rustc_errors::{fluent, struct_span_err, Applicability, MultiSpan};
@@ -1842,13 +1842,11 @@ impl CheckAttrVisitor<'_> {
18421842
match std::fs::File::open(&file) {
18431843
Ok(_) => true,
18441844
Err(err) => {
1845-
self.tcx
1846-
.sess
1847-
.struct_span_err(
1848-
meta_item.span,
1849-
&format!("couldn't read {}: {}", file.display(), err),
1850-
)
1851-
.emit();
1845+
self.tcx.sess.emit_err(DebugVisualizerUnreadable {
1846+
span: meta_item.span,
1847+
file: &file,
1848+
error: err,
1849+
} );
18521850
false
18531851
}
18541852
}

compiler/rustc_passes/src/errors.rs

+11
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::{io::Error, path::Path};
2+
13
use rustc_errors::{Applicability, MultiSpan};
24
use rustc_hir::Target;
35
use rustc_macros::{LintDiagnostic, SessionDiagnostic, SessionSubdiagnostic};
@@ -527,6 +529,15 @@ pub struct DebugVisualizerInvalid {
527529
pub span: Span,
528530
}
529531

532+
#[derive(SessionDiagnostic)]
533+
#[diag(passes::debug_visualizer_unreadable)]
534+
pub struct DebugVisualizerUnreadable<'a> {
535+
#[primary_span]
536+
pub span: Span,
537+
pub file: &'a Path,
538+
pub error: Error,
539+
}
540+
530541
#[derive(SessionDiagnostic)]
531542
#[diag(passes::rustc_allow_const_fn_unstable)]
532543
pub struct RustcAllowConstFnUnstable {

0 commit comments

Comments
 (0)