Skip to content

Commit 487cd4f

Browse files
committed
dont create unnecessary DefIds under mgca
1 parent 693f365 commit 487cd4f

File tree

4 files changed

+26
-15
lines changed

4 files changed

+26
-15
lines changed

compiler/rustc_metadata/src/rmeta/encoder.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1451,7 +1451,10 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
14511451
_ => false,
14521452
}
14531453
{
1454-
continue;
1454+
// MGCA doesn't have unnecessary DefIds
1455+
if !tcx.features().min_generic_const_args() {
1456+
continue;
1457+
}
14551458
}
14561459

14571460
if def_kind == DefKind::Field

compiler/rustc_resolve/src/def_collector.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,13 @@ impl<'a, 'ra, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'ra, 'tcx> {
357357
}
358358

359359
fn visit_anon_const(&mut self, constant: &'a AnonConst) {
360+
if let MgcaDisambiguation::Direct = constant.mgca_disambiguation
361+
&& self.resolver.tcx.features().min_generic_const_args()
362+
{
363+
visit::walk_anon_const(self, constant);
364+
return;
365+
}
366+
360367
let parent = self.create_def(constant.id, None, DefKind::AnonConst, constant.value.span);
361368
self.with_parent(parent, |this| visit::walk_anon_const(this, constant));
362369
}

tests/ui/const-generics/mgca/explicit_anon_consts.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#![feature(associated_const_equality, generic_const_items, min_generic_const_args)]
22
#![expect(incomplete_features)]
3+
// library crates exercise weirder code paths around
4+
// DefIds which were created for const args.
5+
#![crate_type = "lib"]
36

47
struct Foo<const N: usize>;
58

@@ -66,5 +69,3 @@ struct Default3<const N: usize, const M: usize = const { N }>;
6669
struct Default4<const N: usize, const M: usize = { 1 + 1 }>;
6770
//~^ ERROR: complex const arguments must be placed inside of a `const` block
6871
struct Default5<const N: usize, const M: usize = const { 1 + 1}>;
69-
70-
fn main() {}

tests/ui/const-generics/mgca/explicit_anon_consts.stderr

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: generic parameters may not be used in const operations
2-
--> $DIR/explicit_anon_consts.rs:8:41
2+
--> $DIR/explicit_anon_consts.rs:11:41
33
|
44
LL | type Adt3<const N: usize> = Foo<const { N }>;
55
| ^ cannot perform const operation using `N`
@@ -8,7 +8,7 @@ LL | type Adt3<const N: usize> = Foo<const { N }>;
88
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
99

1010
error: generic parameters may not be used in const operations
11-
--> $DIR/explicit_anon_consts.rs:16:42
11+
--> $DIR/explicit_anon_consts.rs:19:42
1212
|
1313
LL | type Arr3<const N: usize> = [(); const { N }];
1414
| ^ cannot perform const operation using `N`
@@ -17,7 +17,7 @@ LL | type Arr3<const N: usize> = [(); const { N }];
1717
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
1818

1919
error: generic parameters may not be used in const operations
20-
--> $DIR/explicit_anon_consts.rs:25:27
20+
--> $DIR/explicit_anon_consts.rs:28:27
2121
|
2222
LL | let _3 = [(); const { N }];
2323
| ^ cannot perform const operation using `N`
@@ -26,7 +26,7 @@ LL | let _3 = [(); const { N }];
2626
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
2727

2828
error: generic parameters may not be used in const operations
29-
--> $DIR/explicit_anon_consts.rs:37:46
29+
--> $DIR/explicit_anon_consts.rs:40:46
3030
|
3131
LL | const ITEM3<const N: usize>: usize = const { N };
3232
| ^ cannot perform const operation using `N`
@@ -35,7 +35,7 @@ LL | const ITEM3<const N: usize>: usize = const { N };
3535
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
3636

3737
error: generic parameters may not be used in const operations
38-
--> $DIR/explicit_anon_consts.rs:55:31
38+
--> $DIR/explicit_anon_consts.rs:58:31
3939
|
4040
LL | T3: Trait<ASSOC = const { N }>,
4141
| ^ cannot perform const operation using `N`
@@ -44,7 +44,7 @@ LL | T3: Trait<ASSOC = const { N }>,
4444
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
4545

4646
error: generic parameters may not be used in const operations
47-
--> $DIR/explicit_anon_consts.rs:64:58
47+
--> $DIR/explicit_anon_consts.rs:67:58
4848
|
4949
LL | struct Default3<const N: usize, const M: usize = const { N }>;
5050
| ^ cannot perform const operation using `N`
@@ -53,37 +53,37 @@ LL | struct Default3<const N: usize, const M: usize = const { N }>;
5353
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
5454

5555
error: complex const arguments must be placed inside of a `const` block
56-
--> $DIR/explicit_anon_consts.rs:10:33
56+
--> $DIR/explicit_anon_consts.rs:13:33
5757
|
5858
LL | type Adt4<const N: usize> = Foo<{ 1 + 1 }>;
5959
| ^^^^^^^^^
6060

6161
error: complex const arguments must be placed inside of a `const` block
62-
--> $DIR/explicit_anon_consts.rs:18:34
62+
--> $DIR/explicit_anon_consts.rs:21:34
6363
|
6464
LL | type Arr4<const N: usize> = [(); 1 + 1];
6565
| ^^^^^
6666

6767
error: complex const arguments must be placed inside of a `const` block
68-
--> $DIR/explicit_anon_consts.rs:27:19
68+
--> $DIR/explicit_anon_consts.rs:30:19
6969
|
7070
LL | let _4 = [(); 1 + 1];
7171
| ^^^^^
7272

7373
error: complex const arguments must be placed inside of a `const` block
74-
--> $DIR/explicit_anon_consts.rs:40:38
74+
--> $DIR/explicit_anon_consts.rs:43:38
7575
|
7676
LL | const ITEM4<const N: usize>: usize = { 1 + 1 };
7777
| ^^^^^^^^^
7878

7979
error: complex const arguments must be placed inside of a `const` block
80-
--> $DIR/explicit_anon_consts.rs:57:23
80+
--> $DIR/explicit_anon_consts.rs:60:23
8181
|
8282
LL | T4: Trait<ASSOC = { 1 + 1 }>,
8383
| ^^^^^^^^^
8484

8585
error: complex const arguments must be placed inside of a `const` block
86-
--> $DIR/explicit_anon_consts.rs:66:50
86+
--> $DIR/explicit_anon_consts.rs:69:50
8787
|
8888
LL | struct Default4<const N: usize, const M: usize = { 1 + 1 }>;
8989
| ^^^^^^^^^

0 commit comments

Comments
 (0)