Commit 05dce48

Browse files
authored
Rollup merge of #150650 - enthropy7:main, r=BoxyUwU
Forbid generic parameters in types of #[type_const] items fixes#150614 we enforce the same restriction on `#[type_const]` const items that already exists for const generic parameters - when `generic_const_parameter_types` feature gate is not enabled, the type of a `#[type_const]` item cannot reference generic parameters. implementation follows the same pattern used for const generic parameters. we check if the item has the `#[type_const]` attribute and if the feature gate is disabled, then we apply `RibKind::ConstParamTy` restrictions when visiting the type, which prevents the use of generic parameters. check is added in three places: - Free const items (`ItemKind::Const`) - Trait associated consts (`AssocItemKind::Const` in traits) - Impl associated consts (`AssocItemKind::Const` in impls) added tests for new feature, hope i get this task right :> r? `@BoxyUwU`
2 parents f63ab49 + 46bb414 commit 05dce48

12 files changed

Lines changed: 228 additions & 18 deletions

‎compiler/rustc_resolve/src/late.rs‎

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2851,6 +2851,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
28512851
ref define_opaque,
28522852
..
28532853
}) => {
2854+
let is_type_const = attr::contains_name(&item.attrs, sym::type_const);
28542855
self.with_generic_param_rib(
28552856
&generics.params,
28562857
RibKind::Item(
@@ -2869,7 +2870,22 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
28692870

28702871
this.with_lifetime_rib(
28712872
LifetimeRibKind::Elided(LifetimeRes::Static),
2872-
|this| this.visit_ty(ty),
2873+
|this| {
2874+
if is_type_const
2875+
&& !this.r.tcx.features().generic_const_parameter_types()
2876+
{
2877+
this.with_rib(TypeNS,RibKind::ConstParamTy, |this| {
2878+
this.with_rib(ValueNS,RibKind::ConstParamTy, |this| {
2879+
this.with_lifetime_rib(
2880+
LifetimeRibKind::ConstParamTy,
2881+
|this| this.visit_ty(ty),
2882+
)
2883+
})
2884+
});
2885+
}else{
2886+
this.visit_ty(ty);
2887+
}
2888+
},
28732889
);
28742890

28752891
ifletSome(rhs) = rhs {
@@ -3209,6 +3225,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
32093225
define_opaque,
32103226
..
32113227
}) => {
3228+
let is_type_const = attr::contains_name(&item.attrs, sym::type_const);
32123229
self.with_generic_param_rib(
32133230
&generics.params,
32143231
RibKind::AssocItem,
@@ -3223,7 +3240,20 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
32233240
},
32243241
|this| {
32253242
this.visit_generics(generics);
3226-
this.visit_ty(ty);
3243+
if is_type_const
3244+
&& !this.r.tcx.features().generic_const_parameter_types()
3245+
{
3246+
this.with_rib(TypeNS,RibKind::ConstParamTy, |this| {
3247+
this.with_rib(ValueNS,RibKind::ConstParamTy, |this| {
3248+
this.with_lifetime_rib(
3249+
LifetimeRibKind::ConstParamTy,
3250+
|this| this.visit_ty(ty),
3251+
)
3252+
})
3253+
});
3254+
}else{
3255+
this.visit_ty(ty);
3256+
}
32273257

32283258
// Only impose the restrictions of `ConstRibKind` for an
32293259
// actual constant expression in a provided default.
@@ -3417,6 +3447,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
34173447
..
34183448
}) => {
34193449
debug!("resolve_implementation AssocItemKind::Const");
3450+
let is_type_const = attr::contains_name(&item.attrs, sym::type_const);
34203451
self.with_generic_param_rib(
34213452
&generics.params,
34223453
RibKind::AssocItem,
@@ -3453,7 +3484,28 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
34533484
);
34543485

34553486
this.visit_generics(generics);
3456-
this.visit_ty(ty);
3487+
if is_type_const
3488+
&& !this
3489+
.r
3490+
.tcx
3491+
.features()
3492+
.generic_const_parameter_types()
3493+
{
3494+
this.with_rib(TypeNS,RibKind::ConstParamTy, |this| {
3495+
this.with_rib(
3496+
ValueNS,
3497+
RibKind::ConstParamTy,
3498+
|this| {
3499+
this.with_lifetime_rib(
3500+
LifetimeRibKind::ConstParamTy,
3501+
|this| this.visit_ty(ty),
3502+
)
3503+
},
3504+
)
3505+
});
3506+
}else{
3507+
this.visit_ty(ty);
3508+
}
34573509
ifletSome(rhs) = rhs {
34583510
// We allow arbitrary const expressions inside of associated consts,
34593511
// even if they are potentially not const evaluatable.

‎tests/ui/associated-consts/assoc-const-eq-bound-var-in-ty-not-wf.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
min_generic_const_args,
66
adt_const_params,
77
unsized_const_params,
8+
generic_const_parameter_types,
89
)]
910
#![allow(incomplete_features)]
1011

‎tests/ui/associated-consts/assoc-const-eq-bound-var-in-ty-not-wf.stderr‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
error: higher-ranked subtype error
2-
--> $DIR/assoc-const-eq-bound-var-in-ty-not-wf.rs:21:13
2+
--> $DIR/assoc-const-eq-bound-var-in-ty-not-wf.rs:22:13
33
|
44
LL | K = const { () }
55
| ^^^^^^^^^^^^
66

77
error: higher-ranked subtype error
8-
--> $DIR/assoc-const-eq-bound-var-in-ty-not-wf.rs:21:13
8+
--> $DIR/assoc-const-eq-bound-var-in-ty-not-wf.rs:22:13
99
|
1010
LL | K = const { () }
1111
| ^^^^^^^^^^^^

‎tests/ui/associated-consts/assoc-const-eq-bound-var-in-ty.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
min_generic_const_args,
99
adt_const_params,
1010
unsized_const_params,
11+
generic_const_parameter_types,
1112
)]
1213
#![allow(incomplete_features)]
1314

‎tests/ui/associated-consts/assoc-const-eq-esc-bound-var-in-ty.rs‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
// Detect and reject escaping late-bound generic params in
22
// the type of assoc consts used in an equality bound.
3-
#![feature(associated_const_equality, min_generic_const_args, unsized_const_params)]
3+
#![feature(
4+
associated_const_equality,
5+
min_generic_const_args,
6+
unsized_const_params,
7+
generic_const_parameter_types,
8+
)]
49
#![allow(incomplete_features)]
510

611
traitTrait<'a>{

‎tests/ui/associated-consts/assoc-const-eq-esc-bound-var-in-ty.stderr‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: the type of the associated constant `K` cannot capture late-bound generic parameters
2-
--> $DIR/assoc-const-eq-esc-bound-var-in-ty.rs:11:35
2+
--> $DIR/assoc-const-eq-esc-bound-var-in-ty.rs:16:35
33
|
44
LL | fn take(_: impl for<'r> Trait<'r, K = const { &() }>) {}
55
| -- ^ its type cannot capture the late-bound lifetime parameter `'r`

‎tests/ui/associated-consts/assoc-const-eq-param-in-ty.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
min_generic_const_args,
66
adt_const_params,
77
unsized_const_params,
8+
generic_const_parameter_types,
89
)]
910
#![allow(incomplete_features)]
1011

‎tests/ui/associated-consts/assoc-const-eq-param-in-ty.stderr‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: the type of the associated constant `K` must not depend on generic parameters
2-
--> $DIR/assoc-const-eq-param-in-ty.rs:22:29
2+
--> $DIR/assoc-const-eq-param-in-ty.rs:23:29
33
|
44
LL | fn take0<'r, A: 'r + ConstParamTy_, const Q: usize>(
55
| -- the lifetime parameter `'r` is defined here
@@ -10,7 +10,7 @@ LL | _: impl Trait<'r, A, Q, K = const { loop {} }>
1010
= note: `K` has type `&'r [A; Q]`
1111

1212
error: the type of the associated constant `K` must not depend on generic parameters
13-
--> $DIR/assoc-const-eq-param-in-ty.rs:22:29
13+
--> $DIR/assoc-const-eq-param-in-ty.rs:23:29
1414
|
1515
LL | fn take0<'r, A: 'r + ConstParamTy_, const Q: usize>(
1616
| - the type parameter `A` is defined here
@@ -21,7 +21,7 @@ LL | _: impl Trait<'r, A, Q, K = const { loop {} }>
2121
= note: `K` has type `&'r [A; Q]`
2222

2323
error: the type of the associated constant `K` must not depend on generic parameters
24-
--> $DIR/assoc-const-eq-param-in-ty.rs:22:29
24+
--> $DIR/assoc-const-eq-param-in-ty.rs:23:29
2525
|
2626
LL | fn take0<'r, A: 'r + ConstParamTy_, const Q: usize>(
2727
| - the const parameter `Q` is defined here
@@ -32,7 +32,7 @@ LL | _: impl Trait<'r, A, Q, K = const { loop {} }>
3232
= note: `K` has type `&'r [A; Q]`
3333

3434
error: the type of the associated constant `SELF` must not depend on `impl Trait`
35-
--> $DIR/assoc-const-eq-param-in-ty.rs:39:26
35+
--> $DIR/assoc-const-eq-param-in-ty.rs:40:26
3636
|
3737
LL | fn take1(_: impl Project<SELF = const {}>) {}
3838
| -------------^^^^------------
@@ -41,7 +41,7 @@ LL | fn take1(_: impl Project<SELF = const {}>) {}
4141
| the `impl Trait` is specified here
4242

4343
error: the type of the associated constant `SELF` must not depend on generic parameters
44-
--> $DIR/assoc-const-eq-param-in-ty.rs:44:21
44+
--> $DIR/assoc-const-eq-param-in-ty.rs:45:21
4545
|
4646
LL | fn take2<P: Project<SELF = const {}>>(_: P) {}
4747
| - ^^^^ its type must not depend on the type parameter `P`
@@ -51,7 +51,7 @@ LL | fn take2<P: Project<SELF = const {}>>(_: P) {}
5151
= note: `SELF` has type `P`
5252

5353
error: the type of the associated constant `K` must not depend on generic parameters
54-
--> $DIR/assoc-const-eq-param-in-ty.rs:53:52
54+
--> $DIR/assoc-const-eq-param-in-ty.rs:54:52
5555
|
5656
LL | trait Iface<'r>: ConstParamTy_ {
5757
| -- the lifetime parameter `'r` is defined here
@@ -62,15 +62,15 @@ LL | type Assoc<const Q: usize>: Trait<'r, Self, Q, K = const { loop {} }>
6262
= note: `K` has type `&'r [Self; Q]`
6363

6464
error: the type of the associated constant `K` must not depend on `Self`
65-
--> $DIR/assoc-const-eq-param-in-ty.rs:53:52
65+
--> $DIR/assoc-const-eq-param-in-ty.rs:54:52
6666
|
6767
LL | type Assoc<const Q: usize>: Trait<'r, Self, Q, K = const { loop {} }>
6868
| ^ its type must not depend on `Self`
6969
|
7070
= note: `K` has type `&'r [Self; Q]`
7171

7272
error: the type of the associated constant `K` must not depend on generic parameters
73-
--> $DIR/assoc-const-eq-param-in-ty.rs:53:52
73+
--> $DIR/assoc-const-eq-param-in-ty.rs:54:52
7474
|
7575
LL | type Assoc<const Q: usize>: Trait<'r, Self, Q, K = const { loop {} }>
7676
| - ^ its type must not depend on the const parameter `Q`
@@ -80,7 +80,7 @@ LL | type Assoc<const Q: usize>: Trait<'r, Self, Q, K = const { loop {} }>
8080
= note: `K` has type `&'r [Self; Q]`
8181

8282
error: the type of the associated constant `K` must not depend on generic parameters
83-
--> $DIR/assoc-const-eq-param-in-ty.rs:53:52
83+
--> $DIR/assoc-const-eq-param-in-ty.rs:54:52
8484
|
8585
LL | trait Iface<'r>: ConstParamTy_ {
8686
| -- the lifetime parameter `'r` is defined here
@@ -92,7 +92,7 @@ LL | type Assoc<const Q: usize>: Trait<'r, Self, Q, K = const { loop {} }>
9292
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
9393

9494
error: the type of the associated constant `K` must not depend on `Self`
95-
--> $DIR/assoc-const-eq-param-in-ty.rs:53:52
95+
--> $DIR/assoc-const-eq-param-in-ty.rs:54:52
9696
|
9797
LL | type Assoc<const Q: usize>: Trait<'r, Self, Q, K = const { loop {} }>
9898
| ^ its type must not depend on `Self`
@@ -101,7 +101,7 @@ LL | type Assoc<const Q: usize>: Trait<'r, Self, Q, K = const { loop {} }>
101101
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
102102

103103
error: the type of the associated constant `K` must not depend on generic parameters
104-
--> $DIR/assoc-const-eq-param-in-ty.rs:53:52
104+
--> $DIR/assoc-const-eq-param-in-ty.rs:54:52
105105
|
106106
LL | type Assoc<const Q: usize>: Trait<'r, Self, Q, K = const { loop {} }>
107107
| - ^ its type must not depend on the const parameter `Q`

‎tests/ui/associated-consts/assoc-const-eq-supertraits.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
min_generic_const_args,
99
adt_const_params,
1010
unsized_const_params,
11+
generic_const_parameter_types,
1112
)]
1213
#![allow(incomplete_features)]
1314

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
error: anonymous constants referencing generics are not yet supported
2+
--> $DIR/type_const-generic-param-in-type.rs:9:53
3+
|
4+
LL | const FOO<T: core::marker::ConstParamTy_>: [T; 0] = const { [] };
5+
| ^^^^^^^^^^^^
6+
7+
error: anonymous constants referencing generics are not yet supported
8+
--> $DIR/type_const-generic-param-in-type.rs:14:38
9+
|
10+
LL | const BAR<const N: usize>: [(); N] = const { [] };
11+
| ^^^^^^^^^^^^
12+
13+
error: anonymous constants with lifetimes in their type are not yet supported
14+
--> $DIR/type_const-generic-param-in-type.rs:19:30
15+
|
16+
LL | const BAZ<'a>: [&'a (); 0] = const { [] };
17+
| ^^^^^^^^^^^^
18+
19+
error: anonymous constants referencing generics are not yet supported
20+
--> $DIR/type_const-generic-param-in-type.rs:39:59
21+
|
22+
LL | const ASSOC<T: core::marker::ConstParamTy_>: [T; 0] = const { [] };
23+
| ^^^^^^^^^^^^
24+
25+
error: anonymous constants referencing generics are not yet supported
26+
--> $DIR/type_const-generic-param-in-type.rs:44:50
27+
|
28+
LL | const ASSOC_CONST<const N: usize>: [(); N] = const { [] };
29+
| ^^^^^^^^^^^^
30+
31+
error: anonymous constants with lifetimes in their type are not yet supported
32+
--> $DIR/type_const-generic-param-in-type.rs:49:39
33+
|
34+
LL | const ASSOC_LT<'a>: [&'a (); 0] = const { [] };
35+
| ^^^^^^^^^^^^
36+
37+
error: aborting due to 6 previous errors
38+

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content

