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 8 pull requests #106386

Merged
merged 24 commits into from
Jan 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
40916ef
Add notes and examples about non-intuitive `PathBuf::set_extension` b…
tbu- Dec 30, 2022
b7b252a
clean: Always store enum disriminant.
aDotInTheVoid Jan 1, 2023
cca5d21
Rustdoc-Json: Report discriminant on all kinds of enum variant.
aDotInTheVoid Jan 1, 2023
beefcf8
Cleanup `mingw-tidy` docker job
jyn514 Dec 31, 2022
3919b71
Fix rustdoc ICE on bad typedef with mismatching types
GuillaumeGomez Jan 2, 2023
e885356
Add regression test for #106226
GuillaumeGomez Jan 2, 2023
ed3c3d3
Add regression test for #105334
GuillaumeGomez Jan 2, 2023
1a94322
Add regression test for #105737
GuillaumeGomez Jan 2, 2023
a167435
Add regression test for #105742
GuillaumeGomez Jan 2, 2023
c156773
Add regression test for #96287
GuillaumeGomez Jan 2, 2023
693399f
Update books
rustbot Jan 2, 2023
fd59b62
Add PhantomData marker to Context to make Context !Send and !Sync
jihiggins Apr 12, 2022
257e766
Remove test of static Context
dtolnay Jan 2, 2023
e1787f5
Reduce HIR debug output
Noratrieb Dec 11, 2022
3c7c694
Document rustc_ast::Extern variants
Manishearth Jan 2, 2023
157211f
Document rustc_ast::FnHeader fields
Manishearth Jan 2, 2023
722bc0c
Rollup merge of #95985 - jihiggins:issue-66481, r=dtolnay
compiler-errors Jan 2, 2023
da1ca5d
Rollup merge of #104298 - tbu-:pr_set_extension_caveats, r=m-ou-se
compiler-errors Jan 2, 2023
fbffaa9
Rollup merge of #105558 - Nilstrieb:less-spam-hir-tree, r=cjgillot
compiler-errors Jan 2, 2023
0670a61
Rollup merge of #106315 - jyn514:cleanup-mingw-tidy, r=fee1-dead
compiler-errors Jan 2, 2023
0d5c5fa
Rollup merge of #106354 - aDotInTheVoid:rdj-always-discr, r=Guillaume…
compiler-errors Jan 2, 2023
ea3c4d8
Rollup merge of #106366 - GuillaumeGomez:fix-rustdoc-ice-typedef-type…
compiler-errors Jan 2, 2023
d112cd9
Rollup merge of #106376 - rustbot:docs-update, r=ehuss
compiler-errors Jan 2, 2023
d4cf00f
Rollup merge of #106383 - Manishearth:ast-docs, r=compiler-errors
compiler-errors Jan 2, 2023
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
15 changes: 15 additions & 0 deletions compiler/rustc_ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2743,8 +2743,19 @@ impl Item {
/// `extern` qualifier on a function item or function type.
#[derive(Clone, Copy, Encodable, Decodable, Debug)]
pub enum Extern {
/// No explicit extern keyword was used
///
/// E.g. `fn foo() {}`
None,
/// An explicit extern keyword was used, but with implicit ABI
///
/// E.g. `extern fn foo() {}`
///
/// This is just `extern "C"` (see `rustc_target::spec::abi::Abi::FALLBACK`)
Implicit(Span),
/// An explicit extern keyword was used with an explicit ABI
///
/// E.g. `extern "C" fn foo() {}`
Explicit(StrLit, Span),
}

Expand All @@ -2763,9 +2774,13 @@ impl Extern {
/// included in this struct (e.g., `async unsafe fn` or `const extern "C" fn`).
#[derive(Clone, Copy, Encodable, Decodable, Debug)]
pub struct FnHeader {
/// The `unsafe` keyword, if any
pub unsafety: Unsafe,
/// The `async` keyword, if any
pub asyncness: Async,
/// The `const` keyword, if any
pub constness: Const,
/// The `extern` keyword and corresponding ABI string, if any
pub ext: Extern,
}

Expand Down
9 changes: 8 additions & 1 deletion compiler/rustc_data_structures/src/sorted_map.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::stable_hasher::{HashStable, StableHasher, StableOrd};
use std::borrow::Borrow;
use std::cmp::Ordering;
use std::fmt::Debug;
use std::mem;
use std::ops::{Bound, Index, IndexMut, RangeBounds};

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

impl<K: Debug, V: Debug> Debug for SortedMap<K, V> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_map().entries(self.data.iter().map(|(a, b)| (a, b))).finish()
}
}

