@@ -124,6 +124,11 @@ impl<'a, 'tcx> Visitor<'tcx> for FindHirNodeVisitor<'a, 'tcx> {
124
124
return ;
125
125
}
126
126
}
127
+
128
+ // FIXME(const_generics): Currently, any uninferred `const` generics arguments
129
+ // are handled specially, but instead they should be handled in `annotate_method_call`,
130
+ // which currently doesn't work because this evaluates to `false` for const arguments.
131
+ // See https://github.com/rust-lang/rust/pull/77758 for more details.
127
132
if self . node_ty_contains_target ( expr. hir_id ) . is_some ( ) {
128
133
match expr. kind {
129
134
ExprKind :: Closure ( ..) => self . found_closure = Some ( & expr) ,
@@ -345,11 +350,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
345
350
) -> DiagnosticBuilder < ' tcx > {
346
351
let arg = self . resolve_vars_if_possible ( arg) ;
347
352
let arg_data = self . extract_inference_diagnostics_data ( arg, None ) ;
348
- let kind_str = match arg. unpack ( ) {
349
- GenericArgKind :: Type ( _) => "type" ,
350
- GenericArgKind :: Const ( _) => "the value" ,
351
- GenericArgKind :: Lifetime ( _) => bug ! ( "unexpected lifetime" ) ,
352
- } ;
353
353
354
354
let mut local_visitor = FindHirNodeVisitor :: new ( & self , arg, span) ;
355
355
let ty_to_string = |ty : Ty < ' tcx > | -> String {
@@ -618,6 +618,28 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
618
618
. any ( |span_label| span_label. label . is_some ( ) && span_label. span == span)
619
619
&& local_visitor. found_arg_pattern . is_none ( )
620
620
{
621
+ let ( kind_str, const_value) = match arg. unpack ( ) {
622
+ GenericArgKind :: Type ( _) => ( "type" , None ) ,
623
+ GenericArgKind :: Const ( _) => ( "the value" , Some ( ( ) ) ) ,
624
+ GenericArgKind :: Lifetime ( _) => bug ! ( "unexpected lifetime" ) ,
625
+ } ;
626
+
627
+ // FIXME(const_generics): we would like to handle const arguments
628
+ // as part of the normal diagnostics flow below, but there appear to
629
+ // be subtleties in doing so, so for now we special-case const args
630
+ // here.
631
+ if let Some ( suggestion) = const_value
632
+ . and_then ( |_| arg_data. parent_name . as_ref ( ) )
633
+ . map ( |parent| format ! ( "{}::<{}>" , parent, arg_data. name) )
634
+ {
635
+ err. span_suggestion_verbose (
636
+ span,
637
+ "consider specifying the const argument" ,
638
+ suggestion,
639
+ Applicability :: MaybeIncorrect ,
640
+ ) ;
641
+ }
642
+
621
643
// Avoid multiple labels pointing at `span`.
622
644
err. span_label (
623
645
span,
0 commit comments