Commit 05dce48

Browse files
authored
Rollup merge of #150650 - enthropy7:main, r=BoxyUwU
Forbid generic parameters in types of #[type_const] items fixes#150614 we enforce the same restriction on `#[type_const]` const items that already exists for const generic parameters - when `generic_const_parameter_types` feature gate is not enabled, the type of a `#[type_const]` item cannot reference generic parameters. implementation follows the same pattern used for const generic parameters. we check if the item has the `#[type_const]` attribute and if the feature gate is disabled, then we apply `RibKind::ConstParamTy` restrictions when visiting the type, which prevents the use of generic parameters. check is added in three places: - Free const items (`ItemKind::Const`) - Trait associated consts (`AssocItemKind::Const` in traits) - Impl associated consts (`AssocItemKind::Const` in impls) added tests for new feature, hope i get this task right :> r? `@BoxyUwU`
2 parents f63ab49 + 46bb414 commit 05dce48

12 files changed

Lines changed: 228 additions & 18 deletions

‎compiler/rustc_resolve/src/late.rs‎

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2851,6 +2851,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
28512851
ref define_opaque,
28522852
..
28532853
}) => {
2854+
let is_type_const = attr::contains_name(&item.attrs, sym::type_const);
28542855
self.with_generic_param_rib(
28552856
&generics.params,
28562857
RibKind::Item(
@@ -2869,7 +2870,22 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
28692870

28702871
this.with_lifetime_rib(
28712872
LifetimeRibKind::Elided(LifetimeRes::Static),
2872-
|this| this.visit_ty(ty),
2873+
|this| {
2874+
if is_type_const
2875+
&& !this.r.tcx.features().generic_const_parameter_types()
2876+
{
2877+
this.with_rib(TypeNS,RibKind::ConstParamTy, |this| {
2878+
this.with_rib(ValueNS,RibKind::ConstParamTy, |this| {
2879+
this.with_lifetime_rib(
2880+
LifetimeRibKind::ConstParamTy,
2881+
|this| this.visit_ty(ty),
2882+
)
2883+
})
2884+
});
2885+
}else{
2886+
this.visit_ty(ty);
2887+
}
2888+
},
28732889
);
28742890

28752891
ifletSome(rhs) = rhs {
@@ -3209,6 +3225,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
32093225
define_opaque,
32103226
..
32113227
}) => {
3228+
let is_type_const = attr::contains_name(&item.attrs, sym::type_const);
32123229
self.with_generic_param_rib(
32133230
&generics.params,
32143231
RibKind::AssocItem,
@@ -3223,7 +3240,20 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
32233240
},
32243241
|this| {
32253242
this.visit_generics(generics);
3226-
this.visit_ty(ty);
3243+
if is_type_const
3244+
&& !this.r.tcx.features().generic_const_parameter_types()
3245+
{
3246+
this.with_rib(TypeNS,RibKind::ConstParamTy, |this| {
3247+
this.with_rib(ValueNS,RibKind::ConstParamTy, |this| {
3248+
this.with_lifetime_rib(
3249+
LifetimeRibKind::ConstParamTy,
3250+
|this| this.visit_ty(ty),
3251+
)
3252+
})
3253+
});
3254+
}else{
3255+
this.visit_ty(ty);
3256+
}
32273257

32283258
// Only impose the restrictions of `ConstRibKind` for an
32293259
// actual constant expression in a provided default.
@@ -3417,6 +3447,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
34173447
..
34183448
}) => {
34193449
debug!("resolve_implementation AssocItemKind::Const");
3450+
let is_type_const = attr::contains_name(&item.attrs, sym::type_const);
34203451
self.with_generic_param_rib(
34213452
&generics.params,
34223453
RibKind::AssocItem,
@@ -3453,7 +3484,28 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
34533484
);
34543485

34553486
this.visit_generics(generics);
3456-
this.visit_ty(ty);
3487+
if is_type_const
3488+
&& !this
3489+
.r
3490+
.tcx
3491+
.features()
3492+
.generic_const_parameter_types()
3493+
{
3494+
this.with_rib(TypeNS,RibKind::ConstParamTy, |this| {
3495+
this.with_rib(
3496+
ValueNS,
3497+
RibKind::ConstParamTy,
3498+
|this| {
3499+
this.with_lifetime_rib(
3500+
LifetimeRibKind::ConstParamTy,
3501+
|this| this.visit_ty(ty),
3502+
)
3503+
},
3504+
)
3505+
});
3506+
}else{
3507+
this.visit_ty(ty);
3508+
}
34573509
ifletSome(rhs) = rhs {
34583510
// We allow arbitrary const expressions inside of associated consts,
34593511
// even if they are potentially not const evaluatable.

‎tests/ui/associated-consts/assoc-const-eq-bound-var-in-ty-not-wf.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
min_generic_const_args,
66
adt_const_params,
77
unsized_const_params,
8+
generic_const_parameter_types,
89
)]
910
#![allow(incomplete_features)]
1011

‎tests/ui/associated-consts/assoc-const-eq-bound-var-in-ty-not-wf.stderr‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
error: higher-ranked subtype error
2-
--> $DIR/assoc-const-eq-bound-var-in-ty-not-wf.rs:21:13
2+
--> $DIR/assoc-const-eq-bound-var-in-ty-not-wf.rs:22:13
33
|
44
LL | K = const { () }
55
| ^^^^^^^^^^^^
66

77
error: higher-ranked subtype error
8-
--> $DIR/assoc-const-eq-bound-var-in-ty-not-wf.rs:21:13
8+
--> $DIR/assoc-const-eq-bound-var-in-ty-not-wf.rs:22:13
99
|
1010
LL | K = const { () }
1111
| ^^^^^^^^^^^^

‎tests/ui/associated-consts/assoc-const-eq-bound-var-in-ty.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
min_generic_const_args,
99
adt_const_params,
1010
unsized_const_params,
11+
generic_const_parameter_types,
1112
)]
1213
#![allow(incomplete_features)]
1314

‎tests/ui/associated-consts/assoc-const-eq-esc-bound-var-in-ty.rs‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
// Detect and reject escaping late-bound generic params in
22
// the type of assoc consts used in an equality bound.
3-
#![feature(associated_const_equality, min_generic_const_args, unsized_const_params)]
3+
#![feature(
4+
associated_const_equality,
5+
min_generic_const_args,
6+
unsized_const_params,
7+
generic_const_parameter_types,
8+
)]
49
#![allow(incomplete_features)]
510

611
traitTrait<'a>{

‎tests/ui/associated-consts/assoc-const-eq-esc-bound-var-in-ty.stderr‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: the type of the associated constant `K` cannot capture late-bound generic parameters
2-
--> $DIR/assoc-const-eq-esc-bound-var-in-ty.rs:11:35
2+
--> $DIR/assoc-const-eq-esc-bound-var-in-ty.rs:16:35
33
|
44
LL | fn take(_: impl for<'r> Trait<'r, K = const { &() }>) {}
55
| -- ^ its type cannot capture the late-bound lifetime parameter `'r`

‎tests/ui/associated-consts/assoc-const-eq-param-in-ty.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
min_generic_const_args,
66
adt_const_params,
77
unsized_const_params,
8+
generic_const_parameter_types,
89
)]
910
#![allow(incomplete_features)]
1011

‎tests/ui/associated-consts/assoc-const-eq-param-in-ty.stderr‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: the type of the associated constant `K` must not depend on generic parameters
2-
--> $DIR/assoc-const-eq-param-in-ty.rs:22:29
2+
--> $DIR/assoc-const-eq-param-in-ty.rs:23:29
33
|
44
LL | fn take0<'r, A: 'r + ConstParamTy_, const Q: usize>(
55
| -- the lifetime parameter `'r` is defined here
@@ -10,7 +10,7 @@ LL | _: impl Trait<'r, A, Q, K = const { loop {} }>
1010
= note: `K` has type `&'r [A; Q]`
1111

1212
error: the type of the associated constant `K` must not depend on generic parameters
13-
--> $DIR/assoc-const-eq-param-in-ty.rs:22:29
13+
--> $DIR/assoc-const-eq-param-in-ty.rs:23:29
1414
|
1515
LL | fn take0<'r, A: 'r + ConstParamTy_, const Q: usize>(
1616
| - the type parameter `A` is defined here
@@ -21,7 +21,7 @@ LL | _: impl Trait<'r, A, Q, K = const { loop {} }>
2121
= note: `K` has type `&'r [A; Q]`
2222

2323
error: the type of the associated constant `K` must not depend on generic parameters
24-
--> $DIR/assoc-const-eq-param-in-ty.rs:22:29
24+
--> $DIR/assoc-const-eq-param-in-ty.rs:23:29
2525
|
2626
LL | fn take0<'r, A: 'r + ConstParamTy_, const Q: usize>(
2727
| - the const parameter `Q` is defined here
@@ -32,7 +32,7 @@ LL | _: impl Trait<'r, A, Q, K = const { loop {} }>
3232
= note: `K` has type `&'r [A; Q]`
3333

3434
error: the type of the associated constant `SELF` must not depend on `impl Trait`
35-
--> $DIR/assoc-const-eq-param-in-ty.rs:39:26
35+
--> $DIR/assoc-const-eq-param-in-ty.rs:40:26
3636
|
3737
LL | fn take1(_: impl Project<SELF = const {}>) {}
3838
| -------------^^^^------------
@@ -41,7 +41,7 @@ LL | fn take1(_: impl Project<SELF = const {}>) {}
4141
| the `impl Trait` is specified here
4242

4343
error: the type of the associated constant `SELF` must not depend on generic parameters
44-
--> $DIR/assoc-const-eq-param-in-ty.rs:44:21
44+
--> $DIR/assoc-const-eq-param-in-ty.rs:45:21
4545
|
4646
LL | fn take2<P: Project<SELF = const {}>>(_: P) {}
4747
| - ^^^^ its type must not depend on the type parameter `P`
@@ -51,7 +51,7 @@ LL | fn take2<P: Project<SELF = const {}>>(_: P) {}
5151
= note: `SELF` has type `P`
5252

5353
error: the type of the associated constant `K` must not depend on generic parameters
54-
--> $DIR/assoc-const-eq-param-in-ty.rs:53:52
54+
--> $DIR/assoc-const-eq-param-in-ty.rs:54:52
5555
|
5656
LL | trait Iface<'r>: ConstParamTy_ {
5757
| -- the lifetime parameter `'r` is defined here
@@ -62,15 +62,15 @@ LL | type Assoc<const Q: usize>: Trait<'r, Self, Q, K = const { loop {} }>
6262
= note: `K` has type `&'r [Self; Q]`
6363

6464
error: the type of the associated constant `K` must not depend on `Self`
65-
--> $DIR/assoc-const-eq-param-in-ty.rs:53:52
65+
--> $DIR/assoc-const-eq-param-in-ty.rs:54:52
6666
|
6767
LL | type Assoc<const Q: usize>: Trait<'r, Self, Q, K = const { loop {} }>
6868
| ^ its type must not depend on `Self`
6969
|
7070
= note: `K` has type `&'r [Self; Q]`
7171

7272
error: the type of the associated constant `K` must not depend on generic parameters
73-
--> $DIR/assoc-const-eq-param-in-ty.rs:53:52
73+
--> $DIR/assoc-const-eq-param-in-ty.rs:54:52
7474
|
7575
LL | type Assoc<const Q: usize>: Trait<'r, Self, Q, K = const { loop {} }>
7676
| - ^ its type must not depend on the const parameter `Q`
@@ -80,7 +80,7 @@ LL | type Assoc<const Q: usize>: Trait<'r, Self, Q, K = const { loop {} }>
8080
= note: `K` has type `&'r [Self; Q]`
8181

8282
error: the type of the associated constant `K` must not depend on generic parameters
83-
--> $DIR/assoc-const-eq-param-in-ty.rs:53:52
83+
--> $DIR/assoc-const-eq-param-in-ty.rs:54:52
8484
|
8585
LL | trait Iface<'r>: ConstParamTy_ {
8686
| -- the lifetime parameter `'r` is defined here
@@ -92,7 +92,7 @@ LL | type Assoc<const Q: usize>: Trait<'r, Self, Q, K = const { loop {} }>
9292
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
9393

9494
error: the type of the associated constant `K` must not depend on `Self`
95-
--> $DIR/assoc-const-eq-param-in-ty.rs:53:52
95+
--> $DIR/assoc-const-eq-param-in-ty.rs:54:52
9696
|
9797
LL | type Assoc<const Q: usize>: Trait<'r, Self, Q, K = const { loop {} }>
9898
| ^ its type must not depend on `Self`
@@ -101,7 +101,7 @@ LL | type Assoc<const Q: usize>: Trait<'r, Self, Q, K = const { loop {} }>
101101
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
102102

103103
error: the type of the associated constant `K` must not depend on generic parameters
104-
--> $DIR/assoc-const-eq-param-in-ty.rs:53:52
104+
--> $DIR/assoc-const-eq-param-in-ty.rs:54:52
105105
|
106106
LL | type Assoc<const Q: usize>: Trait<'r, Self, Q, K = const { loop {} }>
107107
| - ^ its type must not depend on the const parameter `Q`

‎tests/ui/associated-consts/assoc-const-eq-supertraits.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
min_generic_const_args,
99
adt_const_params,
1010
unsized_const_params,
11+
generic_const_parameter_types,
1112
)]
1213
#![allow(incomplete_features)]
1314

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
error: anonymous constants referencing generics are not yet supported
2+
--> $DIR/type_const-generic-param-in-type.rs:9:53
3+
|
4+
LL | const FOO<T: core::marker::ConstParamTy_>: [T; 0] = const { [] };
5+
| ^^^^^^^^^^^^
6+
7+
error: anonymous constants referencing generics are not yet supported
8+
--> $DIR/type_const-generic-param-in-type.rs:14:38
9+
|
10+
LL | const BAR<const N: usize>: [(); N] = const { [] };
11+
| ^^^^^^^^^^^^
12+
13+
error: anonymous constants with lifetimes in their type are not yet supported
14+
--> $DIR/type_const-generic-param-in-type.rs:19:30
15+
|
16+
LL | const BAZ<'a>: [&'a (); 0] = const { [] };
17+
| ^^^^^^^^^^^^
18+
19+
error: anonymous constants referencing generics are not yet supported
20+
--> $DIR/type_const-generic-param-in-type.rs:39:59
21+
|
22+
LL | const ASSOC<T: core::marker::ConstParamTy_>: [T; 0] = const { [] };
23+
| ^^^^^^^^^^^^
24+
25+
error: anonymous constants referencing generics are not yet supported
26+
--> $DIR/type_const-generic-param-in-type.rs:44:50
27+
|
28+
LL | const ASSOC_CONST<const N: usize>: [(); N] = const { [] };
29+
| ^^^^^^^^^^^^
30+
31+
error: anonymous constants with lifetimes in their type are not yet supported
32+
--> $DIR/type_const-generic-param-in-type.rs:49:39
33+
|
34+
LL | const ASSOC_LT<'a>: [&'a (); 0] = const { [] };
35+
| ^^^^^^^^^^^^
36+
37+
error: aborting due to 6 previous errors
38+

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Commit 05dce48

