From 054d071d8032e05f5235be754ccb8407480bb7ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20W=2E=20Urba=C5=84czyk?= Date: Sat, 30 Oct 2021 14:45:49 +0200 Subject: [PATCH] bump toolchain, fix clear issues --- lib/rust/ast/src/generation.rs | 14 ++++---- lib/rust/ast/src/main.rs | 1 - lib/rust/automata/src/dfa.rs | 2 +- lib/rust/automata/src/nfa.rs | 10 +++--- lib/rust/automata/src/pattern.rs | 4 +-- lib/rust/data/benches/bench_tree_query.rs | 2 +- lib/rust/data/src/dependency_graph.rs | 8 ++--- lib/rust/flexer/src/generate.rs | 2 +- lib/rust/flexer/src/group.rs | 2 +- .../tests/flexer_invalid_definitions.rs | 2 ++ lib/rust/lexer/definition/src/lexeme.rs | 2 +- lib/rust/lexer/definition/src/token.rs | 34 +++++++------------ .../generation/benches/lexer_bench_sources.rs | 1 - lib/rust/lexer/generation/build.rs | 4 +-- lib/rust/lexer/generation/tests/test_utils.rs | 1 - lib/rust/macro-utils/src/lib.rs | 2 +- lib/rust/optics/src/lib.rs | 2 +- lib/rust/prelude/src/data/non_empty_vec.rs | 8 ++--- lib/rust/prelude/src/lib.rs | 2 +- lib/rust/shapely/impl/tests/derivation.rs | 2 +- .../shapely/impl/tests/derive_clone_ref.rs | 12 +++---- .../shapely/macros/src/derive_clone_ref.rs | 4 +-- .../shapely/macros/src/derive_iterator.rs | 2 +- rust-toolchain | 1 + 24 files changed, 55 insertions(+), 69 deletions(-) create mode 100644 rust-toolchain diff --git a/lib/rust/ast/src/generation.rs b/lib/rust/ast/src/generation.rs index d3ab6719c1..114aa5d124 100644 --- a/lib/rust/ast/src/generation.rs +++ b/lib/rust/ast/src/generation.rs @@ -50,18 +50,18 @@ impl ScalaGenerator { /// Generates a block of Scala code. fn block(&mut self, ident:&Ident, lines:&[syn::Item]) { write!(self.code, "\n{:i$}object " , "", i=self.indent); - self.typ_name(&ident); + self.typ_name(ident); writeln!(self.code, " {{"); self.indent += 2; - if self.extends.contains_key(&ident) { + if self.extends.contains_key(ident) { write!(self.code, "{:i$}sealed trait ", "", i=self.indent); - self.typ_name(&ident); - self.extends(&ident); + self.typ_name(ident); + self.extends(ident); } for item in lines { match item { - syn::Item::Enum (val) => self.adt(&val), + syn::Item::Enum (val) => self.adt(val), syn::Item::Type (val) => { write!(self.code, "\n{:i$}type ", "", i=self.indent); self.typ_name(&val.ident); @@ -101,7 +101,7 @@ impl ScalaGenerator { for (i, field) in fields.named.iter().enumerate() { if i != 0 { write!(self.code, ", "); } if let Some(ident) = &field.ident { - self.var_name(&ident); + self.var_name(ident); } write!(self.code, ": "); self.typ(&field.ty); @@ -170,7 +170,7 @@ impl ScalaGenerator { /// /// `foo` => `extends Foo` fn extends(&mut self, ident:&Ident) { - if let Some(name) = self.extends.get(&ident).cloned() { + if let Some(name) = self.extends.get(ident).cloned() { write!(self.code, " extends "); self.typ_name(&name); } diff --git a/lib/rust/ast/src/main.rs b/lib/rust/ast/src/main.rs index 7491242e71..84b48aed8e 100644 --- a/lib/rust/ast/src/main.rs +++ b/lib/rust/ast/src/main.rs @@ -1,6 +1,5 @@ use ast::generation::ScalaGenerator; -use clap; use std::fs::File; use std::io::Write; diff --git a/lib/rust/automata/src/dfa.rs b/lib/rust/automata/src/dfa.rs index 9f8e20c4eb..5da0b08788 100644 --- a/lib/rust/automata/src/dfa.rs +++ b/lib/rust/automata/src/dfa.rs @@ -66,7 +66,7 @@ impl Dfa { impl Dfa { /// Simulate the DFA transition with the provided input symbol. pub fn next_state(&self, current_state:State, symbol:&Symbol) -> State { - let ix = self.alphabet.index_of_symbol(&symbol); + let ix = self.alphabet.index_of_symbol(symbol); self.links.safe_index(current_state.id(),ix).unwrap_or_default() } diff --git a/lib/rust/automata/src/nfa.rs b/lib/rust/automata/src/nfa.rs index ce9b09149f..92907125c6 100644 --- a/lib/rust/automata/src/nfa.rs +++ b/lib/rust/automata/src/nfa.rs @@ -353,16 +353,16 @@ pub mod tests { } pub fn has_transition(&self, trigger:RangeInclusive, target:State) -> bool { - self.states.iter().any(|r| r.links().iter().find(|transition | { + self.states.iter().any(|r| r.links().iter().any(|transition | { (transition.symbols == trigger) && transition.target == target - }).is_some()) + })) } pub fn has_epsilon(&self, from:State, to:State) -> bool { self.states.iter().enumerate().fold(false,|l,(ix,r)| { - let state_has = ix == from.id() && r.epsilon_links().iter().find(|ident| { - **ident == to - }).is_some(); + let state_has = ix == from.id() && r.epsilon_links().iter().any(|ident| { + *ident == to + }); l || state_has }) } diff --git a/lib/rust/automata/src/pattern.rs b/lib/rust/automata/src/pattern.rs index 6e89d72e47..74d13cfab0 100644 --- a/lib/rust/automata/src/pattern.rs +++ b/lib/rust/automata/src/pattern.rs @@ -129,9 +129,7 @@ impl Pattern { /// This pattern doesn't trigger on any code contained in `codes`. pub fn none_of_codes(codes:&[u64],names:&[String]) -> Self { - if codes.len() != names.len() { - panic!("`codes` and `names`must have the same length."); - } + assert_eq!(codes.len(), names.len(), "`codes` and `names`must have the same length."); let mut codes = Vec::from(codes); codes.sort_unstable(); codes.dedup(); diff --git a/lib/rust/data/benches/bench_tree_query.rs b/lib/rust/data/benches/bench_tree_query.rs index 103c66df68..b42ae621d5 100644 --- a/lib/rust/data/benches/bench_tree_query.rs +++ b/lib/rust/data/benches/bench_tree_query.rs @@ -28,7 +28,7 @@ fn bench_config() -> Criterion { fn gen_tree(width:usize, depth:usize) -> HashMapTree { let mut tree = HashMapTree::::default(); let paths = (0..width).permutations(depth); - paths.into_iter().for_each(|p| tree.set(p.clone(),1)); + paths.into_iter().for_each(|p| tree.set(p,1)); tree } diff --git a/lib/rust/data/src/dependency_graph.rs b/lib/rust/data/src/dependency_graph.rs index 3f01424819..b40d33e4d3 100644 --- a/lib/rust/data/src/dependency_graph.rs +++ b/lib/rust/data/src/dependency_graph.rs @@ -102,7 +102,7 @@ impl DependencyGraph { let mut keys_iter = keys.iter(); let mut opt_key = keys_iter.next(); while let Some(key) = opt_key { - match next_to_keep.as_ref().map(|t| t.cmp(&key)) { + match next_to_keep.as_ref().map(|t| t.cmp(key)) { Some(std::cmp::Ordering::Less) => { next_to_keep = keep.next() }, @@ -111,13 +111,13 @@ impl DependencyGraph { opt_key = keys_iter.next(); } _ => { - if let Some(node) = self.nodes.get_mut(&key) { + if let Some(node) = self.nodes.get_mut(key) { let node = mem::take(node); for key2 in node.ins { - self.nodes.get_mut(&key2).for_each(|t| t.out.remove_item(&key)) + self.nodes.get_mut(&key2).for_each(|t| t.out.remove_item(key)) } for key2 in node.out { - self.nodes.get_mut(&key2).for_each(|t| t.ins.remove_item(&key)) + self.nodes.get_mut(&key2).for_each(|t| t.ins.remove_item(key)) } } opt_key = keys_iter.next(); diff --git a/lib/rust/flexer/src/generate.rs b/lib/rust/flexer/src/generate.rs index 891396afd4..0df3061041 100644 --- a/lib/rust/flexer/src/generate.rs +++ b/lib/rust/flexer/src/generate.rs @@ -312,7 +312,7 @@ pub fn branch_body } } else { let target_state_has_no_rule = match rule_name_for_state { - Some(_) => if !dfa_has_rule_name_for(&data, dfa, target_state) { + Some(_) => if !dfa_has_rule_name_for(data, dfa, target_state) { dfa.sources[target_state.id()] = (*sources).clone(); has_overlaps.insert(target_state.id(),true); true diff --git a/lib/rust/flexer/src/group.rs b/lib/rust/flexer/src/group.rs index c0e0bcf306..d4b1a44709 100644 --- a/lib/rust/flexer/src/group.rs +++ b/lib/rust/flexer/src/group.rs @@ -192,7 +192,7 @@ impl AutomatonData { /// Get a reference to the states for this automaton. pub fn states(&self) -> &Vec { - &self.automaton.states() + self.automaton.states() } /// Get a reference to the state names for this automaton. diff --git a/lib/rust/flexer/tests/flexer_invalid_definitions.rs b/lib/rust/flexer/tests/flexer_invalid_definitions.rs index eb6b2c4721..4f261bae0c 100644 --- a/lib/rust/flexer/tests/flexer_invalid_definitions.rs +++ b/lib/rust/flexer/tests/flexer_invalid_definitions.rs @@ -4,6 +4,8 @@ //! allows for increased clarity in the testing. #![allow(missing_docs)] +#![allow(clippy::blacklisted_name)] // `foo` is fine here. +#![allow(clippy::new_without_default)] // No need for boilerplate in throwaway test code. use enso_flexer::*; diff --git a/lib/rust/lexer/definition/src/lexeme.rs b/lib/rust/lexer/definition/src/lexeme.rs index 853ce8865b..0ee43fd59c 100644 --- a/lib/rust/lexer/definition/src/lexeme.rs +++ b/lib/rust/lexer/definition/src/lexeme.rs @@ -282,7 +282,7 @@ pub mod literal { /// Get the first character of the lexeme, if it exists. pub fn char(literal:&'static str) -> Option { - literal.chars().nth(0) + literal.chars().next() } /// Get the first character of the lexeme, assuming that it exists. diff --git a/lib/rust/lexer/definition/src/token.rs b/lib/rust/lexer/definition/src/token.rs index 7e31940be5..ff6d3c2d7d 100644 --- a/lib/rust/lexer/definition/src/token.rs +++ b/lib/rust/lexer/definition/src/token.rs @@ -390,30 +390,17 @@ impl TextStyle { /// Check if the text literal is a line literal. pub fn is_line_literal(self) -> bool { - match self { - TextStyle::RawLine => true, - TextStyle::FormatLine => true, - TextStyle::UnclosedLine => true, - _ => false, - } + matches!(self, TextStyle::RawLine | TextStyle::FormatLine | TextStyle::UnclosedLine) } /// Check if the text literal is an inline block literal. pub fn is_inline_block_literal(self) -> bool { - match self { - TextStyle::FormatInlineBlock => true, - TextStyle::RawInlineBlock => true, - _ => false, - } + matches!(self, TextStyle::FormatInlineBlock | TextStyle::RawInlineBlock) } /// Check if the text literal is a block literal. pub fn is_block_literal(self) -> bool { - match self { - TextStyle::FormatBlock => true, - TextStyle::RawBlock => true, - _ => false, - } + matches!(self, TextStyle::FormatBlock | TextStyle::RawBlock) } } @@ -761,9 +748,14 @@ impl Stream { pub fn tokens_len(&self) -> usize { self.tokens.iter().map(|token|token.length + token.offset).sum() } +} - /// Get a consuming iterator over the token stream. - pub fn into_iter(self) -> std::vec::IntoIter { +/// Get a consuming iterator over the token stream. +impl std::iter::IntoIterator for Stream { + type Item = Token; + type IntoIter = std::vec::IntoIter; + + fn into_iter(self) -> Self::IntoIter { self.tokens.into_iter() } } @@ -791,8 +783,8 @@ impl From> for Stream { } } -impl Into> for Stream { - fn into(self) -> Vec { - self.tokens +impl From for Vec { + fn from(stream: Stream) -> Self { + stream.tokens } } diff --git a/lib/rust/lexer/generation/benches/lexer_bench_sources.rs b/lib/rust/lexer/generation/benches/lexer_bench_sources.rs index 1b5548a06a..c827df99fe 100644 --- a/lib/rust/lexer/generation/benches/lexer_bench_sources.rs +++ b/lib/rust/lexer/generation/benches/lexer_bench_sources.rs @@ -2,7 +2,6 @@ //! benchmarking the Enso lexer. use criterion::{black_box, Criterion, Throughput}; -use lexer; use std::time::Duration; diff --git a/lib/rust/lexer/generation/build.rs b/lib/rust/lexer/generation/build.rs index aea553c69d..6016f5c660 100644 --- a/lib/rust/lexer/generation/build.rs +++ b/lib/rust/lexer/generation/build.rs @@ -16,9 +16,9 @@ fn generate_engine() -> std::io::Result<()> { let output_path = "src/generated/engine.rs"; let definition_error = format!("The lexer definition should exist at {}.",definition_path); let output_error = format!("Cannot open output file at {}.",output_path); - let mut lexer_def = File::open(definition_path).expect(definition_error.as_str()); + let mut lexer_def = File::open(definition_path).expect(&definition_error); let mut contents = String::new(); - let mut file = File::create(output_path).expect(output_error.as_str()); + let mut file = File::create(output_path).expect(&output_error); let lexer = EnsoLexer::define(); let engine = lexer.specialize().unwrap(); lexer_def.read_to_string(&mut contents).expect("Unable to read lexer definition."); diff --git a/lib/rust/lexer/generation/tests/test_utils.rs b/lib/rust/lexer/generation/tests/test_utils.rs index 19da65c949..51d1d3bb85 100644 --- a/lib/rust/lexer/generation/tests/test_utils.rs +++ b/lib/rust/lexer/generation/tests/test_utils.rs @@ -5,7 +5,6 @@ use enso_flexer::*; use lexer_definition::library::*; -use lexer; use lexer_definition::library::token::Token; diff --git a/lib/rust/macro-utils/src/lib.rs b/lib/rust/macro-utils/src/lib.rs index 7e8c3a8d5c..3ade666ed6 100644 --- a/lib/rust/macro-utils/src/lib.rs +++ b/lib/rust/macro-utils/src/lib.rs @@ -213,7 +213,7 @@ pub fn gather_all_types(node:&syn::Type) -> Vec<&syn::TypePath> { /// All text representations of `TypePath`s in the given's `Type` subtree. pub fn gather_all_type_reprs(node:&syn::Type) -> Vec { - gather_all_types(node).iter().map(|t| repr(t)).collect() + gather_all_types(node).iter().map(repr).collect() } diff --git a/lib/rust/optics/src/lib.rs b/lib/rust/optics/src/lib.rs index 490c7273a6..0bb2d83979 100644 --- a/lib/rust/optics/src/lib.rs +++ b/lib/rust/optics/src/lib.rs @@ -165,7 +165,7 @@ impl OptLens { impl Lens { pub fn resolve(self, t: &Src) -> &NestedField where Path: Resolver { - >::resolve(&t) + >::resolve(t) } } diff --git a/lib/rust/prelude/src/data/non_empty_vec.rs b/lib/rust/prelude/src/data/non_empty_vec.rs index fa51ae4c32..6cf2259158 100644 --- a/lib/rust/prelude/src/data/non_empty_vec.rs +++ b/lib/rust/prelude/src/data/non_empty_vec.rs @@ -89,9 +89,7 @@ impl NonEmptyVec { /// vec.push(11); /// ``` pub fn with_capacity(first:T, capacity:usize) -> NonEmptyVec { - if capacity == 0 { - panic!("Capacity must be greater than zero for a NonEmptyVec."); - } + assert_ne!(capacity, 0, "Capacity must be greater than zero for a NonEmptyVec."); let mut elems = Vec::with_capacity(capacity); elems.push(first); NonEmptyVec{elems} @@ -198,7 +196,7 @@ impl NonEmptyVec { /// assert_eq!(*vec.first(), 0); /// ``` pub fn first(&self) -> &T { - &self.elems.first().expect("The NonEmptyVec always has an item in it.") + self.elems.first().expect("The NonEmptyVec always has an item in it.") } /// Obtain a mutable reference to the head of the `NonEmptyVec`. @@ -309,4 +307,4 @@ impl Default for NonEmptyVec { fn default() -> Self { Self::singleton(default()) } -} \ No newline at end of file +} diff --git a/lib/rust/prelude/src/lib.rs b/lib/rust/prelude/src/lib.rs index 8ae01b0911..ae6a2cd40b 100644 --- a/lib/rust/prelude/src/lib.rs +++ b/lib/rust/prelude/src/lib.rs @@ -394,7 +394,7 @@ pub trait WeakRef : CloneRef { impl StrongRef for Rc { type WeakRef = Weak; fn downgrade(&self) -> Self::WeakRef { - Rc::downgrade(&self) + Rc::downgrade(self) } } diff --git a/lib/rust/shapely/impl/tests/derivation.rs b/lib/rust/shapely/impl/tests/derivation.rs index c65f75c04d..ba976617bf 100644 --- a/lib/rust/shapely/impl/tests/derivation.rs +++ b/lib/rust/shapely/impl/tests/derivation.rs @@ -1,5 +1,5 @@ #![feature(generators)] -#![feature(min_type_alias_impl_trait)] +#![feature(type_alias_impl_trait)] use enso_shapely::*; diff --git a/lib/rust/shapely/impl/tests/derive_clone_ref.rs b/lib/rust/shapely/impl/tests/derive_clone_ref.rs index e1e1972947..8783c0c70d 100644 --- a/lib/rust/shapely/impl/tests/derive_clone_ref.rs +++ b/lib/rust/shapely/impl/tests/derive_clone_ref.rs @@ -16,11 +16,11 @@ use enso_prelude::*; #[derive(Clone,CloneRef)] enum EnumEmpty {} #[derive(Clone,CloneRef)] enum Enum { - VariantUnit, - VariantNamedEmpty {}, - VariantNamed {named0:Rc,named1:Rc}, - VariantUnnamedEmpty(), - VariantUnnamed(Rc,Rc), + Unit, + NamedEmpty {}, + Named {named0:Rc,named1:Rc}, + UnnamedEmpty(), + Unnamed(Rc,Rc), } #[derive(CloneRef,Derivative)] @@ -42,7 +42,7 @@ struct StructBoundGeneric(Rc); #[derive(CloneRef,Derivative)] #[derivative(Clone(bound=""))] // Note: CloneRef "knows" about `Display` bound. -struct StructGenericLifetime<'t>(Rc<&'t String>); +struct StructGenericLifetime<'t>(PhantomData<&'t String>); #[derive(CloneRef,Derivative)] #[derivative(Clone(bound=""))] diff --git a/lib/rust/shapely/macros/src/derive_clone_ref.rs b/lib/rust/shapely/macros/src/derive_clone_ref.rs index eb40183ee5..28f4fde35d 100644 --- a/lib/rust/shapely/macros/src/derive_clone_ref.rs +++ b/lib/rust/shapely/macros/src/derive_clone_ref.rs @@ -147,9 +147,7 @@ pub fn clone_ref_bounds(attr:&Attribute) -> Option> { Meta::List(ml) => ml.nested, _ => panic!("Attribute contents does not conform to meta item."), }; - if list.len() > 1 { - panic!("Only a single entry within `{}` attribute is allowed.",CLONE_REF_ATTR); - } + assert!(list.len() <= 1,"Only a single entry within `{}` attribute is allowed.",CLONE_REF_ATTR); let bound_value = match list.first() { Some(NestedMeta::Meta(Meta::NameValue(name_val))) => { if is_custom_bound(name_val) { diff --git a/lib/rust/shapely/macros/src/derive_iterator.rs b/lib/rust/shapely/macros/src/derive_iterator.rs index 360d3fc1f5..5b6fb6ba5b 100644 --- a/lib/rust/shapely/macros/src/derive_iterator.rs +++ b/lib/rust/shapely/macros/src/derive_iterator.rs @@ -91,7 +91,7 @@ impl<'t> DependentValue<'t> { match self.ty { syn::Type::Tuple(tuple) => self.yield_tuple_value(tuple, is_mut), syn::Type::Path(path) => { - if type_matches(&self.ty, &self.target_param) { + if type_matches(self.ty, self.target_param) { self.yield_direct_value(is_mut) } else { self.yield_dependent_ty_path_value(path,is_mut) diff --git a/rust-toolchain b/rust-toolchain new file mode 100644 index 0000000000..986feef291 --- /dev/null +++ b/rust-toolchain @@ -0,0 +1 @@ +nightly-2021-10-29