rustc_passes: remove huge error imports
This commit is contained in:
parent
3478b162f3
commit
a399f0ca84
2 changed files with 57 additions and 56 deletions
|
@ -4,11 +4,7 @@
|
|||
//! conflicts between multiple such attributes attached to the same
|
||||
//! item.
|
||||
|
||||
use crate::errors::{
|
||||
self, AttrApplication, DebugVisualizerUnreadable, InvalidAttrAtCrateLevel, ObjectLifetimeErr,
|
||||
OnlyHasEffectOn, ProcMacroDiffArguments, ProcMacroInvalidAbi, ProcMacroMissingArguments,
|
||||
ProcMacroTypeError, ProcMacroUnsafe, TransparentIncompatible, UnrecognizedReprHint,
|
||||
};
|
||||
use crate::errors;
|
||||
use rustc_ast::{ast, AttrStyle, Attribute, LitKind, MetaItemKind, MetaItemLit, NestedMetaItem};
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_errors::{fluent, Applicability, IntoDiagnosticArg, MultiSpan};
|
||||
|
@ -399,7 +395,7 @@ impl CheckAttrVisitor<'_> {
|
|||
UNUSED_ATTRIBUTES,
|
||||
hir_id,
|
||||
attr.span,
|
||||
OnlyHasEffectOn {
|
||||
errors::OnlyHasEffectOn {
|
||||
attr_name: attr.name_or_empty(),
|
||||
target_name: allowed_target.name().replace(' ', "_"),
|
||||
},
|
||||
|
@ -468,7 +464,7 @@ impl CheckAttrVisitor<'_> {
|
|||
ObjectLifetimeDefault::Param(def_id) => tcx.item_name(def_id).to_string(),
|
||||
ObjectLifetimeDefault::Ambiguous => "Ambiguous".to_owned(),
|
||||
};
|
||||
tcx.sess.emit_err(ObjectLifetimeErr { span: p.span, repr });
|
||||
tcx.sess.emit_err(errors::ObjectLifetimeErr { span: p.span, repr });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1715,7 +1711,7 @@ impl CheckAttrVisitor<'_> {
|
|||
match target {
|
||||
Target::Struct | Target::Union | Target::Enum => continue,
|
||||
_ => {
|
||||
self.tcx.sess.emit_err(AttrApplication::StructEnumUnion {
|
||||
self.tcx.sess.emit_err(errors::AttrApplication::StructEnumUnion {
|
||||
hint_span: hint.span(),
|
||||
span,
|
||||
});
|
||||
|
@ -1736,16 +1732,18 @@ impl CheckAttrVisitor<'_> {
|
|||
match target {
|
||||
Target::Struct | Target::Union | Target::Enum | Target::Fn => continue,
|
||||
_ => {
|
||||
self.tcx.sess.emit_err(AttrApplication::StructEnumFunctionUnion {
|
||||
hint_span: hint.span(),
|
||||
span,
|
||||
});
|
||||
self.tcx.sess.emit_err(
|
||||
errors::AttrApplication::StructEnumFunctionUnion {
|
||||
hint_span: hint.span(),
|
||||
span,
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
sym::packed => {
|
||||
if target != Target::Struct && target != Target::Union {
|
||||
self.tcx.sess.emit_err(AttrApplication::StructUnion {
|
||||
self.tcx.sess.emit_err(errors::AttrApplication::StructUnion {
|
||||
hint_span: hint.span(),
|
||||
span,
|
||||
});
|
||||
|
@ -1756,9 +1754,10 @@ impl CheckAttrVisitor<'_> {
|
|||
sym::simd => {
|
||||
is_simd = true;
|
||||
if target != Target::Struct {
|
||||
self.tcx
|
||||
.sess
|
||||
.emit_err(AttrApplication::Struct { hint_span: hint.span(), span });
|
||||
self.tcx.sess.emit_err(errors::AttrApplication::Struct {
|
||||
hint_span: hint.span(),
|
||||
span,
|
||||
});
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
|
@ -1768,7 +1767,7 @@ impl CheckAttrVisitor<'_> {
|
|||
match target {
|
||||
Target::Struct | Target::Union | Target::Enum => continue,
|
||||
_ => {
|
||||
self.tcx.sess.emit_err(AttrApplication::StructEnumUnion {
|
||||
self.tcx.sess.emit_err(errors::AttrApplication::StructEnumUnion {
|
||||
hint_span: hint.span(),
|
||||
span,
|
||||
});
|
||||
|
@ -1789,15 +1788,16 @@ impl CheckAttrVisitor<'_> {
|
|||
| sym::usize => {
|
||||
int_reprs += 1;
|
||||
if target != Target::Enum {
|
||||
self.tcx
|
||||
.sess
|
||||
.emit_err(AttrApplication::Enum { hint_span: hint.span(), span });
|
||||
self.tcx.sess.emit_err(errors::AttrApplication::Enum {
|
||||
hint_span: hint.span(),
|
||||
span,
|
||||
});
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
self.tcx.sess.emit_err(UnrecognizedReprHint { span: hint.span() });
|
||||
self.tcx.sess.emit_err(errors::UnrecognizedReprHint { span: hint.span() });
|
||||
continue;
|
||||
}
|
||||
};
|
||||
|
@ -1810,9 +1810,10 @@ impl CheckAttrVisitor<'_> {
|
|||
// Error on repr(transparent, <anything else>).
|
||||
if is_transparent && hints.len() > 1 {
|
||||
let hint_spans: Vec<_> = hint_spans.clone().collect();
|
||||
self.tcx
|
||||
.sess
|
||||
.emit_err(TransparentIncompatible { hint_spans, target: target.to_string() });
|
||||
self.tcx.sess.emit_err(errors::TransparentIncompatible {
|
||||
hint_spans,
|
||||
target: target.to_string(),
|
||||
});
|
||||
}
|
||||
// Warn on repr(u8, u16), repr(C, simd), and c-like-enum-repr(C, u8)
|
||||
if (int_reprs > 1)
|
||||
|
@ -1965,7 +1966,7 @@ impl CheckAttrVisitor<'_> {
|
|||
match std::fs::File::open(&file) {
|
||||
Ok(_) => true,
|
||||
Err(error) => {
|
||||
self.tcx.sess.emit_err(DebugVisualizerUnreadable {
|
||||
self.tcx.sess.emit_err(errors::DebugVisualizerUnreadable {
|
||||
span: meta_item.span,
|
||||
file: &file,
|
||||
error,
|
||||
|
@ -2175,12 +2176,15 @@ impl CheckAttrVisitor<'_> {
|
|||
let drcx = DeepRejectCtxt { treat_obligation_params: TreatParams::AsInfer };
|
||||
|
||||
if sig.abi != Abi::Rust {
|
||||
tcx.sess.emit_err(ProcMacroInvalidAbi { span: hir_sig.span, abi: sig.abi.name() });
|
||||
tcx.sess.emit_err(errors::ProcMacroInvalidAbi {
|
||||
span: hir_sig.span,
|
||||
abi: sig.abi.name(),
|
||||
});
|
||||
self.abort.set(true);
|
||||
}
|
||||
|
||||
if sig.unsafety == Unsafety::Unsafe {
|
||||
tcx.sess.emit_err(ProcMacroUnsafe { span: hir_sig.span });
|
||||
tcx.sess.emit_err(errors::ProcMacroUnsafe { span: hir_sig.span });
|
||||
self.abort.set(true);
|
||||
}
|
||||
|
||||
|
@ -2188,7 +2192,7 @@ impl CheckAttrVisitor<'_> {
|
|||
|
||||
// Typecheck the output
|
||||
if !drcx.types_may_unify(output, tokenstream) {
|
||||
tcx.sess.emit_err(ProcMacroTypeError {
|
||||
tcx.sess.emit_err(errors::ProcMacroTypeError {
|
||||
span: hir_sig.decl.output.span(),
|
||||
found: output,
|
||||
kind,
|
||||
|
@ -2198,7 +2202,7 @@ impl CheckAttrVisitor<'_> {
|
|||
}
|
||||
|
||||
if sig.inputs().len() < expected_input_count {
|
||||
tcx.sess.emit_err(ProcMacroMissingArguments {
|
||||
tcx.sess.emit_err(errors::ProcMacroMissingArguments {
|
||||
expected_input_count,
|
||||
span: hir_sig.span,
|
||||
kind,
|
||||
|
@ -2213,7 +2217,7 @@ impl CheckAttrVisitor<'_> {
|
|||
sig.inputs().iter().zip(hir_sig.decl.inputs).take(expected_input_count)
|
||||
{
|
||||
if !drcx.types_may_unify(*arg, tokenstream) {
|
||||
tcx.sess.emit_err(ProcMacroTypeError {
|
||||
tcx.sess.emit_err(errors::ProcMacroTypeError {
|
||||
span: input.span,
|
||||
found: *arg,
|
||||
kind,
|
||||
|
@ -2228,7 +2232,7 @@ impl CheckAttrVisitor<'_> {
|
|||
let body_id = tcx.hir().body_owned_by(id.def_id);
|
||||
let excess = tcx.hir().body(body_id).params.get(expected_input_count..);
|
||||
if let Some(excess @ [begin @ end] | excess @ [begin, .., end]) = excess {
|
||||
tcx.sess.emit_err(ProcMacroDiffArguments {
|
||||
tcx.sess.emit_err(errors::ProcMacroDiffArguments {
|
||||
span: begin.span.to(end.span),
|
||||
count: excess.len(),
|
||||
kind,
|
||||
|
@ -2378,7 +2382,7 @@ fn check_invalid_crate_level_attr(tcx: TyCtxt<'_>, attrs: &[Attribute]) {
|
|||
if attr.style == AttrStyle::Inner {
|
||||
for attr_to_check in ATTRS_TO_CHECK {
|
||||
if attr.has_name(*attr_to_check) {
|
||||
tcx.sess.emit_err(InvalidAttrAtCrateLevel {
|
||||
tcx.sess.emit_err(errors::InvalidAttrAtCrateLevel {
|
||||
span: attr.span,
|
||||
snippet: tcx.sess.source_map().span_to_snippet(attr.span).ok(),
|
||||
name: *attr_to_check,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue