Skip to content

Commit 481c9ba

Browse files
committed
Auto merge of #106386 - compiler-errors:rollup-dxjv18b, r=compiler-errors
Rollup of 8 pull requests Successful merges: - #95985 (Add PhantomData marker to Context to make Context !Send and !Sync) - #104298 (Add notes and examples about non-intuitive `PathBuf::set_extension` behavior) - #105558 (Reduce HIR debug output) - #106315 (Cleanup `mingw-tidy` docker job) - #106354 (Rustdoc-Json: Report discriminant on all kinds of enum variant.) - #106366 (Fix rustdoc ICE on bad typedef with mismatching types) - #106376 (Update books) - #106383 (Document some of the AST nodes) Failed merges: - #106356 (clean: Remove `ctor_kind` from `VariantStruct`.) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 67d1617 + d4cf00f commit 481c9ba

Some content is hidden

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

46 files changed

+853
-230
lines changed

compiler/rustc_ast/src/ast.rs

+15
Original file line numberDiff line numberDiff line change
@@ -2743,8 +2743,19 @@ impl Item {
27432743
/// `extern` qualifier on a function item or function type.
27442744
#[derive(Clone, Copy, Encodable, Decodable, Debug)]
27452745
pub enum Extern {
2746+
/// No explicit extern keyword was used
2747+
///
2748+
/// E.g. `fn foo() {}`
27462749
None,
2750+
/// An explicit extern keyword was used, but with implicit ABI
2751+
///
2752+
/// E.g. `extern fn foo() {}`
2753+
///
2754+
/// This is just `extern "C"` (see `rustc_target::spec::abi::Abi::FALLBACK`)
27472755
Implicit(Span),
2756+
/// An explicit extern keyword was used with an explicit ABI
2757+
///
2758+
/// E.g. `extern "C" fn foo() {}`
27482759
Explicit(StrLit, Span),
27492760
}
27502761

@@ -2763,9 +2774,13 @@ impl Extern {
27632774
/// included in this struct (e.g., `async unsafe fn` or `const extern "C" fn`).
27642775
#[derive(Clone, Copy, Encodable, Decodable, Debug)]
27652776
pub struct FnHeader {
2777+
/// The `unsafe` keyword, if any
27662778
pub unsafety: Unsafe,
2779+
/// The `async` keyword, if any
27672780
pub asyncness: Async,
2781+
/// The `const` keyword, if any
27682782
pub constness: Const,
2783+
/// The `extern` keyword and corresponding ABI string, if any
27692784
pub ext: Extern,
27702785
}
27712786

compiler/rustc_data_structures/src/sorted_map.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::stable_hasher::{HashStable, StableHasher, StableOrd};
22
use std::borrow::Borrow;
33
use std::cmp::Ordering;
4+
use std::fmt::Debug;
45
use std::mem;
56
use std::ops::{Bound, Index, IndexMut, RangeBounds};
67

@@ -16,7 +17,7 @@ pub use index_map::SortedIndexMultiMap;
1617
/// stores data in a more compact way. It also supports accessing contiguous
1718
/// ranges of elements as a slice, and slices of already sorted elements can be
1819
/// inserted efficiently.
19-
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Encodable, Decodable)]
20+
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Encodable, Decodable)]
2021
pub struct SortedMap<K, V> {
2122
data: Vec<(K, V)>,
2223
}
@@ -314,5 +315,11 @@ impl<K: HashStable<CTX> + StableOrd, V: HashStable<CTX>, CTX> HashStable<CTX> fo
314315
}
315316
}
316317

318+
impl<K: Debug, V: Debug> Debug for SortedMap<K, V> {
319+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
320+
f.debug_map().entries(self.data.iter().map(|(a, b)| (a, b))).finish()
321+
}
322+
}
323+
317324
#[cfg(test)]
318325
mod tests;