Browse files
authored
Rollup merge of #150650 - enthropy7:main, r=BoxyUwU
Forbid generic parameters in types of #[type_const] items fixes#150614 we enforce the same restriction on `#[type_const]` const items that already exists for const generic parameters - when `generic_const_parameter_types` feature gate is not enabled, the type of a `#[type_const]` item cannot reference generic parameters. implementation follows the same pattern used for const generic parameters. we check if the item has the `#[type_const]` attribute and if the feature gate is disabled, then we apply `RibKind::ConstParamTy` restrictions when visiting the type, which prevents the use of generic parameters. check is added in three places: - Free const items (`ItemKind::Const`) - Trait associated consts (`AssocItemKind::Const` in traits) - Impl associated consts (`AssocItemKind::Const` in impls) added tests for new feature, hope i get this task right :> r? `@BoxyUwU`
2 parents f63ab49 + 46bb414 commit 05dce48

12 files changed

Lines changed: 228 additions & 18 deletions

‎compiler/rustc_resolve/src/late.rs‎

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2851,6 +2851,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
28512851
ref define_opaque,
28522852
..
28532853
}) => {
2854+
let is_type_const = attr::contains_name(&item.attrs, sym::type_const);
28542855
self.with_generic_param_rib(
28552856
&generics.params,
28562857
RibKind::Item(
@@ -2869,7 +2870,22 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
28692870

28702871
this.with_lifetime_rib(
28712872
LifetimeRibKind::Elided(LifetimeRes::Static),
2872-
|this| this.visit_ty(ty),
2873+
|this| {
2874+
if is_type_const
2875+
&& !this.r.tcx.features().generic_const_parameter_types()
2876+
{
2877+
this.with_rib(TypeNS,RibKind::ConstParamTy, |this| {
2878+
this.with_rib(ValueNS,RibKind::ConstParamTy, |this| {
2879+
this.with_lifetime_rib(
2880+
LifetimeRibKind::ConstParamTy,
2881+
|this| this.visit_ty(ty),
2882+
)
2883+
})
2884+
});
2885+
}else{
2886+
this.visit_ty(ty);
2887+
}
2888+
},
28732889
);
28742890

28752891
ifletSome(rhs) = rhs {
@@ -3209,6 +3225,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
32093225
define_opaque,
32103226
..
32113227
}) => {
3228+
let is_type_const = attr::contains_name(&item.attrs, sym::type_const);
32123229
self.with_generic_param_rib(
32133230
&generics.params,
32143231
RibKind::AssocItem,
@@ -3223,7 +3240,20 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
32233240
},
32243241
|this| {
32253242
this.visit_generics(generics);
3226-
this.visit_ty(ty);
3243+
if is_type_const
3244+
&& !this.r.tcx.features().generic_const_parameter_types()
3245+
{
3246+
this.with_rib(TypeNS,RibKind::ConstParamTy, |this| {
3247+
this.with_rib(ValueNS,RibKind::ConstParamTy, |this| {
3248+
this.with_lifetime_rib(
3249+
LifetimeRibKind::ConstParamTy,
3250+
|this| this.visit_ty(ty),
3251+
)
3252+
})
3253+
});
3254+
}else{
3255+
this.visit_ty(ty);
3256+
}
32273257

32283258
// Only impose the restrictions of `ConstRibKind` for an
32293259
// actual constant expression in a provided default.
@@ -3417,6 +3447,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
34173447
..
34183448
}) => {
34193449
debug!("resolve_implementation AssocItemKind::Const");
3450+
let is_type_const = attr::contains_name(&item.attrs, sym::type_const);
34203451
self.with_generic_param_rib(
34213452
&generics.params,
34223453
RibKind::AssocItem,
@@ -3453,7 +3484,28 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
34533484
);
34543485

34553486
this.visit_generics(generics);
3456-
this.visit_ty(ty);
3487+
if is_type_const
3488+
&& !this
3489+
.r
3490+
.tcx
3491+
.features()
3492+
.generic_const_parameter_types()
3493+
{
3494+
this.with_rib(TypeNS,RibKind::ConstParamTy, |this| {
3495+
this.with_rib(
3496+
ValueNS,
3497+
RibKind::ConstParamTy,
3498+
|this| {
3499+
this.with_lifetime_rib(
3500+
LifetimeRibKind::ConstParamTy,
3501+
|this| this.visit_ty(ty),
3502+
)
3503+
},
3504+
)
3505+
});
3506+
}else{
3507+
this.visit_ty(ty);
3508+
}
34573509
ifletSome(rhs) = rhs {
34583510
// We allow arbitrary const expressions inside of associated consts,
34593511
// even if they are potentially not const evaluatable.

‎tests/ui/associated-consts/assoc-const-eq-bound-var-in-ty-not-wf.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
min_generic_const_args,
66
adt_const_params,
77
unsized_const_params,
8+
generic_const_parameter_types,
89
)]
910
#![allow(incomplete_features)]
1011

‎tests/ui/associated-consts/assoc-const-eq-bound-var-in-ty-not-wf.stderr‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
error: higher-ranked subtype error
2-
--> $DIR/assoc-const-eq-bound-var-in-ty-not-wf.rs:21:13
2+
--> $DIR/assoc-const-eq-bound-var-in-ty-not-wf.rs:22:13
33
|
44
LL | K = const { () }
55
| ^^^^^^^^^^^^
66

77
error: higher-ranked subtype error
8-
--> $DIR/assoc-const-eq-bound-var-in-ty-not-wf.rs:21:13
8+
--> $DIR/assoc-const-eq-bound-var-in-ty-not-wf.rs:22:13
99
|
1010
LL | K = const { () }
1111
| ^^^^^^^^^^^^

‎tests/ui/associated-consts/assoc-const-eq-bound-var-in-ty.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
min_generic_const_args,
99
adt_const_params,
1010
unsized_const_params,
11+
generic_const_parameter_types,
1112
)]
1213
#![allow(incomplete_features)]
1314

‎tests/ui/associated-consts/assoc-const-eq-esc-bound-var-in-ty.rs‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
// Detect and reject escaping late-bound generic params in
22
// the type of assoc consts used in an equality bound.
3-
#![feature(associated_const_equality, min_generic_const_args, unsized_const_params)]
3+
#![feature(
4+
associated_const_equality,
5+
min_generic_const_args,
6+
unsized_const_params,
7+
generic_const_parameter_types,
8+
)]
49
#![allow(incomplete_features)]
510

611
traitTrait<'a>{

‎tests/ui/associated-consts/assoc-const-eq-esc-bound-var-in-ty.stderr‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: the type of the associated constant `K` cannot capture late-bound generic parameters
2-
--> $DIR/assoc-const-eq-esc-bound-var-in-ty.rs:11:35
2+
--> $DIR/assoc-const-eq-esc-bound-var-in-ty.rs:16:35
33
|
44
LL | fn take(_: impl for<'r> Trait<'r, K = const { &() }>) {}
55
| -- ^ its type cannot capture the late-bound lifetime parameter `'r`

‎tests/ui/associated-consts/assoc-const-eq-param-in-ty.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
min_generic_const_args,
66
adt_const_params,
77
unsized_const_params,
8+
generic_const_parameter_types,
89
)]
910
#![allow(incomplete_features)]
1011

‎tests/ui/associated-consts/assoc-const-eq-param-in-ty.stderr‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: the type of the associated constant `K` must not depend on generic parameters
2-
--> $DIR/assoc-const-eq-param-in-ty.rs:22:29
2+
--> $DIR/assoc-const-eq-param-in-ty.rs:23:29
33
|
44
LL | fn take0<'r, A: 'r + ConstParamTy_, const Q: usize>(
55
| -- the lifetime parameter `'r` is defined here
@@ -10,7 +10,7 @@ LL | _: impl Trait<'r, A, Q, K = const { loop {} }>
1010
= note: `K` has type `&'r [A; Q]`
1111

1212
error: the type of the associated constant `K` must not depend on generic parameters
13-
--> $DIR/assoc-const-eq-param-in-ty.rs:22:29
13+
--> $DIR/assoc-const-eq-param-in-ty.rs:23:29
1414
|
1515
LL | fn take0<'r, A: 'r + ConstParamTy_, const Q: usize>(
1616
| - the type parameter `A` is defined here
@@ -21,7 +21,7 @@ LL | _: impl Trait<'r, A, Q, K = const { loop {} }>
2121
= note: `K` has type `&'r [A; Q]`
2222

2323
error: the type of the associated constant `K` must not depend on generic parameters
24-
--> $DIR/assoc-const-eq-param-in-ty.rs:22:29
24+
--> $DIR/assoc-const-eq-param-in-ty.rs:23:29
2525
|
2626
LL | fn take0<'r, A: 'r + ConstParamTy_, const Q: usize>(
2727
| - the const parameter `Q` is defined here
@@ -32,7 +32,7 @@ LL | _: impl Trait<'r, A, Q, K = const { loop {} }>
3232
= note: `K` has type `&'r [A; Q]`
3333

3434
error: the type of the associated constant `SELF` must not depend on `impl Trait`
35-
--> $DIR/assoc-const-eq-param-in-ty.rs:39:26
35+
--> $DIR/assoc-const-eq-param-in-ty.rs:40:26
3636
|
3737
LL | fn take1(_: impl Project<SELF = const {}>) {}
3838
| -------------^^^^------------
@@ -41,7 +41,7 @@ LL | fn take1(_: impl Project<SELF = const {}>) {}
4141
| the `impl Trait` is specified here
4242

4343
error: the type of the associated constant `SELF` must not depend on generic parameters
44-
--> $DIR/assoc-const-eq-param-in-ty.rs:44:21
44+
--> $DIR/assoc-const-eq-param-in-ty.rs:45:21
4545
|
4646
LL | fn take2<P: Project<SELF = const {}>>(_: P) {}
4747
| - ^^^^ its type must not depend on the type parameter `P`
@@ -51,7 +51,7 @@ LL | fn take2<P: Project<SELF = const {}>>(_: P) {}
5151
= note: `SELF` has type `P`
5252

5353
error: the type of the associated constant `K` must not depend on generic parameters
54-
--> $DIR/assoc-const-eq-param-in-ty.rs:53:52
54+
--> $DIR/assoc-const-eq-param-in-ty.rs:54:52
5555
|
5656
LL | trait Iface<'r>: ConstParamTy_ {
5757
| -- the lifetime parameter `'r` is defined here
@@ -62,15 +62,15 @@ LL | type Assoc<const Q: usize>: Trait<'r, Self, Q, K = const { loop {} }>
6262
= note: `K` has type `&'r [Self; Q]`
6363

6464
error: the type of the associated constant `K` must not depend on `Self`
65-
--> $DIR/assoc-const-eq-param-in-ty.rs:53:52
65+
--> $DIR/assoc-const-eq-param-in-ty.rs:54:52
6666
|
6767
LL | type Assoc<const Q: usize>: Trait<'r, Self, Q, K = const { loop {} }>
6868
| ^ its type must not depend on `Self`
6969
|
7070
= note: `K` has type `&'r [Self; Q]`
7171

7272
error: the type of the associated constant `K` must not depend on generic parameters
73-
--> $DIR/assoc-const-eq-param-in-ty.rs:53:52
73+
--> $DIR/assoc-const-eq-param-in-ty.rs:54:52
7474
|
7575
LL | type Assoc<const Q: usize>: Trait<'r, Self, Q, K = const { loop {} }>
7676
| - ^ its type must not depend on the const parameter `Q`
@@ -80,7 +80,7 @@ LL | type Assoc<const Q: usize>: Trait<'r, Self, Q, K = const { loop {} }>
8080
= note: `K` has type `&'r [Self; Q]`
8181

8282
error: the type of the associated constant `K` must not depend on generic parameters
83-
--> $DIR/assoc-const-eq-param-in-ty.rs:53:52
83+
--> $DIR/assoc-const-eq-param-in-ty.rs:54:52
8484
|
8585
LL | trait Iface<'r>: ConstParamTy_ {
8686
| -- the lifetime parameter `'r` is defined here
@@ -92,7 +92,7 @@ LL | type Assoc<const Q: usize>: Trait<'r, Self, Q, K = const { loop {} }>
9292
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
9393

9494
error: the type of the associated constant `K` must not depend on `Self`
95-
--> $DIR/assoc-const-eq-param-in-ty.rs:53:52
95+
--> $DIR/assoc-const-eq-param-in-ty.rs:54:52
9696
|
9797
LL | type Assoc<const Q: usize>: Trait<'r, Self, Q, K = const { loop {} }>
9898
| ^ its type must not depend on `Self`
@@ -101,7 +101,7 @@ LL | type Assoc<const Q: usize>: Trait<'r, Self, Q, K = const { loop {} }>
101101
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
102102

103103
error: the type of the associated constant `K` must not depend on generic parameters
104-
--> $DIR/assoc-const-eq-param-in-ty.rs:53:52
104+
--> $DIR/assoc-const-eq-param-in-ty.rs:54:52
105105
|
106106
LL | type Assoc<const Q: usize>: Trait<'r, Self, Q, K = const { loop {} }>
107107
| - ^ its type must not depend on the const parameter `Q`

‎tests/ui/associated-consts/assoc-const-eq-supertraits.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
min_generic_const_args,
99
adt_const_params,
1010
unsized_const_params,
11+
generic_const_parameter_types,
1112
)]
1213
#![allow(incomplete_features)]
1314

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
error: anonymous constants referencing generics are not yet supported
2+
--> $DIR/type_const-generic-param-in-type.rs:9:53
3+
|
4+
LL | const FOO<T: core::marker::ConstParamTy_>: [T; 0] = const { [] };
5+
| ^^^^^^^^^^^^
6+
7+
error: anonymous constants referencing generics are not yet supported
8+
--> $DIR/type_const-generic-param-in-type.rs:14:38
9+
|
10+
LL | const BAR<const N: usize>: [(); N] = const { [] };
11+
| ^^^^^^^^^^^^
12+
13+
error: anonymous constants with lifetimes in their type are not yet supported
14+
--> $DIR/type_const-generic-param-in-type.rs:19:30
15+
|
16+
LL | const BAZ<'a>: [&'a (); 0] = const { [] };
17+
| ^^^^^^^^^^^^
18+
19+
error: anonymous constants referencing generics are not yet supported
20+
--> $DIR/type_const-generic-param-in-type.rs:39:59
21+
|
22+
LL | const ASSOC<T: core::marker::ConstParamTy_>: [T; 0] = const { [] };
23+
| ^^^^^^^^^^^^
24+
25+
error: anonymous constants referencing generics are not yet supported
26+
--> $DIR/type_const-generic-param-in-type.rs:44:50
27+
|
28+
LL | const ASSOC_CONST<const N: usize>: [(); N] = const { [] };
29+
| ^^^^^^^^^^^^
30+
31+
error: anonymous constants with lifetimes in their type are not yet supported
32+
--> $DIR/type_const-generic-param-in-type.rs:49:39
33+
|
34+
LL | const ASSOC_LT<'a>: [&'a (); 0] = const { [] };
35+
| ^^^^^^^^^^^^
36+
37+
error: aborting due to 6 previous errors
38+

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Commit 05dce48

