Skip to content

Commit 24c72ea

Browse files
committed
Auto merge of rust-lang#128039 - matthiaskrgr:rollup-jpxahbo, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - rust-lang#127510 (Rewrite `test-float-parse` in Rust) - rust-lang#127583 (Deal with invalid UTF-8 from `gai_strerror`) - rust-lang#127977 (Update wasi-sdk in CI to latest release) - rust-lang#128014 (Fix stab display in doc blocks) - rust-lang#128020 (Just totally fully deny late-bound consts) - rust-lang#128023 (rustdoc: short descriptions cause word-breaks in tables) - rust-lang#128033 (Explain why we require `_` for empty patterns) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 92c6c03 + a742abe commit 24c72ea

File tree

67 files changed

+2698
-616
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+2698
-616
lines changed

Cargo.lock

+75
Original file line numberDiff line numberDiff line change
@@ -2598,12 +2598,76 @@ dependencies = [
25982598
"windows-sys 0.48.0",
25992599
]
26002600

2601+
[[package]]
2602+
name = "num"
2603+
version = "0.4.3"
2604+
source = "registry+https://github.com/rust-lang/crates.io-index"
2605+
checksum = "35bd024e8b2ff75562e5f34e7f4905839deb4b22955ef5e73d2fea1b9813cb23"
2606+
dependencies = [
2607+
"num-bigint",
2608+
"num-complex",
2609+
"num-integer",
2610+
"num-iter",
2611+
"num-rational",
2612+
"num-traits",
2613+
]
2614+
2615+
[[package]]
2616+
name = "num-bigint"
2617+
version = "0.4.6"
2618+
source = "registry+https://github.com/rust-lang/crates.io-index"
2619+
checksum = "a5e44f723f1133c9deac646763579fdb3ac745e418f2a7af9cd0c431da1f20b9"
2620+
dependencies = [
2621+
"num-integer",
2622+
"num-traits",
2623+
]
2624+
2625+
[[package]]
2626+
name = "num-complex"
2627+
version = "0.4.6"
2628+
source = "registry+https://github.com/rust-lang/crates.io-index"
2629+
checksum = "73f88a1307638156682bada9d7604135552957b7818057dcef22705b4d509495"
2630+
dependencies = [
2631+
"num-traits",
2632+
]
2633+
26012634
[[package]]
26022635
name = "num-conv"
26032636
version = "0.1.0"
26042637
source = "registry+https://github.com/rust-lang/crates.io-index"
26052638
checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9"
26062639

2640+
[[package]]
2641+
name = "num-integer"
2642+
version = "0.1.46"
2643+
source = "registry+https://github.com/rust-lang/crates.io-index"
2644+
checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f"
2645+
dependencies = [
2646+
"num-traits",
2647+
]
2648+
2649+
[[package]]
2650+
name = "num-iter"
2651+
version = "0.1.45"
2652+
source = "registry+https://github.com/rust-lang/crates.io-index"
2653+
checksum = "1429034a0490724d0075ebb2bc9e875d6503c3cf69e235a8941aa757d83ef5bf"
2654+
dependencies = [
2655+
"autocfg",
2656+
"num-integer",
2657+
"num-traits",
2658+
]
2659+
2660+
[[package]]
2661+
name = "num-rational"
2662+
version = "0.4.2"
2663+
source = "registry+https://github.com/rust-lang/crates.io-index"
2664+
checksum = "f83d14da390562dca69fc84082e73e548e1ad308d24accdedd2720017cb37824"
2665+
dependencies = [
2666+
"num-bigint",
2667+
"num-integer",
2668+
"num-traits",
2669+
]
2670+
26072671
[[package]]
26082672
name = "num-traits"
26092673
version = "0.2.19"
@@ -5630,6 +5694,17 @@ dependencies = [
56305694
"std",
56315695
]
56325696

5697+
[[package]]
5698+
name = "test-float-parse"
5699+
version = "0.1.0"
5700+
dependencies = [
5701+
"indicatif",
5702+
"num",
5703+
"rand",
5704+
"rand_chacha",
5705+
"rayon",
5706+
]
5707+
56335708
[[package]]
56345709
name = "textwrap"
56355710
version = "0.16.1"

Cargo.toml

