Skip to content

Commit c79034e

Browse files
authoredJan 6, 2020
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 #66962. r? @eddyb
2 parents 2e965e9 + adb46fd commit c79034e

File tree

4 files changed

+41
-1
lines changed

4 files changed

+41
-1
lines changed
 

‎src/librustc/traits/error_reporting.rs

+6
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use crate::hir::Node;
1212
use crate::infer::error_reporting::TypeAnnotationNeeded as ErrorCode;
1313
use crate::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
1414
use crate::infer::{self, InferCtxt};
15+
use crate::mir::interpret::ErrorHandled;
1516
use crate::session::DiagnosticMessageId;
1617
use crate::ty::error::ExpectedFound;
1718
use crate::ty::fast_reject;
@@ -1086,6 +1087,11 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
10861087

10871088
// already reported in the query
10881089
ConstEvalFailure(err) => {
1090+
if let ErrorHandled::TooGeneric = err {
1091+
// Silence this error, as it can be produced during intermediate steps
1092+
// when a constant is not yet able to be evaluated (but will be later).
1093+
return;
1094+
}
10891095
self.tcx.sess.delay_span_bug(
10901096
span,
10911097
&format!("constant in type had an ignored error: {:?}", err),

‎src/librustc_typeck/impl_wf_check.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,10 @@ fn enforce_impl_params_are_constrained(
9898
// (#36836)
9999
tcx.sess.delay_span_bug(
100100
tcx.def_span(impl_def_id),
101-
"potentially unconstrained type parameters weren't evaluated",
101+
&format!(
102+
"potentially unconstrained type parameters weren't evaluated: {:?}",
103+
impl_self_ty,
104+
),
102105
);
103106
return;
104107
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// run-pass
2+
3+
#![feature(const_generics)]
4+
//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash
5+
6+
#[allow(dead_code)]
7+
struct ArithArrayLen<const N: usize>([u32; 0 + N]); // ok
8+
9+
#[derive(PartialEq, Eq)]
10+
struct Config {
11+
arr_size: usize,
12+
}
13+
14+
struct B<const CFG: Config> {
15+
arr: [u8; CFG.arr_size], // ok
16+
}
17+
18+
const C: Config = Config { arr_size: 5 };
19+
20+
fn main() {
21+
let b = B::<C> { arr: [1, 2, 3, 4, 5] };
22+
assert_eq!(b.arr.len(), 5);
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
warning: the feature `const_generics` is incomplete and may cause the compiler to crash
2+
--> $DIR/array-size-in-generic-struct-param.rs:3:12
3+
|
4+
LL | #![feature(const_generics)]
5+
| ^^^^^^^^^^^^^^
6+
|
7+
= note: `#[warn(incomplete_features)]` on by default
8+

0 commit comments

Comments
 (0)