about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorOli Scherer <github333195615777966@oli-obk.de>2025-02-06 13:48:12 +0000
committerOli Scherer <github333195615777966@oli-obk.de>2025-02-11 08:51:05 +0000
commit6d7ce4e893003cc652428ec02eb752bba63645e2 (patch)
treecaf8b8ce21c274ebb92c49fa29b92c7ccd0a6f49 /tests
parentc182ce9cbc8c29ebc1b4559d027df545e6cdd287 (diff)
downloadrust-6d7ce4e893003cc652428ec02eb752bba63645e2.tar.gz
rust-6d7ce4e893003cc652428ec02eb752bba63645e2.zip
Add a TyPat in the AST to reuse the generic arg lowering logic
Diffstat (limited to 'tests')
-rw-r--r--tests/ui/type/pattern_types/assoc_const.default.stderr83
-rw-r--r--tests/ui/type/pattern_types/assoc_const.rs12
-rw-r--r--tests/ui/type/pattern_types/bad_const_generics_args_on_const_param.rs2
-rw-r--r--tests/ui/type/pattern_types/bad_const_generics_args_on_const_param.stderr11
-rw-r--r--tests/ui/type/pattern_types/const_block.rs2
-rw-r--r--tests/ui/type/pattern_types/const_block.stderr72
-rw-r--r--tests/ui/type/pattern_types/feature-gate-pattern_types.rs1
-rw-r--r--tests/ui/type/pattern_types/feature-gate-pattern_types.stderr8
-rw-r--r--tests/ui/type/pattern_types/feature-gate-pattern_types2.rs2
-rw-r--r--tests/ui/type/pattern_types/feature-gate-pattern_types2.stderr8
-rw-r--r--tests/ui/unpretty/expanded-exhaustive.stdout2
11 files changed, 54 insertions, 149 deletions
diff --git a/tests/ui/type/pattern_types/assoc_const.default.stderr b/tests/ui/type/pattern_types/assoc_const.default.stderr
index c5d9691a029..8cff0cee7b9 100644
--- a/tests/ui/type/pattern_types/assoc_const.default.stderr
+++ b/tests/ui/type/pattern_types/assoc_const.default.stderr
@@ -1,79 +1,38 @@
-error[E0658]: wraparound pattern type ranges cause monomorphization time errors
-  --> $DIR/assoc_const.rs:17:19
+error: generic parameters may not be used in const operations
+  --> $DIR/assoc_const.rs:17:41
    |
 LL | fn foo<T: Foo>(_: pattern_type!(u32 is <T as Foo>::START..=<T as Foo>::END)) {}
-   |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |                                         ^ cannot perform const operation using `T`
    |
-   = note: see issue #136574 <https://github.com/rust-lang/rust/issues/136574> for more information
-   = help: add `#![feature(generic_pattern_types)]` to the crate attributes to enable
-   = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
+   = note: type parameters may not be used in const expressions
+   = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
 
-error[E0658]: wraparound pattern type ranges cause monomorphization time errors
-  --> $DIR/assoc_const.rs:17:19
+error: generic parameters may not be used in const operations
+  --> $DIR/assoc_const.rs:17:61
    |
 LL | fn foo<T: Foo>(_: pattern_type!(u32 is <T as Foo>::START..=<T as Foo>::END)) {}
-   |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |                                                             ^ cannot perform const operation using `T`
    |
-   = note: see issue #136574 <https://github.com/rust-lang/rust/issues/136574> for more information
-   = help: add `#![feature(generic_pattern_types)]` to the crate attributes to enable
-   = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
-   = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
+   = note: type parameters may not be used in const expressions
+   = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
 
-error: constant expression depends on a generic parameter
-  --> $DIR/assoc_const.rs:17:19
-   |
-LL | fn foo<T: Foo>(_: pattern_type!(u32 is <T as Foo>::START..=<T as Foo>::END)) {}
-   |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-   |
-   = note: this may fail depending on what value the parameter takes
-
-error: constant expression depends on a generic parameter
-  --> $DIR/assoc_const.rs:17:19
-   |
-LL | fn foo<T: Foo>(_: pattern_type!(u32 is <T as Foo>::START..=<T as Foo>::END)) {}
-   |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-   |
-   = note: this may fail depending on what value the parameter takes
-   = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
-
-error[E0658]: wraparound pattern type ranges cause monomorphization time errors
-  --> $DIR/assoc_const.rs:22:19
-   |
-LL | fn bar<T: Foo>(_: pattern_type!(u32 is T::START..=T::END)) {}
-   |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-   |
-   = note: see issue #136574 <https://github.com/rust-lang/rust/issues/136574> for more information
-   = help: add `#![feature(generic_pattern_types)]` to the crate attributes to enable
-   = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
-
-error[E0658]: wraparound pattern type ranges cause monomorphization time errors
-  --> $DIR/assoc_const.rs:22:19
-   |
-LL | fn bar<T: Foo>(_: pattern_type!(u32 is T::START..=T::END)) {}
-   |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-   |
-   = note: see issue #136574 <https://github.com/rust-lang/rust/issues/136574> for more information
-   = help: add `#![feature(generic_pattern_types)]` to the crate attributes to enable
-   = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
-   = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
-
-error: constant expression depends on a generic parameter
-  --> $DIR/assoc_const.rs:22:19
+error: generic parameters may not be used in const operations
+  --> $DIR/assoc_const.rs:20:40
    |
 LL | fn bar<T: Foo>(_: pattern_type!(u32 is T::START..=T::END)) {}
