diff options
| author | Jubilee Young <workingjubilee@gmail.com> | 2024-10-17 12:59:04 -0700 |
|---|---|---|
| committer | Jubilee Young <workingjubilee@gmail.com> | 2024-10-19 11:09:09 -0700 |
| commit | 6a834b4df8a45fafea84761b6e25ccdf75cec007 (patch) | |
| tree | 79351aa1243cbefe11282889dd45c27bb62f524b | |
| parent | dd5127615ad626741a1116d022cf784637ac05df (diff) | |
| download | rust-6a834b4df8a45fafea84761b6e25ccdf75cec007.tar.gz rust-6a834b4df8a45fafea84761b6e25ccdf75cec007.zip | |
compiler: Adopt rust-analyzer impls for `LayoutCalculatorError`
| -rw-r--r-- | compiler/rustc_abi/src/layout.rs | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/compiler/rustc_abi/src/layout.rs b/compiler/rustc_abi/src/layout.rs index 6e1299944a0..5ce5f14ce57 100644 --- a/compiler/rustc_abi/src/layout.rs +++ b/compiler/rustc_abi/src/layout.rs @@ -39,7 +39,7 @@ enum NicheBias { End, } -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug, PartialEq, Eq)] pub enum LayoutCalculatorError<F> { /// An unsized type was found in a location where a sized type was expected. /// @@ -56,6 +56,31 @@ pub enum LayoutCalculatorError<F> { EmptyUnion, } +impl<F> LayoutCalculatorError<F> { + pub fn without_payload(&self) -> LayoutCalculatorError<()> { + match self { + LayoutCalculatorError::UnexpectedUnsized(_) => { + LayoutCalculatorError::UnexpectedUnsized(()) + } + LayoutCalculatorError::SizeOverflow => LayoutCalculatorError::SizeOverflow, + LayoutCalculatorError::EmptyUnion => LayoutCalculatorError::EmptyUnion, + } + } + + /// Format an untranslated diagnostic for this type + /// + /// Intended for use by rust-analyzer, as neither it nor `rustc_abi` depend on fluent infra. + pub fn fallback_fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.write_str(match self { + LayoutCalculatorError::UnexpectedUnsized(_) => { + "an unsized type was found where a sized type was expected" + } + LayoutCalculatorError::SizeOverflow => "size overflow", + LayoutCalculatorError::EmptyUnion => "type is a union with no fields", + }) + } +} + type LayoutCalculatorResult<FieldIdx, VariantIdx, F> = Result<LayoutS<FieldIdx, VariantIdx>, LayoutCalculatorError<F>>; |
