Skip to content

Rollup of 11 pull requests #83301

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

Merged
merged 24 commits into from
Mar 19, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
2cbea9f
Reuse `std::sys::unsupported::pipe` on `hermit`
CDirkx Feb 24, 2021
bbbefa3
Allow doc alias attributes to use both list and value
GuillaumeGomez Mar 6, 2021
2069d3e
Update doc alias ui tests
GuillaumeGomez Mar 6, 2021
1d26e6b
Improve code by removing similar function calls and using loops inste…
GuillaumeGomez Mar 8, 2021
cad3c42
Deprecate std::os::haiku::raw
bstrie Mar 16, 2021
bb7c04a
Remove unnecessary `forward_inner_docs` hack
jyn514 Mar 17, 2021
620ecc0
Move some test-only code to test files
jyn514 Mar 17, 2021
b1de9d4
Fix gitattibutes for old git versions
Mar 16, 2021
cfb4ad4
Remove unwrap_none/expect_none from compiler/.
m-ou-se Mar 4, 2021
390d1ef
Extend `proc_macro_back_compat` lint to `actix-web`
Aaron1011 Mar 16, 2021
458d044
Upgrade memmap to memmap2 in other crates.
cjgillot Mar 17, 2021
99b2054
Fix typo/inaccuracy in the documentation of Iterator::skip_while
steffahn Mar 18, 2021
9dfda62
Clarify docs for Read::read's return value
jix Mar 8, 2021
4abcd40
Rollup merge of #82500 - CDirkx:hermit-pipe, r=joshtriplett
Dylan-DPC Mar 19, 2021
2960971
Rollup merge of #82759 - m-ou-se:remove-unwrap-none, r=petrochenkov
Dylan-DPC Mar 19, 2021
61372e1
Rollup merge of #82846 - GuillaumeGomez:doc-alias-list, r=jyn514
Dylan-DPC Mar 19, 2021
db4a97c
Rollup merge of #82892 - jix:clarify-read-read, r=joshtriplett
Dylan-DPC Mar 19, 2021
75571a5
Rollup merge of #83179 - Aaron1011:actix-web-lint, r=petrochenkov
Dylan-DPC Mar 19, 2021
37b7031
Rollup merge of #83197 - jyn514:cfg-test-dead-code, r=joshtriplett
Dylan-DPC Mar 19, 2021
3591242
Rollup merge of #83208 - jethrogb:jb/gitignore, r=Xanewok
Dylan-DPC Mar 19, 2021
675ae2e
Rollup merge of #83215 - bstrie:dephaikuraw, r=joshtriplett
Dylan-DPC Mar 19, 2021
827ad66
Rollup merge of #83230 - jyn514:remove-macros, r=joshtriplett
Dylan-DPC Mar 19, 2021
23128c4
Rollup merge of #83236 - cjgillot:memmap, r=joshtriplett
Dylan-DPC Mar 19, 2021
99f411d
Rollup merge of #83270 - steffahn:missing_word_in_skip_while_doc, r=j…
Dylan-DPC Mar 19, 2021
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
Allow doc alias attributes to use both list and value
  • Loading branch information
GuillaumeGomez committed Mar 10, 2021
commit bbbefa3edc48cb1afd57f1d99bf418731be1ef8f
93 changes: 86 additions & 7 deletions compiler/rustc_passes/src/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,10 +390,25 @@ impl CheckAttrVisitor<'tcx> {
.emit();
}

