Skip to content

Commit 2ef7699

Browse files
Rollup merge of #128020 - compiler-errors:nlb-no-const, r=BoxyUwU
Just totally fully deny late-bound consts Kinda don't care about supporting this until we have where clauses on binders. They're super busted and should be reworked in due time, and they are approximately 100% useless until then 😸 Fixes #127970 Fixes #127009 r? ``@BoxyUwU``
2 parents 5bd7525 + 3862095 commit 2ef7699

18 files changed

+110
-30
lines changed

compiler/rustc_ast_passes/messages.ftl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ ast_passes_fn_without_body =
120120
ast_passes_forbidden_bound =
121121
bounds cannot be used in this context
122122
123+
ast_passes_forbidden_const_param =
124+
late-bound const parameters cannot be used currently
125+
123126
ast_passes_forbidden_default =
124127
`default` is only allowed on items in trait impls
125128
.label = `default` because of this

compiler/rustc_ast_passes/src/errors.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,13 @@ pub struct ForbiddenBound {
6969
pub spans: Vec<Span>,
7070
}
7171

72+
#[derive(Diagnostic)]
73+
#[diag(ast_passes_forbidden_const_param)]
74+
pub struct ForbiddenConstParam {
75+
#[primary_span]
76+
pub const_param_spans: Vec<Span>,
77+
}
78+
7279
#[derive(Diagnostic)]
7380
#[diag(ast_passes_fn_param_too_many)]
7481
pub struct FnParamTooMany {

compiler/rustc_ast_passes/src/feature_gate.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,22 @@ impl<'a> PostExpansionVisitor<'a> {
162162
crate::fluent_generated::ast_passes_forbidden_non_lifetime_param
163163
);
164164

165+
// FIXME(non_lifetime_binders): Const bound params are pretty broken.
166+
// Let's keep users from using this feature accidentally.
167+
if self.features.non_lifetime_binders {
168+
let const_param_spans: Vec<_> = params
169+
.iter()
170+
.filter_map(|param| match param.kind {
171+
ast::GenericParamKind::Const { .. } => Some(param.ident.span),
172+
_ => None,
173+
})
174+
.collect();
175+
176+
if !const_param_spans.is_empty() {
177+
self.sess.dcx().emit_err(errors::ForbiddenConstParam { const_param_spans });
178+
}
179+
}
180+
165181
for param in params {
166182
if !param.bounds.is_empty() {
167183
let spans: Vec<_> = param.bounds.iter().map(|b| b.span()).collect();

compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2094,11 +2094,7 @@ pub fn deny_non_region_late_bound(
20942094
format!("late-bound {what} parameter not allowed on {where_}"),
20952095
);
20962096

2097-
let guar = if tcx.features().non_lifetime_binders && first {
2098-
diag.emit()
2099-
} else {
2100-
diag.delay_as_bug()
2101-
};
2097+
let guar = diag.emit_unless(!tcx.features().non_lifetime_binders || !first);
21022098

21032099
first = false;
21042100
*arg = ResolvedArg::Error(guar);

compiler/rustc_resolve/src/late.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2763,7 +2763,11 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
27632763
let res = match kind {
27642764
RibKind::Item(..) | RibKind::AssocItem => Res::Def(def_kind, def_id.to_def_id()),
27652765
RibKind::Normal => {
2766-
if self.r.tcx.features().non_lifetime_binders {
2766+
// FIXME(non_lifetime_binders): Stop special-casing
2767+
// const params to error out here.
2768+
if self.r.tcx.features().non_lifetime_binders
2769+
&& matches!(param.kind, GenericParamKind::Type { .. })
2770+
{
27672771
Res::Def(def_kind, def_id.to_def_id())
27682772
} else {
27692773
Res::Err

tests/crashes/127009.rs

Lines changed: 0 additions & 11 deletions
This file was deleted.

tests/ui/closures/binder/const-bound.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33

44
fn main() {
55
for<const N: i32> || -> () {};
6-
//~^ ERROR late-bound const parameter not allowed on closures
6+
//~^ ERROR late-bound const parameters cannot be used currently
7+
//~| ERROR late-bound const parameter not allowed on closures
78
}

tests/ui/closures/binder/const-bound.stderr

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
error: late-bound const parameters cannot be used currently
2+
--> $DIR/const-bound.rs:5:15
3+
|
4+
LL | for<const N: i32> || -> () {};
5+
| ^
6+
17
warning: the feature `non_lifetime_binders` is incomplete and may not be safe to use and/or cause compiler crashes
28
--> $DIR/const-bound.rs:1:37
39
|
@@ -13,5 +19,5 @@ error: late-bound const parameter not allowed on closures
1319
LL | for<const N: i32> || -> () {};
1420
| ^^^^^^^^^^^^
1521

16-
error: aborting due to 1 previous error; 1 warning emitted
22+
error: aborting due to 2 previous errors; 1 warning emitted
1723

tests/ui/const-generics/generic_const_exprs/no-entry-found-for-key-ice-gce-nlb-113133.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
pub fn foo()
88
where
99
for<const N: usize = { const fn bar() {} bar(); 1 }> ():,
10-
//~^ ERROR defaults for generic parameters are not allowed in `for<...>` binders
10+
//~^ ERROR late-bound const parameters cannot be used currently
11+
//~| ERROR defaults for generic parameters are not allowed in `for<...>` binders
1112
{}
1213

1314
fn main() {}
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1+
error: late-bound const parameters cannot be used currently
2+
--> $DIR/no-entry-found-for-key-ice-gce-nlb-113133.rs:9:15
3+
|
4+
LL | for<const N: usize = { const fn bar() {} bar(); 1 }> ():,
5+
| ^
6+
17
error: defaults for generic parameters are not allowed in `for<...>` binders
28
--> $DIR/no-entry-found-for-key-ice-gce-nlb-113133.rs:9:9
39
|
410
LL | for<const N: usize = { const fn bar() {} bar(); 1 }> ():,
511
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
612

7-
error: aborting due to 1 previous error
13+
error: aborting due to 2 previous errors
814

0 commit comments

Comments
 (0)