diff options
| author | Michael Goulet <michael@errs.io> | 2023-10-13 19:47:40 +0000 |
|---|---|---|
| committer | Michael Goulet <michael@errs.io> | 2023-10-13 21:01:36 +0000 |
| commit | 3f2574e8bad436a01a2cb7ea1b054f457bba5f0d (patch) | |
| tree | 2e2b8b721da24eae4a840e97883bf134a36e6f6b | |
| parent | ef04c9795b457c35ec9fd2d11d8259cade60caba (diff) | |
| download | rust-3f2574e8bad436a01a2cb7ea1b054f457bba5f0d.tar.gz rust-3f2574e8bad436a01a2cb7ea1b054f457bba5f0d.zip | |
Test that RPITITs have RPIT scope and not impl-wide scope
| -rw-r--r-- | tests/ui/impl-trait/in-trait/sibling-function-constraint.rs | 21 | ||||
| -rw-r--r-- | tests/ui/impl-trait/in-trait/sibling-function-constraint.stderr | 17 |
2 files changed, 38 insertions, 0 deletions
diff --git a/tests/ui/impl-trait/in-trait/sibling-function-constraint.rs b/tests/ui/impl-trait/in-trait/sibling-function-constraint.rs new file mode 100644 index 00000000000..fe162e6cf80 --- /dev/null +++ b/tests/ui/impl-trait/in-trait/sibling-function-constraint.rs @@ -0,0 +1,21 @@ +// Checks that a sibling function (i.e. `foo`) cannot constrain +// an RPITIT from another function (`bar`). + +trait Trait { + fn foo(); + + fn bar() -> impl Sized; +} + +impl Trait for () { + fn foo() { + let _: String = Self::bar(); + //~^ ERROR mismatched types + } + + fn bar() -> impl Sized { + loop {} + } +} + +fn main() {} diff --git a/tests/ui/impl-trait/in-trait/sibling-function-constraint.stderr b/tests/ui/impl-trait/in-trait/sibling-function-constraint.stderr new file mode 100644 index 00000000000..729963a8141 --- /dev/null +++ b/tests/ui/impl-trait/in-trait/sibling-function-constraint.stderr @@ -0,0 +1,17 @@ +error[E0308]: mismatched types + --> $DIR/sibling-function-constraint.rs:12:25 + | +LL | let _: String = Self::bar(); + | ------ ^^^^^^^^^^^ expected `String`, found opaque type + | | + | expected due to this +... +LL | fn bar() -> impl Sized { + | ---------- the found opaque type + | + = note: expected struct `String` + found opaque type `impl Sized` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. |