Browse files
authored
Rollup merge of #150650 - enthropy7:main, r=BoxyUwU
Forbid generic parameters in types of #[type_const] items fixes#150614 we enforce the same restriction on `#[type_const]` const items that already exists for const generic parameters - when `generic_const_parameter_types` feature gate is not enabled, the type of a `#[type_const]` item cannot reference generic parameters. implementation follows the same pattern used for const generic parameters. we check if the item has the `#[type_const]` attribute and if the feature gate is disabled, then we apply `RibKind::ConstParamTy` restrictions when visiting the type, which prevents the use of generic parameters. check is added in three places: - Free const items (`ItemKind::Const`) - Trait associated consts (`AssocItemKind::Const` in traits) - Impl associated consts (`AssocItemKind::Const` in impls) added tests for new feature, hope i get this task right :> r? `@BoxyUwU`
2 parents f63ab49 + 46bb414 commit 05dce48

12 files changed

Lines changed: 228 additions & 18 deletions

‎compiler/rustc_resolve/src/late.rs‎

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2851,6 +2851,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
28512851
ref define_opaque,
28522852
..
28532853
}) => {
2854+
let is_type_const = attr::contains_name(&item.attrs, sym::type_const);
28542855
self.with_generic_param_rib(
28552856
&generics.params,
28562857
RibKind::Item(
@@ -2869,7 +2870,22 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
28692870

28702871
this.with_lifetime_rib(
28712872
LifetimeRibKind::Elided(LifetimeRes::Static),
2872-
|this| this.visit_ty(ty),
2873+
|this| {
2874+
if is_type_const
2875+
&& !this.r.tcx.features().generic_const_parameter_types()
2876+
{
2877+
this.with_rib(TypeNS,RibKind::ConstParamTy, |this| {
2878+
this.with_rib(ValueNS,RibKind::ConstParamTy, |this| {
2879+
this.with_lifetime_rib(
2880+
LifetimeRibKind::ConstParamTy,
2881+
|this| this.visit_ty(ty),
2882+
)
2883+
})
2884+
});
2885+
}else{
2886+
this.visit_ty(ty);
2887+
}
2888+
},
28732889
);
28742890

28752891
ifletSome(rhs) = rhs {
@@ -3209,6 +3225,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
32093225
define_opaque,
32103226
..
32113227
}) => {
3228+
let is_type_const = attr::contains_name(&item.attrs, sym::type_const);
32123229
self.with_generic_param_rib(
32133230
&generics.params,
32143231
RibKind::AssocItem,
@@ -3223,7 +3240,20 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
32233240
},
32243241
|this| {
32253242
this.visit_generics(generics);
3226-
this.visit_ty(ty);
3243+
if is_type_const
3244+
&& !this.r.tcx.features().generic_const_parameter_types()
3245+
{
3246+
this.with_rib(TypeNS,RibKind::ConstParamTy, |this| {
3247+
this.with_rib(ValueNS,RibKind::ConstParamTy, |this| {
3248+
this.with_lifetime_rib(
3249+
LifetimeRibKind::ConstParamTy,
3250+
|this| this.visit_ty(ty),
3251+
)
3252+
})
3253+
});
3254+
}else{
3255+
this.visit_ty(ty);
3256+
}
32273257

32283258
// Only impose the restrictions of `ConstRibKind` for an
32293259
// actual constant expression in a provided default.
@@ -3417,6 +3447,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
34173447
..
34183448
}) => {
34193449
debug!("resolve_implementation AssocItemKind::Const");
3450+
let is_type_const = attr::contains_name(&item.attrs, sym::type_const);
34203451
self.with_generic_param_rib(
34213452
&generics.params,
34223453
RibKind::AssocItem,
@@ -3453,7 +3484,28 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
34533484
);
34543485

34553486
this.visit_generics(generics);
3456-
this.visit_ty(ty);
3487+
if is_type_const
3488+
&& !this
3489+
.r
3490+
.tcx
3491+
.features()
3492+
.generic_const_parameter_types()
3493+
{
3494+
this.with_rib(TypeNS,RibKind::ConstParamTy, |this| {
3495+
this.with_rib(
3496+
ValueNS,
3497+
RibKind::ConstParamTy,
3498+
|this| {
3499+
this.with_lifetime_rib(
3500+
LifetimeRibKind::ConstParamTy,
3501+
|this| this.visit_ty(ty),
3502+
)
3503+
},
3504+
)
3505+
});
3506+
}else{
3507+
this.visit_ty(ty);
3508+
}
34573509
ifletSome(rhs) = rhs {
34583510
// We allow arbitrary const expressions inside of associated consts,
34593511
// even if they are potentially not const evaluatable.

‎tests/ui/associated-consts/assoc-const-eq-bound-var-in-ty-not-wf.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
min_generic_const_args,
66
adt_const_params,
77
unsized_const_params,
8+
generic_const_parameter_types,
89
)]
910
#![allow(incomplete_features)]
1011

‎tests/ui/associated-consts/assoc-const-eq-bound-var-in-ty-not-wf.stderr‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
error: higher-ranked subtype error
2-
--> $DIR/assoc-const-eq-bound-var-in-ty-not-wf.rs:21:13
2+
--> $DIR/assoc-const-eq-bound-var-in-ty-not-wf.rs:22:13
33
|
44
LL | K = const { () }
55
| ^^^^^^^^^^^^
66

77
error: higher-ranked subtype error
8-
--> $DIR/assoc-const-eq-bound-var-in-ty-not-wf.rs:21:13
8+
--> $DIR/assoc-const-eq-bound-var-in-ty-not-wf.rs:22:13
99
|
1010
LL | K = const { () }
1111
| ^^^^^^^^^^^^

‎tests/ui/associated-consts/assoc-const-eq-bound-var-in-ty.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
min_generic_const_args,
99
adt_const_params,
1010
unsized_const_params,
11+
generic_const_parameter_types,
1112
)]
1213
#![allow(incomplete_features)]
1314

‎tests/ui/associated-consts/assoc-const-eq-esc-bound-var-in-ty.rs‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
// Detect and reject escaping late-bound generic params in
22
// the type of assoc consts used in an equality bound.
3-
#![feature(associated_const_equality, min_generic_const_args, unsized_const_params)]
3+
#![feature(
4+
associated_const_equality,
5+
min_generic_const_args,
6+
unsized_const_params,
7+
generic_const_parameter_types,
8+
)]
49
#![allow(incomplete_features)]
510

611
traitTrait<'a>{

‎tests/ui/associated-consts/assoc-const-eq-esc-bound-var-in-ty.stderr‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: the type of the associated constant `K` cannot capture late-bound generic parameters
2-
--> $DIR/assoc-const-eq-esc-bound-var-in-ty.rs:11:35
2+
--> $DIR/assoc-const-eq-esc-bound-var-in-ty.rs:16:35
33
|
44
LL | fn take(_: impl for<'r> Trait<'r, K = const { &() }>) {}
55
| -- ^ its type cannot capture the late-bound lifetime parameter `'r`

‎tests/ui/associated-consts/assoc-const-eq-param-in-ty.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
min_generic_const_args,
66
adt_const_params,
77
unsized_const_params,
8+
generic_const_parameter_types,
89
)]
910
#![allow(incomplete_features)]
1011

‎tests/ui/associated-consts/assoc-const-eq-param-in-ty.stderr‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: the type of the associated constant `K` must not depend on generic parameters
2-
--> $DIR/assoc-const-eq-param-in-ty.rs:22:29
2+
--> $DIR/assoc-const-eq-param-in-ty.rs:23:29
33
|
44
LL | fn take0<'r, A: 'r + ConstParamTy_, const Q: usize>(
55
| -- the lifetime parameter `'r` is defined here
@@ -10,7 +10,7 @@ LL | _: impl Trait<'r, A, Q, K = const { loop {} }>
1010
= note: `K` has type `&'r [A; Q]`
1111

1212
error: the type of the associated constant `K` must not depend on generic parameters
13-
--> $DIR/assoc-const-eq-param-in-ty.rs:22:29
13+
--> $DIR/assoc-const-eq-param-in-ty.rs:23:29
1414
|
1515
LL | fn take0<'r, A: 'r + ConstParamTy_, const Q: usize>(
1616
| - the type parameter `A` is defined here
@@ -21,7 +21,7 @@ LL | _: impl Trait<'r, A, Q, K = const { loop {} }>
2121
= note: `K` has type `&'r [A; Q]`
2222

2323
error: the type of the associated constant `K` must not depend on generic parameters
24-
--> $DIR/assoc-const-eq-param-in-ty.rs:22:29
24+
--> $DIR/assoc-const-eq-param-in-ty.rs:23:29
2525
|
2626
LL | fn take0<'r, A: 'r + ConstParamTy_, const Q: usize>(
2727
| - the const parameter `Q` is defined here
@@ -32,7 +32,7 @@ LL | _: impl Trait<'r, A, Q, K = const { loop {} }>
3232
= note: `K` has type `&'r [A; Q]`
3333

3434
error: the type of the associated constant `SELF` must not depend on `impl Trait`
35-
--> $DIR/assoc-const-eq-param-in-ty.rs:39:26
35+
--> $DIR/assoc-const-eq-param-in-ty.rs:40:26
3636
|
3737
LL | fn take1(_: impl Project<SELF = const {}>) {}
3838
| -------------^^^^------------
@@ -41,7 +41,7 @@ LL | fn take1(_: impl Project<SELF = const {}>) {}
4141
| the `impl Trait` is specified here
4242

4343
error: the type of the associated constant `SELF` must not depend on generic parameters
44-
--> $DIR/assoc-const-eq-param-in-ty.rs:44:21
44+
--> $DIR/assoc-const-eq-param-in-ty.rs:45:21
4545
|
4646
LL | fn take2<P: Project<SELF = const {}>>(_: P) {}
4747
| - ^^^^ its type must not depend on the type parameter `P`
@@ -51,7 +51,7 @@ LL | fn take2<P: Project<SELF = const {}>>(_: P) {}
5151
= note: `SELF` has type `P`
5252

5353
error: the type of the associated constant `K` must not depend on generic parameters
54-
--> $DIR/assoc-const-eq-param-in-ty.rs:53:52
54+
--> $DIR/assoc-const-eq-param-in-ty.rs:54:52
5555
|
5656
LL | trait Iface<'r>: ConstParamTy_ {
5757
| -- the lifetime parameter `'r` is defined here
@@ -62,15 +62,15 @@ LL | type Assoc<const Q: usize>: Trait<'r, Self, Q, K = const { loop {} }>
6262
= note: `K` has type `&'r [Self; Q]`
6363

6464
error: the type of the associated constant `K` must not depend on `Self`
65-
--> $DIR/assoc-const-eq-param-in-ty.rs:53:52
65+
--> $DIR/assoc-const-eq-param-in-ty.rs:54:52
6666
|
6767
LL | type Assoc<const Q: usize>: Trait<'r, Self, Q, K = const { loop {} }>
6868
| ^ its type must not depend on `Self`
6969
|
7070
= note: `K` has type `&'r [Self; Q]`
7171

7272
error: the type of the associated constant `K` must not depend on generic parameters
73-
--> $DIR/assoc-const-eq-param-in-ty.rs:53:52
73+
--> $DIR/assoc-const-eq-param-in-ty.rs:54:52
7474
|
7575
LL | type Assoc<const Q: usize>: Trait<'r, Self, Q, K = const { loop {} }>
7676
| - ^ its type must not depend on the const parameter `Q`
@@ -80,7 +80,7 @@ LL | type Assoc<const Q: usize>: Trait<'r, Self, Q, K = const { loop {} }>
8080
= note: `K` has type `&'r [Self; Q]`
8181

8282
error: the type of the associated constant `K` must not depend on generic parameters
83-
--> $DIR/assoc-const-eq-param-in-ty.rs:53:52
83+
--> $DIR/assoc-const-eq-param-in-ty.rs:54:52
8484
|
8585
LL | trait Iface<'r>: ConstParamTy_ {
8686
| -- the lifetime parameter `'r` is defined here
@@ -92,7 +92,7 @@ LL | type Assoc<const Q: usize>: Trait<'r, Self, Q, K = const { loop {} }>
9292
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
9393

9494
error: the type of the associated constant `K` must not depend on `Self`
95-
--> $DIR/assoc-const-eq-param-in-ty.rs:53:52
95+
--> $DIR/assoc-const-eq-param-in-ty.rs:54:52
9696
|
9797
LL | type Assoc<const Q: usize>: Trait<'r, Self, Q, K = const { loop {} }>
9898
| ^ its type must not depend on `Self`
@@ -101,7 +101,7 @@ LL | type Assoc<const Q: usize>: Trait<'r, Self, Q, K = const { loop {} }>
101101
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
102102

103103
error: the type of the associated constant `K` must not depend on generic parameters
104-
--> $DIR/assoc-const-eq-param-in-ty.rs:53:52
104+
--> $DIR/assoc-const-eq-param-in-ty.rs:54:52
105105
|
106106
LL | type Assoc<const Q: usize>: Trait<'r, Self, Q, K = const { loop {} }>
107107
| - ^ its type must not depend on the const parameter `Q`

‎tests/ui/associated-consts/assoc-const-eq-supertraits.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
min_generic_const_args,
99
adt_const_params,
1010
unsized_const_params,
11+
generic_const_parameter_types,
1112
)]
1213
#![allow(incomplete_features)]
1314

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
error: anonymous constants referencing generics are not yet supported
2+
--> $DIR/type_const-generic-param-in-type.rs:9:53
3+
|
4+
LL | const FOO<T: core::marker::ConstParamTy_>: [T; 0] = const { [] };
5+
| ^^^^^^^^^^^^
6+
7+
error: anonymous constants referencing generics are not yet supported
8+
--> $DIR/type_const-generic-param-in-type.rs:14:38
9+
|
10+
LL | const BAR<const N: usize>: [(); N] = const { [] };
11+
| ^^^^^^^^^^^^
12+
13+
error: anonymous constants with lifetimes in their type are not yet supported
14+
--> $DIR/type_const-generic-param-in-type.rs:19:30
15+
|
16+
LL | const BAZ<'a>: [&'a (); 0] = const { [] };
17+
| ^^^^^^^^^^^^
18+
19+
error: anonymous constants referencing generics are not yet supported
20+
--> $DIR/type_const-generic-param-in-type.rs:39:59
21+
|
22+
LL | const ASSOC<T: core::marker::ConstParamTy_>: [T; 0] = const { [] };
23+
| ^^^^^^^^^^^^
24+
25+
error: anonymous constants referencing generics are not yet supported
26+
--> $DIR/type_const-generic-param-in-type.rs:44:50
27+
|
28+
LL | const ASSOC_CONST<const N: usize>: [(); N] = const { [] };
29+
| ^^^^^^^^^^^^
30+
31+
error: anonymous constants with lifetimes in their type are not yet supported
32+
--> $DIR/type_const-generic-param-in-type.rs:49:39
33+
|
34+
LL | const ASSOC_LT<'a>: [&'a (); 0] = const { [] };
35+
| ^^^^^^^^^^^^
36+
37+
error: aborting due to 6 previous errors
38+

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content

Commit 05dce48

