Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf54c557

Browse files
committed
Auto merge ofrust-lang#125518 - saethlin:check-arguments-new-in-const, r=joboet
Move the checks for Arguments constructors to inline constThanks `@Skgland` for pointing out this opportunity:rust-lang#117804 (comment)
2 parentsbf3ca98 +29a1b3b commitf54c557

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

‎core/src/fmt/mod.rs‎

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -338,23 +338,19 @@ pub struct Arguments<'a> {
338338
impl<'a>Arguments<'a>{
339339
#[inline]
340340
#[rustc_const_unstable(feature ="const_fmt_arguments_new", issue ="none")]
341-
pubconstfnnew_const(pieces:&'a[&'staticstr]) ->Self{
342-
if pieces.len() >1{
343-
// Since panic!() expands to panic_fmt(format_args!()), using panic! here is both a
344-
// bit silly and also significantly increases the amount of MIR generated by panics.
345-
crate::panicking::panic_nounwind("invalid args");
346-
}
341+
pubconstfnnew_const<constN:usize>(pieces:&'a[&'staticstr;N]) ->Self{
342+
const{assert!(N <=1)};
347343
Arguments{ pieces,fmt:None,args:&[]}
348344
}
349345

350346
/// When using the format_args!() macro, this function is used to generate the
351347
/// Arguments structure.
352348
#[inline]
353-
pubfnnew_v1(pieces:&'a[&'staticstr],args:&'a[rt::Argument<'a>]) ->Arguments<'a>{
354-
ifpieces.len() < args.len() || pieces.len() > args.len() +1{
355-
// See Arguments::new_const for why we don't use panic!.
356-
crate::panicking::panic_nounwind("invalid args");
357-
}
349+
pubfnnew_v1<constP:usize,constA:usize>(
350+
pieces:&'a[&'staticstr;P],
351+
args:&'a[rt::Argument<'a>;A],
352+
) ->Arguments<'a>{
353+
const{assert!(P >=A &&P <=A +1,"invalid args")}
358354
Arguments{ pieces,fmt:None, args}
359355
}
360356

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp