Skip to content
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
5ce4d0d
Refresh of #94678
Mallets Mar 20, 2025
03aef02
Use IPv6 addresses in hop_limit_v6 docs
Mallets Mar 20, 2025
5ace46a
Update tracking issue to 139166
Mallets Mar 31, 2025
25fb525
Update docs according to PR review
Mallets Mar 31, 2025
6657c75
Fix unused_variables
Mallets Apr 16, 2025
9a0c856
Specify that split_ascii_whitespace uses the same definition as is_as…
SimonSapin May 12, 2025
8f0522d
Fix confusing WTF surrogate safety docs
teor2345 May 12, 2025
e139d26
Introduce some typedefs to improve readability.
nnethercote May 1, 2025
5b808b7
Simplify `Accepts`.
nnethercote May 1, 2025
1525f54
Fix up some comments.
nnethercote May 1, 2025
354b1cb
Avoid `rustc_span::` qualifiers.
nnethercote May 19, 2025
ec5e841
ci: move PR job x86_64-gnu-tools to codebuild
marcoieni May 24, 2025
6d47489
improve the `std::fs::create_dir_all` docs related to atomicity
fluiderson May 23, 2025
c299e29
Implement normalize lexically
ChrisDenton Dec 23, 2024
5f857a9
Rename `clean::Enum::variants` method into `non_stripped_variants`
GuillaumeGomez May 9, 2025
560aec1
Unify rendering of type aliases without ADT items
GuillaumeGomez May 9, 2025
4194745
Split `Item::attributes` method into three
GuillaumeGomez May 9, 2025
eb9f054
Rename the `document_*` argument/field into `is_type_alias`
GuillaumeGomez May 9, 2025
4f3dd7b
Tweak attribute rendering depending on wether or not it is a type alias
GuillaumeGomez May 9, 2025
2b292d1
Add regression test for #140739
GuillaumeGomez May 9, 2025
3646a09
Improve code
GuillaumeGomez May 21, 2025
ec97b0f
Update to new API
GuillaumeGomez May 25, 2025
cf9ac0e
const-check: stop recommending the use of rustc_allow_const_fn_unstable
RalfJung May 25, 2025
532ed65
Rollup merge of #134696 - ChrisDenton:normalize-lexically, r=workingj…
jhpratt May 25, 2025
5d2ead3
Rollup merge of #138744 - Mallets:set_ipv6_sock_hop_limit, r=dtolnay
jhpratt May 25, 2025
e2beb96
Rollup merge of #140539 - nnethercote:simplify-attribute_groups, r=jd…
jhpratt May 25, 2025
49add8e
Rollup merge of #140863 - GuillaumeGomez:cleanup-tyalias-render, r=lo…
jhpratt May 25, 2025
905d011
Rollup merge of #140936 - teor2345:wtf-surrogate-docs, r=workingjubilee
jhpratt May 25, 2025
25e04e0
Rollup merge of #140952 - SimonSapin:ascii_whitespace_definition, r=d…
jhpratt May 25, 2025
7dc2213
Rollup merge of #141472 - fluiderson:dev, r=workingjubilee
jhpratt May 25, 2025
5796f12
Rollup merge of #141502 - marcoieni:x86_64-gnu-tools-codebuild, r=Kobzol
jhpratt May 25, 2025
8fcd1a7
Rollup merge of #141559 - RalfJung:less-rustc_allow_const_fn_unstable…
jhpratt May 25, 2025
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
Improve code
  • Loading branch information
GuillaumeGomez committed May 25, 2025
commit 3646a09811bfca55e976117b4c2b8bf0b4cb5aee
11 changes: 6 additions & 5 deletions src/librustdoc/clean/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,7 @@ impl Item {
Some(tcx.visibility(def_id))
}

