Skip to content

Commit fd18d9a

Browse files
committed
Renamed TypeErrorAdditionalDiags (was Error0308Subdiags) and ObligationCauseFailureCode (was FailureCodeDiagnostics)
1 parent aa33a6f commit fd18d9a

File tree

3 files changed

+52
-48
lines changed

3 files changed

+52
-48
lines changed

compiler/rustc_infer/src/errors/mod.rs

+14-14
Original file line numberDiff line numberDiff line change
@@ -1361,7 +1361,7 @@ impl AddToDiagnostic for SuggestTuplePatternMany {
13611361
}
13621362

13631363
#[derive(Subdiagnostic)]
1364-
pub enum Error0308Subdiags {
1364+
pub enum TypeErrorAdditionalDiags {
13651365
#[suggestion(
13661366
infer_meant_byte_literal,
13671367
code = "b'{code}'",
@@ -1429,48 +1429,48 @@ pub enum Error0308Subdiags {
14291429
}
14301430

14311431
#[derive(Diagnostic)]
1432-
pub enum FailureCodeDiagnostics {
1432+
pub enum ObligationCauseFailureCode {
14331433
#[diag(infer_oc_method_compat, code = "E0308")]
14341434
MethodCompat {
14351435
#[primary_span]
14361436
span: Span,
14371437
#[subdiagnostic]
1438-
subdiags: Vec<Error0308Subdiags>,
1438+
subdiags: Vec<TypeErrorAdditionalDiags>,
14391439
},
14401440
#[diag(infer_oc_type_compat, code = "E0308")]
14411441
TypeCompat {
14421442
#[primary_span]
14431443
span: Span,
14441444
#[subdiagnostic]
1445-
subdiags: Vec<Error0308Subdiags>,
1445+
subdiags: Vec<TypeErrorAdditionalDiags>,
14461446
},
14471447
#[diag(infer_oc_const_compat, code = "E0308")]
14481448
ConstCompat {
14491449
#[primary_span]
14501450
span: Span,
14511451
#[subdiagnostic]
1452-
subdiags: Vec<Error0308Subdiags>,
1452+
subdiags: Vec<TypeErrorAdditionalDiags>,
14531453
},
14541454
#[diag(infer_oc_try_compat, code = "E0308")]
14551455
TryCompat {
14561456
#[primary_span]
14571457
span: Span,
14581458
#[subdiagnostic]
1459-
subdiags: Vec<Error0308Subdiags>,
1459+
subdiags: Vec<TypeErrorAdditionalDiags>,
14601460
},
14611461
#[diag(infer_oc_match_compat, code = "E0308")]
14621462
MatchCompat {
14631463
#[primary_span]
14641464
span: Span,
14651465
#[subdiagnostic]
1466-
subdiags: Vec<Error0308Subdiags>,
1466+
subdiags: Vec<TypeErrorAdditionalDiags>,
14671467
},
14681468
#[diag(infer_oc_if_else_different, code = "E0308")]
14691469
IfElseDifferent {
14701470
#[primary_span]
14711471
span: Span,
14721472
#[subdiagnostic]
1473-
subdiags: Vec<Error0308Subdiags>,
1473+
subdiags: Vec<TypeErrorAdditionalDiags>,
14741474
},
14751475
#[diag(infer_oc_no_else, code = "E0317")]
14761476
NoElse {
@@ -1482,7 +1482,7 @@ pub enum FailureCodeDiagnostics {
14821482
#[primary_span]
14831483
span: Span,
14841484
#[subdiagnostic]
1485-
subdiags: Vec<Error0308Subdiags>,
1485+
subdiags: Vec<TypeErrorAdditionalDiags>,
14861486
},
14871487
#[diag(infer_oc_fn_main_correct_type, code = "E0580")]
14881488
FnMainCorrectType {
@@ -1494,21 +1494,21 @@ pub enum FailureCodeDiagnostics {
14941494
#[primary_span]
14951495
span: Span,
14961496
#[subdiagnostic]
1497-
subdiags: Vec<Error0308Subdiags>,
1497+
subdiags: Vec<TypeErrorAdditionalDiags>,
14981498
},
14991499
#[diag(infer_oc_intristic_correct_type, code = "E0308")]
15001500
IntristicCorrectType {
15011501
#[primary_span]
15021502
span: Span,
15031503
#[subdiagnostic]
1504-
subdiags: Vec<Error0308Subdiags>,
1504+
subdiags: Vec<TypeErrorAdditionalDiags>,
15051505
},
15061506
#[diag(infer_oc_method_correct_type, code = "E0308")]
15071507
MethodCorrectType {
15081508
#[primary_span]
15091509
span: Span,
15101510
#[subdiagnostic]
1511-
subdiags: Vec<Error0308Subdiags>,
1511+
subdiags: Vec<TypeErrorAdditionalDiags>,
15121512
},
15131513
#[diag(infer_oc_closure_selfref, code = "E0644")]
15141514
ClosureSelfref {
@@ -1520,13 +1520,13 @@ pub enum FailureCodeDiagnostics {
15201520
#[primary_span]
15211521
span: Span,
15221522
#[subdiagnostic]
1523-
subdiags: Vec<Error0308Subdiags>,
1523+
subdiags: Vec<TypeErrorAdditionalDiags>,
15241524
},
15251525
#[diag(infer_oc_generic, code = "E0308")]
15261526
Generic {
15271527
#[primary_span]
15281528
span: Span,
15291529
#[subdiagnostic]
1530-
subdiags: Vec<Error0308Subdiags>,
1530+
subdiags: Vec<TypeErrorAdditionalDiags>,
15311531
},
15321532
}

compiler/rustc_infer/src/infer/error_reporting/mod.rs

+33-29
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ use super::lexical_region_resolve::RegionResolutionError;
4949
use super::region_constraints::GenericKind;
5050
use super::{InferCtxt, RegionVariableOrigin, SubregionOrigin, TypeTrace, ValuePairs};
5151

52-
use crate::errors::{self, Error0308Subdiags, FailureCodeDiagnostics};
52+
use crate::errors::{self, ObligationCauseFailureCode, TypeErrorAdditionalDiags};
5353
use crate::infer;
5454
use crate::infer::error_reporting::nice_region_error::find_anon_type::find_anon_type;
5555
use crate::infer::ExpectedFound;
@@ -1924,7 +1924,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
19241924
&self,
19251925
trace: &TypeTrace<'tcx>,
19261926
terr: TypeError<'tcx>,
1927-
) -> Vec<Error0308Subdiags> {
1927+
) -> Vec<TypeErrorAdditionalDiags> {
19281928
use crate::traits::ObligationCauseCode::MatchExpressionArm;
19291929
let mut suggestions = Vec::new();
19301930
let span = trace.cause.span();
@@ -1946,7 +1946,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
19461946
&& !code.starts_with("\\u") // forbid all Unicode escapes
19471947
&& code.chars().next().map_or(false, |c| c.is_ascii()) // forbids literal Unicode characters beyond ASCII
19481948
{
1949-
suggestions.push(Error0308Subdiags::MeantByteLiteral { span, code: escape_literal(code) })
1949+
suggestions.push(TypeErrorAdditionalDiags::MeantByteLiteral { span, code: escape_literal(code) })
19501950
}
19511951
}
19521952
// If a character was expected and the found expression is a string literal
@@ -1957,7 +1957,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
19571957
&& let Some(code) = code.strip_prefix('"').and_then(|s| s.strip_suffix('"'))
19581958
&& code.chars().count() == 1
19591959
{
1960-
suggestions.push(Error0308Subdiags::MeantCharLiteral { span, code: escape_literal(code) })
1960+
suggestions.push(TypeErrorAdditionalDiags::MeantCharLiteral { span, code: escape_literal(code) })
19611961
}
19621962
}
19631963
// If a string was expected and the found expression is a character literal,
@@ -1967,7 +1967,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
19671967
if let Some(code) =
19681968
code.strip_prefix('\'').and_then(|s| s.strip_suffix('\''))
19691969
{
1970-
suggestions.push(Error0308Subdiags::MeantStrLiteral { span, code: escape_literal(code) })
1970+
suggestions.push(TypeErrorAdditionalDiags::MeantStrLiteral { span, code: escape_literal(code) })
19711971
}
19721972
}
19731973
}
@@ -2032,7 +2032,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
20322032
&& let hir::ArrayLen::Body(hir::AnonConst { hir_id, .. }) = length
20332033
&& let Some(span) = self.tcx.hir().opt_span(*hir_id)
20342034
{
2035-
suggestions.push(Error0308Subdiags::ConsiderSpecifyingLength { span, length: sz.found });
2035+
suggestions.push(TypeErrorAdditionalDiags::ConsiderSpecifyingLength { span, length: sz.found });
20362036
}
20372037
}
20382038
_ => {}
@@ -2043,7 +2043,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
20432043
&& let hir::MatchSource::TryDesugar = source
20442044
&& let Some((expected_ty, found_ty, _, _)) = self.values_str(trace.values)
20452045
{
2046-
suggestions.push(Error0308Subdiags::TryCannotConvert { found: found_ty.content(), expected: expected_ty.content() });
2046+
suggestions.push(TypeErrorAdditionalDiags::TryCannotConvert { found: found_ty.content(), expected: expected_ty.content() });
20472047
}
20482048
suggestions
20492049
}
@@ -2071,7 +2071,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
20712071
span: Span,
20722072
found: Ty<'tcx>,
20732073
expected_fields: &List<Ty<'tcx>>,
2074-
) -> Option<Error0308Subdiags> {
2074+
) -> Option<TypeErrorAdditionalDiags> {
20752075
let [expected_tup_elem] = expected_fields[..] else { return None};
20762076

20772077
if !self.same_type_modulo_infer(expected_tup_elem, found) {
@@ -2083,9 +2083,11 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
20832083

20842084
let sugg = if code.starts_with('(') && code.ends_with(')') {
20852085
let before_close = span.hi() - BytePos::from_u32(1);
2086-
Error0308Subdiags::TupleOnlyComma { span: span.with_hi(before_close).shrink_to_hi() }
2086+
TypeErrorAdditionalDiags::TupleOnlyComma {
2087+
span: span.with_hi(before_close).shrink_to_hi(),
2088+
}
20872089
} else {
2088-
Error0308Subdiags::TupleAlsoParentheses {
2090+
TypeErrorAdditionalDiags::TupleAlsoParentheses {
20892091
span_low: span.shrink_to_lo(),
20902092
span_high: span.shrink_to_hi(),
20912093
}
@@ -2806,8 +2808,8 @@ pub trait ObligationCauseExt<'tcx> {
28062808
&self,
28072809
terr: TypeError<'tcx>,
28082810
span: Span,
2809-
subdiags: Vec<Error0308Subdiags>,
2810-
) -> FailureCodeDiagnostics;
2811+
subdiags: Vec<TypeErrorAdditionalDiags>,
2812+
) -> ObligationCauseFailureCode;
28112813
fn as_requirement_str(&self) -> &'static str;
28122814
}
28132815

@@ -2840,42 +2842,44 @@ impl<'tcx> ObligationCauseExt<'tcx> for ObligationCause<'tcx> {
28402842
&self,
28412843
terr: TypeError<'tcx>,
28422844
span: Span,
2843-
subdiags: Vec<Error0308Subdiags>,
2844-
) -> FailureCodeDiagnostics {
2845+
subdiags: Vec<TypeErrorAdditionalDiags>,
2846+
) -> ObligationCauseFailureCode {
28452847
use crate::traits::ObligationCauseCode::*;
28462848
match self.code() {
28472849
CompareImplItemObligation { kind: ty::AssocKind::Fn, .. } => {
2848-
FailureCodeDiagnostics::MethodCompat { span, subdiags }
2850+
ObligationCauseFailureCode::MethodCompat { span, subdiags }
28492851
}
28502852
CompareImplItemObligation { kind: ty::AssocKind::Type, .. } => {
2851-
FailureCodeDiagnostics::TypeCompat { span, subdiags }
2853+
ObligationCauseFailureCode::TypeCompat { span, subdiags }
28522854
}
28532855
CompareImplItemObligation { kind: ty::AssocKind::Const, .. } => {
2854-
FailureCodeDiagnostics::ConstCompat { span, subdiags }
2856+
ObligationCauseFailureCode::ConstCompat { span, subdiags }
28552857
}
28562858
MatchExpressionArm(box MatchExpressionArmCause { source, .. }) => match source {
28572859
hir::MatchSource::TryDesugar => {
2858-
FailureCodeDiagnostics::TryCompat { span, subdiags }
2860+
ObligationCauseFailureCode::TryCompat { span, subdiags }
28592861
}
2860-
_ => FailureCodeDiagnostics::MatchCompat { span, subdiags },
2862+
_ => ObligationCauseFailureCode::MatchCompat { span, subdiags },
28612863
},
2862-
IfExpression { .. } => FailureCodeDiagnostics::IfElseDifferent { span, subdiags },
2863-
IfExpressionWithNoElse => FailureCodeDiagnostics::NoElse { span },
2864-
LetElse => FailureCodeDiagnostics::NoDiverge { span, subdiags },
2865-
MainFunctionType => FailureCodeDiagnostics::FnMainCorrectType { span },
2866-
StartFunctionType => FailureCodeDiagnostics::FnStartCorrectType { span, subdiags },
2867-
IntrinsicType => FailureCodeDiagnostics::IntristicCorrectType { span, subdiags },
2868-
MethodReceiver => FailureCodeDiagnostics::MethodCorrectType { span, subdiags },
2864+
IfExpression { .. } => ObligationCauseFailureCode::IfElseDifferent { span, subdiags },
2865+
IfExpressionWithNoElse => ObligationCauseFailureCode::NoElse { span },
2866+
LetElse => ObligationCauseFailureCode::NoDiverge { span, subdiags },
2867+
MainFunctionType => ObligationCauseFailureCode::FnMainCorrectType { span },
2868+
StartFunctionType => ObligationCauseFailureCode::FnStartCorrectType { span, subdiags },
2869+
IntrinsicType => ObligationCauseFailureCode::IntristicCorrectType { span, subdiags },
2870+
MethodReceiver => ObligationCauseFailureCode::MethodCorrectType { span, subdiags },
28692871

28702872
// In the case where we have no more specific thing to
28712873
// say, also take a look at the error code, maybe we can
28722874
// tailor to that.
28732875
_ => match terr {
28742876
TypeError::CyclicTy(ty) if ty.is_closure() || ty.is_generator() => {
2875-
FailureCodeDiagnostics::ClosureSelfref { span }
2877+
ObligationCauseFailureCode::ClosureSelfref { span }
2878+
}
2879+
TypeError::IntrinsicCast => {
2880+
ObligationCauseFailureCode::CantCoerce { span, subdiags }
28762881
}
2877-
TypeError::IntrinsicCast => FailureCodeDiagnostics::CantCoerce { span, subdiags },
2878-
_ => FailureCodeDiagnostics::Generic { span, subdiags },
2882+
_ => ObligationCauseFailureCode::Generic { span, subdiags },
28792883
},
28802884
}
28812885
}