fn check_doc_alias(&self, meta: &NestedMetaItem, hir_id: HirId, target: Target) -> bool {
let doc_alias = meta.value_str().map(|s| s.to_string()).unwrap_or_else(String::new);
fn check_doc_alias_value(
&self,
meta: &NestedMetaItem,
doc_alias: &str,
hir_id: HirId,
target: Target,
is_list: bool,
) -> bool {
if doc_alias.is_empty() {
self.doc_attr_str_error(meta, "alias");
self.tcx
.sess
.struct_span_err(
meta.name_value_literal_span().unwrap_or_else(|| meta.span()),
&format!(
"`#[doc(alias{})]` attribute cannot have empty value",
if is_list { "(\"...\")" } else { " = \"...\"" },
),
)
.emit();
return false;
}
if let Some(c) =
Expand All @@ -403,7 +418,11 @@ impl CheckAttrVisitor<'tcx> {
.sess
.struct_span_err(
meta.name_value_literal_span().unwrap_or_else(|| meta.span()),
&format!("{:?} character isn't allowed in `#[doc(alias = \"...\")]`", c),
&format!(
"{:?} character isn't allowed in `#[doc(alias{})]`",
c,
if is_list { "(\"...\")" } else { " = \"...\"" },
),
)
.emit();
return false;
Expand All @@ -413,7 +432,10 @@ impl CheckAttrVisitor<'tcx> {
.sess
.struct_span_err(
meta.name_value_literal_span().unwrap_or_else(|| meta.span()),
"`#[doc(alias = \"...\")]` cannot start or end with ' '",
&format!(
"`#[doc(alias{})]` cannot start or end with ' '",
if is_list { "(\"...\")" } else { " = \"...\"" },
),
)
.emit();
return false;
Expand Down Expand Up @@ -446,7 +468,11 @@ impl CheckAttrVisitor<'tcx> {
.sess
.struct_span_err(
meta.span(),
&format!("`#[doc(alias = \"...\")]` isn't allowed on {}", err),
&format!(
"`#[doc(alias{})]` isn't allowed on {}",
if is_list { "(\"...\")" } else { " = \"...\"" },
err,
),
)
.emit();
return false;
Expand All @@ -457,14 +483,67 @@ impl CheckAttrVisitor<'tcx> {
.sess
.struct_span_err(
meta.span(),
&format!("`#[doc(alias = \"...\")]` is the same as the item's name"),
&format!(
"`#[doc(alias{})]` is the same as the item's name",
if is_list { "(\"...\")" } else { " = \"...\"" },
),
)
.emit();
return false;
}
true
}

fn check_doc_alias(&self, meta: &NestedMetaItem, hir_id: HirId, target: Target) -> bool {
if let Some(values) = meta.meta_item_list() {
let mut errors = 0;
for v in values {
match v.literal() {
Some(l) => match l.kind {
LitKind::Str(s, _) => {
if !self.check_doc_alias_value(v, &s.as_str(), hir_id, target, true) {
errors += 1;
}
}
_ => {
self.tcx
.sess
.struct_span_err(
v.span(),
"`#[doc(alias(\"a\")]` expects string literals",
)
.emit();
errors += 1;
}
},
None => {
self.tcx
.sess
.struct_span_err(
v.span(),
"`#[doc(alias(\"a\")]` expects string literals",
)
.emit();
errors += 1;
}
}
}
errors == 0
} else if let Some(doc_alias) = meta.value_str().map(|s| s.to_string()) {
self.check_doc_alias_value(meta, &doc_alias, hir_id, target, false)
} else {
self.tcx
.sess
.struct_span_err(
meta.span(),
"doc alias attribute expects a string `#[doc(alias = \"a\")]` or a list of \
strings: `#[doc(alias(\"a\", \"b\")]`",
)
.emit();
false
}
}

fn check_doc_keyword(&self, meta: &NestedMetaItem, hir_id: HirId) -> bool {
let doc_keyword = meta.value_str().map(|s| s.to_string()).unwrap_or_else(String::new);
if doc_keyword.is_empty() {
Expand Down
7 changes: 7 additions & 0 deletions src/doc/rustdoc/src/advanced-features.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,10 @@ Then, when looking for it through the `rustdoc` search, if you enter "x" or
"big", search will show the `BigX` struct first.

There are some limitations on the doc alias names though: you can't use `"` or whitespace.

You can add multiple aliases at the same time by using a list:

```rust,no_run
#[doc(alias("x", "big"))]
pub struct BigX;
```
16 changes: 14 additions & 2 deletions src/librustdoc/clean/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -914,8 +914,20 @@ impl Attributes {
self.other_attrs
.lists(sym::doc)
.filter(|a| a.has_name(sym::alias))
.filter_map(|a| a.value_str().map(|s| s.to_string()))
.filter(|v| !v.is_empty())
.map(|a| {
if let Some(values) = a.meta_item_list() {
values
.iter()
.map(|l| match l.literal().unwrap().kind {
ast::LitKind::Str(s, _) => s.as_str().to_string(),
_ => unreachable!(),
})
.collect::<Vec<_>>()
} else {
vec![a.value_str().map(|s| s.to_string()).unwrap()]
}
})
.flatten()
.collect::<FxHashSet<_>>()
}
}
Expand Down