Skip to content

Commit 0baf8fe

Browse files
EliasHolzmanngitbot
authored and
gitbot
committed
Formatter::with_options: Use different lifetimes
Formatter::with_options takes self as a mutable reference (`&'a mut Formatter<'b>`). `'a` and `'b` need to be different lifetimes. Just taking `&'a mut Formatter<'a>` and trusting in Rust being able to implicitely convert from `&'a mut Formatter<'b>` if necessary (after all, `'a` must be smaller than `'b` anyway) fails because `'b` is behind a *mutable* reference. For background on on this behavior, see https://doc.rust-lang.org/nomicon/subtyping.html#variance.
1 parent 0a2bec4 commit 0baf8fe

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

core/src/fmt/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ impl<'a> Formatter<'a> {
530530

531531
/// Creates a new formatter based on this one with given [`FormattingOptions`].
532532
#[unstable(feature = "formatting_options", issue = "118117")]
533-
pub fn with_options(&'a mut self, options: FormattingOptions) -> Self {
533+
pub fn with_options<'b>(&'b mut self, options: FormattingOptions) -> Formatter<'b> {
534534
Formatter { options, buf: self.buf }
535535
}
536536
}

0 commit comments

Comments
 (0)