Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 7 pull requests #128039

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
5b0b4ff
Update wasi-sdk in CI to latest release
alexcrichton Jul 19, 2024
006c884
Fix two new failing tests
alexcrichton Jul 19, 2024
59429e6
Rewrite `test-float-parse` in Rust
tgross35 Jul 20, 2024
51827ce
Move `test-float-parse` to the global workspace
tgross35 Jul 20, 2024
6062059
Expose `test-float-parse` via bootstrap
tgross35 Jul 20, 2024
ee034f4
Fix stab display in doc blocks
GuillaumeGomez Jul 20, 2024
3862095
Just totally fully deny late-bound consts
compiler-errors Jul 20, 2024
9533544
rustdoc: short descr. cause word-breaks in tables
Kijewski Jul 21, 2024
e4d701b
Add regression test for stab display in doc blocks
GuillaumeGomez Jul 20, 2024
84db684
Update `source-code-page-code-scroll.goml` GUI test
GuillaumeGomez Jul 21, 2024
ae42efc
Deal with invalid UTF-8 from `gai_strerror`
Noratrieb Jul 10, 2024
710add5
Tweak `collect_non_exhaustive_tys`
Nadrieril Jul 21, 2024
8a49d83
Explain why we require `_` for empty patterns
Nadrieril Jul 21, 2024
d123878
Run `test-float-parse` as part of CI
tgross35 Jul 20, 2024
3d4b577
Rollup merge of #127510 - tgross35:test-float-parse-update, r=Mark-Si…
matthiaskrgr Jul 21, 2024
1ab77b5
Rollup merge of #127583 - Nilstrieb:invalid-utf8, r=joboet
matthiaskrgr Jul 21, 2024
d9d06ba
Rollup merge of #127977 - alexcrichton:update-wasi-sdk, r=Mark-Simula…
matthiaskrgr Jul 21, 2024
4e8070c
Rollup merge of #128014 - GuillaumeGomez:stab-in-doc-blocks, r=notriddle
matthiaskrgr Jul 21, 2024
4e1ec87
Rollup merge of #128020 - compiler-errors:nlb-no-const, r=BoxyUwU
matthiaskrgr Jul 21, 2024
1c55399
Rollup merge of #128023 - Kijewski:pr-table-width, r=notriddle
matthiaskrgr Jul 21, 2024
a742abe
Rollup merge of #128033 - Nadrieril:explain-empty-wildcards, r=compil…
matthiaskrgr Jul 21, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2598,12 +2598,76 @@ dependencies = [
"windows-sys 0.48.0",
]

[[package]]
name = "num"
version = "0.4.3"
source = "registry+https:/rust-lang/crates.io-index"
checksum = "35bd024e8b2ff75562e5f34e7f4905839deb4b22955ef5e73d2fea1b9813cb23"
dependencies = [
"num-bigint",
"num-complex",
"num-integer",
"num-iter",
"num-rational",
"num-traits",
]

[[package]]
name = "num-bigint"
version = "0.4.6"
source = "registry+https:/rust-lang/crates.io-index"
checksum = "a5e44f723f1133c9deac646763579fdb3ac745e418f2a7af9cd0c431da1f20b9"
dependencies = [
"num-integer",
"num-traits",
]

[[package]]
name = "num-complex"
version = "0.4.6"
source = "registry+https:/rust-lang/crates.io-index"
checksum = "73f88a1307638156682bada9d7604135552957b7818057dcef22705b4d509495"
dependencies = [
"num-traits",
]

[[package]]
name = "num-conv"
version = "0.1.0"
source = "registry+https:/rust-lang/crates.io-index"
checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9"

[[package]]
name = "num-integer"
version = "0.1.46"
source = "registry+https:/rust-lang/crates.io-index"
checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f"
dependencies = [
"num-traits",
]

[[package]]
name = "num-iter"
version = "0.1.45"
source = "registry+https:/rust-lang/crates.io-index"
checksum = "1429034a0490724d0075ebb2bc9e875d6503c3cf69e235a8941aa757d83ef5bf"
dependencies = [
"autocfg",
"num-integer",
"num-traits",
]

[[package]]
name = "num-rational"
version = "0.4.2"
source = "registry+https:/rust-lang/crates.io-index"
checksum = "f83d14da390562dca69fc84082e73e548e1ad308d24accdedd2720017cb37824"
dependencies = [
"num-bigint",
"num-integer",
"num-traits",
]

[[package]]
name = "num-traits"
version = "0.2.19"
Expand Down Expand Up @@ -5630,6 +5694,17 @@ dependencies = [
"std",
]

[[package]]
name = "test-float-parse"
version = "0.1.0"
dependencies = [
"indicatif",
"num",
"rand",
"rand_chacha",
"rayon",
]