Browse files
authored
Rollup merge of #150650 - enthropy7:main, r=BoxyUwU
Forbid generic parameters in types of #[type_const] items fixes#150614 we enforce the same restriction on `#[type_const]` const items that already exists for const generic parameters - when `generic_const_parameter_types` feature gate is not enabled, the type of a `#[type_const]` item cannot reference generic parameters. implementation follows the same pattern used for const generic parameters. we check if the item has the `#[type_const]` attribute and if the feature gate is disabled, then we apply `RibKind::ConstParamTy` restrictions when visiting the type, which prevents the use of generic parameters. check is added in three places: - Free const items (`ItemKind::Const`) - Trait associated consts (`AssocItemKind::Const` in traits) - Impl associated consts (`AssocItemKind::Const` in impls) added tests for new feature, hope i get this task right :> r? `@BoxyUwU`
2 parents f63ab49 + 46bb414 commit 05dce48

12 files changed

Lines changed: 228 additions & 18 deletions

‎compiler/rustc_resolve/src/late.rs‎

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2851,6 +2851,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
28512851
ref define_opaque,
28522852
..
28532853
}) => {
2854+
let is_type_const = attr::contains_name(&item.attrs, sym::type_const);
28542855
self.with_generic_param_rib(
28552856
&generics.params,
28562857
RibKind::Item(
@@ -2869,7 +2870,22 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
28692870

28702871
this.with_lifetime_rib(
28712872
LifetimeRibKind::Elided(LifetimeRes::Static),
2872-
|this| this.visit_ty(ty),
2873+
|this| {
2874+
if is_type_const
2875+
&& !this.r.tcx.features().generic_const_parameter_types()
2876+
{
2877+
this.with_rib(TypeNS,RibKind::ConstParamTy, |this| {
2878+
this.with_rib(ValueNS,RibKind::ConstParamTy, |this| {
2879+
this.with_lifetime_rib(
2880+
LifetimeRibKind::ConstParamTy,
2881+
|this| this.visit_ty(ty),
2882+
)
2883+
})
2884+
});
2885+
}else{
2886+
this.visit_ty(ty);
2887+
}
2888+
},
28732889
);
28742890

28752891
ifletSome(rhs) = rhs {
@@ -3209,6 +3225,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
32093225
define_opaque,
32103226
..
32113227
}) => {
3228+
let is_type_const = attr::contains_name(&item.attrs, sym::type_const);
32123229
self.with_generic_param_rib(
32133230
&generics.params,
32143231
RibKind::AssocItem,
@@ -3223,7 +3240,20 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
32233240
},
32243241
|this| {
32253242
this.visit_generics(generics);
3226-
this.visit_ty(ty);
3243+
if is_type_const
3244+
&& !this.r.tcx.features().generic_const_parameter_types()
3245+
{
3246+
this.with_rib(TypeNS,RibKind::ConstParamTy, |this| {
3247+
this.with_rib(ValueNS,RibKind::ConstParamTy, |this| {
3248+
this.with_lifetime_rib(
3249+
LifetimeRibKind::ConstParamTy,
3250+
|this| this.visit_ty(ty),
3251+
)
3252+
})
3253+
});
3254+
}else{
3255+
this.visit_ty(ty);
3256+
}
32273257

32283258
// Only impose the restrictions of `ConstRibKind` for an
32293259
// actual constant expression in a provided default.
@@ -3417,6 +3447,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
34173447
..
34183448
}) => {
34193449
debug!("resolve_implementation AssocItemKind::Const");
3450+
let is_type_const = attr::contains_name(&item.attrs, sym::type_const);
34203451
self.with_generic_param_rib(
34213452
&generics.params,
34223453
RibKind::AssocItem,
@@ -3453,7 +3484,28 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
34533484
);
34543485

34553486
this.visit_generics(generics);
3456-
this.visit_ty(ty);
3487+
if is_type_const
3488+
&& !this
3489+
.r
3490+
.tcx
3491+
.features()
3492+
.generic_const_parameter_types()
3493+
{
3494+
this.with_rib(TypeNS,RibKind::ConstParamTy, |this| {
3495+
this.with_rib(
3496+
ValueNS,
3497+
RibKind::ConstParamTy,
3498+
|this| {
3499+
this.with_lifetime_rib(
3500+
LifetimeRibKind::ConstParamTy,
3501+
|this| this.visit_ty(ty),
3502+
)
3503+
},
3504+
)
3505+
});
3506+
}else{
3507+
this.visit_ty(ty);
3508+
}
34573509
ifletSome(rhs) = rhs {
34583510
// We allow arbitrary const expressions inside of associated consts,
34593511
// even if they are potentially not const evaluatable.

‎tests/ui/associated-consts/assoc-const-eq-bound-var-in-ty-not-wf.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
min_generic_const_args,
66
adt_const_params,
77
unsized_const_params,
8+
generic_const_parameter_types,
89
)]
910
#![allow(incomplete_features)]
1011

‎tests/ui/associated-consts/assoc-const-eq-bound-var-in-ty-not-wf.stderr‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
error: higher-ranked subtype error
2-
--> $DIR/assoc-const-eq-bound-var-in-ty-not-wf.rs:21:13
2+
--> $DIR/assoc-const-eq-bound-var-in-ty-not-wf.rs:22:13
33
|
44
LL | K = const { () }
55
| ^^^^^^^^^^^^
66

77
error: higher-ranked subtype error
8-
--> $DIR/assoc-const-eq-bound-var-in-ty-not-wf.rs:21:13
8+
--> $DIR/assoc-const-eq-bound-var-in-ty-not-wf.rs:22:13
99
|
1010
LL | K = const { () }
1111
| ^^^^^^^^^^^^

‎tests/ui/associated-consts/assoc-const-eq-bound-var-in-ty.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
min_generic_const_args,
99
adt_const_params,
1010
unsized_const_params,
11+
generic_const_parameter_types,
1112
)]
1213
#![allow(incomplete_features)]
1314

‎tests/ui/associated-consts/assoc-const-eq-esc-bound-var-in-ty.rs‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
// Detect and reject escaping late-bound generic params in
22
// the type of assoc consts used in an equality bound.
3-
#![feature(associated_const_equality, min_generic_const_args, unsized_const_params)]
3+
#![feature(
4+
associated_const_equality,
5+
min_generic_const_args,
6+
unsized_const_params,
7+
generic_const_parameter_types,
8+
)]
49
#![allow(incomplete_features)]
510

611
traitTrait<'a>{

‎tests/ui/associated-consts/assoc-const-eq-esc-bound-var-in-ty.stderr‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: the type of the associated constant `K` cannot capture late-bound generic parameters
2-
--> $DIR/assoc-const-eq-esc-bound-var-in-ty.rs:11:35
2+
--> $DIR/assoc-const-eq-esc-bound-var-in-ty.rs:16:35
33
|
44
LL | fn take(_: impl for<'r> Trait<'r, K = const { &() }>) {}
55
| -- ^ its type cannot capture the late-bound lifetime parameter `'r`

‎tests/ui/associated-consts/assoc-const-eq-param-in-ty.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
min_generic_const_args,
66
adt_const_params,
77
unsized_const_params,
8+
generic_const_parameter_types,
89
)]
910
#![allow(incomplete_features)]
1011

‎tests/ui/associated-consts/assoc-const-eq-param-in-ty.stderr‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: the type of the associated constant `K` must not depend on generic parameters
2-
--> $DIR/assoc-const-eq-param-in-ty.rs:22:29
2+
--> $DIR/assoc-const-eq-param-in-ty.rs:23:29
33
|
44
LL | fn take0<'r, A: 'r + ConstParamTy_, const Q: usize>(
55
| -- the lifetime parameter `'r` is defined here
@@ -10,7 +10,7 @@ LL | _: impl Trait<'r, A, Q, K = const { loop {} }>
1010
= note: `K` has type `&'r [A; Q]`
1111

1212
error: the type of the associated constant `K` must not depend on generic parameters
13-
--> $DIR/assoc-const-eq-param-in-ty.rs:22:29
13+
--> $DIR/assoc-const-eq-param-in-ty.rs:23:29
1414
|
1515
LL | fn take0<'r, A: 'r + ConstParamTy_, const Q: usize>(
1616
| - the type parameter `A` is defined here
@@ -21,7 +21,7 @@ LL | _: impl Trait<'r, A, Q, K = const { loop {} }>
2121
= note: `K` has type `&'r [A; Q]`
2222

2323
error: the type of the associated constant `K` must not depend on generic parameters
24-
--> $DIR/assoc-const-eq-param-in-ty.rs:22:29
24+
--> $DIR/assoc-const-eq-param-in-ty.rs:23:29
2525
|
2626
LL | fn take0<'r, A: 'r + ConstParamTy_, const Q: usize>(
2727
| - the const parameter `Q` is defined here
@@ -32,7 +32,7 @@ LL | _: impl Trait<'r, A, Q, K = const { loop {} }>
3232
= note: `K` has type `&'r [A; Q]`
3333

3434
error: the type of the associated constant `SELF` must not depend on `impl Trait`
35-
--> $DIR/assoc-const-eq-param-in-ty.rs:39:26
35+
--> $DIR/assoc-const-eq-param-in-ty.rs:40:26
3636
|
3737
LL | fn take1(_: impl Project<SELF = const {}>) {}
3838
| -------------^^^^------------
@@ -41,7 +41,7 @@ LL | fn take1(_: impl Project<SELF = const {}>) {}
4141
| the `impl Trait` is specified here
4242

4343
error: the type of the associated constant `SELF` must not depend on generic parameters
44-
--> $DIR/assoc-const-eq-param-in-ty.rs:44:21
44+
--> $DIR/assoc-const-eq-param-in-ty.rs:45:21
4545
|
4646
LL | fn take2<P: Project<SELF = const {}>>(_: P) {}
4747
| - ^^^^ its type must not depend on the type parameter `P`
@@ -51,7 +51,7 @@ LL | fn take2<P: Project<SELF = const {}>>(_: P) {}
5151
= note: `SELF` has type `P`
5252

5353
error: the type of the associated constant `K` must not depend on generic parameters
54-
--> $DIR/assoc-const-eq-param-in-ty.rs:53:52
54+
--> $DIR/assoc-const-eq-param-in-ty.rs:54:52
5555
|
5656
LL | trait Iface<'r>: ConstParamTy_ {
5757
| -- the lifetime parameter `'r` is defined here
@@ -62,15 +62,15 @@ LL | type Assoc<const Q: usize>: Trait<'r, Self, Q, K = const { loop {} }>
6262
= note: `K` has type `&'r [Self; Q]`
6363

6464
error: the type of the associated constant `K` must not depend on `Self`
65-
--> $DIR/assoc-const-eq-param-in-ty.rs:53:52
65+
--> $DIR/assoc-const-eq-param-in-ty.rs:54:52
6666
|
6767
LL | type Assoc<const Q: usize>: Trait<'r, Self, Q, K = const { loop {} }>
6868
| ^ its type must not depend on `Self`
6969
|
7070
= note: `K` has type `&'r [Self; Q]`
7171

7272
error: the type of the associated constant `K` must not depend on generic parameters
73-
--> $DIR/assoc-const-eq-param-in-ty.rs:53:52
73+
--> $DIR/assoc-const-eq-param-in-ty.rs:54:52
7474
|
7575
LL | type Assoc<const Q: usize>: Trait<'r, Self, Q, K = const { loop {} }>
7676
| - ^ its type must not depend on the const parameter `Q`
@@ -80,7 +80,7 @@ LL | type Assoc<const Q: usize>: Trait<'r, Self, Q, K = const { loop {} }>
8080
= note: `K` has type `&'r [Self; Q]`
8181

8282
error: the type of the associated constant `K` must not depend on generic parameters
83-
--> $DIR/assoc-const-eq-param-in-ty.rs:53:52
83+
--> $DIR/assoc-const-eq-param-in-ty.rs:54:52
8484
|
8585
LL | trait Iface<'r>: ConstParamTy_ {
8686
| -- the lifetime parameter `'r` is defined here
@@ -92,7 +92,7 @@ LL | type Assoc<const Q: usize>: Trait<'r, Self, Q, K = const { loop {} }>
9292
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
9393

9494
error: the type of the associated constant `K` must not depend on `Self`
95-
--> $DIR/assoc-const-eq-param-in-ty.rs:53:52
95+
--> $DIR/assoc-const-eq-param-in-ty.rs:54:52
9696
|
9797
LL | type Assoc<const Q: usize>: Trait<'r, Self, Q, K = const { loop {} }>
9898
| ^ its type must not depend on `Self`
@@ -101,7 +101,7 @@ LL | type Assoc<const Q: usize>: Trait<'r, Self, Q, K = const { loop {} }>
101101
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
102102

103103
error: the type of the associated constant `K` must not depend on generic parameters
104-
--> $DIR/assoc-const-eq-param-in-ty.rs:53:52
104+
--> $DIR/assoc-const-eq-param-in-ty.rs:54:52
105105
|
106106
LL | type Assoc<const Q: usize>: Trait<'r, Self, Q, K = const { loop {} }>
107107
| - ^ its type must not depend on the const parameter `Q`

‎tests/ui/associated-consts/assoc-const-eq-supertraits.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
min_generic_const_args,
99
adt_const_params,
1010
unsized_const_params,
11+
generic_const_parameter_types,
1112
)]
1213
#![allow(incomplete_features)]
1314

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
error: anonymous constants referencing generics are not yet supported
2+
--> $DIR/type_const-generic-param-in-type.rs:9:53
3+
|
4+
LL | const FOO<T: core::marker::ConstParamTy_>: [T; 0] = const { [] };
5+
| ^^^^^^^^^^^^
6+
7+
error: anonymous constants referencing generics are not yet supported
8+
--> $DIR/type_const-generic-param-in-type.rs:14:38
9+
|
10+
LL | const BAR<const N: usize>: [(); N] = const { [] };
11+
| ^^^^^^^^^^^^
12+
13+
error: anonymous constants with lifetimes in their type are not yet supported
14+
--> $DIR/type_const-generic-param-in-type.rs:19:30
15+
|
16+
LL | const BAZ<'a>: [&'a (); 0] = const { [] };
17+
| ^^^^^^^^^^^^
18+
19+
error: anonymous constants referencing generics are not yet supported
20+
--> $DIR/type_const-generic-param-in-type.rs:39:59
21+
|
22+
LL | const ASSOC<T: core::marker::ConstParamTy_>: [T; 0] = const { [] };
23+
| ^^^^^^^^^^^^
24+
25+
error: anonymous constants referencing generics are not yet supported
26+
--> $DIR/type_const-generic-param-in-type.rs:44:50
27+
|
28+
LL | const ASSOC_CONST<const N: usize>: [(); N] = const { [] };
29+
| ^^^^^^^^^^^^
30+
31+
error: anonymous constants with lifetimes in their type are not yet supported
32+
--> $DIR/type_const-generic-param-in-type.rs:49:39
33+
|
34+
LL | const ASSOC_LT<'a>: [&'a (); 0] = const { [] };
35+
| ^^^^^^^^^^^^
36+
37+
error: aborting due to 6 previous errors
38+

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Commit 05dce48

