about summary refs log tree commit diff
path: root/tests/ui
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ui')
-rw-r--r--tests/ui/impl-trait/precise-capturing/overcaptures-2024.fixed4
-rw-r--r--tests/ui/impl-trait/precise-capturing/overcaptures-2024.rs4
-rw-r--r--tests/ui/impl-trait/precise-capturing/overcaptures-2024.stderr21
-rw-r--r--tests/ui/structs/default-field-values-support.rs52
-rw-r--r--tests/ui/traits/const-traits/dont-ice-on-const-pred-for-bounds.rs22
5 files changed, 89 insertions, 14 deletions
diff --git a/tests/ui/impl-trait/precise-capturing/overcaptures-2024.fixed b/tests/ui/impl-trait/precise-capturing/overcaptures-2024.fixed
index 1eb88c71d54..ef8dd055a8a 100644
--- a/tests/ui/impl-trait/precise-capturing/overcaptures-2024.fixed
+++ b/tests/ui/impl-trait/precise-capturing/overcaptures-2024.fixed
@@ -42,4 +42,8 @@ async fn async_fn<'a>(x: &'a ()) -> impl Sized + use<> {}
 //~^ ERROR `impl Sized` will capture more lifetimes than possibly intended in edition 2024
 //~| WARN this changes meaning in Rust 2024
 
+pub fn parens(x: &i32) -> &(impl Clone + use<>) { x }
+//~^ ERROR `impl Clone` will capture more lifetimes than possibly intended in edition 2024
+//~| WARN this changes meaning in Rust 2024
+
 fn main() {}
diff --git a/tests/ui/impl-trait/precise-capturing/overcaptures-2024.rs b/tests/ui/impl-trait/precise-capturing/overcaptures-2024.rs
index 6f1ef6a472f..ce1cfe1246f 100644
--- a/tests/ui/impl-trait/precise-capturing/overcaptures-2024.rs
+++ b/tests/ui/impl-trait/precise-capturing/overcaptures-2024.rs
@@ -42,4 +42,8 @@ async fn async_fn<'a>(x: &'a ()) -> impl Sized {}
 //~^ ERROR `impl Sized` will capture more lifetimes than possibly intended in edition 2024
 //~| WARN this changes meaning in Rust 2024
 
+pub fn parens(x: &i32) -> &impl Clone { x }
+//~^ ERROR `impl Clone` will capture more lifetimes than possibly intended in edition 2024
+//~| WARN this changes meaning in Rust 2024
+
 fn main() {}
diff --git a/tests/ui/impl-trait/precise-capturing/overcaptures-2024.stderr b/tests/ui/impl-trait/precise-capturing/overcaptures-2024.stderr
index 63c87cd46c8..965f8e7b672 100644
--- a/tests/ui/impl-trait/precise-capturing/overcaptures-2024.stderr
+++ b/tests/ui/impl-trait/precise-capturing/overcaptures-2024.stderr
@@ -146,5 +146,24 @@ help: use the precise capturing `use<...>` syntax to make the captures explicit
 LL | async fn async_fn<'a>(x: &'a ()) -> impl Sized + use<> {}
    |                                                +++++++
 
-error: aborting due to 7 previous errors
+error: `impl Clone` will capture more lifetimes than possibly intended in edition 2024
+  --> $DIR/overcaptures-2024.rs:45:28
+   |
+LL | pub fn parens(x: &i32) -> &impl Clone { x }
+   |                            ^^^^^^^^^^
+   |
+   = warning: this changes meaning in Rust 2024
+   = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/rpit-lifetime-capture.html>
+note: specifically, this lifetime is in scope but not mentioned in the type's bounds
+  --> $DIR/overcaptures-2024.rs:45:18
+   |
+LL | pub fn parens(x: &i32) -> &impl Clone { x }
+   |                  ^
+   = note: all lifetimes in scope will be captured by `impl Trait`s in edition 2024
+help: use the precise capturing `use<...>` syntax to make the captures explicit
+   |
+LL | pub fn parens(x: &i32) -> &(impl Clone + use<>) { x }
+   |                            +           ++++++++
+
+error: aborting due to 8 previous errors
 
