Closed
Description
trait Test<T> {
fn is_some(self: T);
}
fn f() {
let x = Some(2);
if x.is_some() {
println!("Some");
}
}
produces an expected error:
error[E0307]: invalid `self` parameter type: T
--> src/lib.rs:2:22
|
2 | fn is_some(self: T);
| ^
|
= note: type of `self` must be `Self` or a type that dereferences to it
= help: consider changing to `self`, `&self`, `&mut self`, `self: Box<Self>`, `self: Rc<Self>`, `self: Arc<Self>`, or `self: Pin<P>` (where P is one of the previous types except `Self`)
trait Test<T> {
fn is_some(self: T);
}
async fn f() {
let x = Some(2);
if x.is_some() {
println!("Some");
}
}
the original error is replaced with this:
error[E0308]: mismatched types
--> src/lib.rs:7:8
|
7 | if x.is_some() {
| ^^^^^^^^^^^ expected bool, found ()
|
= note: expected type `bool`
found type `()`
Meta
rustc --version --verbose
:
rustc 1.39.0 (4560ea788 2019-11-04)
binary: rustc
commit-hash: 4560ea788cb760f0a34127156c78e2552949f734
commit-date: 2019-11-04
host: x86_64-unknown-linux-gnu
release: 1.39.0
LLVM version: 9.0
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Done