]> git.proxmox.com Git - rustc.git/blame - src/librustc_error_codes/error_codes/E0699.md
New upstream version 1.47.0+dfsg1
[rustc.git] / src / librustc_error_codes / error_codes / E0699.md
CommitLineData
60c5eb7d
XL
1A method was called on a raw pointer whose inner type wasn't completely known.
2
f035d41b 3Erroneous code example:
60c5eb7d 4
f035d41b 5```compile_fail,edition2018,E0699
60c5eb7d 6# #![deny(warnings)]
f035d41b 7# fn main() {
60c5eb7d
XL
8let foo = &1;
9let bar = foo as *const _;
10if bar.is_null() {
11 // ...
12}
f035d41b 13# }
60c5eb7d
XL
14```
15
16Here, the type of `bar` isn't known; it could be a pointer to anything. Instead,
17specify a type for the pointer (preferably something that makes sense for the
18thing you're pointing to):
19
20```
21let foo = &1;
22let bar = foo as *const i32;
23if bar.is_null() {
24 // ...
25}
26```
27
28Even though `is_null()` exists as a method on any raw pointer, Rust shows this
29error because Rust allows for `self` to have arbitrary types (behind the
30arbitrary_self_types feature flag).
31
32This means that someone can specify such a function:
33
34```ignore (cannot-doctest-feature-doesnt-exist-yet)
35impl Foo {
36 fn is_null(self: *const Self) -> bool {
37 // do something else
38 }
39}
40```
41
42and now when you call `.is_null()` on a raw pointer to `Foo`, there's ambiguity.
43
44Given that we don't know what type the pointer is, and there's potential
45ambiguity for some types, we disallow calling methods on raw pointers when
46the type is unknown.