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 #129900

Closed
wants to merge 32 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
102997a
Update Tests
veera-sivarajan Jul 13, 2024
764675e
Add Tests
veera-sivarajan Aug 6, 2024
f003e92
Don't Suggest Labeling `const` and `unsafe` Blocks
veera-sivarajan Aug 6, 2024
9a29081
call `Cargo::configure_linker` only for specific commands
onur-ozkan Aug 9, 2024
94fbe14
don't try to find target tools on certain commands
onur-ozkan Aug 9, 2024
12de141
Suggest `impl Trait` for References to Bare Trait in Function Header
veera-sivarajan Jul 13, 2024
28dc116
Don't ICE when dumping MIR of a synthetic coroutine body
compiler-errors Aug 28, 2024
8d3945d
Rename dump of coroutine by-move-body to be more consistent, adjust test
compiler-errors Aug 28, 2024
98106cf
Re-parent the by-move body
compiler-errors Aug 28, 2024
9ad8e26
rustdoc: use `LocalDefId` for inline stmt
notriddle Aug 30, 2024
a3127ca
rustdoc: use a single box to store Attributes and ItemKind
notriddle Aug 30, 2024
121e9f4
Add rust.randomize-layout config to build artifacts with -Zrandomize-…
the8472 Sep 2, 2022
f3bc08a
ignore/fix layout-sensitive tests
the8472 Sep 2, 2022
5bf8eeb
disable size asserts in the compiler when randomizing layouts
the8472 Sep 2, 2022
e3169f7
when -Zrandomize-layout is enabled disable alloc test testing interna…
the8472 Sep 2, 2022
1e377c5
enable layout randomization in x86_64-gnu-llvm-17 CI job
the8472 Sep 2, 2022
df20808
inhibit layout randomization for Box
the8472 Aug 31, 2024
c218c75
exclude tools with deps that have size asserts
the8472 Aug 31, 2024
a763f96
Pin memchr to 2.5.0 in the library rather than rustc_ast
tgross35 Aug 26, 2024
dcbe15c
Run `cargo update` in the root, library, and rustbook
tgross35 Aug 26, 2024
a57c399
Adjust allowed dependencies from the latest `cargo update`
tgross35 Aug 26, 2024
f8739f0
Port std library to RTEMS
thesummer Aug 21, 2023
55f3b01
rtems: Add spec file for arm_rtems6_eabihf
thesummer Jan 23, 2024
01b57cb
Add documentation for target armv7-rtems-eabihf
thesummer Jun 26, 2024
17f5098
Rollup merge of #101339 - the8472:ci-randomize-debug, r=Mark-Simulacrum
matthiaskrgr Sep 2, 2024
44a2b5e
Rollup merge of #127021 - thesummer:1-add-target-support-for-rtems-ar…
matthiaskrgr Sep 2, 2024
b409db4
Rollup merge of #127692 - veera-sivarajan:bugfix-125139, r=estebank
matthiaskrgr Sep 2, 2024
31e63ea
Rollup merge of #128701 - veera-sivarajan:fix-128604, r=estebank
matthiaskrgr Sep 2, 2024
5416804
Rollup merge of #128871 - onur-ozkan:128180, r=Kobzol
matthiaskrgr Sep 2, 2024
4841c83
Rollup merge of #129624 - tgross35:cargo-update, r=Mark-Simulacrum
matthiaskrgr Sep 2, 2024
9cf4d3c
Rollup merge of #129706 - compiler-errors:scratch, r=estebank
matthiaskrgr Sep 2, 2024
9b2775a
Rollup merge of #129789 - notriddle:notriddle/inline-stmt-local, r=Gu…
matthiaskrgr Sep 2, 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
Prev Previous commit
Next Next commit
rustdoc: use a single box to store Attributes and ItemKind
  • Loading branch information
notriddle committed Aug 30, 2024
commit a3127ca721620a1a276d98942d4db266c54b3add
22 changes: 12 additions & 10 deletions src/librustdoc/clean/auto_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,17 +114,19 @@ fn synthesize_auto_trait_impl<'tcx>(

