Skip to content

Commit d88ad97

Browse files
committed
Disallow const params in patterns
1 parent b124dfe commit d88ad97

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

src/librustc_resolve/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -564,13 +564,14 @@ impl<'a> PathSource<'a> {
564564
Def::StructCtor(_, CtorKind::Const) | Def::StructCtor(_, CtorKind::Fn) |
565565
Def::VariantCtor(_, CtorKind::Const) | Def::VariantCtor(_, CtorKind::Fn) |
566566
Def::Const(..) | Def::Static(..) | Def::Local(..) | Def::Upvar(..) |
567-
Def::Fn(..) | Def::Method(..) | Def::AssociatedConst(..) | Def::ConstParam(..) => true,
567+
Def::Fn(..) | Def::Method(..) | Def::AssociatedConst(..)
568+
| Def::ConstParam(..) => true,
568569
_ => false,
569570
},
570571
PathSource::Pat => match def {
571572
Def::StructCtor(_, CtorKind::Const) |
572573
Def::VariantCtor(_, CtorKind::Const) |
573-
Def::Const(..) | Def::AssociatedConst(..) | Def::ConstParam(..) => true,
574+
Def::Const(..) | Def::AssociatedConst(..) => true,
574575
_ => false,
575576
},
576577
PathSource::TupleStruct => match def {
@@ -2873,15 +2874,14 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
28732874
match def {
28742875
Def::StructCtor(_, CtorKind::Const) |
28752876
Def::VariantCtor(_, CtorKind::Const) |
2876-
Def::ConstParam(..) |
28772877
Def::Const(..) if is_syntactic_ambiguity => {
28782878
// Disambiguate in favor of a unit struct/variant
28792879
// or constant pattern.
28802880
self.record_use(ident, ValueNS, binding.unwrap(), ident.span);
28812881
Some(PathResolution::new(def))
28822882
}
28832883
Def::StructCtor(..) | Def::VariantCtor(..) |
2884-
Def::ConstParam(..) | Def::Const(..) | Def::Static(..) => {
2884+
Def::Const(..) | Def::Static(..) => {
28852885
// This is unambiguously a fresh binding, either syntactically
28862886
// (e.g. `IDENT @ PAT` or `ref IDENT`) or because `IDENT` resolves
28872887
// to something unusable as a pattern (e.g. constructor function),

src/librustc_typeck/check/_match.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,6 @@ https://doc.rust-lang.org/reference/types.html#trait-objects");
754754
}
755755
Def::VariantCtor(_, CtorKind::Const) |
756756
Def::StructCtor(_, CtorKind::Const) |
757-
Def::ConstParam(..) |
758757
Def::Const(..) | Def::AssociatedConst(..) => {} // OK
759758
_ => bug!("unexpected pattern definition: {:?}", def)
760759
}

0 commit comments

Comments
 (0)