rust/tests/ui/methods/call_method_unknown_referent.stderr
Adrian Taylor e75660dad3 Arbitrary self types v2: use Receiver trait
In this new version of Arbitrary Self Types, we no longer use the Deref trait
exclusively when working out which self types are valid. Instead, we follow a
chain of Receiver traits. This enables methods to be called on smart pointer
types which fundamentally cannot support Deref (for instance because they are
wrappers for pointers that don't follow Rust's aliasing rules).

This includes:
* Changes to tests appropriately
* New tests for:
  * The basics of the feature
  * Ensuring lifetime elision works properly
  * Generic Receivers
  * A copy of the method subst test enhanced with Receiver

This is really the heart of the 'arbitrary self types v2' feature, and
is the most critical commit in the current PR.

Subsequent commits are focused on:
* Detecting "shadowing" problems, where a smart pointer type can hide
  methods in the pointee.
* Diagnostics and cleanup.

Naming: in this commit, the "Autoderef" type is modified so that it no
longer solely focuses on the "Deref" trait, but can now consider the
"Receiver" trait instead. Should it be renamed, to something like
"TraitFollower"? This was considered, but rejected, because
* even in the Receiver case, it still considers built-in derefs
* the name Autoderef is short and snappy.
2024-12-11 11:59:12 +00:00

30 lines
1.1 KiB
Plaintext

error[E0282]: type annotations needed
--> $DIR/call_method_unknown_referent.rs:20:31
|
LL | let _a: i32 = (ptr as &_).read();
| ^^^^ cannot infer type
error[E0282]: type annotations needed
--> $DIR/call_method_unknown_referent.rs:26:37
|
LL | let _b = (rc as std::rc::Rc<_>).read();
| ^^^^ cannot infer type
error[E0599]: no method named `read` found for struct `SmartPtr` in the current scope
--> $DIR/call_method_unknown_referent.rs:46:35
|
LL | struct SmartPtr<T>(T);
| ------------------ method `read` not found for this struct
...
LL | let _c = (ptr as SmartPtr<_>).read();
| ^^^^ method not found in `SmartPtr<_>`
|
= help: items from traits can only be used if the trait is implemented and in scope
= note: the following trait defines an item `read`, perhaps you need to implement it:
candidate #1: `std::io::Read`
error: aborting due to 3 previous errors
Some errors have detailed explanations: E0282, E0599.
For more information about an error, try `rustc --explain E0282`.