-   |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |                                        ^^^^^^^^ cannot perform const operation using `T`
    |
-   = note: this may fail depending on what value the parameter takes
+   = note: type parameters may not be used in const expressions
+   = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
 
-error: constant expression depends on a generic parameter
-  --> $DIR/assoc_const.rs:22:19
+error: generic parameters may not be used in const operations
+  --> $DIR/assoc_const.rs:20:51
    |
 LL | fn bar<T: Foo>(_: pattern_type!(u32 is T::START..=T::END)) {}
-   |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |                                                   ^^^^^^ cannot perform const operation using `T`
    |
-   = note: this may fail depending on what value the parameter takes
-   = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
+   = note: type parameters may not be used in const expressions
+   = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
 
-error: aborting due to 8 previous errors
+error: aborting due to 4 previous errors
 
-For more information about this error, try `rustc --explain E0658`.
diff --git a/tests/ui/type/pattern_types/assoc_const.rs b/tests/ui/type/pattern_types/assoc_const.rs
index 87886587d51..90508801990 100644
--- a/tests/ui/type/pattern_types/assoc_const.rs
+++ b/tests/ui/type/pattern_types/assoc_const.rs
@@ -15,14 +15,10 @@ trait Foo {
 }
 
 fn foo<T: Foo>(_: pattern_type!(u32 is <T as Foo>::START..=<T as Foo>::END)) {}
-//[default]~^ ERROR: constant expression depends on a generic parameter
-//[default]~| ERROR: constant expression depends on a generic parameter
-//[default]~| ERROR: wraparound pattern type ranges cause monomorphization time errors
-//[default]~| ERROR: wraparound pattern type ranges cause monomorphization time errors
+//[default]~^ ERROR: generic parameters may not be used in const operations
+//[default]~| ERROR: generic parameters may not be used in const operations
 fn bar<T: Foo>(_: pattern_type!(u32 is T::START..=T::END)) {}
-//[default]~^ ERROR: constant expression depends on a generic parameter
-//[default]~| ERROR: constant expression depends on a generic parameter
-//[default]~| ERROR: wraparound pattern type ranges cause monomorphization time errors
-//[default]~| ERROR: wraparound pattern type ranges cause monomorphization time errors
+//[default]~^ ERROR: generic parameters may not be used in const operations
+//[default]~| ERROR: generic parameters may not be used in const operations
 
 fn main() {}
diff --git a/tests/ui/type/pattern_types/bad_const_generics_args_on_const_param.rs b/tests/ui/type/pattern_types/bad_const_generics_args_on_const_param.rs
index 0f10bf8ce62..c28fda6f91a 100644
--- a/tests/ui/type/pattern_types/bad_const_generics_args_on_const_param.rs
+++ b/tests/ui/type/pattern_types/bad_const_generics_args_on_const_param.rs
@@ -5,7 +5,7 @@
 //@ normalize-stderr: "(error: internal compiler error: [^:]+):\d+:\d+: " -> "$1:LL:CC: "
 //@ rustc-env:RUST_BACKTRACE=0
 
-#![feature(pattern_types, pattern_type_macro)]
+#![feature(pattern_types, pattern_type_macro, generic_const_exprs)]
 #![allow(internal_features)]
 
 type Pat<const START: u32, const END: u32> =
diff --git a/tests/ui/type/pattern_types/bad_const_generics_args_on_const_param.stderr b/tests/ui/type/pattern_types/bad_const_generics_args_on_const_param.stderr
index fbe80a19863..ffc6068eb17 100644
--- a/tests/ui/type/pattern_types/bad_const_generics_args_on_const_param.stderr
+++ b/tests/ui/type/pattern_types/bad_const_generics_args_on_const_param.stderr
@@ -1,4 +1,11 @@
-error: internal compiler error: compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs:LL:CC: try_lower_anon_const_lit: received const param which shouldn't be possible
+warning: the feature `generic_const_exprs` is incomplete and may not be safe to use and/or cause compiler crashes
+  --> $DIR/bad_const_generics_args_on_const_param.rs:8:47
+   |
+LL | #![feature(pattern_types, pattern_type_macro, generic_const_exprs)]
+   |                                               ^^^^^^^^^^^^^^^^^^^
+   |
+   = note: see issue #76560 <https://github.com/rust-lang/rust/issues/76560> for more information
+   = error: internal compiler error: compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs:LL:CC: try_lower_anon_const_lit: received const param which shouldn't be possible
   --> $DIR/bad_const_generics_args_on_const_param.rs:12:36
    |
 LL |     std::pat::pattern_type!(u32 is START::<(), i32, 2>..=END::<_, Assoc = ()>);