#[cfg(test)]
mod tests;
16 changes: 15 additions & 1 deletion compiler/rustc_hir/src/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,11 @@ impl fmt::Debug for OwnerNodes<'_> {
&self
.nodes
.iter_enumerated()
.map(|(id, parented_node)| (id, parented_node.as_ref().map(|node| node.parent)))
.map(|(id, parented_node)| {
let parented_node = parented_node.as_ref().map(|node| node.parent);

debug_fn(move |f| write!(f, "({id:?}, {parented_node:?})"))
})
.collect::<Vec<_>>(),
)
.field("bodies", &self.bodies)
Expand Down Expand Up @@ -3615,3 +3619,13 @@ mod size_asserts {
static_assert_size!(TyKind<'_>, 32);
// tidy-alphabetical-end
}

fn debug_fn(f: impl Fn(&mut fmt::Formatter<'_>) -> fmt::Result) -> impl fmt::Debug {
struct DebugFn<F>(F);
impl<F: Fn(&mut fmt::Formatter<'_>) -> fmt::Result> fmt::Debug for DebugFn<F> {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
(self.0)(fmt)
}
}
DebugFn(f)
}
21 changes: 18 additions & 3 deletions compiler/rustc_hir/src/hir_id.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
use crate::def_id::{DefId, DefIndex, LocalDefId, CRATE_DEF_ID};
use rustc_data_structures::stable_hasher::{HashStable, StableHasher, StableOrd, ToStableHashKey};
use rustc_span::{def_id::DefPathHash, HashStableContext};
use std::fmt;
use std::fmt::{self, Debug};

#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
#[derive(Encodable, Decodable)]
pub struct OwnerId {
pub def_id: LocalDefId,
}

impl Debug for OwnerId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// Example: DefId(0:1 ~ aa[7697]::{use#0})
Debug::fmt(&self.def_id, f)
}
}

