Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 0315d7c

Browse files
naritanaraCleanCut
authored andcommitted
Migrate derivable diagnostics in check_attr.rs
1 parent 17a4a68 commit 0315d7c

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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 6 additions & 8 deletions
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};
@@ -1863,13 +1863,11 @@ impl CheckAttrVisitor<'_> {
18631863
match std::fs::File::open(&file) {
18641864
Ok(_) => true,
18651865
Err(err) => {
1866-
self.tcx
1867-
.sess
1868-
.struct_span_err(
1869-
meta_item.span,
1870-
&format!("couldn't read {}: {}", file.display(), err),
1871-
)
1872-
.emit();
1866+
self.tcx.sess.emit_err(DebugVisualizerUnreadable {
1867+
span: meta_item.span,
1868+
file: &file,
1869+
error: err,
1870+
} );
18731871
false
18741872
}
18751873
}

compiler/rustc_passes/src/errors.rs

Lines changed: 11 additions & 0 deletions
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::{Diagnostic, LintDiagnostic, Subdiagnostic};
@@ -527,6 +529,15 @@ pub struct DebugVisualizerInvalid {
527529
pub span: Span,
528530
}
529531

532+
#[derive(Diagnostic)]
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(Diagnostic)]
531542
#[diag(passes::rustc_allow_const_fn_unstable)]
532543
pub struct RustcAllowConstFnUnstable {

0 commit comments

Comments
 (0)