Skip to content

Commit

Permalink
review
Browse files Browse the repository at this point in the history
  • Loading branch information
lcnr committed Sep 21, 2020
1 parent 9a493ce commit 2f893e4
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 31 deletions.
6 changes: 6 additions & 0 deletions compiler/rustc_middle/src/mir/interpret/error.rs
Expand Up @@ -23,6 +23,12 @@ pub enum ErrorHandled {
TooGeneric,
}

impl From<ErrorReported> for ErrorHandled {
fn from(err: ErrorReported) -> ErrorHandled {
ErrorHandled::Reported(err)
}
}

CloneTypeFoldableAndLiftImpls! {
ErrorHandled,
}
Expand Down
21 changes: 8 additions & 13 deletions compiler/rustc_trait_selection/src/traits/const_evaluatable.rs
Expand Up @@ -32,18 +32,15 @@ pub fn is_const_evaluatable<'cx, 'tcx>(
) -> Result<(), ErrorHandled> {
debug!("is_const_evaluatable({:?}, {:?})", def, substs);
if infcx.tcx.features().const_evaluatable_checked {
if let Some(ct) =
AbstractConst::new(infcx.tcx, def, substs).map_err(ErrorHandled::Reported)?
{
if let Some(ct) = AbstractConst::new(infcx.tcx, def, substs)? {
for pred in param_env.caller_bounds() {
match pred.skip_binders() {
ty::PredicateAtom::ConstEvaluatable(b_def, b_substs) => {
debug!("is_const_evaluatable: caller_bound={:?}, {:?}", b_def, b_substs);
if b_def == def && b_substs == substs {
debug!("is_const_evaluatable: caller_bound ~~> ok");
return Ok(());
} else if AbstractConst::new(infcx.tcx, b_def, b_substs)
.map_err(ErrorHandled::Reported)?
} else if AbstractConst::new(infcx.tcx, b_def, b_substs)?
.map_or(false, |b_ct| try_unify(infcx.tcx, ct, b_ct))
{
debug!("is_const_evaluatable: abstract_const ~~> ok");
Expand Down Expand Up @@ -153,14 +150,12 @@ struct AbstractConstBuilder<'a, 'tcx> {

impl<'a, 'tcx> AbstractConstBuilder<'a, 'tcx> {
fn error(&mut self, span: Option<Span>, msg: &str) -> Result<!, ErrorReported> {
let mut err =
self.tcx.sess.struct_span_err(self.body.span, "overly complex generic constant");
if let Some(span) = span {
err.span_note(span, msg);
} else {
err.note(msg);
}
err.help("consider moving this anonymous constant into a `const` function").emit();
self.tcx
.sess
.struct_span_err(self.body.span, "overly complex generic constant")
.span_label(span.unwrap_or(self.body.span), msg)
.help("consider moving this anonymous constant into a `const` function")
.emit();

Err(ErrorReported)
}
Expand Down
Expand Up @@ -2,13 +2,10 @@ error: overly complex generic constant
--> $DIR/closures.rs:3:35
|
LL | fn test<const N: usize>() -> [u8; N + (|| 42)()] {}
| ^^^^^^^^^^^^^
| ^^^^-------^^
| |
| unsupported rvalue
|
note: unsupported rvalue
--> $DIR/closures.rs:3:39
|
LL | fn test<const N: usize>() -> [u8; N + (|| 42)()] {}
| ^^^^^^^
= help: consider moving this anonymous constant into a `const` function

error: aborting due to previous error
Expand Down
Expand Up @@ -2,26 +2,20 @@ error: overly complex generic constant
--> $DIR/let-bindings.rs:6:68
|
LL | fn test<const N: usize>() -> [u8; { let x = N; N + 1 }] where [u8; { let x = N; N + 1 }]: Default {
| ^^^^^^^^^^^^^^^^^^^^
| ^^^^^^-^^^^^^^^^^^^^
| |
| unsupported statement
|
note: unsupported statement
--> $DIR/let-bindings.rs:6:74
|
LL | fn test<const N: usize>() -> [u8; { let x = N; N + 1 }] where [u8; { let x = N; N + 1 }]: Default {
| ^
= help: consider moving this anonymous constant into a `const` function

error: overly complex generic constant
--> $DIR/let-bindings.rs:6:35
|
LL | fn test<const N: usize>() -> [u8; { let x = N; N + 1 }] where [u8; { let x = N; N + 1 }]: Default {
| ^^^^^^^^^^^^^^^^^^^^
| ^^^^^^-^^^^^^^^^^^^^
| |
| unsupported statement
|
note: unsupported statement
--> $DIR/let-bindings.rs:6:41
|
LL | fn test<const N: usize>() -> [u8; { let x = N; N + 1 }] where [u8; { let x = N; N + 1 }]: Default {
| ^
= help: consider moving this anonymous constant into a `const` function

error: aborting due to 2 previous errors
Expand Down

0 comments on commit 2f893e4

Please sign in to comment.