Skip to content

Commit 79abac8

Browse files
author
Duddino
committed
Improved try_macro_suggestion function
1 parent 67128f1 commit 79abac8

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

src/librustc_parse/parser/diagnostics.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -1071,17 +1071,15 @@ impl<'a> Parser<'a> {
10711071
self.bump(); //remove )
10721072
let mut err = self.struct_span_err(lo.to(hi), "use of deprecated `try` macro");
10731073
err.note("in the 2018 edition `try` is a reserved keyword, and the `try!()` macro is deprecated");
1074+
let prefix = if is_empty { "" } else { "alternatively, " };
10741075
if !is_empty {
10751076
err.multipart_suggestion(
10761077
"you can use the `?` operator instead",
10771078
vec![(try_span, "".to_owned()), (hi, "?".to_owned())],
10781079
Applicability::MachineApplicable,
10791080
);
1080-
err.span_suggestion(lo.shrink_to_lo(), "alternatively, you can still access the deprecated `try!()` macro using the \"raw identifier\" syntax", "r#".to_string(), Applicability::MachineApplicable);
1081-
} else {
1082-
//if the try! macro is empty, it isn't possible to suggest something using the `?` operator
1083-
err.span_suggestion(lo.shrink_to_lo(), "you can still access the deprecated `try!()` macro using the \"raw identifier\" syntax", "r#".to_string(), Applicability::MachineApplicable);
10841081
}
1082+
err.span_suggestion(lo.shrink_to_lo(), &format!("{}you can still access the deprecated `try!()` macro using the \"raw identifier\" syntax", prefix), "r#".to_string(), Applicability::MachineApplicable);
10851083
err.emit();
10861084
Ok(self.mk_expr_err(lo.to(hi)))
10871085
} else {

0 commit comments

Comments
 (0)