about summary refs log tree commit diff
diff options
context:
space:
mode:
authorElias Holzmann <9659253+EliasHolzmann@users.noreply.github.com>2023-11-27 03:31:29 +0100
committerElias Holzmann <9659253+EliasHolzmann@users.noreply.github.com>2024-12-05 21:48:35 +0100
commitb0d3958e00b3b761d728df713665fed64e911ae3 (patch)
tree9a687299998a208e82093840840fd54fce80205b
parentad8f264e46a3420bc90a94b8047d0a6efde497e8 (diff)
downloadrust-b0d3958e00b3b761d728df713665fed64e911ae3.tar.gz
rust-b0d3958e00b3b761d728df713665fed64e911ae3.zip
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.
-rw-r--r--library/core/src/fmt/mod.rs2
1 files changed, 1 insertions, 1 deletions
diff --git a/library/core/src/fmt/mod.rs b/library/core/src/fmt/mod.rs
index 8e08b7fe983..a5c0e1ce4e3 100644
--- a/library/core/src/fmt/mod.rs
+++ b/library/core/src/fmt/mod.rs
@@ -530,7 +530,7 @@ impl<'a> Formatter<'a> {
 
     /// Creates a new formatter based on this one with given [`FormattingOptions`].
     #[unstable(feature = "formatting_options", issue = "118117")]
-    pub fn with_options(&'a mut self, options: FormattingOptions) -> Self {
+    pub fn with_options<'b>(&'b mut self, options: FormattingOptions) -> Formatter<'b> {
         Formatter { options, buf: self.buf }
     }
 }