Skip to content

Commit

Permalink
Auto merge of rust-lang#93846 - ehuss:beta-backports, r=ehuss
Browse files Browse the repository at this point in the history
[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")
  • Loading branch information
bors committed Feb 11, 2022
2 parents 0426998 + 5cdec68 commit f58f0df
Show file tree
Hide file tree
Showing 14 changed files with 168 additions and 58 deletions.
86 changes: 43 additions & 43 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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 }}"
Expand Down
35 changes: 24 additions & 11 deletions compiler/rustc_builtin_macros/src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ enum ArgumentType {

enum Position {
Exact(usize),
Capture(usize),
Named(Symbol),
}

Expand All @@ -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<P<ast::Expr>>,
/// The number of arguments that were added by implicit capturing.
num_captured_args: usize,
/// Placeholder slot numbers indexed by argument.
arg_types: Vec<Vec<usize>>,
/// Unique format specs seen for each argument.
Expand Down Expand Up @@ -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}")`.
Expand Down Expand Up @@ -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(),
Expand All @@ -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!(
Expand Down Expand Up @@ -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!(
Expand Down Expand Up @@ -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!(
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_lint/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_lint/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,7 @@ pub trait LintContext: Sized {
}
BuiltinLintDiagnostics::NamedAsmLabel(help) => {
db.help(&help);
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");
}
}
// Rewrap `db`, and pass control to the user.
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_lint_defs/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
12 changes: 12 additions & 0 deletions library/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,13 +375,25 @@ 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),*))?) {
/* compiler built-in */
}
/// 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),*))?) {
Expand Down
2 changes: 1 addition & 1 deletion src/ci/github-actions/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit f58f0df

Please sign in to comment.