Skip to content

Commit a6abef0

Browse files
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 ce654a9 commit a6abef0

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

library/core/src/fmt/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ impl<'a> Formatter<'a> {
514514

515515
/// Creates a new formatter based on this one with given [`FormattingOptions`].
516516
#[unstable(feature = "formatting_options", issue = "118117")]
517-
pub fn with_options(&'a mut self, options: FormattingOptions) -> Self {
517+
pub fn with_options<'b>(&'b mut self, options: FormattingOptions) -> Formatter<'b> {
518518
Formatter { options, buf: self.buf }
519519
}
520520
}

0 commit comments

Comments
 (0)