diff options
| author | Dylan DPC <dylan.dpc@gmail.com> | 2020-01-06 12:00:20 +0530 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-01-06 12:00:20 +0530 |
| commit | c79034ed4751175b61b5419d58abf7466f8905cc (patch) | |
| tree | 2c28ae4fce596dd6a761259f5afc954720b37246 /src | |
| parent | 2e965e9c6deeafb4bbac3599cfdb1d271a759316 (diff) | |
| parent | adb46fd0a49108f08bd0d4b8c95317cfbcbb7941 (diff) | |
| download | rust-c79034ed4751175b61b5419d58abf7466f8905cc.tar.gz rust-c79034ed4751175b61b5419d58abf7466f8905cc.zip | |
Rollup merge of #67906 - varkor:silence-toogeneric, r=nagisa
Silence `TooGeneric` error This error may be produced during intermediate failed attempts at evaluation of a generic const, which may nevertheless succeed later. Fixes https://github.com/rust-lang/rust/issues/66962. r? @eddyb
Diffstat (limited to 'src')
4 files changed, 41 insertions, 1 deletions
diff --git a/src/librustc/traits/error_reporting.rs b/src/librustc/traits/error_reporting.rs index 3fef1dd064e..009e52e479a 100644 --- a/src/librustc/traits/error_reporting.rs +++ b/src/librustc/traits/error_reporting.rs @@ -12,6 +12,7 @@ use crate::hir::Node; use crate::infer::error_reporting::TypeAnnotationNeeded as ErrorCode; use crate::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; use crate::infer::{self, InferCtxt}; +use crate::mir::interpret::ErrorHandled; use crate::session::DiagnosticMessageId; use crate::ty::error::ExpectedFound; use crate::ty::fast_reject; @@ -1086,6 +1087,11 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { // already reported in the query ConstEvalFailure(err) => { + if let ErrorHandled::TooGeneric = err { + // Silence this error, as it can be produced during intermediate steps + // when a constant is not yet able to be evaluated (but will be later). + return; + } self.tcx.sess.delay_span_bug( span, &format!("constant in type had an ignored error: {:?}", err), diff --git a/src/librustc_typeck/impl_wf_check.rs b/src/librustc_typeck/impl_wf_check.rs index 770aeb6869a..f8c1af038e9 100644 --- a/src/librustc_typeck/impl_wf_check.rs +++ b/src/librustc_typeck/impl_wf_check.rs @@ -98,7 +98,10 @@ fn enforce_impl_params_are_constrained( // (#36836) tcx.sess.delay_span_bug( tcx.def_span(impl_def_id), - "potentially unconstrained type parameters weren't evaluated", + &format!( + "potentially unconstrained type parameters weren't evaluated: {:?}", + impl_self_ty, + ), ); return; } diff --git a/src/test/ui/const-generics/array-size-in-generic-struct-param.rs b/src/test/ui/const-generics/array-size-in-generic-struct-param.rs new file mode 100644 index 00000000000..f3be7b56db5 --- /dev/null +++ b/src/test/ui/const-generics/array-size-in-generic-struct-param.rs @@ -0,0 +1,23 @@ +// run-pass + +#![feature(const_generics)] +//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash + +#[allow(dead_code)] +struct ArithArrayLen<const N: usize>([u32; 0 + N]); // ok + +#[derive(PartialEq, Eq)] +struct Config { + arr_size: usize, +} + +struct B<const CFG: Config> { + arr: [u8; CFG.arr_size], // ok +} + +const C: Config = Config { arr_size: 5 }; + +fn main() { + let b = B::<C> { arr: [1, 2, 3, 4, 5] }; + assert_eq!(b.arr.len(), 5); +} diff --git a/src/test/ui/const-generics/array-size-in-generic-struct-param.stderr b/src/test/ui/const-generics/array-size-in-generic-struct-param.stderr new file mode 100644 index 00000000000..274f9769702 --- /dev/null +++ b/src/test/ui/const-generics/array-size-in-generic-struct-param.stderr @@ -0,0 +1,8 @@ +warning: the feature `const_generics` is incomplete and may cause the compiler to crash + --> $DIR/array-size-in-generic-struct-param.rs:3:12 + | +LL | #![feature(const_generics)] + | ^^^^^^^^^^^^^^ + | + = note: `#[warn(incomplete_features)]` on by default + |
