Skip to content

Commit 190a22d

Browse files
Rename rustc_hir_typeck/src/errors.rs into rustc_hir_typeck/src/diagnostics.rs
1 parent f6e99c1 commit 190a22d

18 files changed

Lines changed: 115 additions & 95 deletions

File tree

compiler/rustc_hir_typeck/src/_match.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
254254
}
255255

256256
let semi = expr.span.shrink_to_hi().with_hi(semi_span.hi());
257-
let sugg = crate::errors::RemoveSemiForCoerce { expr: expr.span, ret, semi };
257+
let sugg = crate::diagnostics::RemoveSemiForCoerce { expr: expr.span, ret, semi };
258258
diag.subdiagnostic(sugg);
259259
}
260260

compiler/rustc_hir_typeck/src/callee.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use tracing::{debug, instrument};
2525
use super::method::MethodCallee;
2626
use super::method::probe::ProbeScope;
2727
use super::{Expectation, FnCtxt, TupleArgumentsFlag};
28-
use crate::errors;
28+
use crate::diagnostics;
2929
use crate::method::TreatNotYetDefinedOpaques;
3030
use crate::method::confirm::ConfirmContext;
3131
use crate::method::probe::{IsSuggestion, Mode};
@@ -46,14 +46,14 @@ pub(crate) fn check_legal_trait_for_method_call(
4646
&& !tcx.is_lang_item(tcx.parent(body_id), LangItem::Drop)
4747
{
4848
let sugg = if let Some(receiver) = receiver.filter(|s| !s.is_empty()) {
49-
errors::ExplicitDestructorCallSugg::Snippet {
49+
diagnostics::ExplicitDestructorCallSugg::Snippet {
5050
lo: expr_span.shrink_to_lo().to(receiver.shrink_to_lo()),
5151
hi: receiver.shrink_to_hi().to(expr_span.shrink_to_hi()),
5252
}
5353
} else {
54-
errors::ExplicitDestructorCallSugg::Empty(span)
54+
diagnostics::ExplicitDestructorCallSugg::Empty(span)
5555
};
56-
return Err(tcx.dcx().emit_err(errors::ExplicitDestructorCall { span, sugg }));
56+
return Err(tcx.dcx().emit_err(diagnostics::ExplicitDestructorCall { span, sugg }));
5757
}
5858
tcx.ensure_result().coherent_trait(trait_id)
5959
}
@@ -105,7 +105,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
105105
}
106106

107107
if self.is_scalable_vector_ctor(autoderef.final_ty()) {
108-
let mut err = self.dcx().create_err(errors::ScalableVectorCtor {
108+
let mut err = self.dcx().create_err(diagnostics::ScalableVectorCtor {
109109
span: callee_expr.span,
110110
ty: autoderef.final_ty(),
111111
});
@@ -190,13 +190,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
190190
// The interrupt ABIs should only be called by the CPU. They have complex
191191
// pre- and postconditions, and can use non-standard instructions like `iret` on x86.
192192
| CanonAbi::Interrupt(_) => {
193-
let err = crate::errors::AbiCannotBeCalled { span, abi };
193+
let err = crate::diagnostics::AbiCannotBeCalled { span, abi };
194194
self.tcx.dcx().emit_err(err);
195195
}
196196

197197
// This is an entry point for the host, and cannot be called directly.
198198
CanonAbi::GpuKernel => {
199-
let err = crate::errors::GpuKernelAbiCannotBeCalled { span };
199+
let err = crate::diagnostics::GpuKernelAbiCannotBeCalled { span };
200200
self.tcx.dcx().emit_err(err);
201201
}
202202

@@ -608,7 +608,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
608608
);
609609
self.require_type_is_sized(ty, sp, ObligationCauseCode::RustCall);
610610
} else {
611-
self.dcx().emit_err(errors::RustCallIncorrectArgs { span: sp });
611+
self.dcx().emit_err(diagnostics::RustCallIncorrectArgs { span: sp });
612612
}
613613
}
614614

@@ -845,7 +845,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
845845