pub(crate) fn attributes_witout_repr(&self, tcx: TyCtxt<'_>, is_json: bool) -> Vec<String> {
pub(crate) fn attributes_without_repr(&self, tcx: TyCtxt<'_>, is_json: bool) -> Vec<String> {
const ALLOWED_ATTRIBUTES: &[Symbol] =
&[sym::export_name, sym::link_section, sym::no_mangle, sym::non_exhaustive];

Expand Down Expand Up @@ -805,15 +805,15 @@ impl Item {
cache: &Cache,
is_json: bool,
) -> Vec<String> {
let mut attrs = self.attributes_witout_repr(tcx, is_json);
let mut attrs = self.attributes_without_repr(tcx, is_json);

if let Some(repr_attr) = self.repr(tcx, cache) {
attrs.push(repr_attr);
}
attrs
}

/// Returns a `#[repr(...)]` representation.
/// Returns a stringified `#[repr(...)]` attribute.
pub(crate) fn repr(&self, tcx: TyCtxt<'_>, cache: &Cache, is_json: bool) -> Option<String> {
repr_attributes(tcx, cache, self.def_id()?, self.type_(), is_json)
}
Expand Down Expand Up @@ -2370,8 +2370,9 @@ impl TypeAliasInnerType {
fn has_stripped_entries(&self) -> Option<bool> {
Some(match self {
Self::Enum { variants, .. } => variants.iter().any(|v| v.is_stripped()),
Self::Union { fields } => fields.iter().any(|f| f.is_stripped()),
Self::Struct { fields, .. } => fields.iter().any(|f| f.is_stripped()),
Self::Union { fields } | Self::Struct { fields, .. } => {
fields.iter().any(|f| f.is_stripped())
}
})
}
}
Expand Down
10 changes: 4 additions & 6 deletions src/librustdoc/html/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1203,17 +1203,15 @@ fn render_attributes_in_pre(it: &clean::Item, prefix: &str, cx: &Context<'_>) ->

struct CodeAttribute(String);

impl CodeAttribute {
fn render_into(self, w: &mut impl fmt::Write) {
write!(w, "<div class=\"code-attribute\">{}</div>", self.0).unwrap();
}
fn render_code_attribute(code_attr: CodeAttribute, w: &mut impl fmt::Write) {
write!(w, "<div class=\"code-attribute\">{}</div>", code_attr.0).unwrap();
}

// When an attribute is rendered inside a <code> tag, it is formatted using
// a div to produce a newline after it.
fn render_attributes_in_code(w: &mut impl fmt::Write, it: &clean::Item, cx: &Context<'_>) {
for attr in it.attributes_and_repr(cx.tcx(), cx.cache(), false) {
CodeAttribute(attr).render_into(w);
render_code_attribute(CodeAttribute(attr), w);
}
}

Expand All @@ -1225,7 +1223,7 @@ fn render_repr_attributes_in_code(
item_type: ItemType,
) {
if let Some(repr) = clean::repr_attributes(cx.tcx(), cx.cache(), def_id, item_type) {
CodeAttribute(repr).render_into(w);
render_code_attribute(CodeAttribute(repr), w);
}
}

Expand Down
76 changes: 39 additions & 37 deletions src/librustdoc/html/render/print_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1457,26 +1457,23 @@ impl<'a, 'cx: 'a> ItemUnion<'a, 'cx> {
ty.print(self.cx)
}

fn fields_iter(
&self,
) -> iter::Peekable<impl Iterator<Item = (&'a clean::Item, &'a clean::Type)>> {
self.fields
.iter()
.filter_map(|f| match f.kind {
clean::StructFieldItem(ref ty) => Some((f, ty)),
_ => None,
})
.peekable()
// FIXME (GuillaumeGomez): When <https://github.com/askama-rs/askama/issues/452> is implemented,
// we can replace the returned value with:
//
// `iter::Peekable<impl Iterator<Item = (&'a clean::Item, &'a clean::Type)>>`
//
// And update `item_union.html`.
fn fields_iter(&self) -> impl Iterator<Item = (&'a clean::Item, &'a clean::Type)> {
self.fields.iter().filter_map(|f| match f.kind {
clean::StructFieldItem(ref ty) => Some((f, ty)),
_ => None,
})
}

fn render_attributes_in_pre(&self) -> impl fmt::Display {
fmt::from_fn(move |f| {
if !self.is_type_alias {
for a in self.it.attributes_and_repr(self.cx.tcx(), self.cx.cache(), false) {
writeln!(f, "{a}")?;
}
} else {
// For now we only render `repr` attributes for type aliases.
if self.is_type_alias {
// For now the only attributes we render for type aliases are `repr` attributes.
if let Some(repr) = clean::repr_attributes(
self.cx.tcx(),
self.cx.cache(),
Expand All @@ -1485,6 +1482,10 @@ impl<'a, 'cx: 'a> ItemUnion<'a, 'cx> {
) {
writeln!(f, "{repr}")?;
};
} else {
for a in self.it.attributes_and_repr(self.cx.tcx(), self.cx.cache(), false) {
writeln!(f, "{a}")?;
}
}
Ok(())
})
Expand All @@ -1501,8 +1502,7 @@ fn item_union(cx: &Context<'_>, it: &clean::Item, s: &clean::Union) -> impl fmt:
is_type_alias: false,
def_id: it.def_id().unwrap(),
}
.render_into(w)
.unwrap();
.render_into(w)?;
Ok(())
})
}
Expand All @@ -1529,31 +1529,31 @@ fn print_tuple_struct_fields(cx: &Context<'_>, s: &[clean::Item]) -> impl Displa
})
}

struct DisplayEnum<'a> {
variants: &'a IndexVec<VariantIdx, clean::Item>,
generics: &'a clean::Generics,
struct DisplayEnum<'clean> {
variants: &'clean IndexVec<VariantIdx, clean::Item>,
generics: &'clean clean::Generics,
is_non_exhaustive: bool,
def_id: DefId,
}

