diff --git a/macros/src/lib.rs b/macros/src/lib.rs index 01a1e31..809d692 100644 --- a/macros/src/lib.rs +++ b/macros/src/lib.rs @@ -1,3 +1,5 @@ +#![deny(rust_2018_idioms)] + extern crate gll; extern crate proc_macro; extern crate proc_quote; diff --git a/macros/tests/basic.rs b/macros/tests/basic.rs index 7f5f91c..8f37f5b 100644 --- a/macros/tests/basic.rs +++ b/macros/tests/basic.rs @@ -1,3 +1,5 @@ +#![deny(rust_2018_idioms)] + extern crate gll; extern crate gll_macros; diff --git a/macros/tests/json.rs b/macros/tests/json.rs index db8d991..2bfd88b 100644 --- a/macros/tests/json.rs +++ b/macros/tests/json.rs @@ -1,3 +1,5 @@ +#![deny(rust_2018_idioms)] + extern crate gll; extern crate gll_macros; extern crate proc_quote; diff --git a/src/generate/rust.rs b/src/generate/rust.rs index 93f8bdf..495fba0 100644 --- a/src/generate/rust.rs +++ b/src/generate/rust.rs @@ -134,13 +134,13 @@ impl Rule { // FIXME(eddyb) this should just work with `self: &Rc` on inherent methods, // but that still requires `#![feature(arbitrary_self_types)]`. trait RcRuleRuleMapMethods: Sized { - fn parse_node_kind(&self, rules: &RuleMap) -> ParseNodeKind; - fn parse_node_desc(&self, rules: &RuleMap) -> String; - fn fill_parse_node_shape(&self, rules: &RuleMap); + fn parse_node_kind(&self, rules: &RuleMap<'_, Pat>) -> ParseNodeKind; + fn parse_node_desc(&self, rules: &RuleMap<'_, Pat>) -> String; + fn fill_parse_node_shape(&self, rules: &RuleMap<'_, Pat>); } impl RcRuleRuleMapMethods for Rc> { - fn parse_node_kind(&self, rules: &RuleMap) -> ParseNodeKind { + fn parse_node_kind(&self, rules: &RuleMap<'_, Pat>) -> ParseNodeKind { if let Rule::Call(r) = &**self { return ParseNodeKind::NamedRule(r.clone()); } @@ -152,7 +152,7 @@ impl RcRuleRuleMapMethods for Rc> rules.anon.borrow_mut().insert(self.clone()); ParseNodeKind::Anon(i) } - fn parse_node_desc(&self, rules: &RuleMap) -> String { + fn parse_node_desc(&self, rules: &RuleMap<'_, Pat>) -> String { if let Some(desc) = rules.desc.borrow().get(self) { return desc.clone(); } @@ -163,7 +163,7 @@ impl RcRuleRuleMapMethods for Rc> } } // FIXME(eddyb) this probably doesn't need the "fill" API anymore. - fn fill_parse_node_shape(&self, rules: &RuleMap) { + fn fill_parse_node_shape(&self, rules: &RuleMap<'_, Pat>) { if let Rule::Call(_) = **self { return; } @@ -177,7 +177,7 @@ impl RcRuleRuleMapMethods for Rc> } impl Rule { - fn parse_node_desc_uncached(&self, rules: &RuleMap) -> String { + fn parse_node_desc_uncached(&self, rules: &RuleMap<'_, Pat>) -> String { match self { Rule::Empty => "".to_string(), Rule::Eat(pat) => pat.rust_matcher().to_pretty_string(), @@ -215,7 +215,7 @@ impl Rule { fn parse_node_shape_uncached( rc_self: &Rc, - rules: &RuleMap, + rules: &RuleMap<'_, Pat>, ) -> ParseNodeShape { match &**rc_self { Rule::Empty | Rule::Eat(_) | Rule::NegativeLookahead(_) => ParseNodeShape::Opaque, @@ -288,7 +288,7 @@ enum CodeLabel { } impl CodeLabel { - fn flattened_name(&self) -> Cow { + fn flattened_name(&self) -> Cow<'_, str> { match self { CodeLabel::NamedRule(r) => r.into(), CodeLabel::Nested { parent, i } => { @@ -357,7 +357,7 @@ impl Grammar { } else { ParseNodeShape::Alias(rule.rule.parse_node_kind(rules)) }, - ty: Some(quote!(#ident<_>)), + ty: Some(quote!(#ident<'_, '_, _>)), } }) .chain(rules.anon.borrow().iter().map(|rule| ParseNode { @@ -369,7 +369,7 @@ impl Grammar { Rule::Eat(_) => Some(quote!([()])), Rule::Call(r) => { let ident = Src::ident(r); - Some(quote!([#ident<_>])) + Some(quote!([#ident<'_, '_, _>])) } _ => None, }, @@ -413,7 +413,7 @@ impl Continuation<'_> { label } - fn clone(&mut self) -> Continuation { + fn clone(&mut self) -> Continuation<'_> { Continuation { code_labels: self.code_labels, fn_code_label: self.fn_code_label, @@ -464,11 +464,11 @@ impl Continuation<'_> { } trait ContFn { - fn apply(self, cont: Continuation) -> Continuation; + fn apply(self, cont: Continuation<'_>) -> Continuation<'_>; } -impl Continuation> ContFn for F { - fn apply(self, cont: Continuation) -> Continuation { +impl) -> Continuation<'_>> ContFn for F { + fn apply(self, cont: Continuation<'_>) -> Continuation<'_> { self(cont) } } @@ -476,7 +476,7 @@ impl Continuation> ContFn for F { struct Compose(F, G); impl ContFn for Compose { - fn apply(self, cont: Continuation) -> Continuation { + fn apply(self, cont: Continuation<'_>) -> Continuation<'_> { self.1.apply(self.0.apply(cont)) } } @@ -487,7 +487,7 @@ struct Thunk(F); impl Thunk { fn new(f: F) -> Self where - F: FnOnce(Continuation) -> Continuation, + F: FnOnce(Continuation<'_>) -> Continuation<'_>, { Thunk(f) } @@ -501,7 +501,7 @@ impl Add> for Thunk { } impl ContFn for Thunk { - fn apply(self, cont: Continuation) -> Continuation { + fn apply(self, cont: Continuation<'_>) -> Continuation<'_> { self.0.apply(cont) } } @@ -591,14 +591,14 @@ fn sppf_add(parse_node_kind: &ParseNodeKind, child: Src) -> Thunk { } trait ForEachThunk { - fn for_each_thunk(self, cont: &mut Continuation, f: impl FnMut(Continuation)); + fn for_each_thunk(self, cont: &mut Continuation<'_>, f: impl FnMut(Continuation<'_>)); } impl ForEachThunk for Thunk where F: ContFn, { - fn for_each_thunk(self, cont: &mut Continuation, mut f: impl FnMut(Continuation)) { + fn for_each_thunk(self, cont: &mut Continuation<'_>, mut f: impl FnMut(Continuation<'_>)) { f(self.apply(cont.clone())); } } @@ -608,7 +608,7 @@ where T: ForEachThunk, U: ForEachThunk, { - fn for_each_thunk(self, cont: &mut Continuation, mut f: impl FnMut(Continuation)) { + fn for_each_thunk(self, cont: &mut Continuation<'_>, mut f: impl FnMut(Continuation<'_>)) { self.0.for_each_thunk(cont, &mut f); self.1.for_each_thunk(cont, &mut f); } @@ -621,7 +621,7 @@ where I: Iterator, T: ForEachThunk, { - fn for_each_thunk(self, cont: &mut Continuation, mut f: impl FnMut(Continuation)) { + fn for_each_thunk(self, cont: &mut Continuation<'_>, mut f: impl FnMut(Continuation<'_>)) { self.0.for_each(|x| { x.for_each_thunk(cont, &mut f); }); @@ -701,7 +701,7 @@ impl Rule { // but can't be `self` itself without `#![feature(arbitrary_self_types)]`. fn generate_parse<'a>( &'a self, - rc_self_and_rules: Option<(&'a Rc, &'a RuleMap)>, + rc_self_and_rules: Option<(&'a Rc, &'a RuleMap<'_, Pat>)>, ) -> Thunk { if let Some((rc_self, _)) = rc_self_and_rules { assert!(std::ptr::eq(self, &**rc_self)); @@ -804,7 +804,7 @@ impl Rule { } impl Rule { - fn generate_traverse_shape(&self, refutable: bool, rules: &RuleMap) -> Src { + fn generate_traverse_shape(&self, refutable: bool, rules: &RuleMap<'_, Pat>) -> Src { match self { Rule::Empty | Rule::Eat(_) @@ -884,7 +884,7 @@ where ) } -fn declare_rule(name: &str, rule: &RuleWithNamedFields, rules: &RuleMap) -> Src +fn declare_rule(name: &str, rule: &RuleWithNamedFields, rules: &RuleMap<'_, Pat>) -> Src where Pat: Ord + Hash + RustInputPat, { @@ -921,7 +921,7 @@ where }); quote!( #[allow(non_camel_case_types)] - pub enum #ident<'a, 'i: 'a, I: 'a + ::gll::runtime::Input> { + pub enum #ident<'a, 'i, I: ::gll::runtime::Input> { #(#variants),* } ) @@ -938,7 +938,7 @@ where }; quote!( #[allow(non_camel_case_types)] - pub struct #ident<'a, 'i: 'a, I: 'a + ::gll::runtime::Input> { + pub struct #ident<'a, 'i, I: ::gll::runtime::Input> { #(pub #fields_ident: #fields_ty),* #marker_field } @@ -954,7 +954,7 @@ fn impl_rule_from_sppf( name: &str, rule: &RuleWithNamedFields, variants: Option<&[Variant<'_, Pat>]>, - rules: &RuleMap, + rules: &RuleMap<'_, Pat>, ) -> Src where Pat: Ord + Hash + RustInputPat, @@ -1057,7 +1057,7 @@ fn impl_rule_one_and_all( name: &str, rule: &RuleWithNamedFields, variants: Option<&[Variant<'_, Pat>]>, - rules: &RuleMap, + rules: &RuleMap<'_, Pat>, ) -> Src where Pat: Ord + Hash + RustInputPat, @@ -1230,7 +1230,7 @@ fn rule_debug_impl( ) }; quote!(impl fmt::Debug for #ident<'_, '_, I> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { #body } }) @@ -1255,7 +1255,7 @@ fn rule_handle_debug_impl(name: &str, has_fields: bool) -> Src { }; quote!( impl<'a, 'i, I: ::gll::runtime::Input> fmt::Debug for Handle<'a, 'i, I, #ident<'a, 'i, I>> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{:?}", self.source_info())?; #body Ok(()) @@ -1263,7 +1263,7 @@ fn rule_handle_debug_impl(name: &str, has_fields: bool) -> Src { } impl fmt::Debug for OwnedHandle> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { self.with(|handle| handle.fmt(f)) } } @@ -1271,7 +1271,7 @@ fn rule_handle_debug_impl(name: &str, has_fields: bool) -> Src { } fn define_parse_fn( - rules: &RuleMap, + rules: &RuleMap<'_, Pat>, code_labels: &mut OrderMap, usize>, ) -> Src where @@ -1343,7 +1343,7 @@ fn declare_parse_node_kind(all_parse_nodes: &[ParseNode]) -> Src { )* } impl fmt::Display for _P { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let s = match *self { #(#nodes_kind => #nodes_desc),* }; @@ -1380,7 +1380,7 @@ fn impl_debug_for_handle_any(all_parse_nodes: &[ParseNode]) -> Src { }) }); quote!(impl fmt::Debug for Handle<'_, '_, I, Any> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self.node.kind { #(#arms)* _ => write!(f, "{:?}", Handle::<_, ()> { @@ -1394,7 +1394,7 @@ fn impl_debug_for_handle_any(all_parse_nodes: &[ParseNode]) -> Src { } fn code_label_decl_and_impls( - rules: &RuleMap, + rules: &RuleMap<'_, Pat>, code_labels: &OrderMap, usize>, ) -> Src { let all_labels = rules diff --git a/src/generate/src.rs b/src/generate/src.rs index 6b14c8f..47476ec 100644 --- a/src/generate/src.rs +++ b/src/generate/src.rs @@ -155,7 +155,7 @@ enum Elem { } impl fmt::Display for Elem { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { Elem::Char(c, _) => c.fmt(f), Elem::Ident(i) => i.fmt(f), @@ -227,7 +227,7 @@ struct Line { } impl fmt::Display for Line { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { for _ in 0..self.indent { write!(f, " ")?; } @@ -245,7 +245,7 @@ pub struct Fragment { } impl fmt::Display for Fragment { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { for elem in &self.before { elem.fmt(f)?; } diff --git a/src/generate/templates/header.rs b/src/generate/templates/header.rs index 6166da3..9e8c1cd 100644 --- a/src/generate/templates/header.rs +++ b/src/generate/templates/header.rs @@ -17,7 +17,7 @@ impl OwnedHandle { } } -pub struct Handle<'a, 'i: 'a, I: 'a + ::gll::runtime::Input, T: ?Sized> { +pub struct Handle<'a, 'i, I: ::gll::runtime::Input, T: ?Sized> { pub node: ParseNode<'i, _P>, pub forest: &'a ::gll::runtime::ParseForest<'i, _P, I>, _marker: PhantomData, @@ -65,7 +65,7 @@ impl<'a, 'i, I: ::gll::runtime::Input, T> From> } impl fmt::Debug for Handle<'_, '_, I, ()> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{:?}", self.source_info()) } } @@ -74,7 +74,7 @@ impl<'a, 'i, I: ::gll::runtime::Input, T> fmt::Debug for Handle<'a, 'i, I, [T]> where Handle<'a, 'i, I, T>: fmt::Debug, { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{:?} => ", self.source_info())?; match self.all_list_heads() { ListHead::Cons(cons) => { @@ -87,7 +87,7 @@ where Spread(L), } impl fmt::Debug for Elem { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { Elem::One(x) => fmt::Debug::fmt(x, f), Elem::Spread(xs) => { diff --git a/src/grammar.rs b/src/grammar.rs index 7230122..a38caaf 100644 --- a/src/grammar.rs +++ b/src/grammar.rs @@ -593,7 +593,7 @@ pub enum ParseNodeShape

