diff options
| author | varkor <github@varkor.com> | 2020-01-20 15:22:12 +0000 |
|---|---|---|
| committer | varkor <github@varkor.com> | 2020-01-21 01:03:15 +0000 |
| commit | dd0507c054ea27ae836025761908d339a478e0ab (patch) | |
| tree | 46d1061dacc21dd0d2a235604364ec3db08077d9 /src/librustc | |
| parent | 900811e43047fc5593f39b0363373530b02c87e0 (diff) | |
| download | rust-dd0507c054ea27ae836025761908d339a478e0ab.tar.gz rust-dd0507c054ea27ae836025761908d339a478e0ab.zip | |
Make `TooGeneric` error in WF checking a proper error
`TooGeneric` is encountered during WF checking when we cannot determine that a constant involving a generic parameter will always be evaluated successfully (rather than resulting in an error). In these cases, the burden of proof should be with the caller, so that we can avoid post-monomorphisation tim errors (which was the previous previous behaviour). This commit ensures that this situation produces a proper compiler error, rather than silently ignoring it or ICEing.
Diffstat (limited to 'src/librustc')
| -rw-r--r-- | src/librustc/traits/error_reporting/mod.rs | 34 |
1 files changed, 23 insertions, 11 deletions
diff --git a/src/librustc/traits/error_reporting/mod.rs b/src/librustc/traits/error_reporting/mod.rs index 646cb80bffd..f3dc79f0ff6 100644 --- a/src/librustc/traits/error_reporting/mod.rs +++ b/src/librustc/traits/error_reporting/mod.rs @@ -914,17 +914,29 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { report_object_safety_error(self.tcx, span, did, violations) } - // 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), - ); + ConstEvalFailure(ErrorHandled::TooGeneric) => { + // In this instance, we have a const expression containing an unevaluated + // generic parameter. We have no idea whether this expression is valid or + // not (e.g. it might result in an error), but we don't want to just assume + // that it's okay, because that might result in post-monomorphisation time + // errors. The onus is really on the caller to provide values that it can + // prove are well-formed. + let mut err = self + .tcx + .sess + .struct_span_err(span, "constant expression depends on a generic parameter"); + // FIXME(const_generics): we should suggest to the user how they can resolve this + // issue. However, this is currently not actually possible + // (see https://github.com/rust-lang/rust/issues/66962#issuecomment-575907083). + err.note("this may fail depending on what value the parameter takes"); + err + } + + // Already reported in the query. + ConstEvalFailure(ErrorHandled::Reported) => { + self.tcx + .sess + .delay_span_bug(span, &format!("constant in type had an ignored error")); return; } |
