@@ -39,7 +39,7 @@ enum NicheBias {
3939 End ,
4040}
4141
42- #[ derive( Copy , Clone , Debug ) ]
42+ #[ derive( Copy , Clone , Debug , PartialEq , Eq ) ]
4343pub enum LayoutCalculatorError < F > {
4444 /// An unsized type was found in a location where a sized type was expected.
4545 ///
@@ -56,6 +56,31 @@ pub enum LayoutCalculatorError<F> {
5656 EmptyUnion ,
5757}
5858
59+ impl < F > LayoutCalculatorError < F > {
60+ pub fn without_payload ( & self ) -> LayoutCalculatorError < ( ) > {
61+ match self {
62+ LayoutCalculatorError :: UnexpectedUnsized ( _) => {
63+ LayoutCalculatorError :: UnexpectedUnsized ( ( ) )
64+ }
65+ LayoutCalculatorError :: SizeOverflow => LayoutCalculatorError :: SizeOverflow ,
66+ LayoutCalculatorError :: EmptyUnion => LayoutCalculatorError :: EmptyUnion ,
67+ }
68+ }
69+
70+ /// Format an untranslated diagnostic for this type
71+ ///
72+ /// Intended for use by rust-analyzer, as neither it nor `rustc_abi` depend on fluent infra.
73+ pub fn fallback_fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
74+ f. write_str ( match self {
75+ LayoutCalculatorError :: UnexpectedUnsized ( _) => {
76+ "an unsized type was found where a sized type was expected"
77+ }
78+ LayoutCalculatorError :: SizeOverflow => "size overflow" ,
79+ LayoutCalculatorError :: EmptyUnion => "type is a union with no fields" ,
80+ } )
81+ }
82+ }
83+
5984type LayoutCalculatorResult < FieldIdx , VariantIdx , F > =
6085 Result < LayoutS < FieldIdx , VariantIdx > , LayoutCalculatorError < F > > ;
6186
0 commit comments