{ } impl fmt::Display for ParseNodeShape

{ - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { ParseNodeShape::Opaque => write!(f, "Opaque"), ParseNodeShape::Alias(inner) => write!(f, "Alias({})", inner), diff --git a/src/lib.rs b/src/lib.rs index 2887caa..3e366af 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,5 @@ #![deny(unsafe_code)] +#![deny(rust_2018_idioms)] extern crate indexing; extern crate ordermap; diff --git a/src/parse_grammar.rs b/src/parse_grammar.rs index 01ddfa5..62977c8 100644 --- a/src/parse_grammar.rs +++ b/src/parse_grammar.rs @@ -87,7 +87,7 @@ impl Modifier<'_, '_, &str> { impl Pattern<'_, '_, &str> { fn lower(self) -> SPat { - fn unescape(handle: Handle<&str, T>) -> String { + fn unescape(handle: Handle<'_, '_, &str, T>) -> String { let mut out = String::new(); let s = handle.source(); let mut chars = s[1..s.len() - 1].chars(); diff --git a/src/runtime.rs b/src/runtime.rs index 422ec63..76de3ec 100644 --- a/src/runtime.rs +++ b/src/runtime.rs @@ -53,7 +53,7 @@ pub struct LineColumn { } impl fmt::Debug for LineColumn { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}:{}", 1 + self.line, 1 + self.column) } } @@ -76,7 +76,7 @@ pub struct LineColumnRange { } impl fmt::Debug for LineColumnRange { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{:?}-{:?}", self.start, self.end) } } @@ -437,7 +437,7 @@ pub struct Call<'i, C> { } impl fmt::Display for Call<'_, C> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!( f, "{}({}..{})", @@ -468,7 +468,7 @@ impl GraphStack<'_, C> { // FIXME(eddyb) figure out what to do here, now that // the GSS is no longer exposed in the public API. #[allow(unused)] - fn dump_graphviz(&self, out: &mut Write) -> io::Result<()> { + fn dump_graphviz(&self, out: &mut dyn Write) -> io::Result<()> { writeln!(out, "digraph gss {{")?; writeln!(out, " graph [rankdir=RL]")?; for (call, returns) in &self.returns { @@ -620,7 +620,7 @@ impl<'i, P: ParseNodeKind, I: Input> ParseForest<'i, P, I> { } } - pub fn dump_graphviz(&self, out: &mut Write) -> io::Result<()> { + pub fn dump_graphviz(&self, out: &mut dyn Write) -> io::Result<()> { writeln!(out, "digraph sppf {{")?; let mut queue: VecDeque<_> = self.possibilities.keys().cloned().collect(); let mut seen: BTreeSet<_> = queue.iter().cloned().collect(); @@ -710,7 +710,7 @@ impl ParseNode<'_, P> { } impl fmt::Display for ParseNode<'_, P> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!( f, "{} @ {}..{}", @@ -722,7 +722,7 @@ impl fmt::Display for ParseNode<'_, P> { } impl fmt::Debug for ParseNode<'_, P> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!( f, "{} @ {}..{}",