Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit ee0fd6c

Browse files
committed
Auto merge of rust-lang#128048 - workingjubilee:rollup-gehtjxd, r=workingjubilee
Rollup of 6 pull requests Successful merges: - rust-lang#127583 (Deal with invalid UTF-8 from `gai_strerror`) - 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) - rust-lang#128038 (Don't output incremental test artifacts into working directory) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 0f8534e + fdef1d9 commit ee0fd6c

File tree

29 files changed

+172
-57
lines changed

29 files changed

+172
-57
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ build/
5050
/target
5151
/src/bootstrap/target
5252
/src/tools/x/target
53-
/inc-fat/
5453
# Created by default with `src/ci/docker/run.sh`
5554
/obj/
5655
/rustc-ice*

compiler/rustc_ast_passes/messages.ftl

Lines changed: 3 additions & 0 deletions
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

Lines changed: 7 additions & 0 deletions
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

Lines changed: 16 additions & 0 deletions
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

Lines changed: 1 addition & 5 deletions
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

Lines changed: 20 additions & 16 deletions
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

Lines changed: 7 additions & 1 deletion
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

Lines changed: 5 additions & 1 deletion
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

Lines changed: 3 additions & 2 deletions
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/librustdoc/html/static/css/rustdoc.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -831,6 +831,10 @@ pre, .rustdoc.src .example-wrap {
831831
background: var(--table-alt-row-background-color);
832832
}
833833

834+
.docblock .stab, .docblock-short .stab {
835+
display: inline-block;
836+
}
837+
834838
/* "where ..." clauses with block display are also smaller */
835839
div.where {
836840
white-space: pre-wrap;
@@ -953,6 +957,7 @@ table,
953957
display: table;
954958
padding: 0;
955959
margin: 0;
960+
width: 100%;
956961
}
957962
.item-table > li {
958963
display: table-row;

0 commit comments

Comments
 (0)