Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit fdccb42

Browse files
committed
Add test/comment about const patterns with unused params
1 parent 217c4ad commit fdccb42

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

‎compiler/rustc_trait_selection/src/traits/mod.rs‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,12 @@ pub fn try_evaluate_const<'tcx>(
625625
// So we are free to simply defer evaluation here.
626626
//
627627
// FIXME: This assumes that `args` are normalized which is not necessarily true
628+
//
629+
// Const patterns are converted to type system constants before being
630+
// evaluated. However, we don't care about them here as pattern evaluation
631+
// logic does not go through type system normalization. If it did this would
632+
// be a backwards compatibility problem as we do not enforce "syntactic" non-
633+
// usage of generic parameters like we do here.
628634
if uv.args.has_non_region_param() || uv.args.has_non_region_infer() {
629635
return Err(EvaluateConstErr::HasGenericsOrInfers);
630636
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//@ check-pass
2+
3+
// Tests that const patterns that use generic parameters are
4+
// allowed if we are still able to evaluate them.
5+
6+
trait Trait { const ASSOC: usize; }
7+
8+
impl<T> Trait for T {
9+
const ASSOC: usize = 10;
10+
}
11+
12+
fn foo<T>(a: usize) {
13+
match a {
14+
<T as Trait>::ASSOC => (),
15+
_ => (),
16+
}
17+
}
18+
19+
fn main() {}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /