diff options
| author | bors <bors@rust-lang.org> | 2025-09-26 16:10:47 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2025-09-26 16:10:47 +0000 |
| commit | 54a8a1db604e4caff93e26e167ad4a6fde9f0681 (patch) | |
| tree | 4ad8eb2c873b1431c53293cfd0d6c25fc6b853f5 /tests/ui/impl-trait/method/method-resolution3.rs | |
| parent | a8858111044a9391ac7558f969d3bf62ef43222d (diff) | |
| parent | c2e39c2f20c568b96fe89c751e65bbbe9116231c (diff) | |
| download | rust-54a8a1db604e4caff93e26e167ad4a6fde9f0681.tar.gz rust-54a8a1db604e4caff93e26e167ad4a6fde9f0681.zip | |
Auto merge of #146885 - lcnr:method-selection-opaques, r=BoxyUwU
support opaque types in method selection See my notes in https://hackmd.io/4ILASx3mQ3u_gW9r1JyqCw. This PR builds on https://github.com/rust-lang/rust/pull/145993 and allows not-yet defined opaque types as self types in the `method_autoderef_chain`. E.g. for `Box<impl Deref<impl Foo>>` this results in the autoderef chain `Box<impl Deref> -> ?deref_hidden_ty -> ?foo_hidden_ty`. Method selection stays ambiguous if the final autoderef step is still an infer var unless that var is an opaque. TODO: treating opaques as rigid jank. r? `@BoxyUwU`
Diffstat (limited to 'tests/ui/impl-trait/method/method-resolution3.rs')
| -rw-r--r-- | tests/ui/impl-trait/method/method-resolution3.rs | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/ui/impl-trait/method/method-resolution3.rs b/tests/ui/impl-trait/method/method-resolution3.rs new file mode 100644 index 00000000000..8c47ef4fc75 --- /dev/null +++ b/tests/ui/impl-trait/method/method-resolution3.rs @@ -0,0 +1,27 @@ +//! Check that we consider `Bar<impl Sized>` to successfully unify +//! with both `Bar<u32>` and `Bar<i32>` (in isolation), so we bail +//! out with ambiguity. + +//@ revisions: current next +//@[next] compile-flags: -Znext-solver + +struct Bar<T>(T); + +impl Bar<u32> { + fn bar(self) {} +} + +impl Bar<i32> { + fn bar(self) {} +} + +fn foo(x: bool) -> Bar<impl Sized> { + if x { + let x = foo(false); + x.bar(); + //~^ ERROR: multiple applicable items in scope + } + todo!() +} + +fn main() {} |
