Improved try_macro_suggestion function

This commit is contained in:
Duddino 2020-04-17 19:29:36 +02:00
parent 67128f1e4a
commit 79abac863e

View File

@ -1071,17 +1071,15 @@ pub(super) fn try_macro_suggestion(&mut self) -> PResult<'a, P<Expr>> {
self.bump(); //remove )
let mut err = self.struct_span_err(lo.to(hi), "use of deprecated `try` macro");
err.note("in the 2018 edition `try` is a reserved keyword, and the `try!()` macro is deprecated");
let prefix = if is_empty { "" } else { "alternatively, " };
if !is_empty {
err.multipart_suggestion(
"you can use the `?` operator instead",
vec![(try_span, "".to_owned()), (hi, "?".to_owned())],
Applicability::MachineApplicable,
);
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);
} else {
//if the try! macro is empty, it isn't possible to suggest something using the `?` operator
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);
}
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);
err.emit();
Ok(self.mk_expr_err(lo.to(hi)))
} else {