Skip to content

Commit a7752be

Browse files
committed
Fix diagnostic regression for associated const equality
Restore the "associated const equality is incomplete" error message by gating associated const equality spans with `sym::associated_const_equality` and handling them specially in feature_gate.rs to emit the correct diagnostic.
1 parent 1296fc2 commit a7752be

14 files changed

Lines changed: 36 additions & 19 deletions

File tree

compiler/rustc_ast_passes/src/feature_gate.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,23 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) {
517517
gate_all!(postfix_match, "postfix match is experimental");
518518
gate_all!(mut_ref, "mutable by-reference bindings are experimental");
519519
gate_all!(min_generic_const_args, "unbraced const blocks as const args are experimental");
520+
// associated_const_equality is stabilized as part of min_generic_const_args
521+
if let Some(spans) = spans.get(&sym::associated_const_equality) {
522+
for span in spans {
523+
if !visitor.features.min_generic_const_args()
524+
&& !span.allows_unstable(sym::min_generic_const_args)
525+
{
526+
#[allow(rustc::untranslatable_diagnostic)]
527+
feature_err(
528+
&visitor.sess,
529+
sym::min_generic_const_args,
530+
*span,
531+
"associated const equality is incomplete",
532+
)
533+
.emit();
534+
}
535+
}
536+
}
520537
gate_all!(global_registration, "global registration is experimental");
521538
gate_all!(return_type_notation, "return type notation is experimental");
522539
gate_all!(pin_ergonomics, "pinned reference syntax is experimental");

compiler/rustc_parse/src/parser/path.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,7 @@ impl<'a> Parser<'a> {
797797
let term = match arg {
798798
Some(GenericArg::Type(ty)) => ty.into(),
799799
Some(GenericArg::Const(c)) => {
800-
self.psess.gated_spans.gate(sym::min_generic_const_args, span);
800+
self.psess.gated_spans.gate(sym::associated_const_equality, span);
801801
c.into()
802802
}
803803
Some(GenericArg::Lifetime(lt)) => {

tests/ui/associated-type-bounds/issue-99828.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
fn get_iter(vec: &[i32]) -> impl Iterator<Item = {}> + '_ {
22
//~^ ERROR expected type, found constant
33
//~| ERROR expected type, found constant
4-
//~| ERROR unbraced const blocks as const args are experimental
4+
//~| ERROR associated const equality is incomplete
55
vec.iter()
66
}
77

tests/ui/associated-type-bounds/issue-99828.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0658]: unbraced const blocks as const args are experimental
1+
error[E0658]: associated const equality is incomplete
22
--> $DIR/issue-99828.rs:1:43
33
|
44
LL | fn get_iter(vec: &[i32]) -> impl Iterator<Item = {}> + '_ {

tests/ui/associated-types/associated-types-eq-2.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,15 @@ trait Tr3<const N: i32, T2, T3> {
7575
// our suggestion spans are kosher in the face of such formatting)
7676
impl Tr3<N
7777
//~^ ERROR associated item constraints are not allowed here
78-
//~| ERROR unbraced const blocks as const args are experimental
78+
//~| ERROR associated const equality is incomplete
7979
= 42, T2 = Qux, T3 = usize> for Bar {
8080
}
8181

8282
// Test for when equality constraint's ident
8383
// matches the const param's ident but has a different case
8484
impl Tr3<n = 42, T2 = Qux, T3 = usize> for Qux {
8585
//~^ ERROR associated item constraints are not allowed here
86-
//~| ERROR unbraced const blocks as const args are experimental
86+
//~| ERROR associated const equality is incomplete
8787
//~| ERROR trait takes 3 generic arguments but 0 generic arguments were supplied
8888
}
8989

@@ -97,15 +97,15 @@ impl Tr3<N = u32, T2 = Qux, T3 = usize> for Bar {
9797
// matches a type param ident but the constraint is a const arg
9898
impl Tr3<42, T2 = 42, T3 = usize> for Bar {
9999
//~^ ERROR associated item constraints are not allowed here
100-
//~| ERROR unbraced const blocks as const args are experimental
100+
//~| ERROR associated const equality is incomplete
101101
//~| ERROR trait takes 3 generic arguments but 1 generic argument was supplied
102102
}
103103

104104
// Test for when equality constraint's ident
105105
// matches none of the param idents
106106
impl Tr3<X = 42, Y = Qux, Z = usize> for Bar {
107107
//~^ ERROR associated item constraints are not allowed here
108-
//~| ERROR unbraced const blocks as const args are experimental
108+
//~| ERROR associated const equality is incomplete
109109
//~| ERROR trait takes 3 generic arguments but 0 generic arguments were supplied
110110
}
111111

tests/ui/associated-types/associated-types-eq-2.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0658]: unbraced const blocks as const args are experimental
1+
error[E0658]: associated const equality is incomplete
22
--> $DIR/associated-types-eq-2.rs:76:10
33
|
44
LL | impl Tr3<N
@@ -11,7 +11,7 @@ LL | | = 42, T2 = Qux, T3 = usize> for Bar {
1111
= help: add `#![feature(min_generic_const_args)]` to the crate attributes to enable
1212
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
1313

14-
error[E0658]: unbraced const blocks as const args are experimental
14+
error[E0658]: associated const equality is incomplete
1515
--> $DIR/associated-types-eq-2.rs:84:10
1616
|
1717
LL | impl Tr3<n = 42, T2 = Qux, T3 = usize> for Qux {
@@ -21,7 +21,7 @@ LL | impl Tr3<n = 42, T2 = Qux, T3 = usize> for Qux {
2121
= help: add `#![feature(min_generic_const_args)]` to the crate attributes to enable
2222
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
2323

24-
error[E0658]: unbraced const blocks as const args are experimental
24+
error[E0658]: associated const equality is incomplete
2525
--> $DIR/associated-types-eq-2.rs:98:14
2626
|
2727
LL | impl Tr3<42, T2 = 42, T3 = usize> for Bar {
@@ -31,7 +31,7 @@ LL | impl Tr3<42, T2 = 42, T3 = usize> for Bar {
3131
= help: add `#![feature(min_generic_const_args)]` to the crate attributes to enable
3232
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
3333

34-
error[E0658]: unbraced const blocks as const args are experimental
34+
error[E0658]: associated const equality is incomplete
3535
--> $DIR/associated-types-eq-2.rs:106:10
3636
|
3737
LL | impl Tr3<X = 42, Y = Qux, Z = usize> for Bar {

tests/ui/const-generics/parser-error-recovery/issue-89013-no-kw.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const T: usize = 42;
88

99
impl Foo<N = 3> for Bar {
1010
//~^ ERROR associated item constraints are not allowed here
11-
//~| ERROR unbraced const blocks as const args are experimental
11+
//~| ERROR associated const equality is incomplete
1212
fn do_x(&self) -> [u8; 3] {
1313
[0u8; 3]
1414
}

tests/ui/const-generics/parser-error-recovery/issue-89013-no-kw.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0658]: unbraced const blocks as const args are experimental
1+
error[E0658]: associated const equality is incomplete
22
--> $DIR/issue-89013-no-kw.rs:9:10
33
|
44
LL | impl Foo<N = 3> for Bar {

tests/ui/const-generics/parser-error-recovery/issue-89013.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const T: usize = 42;
99
impl Foo<N = const 3> for Bar {
1010
//~^ ERROR expected lifetime, type, or constant, found keyword `const`
1111
//~| ERROR associated item constraints are not allowed here
12-
//~| ERROR unbraced const blocks as const args are experimental
12+
//~| ERROR associated const equality is incomplete
1313
fn do_x(&self) -> [u8; 3] {
1414
[0u8; 3]
1515
}

tests/ui/const-generics/parser-error-recovery/issue-89013.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ LL - impl Foo<N = const 3> for Bar {
1010
LL + impl Foo<N = 3> for Bar {
1111
|
1212

13-
error[E0658]: unbraced const blocks as const args are experimental
13+
error[E0658]: associated const equality is incomplete
1414
--> $DIR/issue-89013.rs:9:10
1515
|
1616
LL | impl Foo<N = const 3> for Bar {

0 commit comments

Comments
 (0)