+13
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ members = [
44
"compiler/rustc",
55
"library/std",
66
"library/sysroot",
7+
"src/etc/test-float-parse",
78
"src/rustdoc-json-types",
89
"src/tools/build_helper",
910
"src/tools/cargotest",
@@ -109,6 +110,18 @@ strip = true
109110
debug = 0
110111
strip = true
111112

113+
# Bigint libraries are slow without optimization, speed up testing
114+
[profile.dev.package.test-float-parse]
115+
opt-level = 3
116+
117+
# Speed up the binary as much as possible
118+
[profile.release.package.test-float-parse]
119+
opt-level = 3
120+
codegen-units = 1
121+
# FIXME: LTO cannot be enabled for binaries in a workspace
122+
# <https://github.com/rust-lang/cargo/issues/9330>
123+
# lto = true
124+
112125
[patch.crates-io]
113126
# See comments in `library/rustc-std-workspace-core/README.md` for what's going on
114127
# here

compiler/rustc_ast_passes/messages.ftl

+3
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ ast_passes_fn_without_body =
120120
ast_passes_forbidden_bound =
121121
bounds cannot be used in this context
122122
123+
ast_passes_forbidden_const_param =
124+
late-bound const parameters cannot be used currently
125+
123126
ast_passes_forbidden_default =
124127
`default` is only allowed on items in trait impls
125128
.label = `default` because of this

compiler/rustc_ast_passes/src/errors.rs

+7
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,13 @@ pub struct ForbiddenBound {
6969
pub spans: Vec<Span>,
7070
}
7171

72+
#[derive(Diagnostic)]
73+
#[diag(ast_passes_forbidden_const_param)]
74+
pub struct ForbiddenConstParam {
75+
#[primary_span]
76+
pub const_param_spans: Vec<Span>,
77+
}
78+
7279
#[derive(Diagnostic)]
7380
#[diag(ast_passes_fn_param_too_many)]
7481
pub struct FnParamTooMany {

compiler/rustc_ast_passes/src/feature_gate.rs

+16
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,22 @@ impl<'a> PostExpansionVisitor<'a> {
162162
crate::fluent_generated::ast_passes_forbidden_non_lifetime_param
163163
);
164164

165+
// FIXME(non_lifetime_binders): Const bound params are pretty broken.
166+
// Let's keep users from using this feature accidentally.
167+
if self.features.non_lifetime_binders {
168+
let const_param_spans: Vec<_> = params
169+
.iter()
170+
.filter_map(|param| match param.kind {
171+
ast::GenericParamKind::Const { .. } => Some(param.ident.span),
172+
_ => None,
173+
})
174+
.collect();
175+
176+
if !const_param_spans.is_empty() {
177+
self.sess.dcx().emit_err(errors::ForbiddenConstParam { const_param_spans });
178+
}
179+
}
180+
165181
for param in params {
166182
if !param.bounds.is_empty() {
167183
let spans: Vec<_> = param.bounds.iter().map(|b| b.span()).collect();

compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -2094,11 +2094,7 @@ pub fn deny_non_region_late_bound(
20942094
format!("late-bound {what} parameter not allowed on {where_}"),
20952095
);
20962096

2097-
let guar = if tcx.features().non_lifetime_binders && first {
2098-
diag.emit()
2099-
} else {
2100-
diag.delay_as_bug()
2101-
};
2097+
let guar = diag.emit_unless(!tcx.features().non_lifetime_binders || !first);
21022098

21032099
first = false;
21042100
*arg = ResolvedArg::Error(guar);

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

+20-16
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ use rustc_middle::ty::print::with_no_trimmed_paths;
1616
use rustc_middle::ty::{self, AdtDef, Ty, TyCtxt};
1717
use rustc_pattern_analysis::errors::Uncovered;
1818
use rustc_pattern_analysis::rustc::{
19-
Constructor, DeconstructedPat, MatchArm, RustcPatCtxt as PatCtxt, Usefulness, UsefulnessReport,
20-
WitnessPat,
19+
Constructor, DeconstructedPat, MatchArm, RevealedTy, RustcPatCtxt as PatCtxt, Usefulness,
20+
UsefulnessReport, WitnessPat,
2121
};
2222
use rustc_session::lint::builtin::{
2323
BINDINGS_WITH_VARIANT_NAME, IRREFUTABLE_LET_PATTERNS, UNREACHABLE_PATTERNS,
@@ -998,27 +998,31 @@ fn report_non_exhaustive_match<'p, 'tcx>(
998998
err.note(format!("the matched value is of type `{}`", scrut_ty));
999999

10001000
if !is_empty_match {
1001-
let mut non_exhaustive_tys = FxIndexSet::default();
1001+
let mut special_tys = FxIndexSet::default();
10021002
// Look at the first witness.
1003-
collect_non_exhaustive_tys(cx, &witnesses[0], &mut non_exhaustive_tys);
1003+
collect_special_tys(cx, &witnesses[0], &mut special_tys);
10041004

1005-
for ty in non_exhaustive_tys {
1005+
for ty in special_tys {
10061006
if ty.is_ptr_sized_integral() {
1007-
if ty == cx.tcx.types.usize {
1007+
if ty.inner() == cx.tcx.types.usize {
10081008
err.note(format!(
10091009
"`{ty}` does not have a fixed maximum value, so half-open ranges are necessary to match \
10101010
exhaustively",
10111011
));
1012-
} else if ty == cx.tcx.types.isize {
1012+
} else if ty.inner() == cx.tcx.types.isize {
10131013
err.note(format!(
10141014
"`{ty}` does not have fixed minimum and maximum values, so half-open ranges are necessary to match \
10151015
exhaustively",
10161016
));
10171017
}
1018-
} else if ty == cx.tcx.types.str_ {
1018+
} else if ty.inner() == cx.tcx.types.str_ {
10191019
err.note("`&str` cannot be matched exhaustively, so a wildcard `_` is necessary");
1020-
} else if cx.is_foreign_non_exhaustive_enum(cx.reveal_opaque_ty(ty)) {
1020+
} else if cx.is_foreign_non_exhaustive_enum(ty) {
10211021
err.note(format!("`{ty}` is marked as non-exhaustive, so a wildcard `_` is necessary to match exhaustively"));
1022+
} else if cx.is_uninhabited(ty.inner()) && cx.tcx.features().min_exhaustive_patterns {
1023+
// The type is uninhabited yet there is a witness: we must be in the `MaybeInvalid`
1024+
// case.
1025+
err.note(format!("`{ty}` is uninhabited but is not being matched by value, so a wildcard `_` is required"));
10221026
}
10231027
}
10241028
}
@@ -1168,22 +1172,22 @@ fn joined_uncovered_patterns<'p, 'tcx>(
11681172
}
11691173
}
11701174

1171-
fn collect_non_exhaustive_tys<'tcx>(
1175+
/// Collect types that require specific explanations when they show up in witnesses.
1176+
fn collect_special_tys<'tcx>(
11721177
cx: &PatCtxt<'_, 'tcx>,
11731178
pat: &WitnessPat<'_, 'tcx>,
1174-
non_exhaustive_tys: &mut FxIndexSet<Ty<'tcx>>,
1179+
special_tys: &mut FxIndexSet<RevealedTy<'tcx>>,
11751180
) {
1176-
if matches!(pat.ctor(), Constructor::NonExhaustive) {
1177-
non_exhaustive_tys.insert(pat.ty().inner());
1181+
if matches!(pat.ctor(), Constructor::NonExhaustive | Constructor::Never) {
1182+
special_tys.insert(*pat.ty());
11781183
}
11791184
if let Constructor::IntRange(range) = pat.ctor() {
11801185
if cx.is_range_beyond_boundaries(range, *pat.ty()) {
11811186
// The range denotes the values before `isize::MIN` or the values after `usize::MAX`/`isize::MAX`.
1182-
non_exhaustive_tys.insert(pat.ty().inner());
1187+
special_tys.insert(*pat.ty());
11831188
}
11841189
}
1185-
pat.iter_fields()
1186-
.for_each(|field_pat| collect_non_exhaustive_tys(cx, field_pat, non_exhaustive_tys))
1190+
pat.iter_fields().for_each(|field_pat| collect_special_tys(cx, field_pat, special_tys))
11871191
}
11881192

11891193
fn report_adt_defined_here<'tcx>(

compiler/rustc_pattern_analysis/src/rustc.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,15 @@ pub type WitnessPat<'p, 'tcx> = crate::pat::WitnessPat<RustcPatCtxt<'p, 'tcx>>;
4040
///
4141
/// Use `.inner()` or deref to get to the `Ty<'tcx>`.
4242
#[repr(transparent)]
43-
#[derive(Clone, Copy)]
43+
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
4444
pub struct RevealedTy<'tcx>(Ty<'tcx>);
4545

46+
impl<'tcx> fmt::Display for RevealedTy<'tcx> {
47+
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
48+
self.0.fmt(fmt)
49+
}
50+
}
51+
4652
impl<'tcx> fmt::Debug for RevealedTy<'tcx> {
4753
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
4854
self.0.fmt(fmt)

compiler/rustc_resolve/src/late.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -2763,7 +2763,11 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
27632763
let res = match kind {
27642764
RibKind::Item(..) | RibKind::AssocItem => Res::Def(def_kind, def_id.to_def_id()),
27652765
RibKind::Normal => {
2766-
if self.r.tcx.features().non_lifetime_binders {
2766+
// FIXME(non_lifetime_binders): Stop special-casing
2767+
// const params to error out here.
2768+
if self.r.tcx.features().non_lifetime_binders
2769+
&& matches!(param.kind, GenericParamKind::Type { .. })
2770+
{
27672771
Res::Def(def_kind, def_id.to_def_id())
27682772
} else {
27692773
Res::Err

library/std/src/sys/pal/unix/net.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use crate::io::{self, BorrowedBuf, BorrowedCursor, IoSlice, IoSliceMut};
44
use crate::mem;
55
use crate::net::{Shutdown, SocketAddr};
66
use crate::os::unix::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, RawFd};
7-
use crate::str;
87
use crate::sys::fd::FileDesc;
98
use crate::sys::pal::unix::IsMinusOne;
109
use crate::sys_common::net::{getsockopt, setsockopt, sockaddr_to_addr};
@@ -47,7 +46,9 @@ pub fn cvt_gai(err: c_int) -> io::Result<()> {
4746

4847
#[cfg(not(target_os = "espidf"))]
4948
let detail = unsafe {
50-
str::from_utf8(CStr::from_ptr(libc::gai_strerror(err)).to_bytes()).unwrap().to_owned()
49+
// We can't always expect a UTF-8 environment. When we don't get that luxury,
50+
// it's better to give a low-quality error message than none at all.
51+
CStr::from_ptr(libc::gai_strerror(err)).to_string_lossy()
5152
};
5253

5354
#[cfg(target_os = "espidf")]

src/bootstrap/mk/Makefile.in

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ check-aux:
5151
$(Q)$(BOOTSTRAP) test --stage 2 \
5252
src/tools/cargo \
5353
src/tools/cargotest \
54+
src/etc/test-float-parse \
5455
$(BOOTSTRAP_ARGS)
5556
# Run standard library tests in Miri.
5657
$(Q)BOOTSTRAP_SKIP_TARGET_SANITY=1 \

src/bootstrap/src/core/build_steps/check.rs

+1
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,7 @@ tool_check_step!(CargoMiri, "src/tools/miri/cargo-miri", SourceType::InTree);
466466
tool_check_step!(Rls, "src/tools/rls", SourceType::InTree);
467467
tool_check_step!(Rustfmt, "src/tools/rustfmt", SourceType::InTree);
468468
tool_check_step!(MiroptTestTools, "src/tools/miropt-test-tools", SourceType::InTree);
469+
tool_check_step!(TestFloatParse, "src/etc/test-float-parse", SourceType::InTree);
469470

470471
tool_check_step!(Bootstrap, "src/bootstrap", SourceType::InTree, false);
471472

src/bootstrap/src/core/build_steps/clippy.rs

+1
Original file line numberDiff line numberDiff line change
@@ -326,4 +326,5 @@ lint_any!(
326326
Rustfmt, "src/tools/rustfmt", "rustfmt";
327327
RustInstaller, "src/tools/rust-installer", "rust-installer";
328328
Tidy, "src/tools/tidy", "tidy";
329+
TestFloatParse, "src/etc/test-float-parse", "test-float-parse";
329330
);

0 commit comments

Comments
 (0)