@@ -16,8 +16,7 @@ use rustc_infer::infer::InferCtxt;
16
16
use rustc_middle:: mir:: abstract_const:: { Node , NodeId } ;
17
17
use rustc_middle:: mir:: interpret:: ErrorHandled ;
18
18
use rustc_middle:: mir:: { self , Rvalue , StatementKind , TerminatorKind } ;
19
- use rustc_middle:: ty:: subst:: Subst ;
20
- use rustc_middle:: ty:: subst:: SubstsRef ;
19
+ use rustc_middle:: ty:: subst:: { Subst , SubstsRef } ;
21
20
use rustc_middle:: ty:: { self , TyCtxt , TypeFoldable } ;
22
21
use rustc_session:: lint;
23
22
use rustc_span:: def_id:: { DefId , LocalDefId } ;
@@ -43,10 +42,6 @@ pub fn is_const_evaluatable<'cx, 'tcx>(
43
42
for pred in param_env. caller_bounds ( ) {
44
43
match pred. kind ( ) . skip_binder ( ) {
45
44
ty:: PredicateKind :: ConstEvaluatable ( b_def, b_substs) => {
46
- debug ! (
47
- "is_const_evaluatable: caller_bound={:?}, {:?}" ,
48
- b_def, b_substs
49
- ) ;
50
45
if b_def == def && b_substs == substs {
51
46
debug ! ( "is_const_evaluatable: caller_bound ~~> ok" ) ;
52
47
return Ok ( ( ) ) ;
@@ -100,15 +95,24 @@ pub fn is_const_evaluatable<'cx, 'tcx>(
100
95
}
101
96
FailureKind :: MentionsParam => {
102
97
// FIXME(const_evaluatable_checked): Better error message.
103
- infcx
104
- . tcx
105
- . sess
106
- . struct_span_err ( span, "unconstrained generic constant" )
107
- . span_help (
98
+ let mut err =
99
+ infcx. tcx . sess . struct_span_err ( span, "unconstrained generic constant" ) ;
100
+ let const_span = tcx. def_span ( def. did ) ;
101
+ // FIXME(const_evaluatable_checked): Update this suggestion once
102
+ // explicit const evaluatable bounds are implemented.
103
+ if let Ok ( snippet) = infcx. tcx . sess . source_map ( ) . span_to_snippet ( const_span)
104
+ {
105
+ err. span_help (
108
106
tcx. def_span ( def. did ) ,
107
+ & format ! ( "try adding a `where` bound using this expression: where [u8; {}]: Sized" , snippet) ,
108
+ ) ;
109
+ } else {
110
+ err. span_help (
111
+ const_span,
109
112
"consider adding a `where` bound for this expression" ,
110
- )
111
- . emit ( ) ;
113
+ ) ;
114
+ }
115
+ err. emit ( ) ;
112
116
return Err ( ErrorHandled :: Reported ( ErrorReported ) ) ;
113
117
}
114
118
FailureKind :: Concrete => {
0 commit comments