Skip to content

Commit

Permalink
Auto merge of rust-lang#3136 - rust-lang:rustup-2023-10-23, r=RalfJung
Browse files Browse the repository at this point in the history
Automatic Rustup
  • Loading branch information
bors committed Oct 23, 2023
2 parents 74092c5 + dd683dd commit d32b158
Show file tree
Hide file tree
Showing 33 changed files with 668 additions and 235 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,10 @@ jobs:
- name: x86_64-gnu-distcheck
os: ubuntu-20.04-8core-32gb
env: {}
- name: x86_64-gnu-llvm-17
env:
RUST_BACKTRACE: 1
os: ubuntu-20.04-8core-32gb
- name: x86_64-gnu-llvm-16
env:
RUST_BACKTRACE: 1
Expand Down
12 changes: 6 additions & 6 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1663,9 +1663,9 @@ checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888"

[[package]]
name = "hashbrown"
version = "0.14.0"
version = "0.14.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2c6201b9ff9fd90a5a3bac2e56a830d0caa509576f0e503818ee82c181b3437a"
checksum = "f93e7192158dbcda357bdec5fb5788eebf8bbac027f3f33e719d29135ae84156"
dependencies = [
"ahash",
"allocator-api2",
Expand Down Expand Up @@ -1982,7 +1982,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d5477fe2230a79769d8dc68e0eabf5437907c0457a5614a9e8dddb67f65eb65d"
dependencies = [
"equivalent",
"hashbrown 0.14.0",
"hashbrown 0.14.2",
"rustc-rayon",
"serde",
]
Expand Down Expand Up @@ -2621,7 +2621,7 @@ dependencies = [
"compiler_builtins",
"crc32fast",
"flate2",
"hashbrown 0.14.0",
"hashbrown 0.14.2",
"indexmap 2.0.0",
"memchr",
"rustc-std-workspace-alloc",
Expand Down Expand Up @@ -5095,7 +5095,7 @@ dependencies = [
"core",
"dlmalloc",
"fortanix-sgx-abi",
"hashbrown 0.14.0",
"hashbrown 0.14.2",
"hermit-abi 0.3.2",
"libc",
"miniz_oxide",
Expand Down Expand Up @@ -5415,7 +5415,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4db52ee8fec06e119b692ef3dd2c4cf621a99204c1b8c47407870ed050305b9b"
dependencies = [
"gimli",
"hashbrown 0.14.0",
"hashbrown 0.14.2",
"object",
"tracing",
]
Expand Down
14 changes: 14 additions & 0 deletions compiler/rustc_builtin_macros/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,20 @@ builtin_macros_format_positional_after_named = positional arguments cannot follo
.label = positional arguments must be before named arguments
.named_args = named argument
builtin_macros_format_redundant_args = redundant {$n ->
[one] argument
*[more] arguments
}
.help = {$n ->
[one] the formatting string already captures the binding directly, it doesn't need to be included in the argument list
*[more] the formatting strings already captures the bindings directly, they don't need to be included in the argument list
}
.note = {$n ->
[one] the formatting specifier is referencing the binding already
*[more] the formatting specifiers are referencing the bindings already
}
.suggestion = this can be removed
builtin_macros_format_remove_raw_ident = remove the `r#`
builtin_macros_format_requires_string = requires at least a format string argument
Expand Down
21 changes: 21 additions & 0 deletions compiler/rustc_builtin_macros/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,27 @@ pub(crate) struct FormatPositionalMismatch {
pub(crate) highlight: SingleLabelManySpans,
}

#[derive(Diagnostic)]
#[diag(builtin_macros_format_redundant_args)]
pub(crate) struct FormatRedundantArgs {
#[primary_span]
pub(crate) span: MultiSpan,
pub(crate) n: usize,

#[note]
pub(crate) note: MultiSpan,

#[subdiagnostic]
pub(crate) sugg: Option<FormatRedundantArgsSugg>,
}

#[derive(Subdiagnostic)]
#[multipart_suggestion(builtin_macros_suggestion, applicability = "machine-applicable")]
pub(crate) struct FormatRedundantArgsSugg {
#[suggestion_part(code = "")]
pub(crate) spans: Vec<Span>,
}

#[derive(Diagnostic)]
#[diag(builtin_macros_test_case_non_item)]
pub(crate) struct TestCaseNonItem {
Expand Down
114 changes: 110 additions & 4 deletions compiler/rustc_builtin_macros/src/format.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use parse::Position::ArgumentNamed;
use rustc_ast::ptr::P;
use rustc_ast::tokenstream::TokenStream;
use rustc_ast::{token, StmtKind};
Expand All @@ -7,7 +8,9 @@ use rustc_ast::{
FormatDebugHex, FormatOptions, FormatPlaceholder, FormatSign, FormatTrait,
};
use rustc_data_structures::fx::FxHashSet;
use rustc_errors::{Applicability, MultiSpan, PResult, SingleLabelManySpans};
use rustc_errors::{
Applicability, DiagnosticBuilder, ErrorGuaranteed, MultiSpan, PResult, SingleLabelManySpans,
};
use rustc_expand::base::{self, *};
use rustc_parse_format as parse;
use rustc_span::symbol::{Ident, Symbol};
Expand Down Expand Up @@ -364,8 +367,8 @@ fn make_format_args(
let mut unfinished_literal = String::new();
let mut placeholder_index = 0;

for piece in pieces {
match piece {
for piece in &pieces {
match *piece {
parse::Piece::String(s) => {
unfinished_literal.push_str(s);
}
Expand Down Expand Up @@ -513,7 +516,17 @@ fn make_format_args(
// If there's a lot of unused arguments,
// let's check if this format arguments looks like another syntax (printf / shell).
let detect_foreign_fmt = unused.len() > args.explicit_args().len() / 2;
report_missing_placeholders(ecx, unused, detect_foreign_fmt, str_style, fmt_str, fmt_span);
report_missing_placeholders(
ecx,
unused,
&used,
&args,
&pieces,
detect_foreign_fmt,
str_style,
fmt_str,
fmt_span,
);
}

// Only check for unused named argument names if there are no other errors to avoid causing
Expand Down Expand Up @@ -580,6 +593,9 @@ fn invalid_placeholder_type_error(
fn report_missing_placeholders(
ecx: &mut ExtCtxt<'_>,
unused: Vec<(Span, bool)>,
used: &[bool],
args: &FormatArguments,
pieces: &[parse::Piece<'_>],
detect_foreign_fmt: bool,
str_style: Option<usize>,
fmt_str: &str,
Expand All @@ -598,6 +614,26 @@ fn report_missing_placeholders(
})
};

let placeholders = pieces
.iter()
.filter_map(|piece| {
if let parse::Piece::NextArgument(argument) = piece && let ArgumentNamed(binding) = argument.position {
let span = fmt_span.from_inner(InnerSpan::new(argument.position_span.start, argument.position_span.end));
Some((span, binding))
} else { None }
})
.collect::<Vec<_>>();

if !placeholders.is_empty() {
if let Some(mut new_diag) =
report_redundant_format_arguments(ecx, &args, used, placeholders)
{
diag.cancel();
new_diag.emit();
return;
}
}

// Used to ensure we only report translations for *one* kind of foreign format.
let mut found_foreign = false;

Expand Down Expand Up @@ -685,6 +721,76 @@ fn report_missing_placeholders(
diag.emit();
}

/// This function detects and reports unused format!() arguments that are
/// redundant due to implicit captures (e.g. `format!("{x}", x)`).
fn report_redundant_format_arguments<'a>(
ecx: &mut ExtCtxt<'a>,
args: &FormatArguments,
used: &[bool],
placeholders: Vec<(Span, &str)>,
) -> Option<DiagnosticBuilder<'a, ErrorGuaranteed>> {
let mut fmt_arg_indices = vec![];
let mut args_spans = vec![];
let mut fmt_spans = vec![];

for (i, unnamed_arg) in args.unnamed_args().iter().enumerate().rev() {
let Some(ty) = unnamed_arg.expr.to_ty() else { continue };
let Some(argument_binding) = ty.kind.is_simple_path() else { continue };
let argument_binding = argument_binding.as_str();

if used[i] {
continue;
}

let matching_placeholders = placeholders
.iter()
.filter(|(_, inline_binding)| argument_binding == *inline_binding)
.map(|(span, _)| span)
.collect::<Vec<_>>();

if !matching_placeholders.is_empty() {
fmt_arg_indices.push(i);
args_spans.push(unnamed_arg.expr.span);
for span in &matching_placeholders {
if fmt_spans.contains(*span) {
continue;
}
fmt_spans.push(**span);
}
}
}

if !args_spans.is_empty() {
let multispan = MultiSpan::from(fmt_spans);
let mut suggestion_spans = vec![];

for (arg_span, fmt_arg_idx) in args_spans.iter().zip(fmt_arg_indices.iter()) {
let span = if fmt_arg_idx + 1 == args.explicit_args().len() {
*arg_span
} else {
arg_span.until(args.explicit_args()[*fmt_arg_idx + 1].expr.span)
};

suggestion_spans.push(span);
}

let sugg = if args.named_args().len() == 0 {
Some(errors::FormatRedundantArgsSugg { spans: suggestion_spans })
} else {
None
};

return Some(ecx.create_err(errors::FormatRedundantArgs {
n: args_spans.len(),
span: MultiSpan::from(args_spans),
note: multispan,
sugg,
}));
}

None
}

/// Handle invalid references to positional arguments. Output different
/// errors for the case where all arguments are positional and for when
/// there are named arguments or numbered positional arguments in the
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_mir_build/src/thir/pattern/usefulness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -884,6 +884,9 @@ fn collect_nonexhaustive_missing_variants<'p, 'tcx>(
cx: &MatchCheckCtxt<'p, 'tcx>,
column: &[&DeconstructedPat<'p, 'tcx>],
) -> Vec<WitnessPat<'tcx>> {
if column.is_empty() {
return Vec::new();
}
let ty = column[0].ty();
let pcx = &PatCtxt { cx, ty, span: DUMMY_SP, is_top_level: false };

Expand Down
13 changes: 11 additions & 2 deletions library/std/src/fs/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1717,7 +1717,7 @@ fn windows_unix_socket_exists() {
let tmp = tmpdir();
let socket_path = tmp.join("socket");

// std doesn't current support Unix sockets on Windows so manually create one here.
// std doesn't currently support Unix sockets on Windows so manually create one here.
net::init();
unsafe {
let socket = c::WSASocketW(
Expand All @@ -1728,7 +1728,16 @@ fn windows_unix_socket_exists() {
0,
c::WSA_FLAG_OVERLAPPED | c::WSA_FLAG_NO_HANDLE_INHERIT,
);
assert_ne!(socket, c::INVALID_SOCKET);
// AF_UNIX is not supported on earlier versions of Windows,
// so skip this test if it's unsupported and we're not in CI.
if socket == c::INVALID_SOCKET {
let error = c::WSAGetLastError();
if env::var_os("CI").is_none() && error == c::WSAEAFNOSUPPORT {
return;
} else {
panic!("Creating AF_UNIX socket failed (OS error {error})");
}
}
let mut addr = c::SOCKADDR_UN { sun_family: c::AF_UNIX, sun_path: mem::zeroed() };
let bytes = socket_path.as_os_str().as_encoded_bytes();
addr.sun_path[..bytes.len()].copy_from_slice(bytes);
Expand Down
4 changes: 2 additions & 2 deletions src/ci/docker/host-x86_64/dist-x86_64-linux/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ COPY host-x86_64/dist-x86_64-linux/build-clang.sh /tmp/
RUN ./build-clang.sh
ENV CC=clang CXX=clang++

# rustc-perf version from 2023-05-30
# rustc-perf version from 2023-10-22
# Should also be changed in the opt-dist tool for other environments.
ENV PERF_COMMIT 8b2ac3042e1ff2c0074455a0a3618adef97156b1
ENV PERF_COMMIT 4f313add609f43e928e98132358e8426ed3969ae
RUN curl -LS -o perf.zip https://ci-mirrors.rust-lang.org/rustc/rustc-perf-$PERF_COMMIT.zip && \
unzip perf.zip && \
mv rustc-perf-$PERF_COMMIT rustc-perf && \
Expand Down
4 changes: 4 additions & 0 deletions src/ci/docker/host-x86_64/x86_64-gnu-llvm-16/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ RUN sh /scripts/sccache.sh
# LLVM, rather than the typical src/llvm-project LLVM.
ENV NO_DOWNLOAD_CI_LLVM 1

# This is not the latest LLVM version, so some components required by tests may
# be missing.
ENV IS_NOT_LATEST_LLVM 1

# Using llvm-link-shared due to libffi issues -- see #34486
ENV RUST_CONFIGURE_ARGS \
--build=x86_64-unknown-linux-gnu \
Expand Down
50 changes: 50 additions & 0 deletions src/ci/docker/host-x86_64/x86_64-gnu-llvm-17/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
FROM ubuntu:23.10

ARG DEBIAN_FRONTEND=noninteractive

RUN apt-get update && apt-get install -y --no-install-recommends \
g++ \
gcc-multilib \
make \
ninja-build \
file \
curl \
ca-certificates \
python3 \
git \
cmake \
sudo \
gdb \
llvm-17-tools \
llvm-17-dev \
libedit-dev \
libssl-dev \
pkg-config \
zlib1g-dev \
xz-utils \
nodejs \
mingw-w64 \
&& rm -rf /var/lib/apt/lists/*

# Install powershell (universal package) so we can test x.ps1 on Linux
RUN curl -sL "https://github.com/PowerShell/PowerShell/releases/download/v7.3.1/powershell_7.3.1-1.deb_amd64.deb" > powershell.deb && \
dpkg -i powershell.deb && \
rm -f powershell.deb

COPY scripts/sccache.sh /scripts/
RUN sh /scripts/sccache.sh

# We are disabling CI LLVM since this builder is intentionally using a host
# LLVM, rather than the typical src/llvm-project LLVM.
ENV NO_DOWNLOAD_CI_LLVM 1

# Using llvm-link-shared due to libffi issues -- see #34486
ENV RUST_CONFIGURE_ARGS \
--build=x86_64-unknown-linux-gnu \
--llvm-root=/usr/lib/llvm-17 \
--enable-llvm-link-shared \
--set rust.thin-lto-import-instr-limit=10

COPY host-x86_64/x86_64-gnu-llvm-15/script.sh /tmp/

ENV SCRIPT /tmp/script.sh
5 changes: 5 additions & 0 deletions src/ci/github-actions/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,11 @@ jobs:
- name: x86_64-gnu-distcheck
<<: *job-linux-8c

- name: x86_64-gnu-llvm-17
env:
RUST_BACKTRACE: 1
<<: *job-linux-8c

- name: x86_64-gnu-llvm-16
env:
RUST_BACKTRACE: 1
Expand Down
2 changes: 1 addition & 1 deletion src/doc/rustdoc/src/write-documentation/what-to-include.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ and your test suite, this example needs some additional code:
``````text
/// Example
/// ```rust
/// # main() -> Result<(), std::num::ParseIntError> {
/// # fn main() -> Result<(), std::num::ParseIntError> {
/// let fortytwo = "42".parse::<u32>()?;
/// println!("{} + 10 = {}", fortytwo, fortytwo+10);
/// # Ok(())
Expand Down
Loading

0 comments on commit d32b158

Please sign in to comment.