Skip to content

Commit bbf0477

Browse files
committed
Re-enable ConstArgKind::Path lowering by default
...and remove the `const_arg_path` feature gate as a result. It was only a stopgap measure to fix the regression that the new lowering introduced (which should now be fixed by this PR).
1 parent 2c42bda commit bbf0477

32 files changed

+69
-198
lines changed

compiler/rustc_ast_lowering/src/asm.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
220220
let parent_def_id = self.current_def_id_parent;
221221
let node_id = self.next_node_id();
222222
// HACK(min_generic_const_args): see lower_anon_const
223-
if !self.tcx.features().const_arg_path
224-
|| !expr.is_potential_trivial_const_arg()
225-
{
223+
if !expr.is_potential_trivial_const_arg() {
226224
self.create_def(
227225
parent_def_id,
228226
node_id,

compiler/rustc_ast_lowering/src/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
387387
let node_id = self.next_node_id();
388388

389389
// HACK(min_generic_const_args): see lower_anon_const
390-
if !self.tcx.features().const_arg_path || !arg.is_potential_trivial_const_arg() {
390+
if !arg.is_potential_trivial_const_arg() {
391391
// Add a definition for the in-band const def.
392392
self.create_def(parent_def_id, node_id, kw::Empty, DefKind::AnonConst, f.span);
393393
}

compiler/rustc_ast_lowering/src/lib.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -2335,7 +2335,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
23352335
span: Span,
23362336
) -> &'hir hir::ConstArg<'hir> {
23372337
let ct_kind = match res {
2338-
Res::Def(DefKind::ConstParam, _) if self.tcx.features().const_arg_path => {
2338+
Res::Def(DefKind::ConstParam, _) => {
23392339
let qpath = self.lower_qpath(
23402340
ty_id,
23412341
&None,
@@ -2410,8 +2410,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
24102410
self.resolver.get_partial_res(expr.id).and_then(|partial_res| partial_res.full_res());
24112411
debug!("res={:?}", maybe_res);
24122412
// FIXME(min_generic_const_args): for now we only lower params to ConstArgKind::Path
2413-
if self.tcx.features().const_arg_path
2414-
&& let Some(res) = maybe_res
2413+
if let Some(res) = maybe_res
24152414
&& let Res::Def(DefKind::ConstParam, _) = res
24162415
&& let ExprKind::Path(qself, path) = &expr.kind
24172416
{
@@ -2442,7 +2441,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
24422441
/// See [`hir::ConstArg`] for when to use this function vs
24432442
/// [`Self::lower_anon_const_to_const_arg`].
24442443
fn lower_anon_const_to_anon_const(&mut self, c: &AnonConst) -> &'hir hir::AnonConst {
2445-
if self.tcx.features().const_arg_path && c.value.is_potential_trivial_const_arg() {
2444+
if c.value.is_potential_trivial_const_arg() {
24462445
// HACK(min_generic_const_args): see DefCollector::visit_anon_const
24472446
// Over there, we guess if this is a bare param and only create a def if
24482447
// we think it's not. However we may can guess wrong (see there for example)

compiler/rustc_feature/src/unstable.rs

-2
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,6 @@ declare_features! (
193193
(unstable, anonymous_lifetime_in_impl_trait, "1.63.0", None),
194194
/// Allows identifying the `compiler_builtins` crate.
195195
(internal, compiler_builtins, "1.13.0", None),
196-
/// Gating for a new desugaring of const arguments of usages of const parameters
197-
(internal, const_arg_path, "1.81.0", None),
198196
/// Allows writing custom MIR
199197
(internal, custom_mir, "1.65.0", None),
200198
/// Outputs useful `assert!` messages

compiler/rustc_middle/src/ty/consts.rs

+5-13
Original file line numberDiff line numberDiff line change
@@ -295,20 +295,12 @@ impl<'tcx> Const<'tcx> {
295295
_ => expr,
296296
};
297297

298-
if let hir::ExprKind::Path(
299-
qpath @ hir::QPath::Resolved(
300-
_,
301-
&hir::Path { res: Res::Def(DefKind::ConstParam, _), .. },
302-
),
303-
) = expr.kind
298+
if let hir::ExprKind::Path(hir::QPath::Resolved(
299+
_,
300+
&hir::Path { res: Res::Def(DefKind::ConstParam, _), .. },
301+
)) = expr.kind
304302
{
305-
if tcx.features().const_arg_path {
306-
span_bug!(
307-
expr.span,
308-
"try_from_lit: received const param which shouldn't be possible"
309-
);
310-
}
311-
return Some(Const::from_param(tcx, qpath, expr.hir_id));
303+
span_bug!(expr.span, "try_from_lit: received const param which shouldn't be possible");
312304
};
313305

314306
let lit_input = match expr.kind {

compiler/rustc_resolve/src/def_collector.rs

+14-16
Original file line numberDiff line numberDiff line change
@@ -347,22 +347,20 @@ impl<'a, 'b, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'b, 'tcx> {
347347
}
348348

349349
fn visit_anon_const(&mut self, constant: &'a AnonConst) {
350-
if self.resolver.tcx.features().const_arg_path {
351-
// HACK(min_generic_const_args): don't create defs for anon consts if we think they will
352-
// later be turned into ConstArgKind::Path's. because this is before resolve is done, we
353-
// may accidentally identify a construction of a unit struct as a param and not create a
354-
// def. we'll then create a def later in ast lowering in this case. the parent of nested
355-
// items will be messed up, but that's ok because there can't be any if we're just looking
356-
// for bare idents.
357-
358-
if matches!(constant.value.maybe_unwrap_block().kind, ExprKind::MacCall(..)) {
359-
// See self.pending_anon_const_info for explanation
360-
self.pending_anon_const_info =
361-
Some(PendingAnonConstInfo { id: constant.id, span: constant.value.span });
362-
return visit::walk_anon_const(self, constant);
363-
} else if constant.value.is_potential_trivial_const_arg() {
364-
return visit::walk_anon_const(self, constant);
365-
}
350+
// HACK(min_generic_const_args): don't create defs for anon consts if we think they will
351+
// later be turned into ConstArgKind::Path's. because this is before resolve is done, we
352+
// may accidentally identify a construction of a unit struct as a param and not create a
353+
// def. we'll then create a def later in ast lowering in this case. the parent of nested
354+
// items will be messed up, but that's ok because there can't be any if we're just looking
355+
// for bare idents.
356+
357+
if matches!(constant.value.maybe_unwrap_block().kind, ExprKind::MacCall(..)) {
358+
// See self.pending_anon_const_info for explanation
359+
self.pending_anon_const_info =
360+
Some(PendingAnonConstInfo { id: constant.id, span: constant.value.span });
361+
return visit::walk_anon_const(self, constant);
362+
} else if constant.value.is_potential_trivial_const_arg() {
363+
return visit::walk_anon_const(self, constant);
366364
}
367365

368366
let def = self.create_def(constant.id, kw::Empty, DefKind::AnonConst, constant.value.span);

compiler/rustc_span/src/symbol.rs

-1
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,6 @@ symbols! {
599599
conservative_impl_trait,
600600
console,
601601
const_allocate,
602-
const_arg_path,
603602
const_async_blocks,
604603
const_closures,
605604
const_compare_raw_pointers,

tests/ui/coherence/negative-coherence/generic_const_type_mismatch.rs

-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
#![feature(with_negative_coherence)]
66
trait Trait {}
77
impl<const N: u8> Trait for [(); N] {}
8-
//~^ ERROR: mismatched types
98
impl<const N: i8> Trait for [(); N] {}
109
//~^ ERROR: conflicting implementations of trait `Trait`
11-
//~| ERROR: mismatched types
1210

1311
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,11 @@
11
error[E0119]: conflicting implementations of trait `Trait` for type `[(); _]`
2-
--> $DIR/generic_const_type_mismatch.rs:9:1
2+
--> $DIR/generic_const_type_mismatch.rs:8:1
33
|
44
LL | impl<const N: u8> Trait for [(); N] {}
55
| ----------------------------------- first implementation here
6-
LL |
76
LL | impl<const N: i8> Trait for [(); N] {}
87
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `[(); _]`
98

10-
error[E0308]: mismatched types
11-
--> $DIR/generic_const_type_mismatch.rs:7:34
12-
|
13-
LL | impl<const N: u8> Trait for [(); N] {}
14-
| ^ expected `usize`, found `u8`
15-
16-
error[E0308]: mismatched types
17-
--> $DIR/generic_const_type_mismatch.rs:9:34
18-
|
19-
LL | impl<const N: i8> Trait for [(); N] {}
20-
| ^ expected `usize`, found `i8`
21-
22-
error: aborting due to 3 previous errors
9+
error: aborting due to 1 previous error
2310

24-
Some errors have detailed explanations: E0119, E0308.
25-
For more information about an error, try `rustc --explain E0119`.
11+
For more information about this error, try `rustc --explain E0119`.

tests/ui/const-generics/bad-subst-const-kind.rs

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ trait Q {
77

88
impl<const N: u64> Q for [u8; N] {
99
//~^ ERROR: the constant `N` is not of type `usize`
10-
//~| ERROR: mismatched types
1110
const ASSOC: usize = 1;
1211
}
1312

tests/ui/const-generics/bad-subst-const-kind.stderr

+2-9
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | impl<const N: u64> Q for [u8; N] {
55
| ^^^^^^^ expected `usize`, found `u64`
66

77
error: the constant `13` is not of type `u64`
8-
--> $DIR/bad-subst-const-kind.rs:14:24
8+
--> $DIR/bad-subst-const-kind.rs:13:24
99
|
1010
LL | pub fn test() -> [u8; <[u8; 13] as Q>::ASSOC] {
1111
| ^^^^^^^^ expected `u64`, found `usize`
@@ -18,12 +18,5 @@ LL | impl<const N: u64> Q for [u8; N] {
1818
| |
1919
| unsatisfied trait bound introduced here
2020

21-
error[E0308]: mismatched types
22-
--> $DIR/bad-subst-const-kind.rs:8:31
23-
|
24-
LL | impl<const N: u64> Q for [u8; N] {
25-
| ^ expected `usize`, found `u64`
26-
27-
error: aborting due to 3 previous errors
21+
error: aborting due to 2 previous errors
2822

29-
For more information about this error, try `rustc --explain E0308`.

tests/ui/const-generics/generic_const_exprs/type_mismatch.rs

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ trait Q {
88
impl<const N: u64> Q for [u8; N] {}
99
//~^ ERROR not all trait items implemented
1010
//~| ERROR the constant `N` is not of type `usize`
11-
//~| ERROR mismatched types
1211

1312
pub fn q_user() -> [u8; <[u8; 13] as Q>::ASSOC] {}
1413
//~^ ERROR the constant `13` is not of type `u64`

tests/ui/const-generics/generic_const_exprs/type_mismatch.stderr

+3-9
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ LL | impl<const N: u64> Q for [u8; N] {}
1414
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `ASSOC` in implementation
1515

1616
error: the constant `13` is not of type `u64`
17-
--> $DIR/type_mismatch.rs:13:26
17+
--> $DIR/type_mismatch.rs:12:26
1818
|
1919
LL | pub fn q_user() -> [u8; <[u8; 13] as Q>::ASSOC] {}
2020
| ^^^^^^^^ expected `u64`, found `usize`
@@ -28,20 +28,14 @@ LL | impl<const N: u64> Q for [u8; N] {}
2828
| unsatisfied trait bound introduced here
2929

3030
error[E0308]: mismatched types
31-
--> $DIR/type_mismatch.rs:13:20
31+
--> $DIR/type_mismatch.rs:12:20
3232
|
3333
LL | pub fn q_user() -> [u8; <[u8; 13] as Q>::ASSOC] {}
3434
| ------ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `[u8; <[u8; 13] as Q>::ASSOC]`, found `()`
3535
| |
3636
| implicitly returns `()` as its body has no tail or `return` expression
3737

38-
error[E0308]: mismatched types
39-
--> $DIR/type_mismatch.rs:8:31
40-
|
41-
LL | impl<const N: u64> Q for [u8; N] {}
42-
| ^ expected `usize`, found `u64`
43-
44-
error: aborting due to 5 previous errors
38+
error: aborting due to 4 previous errors
4539

4640
Some errors have detailed explanations: E0046, E0308.
4741
For more information about an error, try `rustc --explain E0046`.

tests/ui/const-generics/generic_const_exprs/unevaluated-const-ice-119731.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ mod v20 {
2626
}
2727

2828
impl<const v10: usize> v17<v10, v2> {
29-
//~^ ERROR maximum number of nodes exceeded in constant v20::v17::<v10, v2>::{constant#1}
30-
//~| ERROR maximum number of nodes exceeded in constant v20::v17::<v10, v2>::{constant#1}
29+
//~^ ERROR maximum number of nodes exceeded in constant v20::v17::<v10, v2>::{constant#0}
30+
//~| ERROR maximum number of nodes exceeded in constant v20::v17::<v10, v2>::{constant#0}
3131
pub const fn v21() -> v18 {
3232
//~^ ERROR cannot find type `v18` in this scope
3333
v18 { _p: () }

tests/ui/const-generics/generic_const_exprs/unevaluated-const-ice-119731.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,13 @@ help: add `#![feature(adt_const_params)]` to the crate attributes to enable more
7272
LL + #![feature(adt_const_params)]
7373
|
7474

75-
error: maximum number of nodes exceeded in constant v20::v17::<v10, v2>::{constant#1}
75+
error: maximum number of nodes exceeded in constant v20::v17::<v10, v2>::{constant#0}
7676
--> $DIR/unevaluated-const-ice-119731.rs:28:37
7777
|
7878
LL | impl<const v10: usize> v17<v10, v2> {
7979
| ^^
8080

81-
error: maximum number of nodes exceeded in constant v20::v17::<v10, v2>::{constant#1}
81+
error: maximum number of nodes exceeded in constant v20::v17::<v10, v2>::{constant#0}
8282
--> $DIR/unevaluated-const-ice-119731.rs:28:37
8383
|
8484
LL | impl<const v10: usize> v17<v10, v2> {

tests/ui/const-generics/transmute-fail.rs

-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ fn foo<const W: usize, const H: usize>(v: [[u32; H + 1]; W]) -> [[u32; W + 1]; H
1111

1212
fn bar<const W: bool, const H: usize>(v: [[u32; H]; W]) -> [[u32; W]; H] {
1313
//~^ ERROR: the constant `W` is not of type `usize`
14-
//~| ERROR: mismatched types
15-
//~| ERROR: mismatched types
1614
unsafe {
1715
std::mem::transmute(v)
1816
//~^ ERROR: the constant `W` is not of type `usize`

0 commit comments

Comments
 (0)