Skip to content

Commit f58f0df

Browse files
committed
Auto merge of rust-lang#93846 - ehuss:beta-backports, r=ehuss
[beta] Backports Backports of: * rust-lang#92611 — Add links to the reference and rust by example for asm! docs and lints * rust-lang#92983 — Update Linux runners to Ubuntu 20.04 * rust-lang#93081 — Update LLVM submodule * rust-lang#93394 — Don't allow {} to refer to implicit captures in format_args. * Cargo: * rust-lang/cargo#10377 — Remove strip = "off" (and undocumented strip = "n"/strip = "no")
2 parents 0426998 + 5cdec68 commit f58f0df

File tree

14 files changed

+168
-58
lines changed

14 files changed

+168
-58
lines changed

.github/workflows/ci.yml

+43-43
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@ jobs:
4141
matrix:
4242
include:
4343
- name: mingw-check
44-
os: ubuntu-latest-xl
44+
os: ubuntu-20.04-xl
4545
env: {}
4646
- name: x86_64-gnu-llvm-12
47-
os: ubuntu-latest-xl
47+
os: ubuntu-20.04-xl
4848
env: {}
4949
- name: x86_64-gnu-tools
5050
env:
5151
CI_ONLY_WHEN_SUBMODULES_CHANGED: 1
52-
os: ubuntu-latest-xl
52+
os: ubuntu-20.04-xl
5353
timeout-minutes: 600
5454
runs-on: "${{ matrix.os }}"
5555
steps:
@@ -166,128 +166,128 @@ jobs:
166166
- ARM64
167167
- linux
168168
- name: arm-android
169-
os: ubuntu-latest-xl
169+
os: ubuntu-20.04-xl
170170
env: {}
171171
- name: armhf-gnu
172-
os: ubuntu-latest-xl
172+
os: ubuntu-20.04-xl
173173
env: {}
174174
- name: dist-aarch64-linux
175-
os: ubuntu-latest-xl
175+
os: ubuntu-20.04-xl
176176
env: {}
177177
- name: dist-android
178-
os: ubuntu-latest-xl
178+
os: ubuntu-20.04-xl
179179
env: {}
180180
- name: dist-arm-linux
181-
os: ubuntu-latest-xl
181+
os: ubuntu-20.04-xl
182182
env: {}
183183
- name: dist-armhf-linux
184-
os: ubuntu-latest-xl
184+
os: ubuntu-20.04-xl
185185
env: {}
186186
- name: dist-armv7-linux
187-
os: ubuntu-latest-xl
187+
os: ubuntu-20.04-xl
188188
env: {}
189189
- name: dist-i586-gnu-i586-i686-musl
190-
os: ubuntu-latest-xl
190+
os: ubuntu-20.04-xl
191191
env: {}
192192
- name: dist-i686-linux
193-
os: ubuntu-latest-xl
193+
os: ubuntu-20.04-xl
194194
env: {}
195195
- name: dist-mips-linux
196-
os: ubuntu-latest-xl
196+
os: ubuntu-20.04-xl
197197
env: {}
198198
- name: dist-mips64-linux
199-
os: ubuntu-latest-xl
199+
os: ubuntu-20.04-xl
200200
env: {}
201201
- name: dist-mips64el-linux
202-
os: ubuntu-latest-xl
202+
os: ubuntu-20.04-xl
203203
env: {}
204204
- name: dist-mipsel-linux
205-
os: ubuntu-latest-xl
205+
os: ubuntu-20.04-xl
206206
env: {}
207207
- name: dist-powerpc-linux
208-
os: ubuntu-latest-xl
208+
os: ubuntu-20.04-xl
209209
env: {}
210210
- name: dist-powerpc64-linux
211-
os: ubuntu-latest-xl
211+
os: ubuntu-20.04-xl
212212
env: {}
213213
- name: dist-powerpc64le-linux
214-
os: ubuntu-latest-xl
214+
os: ubuntu-20.04-xl
215215
env: {}
216216
- name: dist-riscv64-linux
217-
os: ubuntu-latest-xl
217+
os: ubuntu-20.04-xl
218218
env: {}
219219
- name: dist-s390x-linux
220-
os: ubuntu-latest-xl
220+
os: ubuntu-20.04-xl
221221
env: {}
222222
- name: dist-various-1
223-
os: ubuntu-latest-xl
223+
os: ubuntu-20.04-xl
224224
env: {}
225225
- name: dist-various-2
226-
os: ubuntu-latest-xl
226+
os: ubuntu-20.04-xl
227227
env: {}
228228
- name: dist-x86_64-freebsd
229-
os: ubuntu-latest-xl
229+
os: ubuntu-20.04-xl
230230
env: {}
231231
- name: dist-x86_64-illumos
232-
os: ubuntu-latest-xl
232+
os: ubuntu-20.04-xl
233233
env: {}
234234
- name: dist-x86_64-linux
235-
os: ubuntu-latest-xl
235+
os: ubuntu-20.04-xl
236236
env: {}
237237
- name: dist-x86_64-linux-alt
238238
env:
239239
IMAGE: dist-x86_64-linux
240-
os: ubuntu-latest-xl
240+
os: ubuntu-20.04-xl
241241
- name: dist-x86_64-musl
242-
os: ubuntu-latest-xl
242+
os: ubuntu-20.04-xl
243243
env: {}
244244
- name: dist-x86_64-netbsd
245-
os: ubuntu-latest-xl
245+
os: ubuntu-20.04-xl
246246
env: {}
247247
- name: i686-gnu
248-
os: ubuntu-latest-xl
248+
os: ubuntu-20.04-xl
249249
env: {}
250250
- name: i686-gnu-nopt
251-
os: ubuntu-latest-xl
251+
os: ubuntu-20.04-xl
252252
env: {}
253253
- name: mingw-check
254-
os: ubuntu-latest-xl
254+
os: ubuntu-20.04-xl
255255
env: {}
256256
- name: test-various
257-
os: ubuntu-latest-xl
257+
os: ubuntu-20.04-xl
258258
env: {}
259259
- name: wasm32
260-
os: ubuntu-latest-xl
260+
os: ubuntu-20.04-xl
261261
env: {}
262262
- name: x86_64-gnu
263-
os: ubuntu-latest-xl
263+
os: ubuntu-20.04-xl
264264
env: {}
265265
- name: x86_64-gnu-stable
266266
env:
267267
IMAGE: x86_64-gnu
268268
RUST_CI_OVERRIDE_RELEASE_CHANNEL: stable
269269
CI_ONLY_WHEN_CHANNEL: nightly
270-
os: ubuntu-latest-xl
270+
os: ubuntu-20.04-xl
271271
- name: x86_64-gnu-aux
272-
os: ubuntu-latest-xl
272+
os: ubuntu-20.04-xl
273273
env: {}
274274
- name: x86_64-gnu-debug
275-
os: ubuntu-latest-xl
275+
os: ubuntu-20.04-xl
276276
env: {}
277277
- name: x86_64-gnu-distcheck
278-
os: ubuntu-latest-xl
278+
os: ubuntu-20.04-xl
279279
env: {}
280280
- name: x86_64-gnu-llvm-12
281281
env:
282282
RUST_BACKTRACE: 1
283-
os: ubuntu-latest-xl
283+
os: ubuntu-20.04-xl
284284
- name: x86_64-gnu-nopt
285-
os: ubuntu-latest-xl
285+
os: ubuntu-20.04-xl
286286
env: {}
287287
- name: x86_64-gnu-tools
288288
env:
289289
DEPLOY_TOOLSTATES_JSON: toolstates-linux.json
290-
os: ubuntu-latest-xl
290+
os: ubuntu-20.04-xl
291291
- name: dist-x86_64-apple
292292
env:
293293
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:
538538
matrix:
539539
include:
540540
- name: dist-x86_64-linux
541-
os: ubuntu-latest-xl
541+
os: ubuntu-20.04-xl
542542
env: {}
543543
timeout-minutes: 600
544544
runs-on: "${{ matrix.os }}"

