Skip to content

Commit c896321

Browse files
committed
Limit lifetime of format_args!() with inlined args.
1 parent cc0b02d commit c896321

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

core/src/fmt/rt.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,21 @@ impl<'a> Argument<'a> {
152152
None
153153
}
154154
}
155+
156+
/// Used by `format_args` when all arguments are gone after inlining,
157+
/// when using `&[]` would incorrectly allow for a bigger lifetime.
158+
///
159+
/// This fails without format argument inlining, and that shouldn't be different
160+
/// when the argument is inlined:
161+
///
162+
/// ```compile_fail,E0716
163+
/// let f = format_args!("{}", "a");
164+
/// println!("{f}");
165+
/// ```
166+
#[inline(always)]
167+
pub fn none() -> [Self; 0] {
168+
[]
169+
}
155170
}
156171

157172
/// This struct represents the unsafety of constructing an `Arguments`.

0 commit comments

Comments
 (0)