@@ -804,6 +804,8 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
804
804
)
805
805
}
806
806
SelectionError :: NotConstEvaluatable ( NotConstEvaluatable :: MentionsParam ) => {
807
+ debug ! ( "NotConstEvaluatable::MentionsParam error" ) ;
808
+
807
809
if !self . tcx . features ( ) . generic_const_exprs {
808
810
let mut err = self . tcx . sess . struct_span_err (
809
811
span,
@@ -822,16 +824,41 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
822
824
823
825
match obligation. predicate . kind ( ) . skip_binder ( ) {
824
826
ty:: PredicateKind :: ConstEvaluatable ( uv) => {
827
+ debug ! ( ?uv) ;
828
+
825
829
let mut err =
826
830
self . tcx . sess . struct_span_err ( span, "unconstrained generic constant" ) ;
827
- let const_span = self . tcx . def_span ( uv. def . did ) ;
828
- match self . tcx . sess . source_map ( ) . span_to_snippet ( const_span) {
829
- Ok ( snippet) => err. help ( & format ! (
831
+
832
+ let anon_const_sugg = match AbstractConst :: new ( self . tcx , uv) {
833
+ Ok ( Some ( a) ) => a. try_print_with_replacing_substs ( self . tcx ) . map_or (
834
+ {
835
+ let const_span = self . tcx . def_span ( uv. def . did ) ;
836
+ self . tcx
837
+ . sess
838
+ . source_map ( )
839
+ . span_to_snippet ( const_span)
840
+ . map_or ( None , Some )
841
+ } ,
842
+ |s| Some ( format ! ( "{{ {} }}" , s) ) ,
843
+ ) ,
844
+ _ => {
845
+ let const_span = self . tcx . def_span ( uv. def . did ) ;
846
+ self . tcx
847
+ . sess
848
+ . source_map ( )
849
+ . span_to_snippet ( const_span)
850
+ . map_or ( None , Some )
851
+ }
852
+ } ;
853
+
854
+ match anon_const_sugg {
855
+ Some ( snippet) => err. help ( & format ! (
830
856
"try adding a `where` bound using this expression: `where [(); {}]:`" ,
831
857
snippet
832
858
) ) ,
833
- _ => err. help ( "consider adding a `where` bound using this expression" ) ,
859
+ None => err. help ( "consider adding a `where` bound using this expression" ) ,
834
860
} ;
861
+
835
862
err
836
863
}
837
864
_ => {
0 commit comments