compiler/rustc_builtin_macros/src/format.rs

+24-11
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ enum ArgumentType {
2323

2424
enum Position {
2525
Exact(usize),
26+
Capture(usize),
2627
Named(Symbol),
2728
}
2829

@@ -47,6 +48,8 @@ struct Context<'a, 'b> {
4748
/// * `arg_unique_types` (in simplified JSON): `[["o", "x"], ["o", "x"], ["o", "x"]]`
4849
/// * `names` (in JSON): `{"foo": 2}`
4950
args: Vec<P<ast::Expr>>,
51+
/// The number of arguments that were added by implicit capturing.
52+
num_captured_args: usize,
5053
/// Placeholder slot numbers indexed by argument.
5154
arg_types: Vec<Vec<usize>>,
5255
/// Unique format specs seen for each argument.
@@ -229,6 +232,11 @@ fn parse_args<'a>(
229232
}
230233

231234
impl<'a, 'b> Context<'a, 'b> {
235+
/// The number of arguments that were explicitly given.
236+
fn num_args(&self) -> usize {
237+
self.args.len() - self.num_captured_args
238+
}
239+
232240
fn resolve_name_inplace(&self, p: &mut parse::Piece<'_>) {
233241
// NOTE: the `unwrap_or` branch is needed in case of invalid format
234242
// arguments, e.g., `format_args!("{foo}")`.
@@ -343,7 +351,7 @@ impl<'a, 'b> Context<'a, 'b> {
343351
}
344352

345353
fn describe_num_args(&self) -> Cow<'_, str> {
346-
match self.args.len() {
354+
match self.num_args() {
347355
0 => "no arguments were given".into(),
348356
1 => "there is 1 argument".into(),
349357
x => format!("there are {} arguments", x).into(),
@@ -369,7 +377,7 @@ impl<'a, 'b> Context<'a, 'b> {
369377

370378
let count = self.pieces.len()
371379
+ self.arg_with_formatting.iter().filter(|fmt| fmt.precision_span.is_some()).count();
372-
if self.names.is_empty() && !numbered_position_args && count != self.args.len() {
380+
if self.names.is_empty() && !numbered_position_args && count != self.num_args() {
373381
e = self.ecx.struct_span_err(
374382
sp,
375383
&format!(
@@ -417,7 +425,7 @@ impl<'a, 'b> Context<'a, 'b> {
417425
if let Some(span) = fmt.precision_span {
418426
let span = self.fmtsp.from_inner(span);
419427
match fmt.precision {
420-
parse::CountIsParam(pos) if pos > self.args.len() => {
428+
parse::CountIsParam(pos) if pos > self.num_args() => {
421429
e.span_label(
422430
span,
423431
&format!(
@@ -460,7 +468,7 @@ impl<'a, 'b> Context<'a, 'b> {
460468
if let Some(span) = fmt.width_span {
461469
let span = self.fmtsp.from_inner(span);
462470
match fmt.width {
463-
parse::CountIsParam(pos) if pos > self.args.len() => {
471+
parse::CountIsParam(pos) if pos > self.num_args() => {
464472
e.span_label(
465473
span,
466474
&format!(
@@ -492,12 +500,15 @@ impl<'a, 'b> Context<'a, 'b> {
492500
/// Actually verifies and tracks a given format placeholder
493501
/// (a.k.a. argument).
494502
fn verify_arg_type(&mut self, arg: Position, ty: ArgumentType) {
503+
if let Exact(arg) = arg {
504+
if arg >= self.num_args() {
505+
self.invalid_refs.push((arg, self.curpiece));
506+
return;
507+
}
508+
}
509+
495510
match arg {
496-
Exact(arg) => {
497-
if self.args.len() <= arg {
498-
self.invalid_refs.push((arg, self.curpiece));
499-
return;
500-
}
511+
Exact(arg) | Capture(arg) => {
501512
match ty {
502513
Placeholder(_) => {
503514
// record every (position, type) combination only once
@@ -524,7 +535,7 @@ impl<'a, 'b> Context<'a, 'b> {
524535
match self.names.get(&name) {
525536
Some(&idx) => {
526537
// Treat as positional arg.
527-
self.verify_arg_type(Exact(idx), ty)
538+
self.verify_arg_type(Capture(idx), ty)
528539
}
529540
None => {
530541
// For the moment capturing variables from format strings expanded from macros is
@@ -539,9 +550,10 @@ impl<'a, 'b> Context<'a, 'b> {
539550
} else {
540551
self.fmtsp
541552
};
553+
self.num_captured_args += 1;
542554
self.args.push(self.ecx.expr_ident(span, Ident::new(name, span)));
543555
self.names.insert(name, idx);
544-
self.verify_arg_type(Exact(idx), ty)
556+
self.verify_arg_type(Capture(idx), ty)
545557
} else {
546558
let msg = format!("there is no argument named `{}`", name);
547559
let sp = if self.is_literal {
@@ -1010,6 +1022,7 @@ pub fn expand_preparsed_format_args(
10101022
let mut cx = Context {
10111023
ecx,
10121024
args,
1025+
num_captured_args: 0,
10131026
arg_types,
10141027
arg_unique_types,
10151028
names,

compiler/rustc_lint/src/builtin.rs

+3
Original file line numberDiff line numberDiff line change
@@ -3165,7 +3165,10 @@ declare_lint! {
31653165
/// of this, GNU assembler [local labels] *must* be used instead of labels
31663166
/// with a name. Using named labels might cause assembler or linker errors.
31673167
///
3168+
/// See the explanation in [Rust By Example] for more details.
3169+
///
31683170
/// [local labels]: https://sourceware.org/binutils/docs/as/Symbol-Names.html#Local-Labels
3171+
/// [Rust By Example]: https://doc.rust-lang.org/nightly/rust-by-example/unsafe/asm.html#labels
31693172
pub NAMED_ASM_LABELS,
31703173
Deny,
31713174
"named labels in inline assembly",

compiler/rustc_lint/src/context.rs

+1
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,7 @@ pub trait LintContext: Sized {
770770
}
771771
BuiltinLintDiagnostics::NamedAsmLabel(help) => {
772772
db.help(&help);
773+
db.note("see the asm section of Rust By Example <https://doc.rust-lang.org/nightly/rust-by-example/unsafe/asm.html#labels> for more information");
773774
}
774775
}
775776
// Rewrap `db`, and pass control to the user.

compiler/rustc_lint_defs/src/builtin.rs

+4
Original file line numberDiff line numberDiff line change
@@ -2444,6 +2444,10 @@ declare_lint! {
24442444
/// register size, to alert you of possibly using the incorrect width. To
24452445
/// fix this, add the suggested modifier to the template, or cast the
24462446
/// value to the correct size.
2447+
///
2448+
/// See [register template modifiers] in the reference for more details.
2449+
///
2450+
/// [register template modifiers]: https://doc.rust-lang.org/nightly/reference/inline-assembly.html#template-modifiers
24472451
pub ASM_SUB_REGISTER,
24482452
Warn,
24492453
"using only a subset of a register for inline asm inputs",

library/core/src/lib.rs

+12
Original file line numberDiff line numberDiff line change
@@ -375,13 +375,25 @@ pub mod arch {
375375
pub use crate::core_arch::arch::*;
376376

377377
/// Inline assembly.
378+
///
379+
/// Refer to [rust by example] for a usage guide and the [reference] for
380+
/// detailed information about the syntax and available options.
381+
///
382+
/// [rust by example]: https://doc.rust-lang.org/nightly/rust-by-example/unsafe/asm.html
383+
/// [reference]: https://doc.rust-lang.org/nightly/reference/inline-assembly.html
378384
#[stable(feature = "asm", since = "1.59.0")]
379385
#[rustc_builtin_macro]
380386
pub macro asm("assembly template", $(operands,)* $(options($(option),*))?) {
381387
/* compiler built-in */
382388
}
383389
384390
/// Module-level inline assembly.
391+
///
392+
/// Refer to [rust by example] for a usage guide and the [reference] for
393+
/// detailed information about the syntax and available options.
394+
///
395+
/// [rust by example]: https://doc.rust-lang.org/nightly/rust-by-example/unsafe/asm.html
396+
/// [reference]: https://doc.rust-lang.org/nightly/reference/inline-assembly.html
385397
#[stable(feature = "global_asm", since = "1.59.0")]
386398
#[rustc_builtin_macro]
387399
pub macro global_asm("assembly template", $(operands,)* $(options($(option),*))?) {

src/ci/github-actions/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ x--expand-yaml-anchors--remove:
7373
env: {}
7474

7575
- &job-linux-xl
76-
os: ubuntu-latest-xl
76+
os: ubuntu-20.04-xl
7777
<<: *base-job
7878

7979
- &job-macos-xl

0 commit comments

Comments
 (0)