Skip to content

Commit ee0fd6c

Browse files
committed
Auto merge of #128048 - workingjubilee:rollup-gehtjxd, r=workingjubilee
Rollup of 6 pull requests Successful merges: - #127583 (Deal with invalid UTF-8 from `gai_strerror`) - #128014 (Fix stab display in doc blocks) - #128020 (Just totally fully deny late-bound consts) - #128023 (rustdoc: short descriptions cause word-breaks in tables) - #128033 (Explain why we require `_` for empty patterns) - #128038 (Don't output incremental test artifacts into working directory) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 0f8534e + fdef1d9 commit ee0fd6c

29 files changed

+172
-57
lines changed

.gitignore

-1
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

+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/librustdoc/html/static/css/rustdoc.css

+5
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;

tests/crashes/127009.rs

-11
This file was deleted.

tests/rustdoc-gui/source-code-page-code-scroll.goml

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
go-to: "file://" + |DOC_PATH| + "/src/test_docs/lib.rs.html"
33
set-window-size: (800, 1000)
44
// "scrollWidth" should be superior than "clientWidth".
5-
assert-property: ("body", {"scrollWidth": 1047, "clientWidth": 800})
5+
assert-property: ("body", {"scrollWidth": 1114, "clientWidth": 800})
66

77
// Both properties should be equal (ie, no scroll on the code block).
8-
assert-property: (".example-wrap .rust", {"scrollWidth": 933, "clientWidth": 933})
8+
assert-property: (".example-wrap .rust", {"scrollWidth": 1000, "clientWidth": 1000})

tests/rustdoc-gui/src/test_docs/lib.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ Also, stop using `bar` as it's <span class="stab deprecated" title="">deprecated
2020
Also, stop using `bar` as it's <span class="stab deprecated" title="">deprecated</span>.
2121
Also, stop using `bar` as it's <span class="stab deprecated" title="">deprecated</span>.
2222
23-
Finally, you can use `quz` only on <span class="stab portability"><code>Unix or x86-64</code>
24-
</span>.
25-
Finally, you can use `quz` only on <span class="stab portability"><code>Unix or x86-64</code>
26-
</span>.
23+
Finally, you can use `quz` only on <span class="stab portability" data-span="1"><code>Unix or x86-64
24+
</code></span>.
25+
Finally, you can use `quz` only on <span class="stab portability" data-span="2"><code>Unix or x86-64
26+
</code></span>.
2727
*/
2828

2929
use std::convert::AsRef;

tests/rustdoc-gui/stab-in-doc.goml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// This test ensure that `stab` elements if used in doc blocks are not breaking the text layout.
2+
go-to: "file://" + |DOC_PATH| + "/test_docs/index.html"
3+
// We make the window wide enough for the two stabs who are looking into to be on the same line.
4+
set-window-size: (1100, 600)
5+
compare-elements-position: (
6+
".top-doc .docblock span[data-span='1']",
7+
".top-doc .docblock span[data-span='2']",
8+
["y"],
9+
)

tests/ui/closures/binder/const-bound.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33

44
fn main() {
55
for<const N: i32> || -> () {};
6-
//~^ ERROR late-bound const parameter not allowed on closures
6+
//~^ ERROR late-bound const parameters cannot be used currently
7+
//~| ERROR late-bound const parameter not allowed on closures
78
}

tests/ui/closures/binder/const-bound.stderr

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
error: late-bound const parameters cannot be used currently
2+
--> $DIR/const-bound.rs:5:15
3+
|
4+
LL | for<const N: i32> || -> () {};
5+
| ^
6+
17
warning: the feature `non_lifetime_binders` is incomplete and may not be safe to use and/or cause compiler crashes
28
--> $DIR/const-bound.rs:1:37
39
|
@@ -13,5 +19,5 @@ error: late-bound const parameter not allowed on closures
1319
LL | for<const N: i32> || -> () {};
1420
| ^^^^^^^^^^^^
1521

16-
error: aborting due to 1 previous error; 1 warning emitted
22+
error: aborting due to 2 previous errors; 1 warning emitted
1723

tests/ui/const-generics/generic_const_exprs/no-entry-found-for-key-ice-gce-nlb-113133.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
pub fn foo()
88
where
99
for<const N: usize = { const fn bar() {} bar(); 1 }> ():,
10-
//~^ ERROR defaults for generic parameters are not allowed in `for<...>` binders
10+
//~^ ERROR late-bound const parameters cannot be used currently
11+
//~| ERROR defaults for generic parameters are not allowed in `for<...>` binders
1112
{}
1213

