@@ -2,7 +2,7 @@ use crate::astconv::{
2
2
AstConv , ExplicitLateBound , GenericArgCountMismatch , GenericArgCountResult , GenericArgPosition ,
3
3
} ;
4
4
use rustc_ast:: ast:: ParamKindOrd ;
5
- use rustc_errors:: { pluralize, struct_span_err, DiagnosticId , ErrorReported } ;
5
+ use rustc_errors:: { pluralize, struct_span_err, Applicability , DiagnosticId , ErrorReported } ;
6
6
use rustc_hir as hir;
7
7
use rustc_hir:: def_id:: DefId ;
8
8
use rustc_hir:: { GenericArg , GenericArgs } ;
@@ -448,10 +448,10 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
448
448
let emit_correct =
449
449
|correct : Result < ( ) , ( _ , Option < rustc_errors:: DiagnosticBuilder < ' _ > > ) > | match correct {
450
450
Ok ( ( ) ) => Ok ( ( ) ) ,
451
- Err ( ( v , None ) ) => Err ( v == 0 ) ,
452
- Err ( ( v , Some ( mut err) ) ) => {
451
+ Err ( ( _ , None ) ) => Err ( ( ) ) ,
452
+ Err ( ( _ , Some ( mut err) ) ) => {
453
453
err. emit ( ) ;
454
- Err ( v == 0 )
454
+ Err ( ( ) )
455
455
}
456
456
} ;
457
457
@@ -500,16 +500,27 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
500
500
}
501
501
502
502
// Emit a help message if it's possible that a type could be surrounded in braces
503
- if let Err ( ( c_mismatch, Some ( ref mut _const_err) ) ) = & mut const_count_correct {
504
- if let Err ( ( t_mismatch, Some ( ref mut type_err) ) ) = & mut type_count_correct {
505
- if * c_mismatch == -* t_mismatch && * t_mismatch < 0 {
506
- for i in 0 ..* c_mismatch as usize {
507
- // let t_span = unexpected_type_spans[i].clone();
508
- let ident = args. args [ arg_counts. lifetimes + i] . id ( ) ;
509
- type_err. help ( & format ! (
510
- "For more complex types, surround with braces: `{{ {} }}`" ,
511
- ident,
512
- ) ) ;
503
+ if let Err ( ( c_mismatch, Some ( ref mut _const_err) ) ) = const_count_correct {
504
+ if let Err ( ( t_mismatch, Some ( ref mut type_err) ) ) = type_count_correct {
505
+ if c_mismatch == -t_mismatch && t_mismatch < 0 {
506
+ for i in 0 ..c_mismatch as usize {
507
+ let arg = & args. args [ arg_counts. lifetimes + i] ;
508
+ match arg {
509
+ GenericArg :: Type ( hir:: Ty {
510
+ kind : hir:: TyKind :: Path { .. } , ..
511
+ } ) => { }
512
+ _ => continue ,
513
+ }
514
+ let suggestions = vec ! [
515
+ ( arg. span( ) . shrink_to_lo( ) , String :: from( "{ " ) ) ,
516
+ ( arg. span( ) . shrink_to_hi( ) , String :: from( " }" ) ) ,
517
+ ] ;
518
+ type_err. multipart_suggestion (
519
+ "If this generic argument was intended as a const parameter, \
520
+ try surrounding it with braces:",
521
+ suggestions,
522
+ Applicability :: MaybeIncorrect ,
523
+ ) ;
513
524
}
514
525
}
515
526
}
@@ -521,8 +532,8 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
521
532
522
533
GenericArgCountResult {
523
534
explicit_late_bound,
524
- correct : arg_count_correct. map_err ( |reported_err | GenericArgCountMismatch {
525
- reported : if reported_err { Some ( ErrorReported ) } else { None } ,
535
+ correct : arg_count_correct. map_err ( |( ) | GenericArgCountMismatch {
536
+ reported : Some ( ErrorReported ) ,
526
537
invalid_args : unexpected_spans,
527
538
} ) ,
528
539
}
0 commit comments