Skip to content

Commit fd06ddf

Browse files
Continue migration to new Attribute API for doc attribute
1 parent db53f23 commit fd06ddf

File tree

27 files changed

+696
-610
lines changed

27 files changed

+696
-610
lines changed

Cargo.lock

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4010,7 +4010,6 @@ dependencies = [
40104010
"itertools",
40114011
"rustc_abi",
40124012
"rustc_ast",
4013-
"rustc_attr_parsing",
40144013
"rustc_data_structures",
40154014
"rustc_errors",
40164015
"rustc_fluent_macro",
@@ -4432,7 +4431,6 @@ dependencies = [
44324431
"rustc_abi",
44334432
"rustc_ast",
44344433
"rustc_ast_lowering",
4435-
"rustc_ast_pretty",
44364434
"rustc_attr_parsing",
44374435
"rustc_data_structures",
44384436
"rustc_errors",

compiler/rustc_ast/src/attr/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,11 @@ impl AttributeExt for Attribute {
220220
fn is_automatically_derived_attr(&self) -> bool {
221221
self.has_name(sym::automatically_derived)
222222
}
223+
224+
fn is_doc_hidden(&self) -> bool {
225+
self.has_name(sym::doc)
226+
&& self.meta_item_list().is_some_and(|l| list_contains_name(&l, sym::hidden))
227+
}
223228
}
224229

225230
impl Attribute {
@@ -830,6 +835,9 @@ pub trait AttributeExt: Debug {
830835
/// commented module (for inner doc) vs within its parent module (for outer
831836
/// doc).
832837
fn doc_resolution_scope(&self) -> Option<AttrStyle>;
838+
839+
/// Returns `true` if this attribute contains `doc(hidden)`.
840+
fn is_doc_hidden(&self) -> bool;
833841
}
834842

835843
// FIXME(fn_delegation): use function delegation instead of manually forwarding

compiler/rustc_attr_parsing/messages.ftl

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,10 @@ attr_parsing_doc_keyword_not_keyword =
287287
nonexistent keyword `{$keyword}` used in `#[doc(keyword = "...")]`
288288
.help = only existing keywords are allowed in core/std
289289
290+
attr_parsing_doc_attribute_not_attribute =
291+
nonexistent builtin attribute `{$attribute}` used in `#[doc(attribute = "...")]`
292+
.help = only existing builtin attributes are allowed in core/std
293+
290294
attr_parsing_doc_inline_conflict =
291295
conflicting doc inlining attributes
292296
.help = remove one of the conflicting attributes
@@ -296,3 +300,54 @@ attr_parsing_doc_inline_conflict_first =
296300
297301
attr_parsing_doc_inline_conflict_second =
298302
{"."}..conflicts with this attribute
303+
304+
attr_parsing_doc_auto_cfg_expects_hide_or_show =
305+
only `hide` or `show` are allowed in `#[doc(auto_cfg(...))]`
306+
307+
attr_parsing_doc_auto_cfg_hide_show_unexpected_item =
308+
`#![doc(auto_cfg({$attr_name}(...)))]` only accepts identifiers or key/value items
309+
310+
attr_parsing_doc_auto_cfg_hide_show_expects_list =
311+
`#![doc(auto_cfg({$attr_name}(...)))]` expects a list of items
312+
313+
attr_parsing_doc_invalid =
314+
invalid `doc` attribute
315+
316+
attr_parsing_doc_unknown_include =
317+
unknown `doc` attribute `include`
318+
.suggestion = use `doc = include_str!` instead
319+
320+
attr_parsing_doc_unknown_spotlight =
321+
unknown `doc` attribute `spotlight`
322+
.note = `doc(spotlight)` was renamed to `doc(notable_trait)`
323+
.suggestion = use `notable_trait` instead
324+
.no_op_note = `doc(spotlight)` is now a no-op
325+
326+
attr_parsing_doc_unknown_passes =
327+
unknown `doc` attribute `{$name}`
328+
.note = `doc` attribute `{$name}` no longer functions; see issue #44136 <https://github.com/rust-lang/rust/issues/44136>
329+
.label = no longer functions
330+
.no_op_note = `doc({$name})` is now a no-op
331+
332+
attr_parsing_doc_unknown_plugins =
333+
unknown `doc` attribute `plugins`
334+
.note = `doc` attribute `plugins` no longer functions; see issue #44136 <https://github.com/rust-lang/rust/issues/44136> and CVE-2018-1000622 <https://nvd.nist.gov/vuln/detail/CVE-2018-1000622>
335+
.label = no longer functions
336+
.no_op_note = `doc(plugins)` is now a no-op
337+
338+
attr_parsing_doc_unknown_any =
339+
unknown `doc` attribute `{$name}`
340+
341+
attr_parsing_doc_auto_cfg_wrong_literal =
342+
expected boolean for `#[doc(auto_cfg = ...)]`
343+
344+
attr_parsing_doc_test_takes_list =
345+
`#[doc(test(...)]` takes a list of attributes
346+
347+
attr_parsing_doc_test_unknown =
348+
unknown `doc(test)` attribute `{$name}`
349+
350+
attr_parsing_doc_test_literal = `#![doc(test(...)]` does not take a literal
351+
352+
attr_parsing_doc_alias_malformed =
353+
doc alias attribute expects a string `#[doc(alias = "a")]` or a list of strings `#[doc(alias("a", "b"))]`

compiler/rustc_attr_parsing/src/attributes/cfg.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ fn parse_cfg_entry_target<S: Stage>(
172172
Ok(CfgEntry::All(result, list.span))
173173
}
174174

175-
fn parse_name_value<S: Stage>(
175+
pub(crate) fn parse_name_value<S: Stage>(
176176
name: Symbol,
177177
name_span: Span,
178178
value: Option<&NameValueParser>,

0 commit comments

Comments
 (0)