about summary refs log tree commit diff
path: root/tests/ui/impl-trait/method/would-constrain-opaque.rs
diff options
context:
space:
mode:
authorThe rustc-josh-sync Cronjob Bot <github-actions@github.com>2025-09-29 04:07:50 +0000
committerThe rustc-josh-sync Cronjob Bot <github-actions@github.com>2025-09-29 04:07:50 +0000
commit24f6f94c5ad90be5d1ced24d83b8485712bcc27a (patch)
tree722e3fdf88fdae0903cd1ff43cfc801db18345d3 /tests/ui/impl-trait/method/would-constrain-opaque.rs
parent50171eb172a9418e8a20ad7d813d256305add5f0 (diff)
parentf957826bff7a68b267ce75b1ea56352aed0cca0a (diff)
downloadrust-24f6f94c5ad90be5d1ced24d83b8485712bcc27a.tar.gz
rust-24f6f94c5ad90be5d1ced24d83b8485712bcc27a.zip
Merge ref 'f957826bff7a' from rust-lang/rust
Pull recent changes from https://github.com/rust-lang/rust via Josh.

Upstream ref: f957826bff7a68b267ce75b1ea56352aed0cca0a
Filtered ref: 7291893f9d875b6e8775a7a0e661abdaec15d3c1
Upstream diff: https://github.com/rust-lang/rust/compare/caccb4d0368bd918ef6668af8e13834d07040417...f957826bff7a68b267ce75b1ea56352aed0cca0a

This merge was created using https://github.com/rust-lang/josh-sync.
Diffstat (limited to 'tests/ui/impl-trait/method/would-constrain-opaque.rs')
-rw-r--r--tests/ui/impl-trait/method/would-constrain-opaque.rs39
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/ui/impl-trait/method/would-constrain-opaque.rs b/tests/ui/impl-trait/method/would-constrain-opaque.rs
new file mode 100644
index 00000000000..8dd32282529
--- /dev/null
+++ b/tests/ui/impl-trait/method/would-constrain-opaque.rs
@@ -0,0 +1,39 @@
+//@ revisions: current next
+//@[next] compile-flags: -Znext-solver
+
+// If we don't treat `impl Sized` as rigid, the first call would
+// resolve to the trait method, constraining the opaque, while the
+// second call would resolve to the inherent method.
+//
+// We avoid cases like this by rejecting candidates which constrain
+// opaque types encountered in the autoderef chain.
+//
+// FIXME(-Znext-solver): ideally we would note that the inference variable
+// is an opaque type in the error message and change this to a type annotations
+// needed error.
+
+trait Trait: Sized {
+    fn method(self) {}
+}
+impl Trait for &Foo {}
+
+struct Foo;
+impl Foo {
+    fn method(&self) {}
+}
+
+fn define_opaque(b: bool) -> impl Sized {
+    if b {
+        let x = &define_opaque(false);
+        x.method();
+        //~^ ERROR no method named `method` found for reference
+        x.method();
+        //~^ ERROR no method named `method` found for reference
+    }
+
+    Foo
+}
+
+fn main() {
+    define_opaque(true);
+}