Skip to content

Commit

Permalink
fix: unused warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
justinpombrio committed Apr 6, 2024
1 parent 9166247 commit d7e662c
Show file tree
Hide file tree
Showing 14 changed files with 49 additions and 48 deletions.
1 change: 0 additions & 1 deletion src/engine/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use crate::pretty_doc::DocRef;
use crate::tree::{Bookmark, Location, Mode, Node};
use crate::util::{bug_assert, SynlessBug};
use std::collections::HashMap;
use std::mem;

/// A set of changes that can be undone/redone all at once.
#[derive(Debug)]
Expand Down
2 changes: 1 addition & 1 deletion src/engine/doc_command.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::language::Storage;
use crate::tree::{Bookmark, Node};
use crate::tree::Node;

#[derive(Debug)]
pub enum DocCommand {
Expand Down
12 changes: 4 additions & 8 deletions src/engine/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ use super::Settings;
use crate::language::{Language, LanguageError, LanguageSpec, NotationSetSpec, Storage};
use crate::parsing::{Parse, ParseError};
use crate::pretty_doc::{DocRef, PrettyDocError};
use crate::style::Style;
use crate::tree::{Bookmark, Node};
use crate::util::SynlessBug;
use crate::tree::Node;
use partial_pretty_printer as ppp;
use partial_pretty_printer::pane;
use std::collections::HashMap;
Expand Down Expand Up @@ -154,7 +152,6 @@ impl Engine {
language_name: &str,
parser: impl Parse + 'static,
) -> Result<(), EngineError> {
let lang = self.storage.language(language_name)?;
self.parsers
.insert(language_name.to_owned(), Box::new(parser));
Ok(())
Expand All @@ -164,19 +161,19 @@ impl Engine {
* Doc Management *
******************/

pub fn make_empty_doc(&mut self, doc_name: &str, language: Language) {
pub fn make_empty_doc(&mut self, _doc_name: &str, _language: Language) {
todo!()
}

/****************************
* Doc Loading and Printing *
****************************/

pub fn load_doc_from_sexpr(&self, doc_name: &Path, source: &str) -> Result<(), EngineError> {
pub fn load_doc_from_sexpr(&self, _doc_name: &Path, _source: &str) -> Result<(), EngineError> {
todo!()
}

pub fn print_sexpr(&self, doc_name: &Path) -> Result<String, EngineError> {
pub fn print_sexpr(&self, _doc_name: &Path) -> Result<String, EngineError> {
todo!()
}

Expand All @@ -186,7 +183,6 @@ impl Engine {
language_name: &str,
source: &str,
) -> Result<(), EngineError> {
let lang = self.storage.language(language_name)?;
let parser = self
.parsers
.get_mut(language_name)
Expand Down
6 changes: 3 additions & 3 deletions src/frontends/frontend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,13 @@ pub enum KeyCode {
impl fmt::Display for Key {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
if self.modifiers.ctrl {
write!(f, "C-");
write!(f, "C-")?;
}
if self.modifiers.alt {
write!(f, "A-");
write!(f, "A-")?;
}
if self.modifiers.shift {
write!(f, "S-");
write!(f, "S-")?;
}
match self.code {
KeyCode::Backspace => write!(f, "bksp"),
Expand Down
2 changes: 1 addition & 1 deletion src/frontends/screen_buf.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::style::ConcreteStyle;
use partial_pretty_printer::{pane::PrettyWindow, Height, Pos, Size, Width};
use partial_pretty_printer::{Height, Pos, Size, Width};
use std::mem;

/// The width of a single character. Either 1 ("half-width") or 2 ("full-width").
Expand Down
8 changes: 3 additions & 5 deletions src/frontends/terminal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@

use super::frontend::{Event, Frontend, Key, KeyCode, KeyModifiers, MouseButton, MouseEvent};
use super::screen_buf::{ScreenBuf, ScreenOp};
use crate::style::{ColorTheme, ConcreteStyle, Rgb, Style};
use crate::style::{ColorTheme, Rgb, Style};

use partial_pretty_printer::pane::PrettyWindow;
use partial_pretty_printer::{Col, Height, Pos, Row, Size};

use std::convert::TryFrom;
use std::fmt::Display;
use std::io::{self, stdin, stdout, Stdin, Stdout, StdoutLock, Write};
use std::io::{self, stdout, Write};
use std::time::{Duration, Instant};

use crossterm::cursor;
Expand Down Expand Up @@ -118,7 +116,7 @@ impl Frontend for Terminal {
buf: ScreenBuf::new(Terminal::terminal_window_size()?, default_concrete_style),
focus_pos: None,
};
term.enter();
term.enter()?;
Ok(term)
}

Expand Down
23 changes: 13 additions & 10 deletions src/language/compiled.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ struct GrammarCompiler {
}

impl GrammarSpec {
fn compile(mut self) -> Result<GrammarCompiled, LanguageError> {
fn compile(self) -> Result<GrammarCompiled, LanguageError> {
let mut builder = GrammarCompiler::new(self.root_construct);
for construct in self.constructs {
builder.add_construct(construct)?;
Expand Down Expand Up @@ -315,15 +315,18 @@ impl GrammarCompiler {
}

assert_eq!(construct_id, grammar.constructs.len());
grammar.constructs.insert(
construct.name.clone(),
ConstructCompiled {
name: construct.name.clone(),
arity,
is_comment_or_ws: construct.is_comment_or_ws,
key: construct.key,
},
);
grammar
.constructs
.insert(
construct.name.clone(),
ConstructCompiled {
name: construct.name.clone(),
arity,
is_comment_or_ws: construct.is_comment_or_ws,
key: construct.key,
},
)
.bug();
Ok(())
}
}
8 changes: 4 additions & 4 deletions src/language/interface.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use super::compiled::{
compile_language, compile_notation_set, ArityCompiled, ConstructId, GrammarCompiled,
LanguageCompiled, LanguageId, NotationSetId, SortId,
compile_notation_set, ArityCompiled, ConstructId, GrammarCompiled, LanguageId, NotationSetId,
SortId,
};
use super::specs::{LanguageSpec, NotationSetSpec};
use super::specs::NotationSetSpec;
use super::storage::Storage;
use super::LanguageError;
use crate::style::ValidNotation;
use crate::util::{bug, IndexedMap};
use crate::util::bug;

// NOTE: Why all the wrapper types, instead of using indexes? Two reasons:
//
Expand Down
2 changes: 1 addition & 1 deletion src/language/storage.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::compiled::{compile_language, LanguageCompiled};
use super::interface::Language;
use super::specs::{LanguageSpec, NotationSetSpec};
use super::specs::LanguageSpec;
use super::LanguageError;
use crate::tree::NodeForest;
use crate::util::IndexedMap;
Expand Down
6 changes: 2 additions & 4 deletions src/pretty_doc.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
use crate::language::Storage;
use crate::style::{
Condition, CursorHalf, Style, StyleLabel, ValidNotation, HOLE_STYLE, LEFT_CURSOR_STYLE,
RIGHT_CURSOR_STYLE,
Condition, Style, StyleLabel, ValidNotation, HOLE_STYLE, LEFT_CURSOR_STYLE, RIGHT_CURSOR_STYLE,
};
use crate::tree::{Location, Node, NodeId};
use crate::util::{bug, SynlessBug};
use crate::util::SynlessBug;
use partial_pretty_printer as ppp;
use std::fmt;
use std::sync::OnceLock;

#[derive(thiserror::Error, Debug)]
pub enum PrettyDocError {
Expand Down
2 changes: 1 addition & 1 deletion src/tree/location.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ impl Location {
use LocationInner::{AfterNode, BeforeNode, BelowNode, InText};

match self.0 {
InText(node, _) => None,
InText(_, _) => None,
BeforeNode(node) | AfterNode(node) => node.parent(s),
BelowNode(node) => Some(node),
}
Expand Down
17 changes: 11 additions & 6 deletions src/tree/node.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use super::forest;
use super::text::Text;
use crate::language::{Arity, Construct, Language, LanguageSpec, NotationSetSpec, Storage};
use crate::style::{Condition, StyleLabel, ValidNotation};
use crate::util::{bug, SynlessBug};
use partial_pretty_printer as ppp;
use crate::language::{Arity, Construct, Language, Storage};
use crate::style::ValidNotation;
use crate::util::{bug, bug_assert, SynlessBug};
use std::fmt;

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
Expand Down Expand Up @@ -83,7 +82,7 @@ impl Node {
construct: hole_construct,
text: None,
});
s.forest_mut().insert_last_child(parent, child);
bug_assert!(s.forest_mut().insert_last_child(parent, child));
}
Node(parent)
}
Expand Down Expand Up @@ -111,6 +110,9 @@ impl Node {
children: impl IntoIterator<Item = Node>,
) -> Option<Node> {
let children = children.into_iter().collect::<Vec<_>>();
if children.iter().any(|child| !child.is_root(s)) {
return None;
}
let allowed = match construct.arity(s) {
Arity::Texty => false,
Arity::Listy(sort) => children
Expand All @@ -135,7 +137,10 @@ impl Node {
text: None,
});
for child in children {
s.forest_mut().insert_last_child(parent, child.0);
// Requires that:
// - Each child is a root, validated above
// - No child is the root of `parent`, which was just created
bug_assert!(s.forest_mut().insert_last_child(parent, child.0));
}
Some(Node(parent))
} else {
Expand Down
5 changes: 5 additions & 0 deletions src/util/bug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ macro_rules! bug {
#[macro_export]
/// Like `assert!()`, but with a better error message.
macro_rules! bug_assert {
($condition:expr) => {
if !$condition {
$crate::bug!("Assertion failed.");
}
};
($condition:expr, $message:literal) => {
if !$condition {
$crate::bug!($message);
Expand Down
3 changes: 0 additions & 3 deletions src/util/indexed_map.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use std::borrow::Borrow;
use std::collections::HashMap;
use std::hash::Hash;
use std::ops::{Index, IndexMut};
use std::vec;

#[derive(Debug, Clone)]
pub struct IndexedMap<T> {
Expand Down

0 comments on commit d7e662c

Please sign in to comment.