Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Migrate derivable diagnostics in check_attr.rs
  • Loading branch information
naritanara committed Sep 2, 2022
commit 3719b086e62646d284e6dcb0f498b0e016d4bf56
2 changes: 2 additions & 0 deletions compiler/rustc_error_messages/locales/en-US/passes.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ passes_debug_visualizer_invalid = invalid argument
.note_2 = OR
.note_3 = expected: `gdb_script_file = "..."`

passes_debug_visualizer_unreadable = couldn't read {$file}: {$error}

passes_rustc_allow_const_fn_unstable = attribute should be applied to `const fn`
.label = not a `const fn`

Expand Down
14 changes: 6 additions & 8 deletions compiler/rustc_passes/src/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//! conflicts between multiple such attributes attached to the same
//! item.

use crate::errors;
use crate::errors::{self, DebugVisualizerUnreadable};
use rustc_ast::{ast, AttrStyle, Attribute, Lit, LitKind, MetaItemKind, NestedMetaItem};
use rustc_data_structures::fx::FxHashMap;
use rustc_errors::{fluent, struct_span_err, Applicability, MultiSpan};
Expand Down Expand Up @@ -1842,13 +1842,11 @@ impl CheckAttrVisitor<'_> {
match std::fs::File::open(&file) {
Ok(_) => true,
Err(err) => {
self.tcx
.sess
.struct_span_err(
meta_item.span,
&format!("couldn't read {}: {}", file.display(), err),
)
.emit();
self.tcx.sess.emit_err(DebugVisualizerUnreadable {
span: meta_item.span,
file: &file,
error: err,
} );
false
}
}
Expand Down
11 changes: 11 additions & 0 deletions compiler/rustc_passes/src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::{io::Error, path::Path};

use rustc_errors::{Applicability, MultiSpan};
use rustc_hir::Target;
use rustc_macros::{LintDiagnostic, SessionDiagnostic, SessionSubdiagnostic};
Expand Down Expand Up @@ -527,6 +529,15 @@ pub struct DebugVisualizerInvalid {
pub span: Span,
}

#[derive(SessionDiagnostic)]
#[diag(passes::debug_visualizer_unreadable)]
pub struct DebugVisualizerUnreadable<'a> {
#[primary_span]
pub span: Span,
pub file: &'a Path,
pub error: Error,
}

#[derive(SessionDiagnostic)]
#[diag(passes::rustc_allow_const_fn_unstable)]
pub struct RustcAllowConstFnUnstable {
Expand Down