Skip to content

Commit 2f893e4

Browse files
committed
review
1 parent 9a493ce commit 2f893e4

File tree

4 files changed

+23
-31
lines changed

4 files changed

+23
-31
lines changed

compiler/rustc_middle/src/mir/interpret/error.rs

+6
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ pub enum ErrorHandled {
2323
TooGeneric,
2424
}
2525

26+
impl From<ErrorReported> for ErrorHandled {
27+
fn from(err: ErrorReported) -> ErrorHandled {
28+
ErrorHandled::Reported(err)
29+
}
30+
}
31+
2632
CloneTypeFoldableAndLiftImpls! {
2733
ErrorHandled,
2834
}

compiler/rustc_trait_selection/src/traits/const_evaluatable.rs

+8-13
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,15 @@ pub fn is_const_evaluatable<'cx, 'tcx>(
3232
) -> Result<(), ErrorHandled> {
3333
debug!("is_const_evaluatable({:?}, {:?})", def, substs);
3434
if infcx.tcx.features().const_evaluatable_checked {
35-
if let Some(ct) =
36-
AbstractConst::new(infcx.tcx, def, substs).map_err(ErrorHandled::Reported)?
37-
{
35+
if let Some(ct) = AbstractConst::new(infcx.tcx, def, substs)? {
3836
for pred in param_env.caller_bounds() {
3937
match pred.skip_binders() {
4038
ty::PredicateAtom::ConstEvaluatable(b_def, b_substs) => {
4139
debug!("is_const_evaluatable: caller_bound={:?}, {:?}", b_def, b_substs);
4240
if b_def == def && b_substs == substs {
4341
debug!("is_const_evaluatable: caller_bound ~~> ok");
4442
return Ok(());
45-
} else if AbstractConst::new(infcx.tcx, b_def, b_substs)
46-
.map_err(ErrorHandled::Reported)?
43+
} else if AbstractConst::new(infcx.tcx, b_def, b_substs)?
4744
.map_or(false, |b_ct| try_unify(infcx.tcx, ct, b_ct))
4845
{
4946
debug!("is_const_evaluatable: abstract_const ~~> ok");
@@ -153,14 +150,12 @@ struct AbstractConstBuilder<'a, 'tcx> {
153150

154151
impl<'a, 'tcx> AbstractConstBuilder<'a, 'tcx> {
155152
fn error(&mut self, span: Option<Span>, msg: &str) -> Result<!, ErrorReported> {
156-
let mut err =
157-
self.tcx.sess.struct_span_err(self.body.span, "overly complex generic constant");
158-
if let Some(span) = span {
159-
err.span_note(span, msg);
160-
} else {
161-
err.note(msg);
162-
}
163-
err.help("consider moving this anonymous constant into a `const` function").emit();
153+
self.tcx
154+
.sess
155+
.struct_span_err(self.body.span, "overly complex generic constant")
156+
.span_label(span.unwrap_or(self.body.span), msg)
157+
.help("consider moving this anonymous constant into a `const` function")
158+
.emit();
164159

165160
Err(ErrorReported)
166161
}

src/test/ui/const-generics/const_evaluatable_checked/closures.stderr

+3-6
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,10 @@ error: overly complex generic constant
22
--> $DIR/closures.rs:3:35
33
|
44
LL | fn test<const N: usize>() -> [u8; N + (|| 42)()] {}
5-
| ^^^^^^^^^^^^^
5+
| ^^^^-------^^
6+
| |
7+
| unsupported rvalue
68
|
7-
note: unsupported rvalue
8-
--> $DIR/closures.rs:3:39
9-
|
10-
LL | fn test<const N: usize>() -> [u8; N + (|| 42)()] {}
11-
| ^^^^^^^
129
= help: consider moving this anonymous constant into a `const` function
1310

1411
error: aborting due to previous error

src/test/ui/const-generics/const_evaluatable_checked/let-bindings.stderr

+6-12
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,20 @@ error: overly complex generic constant
22
--> $DIR/let-bindings.rs:6:68
33
|
44
LL | fn test<const N: usize>() -> [u8; { let x = N; N + 1 }] where [u8; { let x = N; N + 1 }]: Default {
5-
| ^^^^^^^^^^^^^^^^^^^^
5+
| ^^^^^^-^^^^^^^^^^^^^
6+
| |
7+
| unsupported statement
68
|
7-
note: unsupported statement
8-
--> $DIR/let-bindings.rs:6:74
9-
|
10-
LL | fn test<const N: usize>() -> [u8; { let x = N; N + 1 }] where [u8; { let x = N; N + 1 }]: Default {
11-
| ^
129
= help: consider moving this anonymous constant into a `const` function
1310

1411
error: overly complex generic constant
1512
--> $DIR/let-bindings.rs:6:35
1613
|
1714
LL | fn test<const N: usize>() -> [u8; { let x = N; N + 1 }] where [u8; { let x = N; N + 1 }]: Default {
18-
| ^^^^^^^^^^^^^^^^^^^^
15+
| ^^^^^^-^^^^^^^^^^^^^
16+
| |
17+
| unsupported statement
1918
|
20-
note: unsupported statement
21-
--> $DIR/let-bindings.rs:6:41
22-
|
23-
LL | fn test<const N: usize>() -> [u8; { let x = N; N + 1 }] where [u8; { let x = N; N + 1 }]: Default {
24-
| ^
2519
= help: consider moving this anonymous constant into a `const` function
2620

2721
error: aborting due to 2 previous errors

0 commit comments

Comments
 (0)