Skip to content

Commit a399f0c

Browse files
committed
rustc_passes: remove huge error imports
1 parent 3478b16 commit a399f0c

File tree

2 files changed

+57
-56
lines changed

2 files changed

+57
-56
lines changed

compiler/rustc_passes/src/check_attr.rs

Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@
44
//! conflicts between multiple such attributes attached to the same
55
//! item.
66
7-
use crate::errors::{
8-
self, AttrApplication, DebugVisualizerUnreadable, InvalidAttrAtCrateLevel, ObjectLifetimeErr,
9-
OnlyHasEffectOn, ProcMacroDiffArguments, ProcMacroInvalidAbi, ProcMacroMissingArguments,
10-
ProcMacroTypeError, ProcMacroUnsafe, TransparentIncompatible, UnrecognizedReprHint,
11-
};
7+
use crate::errors;
128
use rustc_ast::{ast, AttrStyle, Attribute, LitKind, MetaItemKind, MetaItemLit, NestedMetaItem};
139
use rustc_data_structures::fx::FxHashMap;
1410
use rustc_errors::{fluent, Applicability, IntoDiagnosticArg, MultiSpan};
@@ -399,7 +395,7 @@ impl CheckAttrVisitor<'_> {
399395
UNUSED_ATTRIBUTES,
400396
hir_id,
401397
attr.span,
402-
OnlyHasEffectOn {
398+
errors::OnlyHasEffectOn {
403399
attr_name: attr.name_or_empty(),
404400
target_name: allowed_target.name().replace(' ', "_"),
405401
},
@@ -468,7 +464,7 @@ impl CheckAttrVisitor<'_> {
468464
ObjectLifetimeDefault::Param(def_id) => tcx.item_name(def_id).to_string(),
469465
ObjectLifetimeDefault::Ambiguous => "Ambiguous".to_owned(),
470466
};
471-
tcx.sess.emit_err(ObjectLifetimeErr { span: p.span, repr });
467+
tcx.sess.emit_err(errors::ObjectLifetimeErr { span: p.span, repr });
472468
}
473469
}
474470
}
@@ -1715,7 +1711,7 @@ impl CheckAttrVisitor<'_> {
17151711
match target {
17161712
Target::Struct | Target::Union | Target::Enum => continue,
17171713
_ => {
1718-
self.tcx.sess.emit_err(AttrApplication::StructEnumUnion {
1714+
self.tcx.sess.emit_err(errors::AttrApplication::StructEnumUnion {
17191715
hint_span: hint.span(),
17201716
span,
17211717
});
@@ -1736,16 +1732,18 @@ impl CheckAttrVisitor<'_> {
17361732
match target {
17371733
Target::Struct | Target::Union | Target::Enum | Target::Fn => continue,
17381734
_ => {
1739-
self.tcx.sess.emit_err(AttrApplication::StructEnumFunctionUnion {
1740-
hint_span: hint.span(),
1741-
span,
1742-
});
1735+
self.tcx.sess.emit_err(
1736+
errors::AttrApplication::StructEnumFunctionUnion {
1737+
hint_span: hint.span(),
1738+
span,
1739+
},
1740+
);
17431741
}
17441742
}
17451743
}
17461744
sym::packed => {
17471745
if target != Target::Struct && target != Target::Union {
1748-
self.tcx.sess.emit_err(AttrApplication::StructUnion {
1746+
self.tcx.sess.emit_err(errors::AttrApplication::StructUnion {
17491747
hint_span: hint.span(),
17501748
span,
17511749
});
@@ -1756,9 +1754,10 @@ impl CheckAttrVisitor<'_> {
17561754
sym::simd => {
17571755
is_simd = true;
17581756
if target != Target::Struct {
1759-
self.tcx
1760-
.sess
1761-
.emit_err(AttrApplication::Struct { hint_span: hint.span(), span });
1757+
self.tcx.sess.emit_err(errors::AttrApplication::Struct {
1758+
hint_span: hint.span(),
1759+
span,
1760+
});
17621761
} else {
17631762
continue;
17641763
}
@@ -1768,7 +1767,7 @@ impl CheckAttrVisitor<'_> {
17681767
match target {
17691768
Target::Struct | Target::Union | Target::Enum => continue,
17701769
_ => {
1771-
self.tcx.sess.emit_err(AttrApplication::StructEnumUnion {
1770+
self.tcx.sess.emit_err(errors::AttrApplication::StructEnumUnion {
17721771
hint_span: hint.span(),
17731772
span,
17741773
});
@@ -1789,15 +1788,16 @@ impl CheckAttrVisitor<'_> {
17891788
| sym::usize => {
17901789
int_reprs += 1;
17911790
if target != Target::Enum {
1792-
self.tcx
1793-
.sess
1794-
.emit_err(AttrApplication::Enum { hint_span: hint.span(), span });
1791+
self.tcx.sess.emit_err(errors::AttrApplication::Enum {
1792+
hint_span: hint.span(),
1793+
span,
1794+
});
17951795
} else {
17961796
continue;
17971797
}
17981798
}
17991799
_ => {
1800-
self.tcx.sess.emit_err(UnrecognizedReprHint { span: hint.span() });
1800+
self.tcx.sess.emit_err(errors::UnrecognizedReprHint { span: hint.span() });
18011801
continue;
18021802
}
18031803
};
@@ -1810,9 +1810,10 @@ impl CheckAttrVisitor<'_> {
18101810
// Error on repr(transparent, <anything else>).
18111811
if is_transparent && hints.len() > 1 {
18121812
let hint_spans: Vec<_> = hint_spans.clone().collect();
1813-
self.tcx
1814-
.sess
1815-
.emit_err(TransparentIncompatible { hint_spans, target: target.to_string() });
1813+
self.tcx.sess.emit_err(errors::TransparentIncompatible {
1814+
hint_spans,
1815+
target: target.to_string(),
1816+
});
18161817
}
18171818
// Warn on repr(u8, u16), repr(C, simd), and c-like-enum-repr(C, u8)
18181819
if (int_reprs > 1)
@@ -1965,7 +1966,7 @@ impl CheckAttrVisitor<'_> {
19651966
match std::fs::File::open(&file) {
19661967
Ok(_) => true,
19671968
Err(error) => {
1968-
self.tcx.sess.emit_err(DebugVisualizerUnreadable {
1969+
self.tcx.sess.emit_err(errors::DebugVisualizerUnreadable {
19691970
span: meta_item.span,
19701971
file: &file,
19711972
error,
@@ -2175,20 +2176,23 @@ impl CheckAttrVisitor<'_> {
21752176
let drcx = DeepRejectCtxt { treat_obligation_params: TreatParams::AsInfer };
21762177

21772178
if sig.abi != Abi::Rust {
2178-
tcx.sess.emit_err(ProcMacroInvalidAbi { span: hir_sig.span, abi: sig.abi.name() });
2179+
tcx.sess.emit_err(errors::ProcMacroInvalidAbi {
2180+
span: hir_sig.span,
2181+
abi: sig.abi.name(),
2182+
});
21792183
self.abort.set(true);
21802184
}
21812185

21822186
if sig.unsafety == Unsafety::Unsafe {
2183-
tcx.sess.emit_err(ProcMacroUnsafe { span: hir_sig.span });
2187+
tcx.sess.emit_err(errors::ProcMacroUnsafe { span: hir_sig.span });
21842188
self.abort.set(true);
21852189
}
21862190

21872191
let output = sig.output();
21882192

21892193
// Typecheck the output
21902194
if !drcx.types_may_unify(output, tokenstream) {
2191-
tcx.sess.emit_err(ProcMacroTypeError {
2195+
tcx.sess.emit_err(errors::ProcMacroTypeError {
21922196
span: hir_sig.decl.output.span(),
21932197
found: output,
21942198
kind,
@@ -2198,7 +2202,7 @@ impl CheckAttrVisitor<'_> {
21982202
}
21992203

22002204
if sig.inputs().len() < expected_input_count {
2201-
tcx.sess.emit_err(ProcMacroMissingArguments {
2205+
tcx.sess.emit_err(errors::ProcMacroMissingArguments {
22022206
expected_input_count,
22032207
span: hir_sig.span,
22042208
kind,
@@ -2213,7 +2217,7 @@ impl CheckAttrVisitor<'_> {
22132217
sig.inputs().iter().zip(hir_sig.decl.inputs).take(expected_input_count)
22142218
{
22152219
if !drcx.types_may_unify(*arg, tokenstream) {
2216-
tcx.sess.emit_err(ProcMacroTypeError {
2220+
tcx.sess.emit_err(errors::ProcMacroTypeError {
22172221
span: input.span,
22182222
found: *arg,
22192223
kind,
@@ -2228,7 +2232,7 @@ impl CheckAttrVisitor<'_> {
22282232
let body_id = tcx.hir().body_owned_by(id.def_id);
22292233
let excess = tcx.hir().body(body_id).params.get(expected_input_count..);
22302234
if let Some(excess @ [begin @ end] | excess @ [begin, .., end]) = excess {
2231-
tcx.sess.emit_err(ProcMacroDiffArguments {
2235+
tcx.sess.emit_err(errors::ProcMacroDiffArguments {
22322236
span: begin.span.to(end.span),
22332237
count: excess.len(),
22342238
kind,
@@ -2378,7 +2382,7 @@ fn check_invalid_crate_level_attr(tcx: TyCtxt<'_>, attrs: &[Attribute]) {
23782382
if attr.style == AttrStyle::Inner {
23792383
for attr_to_check in ATTRS_TO_CHECK {
23802384
if attr.has_name(*attr_to_check) {
2381-
tcx.sess.emit_err(InvalidAttrAtCrateLevel {
2385+
tcx.sess.emit_err(errors::InvalidAttrAtCrateLevel {
23822386
span: attr.span,
23832387
snippet: tcx.sess.source_map().span_to_snippet(attr.span).ok(),
23842388
name: *attr_to_check,

compiler/rustc_passes/src/stability.rs

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
//! A pass that annotates every item and method with its stability level,
22
//! propagating default levels lexically from parent to children ast nodes.
33
4-
use crate::errors::{
5-
self, CannotStabilizeDeprecated, DeprecatedAttribute, DuplicateFeatureErr,
6-
FeatureOnlyOnNightly, ImpliedFeatureNotExist, InvalidDeprecationVersion, InvalidStability,
7-
MissingConstErr, MissingConstStabAttr, MissingStabilityAttr, TraitImplConstStable,
8-
UnknownFeature, UselessStability,
9-
};
4+
use crate::errors;
105
use rustc_attr::{
116
self as attr, rust_version_symbol, ConstStability, Stability, StabilityLevel, Unstable,
127
UnstableReason, VERSION_PLACEHOLDER,
@@ -185,7 +180,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
185180
{
186181
self.tcx
187182
.sess
188-
.emit_err(MissingConstErr { fn_sig_span: fn_sig.span, const_span });
183+
.emit_err(errors::MissingConstErr { fn_sig_span: fn_sig.span, const_span });
189184
}
190185
}
191186
}
@@ -203,7 +198,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
203198

204199
if let Some((rustc_attr::Deprecation { is_since_rustc_version: true, .. }, span)) = &depr {
205200
if stab.is_none() {
206-
self.tcx.sess.emit_err(DeprecatedAttribute { span: *span });
201+
self.tcx.sess.emit_err(errors::DeprecatedAttribute { span: *span });
207202
}
208203
}
209204

@@ -219,7 +214,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
219214
if kind == AnnotationKind::Prohibited
220215
|| (kind == AnnotationKind::Container && stab.level.is_stable() && is_deprecated)
221216
{
222-
self.tcx.sess.emit_err(UselessStability { span, item_sp });
217+
self.tcx.sess.emit_err(errors::UselessStability { span, item_sp });
223218
}
224219

225220
debug!("annotate: found {:?}", stab);
@@ -235,25 +230,27 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
235230
{
236231
match stab_v.parse::<u64>() {
237232
Err(_) => {
238-
self.tcx.sess.emit_err(InvalidStability { span, item_sp });
233+
self.tcx.sess.emit_err(errors::InvalidStability { span, item_sp });
239234
break;
240235
}
241236
Ok(stab_vp) => match dep_v.parse::<u64>() {
242237
Ok(dep_vp) => match dep_vp.cmp(&stab_vp) {
243238
Ordering::Less => {
244-
self.tcx
245-
.sess
246-
.emit_err(CannotStabilizeDeprecated { span, item_sp });
239+
self.tcx.sess.emit_err(errors::CannotStabilizeDeprecated {
240+
span,
241+
item_sp,
242+
});
247243
break;
248244
}
249245
Ordering::Equal => continue,
250246
Ordering::Greater => break,
251247
},
252248
Err(_) => {
253249
if dep_v != "TBD" {
254-
self.tcx
255-
.sess
256-
.emit_err(InvalidDeprecationVersion { span, item_sp });
250+
self.tcx.sess.emit_err(errors::InvalidDeprecationVersion {
251+
span,
252+
item_sp,
253+
});
257254
}
258255
break;
259256
}
@@ -527,7 +524,7 @@ impl<'tcx> MissingStabilityAnnotations<'tcx> {
527524
&& self.effective_visibilities.is_reachable(def_id)
528525
{
529526
let descr = self.tcx.def_kind(def_id).descr(def_id.to_def_id());
530-
self.tcx.sess.emit_err(MissingStabilityAttr { span, descr });
527+
self.tcx.sess.emit_err(errors::MissingStabilityAttr { span, descr });
531528
}
532529
}
533530

@@ -555,7 +552,7 @@ impl<'tcx> MissingStabilityAnnotations<'tcx> {
555552

556553
if is_const && is_stable && missing_const_stability_attribute && is_reachable {
557554
let descr = self.tcx.def_kind(def_id).descr(def_id.to_def_id());
558-
self.tcx.sess.emit_err(MissingConstStabAttr { span, descr });
555+
self.tcx.sess.emit_err(errors::MissingConstStabAttr { span, descr });
559556
}
560557
}
561558
}
@@ -768,7 +765,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'tcx> {
768765
&& *constness == hir::Constness::Const
769766
&& const_stab.map_or(false, |(stab, _)| stab.is_const_stable())
770767
{
771-
self.tcx.sess.emit_err(TraitImplConstStable { span: item.span });
768+
self.tcx.sess.emit_err(errors::TraitImplConstStable { span: item.span });
772769
}
773770
}
774771

@@ -947,22 +944,22 @@ pub fn check_unused_or_stable_features(tcx: TyCtxt<'_>) {
947944
}
948945
if !lang_features.insert(feature) {
949946
// Warn if the user enables a lang feature multiple times.
950-
tcx.sess.emit_err(DuplicateFeatureErr { span, feature });
947+
tcx.sess.emit_err(errors::DuplicateFeatureErr { span, feature });
951948
}
952949
}
953950

954951
let declared_lib_features = &tcx.features().declared_lib_features;
955952
let mut remaining_lib_features = FxIndexMap::default();
956953
for (feature, span) in declared_lib_features {
957954
if !tcx.sess.opts.unstable_features.is_nightly_build() {
958-
tcx.sess.emit_err(FeatureOnlyOnNightly {
955+
tcx.sess.emit_err(errors::FeatureOnlyOnNightly {
959956
span: *span,
960957
release_channel: env!("CFG_RELEASE_CHANNEL"),
961958
});
962959
}
963960
if remaining_lib_features.contains_key(&feature) {
964961
// Warn if the user enables a lib feature multiple times.
965-
tcx.sess.emit_err(DuplicateFeatureErr { span: *span, feature: *feature });
962+
tcx.sess.emit_err(errors::DuplicateFeatureErr { span: *span, feature: *feature });
966963
}
967964
remaining_lib_features.insert(feature, *span);
968965
}
@@ -1063,7 +1060,7 @@ pub fn check_unused_or_stable_features(tcx: TyCtxt<'_>) {
10631060
}
10641061

10651062
for (feature, span) in remaining_lib_features {
1066-
tcx.sess.emit_err(UnknownFeature { span, feature: *feature });
1063+
tcx.sess.emit_err(errors::UnknownFeature { span, feature: *feature });
10671064
}
10681065

10691066
for (implied_by, feature) in remaining_implications {
@@ -1074,7 +1071,7 @@ pub fn check_unused_or_stable_features(tcx: TyCtxt<'_>) {
10741071
.map(|(_, span)| span)
10751072
.or_else(|| local_defined_features.unstable.get(&feature))
10761073
.expect("feature that implied another does not exist");
1077-
tcx.sess.emit_err(ImpliedFeatureNotExist { span, feature, implied_by });
1074+
tcx.sess.emit_err(errors::ImpliedFeatureNotExist { span, feature, implied_by });
10781075
}
10791076

10801077
// FIXME(#44232): the `used_features` table no longer exists, so we

0 commit comments

Comments
 (0)