compiler/rustc_hir/src/hir.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -854,7 +854,11 @@ impl fmt::Debug for OwnerNodes<'_> {
854854
&self
855855
.nodes
856856
.iter_enumerated()
857-
.map(|(id, parented_node)| (id, parented_node.as_ref().map(|node| node.parent)))
857+
.map(|(id, parented_node)| {
858+
let parented_node = parented_node.as_ref().map(|node| node.parent);
859+
860+
debug_fn(move |f| write!(f, "({id:?}, {parented_node:?})"))
861+
})
858862
.collect::<Vec<_>>(),
859863
)
860864
.field("bodies", &self.bodies)
@@ -3615,3 +3619,13 @@ mod size_asserts {
36153619
static_assert_size!(TyKind<'_>, 32);
36163620
// tidy-alphabetical-end
36173621
}
3622+
3623+
fn debug_fn(f: impl Fn(&mut fmt::Formatter<'_>) -> fmt::Result) -> impl fmt::Debug {
3624+
struct DebugFn<F>(F);
3625+
impl<F: Fn(&mut fmt::Formatter<'_>) -> fmt::Result> fmt::Debug for DebugFn<F> {
3626+
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
3627+
(self.0)(fmt)
3628+
}
3629+
}
3630+
DebugFn(f)
3631+
}

compiler/rustc_hir/src/hir_id.rs

+18-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
use crate::def_id::{DefId, DefIndex, LocalDefId, CRATE_DEF_ID};
22
use rustc_data_structures::stable_hasher::{HashStable, StableHasher, StableOrd, ToStableHashKey};
33
use rustc_span::{def_id::DefPathHash, HashStableContext};
4-
use std::fmt;
4+
use std::fmt::{self, Debug};
55

6-
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
6+
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
77
#[derive(Encodable, Decodable)]
88
pub struct OwnerId {
99
pub def_id: LocalDefId,
1010
}
1111

12+
impl Debug for OwnerId {
13+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
14+
// Example: DefId(0:1 ~ aa[7697]::{use#0})
15+
Debug::fmt(&self.def_id, f)
16+
}
17+
}
18+
1219
impl From<OwnerId> for HirId {
1320
fn from(owner: OwnerId) -> HirId {
1421
HirId { owner, local_id: ItemLocalId::from_u32(0) }
@@ -60,14 +67,22 @@ impl<CTX: HashStableContext> ToStableHashKey<CTX> for OwnerId {
6067
/// the `local_id` part of the `HirId` changing, which is a very useful property in
6168
/// incremental compilation where we have to persist things through changes to
6269
/// the code base.
63-
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
70+
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
6471
#[derive(Encodable, Decodable, HashStable_Generic)]
6572
#[rustc_pass_by_value]
6673
pub struct HirId {
6774
pub owner: OwnerId,
6875
pub local_id: ItemLocalId,
6976
}
7077

78+
impl Debug for HirId {
79+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
80+
// Example: HirId(DefId(0:1 ~ aa[7697]::{use#0}).10)
81+
// Don't use debug_tuple to always keep this on one line.
82+
write!(f, "HirId({:?}.{:?})", self.owner, self.local_id)
83+
}
84+
}
85+
7186
impl HirId {
7287
/// Signal local id which should never be used.
7388
pub const INVALID: HirId =

library/core/src/task/wake.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,9 @@ pub struct Context<'a> {
181181
// are contravariant while return-position lifetimes are
182182
// covariant).
183183
_marker: PhantomData<fn(&'a ()) -> &'a ()>,
184+
// Ensure `Context` is `!Send` and `!Sync` in order to allow
185+
// for future `!Send` and / or `!Sync` fields.
186+
_marker2: PhantomData<*mut ()>,
184187
}
185188

186189
impl<'a> Context<'a> {
@@ -190,7 +193,7 @@ impl<'a> Context<'a> {
190193
#[must_use]
191194
#[inline]
192195
pub const fn from_waker(waker: &'a Waker) -> Self {
193-
Context { waker, _marker: PhantomData }
196+
Context { waker, _marker: PhantomData, _marker2: PhantomData }
194197
}
195198

196199
/// Returns a reference to the [`Waker`] for the current task.

library/core/tests/task.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use core::task::{Context, Poll, RawWaker, RawWakerVTable, Waker};
1+
use core::task::{Poll, RawWaker, RawWakerVTable, Waker};
22

33
#[test]
44
fn poll_const() {
@@ -21,9 +21,5 @@ fn waker_const() {
2121

2222
static WAKER: Waker = unsafe { Waker::from_raw(VOID_WAKER) };
2323

24-
static CONTEXT: Context<'static> = Context::from_waker(&WAKER);
25-
26-
static WAKER_REF: &'static Waker = CONTEXT.waker();
27-
28-
WAKER_REF.wake_by_ref();
24+
WAKER.wake_by_ref();
2925
}

library/std/src/path.rs

+30-3
Original file line numberDiff line numberDiff line change
@@ -1414,14 +1414,29 @@ impl PathBuf {
14141414
self.push(file_name);
14151415
}
14161416

1417-
/// Updates [`self.extension`] to `extension`.
1417+
/// Updates [`self.extension`] to `Some(extension)` or to `None` if
1418+
/// `extension` is empty.
14181419
///
14191420
/// Returns `false` and does nothing if [`self.file_name`] is [`None`],
14201421
/// returns `true` and updates the extension otherwise.
14211422
///
14221423
/// If [`self.extension`] is [`None`], the extension is added; otherwise
14231424
/// it is replaced.
14241425
///
1426+
/// If `extension` is the empty string, [`self.extension`] will be [`None`]
1427+
/// afterwards, not `Some("")`.
1428+
///
1429+
/// # Caveats
1430+
///
1431+
/// The new `extension` may contain dots and will be used in its entirety,
1432+
/// but only the part after the final dot will be reflected in
1433+
/// [`self.extension`].
1434+
///
1435+
/// If the file stem contains internal dots and `extension` is empty, part
1436+
/// of the old file stem will be considered the new [`self.extension`].
1437+
///
1438+
/// See the examples below.
1439+
///
14251440
/// [`self.file_name`]: Path::file_name
14261441
/// [`self.extension`]: Path::extension
14271442
///
@@ -1435,8 +1450,20 @@ impl PathBuf {
14351450
/// p.set_extension("force");
14361451
/// assert_eq!(Path::new("/feel/the.force"), p.as_path());
14371452
///
1438-
/// p.set_extension("dark_side");
1439-
/// assert_eq!(Path::new("/feel/the.dark_side"), p.as_path());
1453+
/// p.set_extension("dark.side");
1454+
/// assert_eq!(Path::new("/feel/the.dark.side"), p.as_path());
1455+
///
1456+
/// p.set_extension("cookie");
1457+
/// assert_eq!(Path::new("/feel/the.dark.cookie"), p.as_path());
1458+
///
1459+
/// p.set_extension("");
1460+
/// assert_eq!(Path::new("/feel/the.dark"), p.as_path());
1461+
///
1462+
/// p.set_extension("");
1463+
/// assert_eq!(Path::new("/feel/the"), p.as_path());
1464+
///
1465+
/// p.set_extension("");
1466+
/// assert_eq!(Path::new("/feel/the"), p.as_path());
14401467
/// ```
14411468
#[stable(feature = "rust1", since = "1.0.0")]
14421469
pub fn set_extension<S: AsRef<OsStr>>(&mut self, extension: S) -> bool {

src/ci/docker/host-x86_64/mingw-check-tidy/Dockerfile

-1
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,4 @@ RUN pip3 install --no-deps --no-cache-dir --require-hashes -r /tmp/reuse-require
3232
COPY host-x86_64/mingw-check/validate-toolstate.sh /scripts/
3333
COPY host-x86_64/mingw-check/validate-error-codes.sh /scripts/
3434

35-
ENV RUN_CHECK_WITH_PARALLEL_QUERIES 1
3635
ENV SCRIPT python3 ../x.py test --stage 0 src/tools/tidy tidyselftest

src/ci/run.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -184,11 +184,11 @@ if [ "$RUN_CHECK_WITH_PARALLEL_QUERIES" != "" ]; then
184184
$SRC/configure --set rust.parallel-compiler
185185

186186
# Save the build metrics before we wipe the directory
187-
if [ $HAS_METRICS = 1 ]; then
187+
if [ "$HAS_METRICS" = 1 ]; then
188188
mv build/metrics.json .
189189
fi
190190
rm -rf build
191-
if [ $HAS_METRICS = 1 ]; then
191+
if [ "$HAS_METRICS" = 1 ]; then
192192
mkdir build
193193
mv metrics.json build
194194
fi

src/doc/nomicon

Submodule nomicon updated 1 file

src/librustdoc/clean/mod.rs

+28-16
Original file line numberDiff line numberDiff line change
@@ -1853,7 +1853,7 @@ pub(crate) fn clean_middle_ty<'tcx>(
18531853
ty::Placeholder(..) => panic!("Placeholder"),
18541854
ty::GeneratorWitness(..) => panic!("GeneratorWitness"),
18551855
ty::Infer(..) => panic!("Infer"),
1856-
ty::Error(_) => panic!("Error"),
1856+
ty::Error(_) => rustc_errors::FatalError.raise(),
18571857
}
18581858
}
18591859

@@ -1949,40 +1949,52 @@ pub(crate) fn clean_field_with_def_id(
19491949
}
19501950

19511951
pub(crate) fn clean_variant_def<'tcx>(variant: &ty::VariantDef, cx: &mut DocContext<'tcx>) -> Item {
1952+
let discriminant = match variant.discr {
1953+
ty::VariantDiscr::Explicit(def_id) => Some(Discriminant { expr: None, value: def_id }),
1954+
ty::VariantDiscr::Relative(_) => None,
1955+
};
1956+
19521957
let kind = match variant.ctor_kind() {
1953-
Some(CtorKind::Const) => Variant::CLike(match variant.discr {
1954-
ty::VariantDiscr::Explicit(def_id) => Some(Discriminant { expr: None, value: def_id }),
1955-
ty::VariantDiscr::Relative(_) => None,
1956-
}),
1957-
Some(CtorKind::Fn) => Variant::Tuple(
1958+
Some(CtorKind::Const) => VariantKind::CLike,
1959+
Some(CtorKind::Fn) => VariantKind::Tuple(
19581960
variant.fields.iter().map(|field| clean_middle_field(field, cx)).collect(),
19591961
),
1960-
None => Variant::Struct(VariantStruct {
1962+
None => VariantKind::Struct(VariantStruct {
19611963
ctor_kind: None,
19621964
fields: variant.fields.iter().map(|field| clean_middle_field(field, cx)).collect(),
19631965
}),
19641966
};
1965-
Item::from_def_id_and_parts(variant.def_id, Some(variant.name), VariantItem(kind), cx)
1967+
1968+
Item::from_def_id_and_parts(
1969+
variant.def_id,
1970+
Some(variant.name),
1971+
VariantItem(Variant { kind, discriminant }),
1972+
cx,
1973+
)
19661974
}
19671975

19681976
fn clean_variant_data<'tcx>(
19691977
variant: &hir::VariantData<'tcx>,
19701978
disr_expr: &Option<hir::AnonConst>,
19711979
cx: &mut DocContext<'tcx>,
19721980
) -> Variant {
1973-
match variant {
1974-
hir::VariantData::Struct(..) => Variant::Struct(VariantStruct {
1981+
let discriminant = disr_expr.map(|disr| Discriminant {
1982+
expr: Some(disr.body),
1983+
value: cx.tcx.hir().local_def_id(disr.hir_id).to_def_id(),
1984+
});
1985+
1986+
let kind = match variant {
1987+
hir::VariantData::Struct(..) => VariantKind::Struct(VariantStruct {
19751988
ctor_kind: None,
19761989
fields: variant.fields().iter().map(|x| clean_field(x, cx)).collect(),
19771990
}),
19781991
hir::VariantData::Tuple(..) => {
1979-
Variant::Tuple(variant.fields().iter().map(|x| clean_field(x, cx)).collect())
1992+
VariantKind::Tuple(variant.fields().iter().map(|x| clean_field(x, cx)).collect())
19801993
}
1981-
hir::VariantData::Unit(..) => Variant::CLike(disr_expr.map(|disr| Discriminant {
1982-
expr: Some(disr.body),
1983-
value: cx.tcx.hir().local_def_id(disr.hir_id).to_def_id(),
1984-
})),
1985-
}
1994+
hir::VariantData::Unit(..) => VariantKind::CLike,
1995+
};
1996+
1997+
Variant { discriminant, kind }
19861998
}
19871999

19882000
fn clean_path<'tcx>(path: &hir::Path<'tcx>, cx: &mut DocContext<'tcx>) -> Path {

src/librustdoc/clean/types.rs

+16-8
Original file line numberDiff line numberDiff line change
@@ -807,8 +807,11 @@ impl ItemKind {
807807
match self {
808808
StructItem(s) => s.fields.iter(),
809809
UnionItem(u) => u.fields.iter(),
810-
VariantItem(Variant::Struct(v)) => v.fields.iter(),
811-
VariantItem(Variant::Tuple(v)) => v.iter(),
810+
VariantItem(v) => match &v.kind {
811+
VariantKind::CLike => [].iter(),
812+
VariantKind::Tuple(t) => t.iter(),
813+
VariantKind::Struct(s) => s.fields.iter(),
814+
},
812815
EnumItem(e) => e.variants.iter(),
813816
TraitItem(t) => t.items.iter(),
814817
ImplItem(i) => i.items.iter(),
@@ -824,7 +827,6 @@ impl ItemKind {
824827
| TyMethodItem(_)
825828
| MethodItem(_, _)
826829
| StructFieldItem(_)
827-
| VariantItem(_)
828830
| ForeignFunctionItem(_)
829831
| ForeignStaticItem(_)
830832
| ForeignTypeItem
@@ -2136,17 +2138,23 @@ impl Enum {
21362138
}
21372139

21382140
#[derive(Clone, Debug)]
2139-
pub(crate) enum Variant {
2140-
CLike(Option<Discriminant>),
2141+
pub(crate) struct Variant {
2142+
pub kind: VariantKind,
2143+
pub discriminant: Option<Discriminant>,
2144+
}
2145+
2146+
#[derive(Clone, Debug)]
2147+
pub(crate) enum VariantKind {
2148+
CLike,
21412149
Tuple(Vec<Item>),
21422150
Struct(VariantStruct),
21432151
}
21442152

21452153
impl Variant {
21462154
pub(crate) fn has_stripped_entries(&self) -> Option<bool> {
2147-
match *self {
2148-
Self::Struct(ref struct_) => Some(struct_.has_stripped_entries()),
2149-
Self::CLike(..) | Self::Tuple(_) => None,
2155+
match &self.kind {
2156+
VariantKind::Struct(struct_) => Some(struct_.has_stripped_entries()),
2157+
VariantKind::CLike | VariantKind::Tuple(_) => None,
21502158
}
21512159
}
21522160
}

0 commit comments

Comments
 (0)