Skip to content

Commit

Permalink
Silence TooGeneric error
Browse files Browse the repository at this point in the history
This error may be produced during intermediate failed attempts at evaluation of a generic const, which may nevertheless succeed later.
  • Loading branch information
varkor committed Jan 5, 2020
1 parent 760ce94 commit adb46fd
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/librustc/traits/error_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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),
Expand Down
5 changes: 4 additions & 1 deletion src/librustc_typeck/impl_wf_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
23 changes: 23 additions & 0 deletions src/test/ui/const-generics/array-size-in-generic-struct-param.rs
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit adb46fd

Please sign in to comment.