From 79abac863e6ef0077d70063518bd34a20f75eae6 Mon Sep 17 00:00:00 2001 From: Duddino Date: Fri, 17 Apr 2020 19:29:36 +0200 Subject: [PATCH] Improved try_macro_suggestion function --- src/librustc_parse/parser/diagnostics.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/librustc_parse/parser/diagnostics.rs b/src/librustc_parse/parser/diagnostics.rs index e2b8da64dc76c..552f3d798ae8a 100644 --- a/src/librustc_parse/parser/diagnostics.rs +++ b/src/librustc_parse/parser/diagnostics.rs @@ -1071,17 +1071,15 @@ impl<'a> Parser<'a> { 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 {