Skip to content

Commit

Permalink
Updated to cargo 1.83 -- new clippy warnings (mainly eliding lifetime…
Browse files Browse the repository at this point in the history
…s) fixed
  • Loading branch information
NSoiffer committed Dec 7, 2024
1 parent e42818f commit 482b2d8
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/canonicalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ struct StackInfo<'a, 'op>{
is_operand: bool, // true if child at end of mrow is an operand (as opposed to an operator)
}

impl<'a, 'op> fmt::Display for StackInfo<'a, 'op> {
impl fmt::Display for StackInfo<'_, '_> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "StackInfo(op={}/{}, is_operand={}, mrow({}",
show_invisible_op_char(self.op_pair.ch), self.op_pair.op.priority, self.is_operand,
Expand Down Expand Up @@ -4055,7 +4055,7 @@ pub fn add_attrs<'a>(mathml: Element<'a>, attrs: &[Attribute]) -> Element<'a> {
}


pub fn name<'a>(node: &'a Element<'a>) -> &str {
pub fn name<'a>(node: &'a Element<'a>) -> &'a str {
return node.name().local_part();
}

Expand Down
1 change: 0 additions & 1 deletion src/definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ type VariableDefHashMap = HashMap<String, CollectionFromFile>;
/// naming conventions, snake case is used (e.g, "function_names").
///
/// There should only be one instance of this structure ([`DEFINITIONS`])
// FIX: this probably can done with a macro to remove all the repetition
pub struct Definitions {
pub name_to_var_mapping: VariableDefHashMap,
Expand Down
23 changes: 11 additions & 12 deletions src/infer_intent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

use sxd_document::dom::*;
use crate::speech::SpeechRulesWithContext;
use crate::canonicalize::{as_element, as_text, name, create_mathml_element, set_mathml_name};
use crate::canonicalize::{as_element, as_text, name, create_mathml_element, set_mathml_name, INTENT_ATTR};
use crate::errors::*;
use std::fmt;
use crate::pretty_print::mml_to_string;
Expand All @@ -24,7 +24,6 @@ pub fn infer_intent<'r, 'c, 's:'c, 'm:'c>(rules_with_context: &'r mut SpeechRule
if intent_preference == "Error" {
return Err(e);
} else {
const INTENT_ATTR: &str = "intent";
let saved_intent_attr = mathml.attribute_value(INTENT_ATTR).unwrap();
mathml.remove_attribute(INTENT_ATTR);
// can't call intent_from_mathml() because we have already borrowed_mut -- we call a more internal version
Expand All @@ -43,7 +42,7 @@ pub fn infer_intent<'r, 'c, 's:'c, 'm:'c>(rules_with_context: &'r mut SpeechRule
}

fn catch_errors_building_intent<'r, 'c, 's:'c, 'm:'c>(rules_with_context: &'r mut SpeechRulesWithContext<'c,'s,'m>, mathml: Element<'c>) -> Result<Element<'m>> {
if let Some(intent_str) = mathml.attribute_value("intent") {
if let Some(intent_str) = mathml.attribute_value(INTENT_ATTR) {
// debug!("Before intent: {}", crate::pretty_print::mml_to_string(&mathml));
let mut lex_state = LexState::init(intent_str.trim())?;
let result = build_intent(rules_with_context, &mut lex_state, mathml)
Expand Down Expand Up @@ -102,7 +101,7 @@ lazy_static! {
static TERMINALS_AS_U8: [u8; 3] = [b'(', b',', b')'];
// static TERMINALS: [char; 3] = ['(', ',',')'];

// 'i -- "i" for the lifetime of the "intent" string
// 'i -- "i" for the lifetime of the INTENT_ATTR string
#[derive(Debug, PartialEq, Eq, Clone)]
enum Token<'i> {
Terminal(&'i str), // "(", ",", ")"
Expand All @@ -113,7 +112,7 @@ enum Token<'i> {
None, // out of characters
}

impl<'i> fmt::Display for Token<'i> {
impl fmt::Display for Token<'_> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
return write!(f, "{}",
match self {
Expand All @@ -128,7 +127,7 @@ impl<'i> fmt::Display for Token<'i> {
}
}

impl<'i> Token<'i> {
impl Token<'_> {
fn is_terminal(&self, terminal: &str) -> bool {
if let Token::Terminal(value) = *self {
return value == terminal;
Expand All @@ -154,7 +153,7 @@ struct LexState<'i> {
remaining_str: &'i str, // always trimmed
}

impl<'i> fmt::Display for LexState<'i> {
impl fmt::Display for LexState<'_> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
return writeln!(f, "token: {}, remaining: '{}'", self.token, self.remaining_str);
}
Expand Down Expand Up @@ -236,11 +235,11 @@ fn build_intent<'b, 'r, 'c, 's:'c, 'm:'c>(rules_with_context: &'r mut SpeechRule
intent = create_mathml_element(&doc, name(&mathml));
intent.set_attribute_value(INTENT_PROPERTY, &properties);
} else {
let saved_intent = mathml.attribute_value("intent").unwrap();
mathml.remove_attribute("intent");
let saved_intent = mathml.attribute_value(INTENT_ATTR).unwrap();
mathml.remove_attribute(INTENT_ATTR);
mathml.set_attribute_value(INTENT_PROPERTY, &properties); // needs to be set before the pattern match
intent = rules_with_context.match_pattern::<Element<'m>>(mathml)?;
mathml.set_attribute_value("intent", saved_intent);
mathml.set_attribute_value(INTENT_ATTR, saved_intent);
}
return Ok(intent); // if we start with properties, then there can only be properties
},
Expand Down Expand Up @@ -394,7 +393,7 @@ fn find_arg<'r, 'c, 's:'c, 'm:'c>(rules_with_context: &'r mut SpeechRulesWithCon
// debug!("looking for '{}', found arg='{}'", name, arg_val);
if name == arg_val {
// check to see if this mathml has an intent value -- if so the value is the value of its intent value
if let Some(intent_str) = mathml.attribute_value("intent") {
if let Some(intent_str) = mathml.attribute_value(INTENT_ATTR) {
let mut lex_state = LexState::init(intent_str.trim())?;
return Ok( Some( build_intent(rules_with_context, &mut lex_state, mathml)? ) );
} else {
Expand All @@ -406,7 +405,7 @@ fn find_arg<'r, 'c, 's:'c, 'm:'c>(rules_with_context: &'r mut SpeechRulesWithCon
}
}

if no_check_inside && mathml.attribute_value("intent").is_some() {
if no_check_inside && mathml.attribute_value(INTENT_ATTR).is_some() {
return Ok(None); // don't look inside 'intent'
}

Expand Down
8 changes: 4 additions & 4 deletions src/pretty_print.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use sxd_document::dom::*;

#[allow(dead_code)]
// #[allow(dead_code)]
// pub fn pp_doc(doc: &Document) {
// for root_child in doc.root().children() {
// if let ChildOfRoot::Element(e) = root_child {
Expand Down Expand Up @@ -83,8 +83,8 @@ fn handle_special_chars(text: &str) -> String {
}


/// Pretty print an xpath value.
/// If the value is a `NodeSet`, the MathML for the node/element is returned.
// /// Pretty print an xpath value.
// /// If the value is a `NodeSet`, the MathML for the node/element is returned.
// pub fn pp_xpath_value(value: Value) {
// use sxd_xpath::Value;
// use sxd_xpath::nodeset::Node;
Expand Down Expand Up @@ -271,7 +271,7 @@ fn escape_str(wr: &mut dyn fmt::Write, v: &str) -> Result<(), fmt::Error> {
}

impl<'a> YamlEmitter<'a> {
pub fn new(writer: &'a mut dyn fmt::Write) -> YamlEmitter {
pub fn new(writer: &'a mut dyn fmt::Write) -> YamlEmitter<'a> {
YamlEmitter {
writer,
best_indent: 2,
Expand Down

0 comments on commit 482b2d8

Please sign in to comment.