Remove UserError from LayoutError

This commit is contained in:
Lukas Wirth 2023-11-14 13:32:04 +01:00
parent e844784d8d
commit b74015512d
4 changed files with 42 additions and 32 deletions

View file

@ -145,7 +145,7 @@ pub fn layout_of_adt_recover(
_: &Substitution,
_: &Arc<TraitEnvironment>,
) -> Result<Arc<Layout>, LayoutError> {
user_error!("infinite sized recursive type");
Err(LayoutError::RecursiveTypeWithoutIndirection)
}
/// Finds the appropriate Integer type and signedness for the given
@ -169,11 +169,7 @@ fn repr_discr(
let discr = Integer::from_attr(dl, ity);
let fit = if ity.is_signed() { signed_fit } else { unsigned_fit };
if discr < fit {
return Err(LayoutError::UserError(
"Integer::repr_discr: `#[repr]` hint too small for \
discriminant range of enum "
.into(),
));
return Err(LayoutError::UserReprTooSmall);
}
return Ok((discr, ity.is_signed()));
}

View file

@ -210,16 +210,13 @@ fn recursive() {
struct BoxLike<T: ?Sized>(*mut T);
struct Goal(BoxLike<Goal>);
}
check_fail(
r#"struct Goal(Goal);"#,
LayoutError::UserError("infinite sized recursive type".into()),
);
check_fail(r#"struct Goal(Goal);"#, LayoutError::RecursiveTypeWithoutIndirection);
check_fail(
r#"
struct Foo<T>(Foo<T>);
struct Goal(Foo<i32>);
"#,
LayoutError::UserError("infinite sized recursive type".into()),
LayoutError::RecursiveTypeWithoutIndirection,
);
}