Skip to content

Commit 3890425

Browse files
authored
Unrolled build for rust-lang#128020
Rollup merge of rust-lang#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 rust-lang#127970 Fixes rust-lang#127009 r? ``@BoxyUwU``
2 parents 0f8534e + 3862095 commit 3890425

18 files changed

+110
-30
lines changed

compiler/rustc_ast_passes/messages.ftl

+3
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

+7
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

+16
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

+1-5
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

+5-1
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

-11
This file was deleted.

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

+2-1
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

+7-1
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

+2-1
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() {}
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

tests/ui/traits/non_lifetime_binders/bad-suggestion-on-missing-assoc.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ trait TraitC {}
1818
fn foo<T>()
1919
where
2020
for<const N: u8 = { T::A }> T: TraitA<AsA = impl TraitB<AsB = impl TraitC>>,
21-
//~^ ERROR defaults for generic parameters are not allowed in `for<...>` binders
21+
//~^ ERROR late-bound const parameters cannot be used currently
22+
//~| ERROR defaults for generic parameters are not allowed in `for<...>` binders
2223
//~| ERROR `impl Trait` is not allowed in bounds
2324
{
2425
}

tests/ui/traits/non_lifetime_binders/bad-suggestion-on-missing-assoc.stderr

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
error: late-bound const parameters cannot be used currently
2+
--> $DIR/bad-suggestion-on-missing-assoc.rs:20:15
3+
|
4+
LL | for<const N: u8 = { T::A }> T: TraitA<AsA = impl TraitB<AsB = impl TraitC>>,
5+
| ^
6+
17
warning: the feature `generic_const_exprs` is incomplete and may not be safe to use and/or cause compiler crashes
28
--> $DIR/bad-suggestion-on-missing-assoc.rs:1:12
39
|
@@ -29,6 +35,6 @@ LL | for<const N: u8 = { T::A }> T: TraitA<AsA = impl TraitB<AsB = impl Trai
2935
|
3036
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
3137

32-
error: aborting due to 2 previous errors; 2 warnings emitted
38+
error: aborting due to 3 previous errors; 2 warnings emitted
3339

3440
For more information about this error, try `rustc --explain E0562`.

tests/ui/traits/non_lifetime_binders/binder-defaults-112547.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
pub fn bar()
55
where
66
for<const N: usize = {
7+
//~^ ERROR late-bound const parameters cannot be used currently
8+
//~| ERROR defaults for generic parameters are not allowed in `for<...>` binders
79
(||1usize)()
810
}> V: IntoIterator
9-
//~^^^ ERROR defaults for generic parameters are not allowed in `for<...>` binders
10-
//~^^ ERROR cannot find type `V` in this scope
11+
//~^ ERROR cannot find type `V` in this scope
1112
{
1213
}
1314

tests/ui/traits/non_lifetime_binders/binder-defaults-112547.stderr

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0412]: cannot find type `V` in this scope
2-
--> $DIR/binder-defaults-112547.rs:8:4
2+
--> $DIR/binder-defaults-112547.rs:10:4
33
|
44
LL | }> V: IntoIterator
55
| ^ not found in this scope
@@ -9,6 +9,12 @@ help: you might be missing a type parameter
99
LL | pub fn bar<V>()
1010
| +++
1111

12+
error: late-bound const parameters cannot be used currently
13+
--> $DIR/binder-defaults-112547.rs:6:15
14+
|
15+
LL | for<const N: usize = {
16+
| ^
17+
1218
warning: the feature `non_lifetime_binders` is incomplete and may not be safe to use and/or cause compiler crashes
1319
--> $DIR/binder-defaults-112547.rs:1:12
1420
|
@@ -23,10 +29,12 @@ error: defaults for generic parameters are not allowed in `for<...>` binders
2329
|
2430
LL | for<const N: usize = {
2531
| _________^
32+
LL | |
33+
LL | |
2634
LL | | (||1usize)()
2735
LL | | }> V: IntoIterator
2836
| |_^
2937

30-
error: aborting due to 2 previous errors; 1 warning emitted
38+
error: aborting due to 3 previous errors; 1 warning emitted
3139

3240
For more information about this error, try `rustc --explain E0412`.

tests/ui/traits/non_lifetime_binders/binder-defaults-119489.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
fn fun()
66
where
77
for<T = (), const N: usize = 1> ():,
8-
//~^ ERROR defaults for generic parameters are not allowed in `for<...>` binders
9-
//~| ERROR defaults for generic parameters are not allowed in `for<...>` binders
8+
//~^ ERROR late-bound const parameters cannot be used currently
9+
//~| ERROR defaults for generic parameters are not allowed in `for<...>` binders
10+
//~| ERROR defaults for generic parameters are not allowed in `for<...>` binders
1011
{}
1112

1213
fn main() {}

tests/ui/traits/non_lifetime_binders/binder-defaults-119489.stderr

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
error: late-bound const parameters cannot be used currently
2+
--> $DIR/binder-defaults-119489.rs:7:23
3+
|
4+
LL | for<T = (), const N: usize = 1> ():,
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/binder-defaults-119489.rs:1:12
39
|
@@ -27,5 +33,5 @@ error: defaults for generic parameters are not allowed in `for<...>` binders
2733
LL | for<T = (), const N: usize = 1> ():,
2834
| ^^^^^^^^^^^^^^^^^^
2935

30-
error: aborting due to 2 previous errors; 2 warnings emitted
36+
error: aborting due to 3 previous errors; 2 warnings emitted
3137

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#![feature(non_lifetime_binders)]
2+
//~^ WARN the feature `non_lifetime_binders` is incomplete
3+
4+
fn b()
5+
where
6+
for<const C: usize> [(); C]: Copy,
7+
//~^ ERROR late-bound const parameters cannot be used currently
8+
{
9+
}
10+
11+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error: late-bound const parameters cannot be used currently
2+
--> $DIR/late-const-param-wf.rs:6:15
3+
|
4+
LL | for<const C: usize> [(); C]: Copy,
5+
| ^
6+
7+
warning: the feature `non_lifetime_binders` is incomplete and may not be safe to use and/or cause compiler crashes
8+
--> $DIR/late-const-param-wf.rs:1:12
9+
|
10+
LL | #![feature(non_lifetime_binders)]
11+
| ^^^^^^^^^^^^^^^^^^^^
12+
|
13+
= note: see issue #108185 <https://github.com/rust-lang/rust/issues/108185> for more information
14+
= note: `#[warn(incomplete_features)]` on by default
15+
16+
error: aborting due to 1 previous error; 1 warning emitted
17+

0 commit comments

Comments
 (0)