1
Fork 0

Migrate InvalidAttrAtCrateLevel

Co-authored-by: Nathan Stocks <cleancut@github.com>
Co-authored-by: rdvdev2 <rdvdev2@gmail.com>
This commit is contained in:
rdvdev2 2022-09-02 05:19:03 +02:00 committed by Nathan Stocks
parent 0315d7c9db
commit 2c3351c9a6
4 changed files with 43 additions and 27 deletions

View file

@ -1,6 +1,6 @@
use std::{io::Error, path::Path};
use rustc_errors::{Applicability, MultiSpan};
use rustc_errors::{Applicability, ErrorGuaranteed, IntoDiagnostic, MultiSpan};
use rustc_hir::Target;
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
use rustc_span::{Span, Symbol};
@ -714,3 +714,33 @@ pub struct UnknownLangItem {
pub span: Span,
pub name: Symbol,
}
pub struct InvalidAttrAtCrateLevel {
pub span: Span,
pub snippet: Option<String>,
pub name: Symbol,
}
impl IntoDiagnostic<'_> for InvalidAttrAtCrateLevel {
fn into_diagnostic(
self,
handler: &'_ rustc_errors::Handler,
) -> rustc_errors::DiagnosticBuilder<'_, ErrorGuaranteed> {
let mut diag =
handler.struct_err(rustc_errors::fluent::passes::invalid_attr_at_crate_level);
diag.set_span(self.span);
diag.set_arg("name", self.name);
// Only emit an error with a suggestion if we can create a string out
// of the attribute span
if let Some(src) = self.snippet {
let replacement = src.replace("#!", "#");
diag.span_suggestion_verbose(
self.span,
rustc_errors::fluent::passes::suggestion,
replacement,
rustc_errors::Applicability::MachineApplicable,
);
}
diag
}
}