Skip to content

Commit b96f38a

Browse files
JasperDeSutteralerque
authored andcommitted
refactor(fluent-bundle): Combine Scope lifetimes
1 parent 1ee2a7c commit b96f38a

File tree

5 files changed

+42
-42
lines changed

5 files changed

+42
-42
lines changed

fluent-bundle/src/resolver/expression.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ use crate::resource::FluentResource;
1212
use crate::types::FluentValue;
1313

1414
impl<'bundle> WriteOrResolve<'bundle> for ast::Expression<&'bundle str> {
15-
fn write_or_resolve<'ast, 'args, 'errors, R, M, T>(
16-
&'ast self,
17-
scope: &mut Scope<'bundle, 'ast, 'args, 'errors, R, M>,
15+
fn write_or_resolve<'other, R, M, T>(
16+
&'bundle self,
17+
scope: &mut Scope<'bundle, 'other, R, M>,
1818
context: &mut T,
1919
) -> T::Result
2020
where

fluent-bundle/src/resolver/inline_expression.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ use std::borrow::{Borrow, Cow};
1010
use std::fmt;
1111

1212
impl<'bundle> WriteOrResolve<'bundle> for ast::InlineExpression<&'bundle str> {
13-
fn write_or_resolve<'ast, 'args, 'errors, R, M, T>(
14-
&'ast self,
15-
scope: &mut Scope<'bundle, 'ast, 'args, 'errors, R, M>,
13+
fn write_or_resolve<'other, R, M, T>(
14+
&'bundle self,
15+
scope: &mut Scope<'bundle, 'other, R, M>,
1616
context: &mut T,
1717
) -> T::Result
1818
where

fluent-bundle/src/resolver/mod.rs

+18-18
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,20 @@ pub trait WriteOrResolveContext<'bundle> {
2727
type Result;
2828

2929
fn unescape(&mut self, s: &'bundle str) -> Self::Result;
30-
fn value<'ast, 'args, 'errors, R, M>(
30+
fn value<'other, R, M>(
3131
&mut self,
32-
scope: &Scope<'bundle, 'ast, 'args, 'errors, R, M>,
32+
scope: &Scope<'bundle, 'other, R, M>,
3333
value: Cow<FluentValue<'bundle>>,
3434
) -> Self::Result
3535
where
3636
R: Borrow<FluentResource>,
3737
M: MemoizerKind;
3838

3939
fn error<E: WriteOrResolve<'bundle>>(&mut self, exp: &E, is_ref: bool) -> Self::Result;
40-
fn resolve_pattern<'ast, 'args, 'errors, R, M>(
40+
fn resolve_pattern<'other, R, M>(
4141
&mut self,
42-
scope: &mut Scope<'bundle, 'ast, 'args, 'errors, R, M>,
43-
pattern: &'ast ast::Pattern<&'bundle str>,
42+
scope: &mut Scope<'bundle, 'other, R, M>,
43+
pattern: &'bundle ast::Pattern<&'bundle str>,
4444
) -> Self::Result
4545
where
4646
R: Borrow<FluentResource>,
@@ -58,9 +58,9 @@ where
5858
unescape_unicode(self, s)
5959
}
6060

61-
fn value<'ast, 'args, 'errors, R, M>(
61+
fn value<'other, R, M>(
6262
&mut self,
63-
scope: &Scope<'bundle, 'ast, 'args, 'errors, R, M>,
63+
scope: &Scope<'bundle, 'other, R, M>,
6464
value: Cow<FluentValue<'bundle>>,
6565
) -> Self::Result
6666
where
@@ -86,10 +86,10 @@ where
8686
Ok(())
8787
}
8888

