E4121#
The attribute (!
, ?
, !!
mark) cannot be used on this application.
This error occurs when:
The attribute (
!
,?
,!!
mark) is used on a constructor.The attribute (
!
,?
,!!
mark) is used on a function that does fit.!
and?
must be annotated on a function that may raise errors.!!
must be annotated on an async function (this will be reported as E4150 though).
错误示例#
enum Err {
IntErr(Int)
}
fn square(x: Int) -> Int {
x * x
}
fn main {
IntErr!(1) |> ignore() // Error: The attribute `!` cannot be used on constructors.
IntErr?(2) |> ignore() // Error: The attribute `?` cannot be used on constructors.
IntErr!!(3) |> ignore() // Error: The attribute `!!` cannot be used on constructors.
square!(1) |> ignore() // Error: The attribute `!` cannot be used on application that does not raise errors
square?(2) |> ignore() // Error: The attribute `?` cannot be used on application that does not raise errors
}
建议#
Remove the attribute (!
, ?
, !!
mark) from the application.
fn main {
IntErr(1) |> ignore()
IntErr(2) |> ignore()
IntErr(3) |> ignore()
square(1) |> ignore()
square(2) |> ignore()
}