-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow using named consts in pattern types
- Loading branch information
Showing
9 changed files
with
184 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
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: constant expression depends on a generic parameter | ||
--> $DIR/assoc_const.rs:20:19 | ||
| | ||
LL | fn bar<T: Foo>(_: pattern_type!(u32 is T::START..=T::END)) {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: this may fail depending on what value the parameter takes | ||
|
||
error: constant expression depends on a generic parameter | ||
--> $DIR/assoc_const.rs:20:19 | ||
| | ||
LL | fn bar<T: Foo>(_: pattern_type!(u32 is T::START..=T::END)) {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: this may fail depending on what value the parameter takes | ||
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` | ||
|
||
error: aborting due to 4 previous errors | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#![feature(pattern_types)] | ||
#![feature(pattern_type_macro)] | ||
#![cfg_attr(const_arg, feature(generic_const_exprs))] | ||
#![expect(incomplete_features)] | ||
|
||
//@ revisions: default const_arg | ||
|
||
//@[const_arg] check-pass | ||
|
||
use std::pat::pattern_type; | ||
|
||
trait Foo { | ||
const START: u32; | ||
const END: u32; | ||
} | ||
|
||
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 | ||
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 | ||
|
||
fn main() {} |
10 changes: 7 additions & 3 deletions
10
tests/ui/type/pattern_types/bad_const_generics_args_on_const_param.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,14 @@ | ||
//@known-bug: #127972 | ||
//@ failure-status: 101 | ||
//@ normalize-stderr: "note: .*\n\n" -> "" | ||
//@ normalize-stderr: "thread 'rustc' panicked.*\n" -> "" | ||
//@ normalize-stderr: "(error: internal compiler error: [^:]+):\d+:\d+: " -> "$1:LL:CC: " | ||
//@ rustc-env:RUST_BACKTRACE=0 | ||
|
||
#![feature(pattern_types, pattern_type_macro)] | ||
#![allow(internal_features)] | ||
|
||
type Pat<const START: u32, const END: u32> = | ||
std::pat::pattern_type!(u32 is START::<(), i32, 2>..=END::<_, Assoc = ()>); | ||
//~^ ERROR type and const arguments are not allowed on const parameter `START` | ||
//~| ERROR generic arguments are not allowed on const parameter `END` | ||
//~| ERROR associated item constraints are not allowed here | ||
|
||
fn main() {} |
42 changes: 9 additions & 33 deletions
42
tests/ui/type/pattern_types/bad_const_generics_args_on_const_param.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,14 @@ | ||
error[E0109]: type and const arguments are not allowed on const parameter `START` | ||
--> $DIR/bad_const_generics_args_on_const_param.rs:5:44 | ||
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 = ()>); | ||
| ----- ^^ ^^^ ^ type and const arguments not allowed | ||
| | | ||
| not allowed on const parameter `START` | ||
| | ||
note: const parameter `START` defined here | ||
--> $DIR/bad_const_generics_args_on_const_param.rs:4:16 | ||
| | ||
LL | type Pat<const START: u32, const END: u32> = | ||
| ^^^^^ | ||
| ^^^^^^^^^^^^^^^^^^^ | ||
|
||
error[E0109]: generic arguments are not allowed on const parameter `END` | ||
--> $DIR/bad_const_generics_args_on_const_param.rs:5:64 | ||
| | ||
LL | std::pat::pattern_type!(u32 is START::<(), i32, 2>..=END::<_, Assoc = ()>); | ||
| --- ^ generic argument not allowed | ||
| | | ||
| not allowed on const parameter `END` | ||
| | ||
note: const parameter `END` defined here | ||
--> $DIR/bad_const_generics_args_on_const_param.rs:4:34 | ||
| | ||
LL | type Pat<const START: u32, const END: u32> = | ||
| ^^^ | ||
|
||
error[E0229]: associated item constraints are not allowed here | ||
--> $DIR/bad_const_generics_args_on_const_param.rs:5:67 | ||
| | ||
LL | std::pat::pattern_type!(u32 is START::<(), i32, 2>..=END::<_, Assoc = ()>); | ||
| ^^^^^^^^^^ associated item constraint not allowed here | ||
|
||
error: aborting due to 3 previous errors | ||
Box<dyn Any> | ||
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 | ||
|
||
Some errors have detailed explanations: E0109, E0229. | ||
For more information about an error, try `rustc --explain E0109`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#![feature(pattern_types)] | ||
#![feature(pattern_type_macro)] | ||
#![feature(inline_const_pat)] | ||
|
||
use std::pat::pattern_type; | ||
|
||
fn bar(x: pattern_type!(u32 is 0..=const{ 5 + 5 })) {} | ||
//~^ ERROR: cycle | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
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`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
//@ check-pass | ||
|
||
#![feature(pattern_types)] | ||
#![feature(pattern_type_macro)] | ||
|
||
use std::pat::pattern_type; | ||
|
||
const START: u32 = 0; | ||
const END: u32 = 10; | ||
|
||
fn foo(_: pattern_type!(u32 is START..=END)) {} | ||
|
||
fn main() {} |