Browse files
authored
Rollup merge of #150650 - enthropy7:main, r=BoxyUwU
Forbid generic parameters in types of #[type_const] items fixes#150614 we enforce the same restriction on `#[type_const]` const items that already exists for const generic parameters - when `generic_const_parameter_types` feature gate is not enabled, the type of a `#[type_const]` item cannot reference generic parameters. implementation follows the same pattern used for const generic parameters. we check if the item has the `#[type_const]` attribute and if the feature gate is disabled, then we apply `RibKind::ConstParamTy` restrictions when visiting the type, which prevents the use of generic parameters. check is added in three places: - Free const items (`ItemKind::Const`) - Trait associated consts (`AssocItemKind::Const` in traits) - Impl associated consts (`AssocItemKind::Const` in impls) added tests for new feature, hope i get this task right :> r? `@BoxyUwU`
2 parents f63ab49 + 46bb414 commit 05dce48

12 files changed

Lines changed: 228 additions & 18 deletions

‎compiler/rustc_resolve/src/late.rs‎

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2851,6 +2851,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
28512851
ref define_opaque,
28522852
..
28532853
}) => {
2854+
let is_type_const = attr::contains_name(&item.attrs, sym::type_const);
28542855
self.with_generic_param_rib(
28552856
&generics.params,
28562857
RibKind::Item(
@@ -2869,7 +2870,22 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
28692870

28702871
this.with_lifetime_rib(
28712872
LifetimeRibKind::Elided(LifetimeRes::Static),
2872-
|this| this.visit_ty(ty),
2873+
|this| {
2874+
if is_type_const
2875+
&& !this.r.tcx.features().generic_const_parameter_types()
2876+
{
2877+
this.with_rib(TypeNS,RibKind::ConstParamTy, |this| {
2878+
this.with_rib(ValueNS,RibKind::ConstParamTy, |this| {
2879+
this.with_lifetime_rib(
2880+
LifetimeRibKind::ConstParamTy,
2881+
|this| this.visit_ty(ty),
2882+
)
2883+
})
2884+
});
2885+
}else{
2886+
this.visit_ty(ty);
2887+
}
2888+
},
28732889
);
28742890

28752891
ifletSome(rhs) = rhs {
@@ -3209,6 +3225,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
32093225
define_opaque,
32103226
..
32113227
}) => {
3228+
let is_type_const = attr::contains_name(&item.attrs, sym::type_const);
32123229
self.with_generic_param_rib(
32133230
&generics.params,
32143231
RibKind::AssocItem,
@@ -3223,7 +3240,20 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
32233240
},
32243241
|this| {
32253242
this.visit_generics(generics);
3226-
this.visit_ty(ty);
3243+
if is_type_const
3244+
&& !this.r.tcx.features().generic_const_parameter_types()
3245+
{
3246+
this.with_rib(TypeNS,RibKind::ConstParamTy, |this| {
3247+
this.with_rib(ValueNS,RibKind::ConstParamTy, |this| {
3248+
this.with_lifetime_rib(
3249+
LifetimeRibKind::ConstParamTy,
3250+
|this| this.visit_ty(ty),
3251+
)
3252+
})
3253+
});
3254+
}else{
3255+
this.visit_ty(ty);
3256+
}
32273257

32283258
// Only impose the restrictions of `ConstRibKind` for an
32293259
// actual constant expression in a provided default.
@@ -3417,6 +3447,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
34173447
..
34183448
}) => {
34193449
debug!("resolve_implementation AssocItemKind::Const");
3450+
let is_type_const = attr::contains_name(&item.attrs, sym::type_const);
34203451
self.with_generic_param_rib(
34213452
&generics.params,
34223453
RibKind::AssocItem,
@@ -3453,7 +3484,28 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
34533484
);
34543485

34553486
this.visit_generics(generics);
3456-
this.visit_ty(ty);
3487+
if is_type_const
3488+
&& !this
3489+
.r
3490+
.tcx
3491+
.features()
3492+
.generic_const_parameter_types()
3493+
{
3494+
this.with_rib(TypeNS,RibKind::ConstParamTy, |this| {
3495+
this.with_rib(
3496+
ValueNS,
3497+
RibKind::ConstParamTy,
3498+
|this| {
3499+
this.with_lifetime_rib(
3500+
LifetimeRibKind::ConstParamTy,
3501+
|this| this.visit_ty(ty),
3502+
)
3503+
},
3504+
)
3505+
});
3506+
}else{
3507+
this.visit_ty(ty);
3508+
}
34573509
ifletSome(rhs) = rhs {
34583510
// We allow arbitrary const expressions inside of associated consts,
34593511
// even if they are potentially not const evaluatable.

‎tests/ui/associated-consts/assoc-const-eq-bound-var-in-ty-not-wf.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
min_generic_const_args,
66
adt_const_params,
77
unsized_const_params,
8+
generic_const_parameter_types,
89
)]
910
#![allow(incomplete_features)]
1011

‎tests/ui/associated-consts/assoc-const-eq-bound-var-in-ty-not-wf.stderr‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
error: higher-ranked subtype error
2-
--> $DIR/assoc-const-eq-bound-var-in-ty-not-wf.rs:21:13
2+
--> $DIR/assoc-const-eq-bound-var-in-ty-not-wf.rs:22:13
33
|
44
LL | K = const { () }
55
| ^^^^^^^^^^^^
66

77
error: higher-ranked subtype error
8-
--> $DIR/assoc-const-eq-bound-var-in-ty-not-wf.rs:21:13
8+
--> $DIR/assoc-const-eq-bound-var-in-ty-not-wf.rs:22:13
99
|
1010
LL | K = const { () }
1111
| ^^^^^^^^^^^^

‎tests/ui/associated-consts/assoc-const-eq-bound-var-in-ty.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
min_generic_const_args,
99
adt_const_params,
1010
unsized_const_params,
11+
generic_const_parameter_types,
1112
)]
1213
#![allow(incomplete_features)]
1314

‎tests/ui/associated-consts/assoc-const-eq-esc-bound-var-in-ty.rs‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
// Detect and reject escaping late-bound generic params in
22
// the type of assoc consts used in an equality bound.
3-
#![feature(associated_const_equality, min_generic_const_args, unsized_const_params)]
3+
#![feature(
4+
associated_const_equality,
5+
min_generic_const_args,
6+
unsized_const_params,
7+
generic_const_parameter_types,
8+
)]
49
#![allow(incomplete_features)]
510

611
traitTrait<'a>{

‎tests/ui/associated-consts/assoc-const-eq-esc-bound-var-in-ty.stderr‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: the type of the associated constant `K` cannot capture late-bound generic parameters
2-
--> $DIR/assoc-const-eq-esc-bound-var-in-ty.rs:11:35
2+
--> $DIR/assoc-const-eq-esc-bound-var-in-ty.rs:16:35
33
|
44
LL | fn take(_: impl for<'r> Trait<'r, K = const { &() }>) {}
55
| -- ^ its type cannot capture the late-bound lifetime parameter `'r`

‎tests/ui/associated-consts/assoc-const-eq-param-in-ty.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
min_generic_const_args,
66
adt_const_params,
77
unsized_const_params,
8+
generic_const_parameter_types,
89
)]
910
#![allow(incomplete_features)]
1011

‎tests/ui/associated-consts/assoc-const-eq-param-in-ty.stderr‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: the type of the associated constant `K` must not depend on generic parameters
2-
--> $DIR/assoc-const-eq-param-in-ty.rs:22:29
2+
--> $DIR/assoc-const-eq-param-in-ty.rs:23:29
33
|
44
LL | fn take0<'r, A: 'r + ConstParamTy_, const Q: usize>(
55
| -- the lifetime parameter `'r` is defined here
@@ -10,7 +10,7 @@ LL | _: impl Trait<'r, A, Q, K = const { loop {} }>
1010
= note: `K` has type `&'r [A; Q]`
1111

1212
error: the type of the associated constant `K` must not depend on generic parameters
13-
--> $DIR/assoc-const-eq-param-in-ty.rs:22:29
13+
--> $DIR/assoc-const-eq-param-in-ty.rs:23:29
1414
|
1515
LL | fn take0<'r, A: 'r + ConstParamTy_, const Q: usize>(
1616
| - the type parameter `A` is defined here
@@ -21,7 +21,7 @@ LL | _: impl Trait<'r, A, Q, K = const { loop {} }>
2121
= note: `K` has type `&'r [A; Q]`
2222

2323
error: the type of the associated constant `K` must not depend on generic parameters
24-
--> $DIR/assoc-const-eq-param-in-ty.rs:22:29
24+
--> $DIR/assoc-const-eq-param-in-ty.rs:23:29
2525
|
2626
LL | fn take0<'r, A: 'r + ConstParamTy_, const Q: usize>(
2727
| - the const parameter `Q` is defined here
@@ -32,7 +32,7 @@ LL | _: impl Trait<'r, A, Q, K = const { loop {} }>
3232
= note: `K` has type `&'r [A; Q]`
3333

3434
error: the type of the associated constant `SELF` must not depend on `impl Trait`
35-
--> $DIR/assoc-const-eq-param-in-ty.rs:39:26
35+
--> $DIR/assoc-const-eq-param-in-ty.rs:40:26
3636
|
3737
LL | fn take1(_: impl Project<SELF = const {}>) {}
3838
| -------------^^^^------------
@@ -41,7 +41,7 @@ LL | fn take1(_: impl Project<SELF = const {}>) {}
4141
| the `impl Trait` is specified here
4242

4343
error: the type of the associated constant `SELF` must not depend on generic parameters
44-
--> $DIR/assoc-const-eq-param-in-ty.rs:44:21
44+
--> $DIR/assoc-const-eq-param-in-ty.rs:45:21
4545
|
4646
LL | fn take2<P: Project<SELF = const {}>>(_: P) {}
4747
| - ^^^^ its type must not depend on the type parameter `P`
@@ -51,7 +51,7 @@ LL | fn take2<P: Project<SELF = const {}>>(_: P) {}
5151
= note: `SELF` has type `P`
5252

5353
error: the type of the associated constant `K` must not depend on generic parameters
54-
--> $DIR/assoc-const-eq-param-in-ty.rs:53:52
54+
--> $DIR/assoc-const-eq-param-in-ty.rs:54:52
5555
|
5656
LL | trait Iface<'r>: ConstParamTy_ {
5757
| -- the lifetime parameter `'r` is defined here
@@ -62,15 +62,15 @@ LL | type Assoc<const Q: usize>: Trait<'r, Self, Q, K = const { loop {} }>
6262
= note: `K` has type `&'r [Self; Q]`
6363

6464
error: the type of the associated constant `K` must not depend on `Self`
65-
--> $DIR/assoc-const-eq-param-in-ty.rs:53:52
65+
--> $DIR/assoc-const-eq-param-in-ty.rs:54:52
6666
|
6767
LL | type Assoc<const Q: usize>: Trait<'r, Self, Q, K = const { loop {} }>
6868
| ^ its type must not depend on `Self`
6969
|
7070
= note: `K` has type `&'r [Self; Q]`
7171

7272
error: the type of the associated constant `K` must not depend on generic parameters
73-
--> $DIR/assoc-const-eq-param-in-ty.rs:53:52
73+
--> $DIR/assoc-const-eq-param-in-ty.rs:54:52
7474
|
7575
LL | type Assoc<const Q: usize>: Trait<'r, Self, Q, K = const { loop {} }>
7676
| - ^ its type must not depend on the const parameter `Q`
@@ -80,7 +80,7 @@ LL | type Assoc<const Q: usize>: Trait<'r, Self, Q, K = const { loop {} }>
8080
= note: `K` has type `&'r [Self; Q]`
8181

8282
error: the type of the associated constant `K` must not depend on generic parameters
83-
--> $DIR/assoc-const-eq-param-in-ty.rs:53:52
83+
--> $DIR/assoc-const-eq-param-in-ty.rs:54:52
8484
|
8585
LL | trait Iface<'r>: ConstParamTy_ {
8686
| -- the lifetime parameter `'r` is defined here
@@ -92,7 +92,7 @@ LL | type Assoc<const Q: usize>: Trait<'r, Self, Q, K = const { loop {} }>
9292
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
9393

9494
error: the type of the associated constant `K` must not depend on `Self`
95-
--> $DIR/assoc-const-eq-param-in-ty.rs:53:52
95+
--> $DIR/assoc-const-eq-param-in-ty.rs:54:52
9696
|
9797
LL | type Assoc<const Q: usize>: Trait<'r, Self, Q, K = const { loop {} }>
9898
| ^ its type must not depend on `Self`
@@ -101,7 +101,7 @@ LL | type Assoc<const Q: usize>: Trait<'r, Self, Q, K = const { loop {} }>
101101
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
102102

103103
error: the type of the associated constant `K` must not depend on generic parameters
104-
--> $DIR/assoc-const-eq-param-in-ty.rs:53:52
104+
--> $DIR/assoc-const-eq-param-in-ty.rs:54:52
105105
|
106106
LL | type Assoc<const Q: usize>: Trait<'r, Self, Q, K = const { loop {} }>
107107
| - ^ its type must not depend on the const parameter `Q`

‎tests/ui/associated-consts/assoc-const-eq-supertraits.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
min_generic_const_args,
99
adt_const_params,
1010
unsized_const_params,
11+
generic_const_parameter_types,
1112
)]
1213
#![allow(incomplete_features)]
1314

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
error: anonymous constants referencing generics are not yet supported
2+
--> $DIR/type_const-generic-param-in-type.rs:9:53
3+
|
4+
LL | const FOO<T: core::marker::ConstParamTy_>: [T; 0] = const { [] };
5+
| ^^^^^^^^^^^^
6+
7+
error: anonymous constants referencing generics are not yet supported
8+
--> $DIR/type_const-generic-param-in-type.rs:14:38
9+
|
10+
LL | const BAR<const N: usize>: [(); N] = const { [] };
11+
| ^^^^^^^^^^^^
12+
13+
error: anonymous constants with lifetimes in their type are not yet supported
14+
--> $DIR/type_const-generic-param-in-type.rs:19:30
15+
|
16+
LL | const BAZ<'a>: [&'a (); 0] = const { [] };
17+
| ^^^^^^^^^^^^
18+
19+
error: anonymous constants referencing generics are not yet supported
20+
--> $DIR/type_const-generic-param-in-type.rs:39:59
21+
|
22+
LL | const ASSOC<T: core::marker::ConstParamTy_>: [T; 0] = const { [] };
23+
| ^^^^^^^^^^^^
24+
25+
error: anonymous constants referencing generics are not yet supported
26+
--> $DIR/type_const-generic-param-in-type.rs:44:50
27+
|
28+
LL | const ASSOC_CONST<const N: usize>: [(); N] = const { [] };
29+
| ^^^^^^^^^^^^
30+
31+
error: anonymous constants with lifetimes in their type are not yet supported
32+
--> $DIR/type_const-generic-param-in-type.rs:49:39
33+
|
34+
LL | const ASSOC_LT<'a>: [&'a (); 0] = const { [] };
35+
| ^^^^^^^^^^^^
36+
37+
error: aborting due to 6 previous errors
38+

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Commit 05dce48

