@@ -2,7 +2,7 @@ use crate::astconv::{
22 AstConv , ExplicitLateBound , GenericArgCountMismatch , GenericArgCountResult , GenericArgPosition ,
33} ;
44use 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 } ;
66use rustc_hir as hir;
77use rustc_hir:: def_id:: DefId ;
88use rustc_hir:: { GenericArg , GenericArgs } ;
@@ -448,10 +448,10 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
448448 let emit_correct =
449449 |correct : Result < ( ) , ( _ , Option < rustc_errors:: DiagnosticBuilder < ' _ > > ) > | match correct {
450450 Ok ( ( ) ) => Ok ( ( ) ) ,
451- Err ( ( v , None ) ) => Err ( v == 0 ) ,
452- Err ( ( v , Some ( mut err) ) ) => {
451+ Err ( ( _ , None ) ) => Err ( ( ) ) ,
452+ Err ( ( _ , Some ( mut err) ) ) => {
453453 err. emit ( ) ;
454- Err ( v == 0 )
454+ Err ( ( ) )
455455 }
456456 } ;
457457
@@ -500,16 +500,27 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
500500 }
501501
502502 // 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+ ) ;
513524 }
514525 }
515526 }
@@ -521,8 +532,8 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
521532
522533 GenericArgCountResult {
523534 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 ) ,
526537 invalid_args : unexpected_spans,
527538 } ) ,
528539 }
0 commit comments