diff --git a/fish-rust/src/ast.rs b/fish-rust/src/ast.rs index 60eb7469c..4b342ef2c 100644 --- a/fish-rust/src/ast.rs +++ b/fish-rust/src/ast.rs @@ -115,10 +115,10 @@ pub trait Node: Acceptor + ConcreteNode + std::fmt::Debug { fn describe(&self) -> WString { let mut res = ast_type_to_string(self.typ()).to_owned(); if let Some(n) = self.as_token() { - let token_type: &'static wstr = n.token_type().into(); + let token_type = n.token_type().to_wstr(); res += &sprintf!(" '%ls'"L, token_type)[..]; } else if let Some(n) = self.as_keyword() { - let keyword: &'static wstr = n.keyword().into(); + let keyword = n.keyword().to_wstr(); res += &sprintf!(" '%ls'"L, keyword)[..]; } res @@ -2341,7 +2341,7 @@ fn dump(&self, orig: &wstr) -> WString { result += &sprintf!(": '%ls'"L, argsrc)[..]; } } else if let Some(n) = node.as_keyword() { - result += &sprintf!("keyword: %ls"L, Into::<&'static wstr>::into(n.keyword()))[..]; + result += &sprintf!("keyword: %ls"L, n.keyword().to_wstr())[..]; } else if let Some(n) = node.as_token() { let desc = match n.token_type() { ParseTokenType::string => { @@ -2754,7 +2754,9 @@ fn did_visit_fields_of<'a>(&'a mut self, node: &'a dyn NodeMut, flow: VisitResul if self.unwinding { return; } - let VisitResult::Break(error) = flow else { return; }; + let VisitResult::Break(error) = flow else { + return; + }; /// We believe the node is some sort of block statement. Attempt to find a source range /// for the block's keyword (for, if, etc) and a user-presentable description. This diff --git a/fish-rust/src/parse_constants.rs b/fish-rust/src/parse_constants.rs index f090e66e2..bcd07dbb2 100644 --- a/fish-rust/src/parse_constants.rs +++ b/fish-rust/src/parse_constants.rs @@ -252,10 +252,11 @@ fn default() -> Self { } } -impl From for &'static wstr { +impl ParseTokenType { + /// Return a string describing the token type. #[widestrs] - fn from(token_type: ParseTokenType) -> Self { - match token_type { + pub fn to_wstr(self) -> &'static wstr { + match self { ParseTokenType::comment => "ParseTokenType::comment"L, ParseTokenType::error => "ParseTokenType::error"L, ParseTokenType::tokenizer_error => "ParseTokenType::tokenizer_error"L, @@ -279,10 +280,11 @@ fn default() -> Self { } } -impl From for &'static wstr { +impl ParseKeyword { + /// Return the keyword as a string. #[widestrs] - fn from(keyword: ParseKeyword) -> Self { - match keyword { + pub fn to_wstr(self) -> &'static wstr { + match self { ParseKeyword::kw_exclam => "!"L, ParseKeyword::kw_and => "and"L, ParseKeyword::kw_begin => "begin"L, @@ -308,7 +310,7 @@ fn from(keyword: ParseKeyword) -> Self { impl printf_compat::args::ToArg<'static> for ParseKeyword { fn to_arg(self) -> printf_compat::args::Arg<'static> { - printf_compat::args::Arg::Str(self.into()) + printf_compat::args::Arg::Str(self.to_wstr()) } } @@ -559,7 +561,7 @@ pub fn token_type_user_presentable_description( keyword: ParseKeyword, ) -> WString { if keyword != ParseKeyword::none { - return sprintf!("keyword: '%ls'"L, Into::<&'static wstr>::into(keyword)); + return sprintf!("keyword: '%ls'"L, keyword.to_wstr()); } match type_ { ParseTokenType::string => "a string"L.to_owned(), @@ -573,7 +575,7 @@ pub fn token_type_user_presentable_description( ParseTokenType::error => "a parse error"L.to_owned(), ParseTokenType::tokenizer_error => "an incomplete token"L.to_owned(), ParseTokenType::comment => "a comment"L.to_owned(), - _ => sprintf!("a %ls"L, Into::<&'static wstr>::into(type_)), + _ => sprintf!("a %ls"L, type_.to_wstr()), } } diff --git a/fish-rust/src/parse_tree.rs b/fish-rust/src/parse_tree.rs index 25aa4a67f..d4e92b18a 100644 --- a/fish-rust/src/parse_tree.rs +++ b/fish-rust/src/parse_tree.rs @@ -73,9 +73,9 @@ pub fn is_dash_prefix_string(&self) -> bool { } /// Returns a string description of the given parse token. pub fn describe(&self) -> WString { - let mut result = Into::<&'static wstr>::into(self.typ).to_owned(); + let mut result = self.typ.to_wstr().to_owned(); if self.keyword != ParseKeyword::none { - result += &sprintf!(L!(" <%ls>"), Into::<&'static wstr>::into(self.keyword))[..] + sprintf!(=> &mut result, " <%ls>", self.keyword.to_wstr()) } result }