about summary refs log tree commit diff
diff options
context:
space:
mode:
author许杰友 Jieyou Xu (Joe) <39484203+jieyouxu@users.noreply.github.com>2024-11-22 20:32:37 +0800
committerGitHub <noreply@github.com>2024-11-22 20:32:37 +0800
commit74b8522855b3d86086dffbe1a1fcaa8146eda51b (patch)
treeedaf41fdae26226eef409bea87d64b8e3743d564
parent8fdba31f8b0d64dfc7fe95fad557c369a0f35f58 (diff)
parent8dfed4ec980a0c6559cffeeea614f13b361170c2 (diff)
downloadrust-74b8522855b3d86086dffbe1a1fcaa8146eda51b.tar.gz
rust-74b8522855b3d86086dffbe1a1fcaa8146eda51b.zip
Rollup merge of #133323 - compiler-errors:bail-if-self-var, r=lcnr
Bail in effects in old solver if self ty is ty var

Otherwise when we try to check something like `?t: ~const Trait` we'll immediately stick it to the first param-env candidate, lol.

r? lcnr
-rw-r--r--compiler/rustc_trait_selection/src/traits/effects.rs5
-rw-r--r--tests/ui/traits/const-traits/effects/dont-prefer-param-env-for-infer-self-ty.rs16
2 files changed, 21 insertions, 0 deletions
diff --git a/compiler/rustc_trait_selection/src/traits/effects.rs b/compiler/rustc_trait_selection/src/traits/effects.rs
index cb36f1a62db..27d3ec160ca 100644
--- a/compiler/rustc_trait_selection/src/traits/effects.rs
+++ b/compiler/rustc_trait_selection/src/traits/effects.rs
@@ -27,6 +27,11 @@ pub fn evaluate_host_effect_obligation<'tcx>(
         );
     }
 
+    // Force ambiguity for infer self ty.
+    if obligation.predicate.self_ty().is_ty_var() {
+        return Err(EvaluationFailure::Ambiguous);
+    }
+
     match evaluate_host_effect_from_bounds(selcx, obligation) {
         Ok(result) => return Ok(result),
         Err(EvaluationFailure::Ambiguous) => return Err(EvaluationFailure::Ambiguous),
diff --git a/tests/ui/traits/const-traits/effects/dont-prefer-param-env-for-infer-self-ty.rs b/tests/ui/traits/const-traits/effects/dont-prefer-param-env-for-infer-self-ty.rs
new file mode 100644
index 00000000000..08dcd7d80b3
--- /dev/null
+++ b/tests/ui/traits/const-traits/effects/dont-prefer-param-env-for-infer-self-ty.rs
@@ -0,0 +1,16 @@
+//@ check-pass
+
+#![feature(const_trait_impl)]
+
+#[const_trait]
+trait Foo {}
+
+impl<T> const Foo for (T,) where T: ~const Foo {}
+
+const fn needs_const_foo(_: impl ~const Foo + Copy) {}
+
+const fn test<T: ~const Foo + Copy>(t: T) {
+    needs_const_foo((t,));
+}
+
+fn main() {}