impl<'a> DisplayEnum<'a> {
impl<'clean> DisplayEnum<'clean> {
fn render_into<W: fmt::Write>(
self,
cx: &Context<'_>,
it: &clean::Item,
is_type_alias: bool,
w: &mut W,
) -> fmt::Result {
let variants_count = self.variants.iter().filter(|i| !i.is_stripped()).count();
let non_stripped_variant_count = self.variants.iter().filter(|i| !i.is_stripped()).count();
let variants_len = self.variants.len();
let has_stripped_entries = variants_len != variants_count;
let has_stripped_entries = variants_len != non_stripped_variant_count;

wrap_item(w, |w| {
if !is_type_alias {
render_attributes_in_code(w, it, cx);
} else {
// For now we only render `repr` attributes for type aliases.
if is_type_alias {
// For now the only attributes we render for type aliases are `repr` attributes.
render_repr_attributes_in_code(w, cx, self.def_id, ItemType::Enum);
} else {
render_attributes_in_code(w, it, cx);
}
write!(
w,
Expand All @@ -1565,7 +1565,7 @@ impl<'a> DisplayEnum<'a> {
cx,
Some(self.generics),
self.variants,
variants_count,
non_stripped_variant_count,
has_stripped_entries,
self.is_non_exhaustive,
self.def_id,
Expand All @@ -1574,14 +1574,16 @@ impl<'a> DisplayEnum<'a> {
})?;

let def_id = it.item_id.expect_def_id();
let layout_def_id = if !is_type_alias {
let layout_def_id = if is_type_alias {
self.def_id
} else {
write!(w, "{}", document(cx, it, None, HeadingOffset::H2))?;
// We don't return the same `DefId` since the layout size of the type alias might be
// different since we might have more information on the generics.
def_id
} else {
self.def_id
};

if variants_count != 0 {
if non_stripped_variant_count != 0 {
write!(w, "{}", item_variants(cx, it, self.variants, self.def_id))?;
}
write!(
Expand Down Expand Up @@ -2005,11 +2007,11 @@ impl<'a> DisplayStruct<'a> {
w: &mut W,
) -> fmt::Result {
wrap_item(w, |w| {
if !is_type_alias {
render_attributes_in_code(w, it, cx);
} else {
// For now we only render `repr` attributes for type aliases.
if is_type_alias {
// For now the only attributes we render for type aliases are `repr` attributes.
render_repr_attributes_in_code(w, cx, self.def_id, ItemType::Struct);
} else {
render_attributes_in_code(w, it, cx);
}
write!(
w,
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/html/templates/item_union.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{% if !self.is_type_alias %}
{{ self.document()|safe }}
{% endif %}
{% if self.fields_iter().peek().is_some() %}
{% if self.fields_iter().next().is_some() %}
<h2 id="fields" class="fields section-header"> {# #}
Fields<a href="#fields" class="anchor">§</a> {# #}
</h2>
Expand Down