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