diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 88817043833a9..34a8b45da72c5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -41,15 +41,15 @@ jobs: matrix: include: - name: mingw-check - os: ubuntu-latest-xl + os: ubuntu-20.04-xl env: {} - name: x86_64-gnu-llvm-12 - os: ubuntu-latest-xl + os: ubuntu-20.04-xl env: {} - name: x86_64-gnu-tools env: CI_ONLY_WHEN_SUBMODULES_CHANGED: 1 - os: ubuntu-latest-xl + os: ubuntu-20.04-xl timeout-minutes: 600 runs-on: "${{ matrix.os }}" steps: @@ -166,128 +166,128 @@ jobs: - ARM64 - linux - name: arm-android - os: ubuntu-latest-xl + os: ubuntu-20.04-xl env: {} - name: armhf-gnu - os: ubuntu-latest-xl + os: ubuntu-20.04-xl env: {} - name: dist-aarch64-linux - os: ubuntu-latest-xl + os: ubuntu-20.04-xl env: {} - name: dist-android - os: ubuntu-latest-xl + os: ubuntu-20.04-xl env: {} - name: dist-arm-linux - os: ubuntu-latest-xl + os: ubuntu-20.04-xl env: {} - name: dist-armhf-linux - os: ubuntu-latest-xl + os: ubuntu-20.04-xl env: {} - name: dist-armv7-linux - os: ubuntu-latest-xl + os: ubuntu-20.04-xl env: {} - name: dist-i586-gnu-i586-i686-musl - os: ubuntu-latest-xl + os: ubuntu-20.04-xl env: {} - name: dist-i686-linux - os: ubuntu-latest-xl + os: ubuntu-20.04-xl env: {} - name: dist-mips-linux - os: ubuntu-latest-xl + os: ubuntu-20.04-xl env: {} - name: dist-mips64-linux - os: ubuntu-latest-xl + os: ubuntu-20.04-xl env: {} - name: dist-mips64el-linux - os: ubuntu-latest-xl + os: ubuntu-20.04-xl env: {} - name: dist-mipsel-linux - os: ubuntu-latest-xl + os: ubuntu-20.04-xl env: {} - name: dist-powerpc-linux - os: ubuntu-latest-xl + os: ubuntu-20.04-xl env: {} - name: dist-powerpc64-linux - os: ubuntu-latest-xl + os: ubuntu-20.04-xl env: {} - name: dist-powerpc64le-linux - os: ubuntu-latest-xl + os: ubuntu-20.04-xl env: {} - name: dist-riscv64-linux - os: ubuntu-latest-xl + os: ubuntu-20.04-xl env: {} - name: dist-s390x-linux - os: ubuntu-latest-xl + os: ubuntu-20.04-xl env: {} - name: dist-various-1 - os: ubuntu-latest-xl + os: ubuntu-20.04-xl env: {} - name: dist-various-2 - os: ubuntu-latest-xl + os: ubuntu-20.04-xl env: {} - name: dist-x86_64-freebsd - os: ubuntu-latest-xl + os: ubuntu-20.04-xl env: {} - name: dist-x86_64-illumos - os: ubuntu-latest-xl + os: ubuntu-20.04-xl env: {} - name: dist-x86_64-linux - os: ubuntu-latest-xl + os: ubuntu-20.04-xl env: {} - name: dist-x86_64-linux-alt env: IMAGE: dist-x86_64-linux - os: ubuntu-latest-xl + os: ubuntu-20.04-xl - name: dist-x86_64-musl - os: ubuntu-latest-xl + os: ubuntu-20.04-xl env: {} - name: dist-x86_64-netbsd - os: ubuntu-latest-xl + os: ubuntu-20.04-xl env: {} - name: i686-gnu - os: ubuntu-latest-xl + os: ubuntu-20.04-xl env: {} - name: i686-gnu-nopt - os: ubuntu-latest-xl + os: ubuntu-20.04-xl env: {} - name: mingw-check - os: ubuntu-latest-xl + os: ubuntu-20.04-xl env: {} - name: test-various - os: ubuntu-latest-xl + os: ubuntu-20.04-xl env: {} - name: wasm32 - os: ubuntu-latest-xl + os: ubuntu-20.04-xl env: {} - name: x86_64-gnu - os: ubuntu-latest-xl + os: ubuntu-20.04-xl env: {} - name: x86_64-gnu-stable env: IMAGE: x86_64-gnu RUST_CI_OVERRIDE_RELEASE_CHANNEL: stable CI_ONLY_WHEN_CHANNEL: nightly - os: ubuntu-latest-xl + os: ubuntu-20.04-xl - name: x86_64-gnu-aux - os: ubuntu-latest-xl + os: ubuntu-20.04-xl env: {} - name: x86_64-gnu-debug - os: ubuntu-latest-xl + os: ubuntu-20.04-xl env: {} - name: x86_64-gnu-distcheck - os: ubuntu-latest-xl + os: ubuntu-20.04-xl env: {} - name: x86_64-gnu-llvm-12 env: RUST_BACKTRACE: 1 - os: ubuntu-latest-xl + os: ubuntu-20.04-xl - name: x86_64-gnu-nopt - os: ubuntu-latest-xl + os: ubuntu-20.04-xl env: {} - name: x86_64-gnu-tools env: DEPLOY_TOOLSTATES_JSON: toolstates-linux.json - os: ubuntu-latest-xl + os: ubuntu-20.04-xl - name: dist-x86_64-apple env: SCRIPT: "./x.py dist --exclude rust-docs --exclude extended && ./x.py dist --target=x86_64-apple-darwin rust-docs && ./x.py dist extended" @@ -538,7 +538,7 @@ jobs: matrix: include: - name: dist-x86_64-linux - os: ubuntu-latest-xl + os: ubuntu-20.04-xl env: {} timeout-minutes: 600 runs-on: "${{ matrix.os }}" diff --git a/compiler/rustc_builtin_macros/src/format.rs b/compiler/rustc_builtin_macros/src/format.rs index 407aaacb88999..154c51b2c7b9e 100644 --- a/compiler/rustc_builtin_macros/src/format.rs +++ b/compiler/rustc_builtin_macros/src/format.rs @@ -23,6 +23,7 @@ enum ArgumentType { enum Position { Exact(usize), + Capture(usize), Named(Symbol), } @@ -47,6 +48,8 @@ struct Context<'a, 'b> { /// * `arg_unique_types` (in simplified JSON): `[["o", "x"], ["o", "x"], ["o", "x"]]` /// * `names` (in JSON): `{"foo": 2}` args: Vec>, + /// The number of arguments that were added by implicit capturing. + num_captured_args: usize, /// Placeholder slot numbers indexed by argument. arg_types: Vec>, /// Unique format specs seen for each argument. @@ -229,6 +232,11 @@ fn parse_args<'a>( } impl<'a, 'b> Context<'a, 'b> { + /// The number of arguments that were explicitly given. + fn num_args(&self) -> usize { + self.args.len() - self.num_captured_args + } + fn resolve_name_inplace(&self, p: &mut parse::Piece<'_>) { // NOTE: the `unwrap_or` branch is needed in case of invalid format // arguments, e.g., `format_args!("{foo}")`. @@ -343,7 +351,7 @@ impl<'a, 'b> Context<'a, 'b> { } fn describe_num_args(&self) -> Cow<'_, str> { - match self.args.len() { + match self.num_args() { 0 => "no arguments were given".into(), 1 => "there is 1 argument".into(), x => format!("there are {} arguments", x).into(), @@ -369,7 +377,7 @@ impl<'a, 'b> Context<'a, 'b> { let count = self.pieces.len() + self.arg_with_formatting.iter().filter(|fmt| fmt.precision_span.is_some()).count(); - if self.names.is_empty() && !numbered_position_args && count != self.args.len() { + if self.names.is_empty() && !numbered_position_args && count != self.num_args() { e = self.ecx.struct_span_err( sp, &format!( @@ -417,7 +425,7 @@ impl<'a, 'b> Context<'a, 'b> { if let Some(span) = fmt.precision_span { let span = self.fmtsp.from_inner(span); match fmt.precision { - parse::CountIsParam(pos) if pos > self.args.len() => { + parse::CountIsParam(pos) if pos > self.num_args() => { e.span_label( span, &format!( @@ -460,7 +468,7 @@ impl<'a, 'b> Context<'a, 'b> { if let Some(span) = fmt.width_span { let span = self.fmtsp.from_inner(span); match fmt.width { - parse::CountIsParam(pos) if pos > self.args.len() => { + parse::CountIsParam(pos) if pos > self.num_args() => { e.span_label( span, &format!( @@ -492,12 +500,15 @@ impl<'a, 'b> Context<'a, 'b> { /// Actually verifies and tracks a given format placeholder /// (a.k.a. argument). fn verify_arg_type(&mut self, arg: Position, ty: ArgumentType) { + if let Exact(arg) = arg { + if arg >= self.num_args() { + self.invalid_refs.push((arg, self.curpiece)); + return; + } + } + match arg { - Exact(arg) => { - if self.args.len() <= arg { - self.invalid_refs.push((arg, self.curpiece)); - return; - } + Exact(arg) | Capture(arg) => { match ty { Placeholder(_) => { // record every (position, type) combination only once @@ -524,7 +535,7 @@ impl<'a, 'b> Context<'a, 'b> { match self.names.get(&name) { Some(&idx) => { // Treat as positional arg. - self.verify_arg_type(Exact(idx), ty) + self.verify_arg_type(Capture(idx), ty) } None => { // For the moment capturing variables from format strings expanded from macros is @@ -539,9 +550,10 @@ impl<'a, 'b> Context<'a, 'b> { } else { self.fmtsp }; + self.num_captured_args += 1; self.args.push(self.ecx.expr_ident(span, Ident::new(name, span))); self.names.insert(name, idx); - self.verify_arg_type(Exact(idx), ty) + self.verify_arg_type(Capture(idx), ty) } else { let msg = format!("there is no argument named `{}`", name); let sp = if self.is_literal { @@ -1010,6 +1022,7 @@ pub fn expand_preparsed_format_args( let mut cx = Context { ecx, args, + num_captured_args: 0, arg_types, arg_unique_types, names, diff --git a/compiler/rustc_lint/src/builtin.rs b/compiler/rustc_lint/src/builtin.rs index c0384875a47c9..1fd6379b6e524 100644 --- a/compiler/rustc_lint/src/builtin.rs +++ b/compiler/rustc_lint/src/builtin.rs @@ -3165,7 +3165,10 @@ declare_lint! { /// of this, GNU assembler [local labels] *must* be used instead of labels /// with a name. Using named labels might cause assembler or linker errors. /// + /// See the explanation in [Rust By Example] for more details. + /// /// [local labels]: https://sourceware.org/binutils/docs/as/Symbol-Names.html#Local-Labels + /// [Rust By Example]: https://doc.rust-lang.org/nightly/rust-by-example/unsafe/asm.html#labels pub NAMED_ASM_LABELS, Deny, "named labels in inline assembly", diff --git a/compiler/rustc_lint/src/context.rs b/compiler/rustc_lint/src/context.rs index 69c376c6169ba..d93866443a00e 100644 --- a/compiler/rustc_lint/src/context.rs +++ b/compiler/rustc_lint/src/context.rs @@ -770,6 +770,7 @@ pub trait LintContext: Sized { } BuiltinLintDiagnostics::NamedAsmLabel(help) => { db.help(&help); + db.note("see the asm section of Rust By Example for more information"); } } // Rewrap `db`, and pass control to the user. diff --git a/compiler/rustc_lint_defs/src/builtin.rs b/compiler/rustc_lint_defs/src/builtin.rs index 27a06943cbc25..6b89fd657b32e 100644 --- a/compiler/rustc_lint_defs/src/builtin.rs +++ b/compiler/rustc_lint_defs/src/builtin.rs @@ -2444,6 +2444,10 @@ declare_lint! { /// register size, to alert you of possibly using the incorrect width. To /// fix this, add the suggested modifier to the template, or cast the /// value to the correct size. + /// + /// See [register template modifiers] in the reference for more details. + /// + /// [register template modifiers]: https://doc.rust-lang.org/nightly/reference/inline-assembly.html#template-modifiers pub ASM_SUB_REGISTER, Warn, "using only a subset of a register for inline asm inputs", diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs index 4bd94e3ce3915..d61800dcbb9ad 100644 --- a/library/core/src/lib.rs +++ b/library/core/src/lib.rs @@ -375,6 +375,12 @@ pub mod arch { pub use crate::core_arch::arch::*; /// Inline assembly. + /// + /// Refer to [rust by example] for a usage guide and the [reference] for + /// detailed information about the syntax and available options. + /// + /// [rust by example]: https://doc.rust-lang.org/nightly/rust-by-example/unsafe/asm.html + /// [reference]: https://doc.rust-lang.org/nightly/reference/inline-assembly.html #[stable(feature = "asm", since = "1.59.0")] #[rustc_builtin_macro] pub macro asm("assembly template", $(operands,)* $(options($(option),*))?) { @@ -382,6 +388,12 @@ pub mod arch { } /// Module-level inline assembly. + /// + /// Refer to [rust by example] for a usage guide and the [reference] for + /// detailed information about the syntax and available options. + /// + /// [rust by example]: https://doc.rust-lang.org/nightly/rust-by-example/unsafe/asm.html + /// [reference]: https://doc.rust-lang.org/nightly/reference/inline-assembly.html #[stable(feature = "global_asm", since = "1.59.0")] #[rustc_builtin_macro] pub macro global_asm("assembly template", $(operands,)* $(options($(option),*))?) { diff --git a/src/ci/github-actions/ci.yml b/src/ci/github-actions/ci.yml index 4f9909e25c46f..1617a74ad2e0d 100644 --- a/src/ci/github-actions/ci.yml +++ b/src/ci/github-actions/ci.yml @@ -73,7 +73,7 @@ x--expand-yaml-anchors--remove: env: {} - &job-linux-xl - os: ubuntu-latest-xl + os: ubuntu-20.04-xl <<: *base-job - &job-macos-xl diff --git a/src/doc/rust-by-example b/src/doc/rust-by-example index 1ca6a7bd1d73e..18c0055b8aea4 160000 --- a/src/doc/rust-by-example +++ b/src/doc/rust-by-example @@ -1 +1 @@ -Subproject commit 1ca6a7bd1d73edc4a3e6c7d6a40f5d4b66c1e517 +Subproject commit 18c0055b8aea49391e8f758a4400097999c9cf1e diff --git a/src/llvm-project b/src/llvm-project index 6b3dbcc81a470..221a195b62f43 160000 --- a/src/llvm-project +++ b/src/llvm-project @@ -1 +1 @@ -Subproject commit 6b3dbcc81a470e5da84576d63fcfc19e3b1154cd +Subproject commit 221a195b62f4373a8893f4d022e4ce981b09a857 diff --git a/src/test/ui/asm/named-asm-labels.stderr b/src/test/ui/asm/named-asm-labels.stderr index b8ff42d86b564..001601497a272 100644 --- a/src/test/ui/asm/named-asm-labels.stderr +++ b/src/test/ui/asm/named-asm-labels.stderr @@ -6,6 +6,7 @@ LL | asm!("bar: nop"); | = note: `#[deny(named_asm_labels)]` on by default = help: only local labels of the form `:` should be used in inline asm + = note: see the asm section of Rust By Example for more information error: avoid using named labels in inline assembly --> $DIR/named-asm-labels.rs:27:15 @@ -14,6 +15,7 @@ LL | asm!("abcd:"); | ^^^^ | = help: only local labels of the form `:` should be used in inline asm + = note: see the asm section of Rust By Example for more information error: avoid using named labels in inline assembly --> $DIR/named-asm-labels.rs:30:15 @@ -22,6 +24,7 @@ LL | asm!("foo: bar1: nop"); | ^^^ ^^^^ | = help: only local labels of the form `:` should be used in inline asm + = note: see the asm section of Rust By Example for more information error: avoid using named labels in inline assembly --> $DIR/named-asm-labels.rs:34:15 @@ -30,6 +33,7 @@ LL | asm!("foo1: nop", "nop"); | ^^^^ | = help: only local labels of the form `:` should be used in inline asm + = note: see the asm section of Rust By Example for more information error: avoid using named labels in inline assembly --> $DIR/named-asm-labels.rs:35:15 @@ -38,6 +42,7 @@ LL | asm!("foo2: foo3: nop", "nop"); | ^^^^ ^^^^ | = help: only local labels of the form `:` should be used in inline asm + = note: see the asm section of Rust By Example for more information error: avoid using named labels in inline assembly --> $DIR/named-asm-labels.rs:37:22 @@ -46,6 +51,7 @@ LL | asm!("nop", "foo4: nop"); | ^^^^ | = help: only local labels of the form `:` should be used in inline asm + = note: see the asm section of Rust By Example for more information error: avoid using named labels in inline assembly --> $DIR/named-asm-labels.rs:38:15 @@ -54,6 +60,7 @@ LL | asm!("foo5: nop", "foo6: nop"); | ^^^^ | = help: only local labels of the form `:` should be used in inline asm + = note: see the asm section of Rust By Example for more information error: avoid using named labels in inline assembly --> $DIR/named-asm-labels.rs:38:28 @@ -62,6 +69,7 @@ LL | asm!("foo5: nop", "foo6: nop"); | ^^^^ | = help: only local labels of the form `:` should be used in inline asm + = note: see the asm section of Rust By Example for more information error: avoid using named labels in inline assembly --> $DIR/named-asm-labels.rs:43:15 @@ -70,6 +78,7 @@ LL | asm!("foo7: nop; foo8: nop"); | ^^^^ ^^^^ | = help: only local labels of the form `:` should be used in inline asm + = note: see the asm section of Rust By Example for more information error: avoid using named labels in inline assembly --> $DIR/named-asm-labels.rs:45:15 @@ -78,6 +87,7 @@ LL | asm!("foo9: nop; nop"); | ^^^^ | = help: only local labels of the form `:` should be used in inline asm + = note: see the asm section of Rust By Example for more information error: avoid using named labels in inline assembly --> $DIR/named-asm-labels.rs:46:20 @@ -86,6 +96,7 @@ LL | asm!("nop; foo10: nop"); | ^^^^^ | = help: only local labels of the form `:` should be used in inline asm + = note: see the asm section of Rust By Example for more information error: avoid using named labels in inline assembly --> $DIR/named-asm-labels.rs:49:15 @@ -94,6 +105,7 @@ LL | asm!("bar2: nop\n bar3: nop"); | ^^^^ ^^^^ | = help: only local labels of the form `:` should be used in inline asm + = note: see the asm section of Rust By Example for more information error: avoid using named labels in inline assembly --> $DIR/named-asm-labels.rs:51:15 @@ -102,6 +114,7 @@ LL | asm!("bar4: nop\n nop"); | ^^^^ | = help: only local labels of the form `:` should be used in inline asm + = note: see the asm section of Rust By Example for more information error: avoid using named labels in inline assembly --> $DIR/named-asm-labels.rs:52:21 @@ -110,6 +123,7 @@ LL | asm!("nop\n bar5: nop"); | ^^^^ | = help: only local labels of the form `:` should be used in inline asm + = note: see the asm section of Rust By Example for more information error: avoid using named labels in inline assembly --> $DIR/named-asm-labels.rs:53:21 @@ -118,6 +132,7 @@ LL | asm!("nop\n bar6: bar7: nop"); | ^^^^ ^^^^ | = help: only local labels of the form `:` should be used in inline asm + = note: see the asm section of Rust By Example for more information error: avoid using named labels in inline assembly --> $DIR/named-asm-labels.rs:59:13 @@ -128,6 +143,7 @@ LL | blah3: nop | ^^^^^ | = help: only local labels of the form `:` should be used in inline asm + = note: see the asm section of Rust By Example for more information error: avoid using named labels in inline assembly --> $DIR/named-asm-labels.rs:68:19 @@ -136,6 +152,7 @@ LL | nop ; blah4: nop | ^^^^^ | = help: only local labels of the form `:` should be used in inline asm + = note: see the asm section of Rust By Example for more information error: avoid using named labels in inline assembly --> $DIR/named-asm-labels.rs:82:15 @@ -144,6 +161,7 @@ LL | asm!("blah1: 2bar: nop"); | ^^^^^ | = help: only local labels of the form `:` should be used in inline asm + = note: see the asm section of Rust By Example for more information error: avoid using named labels in inline assembly --> $DIR/named-asm-labels.rs:85:15 @@ -152,6 +170,7 @@ LL | asm!("def: def: nop"); | ^^^ | = help: only local labels of the form `:` should be used in inline asm + = note: see the asm section of Rust By Example for more information error: avoid using named labels in inline assembly --> $DIR/named-asm-labels.rs:86:15 @@ -160,6 +179,7 @@ LL | asm!("def: nop\ndef: nop"); | ^^^ | = help: only local labels of the form `:` should be used in inline asm + = note: see the asm section of Rust By Example for more information error: avoid using named labels in inline assembly --> $DIR/named-asm-labels.rs:87:15 @@ -168,6 +188,7 @@ LL | asm!("def: nop; def: nop"); | ^^^ | = help: only local labels of the form `:` should be used in inline asm + = note: see the asm section of Rust By Example for more information error: avoid using named labels in inline assembly --> $DIR/named-asm-labels.rs:95:15 @@ -176,6 +197,7 @@ LL | asm!("fooo\u{003A} nop"); | ^^^^^^^^^^^^^^^^ | = help: only local labels of the form `:` should be used in inline asm + = note: see the asm section of Rust By Example for more information error: avoid using named labels in inline assembly --> $DIR/named-asm-labels.rs:96:15 @@ -184,6 +206,7 @@ LL | asm!("foooo\x3A nop"); | ^^^^^^^^^^^^^ | = help: only local labels of the form `:` should be used in inline asm + = note: see the asm section of Rust By Example for more information error: avoid using named labels in inline assembly --> $DIR/named-asm-labels.rs:99:15 @@ -192,6 +215,7 @@ LL | asm!("fooooo:\u{000A} nop"); | ^^^^^^ | = help: only local labels of the form `:` should be used in inline asm + = note: see the asm section of Rust By Example for more information error: avoid using named labels in inline assembly --> $DIR/named-asm-labels.rs:100:15 @@ -200,6 +224,7 @@ LL | asm!("foooooo:\x0A nop"); | ^^^^^^^ | = help: only local labels of the form `:` should be used in inline asm + = note: see the asm section of Rust By Example for more information error: avoid using named labels in inline assembly --> $DIR/named-asm-labels.rs:104:14 @@ -208,6 +233,7 @@ LL | asm!("\x41\x42\x43\x3A\x20\x6E\x6F\x70"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: only local labels of the form `:` should be used in inline asm + = note: see the asm section of Rust By Example for more information error: avoid using named labels in inline assembly --> $DIR/named-asm-labels.rs:112:13 @@ -216,6 +242,7 @@ LL | ab: nop // ab: does foo | ^^ | = help: only local labels of the form `:` should be used in inline asm + = note: see the asm section of Rust By Example for more information error: avoid using named labels in inline assembly --> $DIR/named-asm-labels.rs:124:14 @@ -224,6 +251,7 @@ LL | asm!(include_str!("named-asm-labels.s")); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: only local labels of the form `:` should be used in inline asm + = note: see the asm section of Rust By Example for more information warning: avoid using named labels in inline assembly --> $DIR/named-asm-labels.rs:134:19 @@ -237,6 +265,7 @@ note: the lint level is defined here LL | #[warn(named_asm_labels)] | ^^^^^^^^^^^^^^^^ = help: only local labels of the form `:` should be used in inline asm + = note: see the asm section of Rust By Example for more information error: avoid using named labels in inline assembly --> $DIR/named-asm-labels.rs:143:20 @@ -245,6 +274,7 @@ LL | unsafe { asm!(".Lfoo: mov rax, {}; ret;", "nop", const 1, options(noret | ^^^^^ | = help: only local labels of the form `:` should be used in inline asm + = note: see the asm section of Rust By Example for more information error: avoid using named labels in inline assembly --> $DIR/named-asm-labels.rs:149:20 @@ -253,6 +283,7 @@ LL | unsafe { asm!(".Lbar: mov rax, {}; ret;", "nop", const 1, options(noret | ^^^^^ | = help: only local labels of the form `:` should be used in inline asm + = note: see the asm section of Rust By Example for more information error: avoid using named labels in inline assembly --> $DIR/named-asm-labels.rs:157:20 @@ -261,6 +292,7 @@ LL | unsafe { asm!(".Laaa: nop; ret;", options(noreturn)) } | ^^^^^ | = help: only local labels of the form `:` should be used in inline asm + = note: see the asm section of Rust By Example for more information error: avoid using named labels in inline assembly --> $DIR/named-asm-labels.rs:167:24 @@ -269,6 +301,7 @@ LL | unsafe { asm!(".Lbbb: nop; ret;", options(noreturn)) } | ^^^^^ | = help: only local labels of the form `:` should be used in inline asm + = note: see the asm section of Rust By Example for more information error: avoid using named labels in inline assembly --> $DIR/named-asm-labels.rs:176:15 @@ -277,6 +310,7 @@ LL | asm!("closure1: nop"); | ^^^^^^^^ | = help: only local labels of the form `:` should be used in inline asm + = note: see the asm section of Rust By Example for more information error: avoid using named labels in inline assembly --> $DIR/named-asm-labels.rs:180:15 @@ -285,6 +319,7 @@ LL | asm!("closure2: nop"); | ^^^^^^^^ | = help: only local labels of the form `:` should be used in inline asm + = note: see the asm section of Rust By Example for more information error: avoid using named labels in inline assembly --> $DIR/named-asm-labels.rs:190:19 @@ -293,6 +328,7 @@ LL | asm!("closure3: nop"); | ^^^^^^^^ | = help: only local labels of the form `:` should be used in inline asm + = note: see the asm section of Rust By Example for more information error: aborting due to 35 previous errors; 1 warning emitted diff --git a/src/test/ui/fmt/format-args-capture-issue-93378.rs b/src/test/ui/fmt/format-args-capture-issue-93378.rs new file mode 100644 index 0000000000000..6744444426472 --- /dev/null +++ b/src/test/ui/fmt/format-args-capture-issue-93378.rs @@ -0,0 +1,11 @@ +fn main() { + let a = "a"; + let b = "b"; + + println!("{a} {b} {} {} {c} {}", c = "c"); + //~^ ERROR: invalid reference to positional arguments 1 and 2 (there is 1 argument) + + let n = 1; + println!("{a:.n$} {b:.*}"); + //~^ ERROR: invalid reference to positional argument 0 (no arguments were given) +} diff --git a/src/test/ui/fmt/format-args-capture-issue-93378.stderr b/src/test/ui/fmt/format-args-capture-issue-93378.stderr new file mode 100644 index 0000000000000..588541044fe13 --- /dev/null +++ b/src/test/ui/fmt/format-args-capture-issue-93378.stderr @@ -0,0 +1,22 @@ +error: invalid reference to positional arguments 1 and 2 (there is 1 argument) + --> $DIR/format-args-capture-issue-93378.rs:5:26 + | +LL | println!("{a} {b} {} {} {c} {}", c = "c"); + | ^^ ^^ + | + = note: positional arguments are zero-based + +error: invalid reference to positional argument 0 (no arguments were given) + --> $DIR/format-args-capture-issue-93378.rs:9:23 + | +LL | println!("{a:.n$} {b:.*}"); + | ------- ^^^--^ + | | | + | | this precision flag adds an extra required argument at position 0, which is why there are 3 arguments expected + | this parameter corresponds to the precision flag + | + = note: positional arguments are zero-based + = note: for information about formatting flags, visit https://doc.rust-lang.org/std/fmt/index.html + +error: aborting due to 2 previous errors + diff --git a/src/test/ui/fmt/format-args-capture.rs b/src/test/ui/fmt/format-args-capture.rs index e830a5bc9c5c8..d31d2a6c33657 100644 --- a/src/test/ui/fmt/format-args-capture.rs +++ b/src/test/ui/fmt/format-args-capture.rs @@ -5,6 +5,7 @@ fn main() { named_argument_takes_precedence_to_captured(); formatting_parameters_can_be_captured(); capture_raw_strings_and_idents(); + repeated_capture(); #[cfg(panic = "unwind")] { @@ -80,3 +81,10 @@ fn formatting_parameters_can_be_captured() { let s = format!("{x:-^width$.precision$}"); assert_eq!(&s, "--7.000--"); } + +fn repeated_capture() { + let a = 1; + let b = 2; + let s = format!("{a} {b} {a}"); + assert_eq!(&s, "1 2 1"); +} diff --git a/src/tools/cargo b/src/tools/cargo index 5ad495c6839f3..49d8809dc2d3e 160000 --- a/src/tools/cargo +++ b/src/tools/cargo @@ -1 +1 @@ -Subproject commit 5ad495c6839f34ead56177829575da443d3e01d0 +Subproject commit 49d8809dc2d3e6e0d5ec634fcf26d8e2aab67130