Some(clean::Item {
name: None,
attrs: Default::default(),
inner: Box::new(clean::ItemInner {
attrs: Default::default(),
kind: clean::ImplItem(Box::new(clean::Impl {
safety: hir::Safety::Safe,
generics,
trait_: Some(clean_trait_ref_with_constraints(cx, trait_ref, ThinVec::new())),
for_: clean_middle_ty(ty::Binder::dummy(ty), cx, None, None),
items: Vec::new(),
polarity,
kind: clean::ImplKind::Auto,
})),
}),
item_id: clean::ItemId::Auto { trait_: trait_def_id, for_: item_def_id },
kind: Box::new(clean::ImplItem(Box::new(clean::Impl {
safety: hir::Safety::Safe,
generics,
trait_: Some(clean_trait_ref_with_constraints(cx, trait_ref, ThinVec::new())),
for_: clean_middle_ty(ty::Binder::dummy(ty), cx, None, None),
items: Vec::new(),
polarity,
kind: clean::ImplKind::Auto,
}))),
cfg: None,
inline_stmt_id: None,
})
Expand Down
72 changes: 37 additions & 35 deletions src/librustdoc/clean/blanket_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,42 +83,44 @@ pub(crate) fn synthesize_blanket_impls(

blanket_impls.push(clean::Item {
name: None,
attrs: Default::default(),
item_id: clean::ItemId::Blanket { impl_id: impl_def_id, for_: item_def_id },
kind: Box::new(clean::ImplItem(Box::new(clean::Impl {
safety: hir::Safety::Safe,
generics: clean_ty_generics(
cx,
tcx.generics_of(impl_def_id),
tcx.explicit_predicates_of(impl_def_id),
),
// FIXME(eddyb) compute both `trait_` and `for_` from
// the post-inference `trait_ref`, as it's more accurate.
trait_: Some(clean_trait_ref_with_constraints(
cx,
ty::Binder::dummy(trait_ref.instantiate_identity()),
ThinVec::new(),
)),
for_: clean_middle_ty(
ty::Binder::dummy(ty.instantiate_identity()),
cx,
None,
None,
),
items: tcx
.associated_items(impl_def_id)
.in_definition_order()
.filter(|item| !item.is_impl_trait_in_trait())
.map(|item| clean_middle_assoc_item(item, cx))
.collect(),
polarity: ty::ImplPolarity::Positive,
kind: clean::ImplKind::Blanket(Box::new(clean_middle_ty(
ty::Binder::dummy(trait_ref.instantiate_identity().self_ty()),
cx,
None,
None,
))),
}))),
inner: Box::new(clean::ItemInner {
attrs: Default::default(),
kind: clean::ImplItem(Box::new(clean::Impl {
safety: hir::Safety::Safe,
generics: clean_ty_generics(
cx,
tcx.generics_of(impl_def_id),
tcx.explicit_predicates_of(impl_def_id),
),
// FIXME(eddyb) compute both `trait_` and `for_` from
// the post-inference `trait_ref`, as it's more accurate.
trait_: Some(clean_trait_ref_with_constraints(
cx,
ty::Binder::dummy(trait_ref.instantiate_identity()),
ThinVec::new(),
)),
for_: clean_middle_ty(
ty::Binder::dummy(ty.instantiate_identity()),
cx,
None,
None,
),
items: tcx
.associated_items(impl_def_id)
.in_definition_order()
.filter(|item| !item.is_impl_trait_in_trait())
.map(|item| clean_middle_assoc_item(item, cx))
.collect(),
polarity: ty::ImplPolarity::Positive,
kind: clean::ImplKind::Blanket(Box::new(clean_middle_ty(
ty::Binder::dummy(trait_ref.instantiate_identity().self_ty()),
cx,
None,
None,
))),
})),
}),
cfg: None,
inline_stmt_id: None,
});
Expand Down
51 changes: 24 additions & 27 deletions src/librustdoc/clean/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,8 @@ pub(crate) fn try_inline(
};

cx.inlined.insert(did.into());
let mut item = crate::clean::generate_item_with_correct_attrs(
cx,
kind,
did,
name,
import_def_id,
None,
);
let mut item =
crate::clean::generate_item_with_correct_attrs(cx, kind, did, name, import_def_id, None);
// The visibility needs to reflect the one from the reexport and not from the "source" DefId.
item.inline_stmt_id = import_def_id;
ret.push(item);
Expand Down Expand Up @@ -622,7 +616,7 @@ pub(crate) fn build_impl(
ImplKind::Normal
},
})),
Box::new(merged_attrs),
merged_attrs,
cfg,
));
}
Expand Down Expand Up @@ -672,27 +666,29 @@ fn build_module_items(
let prim_ty = clean::PrimitiveType::from(p);
items.push(clean::Item {
name: None,
attrs: Box::default(),
// We can use the item's `DefId` directly since the only information ever used
// from it is `DefId.krate`.
item_id: ItemId::DefId(did),
kind: Box::new(clean::ImportItem(clean::Import::new_simple(
item.ident.name,
clean::ImportSource {
path: clean::Path {
res,
segments: thin_vec![clean::PathSegment {
name: prim_ty.as_sym(),
args: clean::GenericArgs::AngleBracketed {
args: Default::default(),
constraints: ThinVec::new(),
},
}],
inner: Box::new(clean::ItemInner {
attrs: Default::default(),
kind: clean::ImportItem(clean::Import::new_simple(
item.ident.name,
clean::ImportSource {
path: clean::Path {
res,
segments: thin_vec![clean::PathSegment {
name: prim_ty.as_sym(),
args: clean::GenericArgs::AngleBracketed {
args: Default::default(),
constraints: ThinVec::new(),
},
}],
},
did: None,
},
did: None,
},
true,
))),
true,
)),
}),
cfg: None,
inline_stmt_id: None,
});
Expand Down Expand Up @@ -752,7 +748,8 @@ fn build_macro(
LoadedMacro::MacroDef(item_def, _) => match macro_kind {
MacroKind::Bang => {
if let ast::ItemKind::MacroDef(ref def) = item_def.kind {
let vis = cx.tcx.visibility(import_def_id.map(|d| d.to_def_id()).unwrap_or(def_id));
let vis =
cx.tcx.visibility(import_def_id.map(|d| d.to_def_id()).unwrap_or(def_id));
clean::MacroItem(clean::Macro {
source: utils::display_macro_source(
cx,
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ fn generate_item_with_correct_attrs(
let attrs = Attributes::from_ast_iter(attrs.iter().map(|(attr, did)| (&**attr, *did)), false);

let name = renamed.or(Some(name));
let mut item = Item::from_def_id_and_attrs_and_parts(def_id, name, kind, Box::new(attrs), cfg);
let mut item = Item::from_def_id_and_attrs_and_parts(def_id, name, kind, attrs, cfg);
item.inline_stmt_id = import_id;
item
}
Expand Down
55 changes: 33 additions & 22 deletions src/librustdoc/clean/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,10 +319,7 @@ pub(crate) struct Item {
/// The name of this item.
/// Optional because not every item has a name, e.g. impls.
pub(crate) name: Option<Symbol>,
pub(crate) attrs: Box<Attributes>,
/// Information about this item that is specific to what kind of item it is.
/// E.g., struct vs enum vs function.
pub(crate) kind: Box<ItemKind>,
pub(crate) inner: Box<ItemInner>,
pub(crate) item_id: ItemId,
/// This is the `LocalDefId` of the `use` statement if the item was inlined.
/// The crate metadata doesn't hold this information, so the `use` statement
Expand All @@ -331,6 +328,21 @@ pub(crate) struct Item {
pub(crate) cfg: Option<Arc<Cfg>>,
}

#[derive(Clone)]
pub(crate) struct ItemInner {
/// Information about this item that is specific to what kind of item it is.
/// E.g., struct vs enum vs function.
pub(crate) kind: ItemKind,
pub(crate) attrs: Attributes,
}

impl std::ops::Deref for Item {
type Target = ItemInner;
fn deref(&self) -> &ItemInner {
&*self.inner
}
}

/// NOTE: this does NOT unconditionally print every item, to avoid thousands of lines of logs.
/// If you want to see the debug output for attributes and the `kind` as well, use `{:#?}` instead of `{:?}`.
impl fmt::Debug for Item {
Expand Down Expand Up @@ -390,9 +402,9 @@ impl Item {
}

pub(crate) fn span(&self, tcx: TyCtxt<'_>) -> Option<Span> {
let kind = match &*self.kind {
ItemKind::StrippedItem(k) => k,
_ => &*self.kind,
let kind = match &self.kind {
ItemKind::StrippedItem(k) => &*k,
_ => &self.kind,
};
match kind {
ItemKind::ModuleItem(Module { span, .. }) => Some(*span),
Expand Down Expand Up @@ -437,7 +449,7 @@ impl Item {
def_id,
name,
kind,
Box::new(Attributes::from_ast(ast_attrs)),
Attributes::from_ast(ast_attrs),
ast_attrs.cfg(cx.tcx, &cx.cache.hidden_cfg),
)
}
Expand All @@ -446,16 +458,15 @@ impl Item {
def_id: DefId,
name: Option<Symbol>,
kind: ItemKind,
attrs: Box<Attributes>,
attrs: Attributes,
cfg: Option<Arc<Cfg>>,
) -> Item {
trace!("name={name:?}, def_id={def_id:?} cfg={cfg:?}");

Item {
item_id: def_id.into(),
kind: Box::new(kind),
inner: Box::new(ItemInner { kind, attrs }),
name,
attrs,
cfg,
inline_stmt_id: None,
}
Expand Down Expand Up @@ -526,16 +537,16 @@ impl Item {
self.type_() == ItemType::Variant
}
pub(crate) fn is_associated_type(&self) -> bool {
matches!(&*self.kind, AssocTypeItem(..) | StrippedItem(box AssocTypeItem(..)))
matches!(self.kind, AssocTypeItem(..) | StrippedItem(box AssocTypeItem(..)))
}
pub(crate) fn is_ty_associated_type(&self) -> bool {
matches!(&*self.kind, TyAssocTypeItem(..) | StrippedItem(box TyAssocTypeItem(..)))
matches!(self.kind, TyAssocTypeItem(..) | StrippedItem(box TyAssocTypeItem(..)))
}
pub(crate) fn is_associated_const(&self) -> bool {
matches!(&*self.kind, AssocConstItem(..) | StrippedItem(box AssocConstItem(..)))
matches!(self.kind, AssocConstItem(..) | StrippedItem(box AssocConstItem(..)))
}
pub(crate) fn is_ty_associated_const(&self) -> bool {
matches!(&*self.kind, TyAssocConstItem(..) | StrippedItem(box TyAssocConstItem(..)))
matches!(self.kind, TyAssocConstItem(..) | StrippedItem(box TyAssocConstItem(..)))
}
pub(crate) fn is_method(&self) -> bool {
self.type_() == ItemType::Method
Expand All @@ -562,14 +573,14 @@ impl Item {
self.type_() == ItemType::Keyword
}
pub(crate) fn is_stripped(&self) -> bool {
match *self.kind {
match self.kind {
StrippedItem(..) => true,
ImportItem(ref i) => !i.should_be_displayed,
_ => false,
}
}
pub(crate) fn has_stripped_entries(&self) -> Option<bool> {
match *self.kind {
match self.kind {
StructItem(ref struct_) => Some(struct_.has_stripped_entries()),
UnionItem(ref union_) => Some(union_.has_stripped_entries()),
EnumItem(ref enum_) => Some(enum_.has_stripped_entries()),
Expand Down Expand Up @@ -612,7 +623,7 @@ impl Item {
}

pub(crate) fn is_default(&self) -> bool {
match *self.kind {
match self.kind {
ItemKind::MethodItem(_, Some(defaultness)) => {
defaultness.has_value() && !defaultness.is_final()
}
Expand Down Expand Up @@ -640,7 +651,7 @@ impl Item {
};
hir::FnHeader { safety: sig.safety(), abi: sig.abi(), constness, asyncness }
}
let header = match *self.kind {
let header = match self.kind {
ItemKind::ForeignFunctionItem(_, safety) => {
let def_id = self.def_id().unwrap();
let abi = tcx.fn_sig(def_id).skip_binder().abi();
Expand Down Expand Up @@ -679,7 +690,7 @@ impl Item {
ItemId::DefId(def_id) => def_id,
};

match *self.kind {
match self.kind {
// Primitives and Keywords are written in the source code as private modules.
// The modules need to be private so that nobody actually uses them, but the
// keywords and primitives that they are documenting are public.
Expand Down Expand Up @@ -2566,13 +2577,13 @@ mod size_asserts {

use super::*;
// tidy-alphabetical-start
static_assert_size!(Crate, 64); // frequently moved by-value
static_assert_size!(Crate, 56); // frequently moved by-value
static_assert_size!(DocFragment, 32);
static_assert_size!(GenericArg, 32);
static_assert_size!(GenericArgs, 32);
static_assert_size!(GenericParamDef, 40);
static_assert_size!(Generics, 16);
static_assert_size!(Item, 56);
static_assert_size!(Item, 48);
static_assert_size!(ItemKind, 48);
static_assert_size!(PathSegment, 40);
static_assert_size!(Type, 32);
Expand Down
6 changes: 3 additions & 3 deletions src/librustdoc/clean/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub(crate) fn krate(cx: &mut DocContext<'_>) -> Crate {
// understood by rustdoc.
let mut module = clean_doc_module(&module, cx);

match *module.kind {
match module.kind {
ItemKind::ModuleItem(ref module) => {
for it in &module.items {
// `compiler_builtins` should be masked too, but we can't apply
Expand All @@ -59,7 +59,7 @@ pub(crate) fn krate(cx: &mut DocContext<'_>) -> Crate {
let primitives = local_crate.primitives(cx.tcx);
let keywords = local_crate.keywords(cx.tcx);
{
let ItemKind::ModuleItem(ref mut m) = *module.kind else { unreachable!() };
let ItemKind::ModuleItem(ref mut m) = &mut module.inner.kind else { unreachable!() };
m.items.extend(primitives.iter().map(|&(def_id, prim)| {
Item::from_def_id_and_parts(
def_id,
Expand Down Expand Up @@ -280,7 +280,7 @@ pub(crate) fn build_deref_target_impls(
let tcx = cx.tcx;

for item in items {
let target = match *item.kind {
let target = match item.kind {
ItemKind::AssocTypeItem(ref t, _) => &t.type_,
_ => continue,
};
Expand Down
Loading
Loading