@@ -4698,6 +4698,55 @@ element type `T`. Also note that the error is conservatively reported even when
4698
4698
the alignment of the zero-sized type is less than or equal to the data field's
4699
4699
alignment.
4700
4700
"## ,
4701
+
4702
+
4703
+ E0908 : r##"
4704
+ A method was called on a raw pointer whose inner type wasn't completely known.
4705
+
4706
+ For example, you may have done something like:
4707
+
4708
+ ```compile_fail
4709
+ # #![deny(warnings)]
4710
+ let foo = &1;
4711
+ let bar = foo as *const _;
4712
+ if bar.is_null() {
4713
+ // ...
4714
+ }
4715
+ ```
4716
+
4717
+ Here, the type of `bar` isn't known; it could be a pointer to anything. Instead,
4718
+ specify a type for the pointer (preferably something that makes sense for the
4719
+ thing you're pointing to):
4720
+
4721
+ ```
4722
+ let foo = &1;
4723
+ let bar = foo as *const i32;
4724
+ if bar.is_null() {
4725
+ // ...
4726
+ }
4727
+ ```
4728
+
4729
+ Even though `is_null()` exists as a method on any raw pointer, Rust shows this
4730
+ error because Rust allows for `self` to have arbitrary types (behind the
4731
+ arbitrary_self_types feature flag).
4732
+
4733
+ This means that someone can specify such a function:
4734
+
4735
+ ```ignore (cannot-doctest-feature-doesnt-exist-yet)
4736
+ impl Foo {
4737
+ fn is_null(self: *const Self) -> bool {
4738
+ // do something else
4739
+ }
4740
+ }
4741
+ ```
4742
+
4743
+ and now when you call `.is_null()` on a raw pointer to `Foo`, there's ambiguity.
4744
+
4745
+ Given that we don't know what type the pointer is, and there's potential
4746
+ ambiguity for some types, we disallow calling methods on raw pointers when
4747
+ the type is unknown.
4748
+ "## ,
4749
+
4701
4750
}
4702
4751
4703
4752
register_diagnostics ! {
@@ -4777,5 +4826,4 @@ register_diagnostics! {
4777
4826
E0641 , // cannot cast to/from a pointer with an unknown kind
4778
4827
E0645 , // trait aliases not finished
4779
4828
E0907 , // type inside generator must be known in this context
4780
- E0908 , // methods on raw pointers can only be called if the pointer type is fully known
4781
4829
}
0 commit comments