E4121#
这个应用中不允许使用 !
、?
或 !!
标记。
这个错误发生在以下情况:
!
、?
或!!
标记用于构造函数。!
、?
或!!
标记用于不适合的函数。!
和?
必须用于可能引发错误的函数。在异步函数上使用
!!
标记(这将被报告为 E4150)。
错误示例#
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
}
建议#
从应用中移除 !
、?
或 !!
标记。
fn main {
IntErr(1) |> ignore()
IntErr(2) |> ignore()
IntErr(3) |> ignore()
square(1) |> ignore()
square(2) |> ignore()
}