@@ -10,5 +17,5 @@ query stack during panic:
 #0 [type_of] expanding type alias `Pat`
 #1 [check_well_formed] checking that `Pat` is well-formed
 ... and 2 other queries... use `env RUST_BACKTRACE=1` to see the full query stack
-error: aborting due to 1 previous error
+error: aborting due to 1 previous error; 1 warning emitted
 
diff --git a/tests/ui/type/pattern_types/const_block.rs b/tests/ui/type/pattern_types/const_block.rs
index 49c87f4fa0d..ed19b10671a 100644
--- a/tests/ui/type/pattern_types/const_block.rs
+++ b/tests/ui/type/pattern_types/const_block.rs
@@ -1,10 +1,10 @@
 #![feature(pattern_types)]
 #![feature(pattern_type_macro)]
 #![feature(inline_const_pat)]
+//@ check-pass
 
 use std::pat::pattern_type;
 
 fn bar(x: pattern_type!(u32 is 0..=const{ 5 + 5 })) {}
-//~^ ERROR: cycle
 
 fn main() {}
diff --git a/tests/ui/type/pattern_types/const_block.stderr b/tests/ui/type/pattern_types/const_block.stderr
deleted file mode 100644
index 82b616105af..00000000000
--- a/tests/ui/type/pattern_types/const_block.stderr
+++ /dev/null
@@ -1,72 +0,0 @@
-error[E0391]: cycle detected when evaluating type-level constant
-  --> $DIR/const_block.rs:7:36
-   |
-LL | fn bar(x: pattern_type!(u32 is 0..=const{ 5 + 5 })) {}
-   |                                    ^^^^^^^^^^^^^^
-   |
-note: ...which requires const-evaluating + checking `bar::{constant#2}`...
-  --> $DIR/const_block.rs:7:36
-   |
-LL | fn bar(x: pattern_type!(u32 is 0..=const{ 5 + 5 })) {}
-   |                                    ^^^^^^^^^^^^^^
-note: ...which requires caching mir of `bar::{constant#2}` for CTFE...
-  --> $DIR/const_block.rs:7:36
-   |
-LL | fn bar(x: pattern_type!(u32 is 0..=const{ 5 + 5 })) {}
-   |                                    ^^^^^^^^^^^^^^
-note: ...which requires elaborating drops for `bar::{constant#2}`...
-  --> $DIR/const_block.rs:7:36
-   |
-LL | fn bar(x: pattern_type!(u32 is 0..=const{ 5 + 5 })) {}
-   |                                    ^^^^^^^^^^^^^^
-note: ...which requires borrow-checking `bar::{constant#2}`...
-  --> $DIR/const_block.rs:7:36
-   |
-LL | fn bar(x: pattern_type!(u32 is 0..=const{ 5 + 5 })) {}
-   |                                    ^^^^^^^^^^^^^^
-note: ...which requires borrow-checking `bar::{constant#0}`...
-  --> $DIR/const_block.rs:7:41
-   |
-LL | fn bar(x: pattern_type!(u32 is 0..=const{ 5 + 5 })) {}
-   |                                         ^^^^^^^^^
-note: ...which requires promoting constants in MIR for `bar::{constant#0}`...
-  --> $DIR/const_block.rs:7:41
-   |
-LL | fn bar(x: pattern_type!(u32 is 0..=const{ 5 + 5 })) {}
-   |                                         ^^^^^^^^^
-note: ...which requires const checking `bar::{constant#0}`...
-  --> $DIR/const_block.rs:7:41
-   |
-LL | fn bar(x: pattern_type!(u32 is 0..=const{ 5 + 5 })) {}
-   |                                         ^^^^^^^^^
-note: ...which requires building MIR for `bar::{constant#0}`...
-  --> $DIR/const_block.rs:7:41
-   |
-LL | fn bar(x: pattern_type!(u32 is 0..=const{ 5 + 5 })) {}
-   |                                         ^^^^^^^^^
-note: ...which requires match-checking `bar::{constant#0}`...
-  --> $DIR/const_block.rs:7:41
-   |
-LL | fn bar(x: pattern_type!(u32 is 0..=const{ 5 + 5 })) {}
-   |                                         ^^^^^^^^^
-note: ...which requires type-checking `bar::{constant#0}`...
-  --> $DIR/const_block.rs:7:41
-   |
-LL | fn bar(x: pattern_type!(u32 is 0..=const{ 5 + 5 })) {}
-   |                                         ^^^^^^^^^
-note: ...which requires type-checking `bar`...
-  --> $DIR/const_block.rs:7:1
-   |
-LL | fn bar(x: pattern_type!(u32 is 0..=const{ 5 + 5 })) {}
-   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-   = note: ...which again requires evaluating type-level constant, completing the cycle
-note: cycle used when checking that `bar` is well-formed
-  --> $DIR/const_block.rs:7:1
-   |
-LL | fn bar(x: pattern_type!(u32 is 0..=const{ 5 + 5 })) {}
-   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-   = note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
-
-error: aborting due to 1 previous error
-
-For more information about this error, try `rustc --explain E0391`.
diff --git a/tests/ui/type/pattern_types/feature-gate-pattern_types.rs b/tests/ui/type/pattern_types/feature-gate-pattern_types.rs
index b90ba478402..b4f4bd656f5 100644
--- a/tests/ui/type/pattern_types/feature-gate-pattern_types.rs
+++ b/tests/ui/type/pattern_types/feature-gate-pattern_types.rs
@@ -12,3 +12,4 @@ type Positive = pattern_type!(i32 is 0..);
 //~^ use of unstable library feature `pattern_type_macro`
 type Always = pattern_type!(Option<u32> is Some(_));
 //~^ use of unstable library feature `pattern_type_macro`
