Skip to content

Elide impl header lifetimes where possible #98

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 1 commit 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
16 changes: 7 additions & 9 deletions src/generate/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ enum Code {
Label(Rc<CodeLabel>),
}

impl<'a> Continuation<'a> {
impl Continuation<'_> {
fn next_code_label(&mut self) -> Rc<CodeLabel> {
let counter = self
.code_labels
Expand Down Expand Up @@ -860,12 +860,10 @@ where
let parse_node_kind = ParseNodeKind::NamedRule(name.to_string());
let rust_slice_ty = Pat::rust_slice_ty();
quote!(
impl<'_a, I> #ident<'_a, 'static, I>
impl<I> #ident<'_, '_, I>
where I: ::gll::runtime::Input<Slice = #rust_slice_ty>,
{
pub fn parse(input: I)
-> ::gll::runtime::ParseResult<OwnedHandle<I, #ident<'_a, 'static, I>>>
{
pub fn parse(input: I) -> ::gll::runtime::ParseResult<OwnedHandle<I, Self>> {
let handle = |forest_and_node| OwnedHandle {
forest_and_node,
_marker: PhantomData,
Expand All @@ -878,7 +876,7 @@ where
}
}

impl<'_a, I: ::gll::runtime::Input> OwnedHandle<I, #ident<'_a, 'static, I>> {
impl<I: ::gll::runtime::Input> OwnedHandle<I, #ident<'_, '_, I>> {
pub fn with<R>(&self, f: impl for<'a, 'i> FnOnce(Handle<'a, 'i, I, #ident<'a, 'i, I>>) -> R) -> R {
self.forest_and_node.unpack_ref(|_, forest_and_node| {
let (ref forest, node) = *forest_and_node;
Expand Down Expand Up @@ -1238,7 +1236,7 @@ fn rule_debug_impl<Pat>(
d.finish()
)
};
quote!(impl<'a, 'i, I: ::gll::runtime::Input> fmt::Debug for #ident<'a, 'i, I> {
quote!(impl<I: ::gll::runtime::Input> fmt::Debug for #ident<'_, '_, I> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
#body
}
Expand Down Expand Up @@ -1271,7 +1269,7 @@ fn rule_handle_debug_impl(name: &str, has_fields: bool) -> Src {
}
}

impl<'_a, I: ::gll::runtime::Input> fmt::Debug for OwnedHandle<I, #ident<'_a, 'static, I>> {
impl<I: ::gll::runtime::Input> fmt::Debug for OwnedHandle<I, #ident<'_, '_, I>> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.with(|handle| handle.fmt(f))
}
Expand Down Expand Up @@ -1388,7 +1386,7 @@ fn impl_debug_for_handle_any(all_parse_nodes: &[ParseNode]) -> Src {
}),)
})
});
quote!(impl<'a, 'i, I: ::gll::runtime::Input> fmt::Debug for Handle<'a, 'i, I, Any> {
quote!(impl<I: ::gll::runtime::Input> fmt::Debug for Handle<'_, '_, I, Any> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self.node.kind {
#(#arms)*
Expand Down
12 changes: 5 additions & 7 deletions src/generate/templates/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ pub struct Handle<'a, 'i: 'a, I: 'a + ::gll::runtime::Input, T: ?Sized> {
_marker: PhantomData<T>,
}

impl<'a, 'i, I: ::gll::runtime::Input, T: ?Sized> Copy for Handle<'a, 'i, I, T> {}
impl<I: ::gll::runtime::Input, T: ?Sized> Copy for Handle<'_, '_, I, T> {}

impl<'a, 'i, I: ::gll::runtime::Input, T: ?Sized> Clone for Handle<'a, 'i, I, T> {
impl<I: ::gll::runtime::Input, T: ?Sized> Clone for Handle<'_, '_, I, T> {
fn clone(&self) -> Self {
*self
}
}

impl<'a, 'i, I: ::gll::runtime::Input, T: ?Sized> Handle<'a, 'i, I, T> {
impl<'a, I: ::gll::runtime::Input, T: ?Sized> Handle<'a, '_, I, T> {
pub fn source(self) -> &'a I::Slice {
self.forest.input(self.node.range)
}
Expand Down Expand Up @@ -64,7 +64,7 @@ impl<'a, 'i, I: ::gll::runtime::Input, T> From<Ambiguity<Handle<'a, 'i, I, [T]>>
}
}

impl<'a, 'i, I: ::gll::runtime::Input> fmt::Debug for Handle<'a, 'i, I, ()> {
impl<I: ::gll::runtime::Input> fmt::Debug for Handle<'_, '_, I, ()> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{:?}", self.source_info())
}
Expand Down Expand Up @@ -151,9 +151,7 @@ pub enum ListHead<C> {
}

impl<'a, 'i, I: ::gll::runtime::Input, T> Handle<'a, 'i, I, [T]> {
fn one_list_head(
self,
) -> ListHead<Result<(Handle<'a, 'i, I, T>, Handle<'a, 'i, I, [T]>), Ambiguity<Self>>> {
fn one_list_head(self) -> ListHead<Result<(Handle<'a, 'i, I, T>, Self), Ambiguity<Self>>> {
match self.all_list_heads() {
ListHead::Cons(mut iter) => {
let first = iter.next().unwrap();
Expand Down
12 changes: 6 additions & 6 deletions src/high.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ type_lambda! {
// FIXME(#52812) replace with `&'a <T as ApplyL<'b>>::Out`
pub struct RefApplyL<'a, 'b, T: LambdaL>(&'a <T as ApplyL<'b>>::Out);

impl<'a, 'b, T: LambdaL> Deref for RefApplyL<'a, 'b, T> {
type Target = <T as ApplyL<'b>>::Out;
impl<'a, T: LambdaL> Deref for RefApplyL<'_, 'a, T> {
type Target = <T as ApplyL<'a>>::Out;
fn deref(&self) -> &Self::Target {
self.0
}
Expand All @@ -55,14 +55,14 @@ impl<'a, 'b, T: LambdaL> Deref for RefApplyL<'a, 'b, T> {
// FIXME(#52812) replace with `&'a mut <T as ApplyL<'b>>::Out`
pub struct RefMutApplyL<'a, 'b, T: LambdaL>(&'a mut <T as ApplyL<'b>>::Out);

impl<'a, 'b, T: LambdaL> Deref for RefMutApplyL<'a, 'b, T> {
type Target = <T as ApplyL<'b>>::Out;
impl<'a, T: LambdaL> Deref for RefMutApplyL<'_, 'a, T> {
type Target = <T as ApplyL<'a>>::Out;
fn deref(&self) -> &Self::Target {
self.0
}
}

impl<'a, 'b, T: LambdaL> DerefMut for RefMutApplyL<'a, 'b, T> {
impl<T: LambdaL> DerefMut for RefMutApplyL<'_, '_, T> {
fn deref_mut(&mut self) -> &mut Self::Target {
self.0
}
Expand All @@ -76,7 +76,7 @@ pub struct ErasableL<'a> {
_marker: ::std::marker::PhantomData<&'a mut &'a ()>,
}

impl<'a> ErasableL<'a> {
impl ErasableL<'_> {
/// Trivial proof that `'static` is erasable (it's always valid).
pub const STATIC: ErasableL<'static> = ErasableL {
_marker: ::std::marker::PhantomData,
Expand Down
12 changes: 6 additions & 6 deletions src/parse_grammar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,23 @@ impl<Pat: From<SPat>> FromStr for ::grammar::Grammar<Pat> {
}
}

impl<'a, 'i, 's> Or<'a, 'i, &'s str> {
impl Or<'_, '_, &str> {
fn lower<Pat: From<SPat>>(self) -> ::grammar::RuleWithNamedFields<Pat> {
let mut rules = self.rules.map(|rule| rule.unwrap().one().unwrap().lower());
let first = rules.next().unwrap();
rules.fold(first, |a, b| a | b)
}
}

impl<'a, 'i, 's> Concat<'a, 'i, &'s str> {
impl Concat<'_, '_, &str> {
fn lower<Pat: From<SPat>>(self) -> ::grammar::RuleWithNamedFields<Pat> {
self.rules
.map(|rule| rule.unwrap().one().unwrap().lower())
.fold(::grammar::empty(), |a, b| a + b)
}
}

impl<'a, 'i, 's> Rule<'a, 'i, &'s str> {
impl Rule<'_, '_, &str> {
fn lower<Pat: From<SPat>>(self) -> ::grammar::RuleWithNamedFields<Pat> {
let mut rule = self.rule.one().unwrap().lower();
if let Some(modifier) = self.modifier {
Expand All @@ -52,7 +52,7 @@ impl<'a, 'i, 's> Rule<'a, 'i, &'s str> {
}
}

impl<'a, 'i, 's> Primary<'a, 'i, &'s str> {
impl Primary<'_, '_, &str> {
fn lower<Pat: From<SPat>>(self) -> ::grammar::RuleWithNamedFields<Pat> {
match self {
Primary::Eat(pat) => ::grammar::eat(pat.one().unwrap().lower()),
Expand All @@ -67,7 +67,7 @@ impl<'a, 'i, 's> Primary<'a, 'i, &'s str> {
}
}

impl<'a, 'i, 's> Modifier<'a, 'i, &'s str> {
impl Modifier<'_, '_, &str> {
fn lower<Pat: From<SPat>>(
self,
rule: ::grammar::RuleWithNamedFields<Pat>,
Expand All @@ -85,7 +85,7 @@ impl<'a, 'i, 's> Modifier<'a, 'i, &'s str> {
}
}

impl<'a, 'i, 's> Pattern<'a, 'i, &'s str> {
impl Pattern<'_, '_, &str> {
fn lower(self) -> SPat {
fn unescape<T>(handle: Handle<&str, T>) -> String {
let mut out = String::new();
Expand Down
2 changes: 1 addition & 1 deletion src/proc_macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ impl Input for TokenStream {
}
}

impl<'a> InputMatch<&'a [FlatTokenPat<&'a str>]> for [FlatToken] {
impl InputMatch<&[FlatTokenPat<&str>]> for [FlatToken] {
fn match_left(&self, pat: &[FlatTokenPat<&str>]) -> Option<usize> {
if self
.iter()
Expand Down
28 changes: 14 additions & 14 deletions src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,25 @@ impl<'i> Deref for Range<'i> {
}
}

impl<'i> PartialOrd for Range<'i> {
impl PartialOrd for Range<'_> {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
(self.start(), self.end()).partial_cmp(&(other.start(), other.end()))
}
}

impl<'i> Ord for Range<'i> {
impl Ord for Range<'_> {
fn cmp(&self, other: &Self) -> Ordering {
(self.start(), self.end()).cmp(&(other.start(), other.end()))
}
}

impl<'i> Hash for Range<'i> {
impl Hash for Range<'_> {
fn hash<H: Hasher>(&self, state: &mut H) {
(self.start(), self.end()).hash(state);
}
}

impl<'i> Range<'i> {
impl Range<'_> {
pub fn subtract_suffix(self, other: Self) -> Self {
assert_eq!(self.end(), other.end());
Range(self.split_at(other.start() - self.start()).0)
Expand Down Expand Up @@ -96,7 +96,7 @@ pub trait Input: Sized {
) -> Self::SourceInfo;
}

impl<'a, T> Input for &'a [T] {
impl<T> Input for &[T] {
type Container = Self;
type Slice = [T];
type SourceInfo = ops::Range<usize>;
Expand Down Expand Up @@ -149,7 +149,7 @@ pub trait InputMatch<Pat> {
fn match_right(&self, pat: Pat) -> Option<usize>;
}

impl<'a, T: PartialEq> InputMatch<&'a [T]> for [T] {
impl<T: PartialEq> InputMatch<&[T]> for [T] {
fn match_left(&self, pat: &[T]) -> Option<usize> {
if self.starts_with(pat) {
Some(pat.len())
Expand Down Expand Up @@ -185,7 +185,7 @@ impl<T: PartialOrd> InputMatch<RangeInclusive<T>> for [T] {
}
}

impl<'a> InputMatch<&'a str> for str {
impl InputMatch<&str> for str {
fn match_left(&self, pat: &str) -> Option<usize> {
if self.starts_with(pat) {
Some(pat.len())
Expand Down Expand Up @@ -435,7 +435,7 @@ pub struct Call<'i, C> {
pub range: Range<'i>,
}

impl<'i, C: fmt::Display> fmt::Display for Call<'i, C> {
impl<C: fmt::Display> fmt::Display for Call<'_, C> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(
f,
Expand All @@ -447,13 +447,13 @@ impl<'i, C: fmt::Display> fmt::Display for Call<'i, C> {
}
}

impl<'i, C: PartialOrd> PartialOrd for Call<'i, C> {
impl<C: PartialOrd> PartialOrd for Call<'_, C> {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
(Reverse(self.range), &self.callee).partial_cmp(&(Reverse(other.range), &other.callee))
}
}

impl<'i, C: Ord> Ord for Call<'i, C> {
impl<C: Ord> Ord for Call<'_, C> {
fn cmp(&self, other: &Self) -> Ordering {
(Reverse(self.range), &self.callee).cmp(&(Reverse(other.range), &other.callee))
}
Expand All @@ -463,7 +463,7 @@ pub struct GraphStack<'i, C: CodeLabel> {
returns: HashMap<Call<'i, C>, BTreeSet<Continuation<'i, C>>>,
}

impl<'i, C: CodeLabel> GraphStack<'i, C> {
impl<C: CodeLabel> GraphStack<'_, C> {
// FIXME(eddyb) figure out what to do here, now that
// the GSS is no longer exposed in the public API.
#[allow(unused)]
Expand Down Expand Up @@ -680,7 +680,7 @@ pub struct ParseNode<'i, P: ParseNodeKind> {
pub range: Range<'i>,
}

impl<'i, P: ParseNodeKind> ParseNode<'i, P> {
impl<P: ParseNodeKind> ParseNode<'_, P> {
pub fn unpack_alias(self) -> Self {
match self.kind.shape() {
ParseNodeShape::Alias(inner) => ParseNode {
Expand Down Expand Up @@ -708,7 +708,7 @@ impl<'i, P: ParseNodeKind> ParseNode<'i, P> {
}
}

impl<'i, P: ParseNodeKind> fmt::Display for ParseNode<'i, P> {
impl<P: ParseNodeKind> fmt::Display for ParseNode<'_, P> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(
f,
Expand All @@ -720,7 +720,7 @@ impl<'i, P: ParseNodeKind> fmt::Display for ParseNode<'i, P> {
}
}

impl<'i, P: ParseNodeKind> fmt::Debug for ParseNode<'i, P> {
impl<P: ParseNodeKind> fmt::Debug for ParseNode<'_, P> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(
f,
Expand Down
2 changes: 1 addition & 1 deletion src/scannerless.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ impl<'a, C> From<&'a str> for Pat<&'a str, C> {
}
}

impl<'a, C> From<&'a str> for Pat<String, C> {
impl<C> From<&str> for Pat<String, C> {
fn from(s: &str) -> Self {
Pat::String(s.to_string())
}
Expand Down