Skip to content

Commit 7f148d8

Browse files
authored
Merge pull request #100 from Centril/idiomatic
Apply `#![deny(rust_2018_idioms]` to all crate roots
2 parents 8845b71 + aace166 commit 7f148d8

File tree

10 files changed

+59
-52
lines changed

10 files changed

+59
-52
lines changed

macros/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![deny(rust_2018_idioms)]
2+
13
extern crate gll;
24
extern crate proc_macro;
35
extern crate proc_quote;

macros/tests/basic.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![deny(rust_2018_idioms)]
2+
13
extern crate gll;
24
extern crate gll_macros;
35

macros/tests/json.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![deny(rust_2018_idioms)]
2+
13
extern crate gll;
24
extern crate gll_macros;
35
extern crate proc_quote;

src/generate/rust.rs

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,13 @@ impl<Pat> Rule<Pat> {
134134
// FIXME(eddyb) this should just work with `self: &Rc<Self>` on inherent methods,
135135
// but that still requires `#![feature(arbitrary_self_types)]`.
136136
trait RcRuleRuleMapMethods<Pat>: Sized {
137-
fn parse_node_kind(&self, rules: &RuleMap<Pat>) -> ParseNodeKind;
138-
fn parse_node_desc(&self, rules: &RuleMap<Pat>) -> String;
139-
fn fill_parse_node_shape(&self, rules: &RuleMap<Pat>);
137+
fn parse_node_kind(&self, rules: &RuleMap<'_, Pat>) -> ParseNodeKind;
138+
fn parse_node_desc(&self, rules: &RuleMap<'_, Pat>) -> String;
139+
fn fill_parse_node_shape(&self, rules: &RuleMap<'_, Pat>);
140140
}
141141

142142
impl<Pat: Ord + Hash + RustInputPat> RcRuleRuleMapMethods<Pat> for Rc<Rule<Pat>> {
143-
fn parse_node_kind(&self, rules: &RuleMap<Pat>) -> ParseNodeKind {
143+
fn parse_node_kind(&self, rules: &RuleMap<'_, Pat>) -> ParseNodeKind {
144144
if let Rule::Call(r) = &**self {
145145
return ParseNodeKind::NamedRule(r.clone());
146146
}
@@ -152,7 +152,7 @@ impl<Pat: Ord + Hash + RustInputPat> RcRuleRuleMapMethods<Pat> for Rc<Rule<Pat>>
152152
rules.anon.borrow_mut().insert(self.clone());
153153
ParseNodeKind::Anon(i)
154154
}
155-
fn parse_node_desc(&self, rules: &RuleMap<Pat>) -> String {
155+
fn parse_node_desc(&self, rules: &RuleMap<'_, Pat>) -> String {
156156
if let Some(desc) = rules.desc.borrow().get(self) {
157157
return desc.clone();
158158
}
@@ -163,7 +163,7 @@ impl<Pat: Ord + Hash + RustInputPat> RcRuleRuleMapMethods<Pat> for Rc<Rule<Pat>>
163163
}
164164
}
165165
// FIXME(eddyb) this probably doesn't need the "fill" API anymore.
166-
fn fill_parse_node_shape(&self, rules: &RuleMap<Pat>) {
166+
fn fill_parse_node_shape(&self, rules: &RuleMap<'_, Pat>) {
167167
if let Rule::Call(_) = **self {
168168
return;
169169
}
@@ -177,7 +177,7 @@ impl<Pat: Ord + Hash + RustInputPat> RcRuleRuleMapMethods<Pat> for Rc<Rule<Pat>>
177177
}
178178

179179
impl<Pat: Ord + Hash + RustInputPat> Rule<Pat> {
180-
fn parse_node_desc_uncached(&self, rules: &RuleMap<Pat>) -> String {
180+
fn parse_node_desc_uncached(&self, rules: &RuleMap<'_, Pat>) -> String {
181181
match self {
182182
Rule::Empty => "".to_string(),
183183
Rule::Eat(pat) => pat.rust_matcher().to_pretty_string(),
@@ -215,7 +215,7 @@ impl<Pat: Ord + Hash + RustInputPat> Rule<Pat> {
215215

216216
fn parse_node_shape_uncached(
217217
rc_self: &Rc<Self>,
218-
rules: &RuleMap<Pat>,
218+
rules: &RuleMap<'_, Pat>,
219219
) -> ParseNodeShape<ParseNodeKind> {
220220
match &**rc_self {
221221
Rule::Empty | Rule::Eat(_) | Rule::NegativeLookahead(_) => ParseNodeShape::Opaque,
@@ -288,7 +288,7 @@ enum CodeLabel {
288288
}
289289

290290
impl CodeLabel {
291-
fn flattened_name(&self) -> Cow<str> {
291+
fn flattened_name(&self) -> Cow<'_, str> {
292292
match self {
293293
CodeLabel::NamedRule(r) => r.into(),
294294
CodeLabel::Nested { parent, i } => {
@@ -357,7 +357,7 @@ impl<Pat: Ord + Hash + MatchesEmpty + RustInputPat> Grammar<Pat> {
357357
} else {
358358
ParseNodeShape::Alias(rule.rule.parse_node_kind(rules))
359359
},
360-
ty: Some(quote!(#ident<_>)),
360+
ty: Some(quote!(#ident<'_, '_, _>)),
361361
}
362362
})
363363
.chain(rules.anon.borrow().iter().map(|rule| ParseNode {
@@ -369,7 +369,7 @@ impl<Pat: Ord + Hash + MatchesEmpty + RustInputPat> Grammar<Pat> {
369369
Rule::Eat(_) => Some(quote!([()])),
370370
Rule::Call(r) => {
371371
let ident = Src::ident(r);
372-
Some(quote!([#ident<_>]))
372+
Some(quote!([#ident<'_, '_, _>]))
373373
}
374374
_ => None,
375375
},
@@ -413,7 +413,7 @@ impl Continuation<'_> {
413413
label
414414
}
415415

416-
fn clone(&mut self) -> Continuation {
416+
fn clone(&mut self) -> Continuation<'_> {
417417
Continuation {
418418
code_labels: self.code_labels,
419419
fn_code_label: self.fn_code_label,
@@ -464,19 +464,19 @@ impl Continuation<'_> {
464464
}
465465

466466
trait ContFn {
467-
fn apply(self, cont: Continuation) -> Continuation;
467+
fn apply(self, cont: Continuation<'_>) -> Continuation<'_>;
468468
}
469469

470-
impl<F: FnOnce(Continuation) -> Continuation> ContFn for F {
471-
fn apply(self, cont: Continuation) -> Continuation {
470+
impl<F: FnOnce(Continuation<'_>) -> Continuation<'_>> ContFn for F {
471+
fn apply(self, cont: Continuation<'_>) -> Continuation<'_> {
472472
self(cont)
473473
}
474474
}
475475

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

478478
impl<F: ContFn, G: ContFn> ContFn for Compose<F, G> {
479-
fn apply(self, cont: Continuation) -> Continuation {
479+
fn apply(self, cont: Continuation<'_>) -> Continuation<'_> {
480480
self.1.apply(self.0.apply(cont))
481481
}
482482
}
@@ -487,7 +487,7 @@ struct Thunk<F>(F);
487487
impl<F> Thunk<F> {
488488
fn new(f: F) -> Self
489489
where
490-
F: FnOnce(Continuation) -> Continuation,
490+
F: FnOnce(Continuation<'_>) -> Continuation<'_>,
491491
{
492492
Thunk(f)
493493
}
@@ -501,7 +501,7 @@ impl<F, G> Add<Thunk<G>> for Thunk<F> {
501501
}
502502

503503
impl<F: ContFn> ContFn for Thunk<F> {
504-
fn apply(self, cont: Continuation) -> Continuation {
504+
fn apply(self, cont: Continuation<'_>) -> Continuation<'_> {
505505
self.0.apply(cont)
506506
}
507507
}
@@ -591,14 +591,14 @@ fn sppf_add(parse_node_kind: &ParseNodeKind, child: Src) -> Thunk<impl ContFn> {
591591
}
592592

593593
trait ForEachThunk {
594-
fn for_each_thunk(self, cont: &mut Continuation, f: impl FnMut(Continuation));
594+
fn for_each_thunk(self, cont: &mut Continuation<'_>, f: impl FnMut(Continuation<'_>));
595595
}
596596

597597
impl<F> ForEachThunk for Thunk<F>
598598
where
599599
F: ContFn,
600600
{
601-
fn for_each_thunk(self, cont: &mut Continuation, mut f: impl FnMut(Continuation)) {
601+
fn for_each_thunk(self, cont: &mut Continuation<'_>, mut f: impl FnMut(Continuation<'_>)) {
602602
f(self.apply(cont.clone()));
603603
}
604604
}
@@ -608,7 +608,7 @@ where
608608
T: ForEachThunk,
609609
U: ForEachThunk,
610610
{
611-
fn for_each_thunk(self, cont: &mut Continuation, mut f: impl FnMut(Continuation)) {
611+
fn for_each_thunk(self, cont: &mut Continuation<'_>, mut f: impl FnMut(Continuation<'_>)) {
612612
self.0.for_each_thunk(cont, &mut f);
613613
self.1.for_each_thunk(cont, &mut f);
614614
}
@@ -621,7 +621,7 @@ where
621621
I: Iterator<Item = T>,
622622
T: ForEachThunk,
623623
{
624-
fn for_each_thunk(self, cont: &mut Continuation, mut f: impl FnMut(Continuation)) {
624+
fn for_each_thunk(self, cont: &mut Continuation<'_>, mut f: impl FnMut(Continuation<'_>)) {
625625
self.0.for_each(|x| {
626626
x.for_each_thunk(cont, &mut f);
627627
});
@@ -701,7 +701,7 @@ impl<Pat: Ord + Hash + RustInputPat> Rule<Pat> {
701701
// but can't be `self` itself without `#![feature(arbitrary_self_types)]`.
702702
fn generate_parse<'a>(
703703
&'a self,
704-
rc_self_and_rules: Option<(&'a Rc<Self>, &'a RuleMap<Pat>)>,
704+
rc_self_and_rules: Option<(&'a Rc<Self>, &'a RuleMap<'_, Pat>)>,
705705
) -> Thunk<impl ContFn + 'a> {
706706
if let Some((rc_self, _)) = rc_self_and_rules {
707707
assert!(std::ptr::eq(self, &**rc_self));
@@ -804,7 +804,7 @@ impl<Pat: Ord + Hash + RustInputPat> Rule<Pat> {
804804
}
805805

806806
impl<Pat: Ord + Hash + RustInputPat> Rule<Pat> {
807-
fn generate_traverse_shape(&self, refutable: bool, rules: &RuleMap<Pat>) -> Src {
807+
fn generate_traverse_shape(&self, refutable: bool, rules: &RuleMap<'_, Pat>) -> Src {
808808
match self {
809809
Rule::Empty
810810
| Rule::Eat(_)
@@ -884,7 +884,7 @@ where
884884
)
885885
}
886886

887-
fn declare_rule<Pat>(name: &str, rule: &RuleWithNamedFields<Pat>, rules: &RuleMap<Pat>) -> Src
887+
fn declare_rule<Pat>(name: &str, rule: &RuleWithNamedFields<Pat>, rules: &RuleMap<'_, Pat>) -> Src
888888
where
889889
Pat: Ord + Hash + RustInputPat,
890890
{
@@ -921,7 +921,7 @@ where
921921
});
922922
quote!(
923923
#[allow(non_camel_case_types)]
924-
pub enum #ident<'a, 'i: 'a, I: 'a + ::gll::runtime::Input> {
924+
pub enum #ident<'a, 'i, I: ::gll::runtime::Input> {
925925
#(#variants),*
926926
}
927927
)
@@ -938,7 +938,7 @@ where
938938
};
939939
quote!(
940940
#[allow(non_camel_case_types)]
941-
pub struct #ident<'a, 'i: 'a, I: 'a + ::gll::runtime::Input> {
941+
pub struct #ident<'a, 'i, I: ::gll::runtime::Input> {
942942
#(pub #fields_ident: #fields_ty),*
943943
#marker_field
944944
}
@@ -954,7 +954,7 @@ fn impl_rule_from_sppf<Pat>(
954954
name: &str,
955955
rule: &RuleWithNamedFields<Pat>,
956956
variants: Option<&[Variant<'_, Pat>]>,
957-
rules: &RuleMap<Pat>,
957+
rules: &RuleMap<'_, Pat>,
958958
) -> Src
959959
where
960960
Pat: Ord + Hash + RustInputPat,
@@ -1057,7 +1057,7 @@ fn impl_rule_one_and_all<Pat>(
10571057
name: &str,
10581058
rule: &RuleWithNamedFields<Pat>,
10591059
variants: Option<&[Variant<'_, Pat>]>,
1060-
rules: &RuleMap<Pat>,
1060+
rules: &RuleMap<'_, Pat>,
10611061
) -> Src
10621062
where
10631063
Pat: Ord + Hash + RustInputPat,
@@ -1230,7 +1230,7 @@ fn rule_debug_impl<Pat>(
12301230
)
12311231
};
12321232
quote!(impl<I: ::gll::runtime::Input> fmt::Debug for #ident<'_, '_, I> {
1233-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1233+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
12341234
#body
12351235
}
12361236
})
@@ -1255,23 +1255,23 @@ fn rule_handle_debug_impl(name: &str, has_fields: bool) -> Src {
12551255
};
12561256
quote!(
12571257
impl<'a, 'i, I: ::gll::runtime::Input> fmt::Debug for Handle<'a, 'i, I, #ident<'a, 'i, I>> {
1258-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1258+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
12591259
write!(f, "{:?}", self.source_info())?;
12601260
#body
12611261
Ok(())
12621262
}
12631263
}
12641264

12651265
impl<I: ::gll::runtime::Input> fmt::Debug for OwnedHandle<I, #ident<'_, '_, I>> {
1266-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1266+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
12671267
self.with(|handle| handle.fmt(f))
12681268
}
12691269
}
12701270
)
12711271
}
12721272

12731273
fn define_parse_fn<Pat>(
1274-
rules: &RuleMap<Pat>,
1274+
rules: &RuleMap<'_, Pat>,
12751275
code_labels: &mut OrderMap<Rc<CodeLabel>, usize>,
12761276
) -> Src
12771277
where
@@ -1343,7 +1343,7 @@ fn declare_parse_node_kind(all_parse_nodes: &[ParseNode]) -> Src {
13431343
)*
13441344
}
13451345
impl fmt::Display for _P {
1346-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1346+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
13471347
let s = match *self {
13481348
#(#nodes_kind => #nodes_desc),*
13491349
};
@@ -1380,7 +1380,7 @@ fn impl_debug_for_handle_any(all_parse_nodes: &[ParseNode]) -> Src {
13801380
})
13811381
});
13821382
quote!(impl<I: ::gll::runtime::Input> fmt::Debug for Handle<'_, '_, I, Any> {
1383-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1383+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
13841384
match self.node.kind {
13851385
#(#arms)*
13861386
_ => write!(f, "{:?}", Handle::<_, ()> {
@@ -1394,7 +1394,7 @@ fn impl_debug_for_handle_any(all_parse_nodes: &[ParseNode]) -> Src {
13941394
}
13951395

13961396
fn code_label_decl_and_impls<Pat>(
1397-
rules: &RuleMap<Pat>,
1397+
rules: &RuleMap<'_, Pat>,
13981398
code_labels: &OrderMap<Rc<CodeLabel>, usize>,
13991399
) -> Src {
14001400
let all_labels = rules

src/generate/src.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ enum Elem {
155155
}
156156

157157
impl fmt::Display for Elem {
158-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
158+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
159159
match self {
160160
Elem::Char(c, _) => c.fmt(f),
161161
Elem::Ident(i) => i.fmt(f),
@@ -227,7 +227,7 @@ struct Line {
227227
}
228228

229229
impl fmt::Display for Line {
230-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
230+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
231231
for _ in 0..self.indent {
232232
write!(f, " ")?;
233233
}
@@ -245,7 +245,7 @@ pub struct Fragment {
245245
}
246246

247247
impl fmt::Display for Fragment {
248-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
248+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
249249
for elem in &self.before {
250250
elem.fmt(f)?;
251251
}

src/generate/templates/header.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ impl<I: ::gll::runtime::Input, T: ?Sized> OwnedHandle<I, T> {
1717
}
1818
}
1919

20-
pub struct Handle<'a, 'i: 'a, I: 'a + ::gll::runtime::Input, T: ?Sized> {
20+
pub struct Handle<'a, 'i, I: ::gll::runtime::Input, T: ?Sized> {
2121
pub node: ParseNode<'i, _P>,
2222
pub forest: &'a ::gll::runtime::ParseForest<'i, _P, I>,
2323
_marker: PhantomData<T>,
@@ -65,7 +65,7 @@ impl<'a, 'i, I: ::gll::runtime::Input, T> From<Ambiguity<Handle<'a, 'i, I, [T]>>
6565
}
6666

6767
impl<I: ::gll::runtime::Input> fmt::Debug for Handle<'_, '_, I, ()> {
68-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
68+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
6969
write!(f, "{:?}", self.source_info())
7070
}
7171
}
@@ -74,7 +74,7 @@ impl<'a, 'i, I: ::gll::runtime::Input, T> fmt::Debug for Handle<'a, 'i, I, [T]>
7474
where
7575
Handle<'a, 'i, I, T>: fmt::Debug,
7676
{
77-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
77+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
7878
write!(f, "{:?} => ", self.source_info())?;
7979
match self.all_list_heads() {
8080
ListHead::Cons(cons) => {
@@ -87,7 +87,7 @@ where
8787
Spread(L),
8888
}
8989
impl<T: fmt::Debug, L: fmt::Debug> fmt::Debug for Elem<T, L> {
90-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
90+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
9191
match self {
9292
Elem::One(x) => fmt::Debug::fmt(x, f),
9393
Elem::Spread(xs) => {

src/grammar.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ pub enum ParseNodeShape<P> {
593593
}
594594

595595
impl<P: fmt::Display> fmt::Display for ParseNodeShape<P> {
596-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
596+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
597597
match self {
598598
ParseNodeShape::Opaque => write!(f, "Opaque"),
599599
ParseNodeShape::Alias(inner) => write!(f, "Alias({})", inner),

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#![deny(unsafe_code)]
2+
#![deny(rust_2018_idioms)]
23

34
extern crate indexing;
45
extern crate ordermap;

src/parse_grammar.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ impl Modifier<'_, '_, &str> {
8787

8888
impl Pattern<'_, '_, &str> {
8989
fn lower(self) -> SPat {
90-
fn unescape<T>(handle: Handle<&str, T>) -> String {
90+
fn unescape<T>(handle: Handle<'_, '_, &str, T>) -> String {
9191
let mut out = String::new();
9292
let s = handle.source();
9393
let mut chars = s[1..s.len() - 1].chars();

0 commit comments

Comments
 (0)