Add test/comment about const patterns with unused params
This commit is contained in:
parent
217c4ad427
commit
fdccb42167
2 changed files with 25 additions and 0 deletions
|
|
@ -625,6 +625,12 @@ pub fn try_evaluate_const<'tcx>(
|
|||
// So we are free to simply defer evaluation here.
|
||||
//
|
||||
// FIXME: This assumes that `args` are normalized which is not necessarily true
|
||||
//
|
||||
// Const patterns are converted to type system constants before being
|
||||
// evaluated. However, we don't care about them here as pattern evaluation
|
||||
// logic does not go through type system normalization. If it did this would
|
||||
// be a backwards compatibility problem as we do not enforce "syntactic" non-
|
||||
// usage of generic parameters like we do here.
|
||||
if uv.args.has_non_region_param() || uv.args.has_non_region_infer() {
|
||||
return Err(EvaluateConstErr::HasGenericsOrInfers);
|
||||
}
|
||||
|
|
|
|||
19
tests/ui/pattern/unused-parameters-const-pattern.rs
Normal file
19
tests/ui/pattern/unused-parameters-const-pattern.rs
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
//@ check-pass
|
||||
|
||||
// Tests that const patterns that use generic parameters are
|
||||
// allowed if we are still able to evaluate them.
|
||||
|
||||
trait Trait { const ASSOC: usize; }
|
||||
|
||||
impl<T> Trait for T {
|
||||
const ASSOC: usize = 10;
|
||||
}
|
||||
|
||||
fn foo<T>(a: usize) {
|
||||
match a {
|
||||
<T as Trait>::ASSOC => (),
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
Loading…
Add table
Add a link
Reference in a new issue