Skip to content

Commit 425fb58

Browse files
committed
Don't abort early when collecting const generics
1 parent 2a1b6c5 commit 425fb58

File tree

5 files changed

+19
-4
lines changed

5 files changed

+19
-4
lines changed

src/librustc_typeck/collect.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1053,12 +1053,13 @@ fn generics_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx ty
10531053
);
10541054
}
10551055

1056+
// Emit an error, but skip the parameter rather than aborting to
1057+
// continue to get other errors.
10561058
tcx.sess.struct_span_err(
10571059
param.span,
10581060
"const generics in any position are currently unsupported",
10591061
).emit();
1060-
tcx.sess.abort_if_errors();
1061-
bug!();
1062+
None
10621063
}
10631064
_ => None,
10641065
}),

src/test/ui/const-generics/const-param-before-other-params.rs

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ fn foo<const X: (), T>(_: T) {
88

99
fn bar<const X: (), 'a>(_: &'a ()) {
1010
//~^ ERROR lifetime parameters must be declared prior to const parameters
11+
//~^^ ERROR const generics in any position are currently unsupported
1112
}
1213

1314
fn main() {}

src/test/ui/const-generics/const-param-before-other-params.stderr

+7-1
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,11 @@ error: const generics in any position are currently unsupported
2222
LL | fn foo<const X: (), T>(_: T) {
2323
| ^
2424

25-
error: aborting due to 3 previous errors
25+
error: const generics in any position are currently unsupported
26+
--> $DIR/const-param-before-other-params.rs:9:14
27+
|
28+
LL | fn bar<const X: (), 'a>(_: &'a ()) {
29+
| ^
30+
31+
error: aborting due to 4 previous errors
2632

src/test/ui/feature-gates/feature-gate-const_generics.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ fn foo<const X: ()>() {} //~ ERROR const generics are unstable
22
//~^ const generics in any position are currently unsupported
33

44
struct Foo<const X: usize>([(); X]); //~ ERROR const generics are unstable
5+
//~^ const generics in any position are currently unsupported
56

67
fn main() {}

src/test/ui/feature-gates/feature-gate-const_generics.stderr

+7-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ error: const generics in any position are currently unsupported
2020
LL | fn foo<const X: ()>() {} //~ ERROR const generics are unstable
2121
| ^
2222

23-
error: aborting due to 3 previous errors
23+
error: const generics in any position are currently unsupported
24+
--> $DIR/feature-gate-const_generics.rs:4:18
25+
|
26+
LL | struct Foo<const X: usize>([(); X]); //~ ERROR const generics are unstable
27+
| ^
28+
29+
error: aborting due to 4 previous errors
2430

2531
For more information about this error, try `rustc --explain E0658`.

0 commit comments

Comments
 (0)