Skip to content

rustdoc: Indicate struct can be created + fn #107926

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions src/librustdoc/clean/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1507,6 +1507,11 @@ impl FnDecl {
_ => panic!("unexpected desugaring of async function"),
}
}

/// Indicates id this function declaration can be used to create the type
pub(crate) fn type_builder(&self) -> bool {
self.inputs.values.get(0).and_then(|v| v.to_self())
}
}

#[derive(Clone, PartialEq, Eq, Debug, Hash)]
Expand Down
15 changes: 14 additions & 1 deletion src/librustdoc/html/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -845,11 +845,12 @@ fn assoc_method(
render_attributes_in_code(w, meth);
(0, "", Ending::Newline)
};
let takes_self = d.inputs.values.iter().filter(|v| v.to_self().is_some()).count() > 0;
w.reserve(header_len + "<a href=\"\" class=\"fn\">{".len() + "</a>".len());
write!(
w,
"{indent}{vis}{constness}{asyncness}{unsafety}{defaultness}{abi}fn <a{href} class=\"fn\">{name}</a>\
{generics}{decl}{notable_traits}{where_clause}",
{generics}{decl}{notable_traits}{where_clause}{no_self}",
indent = indent_str,
vis = vis,
constness = constness,
Expand All @@ -863,9 +864,21 @@ fn assoc_method(
decl = d.full_print(header_len, indent, cx),
notable_traits = notable_traits.unwrap_or_default(),
where_clause = print_where_clause(g, cx, indent, end_newline),
no_self = if !takes_self {
"<span class=\"stab\" title=\"Can be used to construct this type\">⚒️</span>"
} else {
""
}
);
}

/// Returns true if the given function can be used to construct the type.
///
/// This means the function does not take `self` ad returns the given type (including if Option or Result)
fn fn_is_to_build_type(ty: &clean::Item, fn_item: &clean::FnDecl) -> bool {
todo!()
}

/// Writes a span containing the versions at which an item became stable and/or const-stable. For
/// example, if the item became stable at 1.0.0, and const-stable at 1.45.0, this function would
/// write a span containing "1.0.0 (const: 1.45.0)".
Expand Down
7 changes: 6 additions & 1 deletion src/librustdoc/html/render/print_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ fn item_module(w: &mut Buffer, cx: &mut Context<'_>, item: &clean::Item, items:
write!(
w,
"<div class=\"item-left\">\
<a class=\"{class}\" href=\"{href}\" title=\"{title}\">{name}</a>\
<a class=\"{class}\" href=\"{href}\" title=\"{title}\">{name} {ind}</a>\
{visibility_emoji}\
{unsafety_flag}\
{stab_tags}\
Expand All @@ -448,6 +448,11 @@ fn item_module(w: &mut Buffer, cx: &mut Context<'_>, item: &clean::Item, items:
.filter_map(|s| if !s.is_empty() { Some(s.as_str()) } else { None })
.collect::<Vec<_>>()
.join(" "),
ind = if myitem.is_struct() {
"*" // ToDo: indicate if can be constructed
} else {
""
}
);
w.write_str(ITEM_TABLE_ROW_CLOSE);
}
Expand Down