@@ -73,38 +73,36 @@ pub(crate) fn make_unclosed_delims_error(
73
73
if let Some ( sp) = unmatched. unclosed_span {
74
74
spans. push ( sp) ;
75
75
} ;
76
- let mut err = psess. dcx ( ) . create_err ( MismatchedClosingDelimiter {
76
+
77
+ let missing_open_note = report_missing_open_delim ( & unmatched)
78
+ . map ( |s| format ! ( ", may missing open `{s}`" ) )
79
+ . unwrap_or_default ( ) ;
80
+
81
+ let err = psess. dcx ( ) . create_err ( MismatchedClosingDelimiter {
77
82
spans,
78
83
delimiter : pprust:: token_kind_to_string ( & token:: CloseDelim ( found_delim) ) . to_string ( ) ,
79
84
unmatched : unmatched. found_span ,
85
+ missing_open_note,
80
86
opening_candidate : unmatched. candidate_span ,
81
87
unclosed : unmatched. unclosed_span ,
82
88
} ) ;
83
- report_missing_open_delim ( & mut err, & [ unmatched] ) ;
84
89
Some ( err)
85
90
}
86
91
87
92
// When we get a `)` or `]` for `{`, we should emit help message here
88
93
// it's more friendly compared to report `unmatched error` in later phase
89
- fn report_missing_open_delim ( err : & mut Diag < ' _ > , unmatched_delims : & [ UnmatchedDelim ] ) -> bool {
90
- let mut reported_missing_open = false ;
91
- for unmatch_brace in unmatched_delims. iter ( ) {
92
- if let Some ( delim) = unmatch_brace. found_delim
93
- && matches ! ( delim, Delimiter :: Parenthesis | Delimiter :: Bracket )
94
- {
95
- let missed_open = match delim {
96
- Delimiter :: Parenthesis => "(" ,
97
- Delimiter :: Bracket => "[" ,
98
- _ => unreachable ! ( ) ,
99
- } ;
100
- err. span_label (
101
- unmatch_brace. found_span . shrink_to_lo ( ) ,
102
- format ! ( "missing open `{missed_open}` for this delimiter" ) ,
103
- ) ;
104
- reported_missing_open = true ;
105
- }
94
+ fn report_missing_open_delim ( unmatched_delim : & UnmatchedDelim ) -> Option < String > {
95
+ if let Some ( delim) = unmatched_delim. found_delim
96
+ && matches ! ( delim, Delimiter :: Parenthesis | Delimiter :: Bracket )
97
+ {
98
+ let missed_open = match delim {
99
+ Delimiter :: Parenthesis => "(" ,
100
+ Delimiter :: Bracket => "[" ,
101
+ _ => unreachable ! ( ) ,
102
+ } ;
103
+ return Some ( missed_open. to_owned ( ) ) ;
106
104
}
107
- reported_missing_open
105
+ None
108
106
}
109
107
110
108
pub ( super ) fn report_suspicious_mismatch_block (
0 commit comments