Skip to content

Apply #![deny(rust_2018_idioms] to all crate roots #100

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions macros/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![deny(rust_2018_idioms)]

extern crate gll;
extern crate proc_macro;
extern crate proc_quote;
Expand Down
2 changes: 2 additions & 0 deletions macros/tests/basic.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![deny(rust_2018_idioms)]

extern crate gll;
extern crate gll_macros;

Expand Down
2 changes: 2 additions & 0 deletions macros/tests/json.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![deny(rust_2018_idioms)]

extern crate gll;
extern crate gll_macros;
extern crate proc_quote;
Expand Down
72 changes: 36 additions & 36 deletions src/generate/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,13 @@ impl<Pat> Rule<Pat> {
// FIXME(eddyb) this should just work with `self: &Rc<Self>` on inherent methods,
// but that still requires `#![feature(arbitrary_self_types)]`.
trait RcRuleRuleMapMethods<Pat>: Sized {
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>);
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<Pat: Ord + Hash + RustInputPat> RcRuleRuleMapMethods<Pat> for Rc<Rule<Pat>> {
fn parse_node_kind(&self, rules: &RuleMap<Pat>) -> ParseNodeKind {
fn parse_node_kind(&self, rules: &RuleMap<'_, Pat>) -> ParseNodeKind {
if let Rule::Call(r) = &**self {
return ParseNodeKind::NamedRule(r.clone());
}
Expand All @@ -152,7 +152,7 @@ impl<Pat: Ord + Hash + RustInputPat> RcRuleRuleMapMethods<Pat> for Rc<Rule<Pat>>
rules.anon.borrow_mut().insert(self.clone());
ParseNodeKind::Anon(i)
}
fn parse_node_desc(&self, rules: &RuleMap<Pat>) -> String {
fn parse_node_desc(&self, rules: &RuleMap<'_, Pat>) -> String {
if let Some(desc) = rules.desc.borrow().get(self) {
return desc.clone();
}
Expand All @@ -163,7 +163,7 @@ impl<Pat: Ord + Hash + RustInputPat> RcRuleRuleMapMethods<Pat> for Rc<Rule<Pat>>
}
}
// FIXME(eddyb) this probably doesn't need the "fill" API anymore.
fn fill_parse_node_shape(&self, rules: &RuleMap<Pat>) {
fn fill_parse_node_shape(&self, rules: &RuleMap<'_, Pat>) {
if let Rule::Call(_) = **self {
return;
}
Expand All @@ -177,7 +177,7 @@ impl<Pat: Ord + Hash + RustInputPat> RcRuleRuleMapMethods<Pat> for Rc<Rule<Pat>>
}

impl<Pat: Ord + Hash + RustInputPat> Rule<Pat> {
fn parse_node_desc_uncached(&self, rules: &RuleMap<Pat>) -> 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(),
Expand Down Expand Up @@ -215,7 +215,7 @@ impl<Pat: Ord + Hash + RustInputPat> Rule<Pat> {

fn parse_node_shape_uncached(
rc_self: &Rc<Self>,
rules: &RuleMap<Pat>,
rules: &RuleMap<'_, Pat>,
) -> ParseNodeShape<ParseNodeKind> {
match &**rc_self {
Rule::Empty | Rule::Eat(_) | Rule::NegativeLookahead(_) => ParseNodeShape::Opaque,
Expand Down Expand Up @@ -288,7 +288,7 @@ enum CodeLabel {
}

impl CodeLabel {
fn flattened_name(&self) -> Cow<str> {
fn flattened_name(&self) -> Cow<'_, str> {
match self {
CodeLabel::NamedRule(r) => r.into(),
CodeLabel::Nested { parent, i } => {
Expand Down Expand Up @@ -357,7 +357,7 @@ impl<Pat: Ord + Hash + MatchesEmpty + RustInputPat> Grammar<Pat> {
} 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 {
Expand All @@ -369,7 +369,7 @@ impl<Pat: Ord + Hash + MatchesEmpty + RustInputPat> Grammar<Pat> {
Rule::Eat(_) => Some(quote!([()])),
Rule::Call(r) => {
let ident = Src::ident(r);
Some(quote!([#ident<_>]))
Some(quote!([#ident<'_, '_, _>]))
}
_ => None,
},
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -464,19 +464,19 @@ impl Continuation<'_> {
}

trait ContFn {
fn apply(self, cont: Continuation) -> Continuation;
fn apply(self, cont: Continuation<'_>) -> Continuation<'_>;
}

impl<F: FnOnce(Continuation) -> Continuation> ContFn for F {
fn apply(self, cont: Continuation) -> Continuation {
impl<F: FnOnce(Continuation<'_>) -> Continuation<'_>> ContFn for F {
fn apply(self, cont: Continuation<'_>) -> Continuation<'_> {
self(cont)
}
}

struct Compose<F, G>(F, G);

impl<F: ContFn, G: ContFn> ContFn for Compose<F, G> {
fn apply(self, cont: Continuation) -> Continuation {
fn apply(self, cont: Continuation<'_>) -> Continuation<'_> {
self.1.apply(self.0.apply(cont))
}
}
Expand All @@ -487,7 +487,7 @@ struct Thunk<F>(F);
impl<F> Thunk<F> {
fn new(f: F) -> Self
where
F: FnOnce(Continuation) -> Continuation,
F: FnOnce(Continuation<'_>) -> Continuation<'_>,
{
Thunk(f)
}
Expand All @@ -501,7 +501,7 @@ impl<F, G> Add<Thunk<G>> for Thunk<F> {
}

impl<F: ContFn> ContFn for Thunk<F> {
fn apply(self, cont: Continuation) -> Continuation {
fn apply(self, cont: Continuation<'_>) -> Continuation<'_> {
self.0.apply(cont)
}
}
Expand Down Expand Up @@ -591,14 +591,14 @@ fn sppf_add(parse_node_kind: &ParseNodeKind, child: Src) -> Thunk<impl ContFn> {
}

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<F> ForEachThunk for Thunk<F>
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()));
}
}
Expand All @@ -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);
}
Expand All @@ -621,7 +621,7 @@ where
I: Iterator<Item = T>,
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);
});
Expand Down Expand Up @@ -701,7 +701,7 @@ impl<Pat: Ord + Hash + RustInputPat> Rule<Pat> {
// but can't be `self` itself without `#![feature(arbitrary_self_types)]`.
fn generate_parse<'a>(
&'a self,
rc_self_and_rules: Option<(&'a Rc<Self>, &'a RuleMap<Pat>)>,
rc_self_and_rules: Option<(&'a Rc<Self>, &'a RuleMap<'_, Pat>)>,
) -> Thunk<impl ContFn + 'a> {
if let Some((rc_self, _)) = rc_self_and_rules {
assert!(std::ptr::eq(self, &**rc_self));
Expand Down Expand Up @@ -804,7 +804,7 @@ impl<Pat: Ord + Hash + RustInputPat> Rule<Pat> {
}

impl<Pat: Ord + Hash + RustInputPat> Rule<Pat> {
fn generate_traverse_shape(&self, refutable: bool, rules: &RuleMap<Pat>) -> Src {
fn generate_traverse_shape(&self, refutable: bool, rules: &RuleMap<'_, Pat>) -> Src {
match self {
Rule::Empty
| Rule::Eat(_)
Expand Down Expand Up @@ -884,7 +884,7 @@ where
)
}

fn declare_rule<Pat>(name: &str, rule: &RuleWithNamedFields<Pat>, rules: &RuleMap<Pat>) -> Src
fn declare_rule<Pat>(name: &str, rule: &RuleWithNamedFields<Pat>, rules: &RuleMap<'_, Pat>) -> Src
where
Pat: Ord + Hash + RustInputPat,
{
Expand Down Expand Up @@ -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),*
}
)
Expand All @@ -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
}
Expand All @@ -954,7 +954,7 @@ fn impl_rule_from_sppf<Pat>(
name: &str,
rule: &RuleWithNamedFields<Pat>,
variants: Option<&[Variant<'_, Pat>]>,
rules: &RuleMap<Pat>,
rules: &RuleMap<'_, Pat>,
) -> Src
where
Pat: Ord + Hash + RustInputPat,
Expand Down Expand Up @@ -1057,7 +1057,7 @@ fn impl_rule_one_and_all<Pat>(
name: &str,
rule: &RuleWithNamedFields<Pat>,
variants: Option<&[Variant<'_, Pat>]>,
rules: &RuleMap<Pat>,
rules: &RuleMap<'_, Pat>,
) -> Src
where
Pat: Ord + Hash + RustInputPat,
Expand Down Expand Up @@ -1230,7 +1230,7 @@ fn rule_debug_impl<Pat>(
)
};
quote!(impl<I: ::gll::runtime::Input> fmt::Debug for #ident<'_, '_, I> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
#body
}
})
Expand All @@ -1255,23 +1255,23 @@ 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(())
}
}

impl<I: ::gll::runtime::Input> fmt::Debug for OwnedHandle<I, #ident<'_, '_, I>> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.with(|handle| handle.fmt(f))
}
}
)
}

fn define_parse_fn<Pat>(
rules: &RuleMap<Pat>,
rules: &RuleMap<'_, Pat>,
code_labels: &mut OrderMap<Rc<CodeLabel>, usize>,
) -> Src
where
Expand Down Expand Up @@ -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),*
};
Expand Down Expand Up @@ -1380,7 +1380,7 @@ fn impl_debug_for_handle_any(all_parse_nodes: &[ParseNode]) -> Src {
})
});
quote!(impl<I: ::gll::runtime::Input> 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::<_, ()> {
Expand All @@ -1394,7 +1394,7 @@ fn impl_debug_for_handle_any(all_parse_nodes: &[ParseNode]) -> Src {
}

fn code_label_decl_and_impls<Pat>(
rules: &RuleMap<Pat>,
rules: &RuleMap<'_, Pat>,
code_labels: &OrderMap<Rc<CodeLabel>, usize>,
) -> Src {
let all_labels = rules
Expand Down
6 changes: 3 additions & 3 deletions src/generate/src.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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, " ")?;
}
Expand All @@ -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)?;
}
Expand Down
8 changes: 4 additions & 4 deletions src/generate/templates/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ impl<I: ::gll::runtime::Input, T: ?Sized> OwnedHandle<I, T> {
}
}

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<T>,
Expand Down Expand Up @@ -65,7 +65,7 @@ impl<'a, 'i, I: ::gll::runtime::Input, T> From<Ambiguity<Handle<'a, 'i, I, [T]>>
}

impl<I: ::gll::runtime::Input> 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())
}
}
Expand All @@ -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) => {
Expand All @@ -87,7 +87,7 @@ where
Spread(L),
}
impl<T: fmt::Debug, L: fmt::Debug> fmt::Debug for Elem<T, L> {
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) => {
Expand Down
2 changes: 1 addition & 1 deletion src/grammar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ pub enum ParseNodeShape<P> {
}

impl<P: fmt::Display> fmt::Display for ParseNodeShape<P> {
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),
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![deny(unsafe_code)]
#![deny(rust_2018_idioms)]

extern crate indexing;
extern crate ordermap;
Expand Down
2 changes: 1 addition & 1 deletion src/parse_grammar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ impl Modifier<'_, '_, &str> {

impl Pattern<'_, '_, &str> {
fn lower(self) -> SPat {
fn unescape<T>(handle: Handle<&str, T>) -> String {
fn unescape<T>(handle: Handle<'_, '_, &str, T>) -> String {
let mut out = String::new();
let s = handle.source();
let mut chars = s[1..s.len() - 1].chars();
Expand Down
Loading