Skip to content

Commit d32b158

Browse files
committed
Auto merge of #3136 - rust-lang:rustup-2023-10-23, r=RalfJung
Automatic Rustup
2 parents 74092c5 + dd683dd commit d32b158

File tree

33 files changed

+668
-235
lines changed

33 files changed

+668
-235
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,10 @@ jobs:
286286
- name: x86_64-gnu-distcheck
287287
os: ubuntu-20.04-8core-32gb
288288
env: {}
289+
- name: x86_64-gnu-llvm-17
290+
env:
291+
RUST_BACKTRACE: 1
292+
os: ubuntu-20.04-8core-32gb
289293
- name: x86_64-gnu-llvm-16
290294
env:
291295
RUST_BACKTRACE: 1

Cargo.lock

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1663,9 +1663,9 @@ checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888"
16631663

16641664
[[package]]
16651665
name = "hashbrown"
1666-
version = "0.14.0"
1666+
version = "0.14.2"
16671667
source = "registry+https://github.com/rust-lang/crates.io-index"
1668-
checksum = "2c6201b9ff9fd90a5a3bac2e56a830d0caa509576f0e503818ee82c181b3437a"
1668+
checksum = "f93e7192158dbcda357bdec5fb5788eebf8bbac027f3f33e719d29135ae84156"
16691669
dependencies = [
16701670
"ahash",
16711671
"allocator-api2",
@@ -1982,7 +1982,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
19821982
checksum = "d5477fe2230a79769d8dc68e0eabf5437907c0457a5614a9e8dddb67f65eb65d"
19831983
dependencies = [
19841984
"equivalent",
1985-
"hashbrown 0.14.0",
1985+
"hashbrown 0.14.2",
19861986
"rustc-rayon",
19871987
"serde",
19881988
]
@@ -2621,7 +2621,7 @@ dependencies = [
26212621
"compiler_builtins",
26222622
"crc32fast",
26232623
"flate2",
2624-
"hashbrown 0.14.0",
2624+
"hashbrown 0.14.2",
26252625
"indexmap 2.0.0",
26262626
"memchr",
26272627
"rustc-std-workspace-alloc",
@@ -5095,7 +5095,7 @@ dependencies = [
50955095
"core",
50965096
"dlmalloc",
50975097
"fortanix-sgx-abi",
5098-
"hashbrown 0.14.0",
5098+
"hashbrown 0.14.2",
50995099
"hermit-abi 0.3.2",
51005100
"libc",
51015101
"miniz_oxide",
@@ -5415,7 +5415,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
54155415
checksum = "4db52ee8fec06e119b692ef3dd2c4cf621a99204c1b8c47407870ed050305b9b"
54165416
dependencies = [
54175417
"gimli",
5418-
"hashbrown 0.14.0",
5418+
"hashbrown 0.14.2",
54195419
"object",
54205420
"tracing",
54215421
]

compiler/rustc_builtin_macros/messages.ftl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,20 @@ builtin_macros_format_positional_after_named = positional arguments cannot follo
137137
.label = positional arguments must be before named arguments
138138
.named_args = named argument
139139
140+
builtin_macros_format_redundant_args = redundant {$n ->
141+
[one] argument
142+
*[more] arguments
143+
}
144+
.help = {$n ->
145+
[one] the formatting string already captures the binding directly, it doesn't need to be included in the argument list
146+
*[more] the formatting strings already captures the bindings directly, they don't need to be included in the argument list
147+
}
148+
.note = {$n ->
149+
[one] the formatting specifier is referencing the binding already
150+
*[more] the formatting specifiers are referencing the bindings already
151+
}
152+
.suggestion = this can be removed
153+
140154
builtin_macros_format_remove_raw_ident = remove the `r#`
141155
142156
builtin_macros_format_requires_string = requires at least a format string argument

compiler/rustc_builtin_macros/src/errors.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,27 @@ pub(crate) struct FormatPositionalMismatch {
646646
pub(crate) highlight: SingleLabelManySpans,
647647
}
648648

649+
#[derive(Diagnostic)]
650+
#[diag(builtin_macros_format_redundant_args)]
651+
pub(crate) struct FormatRedundantArgs {
652+
#[primary_span]
653+
pub(crate) span: MultiSpan,
654+
pub(crate) n: usize,
655+
656+
#[note]
657+
pub(crate) note: MultiSpan,
658+
659+
#[subdiagnostic]
660+
pub(crate) sugg: Option<FormatRedundantArgsSugg>,
661+
}
662+
663+
#[derive(Subdiagnostic)]
664+
#[multipart_suggestion(builtin_macros_suggestion, applicability = "machine-applicable")]
665+
pub(crate) struct FormatRedundantArgsSugg {
666+
#[suggestion_part(code = "")]
667+
pub(crate) spans: Vec<Span>,
668+
}
669+
649670
#[derive(Diagnostic)]
650671
#[diag(builtin_macros_test_case_non_item)]
651672
pub(crate) struct TestCaseNonItem {

compiler/rustc_builtin_macros/src/format.rs

Lines changed: 110 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use parse::Position::ArgumentNamed;
12
use rustc_ast::ptr::P;
23
use rustc_ast::tokenstream::TokenStream;
34
use rustc_ast::{token, StmtKind};
@@ -7,7 +8,9 @@ use rustc_ast::{
78
FormatDebugHex, FormatOptions, FormatPlaceholder, FormatSign, FormatTrait,
89
};
910
use rustc_data_structures::fx::FxHashSet;
10-
use rustc_errors::{Applicability, MultiSpan, PResult, SingleLabelManySpans};
11+
use rustc_errors::{
12+
Applicability, DiagnosticBuilder, ErrorGuaranteed, MultiSpan, PResult, SingleLabelManySpans,
13+
};
1114
use rustc_expand::base::{self, *};
1215
use rustc_parse_format as parse;
1316
use rustc_span::symbol::{Ident, Symbol};
@@ -364,8 +367,8 @@ fn make_format_args(
364367
let mut unfinished_literal = String::new();
365368
let mut placeholder_index = 0;
366369

367-
for piece in pieces {
368-
match piece {
370+
for piece in &pieces {
371+
match *piece {
369372
parse::Piece::String(s) => {
370373
unfinished_literal.push_str(s);
371374
}
@@ -513,7 +516,17 @@ fn make_format_args(
513516
// If there's a lot of unused arguments,
514517
// let's check if this format arguments looks like another syntax (printf / shell).
515518
let detect_foreign_fmt = unused.len() > args.explicit_args().len() / 2;
516-
report_missing_placeholders(ecx, unused, detect_foreign_fmt, str_style, fmt_str, fmt_span);
519+
report_missing_placeholders(
520+
ecx,
521+
unused,
522+
&used,
523+
&args,
524+
&pieces,
525+
detect_foreign_fmt,
526+
str_style,
527+
fmt_str,
528+
fmt_span,
529+
);
517530
}
518531

519532
// Only check for unused named argument names if there are no other errors to avoid causing
@@ -580,6 +593,9 @@ fn invalid_placeholder_type_error(
580593
fn report_missing_placeholders(
581594
ecx: &mut ExtCtxt<'_>,
582595
unused: Vec<(Span, bool)>,
596+
used: &[bool],
597+
args: &FormatArguments,
598+
pieces: &[parse::Piece<'_>],
583599
detect_foreign_fmt: bool,
584600
str_style: Option<usize>,
585601
fmt_str: &str,
@@ -598,6 +614,26 @@ fn report_missing_placeholders(
598614
})
599615
};
600616

617+
let placeholders = pieces
618+
.iter()
619+
.filter_map(|piece| {
620+
if let parse::Piece::NextArgument(argument) = piece && let ArgumentNamed(binding) = argument.position {
621+
let span = fmt_span.from_inner(InnerSpan::new(argument.position_span.start, argument.position_span.end));
622+
Some((span, binding))
623+
} else { None }
624+
})
625+
.collect::<Vec<_>>();
626+
627+
if !placeholders.is_empty() {
628+
if let Some(mut new_diag) =
629+
report_redundant_format_arguments(ecx, &args, used, placeholders)
630+
{
631+
diag.cancel();
632+
new_diag.emit();
633+
return;
634+
}
635+
}
636+
601637
// Used to ensure we only report translations for *one* kind of foreign format.
602638
let mut found_foreign = false;
603639

@@ -685,6 +721,76 @@ fn report_missing_placeholders(
685721
diag.emit();
686722
}
687723

724+
/// This function detects and reports unused format!() arguments that are
725+
/// redundant due to implicit captures (e.g. `format!("{x}", x)`).
726+
fn report_redundant_format_arguments<'a>(
727+
ecx: &mut ExtCtxt<'a>,
728+
args: &FormatArguments,
729+
used: &[bool],
730+
placeholders: Vec<(Span, &str)>,
731+
) -> Option<DiagnosticBuilder<'a, ErrorGuaranteed>> {
732+
let mut fmt_arg_indices = vec![];
733+
let mut args_spans = vec![];
734+
let mut fmt_spans = vec![];
735+
736+
for (i, unnamed_arg) in args.unnamed_args().iter().enumerate().rev() {
737+
let Some(ty) = unnamed_arg.expr.to_ty() else { continue };
738+
let Some(argument_binding) = ty.kind.is_simple_path() else { continue };
739+
let argument_binding = argument_binding.as_str();
740+
741+
if used[i] {
742+
continue;
743+
}
744+
745+
let matching_placeholders = placeholders
746+
.iter()
747+
.filter(|(_, inline_binding)| argument_binding == *inline_binding)
748+
.map(|(span, _)| span)
749+
.collect::<Vec<_>>();
750+
751+
if !matching_placeholders.is_empty() {
752+
fmt_arg_indices.push(i);
753+
args_spans.push(unnamed_arg.expr.span);
754+
for span in &matching_placeholders {
755+
if fmt_spans.contains(*span) {
756+
continue;
757+
}
758+
fmt_spans.push(**span);
759+
}
760+
}
761+
}
762+
763+
if !args_spans.is_empty() {
764+
let multispan = MultiSpan::from(fmt_spans);
765+
let mut suggestion_spans = vec![];
766+
767+
for (arg_span, fmt_arg_idx) in args_spans.iter().zip(fmt_arg_indices.iter()) {
768+
let span = if fmt_arg_idx + 1 == args.explicit_args().len() {
769+
*arg_span
770+
} else {
771+
arg_span.until(args.explicit_args()[*fmt_arg_idx + 1].expr.span)
772+
};
773+
774+
suggestion_spans.push(span);
775+
}
776+
777+
let sugg = if args.named_args().len() == 0 {
778+
Some(errors::FormatRedundantArgsSugg { spans: suggestion_spans })
779+
} else {
780+
None
781+
};
782+
783+
return Some(ecx.create_err(errors::FormatRedundantArgs {
784+
n: args_spans.len(),
785+
span: MultiSpan::from(args_spans),
786+
note: multispan,
787+
sugg,
788+
}));
789+
}
790+
791+
None
792+
}
793+
688794
/// Handle invalid references to positional arguments. Output different
689795
/// errors for the case where all arguments are positional and for when
690796
/// there are named arguments or numbered positional arguments in the

compiler/rustc_mir_build/src/thir/pattern/usefulness.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -884,6 +884,9 @@ fn collect_nonexhaustive_missing_variants<'p, 'tcx>(
884884
cx: &MatchCheckCtxt<'p, 'tcx>,
885885
column: &[&DeconstructedPat<'p, 'tcx>],
886886
) -> Vec<WitnessPat<'tcx>> {
887+
if column.is_empty() {
888+
return Vec::new();
889+
}
887890
let ty = column[0].ty();
888891
let pcx = &PatCtxt { cx, ty, span: DUMMY_SP, is_top_level: false };
889892

library/std/src/fs/tests.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1717,7 +1717,7 @@ fn windows_unix_socket_exists() {
17171717
let tmp = tmpdir();
17181718
let socket_path = tmp.join("socket");
17191719

1720-
// std doesn't current support Unix sockets on Windows so manually create one here.
1720+
// std doesn't currently support Unix sockets on Windows so manually create one here.
17211721
net::init();
17221722
unsafe {
17231723
let socket = c::WSASocketW(
@@ -1728,7 +1728,16 @@ fn windows_unix_socket_exists() {
17281728
0,
17291729
c::WSA_FLAG_OVERLAPPED | c::WSA_FLAG_NO_HANDLE_INHERIT,
17301730
);
1731-
assert_ne!(socket, c::INVALID_SOCKET);
1731+
// AF_UNIX is not supported on earlier versions of Windows,
1732+
// so skip this test if it's unsupported and we're not in CI.
1733+
if socket == c::INVALID_SOCKET {
1734+
let error = c::WSAGetLastError();
1735+
if env::var_os("CI").is_none() && error == c::WSAEAFNOSUPPORT {
1736+
return;
1737+
} else {
1738+
panic!("Creating AF_UNIX socket failed (OS error {error})");
1739+
}
1740+
}
17321741
let mut addr = c::SOCKADDR_UN { sun_family: c::AF_UNIX, sun_path: mem::zeroed() };
17331742
let bytes = socket_path.as_os_str().as_encoded_bytes();
17341743
addr.sun_path[..bytes.len()].copy_from_slice(bytes);

src/ci/docker/host-x86_64/dist-x86_64-linux/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ COPY host-x86_64/dist-x86_64-linux/build-clang.sh /tmp/
5757
RUN ./build-clang.sh
5858
ENV CC=clang CXX=clang++
5959

60-
# rustc-perf version from 2023-05-30
60+
# rustc-perf version from 2023-10-22
6161
# Should also be changed in the opt-dist tool for other environments.
62-
ENV PERF_COMMIT 8b2ac3042e1ff2c0074455a0a3618adef97156b1
62+
ENV PERF_COMMIT 4f313add609f43e928e98132358e8426ed3969ae
6363
RUN curl -LS -o perf.zip https://ci-mirrors.rust-lang.org/rustc/rustc-perf-$PERF_COMMIT.zip && \
6464
unzip perf.zip && \
6565
mv rustc-perf-$PERF_COMMIT rustc-perf && \

src/ci/docker/host-x86_64/x86_64-gnu-llvm-16/Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ RUN sh /scripts/sccache.sh
3838
# LLVM, rather than the typical src/llvm-project LLVM.
3939
ENV NO_DOWNLOAD_CI_LLVM 1
4040

41+
# This is not the latest LLVM version, so some components required by tests may
42+
# be missing.
43+
ENV IS_NOT_LATEST_LLVM 1
44+
4145
# Using llvm-link-shared due to libffi issues -- see #34486
4246
ENV RUST_CONFIGURE_ARGS \
4347
--build=x86_64-unknown-linux-gnu \
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
FROM ubuntu:23.10
2+
3+
ARG DEBIAN_FRONTEND=noninteractive
4+
5+
RUN apt-get update && apt-get install -y --no-install-recommends \
6+
g++ \
7+
gcc-multilib \
8+
make \
9+
ninja-build \
10+
file \
11+
curl \
12+
ca-certificates \
13+
python3 \
14+
git \
15+
cmake \
16+
sudo \
17+
gdb \
18+
llvm-17-tools \
19+
llvm-17-dev \
20+
libedit-dev \
21+
libssl-dev \
22+
pkg-config \
23+
zlib1g-dev \
24+
xz-utils \
25+
nodejs \
26+
mingw-w64 \
27+
&& rm -rf /var/lib/apt/lists/*
28+
29+
# Install powershell (universal package) so we can test x.ps1 on Linux
30+
RUN curl -sL "https://github.com/PowerShell/PowerShell/releases/download/v7.3.1/powershell_7.3.1-1.deb_amd64.deb" > powershell.deb && \
31+
dpkg -i powershell.deb && \
32+
rm -f powershell.deb
33+
34+
COPY scripts/sccache.sh /scripts/
35+
RUN sh /scripts/sccache.sh
36+
37+
# We are disabling CI LLVM since this builder is intentionally using a host
38+
# LLVM, rather than the typical src/llvm-project LLVM.
39+
ENV NO_DOWNLOAD_CI_LLVM 1
40+
41+
# Using llvm-link-shared due to libffi issues -- see #34486
42+
ENV RUST_CONFIGURE_ARGS \
43+
--build=x86_64-unknown-linux-gnu \
44+
--llvm-root=/usr/lib/llvm-17 \
45+
--enable-llvm-link-shared \
46+
--set rust.thin-lto-import-instr-limit=10
47+
48+
COPY host-x86_64/x86_64-gnu-llvm-15/script.sh /tmp/
49+
50+
ENV SCRIPT /tmp/script.sh

src/ci/github-actions/ci.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,11 @@ jobs:
463463
- name: x86_64-gnu-distcheck
464464
<<: *job-linux-8c
465465

466+
- name: x86_64-gnu-llvm-17
467+
env:
468+
RUST_BACKTRACE: 1
469+
<<: *job-linux-8c
470+
466471
- name: x86_64-gnu-llvm-16
467472
env:
468473
RUST_BACKTRACE: 1

src/doc/rustdoc/src/write-documentation/what-to-include.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ and your test suite, this example needs some additional code:
7373
``````text
7474
/// Example
7575
/// ```rust
76-
/// # main() -> Result<(), std::num::ParseIntError> {
76+
/// # fn main() -> Result<(), std::num::ParseIntError> {
7777
/// let fortytwo = "42".parse::<u32>()?;
7878
/// println!("{} + 10 = {}", fortytwo, fortytwo+10);
7979
/// # Ok(())

0 commit comments

Comments
 (0)