[[package]]
name = "textwrap"
version = "0.16.1"
Expand Down
13 changes: 13 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ members = [
"compiler/rustc",
"library/std",
"library/sysroot",
"src/etc/test-float-parse",
"src/rustdoc-json-types",
"src/tools/build_helper",
"src/tools/cargotest",
Expand Down Expand Up @@ -109,6 +110,18 @@ strip = true
debug = 0
strip = true

# Bigint libraries are slow without optimization, speed up testing
[profile.dev.package.test-float-parse]
opt-level = 3

# Speed up the binary as much as possible
[profile.release.package.test-float-parse]
opt-level = 3
codegen-units = 1
# FIXME: LTO cannot be enabled for binaries in a workspace
# <https:/rust-lang/cargo/issues/9330>
# lto = true

[patch.crates-io]
# See comments in `library/rustc-std-workspace-core/README.md` for what's going on
# here
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_ast_passes/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ ast_passes_fn_without_body =
ast_passes_forbidden_bound =
bounds cannot be used in this context
ast_passes_forbidden_const_param =
late-bound const parameters cannot be used currently
ast_passes_forbidden_default =
`default` is only allowed on items in trait impls
.label = `default` because of this
Expand Down
7 changes: 7 additions & 0 deletions compiler/rustc_ast_passes/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ pub struct ForbiddenBound {
pub spans: Vec<Span>,
}

#[derive(Diagnostic)]
#[diag(ast_passes_forbidden_const_param)]
pub struct ForbiddenConstParam {
#[primary_span]
pub const_param_spans: Vec<Span>,
}

#[derive(Diagnostic)]
#[diag(ast_passes_fn_param_too_many)]
pub struct FnParamTooMany {
Expand Down
16 changes: 16 additions & 0 deletions compiler/rustc_ast_passes/src/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,22 @@ impl<'a> PostExpansionVisitor<'a> {
crate::fluent_generated::ast_passes_forbidden_non_lifetime_param
);

// FIXME(non_lifetime_binders): Const bound params are pretty broken.
// Let's keep users from using this feature accidentally.
if self.features.non_lifetime_binders {
let const_param_spans: Vec<_> = params
.iter()
.filter_map(|param| match param.kind {
ast::GenericParamKind::Const { .. } => Some(param.ident.span),
_ => None,
})
.collect();

if !const_param_spans.is_empty() {
self.sess.dcx().emit_err(errors::ForbiddenConstParam { const_param_spans });
}
}

for param in params {
if !param.bounds.is_empty() {
let spans: Vec<_> = param.bounds.iter().map(|b| b.span()).collect();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2094,11 +2094,7 @@ pub fn deny_non_region_late_bound(
format!("late-bound {what} parameter not allowed on {where_}"),
);

let guar = if tcx.features().non_lifetime_binders && first {
diag.emit()
} else {
diag.delay_as_bug()
};
let guar = diag.emit_unless(!tcx.features().non_lifetime_binders || !first);

first = false;
*arg = ResolvedArg::Error(guar);
Expand Down
36 changes: 20 additions & 16 deletions compiler/rustc_mir_build/src/thir/pattern/check_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ use rustc_middle::ty::print::with_no_trimmed_paths;
use rustc_middle::ty::{self, AdtDef, Ty, TyCtxt};
use rustc_pattern_analysis::errors::Uncovered;
use rustc_pattern_analysis::rustc::{
Constructor, DeconstructedPat, MatchArm, RustcPatCtxt as PatCtxt, Usefulness, UsefulnessReport,
WitnessPat,
Constructor, DeconstructedPat, MatchArm, RevealedTy, RustcPatCtxt as PatCtxt, Usefulness,
UsefulnessReport, WitnessPat,
};
use rustc_session::lint::builtin::{
BINDINGS_WITH_VARIANT_NAME, IRREFUTABLE_LET_PATTERNS, UNREACHABLE_PATTERNS,
Expand Down Expand Up @@ -998,27 +998,31 @@ fn report_non_exhaustive_match<'p, 'tcx>(
err.note(format!("the matched value is of type `{}`", scrut_ty));

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

for ty in non_exhaustive_tys {
for ty in special_tys {
if ty.is_ptr_sized_integral() {
if ty == cx.tcx.types.usize {
if ty.inner() == cx.tcx.types.usize {
err.note(format!(
"`{ty}` does not have a fixed maximum value, so half-open ranges are necessary to match \
exhaustively",
));
} else if ty == cx.tcx.types.isize {
} else if ty.inner() == cx.tcx.types.isize {
err.note(format!(
"`{ty}` does not have fixed minimum and maximum values, so half-open ranges are necessary to match \
exhaustively",
));
}
} else if ty == cx.tcx.types.str_ {
} else if ty.inner() == cx.tcx.types.str_ {
err.note("`&str` cannot be matched exhaustively, so a wildcard `_` is necessary");
} else if cx.is_foreign_non_exhaustive_enum(cx.reveal_opaque_ty(ty)) {
} else if cx.is_foreign_non_exhaustive_enum(ty) {
err.note(format!("`{ty}` is marked as non-exhaustive, so a wildcard `_` is necessary to match exhaustively"));
} else if cx.is_uninhabited(ty.inner()) && cx.tcx.features().min_exhaustive_patterns {
// The type is uninhabited yet there is a witness: we must be in the `MaybeInvalid`
// case.
err.note(format!("`{ty}` is uninhabited but is not being matched by value, so a wildcard `_` is required"));
}
}
}
Expand Down Expand Up @@ -1168,22 +1172,22 @@ fn joined_uncovered_patterns<'p, 'tcx>(
}
}

fn collect_non_exhaustive_tys<'tcx>(
/// Collect types that require specific explanations when they show up in witnesses.
fn collect_special_tys<'tcx>(
cx: &PatCtxt<'_, 'tcx>,
pat: &WitnessPat<'_, 'tcx>,
non_exhaustive_tys: &mut FxIndexSet<Ty<'tcx>>,
special_tys: &mut FxIndexSet<RevealedTy<'tcx>>,
) {
if matches!(pat.ctor(), Constructor::NonExhaustive) {
non_exhaustive_tys.insert(pat.ty().inner());
if matches!(pat.ctor(), Constructor::NonExhaustive | Constructor::Never) {
special_tys.insert(*pat.ty());
}
if let Constructor::IntRange(range) = pat.ctor() {
if cx.is_range_beyond_boundaries(range, *pat.ty()) {
// The range denotes the values before `isize::MIN` or the values after `usize::MAX`/`isize::MAX`.
non_exhaustive_tys.insert(pat.ty().inner());
special_tys.insert(*pat.ty());
}
}
pat.iter_fields()
.for_each(|field_pat| collect_non_exhaustive_tys(cx, field_pat, non_exhaustive_tys))
pat.iter_fields().for_each(|field_pat| collect_special_tys(cx, field_pat, special_tys))
}

fn report_adt_defined_here<'tcx>(
Expand Down
8 changes: 7 additions & 1 deletion compiler/rustc_pattern_analysis/src/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,15 @@ pub type WitnessPat<'p, 'tcx> = crate::pat::WitnessPat<RustcPatCtxt<'p, 'tcx>>;
///
/// Use `.inner()` or deref to get to the `Ty<'tcx>`.
#[repr(transparent)]
#[derive(Clone, Copy)]
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
pub struct RevealedTy<'tcx>(Ty<'tcx>);

impl<'tcx> fmt::Display for RevealedTy<'tcx> {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
self.0.fmt(fmt)
}
}

impl<'tcx> fmt::Debug for RevealedTy<'tcx> {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
self.0.fmt(fmt)
Expand Down
6 changes: 5 additions & 1 deletion compiler/rustc_resolve/src/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2763,7 +2763,11 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
let res = match kind {
RibKind::Item(..) | RibKind::AssocItem => Res::Def(def_kind, def_id.to_def_id()),
RibKind::Normal => {
if self.r.tcx.features().non_lifetime_binders {
// FIXME(non_lifetime_binders): Stop special-casing
// const params to error out here.
if self.r.tcx.features().non_lifetime_binders
&& matches!(param.kind, GenericParamKind::Type { .. })
{
Res::Def(def_kind, def_id.to_def_id())
} else {
Res::Err
Expand Down
5 changes: 3 additions & 2 deletions library/std/src/sys/pal/unix/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use crate::io::{self, BorrowedBuf, BorrowedCursor, IoSlice, IoSliceMut};
use crate::mem;
use crate::net::{Shutdown, SocketAddr};
use crate::os::unix::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, RawFd};
use crate::str;
use crate::sys::fd::FileDesc;
use crate::sys::pal::unix::IsMinusOne;
use crate::sys_common::net::{getsockopt, setsockopt, sockaddr_to_addr};
Expand Down Expand Up @@ -47,7 +46,9 @@ pub fn cvt_gai(err: c_int) -> io::Result<()> {

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

#[cfg(target_os = "espidf")]
Expand Down
1 change: 1 addition & 0 deletions src/bootstrap/mk/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ check-aux:
$(Q)$(BOOTSTRAP) test --stage 2 \
src/tools/cargo \
src/tools/cargotest \
src/etc/test-float-parse \
$(BOOTSTRAP_ARGS)
# Run standard library tests in Miri.
$(Q)BOOTSTRAP_SKIP_TARGET_SANITY=1 \
Expand Down
1 change: 1 addition & 0 deletions src/bootstrap/src/core/build_steps/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,7 @@ tool_check_step!(CargoMiri, "src/tools/miri/cargo-miri", SourceType::InTree);
tool_check_step!(Rls, "src/tools/rls", SourceType::InTree);
tool_check_step!(Rustfmt, "src/tools/rustfmt", SourceType::InTree);
tool_check_step!(MiroptTestTools, "src/tools/miropt-test-tools", SourceType::InTree);
tool_check_step!(TestFloatParse, "src/etc/test-float-parse", SourceType::InTree);

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

Expand Down
1 change: 1 addition & 0 deletions src/bootstrap/src/core/build_steps/clippy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,4 +326,5 @@ lint_any!(
Rustfmt, "src/tools/rustfmt", "rustfmt";
RustInstaller, "src/tools/rust-installer", "rust-installer";
Tidy, "src/tools/tidy", "tidy";
TestFloatParse, "src/etc/test-float-parse", "test-float-parse";
);
Loading
Loading