846846
let callee_ty = self.resolve_vars_if_possible(callee_ty);
847847
let mut path = None;
848-
let mut err = self.dcx().create_err(errors::InvalidCallee {
848+
let mut err = self.dcx().create_err(diagnostics::InvalidCallee {
849849
span: callee_expr.span,
850850
found: match &unit_variant {
851851
Some((_, kind, path)) => format!("{kind} `{path}`"),

compiler/rustc_hir_typeck/src/cast.rs

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ use rustc_trait_selection::infer::InferCtxtExt;
4949
use tracing::{debug, instrument};
5050

5151
use super::FnCtxt;
52-
use crate::{errors, type_error_struct};
52+
use crate::{diagnostics, type_error_struct};
5353

5454
/// Reifies a cast check to be checked once we have full type information for
5555
/// a function context.
@@ -389,13 +389,17 @@ impl<'a, 'tcx> CastCheck<'tcx> {
389389
CastError::CastToBool => {
390390
let expr_ty = fcx.resolve_vars_if_possible(self.expr_ty);
391391
let help = if self.expr_ty.is_numeric() {
392-
errors::CannotCastToBoolHelp::Numeric(
392+
diagnostics::CannotCastToBoolHelp::Numeric(
393393
self.expr_span.shrink_to_hi().with_hi(self.span.hi()),
394394
)
395395
} else {
396-
errors::CannotCastToBoolHelp::Unsupported(self.span)
396+
diagnostics::CannotCastToBoolHelp::Unsupported(self.span)
397397
};
398-
fcx.dcx().emit_err(errors::CannotCastToBool { span: self.span, expr_ty, help });
398+
fcx.dcx().emit_err(diagnostics::CannotCastToBool {
399+
span: self.span,
400+
expr_ty,
401+
help,
402+
});
399403
}
400404
CastError::CastToChar => {
401405
let mut err = type_error_struct!(
@@ -588,7 +592,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
588592
CastError::SizedUnsizedCast => {
589593
let cast_ty = fcx.resolve_vars_if_possible(self.cast_ty);
590594
let expr_ty = fcx.resolve_vars_if_possible(self.expr_ty);
591-
fcx.dcx().emit_err(errors::CastThinPointerToWidePointer {
595+
fcx.dcx().emit_err(diagnostics::CastThinPointerToWidePointer {
592596
span: self.span,
593597
expr_ty,
594598
cast_ty,
@@ -606,14 +610,14 @@ impl<'a, 'tcx> CastCheck<'tcx> {
606610
.then(|| match cast_ty.kind() {
607611
ty::RawPtr(pointee, _) => match pointee.kind() {
608612
ty::Param(param) => {
609-
Some(errors::IntToWideParamNote { param: param.name })
613+
Some(diagnostics::IntToWideParamNote { param: param.name })
610614
}
611615
_ => None,
612616
},
613617
_ => None,
614618
})
615619
.flatten();
616-
fcx.dcx().emit_err(errors::IntToWide {
620+
fcx.dcx().emit_err(diagnostics::IntToWide {
617621
span,
618622
metadata,
619623
expr_ty,
@@ -630,17 +634,21 @@ impl<'a, 'tcx> CastCheck<'tcx> {
630634
e => unreachable!("control flow means we should never encounter a {e:?}"),
631635
};
632636
let (span, sub) = if unknown_cast_to {
633-
(self.cast_span, errors::CastUnknownPointerSub::To(self.cast_span))
637+
(self.cast_span, diagnostics::CastUnknownPointerSub::To(self.cast_span))
634638
} else {
635-
(self.cast_span, errors::CastUnknownPointerSub::From(self.span))
639+
(self.cast_span, diagnostics::CastUnknownPointerSub::From(self.span))
636640
};
637-
fcx.dcx().emit_err(errors::CastUnknownPointer { span, to: unknown_cast_to, sub });
641+
fcx.dcx().emit_err(diagnostics::CastUnknownPointer {
642+
span,
643+
to: unknown_cast_to,
644+
sub,
645+
});
638646
}
639647
CastError::CastEnumDrop => {
640648
let expr_ty = fcx.resolve_vars_if_possible(self.expr_ty);
641649
let cast_ty = fcx.resolve_vars_if_possible(self.cast_ty);
642650

643-
fcx.dcx().emit_err(errors::CastEnumDrop { span: self.span, expr_ty, cast_ty });
651+
fcx.dcx().emit_err(diagnostics::CastEnumDrop { span: self.span, expr_ty, cast_ty });
644652
}
645653
CastError::ForeignNonExhaustiveAdt => {
646654
make_invalid_casting_error(
@@ -653,7 +661,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
653661
.emit();
654662
}
655663
CastError::PtrPtrAddingAutoTrait(added) => {
656-
fcx.dcx().emit_err(errors::PtrCastAddAutoToObject {
664+
fcx.dcx().emit_err(diagnostics::PtrCastAddAutoToObject {
657665
span: self.span,
658666
traits_len: added.len(),
659667
traits: {
@@ -727,7 +735,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
727735
lint,
728736
self.expr.hir_id,
729737
self.span,
730-
errors::TrivialCast { numeric, expr_ty, cast_ty },
738+
diagnostics::TrivialCast { numeric, expr_ty, cast_ty },
731739
);
732740
}
733741

@@ -1144,12 +1152,15 @@ impl<'a, 'tcx> CastCheck<'tcx> {
11441152
if let Some((deref_ty, _)) = derefed {
11451153
// Give a note about what the expr derefs to.
11461154
if deref_ty != self.expr_ty.peel_refs() {
1147-
err.subdiagnostic(errors::DerefImplsIsEmpty { span: self.expr_span, deref_ty });
1155+
err.subdiagnostic(diagnostics::DerefImplsIsEmpty {
1156+
span: self.expr_span,
1157+
deref_ty,
1158+
});
11481159
}
11491160

11501161
// Create a multipart suggestion: add `!` and `.is_empty()` in
11511162
// place of the cast.
1152-
err.subdiagnostic(errors::UseIsEmpty {
1163+
err.subdiagnostic(diagnostics::UseIsEmpty {
11531164
lo: self.expr_span.shrink_to_lo(),
11541165
hi: self.span.with_lo(self.expr_span.hi()),
11551166
expr_ty: self.expr_ty,

compiler/rustc_hir_typeck/src/coercion.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ use smallvec::{SmallVec, smallvec};
6767
use tracing::{debug, instrument};
6868

6969
use crate::FnCtxt;
70-
use crate::errors::SuggestBoxingForReturnImplTrait;
70+
use crate::diagnostics::SuggestBoxingForReturnImplTrait;
7171

7272
struct Coerce<'a, 'tcx> {
7373
fcx: &'a FnCtxt<'a, 'tcx>,
File renamed without changes.

compiler/rustc_hir_typeck/src/expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ use tracing::{debug, instrument, trace};
4040

4141
use crate::Expectation::{self, ExpectCastableToType, ExpectHasType, NoExpectation};
4242
use crate::coercion::CoerceMany;
43-
use crate::errors::{
43+
use crate::diagnostics::{
4444
AddressOfTemporaryTaken, BaseExpressionDoubleDot, BaseExpressionDoubleDotAddExpr,
4545
BaseExpressionDoubleDotRemove, CantDereference, FieldMultiplySpecifiedInInitializer,
4646
FunctionalRecordUpdateOnNonStruct, HelpUseLatestEdition, NakedAsmOutsideNakedFn,

compiler/rustc_hir_typeck/src/fallback.rs

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use rustc_span::{DUMMY_SP, Span};
1818
use rustc_trait_selection::traits::{ObligationCause, ObligationCtxt};
1919
use tracing::debug;
2020

21-
use crate::{FnCtxt, errors};
21+
use crate::{FnCtxt, diagnostics};
2222

2323
impl<'tcx> FnCtxt<'_, 'tcx> {
2424
/// Performs type inference fallback, setting [`FnCtxt::diverging_fallback_has_occurred`]
@@ -182,7 +182,7 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
182182
FLOAT_LITERAL_F32_FALLBACK,
183183
origin.lint_id.unwrap_or(CRATE_HIR_ID),
184184
origin.span,
185-
errors::FloatLiteralF32Fallback {
185+
diagnostics::FloatLiteralF32Fallback {
186186
span: literal.as_ref().map(|_| origin.span),
187187
literal: literal.unwrap_or_default(),
188188
},
@@ -312,21 +312,25 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
312312
span,
313313
match reason {
314314
UnsafeUseReason::Call => {
315-
errors::NeverTypeFallbackFlowingIntoUnsafe::Call { sugg: sugg.clone() }
315+
diagnostics::NeverTypeFallbackFlowingIntoUnsafe::Call { sugg: sugg.clone() }
316316
}
317317
UnsafeUseReason::Method => {
318-
errors::NeverTypeFallbackFlowingIntoUnsafe::Method { sugg: sugg.clone() }
318+
diagnostics::NeverTypeFallbackFlowingIntoUnsafe::Method {
319+
sugg: sugg.clone(),
320+
}
319321
}
320322
UnsafeUseReason::Path => {
321-
errors::NeverTypeFallbackFlowingIntoUnsafe::Path { sugg: sugg.clone() }
323+
diagnostics::NeverTypeFallbackFlowingIntoUnsafe::Path { sugg: sugg.clone() }
322324
}
323325
UnsafeUseReason::UnionField => {
324-
errors::NeverTypeFallbackFlowingIntoUnsafe::UnionField {
326+
diagnostics::NeverTypeFallbackFlowingIntoUnsafe::UnionField {
325327
sugg: sugg.clone(),
326328
}
327329
}
328330
UnsafeUseReason::Deref => {
329-
errors::NeverTypeFallbackFlowingIntoUnsafe::Deref { sugg: sugg.clone() }
331+
diagnostics::NeverTypeFallbackFlowingIntoUnsafe::Deref {
332+
sugg: sugg.clone(),
333+
}
330334
}
331335
},
332336
);
@@ -376,7 +380,7 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
376380
lint::builtin::DEPENDENCY_ON_UNIT_NEVER_TYPE_FALLBACK,
377381
self.tcx.local_def_id_to_hir_id(self.body_id),
378382
self.tcx.def_span(self.body_id),
379-
errors::DependencyOnUnitNeverTypeFallback {
383+
diagnostics::DependencyOnUnitNeverTypeFallback {
380384
obligation_span: never_error.obligation.cause.span,
381385
obligation: never_error.obligation.predicate,
382386
sugg,
@@ -441,7 +445,7 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
441445
&self,
442446
diverging_vids: &[ty::TyVid],
443447
coercions: &VecGraph<ty::TyVid, true>,
444-
) -> errors::SuggestAnnotations {
448+
) -> diagnostics::SuggestAnnotations {
445449
let body =
446450
self.tcx.hir_maybe_body_owned_by(self.body_id).expect("body id must have an owner");
447451
// For each diverging var, look through the HIR for a place to give it
@@ -458,7 +462,7 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
458462
.break_value()
459463
})
460464
.collect();
461-
errors::SuggestAnnotations { suggestions }
465+
diagnostics::SuggestAnnotations { suggestions }
462466
}
463467
}
464468

@@ -479,7 +483,7 @@ impl<'tcx> AnnotateUnitFallbackVisitor<'_, 'tcx> {
479483
arg_segment: &'tcx hir::PathSegment<'tcx>,
480484
def_id: DefId,
481485
id: HirId,
482-
) -> ControlFlow<errors::SuggestAnnotation> {
486+
) -> ControlFlow<diagnostics::SuggestAnnotation> {
483487
if arg_segment.args.is_none()
484488
&& let Some(all_args) = self.fcx.typeck_results.borrow().node_args_opt(id)
485489
&& let generics = self.fcx.tcx.generics_of(def_id)
@@ -497,7 +501,7 @@ impl<'tcx> AnnotateUnitFallbackVisitor<'_, 'tcx> {
497501
&& let Some(vid) = self.fcx.root_vid(ty)
498502
&& self.reachable_vids.contains(&vid)
499503
{
500-
return ControlFlow::Break(errors::SuggestAnnotation::Turbo(
504+
return ControlFlow::Break(diagnostics::SuggestAnnotation::Turbo(
501505
arg_segment.ident.span.shrink_to_hi(),
502506
n_tys,
503507
idx,
@@ -509,7 +513,7 @@ impl<'tcx> AnnotateUnitFallbackVisitor<'_, 'tcx> {
509513
}
510514
}
511515
impl<'tcx> Visitor<'tcx> for AnnotateUnitFallbackVisitor<'_, 'tcx> {
512-
type Result = ControlFlow<errors::SuggestAnnotation>;
516+
type Result = ControlFlow<diagnostics::SuggestAnnotation>;
513517

514518
fn visit_infer(
515519
&mut self,
@@ -523,7 +527,7 @@ impl<'tcx> Visitor<'tcx> for AnnotateUnitFallbackVisitor<'_, 'tcx> {
523527
&& self.reachable_vids.contains(&vid)
524528
&& inf_span.can_be_used_for_suggestions()
525529
{
526-
return ControlFlow::Break(errors::SuggestAnnotation::Unit(inf_span));
530+
return ControlFlow::Break(diagnostics::SuggestAnnotation::Unit(inf_span));
527531
}
528532

529533
ControlFlow::Continue(())
@@ -570,7 +574,7 @@ impl<'tcx> Visitor<'tcx> for AnnotateUnitFallbackVisitor<'_, 'tcx> {
570574
&& expr.span.can_be_used_for_suggestions()
571575
{
572576
let span = path.span.shrink_to_lo().to(trait_segment.ident.span);
573-
return ControlFlow::Break(errors::SuggestAnnotation::Path(span));
577+
return ControlFlow::Break(diagnostics::SuggestAnnotation::Path(span));
574578
}
575579

576580
// Or else, try suggesting turbofishing the method args.
@@ -594,7 +598,7 @@ impl<'tcx> Visitor<'tcx> for AnnotateUnitFallbackVisitor<'_, 'tcx> {
594598
&& self.reachable_vids.contains(&vid)
595599
&& local.span.can_be_used_for_suggestions()
596600
{
597-
return ControlFlow::Break(errors::SuggestAnnotation::Local(
601+
return ControlFlow::Break(diagnostics::SuggestAnnotation::Local(
598602
local.pat.span.shrink_to_hi(),
599603
));
600604
}

compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ use rustc_trait_selection::traits::{
4242
use tracing::{debug, instrument};
4343

4444
use crate::callee::{self, DeferredCallResolution};
45-
use crate::errors::{self, CtorIsPrivate};
45+
use crate::diagnostics::{self, CtorIsPrivate};
4646
use crate::method::{self, MethodCallee};
4747
use crate::{BreakableCtxt, Diverges, Expectation, FnCtxt, LoweredTy};
4848

@@ -1158,21 +1158,21 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
11581158
})
11591159
.all(|def_id| def_id != impl_def_id)
11601160
{
1161-
let sugg = ty.normalized.ty_adt_def().map(|def| errors::ReplaceWithName {
1161+
let sugg = ty.normalized.ty_adt_def().map(|def| diagnostics::ReplaceWithName {
11621162
span: path_span,
11631163
name: self.tcx.item_name(def.did()).to_ident_string(),
11641164
});
11651165
let item = match self
11661166
.tcx
11671167
.hir_node_by_def_id(self.tcx.hir_get_parent_item(hir_id).def_id)
11681168
{
1169-
hir::Node::Item(item) => Some(errors::InnerItem {
1169+
hir::Node::Item(item) => Some(diagnostics::InnerItem {
11701170
span: item.kind.ident().map(|i| i.span).unwrap_or(item.span),
11711171
}),
11721172
_ => None,
11731173
};
11741174
if ty.raw.has_param() {
1175-
let guar = self.dcx().emit_err(errors::SelfCtorFromOuterItem {
1175+
let guar = self.dcx().emit_err(diagnostics::SelfCtorFromOuterItem {
11761176
span: path_span,
11771177
impl_span: tcx.def_span(impl_def_id),
11781178
sugg,
@@ -1184,7 +1184,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
11841184
SELF_CONSTRUCTOR_FROM_OUTER_ITEM,
11851185
hir_id,
11861186
path_span,
1187-
errors::SelfCtorFromOuterItemLint {
1187+
diagnostics::SelfCtorFromOuterItemLint {
11881188
impl_span: tcx.def_span(impl_def_id),
11891189
sugg,
11901190
item,

0 commit comments

Comments
 (0)