impl From<OwnerId> for HirId {
fn from(owner: OwnerId) -> HirId {
HirId { owner, local_id: ItemLocalId::from_u32(0) }
Expand Down Expand Up @@ -60,14 +67,22 @@ impl<CTX: HashStableContext> ToStableHashKey<CTX> for OwnerId {
/// the `local_id` part of the `HirId` changing, which is a very useful property in
/// incremental compilation where we have to persist things through changes to
/// the code base.
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
#[derive(Encodable, Decodable, HashStable_Generic)]
#[rustc_pass_by_value]
pub struct HirId {
pub owner: OwnerId,
pub local_id: ItemLocalId,
}

impl Debug for HirId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// Example: HirId(DefId(0:1 ~ aa[7697]::{use#0}).10)
// Don't use debug_tuple to always keep this on one line.
write!(f, "HirId({:?}.{:?})", self.owner, self.local_id)
}
}

impl HirId {
/// Signal local id which should never be used.
pub const INVALID: HirId =
Expand Down
5 changes: 4 additions & 1 deletion library/core/src/task/wake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@ pub struct Context<'a> {
// are contravariant while return-position lifetimes are
// covariant).
_marker: PhantomData<fn(&'a ()) -> &'a ()>,
// Ensure `Context` is `!Send` and `!Sync` in order to allow
// for future `!Send` and / or `!Sync` fields.
_marker2: PhantomData<*mut ()>,
}

impl<'a> Context<'a> {
Expand All @@ -190,7 +193,7 @@ impl<'a> Context<'a> {
#[must_use]
#[inline]
pub const fn from_waker(waker: &'a Waker) -> Self {
Context { waker, _marker: PhantomData }
Context { waker, _marker: PhantomData, _marker2: PhantomData }
}

/// Returns a reference to the [`Waker`] for the current task.
Expand Down
8 changes: 2 additions & 6 deletions library/core/tests/task.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use core::task::{Context, Poll, RawWaker, RawWakerVTable, Waker};
use core::task::{Poll, RawWaker, RawWakerVTable, Waker};

#[test]
fn poll_const() {
Expand All @@ -21,9 +21,5 @@ fn waker_const() {

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

static CONTEXT: Context<'static> = Context::from_waker(&WAKER);

static WAKER_REF: &'static Waker = CONTEXT.waker();

WAKER_REF.wake_by_ref();
WAKER.wake_by_ref();
}
33 changes: 30 additions & 3 deletions library/std/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1414,14 +1414,29 @@ impl PathBuf {
self.push(file_name);
}

/// Updates [`self.extension`] to `extension`.
/// Updates [`self.extension`] to `Some(extension)` or to `None` if
/// `extension` is empty.
///
/// Returns `false` and does nothing if [`self.file_name`] is [`None`],
/// returns `true` and updates the extension otherwise.
///
/// If [`self.extension`] is [`None`], the extension is added; otherwise
/// it is replaced.
///
/// If `extension` is the empty string, [`self.extension`] will be [`None`]
/// afterwards, not `Some("")`.
///
/// # Caveats
///
/// The new `extension` may contain dots and will be used in its entirety,
/// but only the part after the final dot will be reflected in
/// [`self.extension`].
///
/// If the file stem contains internal dots and `extension` is empty, part
/// of the old file stem will be considered the new [`self.extension`].
///
/// See the examples below.
///
/// [`self.file_name`]: Path::file_name
/// [`self.extension`]: Path::extension
///
Expand All @@ -1435,8 +1450,20 @@ impl PathBuf {
/// p.set_extension("force");
/// assert_eq!(Path::new("/feel/the.force"), p.as_path());
///
/// p.set_extension("dark_side");
/// assert_eq!(Path::new("/feel/the.dark_side"), p.as_path());
/// p.set_extension("dark.side");
/// assert_eq!(Path::new("/feel/the.dark.side"), p.as_path());
///
/// p.set_extension("cookie");
/// assert_eq!(Path::new("/feel/the.dark.cookie"), p.as_path());
///
/// p.set_extension("");
/// assert_eq!(Path::new("/feel/the.dark"), p.as_path());
///
/// p.set_extension("");
/// assert_eq!(Path::new("/feel/the"), p.as_path());
///
/// p.set_extension("");
/// assert_eq!(Path::new("/feel/the"), p.as_path());
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn set_extension<S: AsRef<OsStr>>(&mut self, extension: S) -> bool {
Expand Down
1 change: 0 additions & 1 deletion src/ci/docker/host-x86_64/mingw-check-tidy/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,4 @@ RUN pip3 install --no-deps --no-cache-dir --require-hashes -r /tmp/reuse-require
COPY host-x86_64/mingw-check/validate-toolstate.sh /scripts/
COPY host-x86_64/mingw-check/validate-error-codes.sh /scripts/

ENV RUN_CHECK_WITH_PARALLEL_QUERIES 1
ENV SCRIPT python3 ../x.py test --stage 0 src/tools/tidy tidyselftest
4 changes: 2 additions & 2 deletions src/ci/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,11 @@ if [ "$RUN_CHECK_WITH_PARALLEL_QUERIES" != "" ]; then
$SRC/configure --set rust.parallel-compiler

# Save the build metrics before we wipe the directory
if [ $HAS_METRICS = 1 ]; then
if [ "$HAS_METRICS" = 1 ]; then
mv build/metrics.json .
fi
rm -rf build
if [ $HAS_METRICS = 1 ]; then
if [ "$HAS_METRICS" = 1 ]; then
mkdir build
mv metrics.json build
fi
Expand Down
2 changes: 1 addition & 1 deletion src/doc/nomicon
Submodule nomicon updated 1 files
+2 −1 src/ffi.md
44 changes: 28 additions & 16 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1853,7 +1853,7 @@ pub(crate) fn clean_middle_ty<'tcx>(
ty::Placeholder(..) => panic!("Placeholder"),
ty::GeneratorWitness(..) => panic!("GeneratorWitness"),
ty::Infer(..) => panic!("Infer"),
ty::Error(_) => panic!("Error"),
ty::Error(_) => rustc_errors::FatalError.raise(),
}
}

Expand Down Expand Up @@ -1949,40 +1949,52 @@ pub(crate) fn clean_field_with_def_id(
}

pub(crate) fn clean_variant_def<'tcx>(variant: &ty::VariantDef, cx: &mut DocContext<'tcx>) -> Item {
let discriminant = match variant.discr {
ty::VariantDiscr::Explicit(def_id) => Some(Discriminant { expr: None, value: def_id }),
ty::VariantDiscr::Relative(_) => None,
};

let kind = match variant.ctor_kind() {
Some(CtorKind::Const) => Variant::CLike(match variant.discr {
ty::VariantDiscr::Explicit(def_id) => Some(Discriminant { expr: None, value: def_id }),
ty::VariantDiscr::Relative(_) => None,
}),
Some(CtorKind::Fn) => Variant::Tuple(
Some(CtorKind::Const) => VariantKind::CLike,
Some(CtorKind::Fn) => VariantKind::Tuple(
variant.fields.iter().map(|field| clean_middle_field(field, cx)).collect(),
),
None => Variant::Struct(VariantStruct {
None => VariantKind::Struct(VariantStruct {
ctor_kind: None,
fields: variant.fields.iter().map(|field| clean_middle_field(field, cx)).collect(),
}),
};
Item::from_def_id_and_parts(variant.def_id, Some(variant.name), VariantItem(kind), cx)

Item::from_def_id_and_parts(
variant.def_id,
Some(variant.name),
VariantItem(Variant { kind, discriminant }),
cx,
)
}

fn clean_variant_data<'tcx>(
variant: &hir::VariantData<'tcx>,
disr_expr: &Option<hir::AnonConst>,
cx: &mut DocContext<'tcx>,
) -> Variant {
match variant {
hir::VariantData::Struct(..) => Variant::Struct(VariantStruct {
let discriminant = disr_expr.map(|disr| Discriminant {
expr: Some(disr.body),
value: cx.tcx.hir().local_def_id(disr.hir_id).to_def_id(),
});

let kind = match variant {
hir::VariantData::Struct(..) => VariantKind::Struct(VariantStruct {
ctor_kind: None,
fields: variant.fields().iter().map(|x| clean_field(x, cx)).collect(),
}),
hir::VariantData::Tuple(..) => {
Variant::Tuple(variant.fields().iter().map(|x| clean_field(x, cx)).collect())
VariantKind::Tuple(variant.fields().iter().map(|x| clean_field(x, cx)).collect())
}
hir::VariantData::Unit(..) => Variant::CLike(disr_expr.map(|disr| Discriminant {
expr: Some(disr.body),
value: cx.tcx.hir().local_def_id(disr.hir_id).to_def_id(),
})),
}
hir::VariantData::Unit(..) => VariantKind::CLike,
};

Variant { discriminant, kind }
}

fn clean_path<'tcx>(path: &hir::Path<'tcx>, cx: &mut DocContext<'tcx>) -> Path {
Expand Down
24 changes: 16 additions & 8 deletions src/librustdoc/clean/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -807,8 +807,11 @@ impl ItemKind {
match self {
StructItem(s) => s.fields.iter(),
UnionItem(u) => u.fields.iter(),
VariantItem(Variant::Struct(v)) => v.fields.iter(),
VariantItem(Variant::Tuple(v)) => v.iter(),
VariantItem(v) => match &v.kind {
VariantKind::CLike => [].iter(),
VariantKind::Tuple(t) => t.iter(),
VariantKind::Struct(s) => s.fields.iter(),
},
EnumItem(e) => e.variants.iter(),
TraitItem(t) => t.items.iter(),
ImplItem(i) => i.items.iter(),
Expand All @@ -824,7 +827,6 @@ impl ItemKind {
| TyMethodItem(_)
| MethodItem(_, _)
| StructFieldItem(_)
| VariantItem(_)
| ForeignFunctionItem(_)
| ForeignStaticItem(_)
| ForeignTypeItem
Expand Down Expand Up @@ -2136,17 +2138,23 @@ impl Enum {
}

#[derive(Clone, Debug)]
pub(crate) enum Variant {
CLike(Option<Discriminant>),
pub(crate) struct Variant {
pub kind: VariantKind,
pub discriminant: Option<Discriminant>,
}

#[derive(Clone, Debug)]
pub(crate) enum VariantKind {
CLike,
Tuple(Vec<Item>),
Struct(VariantStruct),
}

impl Variant {
pub(crate) fn has_stripped_entries(&self) -> Option<bool> {
match *self {
Self::Struct(ref struct_) => Some(struct_.has_stripped_entries()),
Self::CLike(..) | Self::Tuple(_) => None,
match &self.kind {
VariantKind::Struct(struct_) => Some(struct_.has_stripped_entries()),
VariantKind::CLike | VariantKind::Tuple(_) => None,
}
}
}
Expand Down
Loading