From 425fb58cacb9dbded92e46ee1bdeaa9dda4a219e Mon Sep 17 00:00:00 2001 From: varkor Date: Sat, 16 Feb 2019 13:03:58 +0000 Subject: [PATCH] Don't abort early when collecting const generics --- src/librustc_typeck/collect.rs | 5 +++-- .../ui/const-generics/const-param-before-other-params.rs | 1 + .../const-generics/const-param-before-other-params.stderr | 8 +++++++- src/test/ui/feature-gates/feature-gate-const_generics.rs | 1 + .../ui/feature-gates/feature-gate-const_generics.stderr | 8 +++++++- 5 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index 8f382243bb5..84de38beafa 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -1053,12 +1053,13 @@ fn generics_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx ty ); } + // Emit an error, but skip the parameter rather than aborting to + // continue to get other errors. tcx.sess.struct_span_err( param.span, "const generics in any position are currently unsupported", ).emit(); - tcx.sess.abort_if_errors(); - bug!(); + None } _ => None, }), diff --git a/src/test/ui/const-generics/const-param-before-other-params.rs b/src/test/ui/const-generics/const-param-before-other-params.rs index 3f120cbc4d3..47f826789e0 100644 --- a/src/test/ui/const-generics/const-param-before-other-params.rs +++ b/src/test/ui/const-generics/const-param-before-other-params.rs @@ -8,6 +8,7 @@ fn foo(_: T) { fn bar(_: &'a ()) { //~^ ERROR lifetime parameters must be declared prior to const parameters + //~^^ ERROR const generics in any position are currently unsupported } fn main() {} diff --git a/src/test/ui/const-generics/const-param-before-other-params.stderr b/src/test/ui/const-generics/const-param-before-other-params.stderr index aedcaf52e26..a43415d0e5a 100644 --- a/src/test/ui/const-generics/const-param-before-other-params.stderr +++ b/src/test/ui/const-generics/const-param-before-other-params.stderr @@ -22,5 +22,11 @@ error: const generics in any position are currently unsupported LL | fn foo(_: T) { | ^ -error: aborting due to 3 previous errors +error: const generics in any position are currently unsupported + --> $DIR/const-param-before-other-params.rs:9:14 + | +LL | fn bar(_: &'a ()) { + | ^ + +error: aborting due to 4 previous errors diff --git a/src/test/ui/feature-gates/feature-gate-const_generics.rs b/src/test/ui/feature-gates/feature-gate-const_generics.rs index a8a4ed57722..907e00b11e5 100644 --- a/src/test/ui/feature-gates/feature-gate-const_generics.rs +++ b/src/test/ui/feature-gates/feature-gate-const_generics.rs @@ -2,5 +2,6 @@ fn foo() {} //~ ERROR const generics are unstable //~^ const generics in any position are currently unsupported struct Foo([(); X]); //~ ERROR const generics are unstable +//~^ const generics in any position are currently unsupported fn main() {} diff --git a/src/test/ui/feature-gates/feature-gate-const_generics.stderr b/src/test/ui/feature-gates/feature-gate-const_generics.stderr index 905cc07b6a1..3ab1aa2367f 100644 --- a/src/test/ui/feature-gates/feature-gate-const_generics.stderr +++ b/src/test/ui/feature-gates/feature-gate-const_generics.stderr @@ -20,6 +20,12 @@ error: const generics in any position are currently unsupported LL | fn foo() {} //~ ERROR const generics are unstable | ^ -error: aborting due to 3 previous errors +error: const generics in any position are currently unsupported + --> $DIR/feature-gate-const_generics.rs:4:18 + | +LL | struct Foo([(); X]); //~ ERROR const generics are unstable + | ^ + +error: aborting due to 4 previous errors For more information about this error, try `rustc --explain E0658`.