89-
fn resolve_pattern<'ast, 'args, 'errors, R, M>(
89+
fn resolve_pattern<'other, R, M>(
9090
&mut self,
91-
scope: &mut Scope<'bundle, 'ast, 'args, 'errors, R, M>,
92-
pattern: &'ast ast::Pattern<&'bundle str>,
91+
scope: &mut Scope<'bundle, 'other, R, M>,
92+
pattern: &'bundle ast::Pattern<&'bundle str>,
9393
) -> Self::Result
9494
where
9595
R: Borrow<FluentResource>,
@@ -109,9 +109,9 @@ impl<'bundle> WriteOrResolveContext<'bundle> for ResolveContext {
109109
unescape_unicode_to_string(s).into()
110110
}
111111

112-
fn value<'ast, 'args, 'errors, R, M>(
112+
fn value<'other, R, M>(
113113
&mut self,
114-
_scope: &Scope<'bundle, 'ast, 'args, 'errors, R, M>,
114+
_scope: &Scope<'bundle, 'other, R, M>,
115115
value: Cow<FluentValue<'bundle>>,
116116
) -> Self::Result
117117
where
@@ -125,10 +125,10 @@ impl<'bundle> WriteOrResolveContext<'bundle> for ResolveContext {
125125
FluentValue::Error
126126
}
127127

128-
fn resolve_pattern<'ast, 'args, 'errors, R, M>(
128+
fn resolve_pattern<'other, R, M>(
129129
&mut self,
130-
scope: &mut Scope<'bundle, 'ast, 'args, 'errors, R, M>,
131-
pattern: &'ast ast::Pattern<&'bundle str>,
130+
scope: &mut Scope<'bundle, 'other, R, M>,
131+
pattern: &'bundle ast::Pattern<&'bundle str>,
132132
) -> Self::Result
133133
where
134134
R: Borrow<FluentResource>,
@@ -139,9 +139,9 @@ impl<'bundle> WriteOrResolveContext<'bundle> for ResolveContext {
139139
}
140140

141141
pub trait WriteOrResolve<'bundle> {
142-
fn write_or_resolve<'ast, 'args, 'errors, R, M, T>(
143-
&'ast self,
144-
scope: &mut Scope<'bundle, 'ast, 'args, 'errors, R, M>,
142+
fn write_or_resolve<'other, R, M, T>(
143+
&'bundle self,
144+
scope: &mut Scope<'bundle, 'other, R, M>,
145145
context: &mut T,
146146
) -> T::Result
147147
where

fluent-bundle/src/resolver/pattern.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ use crate::types::FluentValue;
1212

1313
const MAX_PLACEABLES: u8 = 100;
1414

15-
pub fn write_pattern<'bundle, 'ast, 'args, 'errors, W, R, M>(
16-
pattern: &'ast ast::Pattern<&'bundle str>,
15+
pub fn write_pattern<'bundle, 'other, W, R, M>(
16+
pattern: &'bundle ast::Pattern<&'bundle str>,
1717
w: &mut W,
18-
scope: &mut Scope<'bundle, 'ast, 'args, 'errors, R, M>,
18+
scope: &mut Scope<'bundle, 'other, R, M>,
1919
) -> fmt::Result
2020
where
2121
W: fmt::Write,
@@ -66,9 +66,9 @@ where
6666
Ok(())
6767
}
6868

