about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2025-03-09 01:53:57 +0000
committerMichael Goulet <michael@errs.io>2025-03-09 02:00:01 +0000
commit3129802f902c361aa5ed2f7c44a7e5c892c8a37a (patch)
tree4971e0c50e11f079f00c59c0d46ec4c2cf1faec5
parentdea1661cdb6ccaa636abdeea3bd0a9804d3db240 (diff)
downloadrust-3129802f902c361aa5ed2f7c44a7e5c892c8a37a.tar.gz
rust-3129802f902c361aa5ed2f7c44a7e5c892c8a37a.zip
Do not register `Self: AutoTrait` when confirming auto trait
-rw-r--r--compiler/rustc_trait_selection/src/traits/select/confirmation.rs16
-rw-r--r--tests/ui/traits/inductive-overflow/supertrait-auto-trait.rs2
-rw-r--r--tests/ui/traits/inductive-overflow/supertrait-auto-trait.stderr29
3 files changed, 4 insertions, 43 deletions
diff --git a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs
index 6db97fc321a..4cd6781ab89 100644
--- a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs
+++ b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs
@@ -463,18 +463,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
             let cause = obligation.derived_cause(ObligationCauseCode::BuiltinDerived);
 
             assert_eq!(obligation.predicate.polarity(), ty::PredicatePolarity::Positive);
-            let trait_ref =
-                self.infcx.enter_forall_and_leak_universe(obligation.predicate).trait_ref;
-            let trait_obligations = self.impl_or_trait_obligations(
-                &cause,
-                obligation.recursion_depth + 1,
-                obligation.param_env,
-                trait_def_id,
-                trait_ref.args,
-                obligation.predicate,
-            );
 
-            let mut obligations = self.collect_predicates_for_types(
+            let obligations = self.collect_predicates_for_types(
                 obligation.param_env,
                 cause,
                 obligation.recursion_depth + 1,
@@ -482,10 +472,6 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
                 nested,
             );
 
-            // Adds the predicates from the trait. Note that this contains a `Self: Trait`
-            // predicate as usual. It won't have any effect since auto traits are coinductive.
-            obligations.extend(trait_obligations);
-
             debug!(?obligations, "vtable_auto_impl");
 
             obligations
diff --git a/tests/ui/traits/inductive-overflow/supertrait-auto-trait.rs b/tests/ui/traits/inductive-overflow/supertrait-auto-trait.rs
index 5fea47a1be8..ca31d39de98 100644
--- a/tests/ui/traits/inductive-overflow/supertrait-auto-trait.rs
+++ b/tests/ui/traits/inductive-overflow/supertrait-auto-trait.rs
@@ -13,6 +13,6 @@ fn copy<T: Magic>(x: T) -> (T, T) { (x, x) }
 struct NoClone;
 
 fn main() {
-    let (a, b) = copy(NoClone); //~ ERROR
+    let (a, b) = copy(NoClone);
     println!("{:?} {:?}", a, b);
 }
diff --git a/tests/ui/traits/inductive-overflow/supertrait-auto-trait.stderr b/tests/ui/traits/inductive-overflow/supertrait-auto-trait.stderr
index 07edc4ede76..3a3b99f6c5b 100644
--- a/tests/ui/traits/inductive-overflow/supertrait-auto-trait.stderr
+++ b/tests/ui/traits/inductive-overflow/supertrait-auto-trait.stderr
@@ -6,31 +6,6 @@ LL | auto trait Magic: Copy {}
    |            |
    |            auto traits cannot have super traits or lifetime bounds
 
-error[E0277]: the trait bound `NoClone: Magic` is not satisfied
-  --> $DIR/supertrait-auto-trait.rs:16:23
-   |
-LL |     let (a, b) = copy(NoClone);
-   |                  ---- ^^^^^^^ the trait `Copy` is not implemented for `NoClone`
-   |                  |
-   |                  required by a bound introduced by this call
-   |
-note: required for `NoClone` to implement `Magic`
-  --> $DIR/supertrait-auto-trait.rs:8:12
-   |
-LL | auto trait Magic: Copy {}
-   |            ^^^^^
-note: required by a bound in `copy`
-  --> $DIR/supertrait-auto-trait.rs:10:12
-   |
-LL | fn copy<T: Magic>(x: T) -> (T, T) { (x, x) }
-   |            ^^^^^ required by this bound in `copy`
-help: consider annotating `NoClone` with `#[derive(Copy)]`
-   |
-LL + #[derive(Copy)]
-LL | struct NoClone;
-   |
-
-error: aborting due to 2 previous errors
+error: aborting due to 1 previous error
 
-Some errors have detailed explanations: E0277, E0568.
-For more information about an error, try `rustc --explain E0277`.
+For more information about this error, try `rustc --explain E0568`.