2024-08-17 14:38:10 -05:00
|
|
|
//@ignore-bitwidth: 32
|
2023-09-06 09:58:44 -05:00
|
|
|
|
2022-08-24 16:11:19 -05:00
|
|
|
#![warn(clippy::result_large_err)]
|
2022-08-30 15:27:21 -05:00
|
|
|
#![allow(clippy::large_enum_variant)]
|
2022-08-24 16:11:19 -05:00
|
|
|
|
|
|
|
pub fn small_err() -> Result<(), u128> {
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn large_err() -> Result<(), [u8; 512]> {
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: the `Err`-variant returned from this function is very large
|
2022-08-24 16:11:19 -05:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct FullyDefinedLargeError {
|
|
|
|
_foo: u128,
|
|
|
|
_bar: [u8; 100],
|
|
|
|
_foobar: [u8; 120],
|
|
|
|
}
|
|
|
|
|
|
|
|
impl FullyDefinedLargeError {
|
|
|
|
pub fn ret() -> Result<(), Self> {
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: the `Err`-variant returned from this function is very large
|
2022-08-24 16:11:19 -05:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn struct_error() -> Result<(), FullyDefinedLargeError> {
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: the `Err`-variant returned from this function is very large
|
2022-08-24 16:11:19 -05:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
type Fdlr<T> = std::result::Result<T, FullyDefinedLargeError>;
|
|
|
|
pub fn large_err_via_type_alias<T>(x: T) -> Fdlr<T> {
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: the `Err`-variant returned from this function is very large
|
2022-08-24 16:11:19 -05:00
|
|
|
Ok(x)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn param_small_error<R>() -> Result<(), (R, u128)> {
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn param_large_error<R>() -> Result<(), (u128, R, FullyDefinedLargeError)> {
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: the `Err`-variant returned from this function is very large
|
2022-08-24 16:11:19 -05:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
pub enum LargeErrorVariants<T> {
|
|
|
|
_Small(u8),
|
|
|
|
_Omg([u8; 512]),
|
|
|
|
_Param(T),
|
|
|
|
}
|
|
|
|
|
|
|
|
impl LargeErrorVariants<()> {
|
|
|
|
pub fn large_enum_error() -> Result<(), Self> {
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: the `Err`-variant returned from this function is very large
|
2022-08-24 16:11:19 -05:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-16 13:37:26 -05:00
|
|
|
enum MultipleLargeVariants {
|
|
|
|
_Biggest([u8; 1024]),
|
|
|
|
_AlsoBig([u8; 512]),
|
|
|
|
_Ok(usize),
|
|
|
|
}
|
|
|
|
|
|
|
|
impl MultipleLargeVariants {
|
|
|
|
fn large_enum_error() -> Result<(), Self> {
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: the `Err`-variant returned from this function is very large
|
2022-10-16 13:37:26 -05:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-24 16:11:19 -05:00
|
|
|
trait TraitForcesLargeError {
|
|
|
|
fn large_error() -> Result<(), [u8; 512]> {
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: the `Err`-variant returned from this function is very large
|
2022-08-24 16:11:19 -05:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct TraitImpl;
|
|
|
|
|
|
|
|
impl TraitForcesLargeError for TraitImpl {
|
|
|
|
// Should not lint
|
|
|
|
fn large_error() -> Result<(), [u8; 512]> {
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub union FullyDefinedUnionError {
|
|
|
|
_maybe: u8,
|
|
|
|
_or_even: [[u8; 16]; 32],
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn large_union_err() -> Result<(), FullyDefinedUnionError> {
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: the `Err`-variant returned from this function is very large
|
2022-08-24 16:11:19 -05:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
pub union UnionError<T: Copy> {
|
|
|
|
_maybe: T,
|
|
|
|
_or_perhaps_even: (T, [u8; 512]),
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn param_large_union<T: Copy>() -> Result<(), UnionError<T>> {
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: the `Err`-variant returned from this function is very large
|
2022-08-24 16:11:19 -05:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct ArrayError<T, U> {
|
|
|
|
_large_array: [T; 32],
|
|
|
|
_other_stuff: U,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn array_error_subst<U>() -> Result<(), ArrayError<i32, U>> {
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: the `Err`-variant returned from this function is very large
|
2022-08-24 16:11:19 -05:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn array_error<T, U>() -> Result<(), ArrayError<(i32, T), U>> {
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: the `Err`-variant returned from this function is very large
|
2022-08-24 16:11:19 -05:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2022-11-30 20:44:18 -06:00
|
|
|
// Issue #10005
|
|
|
|
enum Empty {}
|
|
|
|
fn _empty_error() -> Result<(), Empty> {
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2022-08-24 16:11:19 -05:00
|
|
|
fn main() {}
|