Skip to content

Commit df3f71b

Browse files
markpritchardzbraniecki
authored andcommitted
Specific lifetime on initialiser (#68)
* Specific lifetime on initialiser When not explicitly defined, Rust will assign the same lifetime to all input parameters and return values. The FluentBundle::new constructor does not define an explicit lifetime for the 'locale' input parameter, so it is assigned the same lifetime as the bundle itself. This causes the borrow checker to reject code that initialises bundles populated from dynamically loaded resources and stored in separate containers. This adds an explicit lifetime to the locales parameter to decouple it from the return value and a test case that fails to compile without the change. * Remove disabled code
1 parent 5645c35 commit df3f71b

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

fluent/src/bundle.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ pub struct FluentBundle<'bundle> {
5656
}
5757

5858
impl<'bundle> FluentBundle<'bundle> {
59-
pub fn new<S: ToString>(locales: &[S]) -> FluentBundle {
59+
pub fn new<'a, S: ToString>(locales: &'a [S]) -> FluentBundle<'bundle> {
6060
let locales = locales
6161
.into_iter()
6262
.map(|s| s.to_string())

fluent/tests/bundle.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,13 @@ fn bundle_new_from_strings() {
3939
let _ = FluentBundle::new(&vec_from_iter);
4040
let _ = FluentBundle::new(&vec_from_iter[..]);
4141
}
42+
43+
fn create_bundle<'a, 'b>(locales: &'b Vec<&'b str>) -> FluentBundle<'a> {
44+
FluentBundle::new(locales)
45+
}
46+
47+
#[test]
48+
fn bundle_locale_diff_scope() {
49+
let locales = vec!("x-testing");
50+
create_bundle(&locales);
51+
}

0 commit comments

Comments
 (0)