compiler/rustc_infer/src/infer/error_reporting/suggest.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ use rustc_span::{sym, BytePos, Span};
1313
use rustc_target::abi::FieldIdx;
1414

1515
use crate::errors::{
16-
ConsiderAddingAwait, DiagArg, Error0308Subdiags, FnConsiderCasting, FnItemsAreDistinct,
17-
FnUniqTypes, FunctionPointerSuggestion, SuggestAccessingField, SuggestAsRefWhereAppropriate,
16+
ConsiderAddingAwait, DiagArg, FnConsiderCasting, FnItemsAreDistinct, FnUniqTypes,
17+
FunctionPointerSuggestion, SuggestAccessingField, SuggestAsRefWhereAppropriate,
1818
SuggestBoxingForReturnImplTrait, SuggestRemoveSemiOrReturnBinding, SuggestTuplePatternMany,
19-
SuggestTuplePatternOne,
19+
SuggestTuplePatternOne, TypeErrorAdditionalDiags,
2020
};
2121

2222
use super::TypeErrCtxt;
@@ -484,7 +484,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
484484
&self,
485485
cause: &ObligationCause<'_>,
486486
span: Span,
487-
) -> Option<Error0308Subdiags> {
487+
) -> Option<TypeErrorAdditionalDiags> {
488488
let hir = self.tcx.hir();
489489
if let Some(node) = self.tcx.hir().find_by_def_id(cause.body_id) &&
490490
let hir::Node::Item(hir::Item {
@@ -531,7 +531,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
531531
let mut visitor = IfVisitor { err_span: span, found_if: false, result: false };
532532
visitor.visit_body(&body);
533533
if visitor.result {
534-
return Some(Error0308Subdiags::AddLetForLetChains{span: span.shrink_to_lo()});
534+
return Some(TypeErrorAdditionalDiags::AddLetForLetChains{span: span.shrink_to_lo()});
535535
}
536536
}
537537
None

0 commit comments

Comments
 (0)