Browse files
authored
Rollup merge of #150650 - enthropy7:main, r=BoxyUwU
Forbid generic parameters in types of #[type_const] items fixes#150614 we enforce the same restriction on `#[type_const]` const items that already exists for const generic parameters - when `generic_const_parameter_types` feature gate is not enabled, the type of a `#[type_const]` item cannot reference generic parameters. implementation follows the same pattern used for const generic parameters. we check if the item has the `#[type_const]` attribute and if the feature gate is disabled, then we apply `RibKind::ConstParamTy` restrictions when visiting the type, which prevents the use of generic parameters. check is added in three places: - Free const items (`ItemKind::Const`) - Trait associated consts (`AssocItemKind::Const` in traits) - Impl associated consts (`AssocItemKind::Const` in impls) added tests for new feature, hope i get this task right :> r? `@BoxyUwU`
2 parents f63ab49 + 46bb414 commit 05dce48

12 files changed

Lines changed: 228 additions & 18 deletions

‎compiler/rustc_resolve/src/late.rs‎

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2851,6 +2851,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
28512851
ref define_opaque,
28522852
..
28532853
}) => {
2854+
let is_type_const = attr::contains_name(&item.attrs, sym::type_const);
28542855
self.with_generic_param_rib(
28552856
&generics.params,
28562857
RibKind::Item(
@@ -2869,7 +2870,22 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
28692870

28702871
this.with_lifetime_rib(
28712872
LifetimeRibKind::Elided(LifetimeRes::Static),
2872-
|this| this.visit_ty(ty),
2873+
|this| {
2874+
if is_type_const
2875+
&& !this.r.tcx.features().generic_const_parameter_types()
2876+
{
2877+
this.with_rib(TypeNS,RibKind::ConstParamTy, |this| {
2878+
this.with_rib(ValueNS,RibKind::ConstParamTy, |this| {
2879+
this.with_lifetime_rib(
2880+
LifetimeRibKind::ConstParamTy,
2881+
|this| this.visit_ty(ty),
2882+
)
2883+
})
2884+
});
2885+
}else{
2886+
this.visit_ty(ty);
2887+
}
2888+
},
28732889
);
28742890

28752891
ifletSome(rhs) = rhs {
@@ -3209,6 +3225,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
32093225
define_opaque,
32103226
..
32113227
}) => {
3228+
let is_type_const = attr::contains_name(&item.attrs, sym::type_const);
32123229
self.with_generic_param_rib(
32133230
&generics.params,
32143231
RibKind::AssocItem,
@@ -3223,7 +3240,20 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
32233240
},
32243241
|this| {
32253242
this.visit_generics(generics);
3226-
this.visit_ty(ty);
3243+
if is_type_const
3244+
&& !this.r.tcx.features().generic_const_parameter_types()
3245+
{
3246+
this.with_rib(TypeNS,RibKind::ConstParamTy, |this| {
3247+
this.with_rib(ValueNS,RibKind::ConstParamTy, |this| {
3248+
this.with_lifetime_rib(
3249+
LifetimeRibKind::ConstParamTy,
3250+
|this| this.visit_ty(ty),
3251+
)
3252+
})
3253+
});
3254+
}else{
3255+
this.visit_ty(ty);
3256+
}
32273257

32283258
// Only impose the restrictions of `ConstRibKind` for an
32293259
// actual constant expression in a provided default.
@@ -3417,6 +3447,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
34173447
..
34183448
}) => {
34193449
debug!("resolve_implementation AssocItemKind::Const");
3450+
let is_type_const = attr::contains_name(&item.attrs, sym::type_const);
34203451
self.with_generic_param_rib(
34213452
&generics.params,
34223453
RibKind::AssocItem,
@@ -3453,7 +3484,28 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
34533484
);
34543485

34553486
this.visit_generics(generics);
3456-
this.visit_ty(ty);
3487+
if is_type_const
3488+
&& !this
3489+
.r
3490+
.tcx
3491+
.features()
3492+
.generic_const_parameter_types()
3493+
{
3494+
this.with_rib(TypeNS,RibKind::ConstParamTy, |this| {
3495+
this.with_rib(
3496+
ValueNS,
3497+
RibKind::ConstParamTy,
3498+
|this| {
3499+
this.with_lifetime_rib(
3500+
LifetimeRibKind::ConstParamTy,
3501+
|this| this.visit_ty(ty),
3502+
)
3503+
},
3504+
)
3505+
});
3506+
}else{
3507+
this.visit_ty(ty);
3508+
}
34573509
ifletSome(rhs) = rhs {
34583510
// We allow arbitrary const expressions inside of associated consts,
34593511
// even if they are potentially not const evaluatable.

‎tests/ui/associated-consts/assoc-const-eq-bound-var-in-ty-not-wf.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
min_generic_const_args,
66
adt_const_params,
77
unsized_const_params,
8+
generic_const_parameter_types,
89
)]
910
#![allow(incomplete_features)]
1011

‎tests/ui/associated-consts/assoc-const-eq-bound-var-in-ty-not-wf.stderr‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
error: higher-ranked subtype error
2-
--> $DIR/assoc-const-eq-bound-var-in-ty-not-wf.rs:21:13
2+
--> $DIR/assoc-const-eq-bound-var-in-ty-not-wf.rs:22:13
33
|
44
LL | K = const { () }
55
| ^^^^^^^^^^^^
66

77
error: higher-ranked subtype error
8-
--> $DIR/assoc-const-eq-bound-var-in-ty-not-wf.rs:21:13
8+
--> $DIR/assoc-const-eq-bound-var-in-ty-not-wf.rs:22:13
99
|
1010
LL | K = const { () }
1111
| ^^^^^^^^^^^^

‎tests/ui/associated-consts/assoc-const-eq-bound-var-in-ty.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
min_generic_const_args,
99
adt_const_params,
1010
unsized_const_params,
11+
generic_const_parameter_types,
1112
)]
1213
#![allow(incomplete_features)]
1314

‎tests/ui/associated-consts/assoc-const-eq-esc-bound-var-in-ty.rs‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
// Detect and reject escaping late-bound generic params in
22
// the type of assoc consts used in an equality bound.
3-
#![feature(associated_const_equality, min_generic_const_args, unsized_const_params)]
3+
#![feature(
4+
associated_const_equality,
5+
min_generic_const_args,
6+
unsized_const_params,
7+
generic_const_parameter_types,
8+
)]
49
#![allow(incomplete_features)]
510

611
traitTrait<'a>{

‎tests/ui/associated-consts/assoc-const-eq-esc-bound-var-in-ty.stderr‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: the type of the associated constant `K` cannot capture late-bound generic parameters
2-
--> $DIR/assoc-const-eq-esc-bound-var-in-ty.rs:11:35
2+
--> $DIR/assoc-const-eq-esc-bound-var-in-ty.rs:16:35
33
|
44
LL | fn take(_: impl for<'r> Trait<'r, K = const { &() }>) {}
55
| -- ^ its type cannot capture the late-bound lifetime parameter `'r`

‎tests/ui/associated-consts/assoc-const-eq-param-in-ty.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
min_generic_const_args,
66
adt_const_params,
77
unsized_const_params,
8+
generic_const_parameter_types,
89
)]
910
#![allow(incomplete_features)]
1011

‎tests/ui/associated-consts/assoc-const-eq-param-in-ty.stderr‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: the type of the associated constant `K` must not depend on generic parameters
2-
--> $DIR/assoc-const-eq-param-in-ty.rs:22:29
2+
--> $DIR/assoc-const-eq-param-in-ty.rs:23:29
33
|
44
LL | fn take0<'r, A: 'r + ConstParamTy_, const Q: usize>(
55
| -- the lifetime parameter `'r` is defined here
@@ -10,7 +10,7 @@ LL | _: impl Trait<'r, A, Q, K = const { loop {} }>
1010
= note: `K` has type `&'r [A; Q]`
1111

1212
error: the type of the associated constant `K` must not depend on generic parameters
13-
--> $DIR/assoc-const-eq-param-in-ty.rs:22:29
13+
--> $DIR/assoc-const-eq-param-in-ty.rs:23:29
1414
|
1515
LL | fn take0<'r, A: 'r + ConstParamTy_, const Q: usize>(
1616
| - the type parameter `A` is defined here
@@ -21,7 +21,7 @@ LL | _: impl Trait<'r, A, Q, K = const { loop {} }>
2121
= note: `K` has type `&'r [A; Q]`
2222

2323
error: the type of the associated constant `K` must not depend on generic parameters
24-
--> $DIR/assoc-const-eq-param-in-ty.rs:22:29
24+
--> $DIR/assoc-const-eq-param-in-ty.rs:23:29
2525
|
2626
LL | fn take0<'r, A: 'r + ConstParamTy_, const Q: usize>(
2727
| - the const parameter `Q` is defined here
@@ -32,7 +32,7 @@ LL | _: impl Trait<'r, A, Q, K = const { loop {} }>
3232
= note: `K` has type `&'r [A; Q]`
3333

3434
error: the type of the associated constant `SELF` must not depend on `impl Trait`
35-
--> $DIR/assoc-const-eq-param-in-ty.rs:39:26
35+
--> $DIR/assoc-const-eq-param-in-ty.rs:40:26
3636
|
3737
LL | fn take1(_: impl Project<SELF = const {}>) {}
3838
| -------------^^^^------------
@@ -41,7 +41,7 @@ LL | fn take1(_: impl Project<SELF = const {}>) {}
4141
| the `impl Trait` is specified here
4242

4343
error: the type of the associated constant `SELF` must not depend on generic parameters
44-
--> $DIR/assoc-const-eq-param-in-ty.rs:44:21
44+
--> $DIR/assoc-const-eq-param-in-ty.rs:45:21
4545
|
4646
LL | fn take2<P: Project<SELF = const {}>>(_: P) {}
4747
| - ^^^^ its type must not depend on the type parameter `P`
@@ -51,7 +51,7 @@ LL | fn take2<P: Project<SELF = const {}>>(_: P) {}
5151
= note: `SELF` has type `P`
5252

5353
error: the type of the associated constant `K` must not depend on generic parameters
54-
--> $DIR/assoc-const-eq-param-in-ty.rs:53:52
54+
--> $DIR/assoc-const-eq-param-in-ty.rs:54:52
5555
|
5656
LL | trait Iface<'r>: ConstParamTy_ {
5757
| -- the lifetime parameter `'r` is defined here
@@ -62,15 +62,15 @@ LL | type Assoc<const Q: usize>: Trait<'r, Self, Q, K = const { loop {} }>
6262
= note: `K` has type `&'r [Self; Q]`
6363

6464
error: the type of the associated constant `K` must not depend on `Self`
65-
--> $DIR/assoc-const-eq-param-in-ty.rs:53:52
65+
--> $DIR/assoc-const-eq-param-in-ty.rs:54:52
6666
|
6767
LL | type Assoc<const Q: usize>: Trait<'r, Self, Q, K = const { loop {} }>
6868
| ^ its type must not depend on `Self`
6969
|
7070
= note: `K` has type `&'r [Self; Q]`
7171

7272
error: the type of the associated constant `K` must not depend on generic parameters
73-
--> $DIR/assoc-const-eq-param-in-ty.rs:53:52
73+
--> $DIR/assoc-const-eq-param-in-ty.rs:54:52
7474
|
7575
LL | type Assoc<const Q: usize>: Trait<'r, Self, Q, K = const { loop {} }>
7676
| - ^ its type must not depend on the const parameter `Q`
@@ -80,7 +80,7 @@ LL | type Assoc<const Q: usize>: Trait<'r, Self, Q, K = const { loop {} }>
8080
= note: `K` has type `&'r [Self; Q]`
8181

8282
error: the type of the associated constant `K` must not depend on generic parameters
83-
--> $DIR/assoc-const-eq-param-in-ty.rs:53:52
83+
--> $DIR/assoc-const-eq-param-in-ty.rs:54:52
8484
|
8585
LL | trait Iface<'r>: ConstParamTy_ {
8686
| -- the lifetime parameter `'r` is defined here
@@ -92,7 +92,7 @@ LL | type Assoc<const Q: usize>: Trait<'r, Self, Q, K = const { loop {} }>
9292
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
9393

9494
error: the type of the associated constant `K` must not depend on `Self`
95-
--> $DIR/assoc-const-eq-param-in-ty.rs:53:52
95+
--> $DIR/assoc-const-eq-param-in-ty.rs:54:52
9696
|
9797
LL | type Assoc<const Q: usize>: Trait<'r, Self, Q, K = const { loop {} }>
9898
| ^ its type must not depend on `Self`
@@ -101,7 +101,7 @@ LL | type Assoc<const Q: usize>: Trait<'r, Self, Q, K = const { loop {} }>
101101
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
102102

103103
error: the type of the associated constant `K` must not depend on generic parameters
104-
--> $DIR/assoc-const-eq-param-in-ty.rs:53:52
104+
--> $DIR/assoc-const-eq-param-in-ty.rs:54:52
105105
|
106106
LL | type Assoc<const Q: usize>: Trait<'r, Self, Q, K = const { loop {} }>
107107
| - ^ its type must not depend on the const parameter `Q`

‎tests/ui/associated-consts/assoc-const-eq-supertraits.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
min_generic_const_args,
99
adt_const_params,
1010
unsized_const_params,
11+
generic_const_parameter_types,
1112
)]
1213
#![allow(incomplete_features)]
1314

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
error: anonymous constants referencing generics are not yet supported
2+
--> $DIR/type_const-generic-param-in-type.rs:9:53
3+
|
4+
LL | const FOO<T: core::marker::ConstParamTy_>: [T; 0] = const { [] };
5+
| ^^^^^^^^^^^^
6+
7+
error: anonymous constants referencing generics are not yet supported
8+
--> $DIR/type_const-generic-param-in-type.rs:14:38
9+
|
10+
LL | const BAR<const N: usize>: [(); N] = const { [] };
11+
| ^^^^^^^^^^^^
12+
13+
error: anonymous constants with lifetimes in their type are not yet supported
14+
--> $DIR/type_const-generic-param-in-type.rs:19:30
15+
|
16+
LL | const BAZ<'a>: [&'a (); 0] = const { [] };
17+
| ^^^^^^^^^^^^
18+
19+
error: anonymous constants referencing generics are not yet supported
20+
--> $DIR/type_const-generic-param-in-type.rs:39:59
21+
|
22+
LL | const ASSOC<T: core::marker::ConstParamTy_>: [T; 0] = const { [] };
23+
| ^^^^^^^^^^^^
24+
25+
error: anonymous constants referencing generics are not yet supported
26+
--> $DIR/type_const-generic-param-in-type.rs:44:50
27+
|
28+
LL | const ASSOC_CONST<const N: usize>: [(); N] = const { [] };
29+
| ^^^^^^^^^^^^
30+
31+
error: anonymous constants with lifetimes in their type are not yet supported
32+
--> $DIR/type_const-generic-param-in-type.rs:49:39
33+
|
34+
LL | const ASSOC_LT<'a>: [&'a (); 0] = const { [] };
35+
| ^^^^^^^^^^^^
36+
37+
error: aborting due to 6 previous errors
38+

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content

Commit 05dce48

