mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 14:55:26 +00:00
compiler: Adopt rust-analyzer impls for LayoutCalculatorError
This commit is contained in:
parent
dd5127615a
commit
6a834b4df8
@ -39,7 +39,7 @@ enum NicheBias {
|
|||||||
End,
|
End,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug)]
|
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
||||||
pub enum LayoutCalculatorError<F> {
|
pub enum LayoutCalculatorError<F> {
|
||||||
/// An unsized type was found in a location where a sized type was expected.
|
/// An unsized type was found in a location where a sized type was expected.
|
||||||
///
|
///
|
||||||
@ -56,6 +56,31 @@ pub enum LayoutCalculatorError<F> {
|
|||||||
EmptyUnion,
|
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> =
|
type LayoutCalculatorResult<FieldIdx, VariantIdx, F> =
|
||||||
Result<LayoutS<FieldIdx, VariantIdx>, LayoutCalculatorError<F>>;
|
Result<LayoutS<FieldIdx, VariantIdx>, LayoutCalculatorError<F>>;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user