+//~| ERROR pattern not supported in pattern types
diff --git a/tests/ui/type/pattern_types/feature-gate-pattern_types.stderr b/tests/ui/type/pattern_types/feature-gate-pattern_types.stderr
index 69239d68bdc..12508bcb54a 100644
--- a/tests/ui/type/pattern_types/feature-gate-pattern_types.stderr
+++ b/tests/ui/type/pattern_types/feature-gate-pattern_types.stderr
@@ -48,6 +48,12 @@ LL | type Always = pattern_type!(Option<u32> is Some(_));
    = help: add `#![feature(pattern_type_macro)]` to the crate attributes to enable
    = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
 
-error: aborting due to 5 previous errors
+error: pattern not supported in pattern types
+  --> $DIR/feature-gate-pattern_types.rs:13:44
+   |
+LL | type Always = pattern_type!(Option<u32> is Some(_));
+   |                                            ^^^^^^^
+
+error: aborting due to 6 previous errors
 
 For more information about this error, try `rustc --explain E0658`.
diff --git a/tests/ui/type/pattern_types/feature-gate-pattern_types2.rs b/tests/ui/type/pattern_types/feature-gate-pattern_types2.rs
index 50c355c8de6..c6b4b325fa3 100644
--- a/tests/ui/type/pattern_types/feature-gate-pattern_types2.rs
+++ b/tests/ui/type/pattern_types/feature-gate-pattern_types2.rs
@@ -1,5 +1,4 @@
 //@ compile-flags: -Zno-analysis
-//@ check-pass
 
 #![feature(pattern_type_macro)]
 
@@ -10,3 +9,4 @@ type Percent = pattern_type!(u32 is 0..=100);
 type Negative = pattern_type!(i32 is ..=0);
 type Positive = pattern_type!(i32 is 0..);
 type Always = pattern_type!(Option<u32> is Some(_));
+//~^ ERROR: pattern not supported in pattern types
diff --git a/tests/ui/type/pattern_types/feature-gate-pattern_types2.stderr b/tests/ui/type/pattern_types/feature-gate-pattern_types2.stderr
new file mode 100644
index 00000000000..81bf9dea0e2
--- /dev/null
+++ b/tests/ui/type/pattern_types/feature-gate-pattern_types2.stderr
@@ -0,0 +1,8 @@
+error: pattern not supported in pattern types
+  --> $DIR/feature-gate-pattern_types2.rs:11:44
+   |
+LL | type Always = pattern_type!(Option<u32> is Some(_));
+   |                                            ^^^^^^^
+
+error: aborting due to 1 previous error
+
diff --git a/tests/ui/unpretty/expanded-exhaustive.stdout b/tests/ui/unpretty/expanded-exhaustive.stdout
index 11066c90edb..19ae66f7a07 100644
--- a/tests/ui/unpretty/expanded-exhaustive.stdout
+++ b/tests/ui/unpretty/expanded-exhaustive.stdout
@@ -678,7 +678,7 @@ mod types {
         /*! FIXME: todo */
     }
     /// TyKind::Pat
-    fn ty_pat() { let _: u32 is 1..; }
+    fn ty_pat() { let _: u32 is const 1..; }
 }
 mod visibilities {
     /// VisibilityKind::Public