Change:
From this comment: Still remaining the .
Actually, the character has a meaning in the search (for "exact" search). But instead of just removing it, maybe we should instead emit an error when we encounter it. What do you think ?
That doesn't work for though, maybe it should? It would make sense to restrict allowed characters because even whitespace is allowed at the moment which seems questionable.
It sounds like we need to make sure this lands before we branch beta or so?
Let's forbid , whitespaces and tabs in the the doc alias then.
Can we avoid ad-hoc rules and say something like "must be a rust identifier"?
Even better! Great suggestion !
Just thought about it, but it cannot be the case : we allow things like "*" or "+" (for the traits for example), so it cannot be ident only. I'll stick to the listed characters above.
The documentation () has no mention of that -- can you elaborate?
Doc aliases can be something else than a rust identifier. For example, you can look for or in the std docs, and you'll see aliases results.
Ah, I see what you mean. Okay, then I agree that we need more than just Rust identifiers, and it might be reasonable to just allow as you suggest -- everything except whitespace and quotes. I'm a bit worried that'll hurt us in terms of how expansive it is but it's probably fine.
I don't expect attributes to be used widely, so we should be fine. ;)
Is there more justification for removing whitespace support other than calling the characters questionable? If I have a struct or a function that implements an algorithm, I would like to alias the item to the plaintext name of the algorithm, for example .
I just had in mind "idents", so no whitespace in them. However I don't see any reason to not allow specfically. I'll send a PR tomorrow.
rustdoc only being ident-centric is .
path-centric would be more accurate. ;)

Discussion:
} } <ins> fn doc_alias_str_error(&self, meta: &NestedMetaItem) { self.tcx .sess .struct_span_err( meta.span(), "doc alias attribute expects a string: #[doc(alias = "0")]", ) .emit(); } </ins> fn check_doc_alias(&self, attr: &Attribute, hir_id: HirId, target: Target) -> bool { if let Some(mi) = attr.meta() { if let Some(list) = mi.meta_item_list() { for meta in list { if meta.has_name(sym::alias) { <del> if !meta.is_value_str() || meta .value_str() .map(|s| s.to_string()) .unwrap_or_else(String::new) .is_empty() </del> <ins> if !meta.is_value_str() { self.doc_alias_str_error(meta); return false; } let doc_alias = meta.value_str().map(|s| s.to_string()).unwrap_or_else(String::new); if doc_alias.is_empty() { self.doc_alias_str_error(meta); return false; } if let Some(c) = doc_alias.chars().find(|&c| c == '"' || c == ''' || c.is_whitespace()) </ins> { self.tcx .sess .struct_span_err( meta.span(), <del> "doc alias attribute expects a string: #[doc(alias = "0")]", </del> <ins> &format!( "{:?} character isn't allowed in `#[doc(alias = "...")]`", c, ), </ins> ) .emit(); return false;

&format!("`#[doc(alias = "...")]` isn't allowed on {}", err), ) .emit(); <ins> return false; </ins> } } }

Then, when looking for it through the `rustdoc` search, if you enter "x" or "big", search will show the `BigX` struct first. <ins> There are some limitations on the doc alias names though: you can't use `"` or whitespace. </ins>

self.other_attrs .lists(sym::doc) .filter(|a| a.has_name(sym::alias)) <del> .filter_map(|a| a.value_str().map(|s| s.to_string().replace(""", ""))) </del> <ins> .filter_map(|a| a.value_str().map(|s| s.to_string())) </ins> .filter(|v| !v.is_empty()) .collect::<FxHashSet<_>>() }

#[doc(alias)] //~ ERROR #[doc(alias = 0)] //~ ERROR #[doc(alias("bar"))] //~ ERROR <ins> #[doc(alias = """)] //~ ERROR #[doc(alias = "n")] //~ ERROR #[doc(alias = " ")] //~^ ERROR #[doc(alias = " ")] //~ ERROR #[doc(alias = "t")] //~ ERROR </ins> pub struct Foo;

LL | #[doc(alias("bar"))] |       ^^^^^^^^^^^^ <del> error: aborting due to 3 previous errors </del> <ins> error: '"' character isn't allowed in `#[doc(alias = "...")]` --> $DIR/check-doc-alias-attr.rs:10:7 | LL | #[doc(alias = """)] |       ^^^^^^^^^^^^ error: 'n' character isn't allowed in `#[doc(alias = "...")]` --> $DIR/check-doc-alias-attr.rs:11:7 | LL | #[doc(alias = "n")] |       ^^^^^^^^^^^^ error: 'n' character isn't allowed in `#[doc(alias = "...")]` --> $DIR/check-doc-alias-attr.rs:12:7 | LL |   #[doc(alias = " |  _______^ LL | | ")] | |_^ error: ' ' character isn't allowed in `#[doc(alias = "...")]` --> $DIR/check-doc-alias-attr.rs:14:7 | LL | #[doc(alias = " ")] |       ^^^^^^^^^^^ error: 't' character isn't allowed in `#[doc(alias = "...")]` --> $DIR/check-doc-alias-attr.rs:15:7 | LL | #[doc(alias = "t")] |       ^^^^^^^^^^^^ error: aborting due to 8 previous errors </ins>