diff --git a/tests/ui/structs/default-field-values-support.rs b/tests/ui/structs/default-field-values-support.rs
index da0379af94b..8209d6dd4a0 100644
--- a/tests/ui/structs/default-field-values-support.rs
+++ b/tests/ui/structs/default-field-values-support.rs
@@ -1,18 +1,23 @@
+// Exercise the `default_field_values` feature to confirm it interacts correctly with other nightly
+// features. In particular, we want to verify that interaction with consts coming from different
+// contexts are usable as a default field value.
 //@ run-pass
 //@ aux-build:struct_field_default.rs
-#![feature(default_field_values, generic_const_exprs)]
+#![feature(const_trait_impl, default_field_values, generic_const_exprs)]
 #![allow(unused_variables, dead_code, incomplete_features)]
 
 extern crate struct_field_default as xc;
 
 pub struct S;
 
+// Basic expressions and `Default` expansion
 #[derive(Default)]
 pub struct Foo {
     pub bar: S = S,
     pub baz: i32 = 42 + 3,
 }
 
+// Enum support for deriving `Default` when all fields have default values
 #[derive(Default)]
 pub enum Bar {
     #[default]
@@ -22,17 +27,27 @@ pub enum Bar {
     }
 }
 
-#[derive(Default)]
-pub struct Qux<A, const C: i32> {
-    bar: S = Qux::<A, C>::S,
-    baz: i32 = foo(),
-    bat: i32 = <Qux<A, C> as T>::K,
-    baq: i32 = Self::K,
-    bay: i32 = C,
-    bak: Vec<A> = Vec::new(),
+#[const_trait] pub trait ConstDefault {
+    fn value() -> Self;
+}
+
+impl const ConstDefault for i32 {
+    fn value() -> i32 {
+        101
+    }
+}
+
+pub struct Qux<A, const C: i32, X: const ConstDefault> {
+    bar: S = Qux::<A, C, X>::S, // Associated constant from inherent impl
+    baz: i32 = foo(), // Constant function
+    bat: i32 = <Qux<A, C, X> as T>::K, // Associated constant from explicit trait
+    baq: i32 = Self::K, // Associated constant from implicit trait
+    bay: i32 = C, // `const` parameter
+    bak: Vec<A> = Vec::new(), // Associated constant function
+    ban: X = X::value(), // Associated constant function from `const` trait parameter
 }
 
-impl<A, const C: i32> Qux<A, C> {
+impl<A, const C: i32, X: const ConstDefault> Qux<A, C, X> {
     const S: S = S;
 }
 
@@ -40,7 +55,7 @@ trait T {
     const K: i32;
 }
 
-impl<A, const C: i32> T for Qux<A, C> {
+impl<A, const C: i32, X: const ConstDefault> T for Qux<A, C, X> {
     const K: i32 = 2;
 }
 
@@ -65,8 +80,19 @@ fn main () {
     assert!(matches!(Bar::Foo { bar: S, baz: 45 }, y));
     assert!(matches!(Bar::Foo { bar: S, baz: 1 }, z));
 
-    let x = Qux::<i32, 4> { .. };
-    assert!(matches!(Qux::<i32, 4> { bar: S, baz: 42, bat: 2, baq: 2, bay: 4, .. }, x));
+    let x = Qux::<i32, 4, i32> { .. };
+    assert!(matches!(
+        Qux::<i32, 4, i32> {
+            bar: S,
+            baz: 42,
+            bat: 2,
+            baq: 2,
+            bay: 4,
+            ban: 101,
+            ..
+        },
+        x,
+    ));
     assert!(x.bak.is_empty());
 
     let x = xc::A { .. };
diff --git a/tests/ui/traits/const-traits/dont-ice-on-const-pred-for-bounds.rs b/tests/ui/traits/const-traits/dont-ice-on-const-pred-for-bounds.rs
new file mode 100644
index 00000000000..2295c2c3857
--- /dev/null
+++ b/tests/ui/traits/const-traits/dont-ice-on-const-pred-for-bounds.rs
@@ -0,0 +1,22 @@
+// Regression test for <https://github.com/rust-lang/rust/issues/133526>.
+
+// Ensures we don't ICE when we encounter a `HostEffectPredicate` when computing
+// the "item super predicates" for `Assoc`.
+
+//@ compile-flags: -Znext-solver
+//@ check-pass
+
+#![feature(const_trait_impl)]
+
+#[const_trait]
+trait Trait {
+    type Assoc: const Trait;
+}
+
+const fn needs_trait<T: ~const Trait>() {}
+
+fn test<T: Trait>() {
+    const { needs_trait::<T::Assoc>() };
+}
+
+fn main() {}