Browse files
authored
Rollup merge of #150650 - enthropy7:main, r=BoxyUwU
Forbid generic parameters in types of #[type_const] items fixes#150614 we enforce the same restriction on `#[type_const]` const items that already exists for const generic parameters - when `generic_const_parameter_types` feature gate is not enabled, the type of a `#[type_const]` item cannot reference generic parameters. implementation follows the same pattern used for const generic parameters. we check if the item has the `#[type_const]` attribute and if the feature gate is disabled, then we apply `RibKind::ConstParamTy` restrictions when visiting the type, which prevents the use of generic parameters. check is added in three places: - Free const items (`ItemKind::Const`) - Trait associated consts (`AssocItemKind::Const` in traits) - Impl associated consts (`AssocItemKind::Const` in impls) added tests for new feature, hope i get this task right :> r? `@BoxyUwU`
2 parents f63ab49 + 46bb414 commit 05dce48

12 files changed

Lines changed: 228 additions & 18 deletions

‎compiler/rustc_resolve/src/late.rs‎

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2851,6 +2851,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
28512851
ref define_opaque,
28522852
..
28532853
}) => {
2854+
let is_type_const = attr::contains_name(&item.attrs, sym::type_const);
28542855
self.with_generic_param_rib(
28552856
&generics.params,
28562857
RibKind::Item(
@@ -2869,7 +2870,22 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
28692870

28702871
this.with_lifetime_rib(
28712872
LifetimeRibKind::Elided(LifetimeRes::Static),
2872-
|this| this.visit_ty(ty),
2873+
|this| {
2874+
if is_type_const
2875+
&& !this.r.tcx.features().generic_const_parameter_types()
2876+
{
2877+
this.with_rib(TypeNS,RibKind::ConstParamTy, |this| {
2878+
this.with_rib(ValueNS,RibKind::ConstParamTy, |this| {
2879+
this.with_lifetime_rib(
2880+
LifetimeRibKind::ConstParamTy,
2881+
|this| this.visit_ty(ty),
2882+
)
2883+
})
2884+
});
2885+
}else{
2886+
this.visit_ty(ty);
2887+
}
2888+
},
28732889
);
28742890

28752891
ifletSome(rhs) = rhs {
@@ -3209,6 +3225,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
32093225
define_opaque,
32103226
..
32113227
}) => {
3228+
let is_type_const = attr::contains_name(&item.attrs, sym::type_const);
32123229
self.with_generic_param_rib(
32133230
&generics.params,
32143231
RibKind::AssocItem,
@@ -3223,7 +3240,20 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
32233240
},
32243241
|this| {
32253242
this.visit_generics(generics);
3226-
this.visit_ty(ty);
3243+
if is_type_const
3244+
&& !this.r.tcx.features().generic_const_parameter_types()
3245+
{
3246+
this.with_rib(TypeNS,RibKind::ConstParamTy, |this| {
3247+
this.with_rib(ValueNS,RibKind::ConstParamTy, |this| {
3248+
this.with_lifetime_rib(
3249+
LifetimeRibKind::ConstParamTy,
3250+
|this| this.visit_ty(ty),
3251+
)
3252+
})
3253+
});
3254+
}else{
3255+
this.visit_ty(ty);
3256+
}
32273257

32283258
// Only impose the restrictions of `ConstRibKind` for an
32293259
// actual constant expression in a provided default.
@@ -3417,6 +3447,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
34173447
..
34183448
}) => {
34193449
debug!("resolve_implementation AssocItemKind::Const");
3450+
let is_type_const = attr::contains_name(&item.attrs, sym::type_const);
34203451
self.with_generic_param_rib(
34213452
&generics.params,
34223453
RibKind::AssocItem,
@@ -3453,7 +3484,28 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
34533484
);
34543485

34553486
this.visit_generics(generics);
3456-
this.visit_ty(ty);
3487+
if is_type_const
3488+
&& !this
3489+
.r
3490+
.tcx
3491+
.features()
3492+
.generic_const_parameter_types()
3493+
{
3494+
this.with_rib(TypeNS,RibKind::ConstParamTy, |this| {
3495+
this.with_rib(
3496+
ValueNS,
3497+
RibKind::ConstParamTy,
3498+
|this| {
3499+
this.with_lifetime_rib(
3500+
LifetimeRibKind::ConstParamTy,
3501+
|this| this.visit_ty(ty),
3502+
)
3503+
},
3504+
)
3505+
});
3506+
}else{
3507+
this.visit_ty(ty);
3508+
}
34573509
ifletSome(rhs) = rhs {
34583510
// We allow arbitrary const expressions inside of associated consts,
34593511
// even if they are potentially not const evaluatable.

‎tests/ui/associated-consts/assoc-const-eq-bound-var-in-ty-not-wf.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
min_generic_const_args,
66
adt_const_params,
77
unsized_const_params,
8+
generic_const_parameter_types,
89
)]
910
#![allow(incomplete_features)]
1011

‎tests/ui/associated-consts/assoc-const-eq-bound-var-in-ty-not-wf.stderr‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
error: higher-ranked subtype error
2-
--> $DIR/assoc-const-eq-bound-var-in-ty-not-wf.rs:21:13
2+
--> $DIR/assoc-const-eq-bound-var-in-ty-not-wf.rs:22:13
33
|
44
LL | K = const { () }
55
| ^^^^^^^^^^^^
66

77
error: higher-ranked subtype error
8-
--> $DIR/assoc-const-eq-bound-var-in-ty-not-wf.rs:21:13
8+
--> $DIR/assoc-const-eq-bound-var-in-ty-not-wf.rs:22:13
99
|
1010
LL | K = const { () }
1111
| ^^^^^^^^^^^^

‎tests/ui/associated-consts/assoc-const-eq-bound-var-in-ty.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
min_generic_const_args,
99
adt_const_params,
1010
unsized_const_params,
11+
generic_const_parameter_types,
1112
)]
1213
#![allow(incomplete_features)]
1314

‎tests/ui/associated-consts/assoc-const-eq-esc-bound-var-in-ty.rs‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
// Detect and reject escaping late-bound generic params in
22
// the type of assoc consts used in an equality bound.
3-
#![feature(associated_const_equality, min_generic_const_args, unsized_const_params)]
3+
#![feature(
4+
associated_const_equality,
5+
min_generic_const_args,
6+
unsized_const_params,
7+
generic_const_parameter_types,
8+
)]
49
#![allow(incomplete_features)]
510

611
traitTrait<'a>{

‎tests/ui/associated-consts/assoc-const-eq-esc-bound-var-in-ty.stderr‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: the type of the associated constant `K` cannot capture late-bound generic parameters
2-
--> $DIR/assoc-const-eq-esc-bound-var-in-ty.rs:11:35
2+
--> $DIR/assoc-const-eq-esc-bound-var-in-ty.rs:16:35
33
|
44
LL | fn take(_: impl for<'r> Trait<'r, K = const { &() }>) {}
55
| -- ^ its type cannot capture the late-bound lifetime parameter `'r`

‎tests/ui/associated-consts/assoc-const-eq-param-in-ty.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
min_generic_const_args,
66
adt_const_params,
77
unsized_const_params,
8+
generic_const_parameter_types,
89
)]
910
#![allow(incomplete_features)]
1011

‎tests/ui/associated-consts/assoc-const-eq-param-in-ty.stderr‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: the type of the associated constant `K` must not depend on generic parameters
2-
--> $DIR/assoc-const-eq-param-in-ty.rs:22:29
2+
--> $DIR/assoc-const-eq-param-in-ty.rs:23:29
33
|
44
LL | fn take0<'r, A: 'r + ConstParamTy_, const Q: usize>(
55
| -- the lifetime parameter `'r` is defined here
@@ -10,7 +10,7 @@ LL | _: impl Trait<'r, A, Q, K = const { loop {} }>
1010
= note: `K` has type `&'r [A; Q]`
1111

1212
error: the type of the associated constant `K` must not depend on generic parameters
13-
--> $DIR/assoc-const-eq-param-in-ty.rs:22:29
13+
--> $DIR/assoc-const-eq-param-in-ty.rs:23:29
1414
|
1515
LL | fn take0<'r, A: 'r + ConstParamTy_, const Q: usize>(
1616
| - the type parameter `A` is defined here
@@ -21,7 +21,7 @@ LL | _: impl Trait<'r, A, Q, K = const { loop {} }>
2121
= note: `K` has type `&'r [A; Q]`
2222

2323
error: the type of the associated constant `K` must not depend on generic parameters
24-
--> $DIR/assoc-const-eq-param-in-ty.rs:22:29
24+
--> $DIR/assoc-const-eq-param-in-ty.rs:23:29
2525
|
2626
LL | fn take0<'r, A: 'r + ConstParamTy_, const Q: usize>(
2727
| - the const parameter `Q` is defined here
@@ -32,7 +32,7 @@ LL | _: impl Trait<'r, A, Q, K = const { loop {} }>
3232
= note: `K` has type `&'r [A; Q]`
3333

3434
error: the type of the associated constant `SELF` must not depend on `impl Trait`
35-
--> $DIR/assoc-const-eq-param-in-ty.rs:39:26
35+
--> $DIR/assoc-const-eq-param-in-ty.rs:40:26
3636
|
3737
LL | fn take1(_: impl Project<SELF = const {}>) {}
3838
| -------------^^^^------------
@@ -41,7 +41,7 @@ LL | fn take1(_: impl Project<SELF = const {}>) {}
4141
| the `impl Trait` is specified here
4242

4343
error: the type of the associated constant `SELF` must not depend on generic parameters
44-
--> $DIR/assoc-const-eq-param-in-ty.rs:44:21
44+
--> $DIR/assoc-const-eq-param-in-ty.rs:45:21
4545
|
4646
LL | fn take2<P: Project<SELF = const {}>>(_: P) {}
4747
| - ^^^^ its type must not depend on the type parameter `P`
@@ -51,7 +51,7 @@ LL | fn take2<P: Project<SELF = const {}>>(_: P) {}
5151
= note: `SELF` has type `P`
5252

5353
error: the type of the associated constant `K` must not depend on generic parameters
54-
--> $DIR/assoc-const-eq-param-in-ty.rs:53:52
54+
--> $DIR/assoc-const-eq-param-in-ty.rs:54:52
5555
|
5656
LL | trait Iface<'r>: ConstParamTy_ {
5757
| -- the lifetime parameter `'r` is defined here
@@ -62,15 +62,15 @@ LL | type Assoc<const Q: usize>: Trait<'r, Self, Q, K = const { loop {} }>
6262
= note: `K` has type `&'r [Self; Q]`
6363

6464
error: the type of the associated constant `K` must not depend on `Self`
65-
--> $DIR/assoc-const-eq-param-in-ty.rs:53:52
65+
--> $DIR/assoc-const-eq-param-in-ty.rs:54:52
6666
|
6767
LL | type Assoc<const Q: usize>: Trait<'r, Self, Q, K = const { loop {} }>
6868
| ^ its type must not depend on `Self`
6969
|
7070
= note: `K` has type `&'r [Self; Q]`
7171

7272
error: the type of the associated constant `K` must not depend on generic parameters
73-
--> $DIR/assoc-const-eq-param-in-ty.rs:53:52
73+
--> $DIR/assoc-const-eq-param-in-ty.rs:54:52
7474
|
7575
LL | type Assoc<const Q: usize>: Trait<'r, Self, Q, K = const { loop {} }>
7676
| - ^ its type must not depend on the const parameter `Q`
@@ -80,7 +80,7 @@ LL | type Assoc<const Q: usize>: Trait<'r, Self, Q, K = const { loop {} }>
8080
= note: `K` has type `&'r [Self; Q]`
8181

8282
error: the type of the associated constant `K` must not depend on generic parameters
83-
--> $DIR/assoc-const-eq-param-in-ty.rs:53:52
83+
--> $DIR/assoc-const-eq-param-in-ty.rs:54:52
8484
|
8585
LL | trait Iface<'r>: ConstParamTy_ {
8686
| -- the lifetime parameter `'r` is defined here
@@ -92,7 +92,7 @@ LL | type Assoc<const Q: usize>: Trait<'r, Self, Q, K = const { loop {} }>
9292
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
9393

9494
error: the type of the associated constant `K` must not depend on `Self`
95-
--> $DIR/assoc-const-eq-param-in-ty.rs:53:52
95+
--> $DIR/assoc-const-eq-param-in-ty.rs:54:52
9696
|
9797
LL | type Assoc<const Q: usize>: Trait<'r, Self, Q, K = const { loop {} }>
9898
| ^ its type must not depend on `Self`
@@ -101,7 +101,7 @@ LL | type Assoc<const Q: usize>: Trait<'r, Self, Q, K = const { loop {} }>
101101
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
102102

103103
error: the type of the associated constant `K` must not depend on generic parameters
104-
--> $DIR/assoc-const-eq-param-in-ty.rs:53:52
104+
--> $DIR/assoc-const-eq-param-in-ty.rs:54:52
105105
|
106106
LL | type Assoc<const Q: usize>: Trait<'r, Self, Q, K = const { loop {} }>
107107
| - ^ its type must not depend on the const parameter `Q`

‎tests/ui/associated-consts/assoc-const-eq-supertraits.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
min_generic_const_args,
99
adt_const_params,
1010
unsized_const_params,
11+
generic_const_parameter_types,
1112
)]
1213
#![allow(incomplete_features)]
1314

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
error: anonymous constants referencing generics are not yet supported
2+
--> $DIR/type_const-generic-param-in-type.rs:9:53
3+
|
4+
LL | const FOO<T: core::marker::ConstParamTy_>: [T; 0] = const { [] };
5+
| ^^^^^^^^^^^^
6+
7+
error: anonymous constants referencing generics are not yet supported
8+
--> $DIR/type_const-generic-param-in-type.rs:14:38
9+
|
10+
LL | const BAR<const N: usize>: [(); N] = const { [] };
11+
| ^^^^^^^^^^^^
12+
13+
error: anonymous constants with lifetimes in their type are not yet supported
14+
--> $DIR/type_const-generic-param-in-type.rs:19:30
15+
|
16+
LL | const BAZ<'a>: [&'a (); 0] = const { [] };
17+
| ^^^^^^^^^^^^
18+
19+
error: anonymous constants referencing generics are not yet supported
20+
--> $DIR/type_const-generic-param-in-type.rs:39:59
21+
|
22+
LL | const ASSOC<T: core::marker::ConstParamTy_>: [T; 0] = const { [] };
23+
| ^^^^^^^^^^^^
24+
25+
error: anonymous constants referencing generics are not yet supported
26+
--> $DIR/type_const-generic-param-in-type.rs:44:50
27+
|
28+
LL | const ASSOC_CONST<const N: usize>: [(); N] = const { [] };
29+
| ^^^^^^^^^^^^
30+
31+
error: anonymous constants with lifetimes in their type are not yet supported
32+
--> $DIR/type_const-generic-param-in-type.rs:49:39
33+
|
34+
LL | const ASSOC_LT<'a>: [&'a (); 0] = const { [] };
35+
| ^^^^^^^^^^^^
36+
37+
error: aborting due to 6 previous errors
38+

0 commit comments

Comments
 (0)