review
This commit is contained in:
parent
9a493ced74
commit
2f893e458a
@ -23,6 +23,12 @@ pub enum ErrorHandled {
|
|||||||
TooGeneric,
|
TooGeneric,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<ErrorReported> for ErrorHandled {
|
||||||
|
fn from(err: ErrorReported) -> ErrorHandled {
|
||||||
|
ErrorHandled::Reported(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
CloneTypeFoldableAndLiftImpls! {
|
CloneTypeFoldableAndLiftImpls! {
|
||||||
ErrorHandled,
|
ErrorHandled,
|
||||||
}
|
}
|
||||||
|
@ -32,9 +32,7 @@ pub fn is_const_evaluatable<'cx, 'tcx>(
|
|||||||
) -> Result<(), ErrorHandled> {
|
) -> Result<(), ErrorHandled> {
|
||||||
debug!("is_const_evaluatable({:?}, {:?})", def, substs);
|
debug!("is_const_evaluatable({:?}, {:?})", def, substs);
|
||||||
if infcx.tcx.features().const_evaluatable_checked {
|
if infcx.tcx.features().const_evaluatable_checked {
|
||||||
if let Some(ct) =
|
if let Some(ct) = AbstractConst::new(infcx.tcx, def, substs)? {
|
||||||
AbstractConst::new(infcx.tcx, def, substs).map_err(ErrorHandled::Reported)?
|
|
||||||
{
|
|
||||||
for pred in param_env.caller_bounds() {
|
for pred in param_env.caller_bounds() {
|
||||||
match pred.skip_binders() {
|
match pred.skip_binders() {
|
||||||
ty::PredicateAtom::ConstEvaluatable(b_def, b_substs) => {
|
ty::PredicateAtom::ConstEvaluatable(b_def, b_substs) => {
|
||||||
@ -42,8 +40,7 @@ pub fn is_const_evaluatable<'cx, 'tcx>(
|
|||||||
if b_def == def && b_substs == substs {
|
if b_def == def && b_substs == substs {
|
||||||
debug!("is_const_evaluatable: caller_bound ~~> ok");
|
debug!("is_const_evaluatable: caller_bound ~~> ok");
|
||||||
return Ok(());
|
return Ok(());
|
||||||
} else if AbstractConst::new(infcx.tcx, b_def, b_substs)
|
} else if AbstractConst::new(infcx.tcx, b_def, b_substs)?
|
||||||
.map_err(ErrorHandled::Reported)?
|
|
||||||
.map_or(false, |b_ct| try_unify(infcx.tcx, ct, b_ct))
|
.map_or(false, |b_ct| try_unify(infcx.tcx, ct, b_ct))
|
||||||
{
|
{
|
||||||
debug!("is_const_evaluatable: abstract_const ~~> ok");
|
debug!("is_const_evaluatable: abstract_const ~~> ok");
|
||||||
@ -153,14 +150,12 @@ struct AbstractConstBuilder<'a, 'tcx> {
|
|||||||
|
|
||||||
impl<'a, 'tcx> AbstractConstBuilder<'a, 'tcx> {
|
impl<'a, 'tcx> AbstractConstBuilder<'a, 'tcx> {
|
||||||
fn error(&mut self, span: Option<Span>, msg: &str) -> Result<!, ErrorReported> {
|
fn error(&mut self, span: Option<Span>, msg: &str) -> Result<!, ErrorReported> {
|
||||||
let mut err =
|
self.tcx
|
||||||
self.tcx.sess.struct_span_err(self.body.span, "overly complex generic constant");
|
.sess
|
||||||
if let Some(span) = span {
|
.struct_span_err(self.body.span, "overly complex generic constant")
|
||||||
err.span_note(span, msg);
|
.span_label(span.unwrap_or(self.body.span), msg)
|
||||||
} else {
|
.help("consider moving this anonymous constant into a `const` function")
|
||||||
err.note(msg);
|
.emit();
|
||||||
}
|
|
||||||
err.help("consider moving this anonymous constant into a `const` function").emit();
|
|
||||||
|
|
||||||
Err(ErrorReported)
|
Err(ErrorReported)
|
||||||
}
|
}
|
||||||
|
@ -2,13 +2,10 @@ error: overly complex generic constant
|
|||||||
--> $DIR/closures.rs:3:35
|
--> $DIR/closures.rs:3:35
|
||||||
|
|
|
|
||||||
LL | fn test<const N: usize>() -> [u8; N + (|| 42)()] {}
|
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
|
= help: consider moving this anonymous constant into a `const` function
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
@ -2,26 +2,20 @@ error: overly complex generic constant
|
|||||||
--> $DIR/let-bindings.rs:6:68
|
--> $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 {
|
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
|
= help: consider moving this anonymous constant into a `const` function
|
||||||
|
|
||||||
error: overly complex generic constant
|
error: overly complex generic constant
|
||||||
--> $DIR/let-bindings.rs:6:35
|
--> $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 {
|
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
|
= help: consider moving this anonymous constant into a `const` function
|
||||||
|
|
||||||
error: aborting due to 2 previous errors
|
error: aborting due to 2 previous errors
|
||||||
|
Loading…
x
Reference in New Issue
Block a user