1314
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1+
error: late-bound const parameters cannot be used currently
2+
--> $DIR/no-entry-found-for-key-ice-gce-nlb-113133.rs:9:15
3+
|
4+
LL | for<const N: usize = { const fn bar() {} bar(); 1 }> ():,
5+
| ^
6+
17
error: defaults for generic parameters are not allowed in `for<...>` binders
28
--> $DIR/no-entry-found-for-key-ice-gce-nlb-113133.rs:9:9
39
|
410
LL | for<const N: usize = { const fn bar() {} bar(); 1 }> ():,
511
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
612

7-
error: aborting due to 1 previous error
13+
error: aborting due to 2 previous errors
814

tests/ui/lto/debuginfo-lto-alloc.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
// that compilation is successful.
1010

1111
//@ check-pass
12-
//@ compile-flags: --test -C debuginfo=2 -C lto=fat -C incremental=inc-fat
12+
//@ compile-flags: --test -C debuginfo=2 -C lto=fat
13+
//@ incremental
1314

1415
extern crate alloc;
1516

tests/ui/pattern/usefulness/empty-types.min_exh_pats.stderr

+9
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ note: `Option<Void>` defined here
204204
|
205205
= note: not covered
206206
= note: the matched value is of type `Option<Void>`
207+
= note: `Void` is uninhabited but is not being matched by value, so a wildcard `_` is required
207208
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
208209
|
209210
LL ~ None => {},
@@ -349,6 +350,7 @@ LL | match slice_never {
349350
| ^^^^^^^^^^^ pattern `&[_, ..]` not covered
350351
|
351352
= note: the matched value is of type `&[!]`
353+
= note: `!` is uninhabited but is not being matched by value, so a wildcard `_` is required
352354
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
353355
|
354356
LL ~ [] => {},
@@ -484,6 +486,7 @@ note: `Option<!>` defined here
484486
|
485487
= note: not covered
486488
= note: the matched value is of type `&Option<!>`
489+
= note: `!` is uninhabited but is not being matched by value, so a wildcard `_` is required
487490
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
488491
|
489492
LL ~ &None => {},
@@ -502,6 +505,7 @@ note: `Option<!>` defined here
502505
|
503506
= note: not covered
504507
= note: the matched value is of type `Option<!>`
508+
= note: `!` is uninhabited but is not being matched by value, so a wildcard `_` is required
505509
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
506510
|
507511
LL ~ None => {},
@@ -520,6 +524,7 @@ note: `Result<!, !>` defined here
520524
|
521525
= note: not covered
522526
= note: the matched value is of type `Result<!, !>`
527+
= note: `!` is uninhabited but is not being matched by value, so a wildcard `_` is required
523528
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
524529
|
525530
LL ~ Ok(_) => {},
@@ -538,6 +543,7 @@ note: `Result<!, !>` defined here
538543
|
539544
= note: not covered
540545
= note: the matched value is of type `Result<!, !>`
546+
= note: `!` is uninhabited but is not being matched by value, so a wildcard `_` is required
541547
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
542548
|
543549
LL ~ Ok(_a) => {},
@@ -589,6 +595,7 @@ LL | match ref_never {
589595
| ^^^^^^^^^ pattern `&_` not covered
590596
|
591597
= note: the matched value is of type `&!`
598+
= note: `!` is uninhabited but is not being matched by value, so a wildcard `_` is required
592599
= note: references are always considered inhabited
593600
= note: match arms with guards don't count towards exhaustivity
594601
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
@@ -609,6 +616,7 @@ note: `Result<!, !>` defined here
609616
|
610617
= note: not covered
611618
= note: the matched value is of type `Result<!, !>`
619+
= note: `!` is uninhabited but is not being matched by value, so a wildcard `_` is required
612620
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
613621
|
614622
LL ~ Err(_) => {},
@@ -627,6 +635,7 @@ note: `Option<Result<!, !>>` defined here
627635
|
628636
= note: not covered
629637
= note: the matched value is of type `Option<Result<!, !>>`
638+
= note: `Result<!, !>` is uninhabited but is not being matched by value, so a wildcard `_` is required
630639
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
631640
|
632641
LL ~ None => {},

0 commit comments

Comments
 (0)