about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2024-12-10 17:20:54 +0000
committerMichael Goulet <michael@errs.io>2024-12-10 17:23:02 +0000
commit57e8a1c9c3b753f3a96a124149ca1ba07f0db483 (patch)
tree634960ebf1315980712814ee0d43362e7e8fafb2
parenta7fa4cbcb498b80b126a954b5944f19a11e28dec (diff)
downloadrust-57e8a1c9c3b753f3a96a124149ca1ba07f0db483.tar.gz
rust-57e8a1c9c3b753f3a96a124149ca1ba07f0db483.zip
Don't check RPITITs that are Self:Sized for PointerLike
-rw-r--r--compiler/rustc_trait_selection/src/traits/select/confirmation.rs5
-rw-r--r--tests/ui/impl-trait/in-trait/sized-rpits-dont-need-pointer-like.rs13
2 files changed, 18 insertions, 0 deletions
diff --git a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs
index 3664121ac4b..962b6b94fa6 100644
--- a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs
+++ b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs
@@ -1197,6 +1197,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
                                 continue;
                             }
 
+                            // RPITITs with `Self: Sized` don't need to be checked.
+                            if tcx.generics_require_sized_self(assoc_item) {
+                                continue;
+                            }
+
                             let pointer_like_goal = pointer_like_goal_for_rpitit(
                                 tcx,
                                 supertrait,
diff --git a/tests/ui/impl-trait/in-trait/sized-rpits-dont-need-pointer-like.rs b/tests/ui/impl-trait/in-trait/sized-rpits-dont-need-pointer-like.rs
new file mode 100644
index 00000000000..80850a2639f
--- /dev/null
+++ b/tests/ui/impl-trait/in-trait/sized-rpits-dont-need-pointer-like.rs
@@ -0,0 +1,13 @@
+//@ check-pass
+
+// Make sure that we don't enforce that an RPIT that has `where Self: Sized` is pointer-like.
+
+trait Foo {
+    fn foo() -> impl Sized where Self: Sized {}
+}
+
+impl Foo for () {}
+
+fn main() {
+    let x: &dyn Foo = &();
+}