69-
pub fn resolve_pattern<'bundle, 'ast, 'args, 'errors, R, M>(
70-
pattern: &'ast ast::Pattern<&'bundle str>,
71-
scope: &mut Scope<'bundle, 'ast, 'args, 'errors, R, M>,
69+
pub fn resolve_pattern<'bundle, 'other, R, M>(
70+
pattern: &'bundle ast::Pattern<&'bundle str>,
71+
scope: &mut Scope<'bundle, 'other, R, M>,
7272
) -> FluentValue<'bundle>
7373
where
7474
R: Borrow<FluentResource>,

fluent-bundle/src/resolver/scope.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,29 @@ use std::borrow::Borrow;
88
use super::{ResolveContext, ResolverError, WriteOrResolve, WriteOrResolveContext};
99

1010
/// State for a single `WriteOrResolve::write_or_resolve` call.
11-
pub struct Scope<'bundle, 'ast, 'args, 'errors, R, M> {
11+
pub struct Scope<'bundle, 'other, R, M> {
1212
/// The current `FluentBundle` instance.
1313
pub bundle: &'bundle FluentBundle<R, M>,
1414
/// The current arguments passed by the developer.
15-
pub(super) args: Option<&'args FluentArgs<'args>>,
15+
pub(super) args: Option<&'other FluentArgs<'other>>,
1616
/// Local args
1717
pub(super) local_args: Option<FluentArgs<'bundle>>,
1818
/// The running count of resolved placeables. Used to detect the Billion
1919
/// Laughs and Quadratic Blowup attacks.
2020
pub(super) placeables: u8,
2121
/// Tracks hashes to prevent infinite recursion.
22-
travelled: smallvec::SmallVec<[&'ast ast::Pattern<&'bundle str>; 2]>,
22+
travelled: smallvec::SmallVec<[&'bundle ast::Pattern<&'bundle str>; 2]>,
2323
/// Track errors accumulated during resolving.
24-
pub errors: Option<&'errors mut Vec<FluentError>>,
24+
pub errors: Option<&'other mut Vec<FluentError>>,
2525
/// Makes the resolver bail.
2626
pub dirty: bool,
2727
}
2828

29-
impl<'bundle, 'ast, 'args, 'errors, R, M> Scope<'bundle, 'ast, 'args, 'errors, R, M> {
29+
impl<'bundle, 'other, R, M> Scope<'bundle, 'other, R, M> {
3030
pub fn new(
3131
bundle: &'bundle FluentBundle<R, M>,
32-
args: Option<&'args FluentArgs>,
33-
errors: Option<&'errors mut Vec<FluentError>>,
32+
args: Option<&'other FluentArgs>,
33+
errors: Option<&'other mut Vec<FluentError>>,
3434
) -> Self {
3535
Scope {
3636
bundle,
@@ -57,8 +57,8 @@ impl<'bundle, 'ast, 'args, 'errors, R, M> Scope<'bundle, 'ast, 'args, 'errors, R
5757
pub fn maybe_track<T>(
5858
&mut self,
5959
context: &mut T,
60-
pattern: &'ast ast::Pattern<&'bundle str>,
61-
exp: &'ast ast::Expression<&'bundle str>,
60+
pattern: &'bundle ast::Pattern<&'bundle str>,
61+
exp: &'bundle ast::Expression<&'bundle str>,
6262
) -> T::Result
6363
where
6464
R: Borrow<FluentResource>,
@@ -79,8 +79,8 @@ impl<'bundle, 'ast, 'args, 'errors, R, M> Scope<'bundle, 'ast, 'args, 'errors, R
7979
pub fn track<T>(
8080
&mut self,
8181
context: &mut T,
82-
pattern: &'ast ast::Pattern<&'bundle str>,
83-
exp: &'ast ast::InlineExpression<&'bundle str>,
82+
pattern: &'bundle ast::Pattern<&'bundle str>,
83+
exp: &'bundle ast::InlineExpression<&'bundle str>,
8484
) -> T::Result
8585
where
8686
R: Borrow<FluentResource>,
@@ -100,7 +100,7 @@ impl<'bundle, 'ast, 'args, 'errors, R, M> Scope<'bundle, 'ast, 'args, 'errors, R
100100

101101
pub fn get_arguments(
102102
&mut self,
103-
arguments: Option<&'ast ast::CallArguments<&'bundle str>>,
103+
arguments: Option<&'bundle ast::CallArguments<&'bundle str>>,
104104
) -> (Vec<FluentValue<'bundle>>, FluentArgs<'bundle>)
105105
where
106106
R: Borrow<FluentResource>,

0 commit comments

Comments
 (0)