Skip to content

Commit a72e4e8

Browse files
committed
rustdoc: use anonymous constant for primitives/keywords/attribute docs
1 parent 922325b commit a72e4e8

53 files changed

Lines changed: 205 additions & 233 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

compiler/rustc_attr_parsing/src/attributes/rustc_internal.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1119,7 +1119,7 @@ pub(crate) struct RustcDocPrimitiveParser;
11191119

11201120
impl SingleAttributeParser for RustcDocPrimitiveParser {
11211121
const PATH: &[Symbol] = &[sym::rustc_doc_primitive];
1122-
const ALLOWED_TARGETS: AllowedTargets<'_> = AllowedTargets::AllowList(&[Allow(Target::Mod)]);
1122+
const ALLOWED_TARGETS: AllowedTargets<'_> = AllowedTargets::AllowList(&[Allow(Target::Const)]);
11231123
const TEMPLATE: AttributeTemplate = template!(NameValueStr: "primitive name");
11241124
const STABILITY: AttributeStability = unstable!(
11251125
rustc_attrs,

compiler/rustc_passes/src/check_attr.rs

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ use rustc_session::lint::builtin::{
4444
MALFORMED_DIAGNOSTIC_FORMAT_LITERALS, MISPLACED_DIAGNOSTIC_ATTRIBUTES, UNUSED_ATTRIBUTES,
4545
};
4646
use rustc_span::edition::Edition;
47-
use rustc_span::{DUMMY_SP, Ident, Span, Symbol, sym};
47+
use rustc_span::{DUMMY_SP, Ident, Span, Symbol, kw, sym};
4848
use rustc_trait_selection::error_reporting::InferCtxtErrorExt;
4949
use rustc_trait_selection::infer::{TyCtxtInferExt, ValuePairs};
5050
use rustc_trait_selection::traits::ObligationCtxt;
@@ -1026,18 +1026,11 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
10261026
hir::Node::Item(item) => Some(&item.kind),
10271027
_ => None,
10281028
};
1029-
match item_kind {
1030-
Some(ItemKind::Mod(_, module)) => {
1031-
if !module.item_ids.is_empty() {
1032-
self.dcx()
1033-
.emit_err(diagnostics::DocKeywordAttributeEmptyMod { span, attr_name });
1034-
return;
1035-
}
1036-
}
1037-
_ => {
1038-
self.dcx().emit_err(diagnostics::DocKeywordAttributeNotMod { span, attr_name });
1039-
return;
1040-
}
1029+
if let Some(ItemKind::Const(ident, _gen, _ty, _rhs)) = item_kind
1030+
&& ident.name == kw::Underscore
1031+
{
1032+
} else {
1033+
self.dcx().emit_err(diagnostics::DocKeywordAttributeNotAnonConst { span, attr_name });
10411034
}
10421035
}
10431036

compiler/rustc_passes/src/diagnostics.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,8 @@ pub(crate) struct DocAliasNotAnAlias {
7373
}
7474

7575
#[derive(Diagnostic)]
76-
#[diag("`#[doc({$attr_name} = \"...\")]` should be used on empty modules")]
77-
pub(crate) struct DocKeywordAttributeEmptyMod {
78-
#[primary_span]
79-
pub span: Span,
80-
pub attr_name: &'static str,
81-
}
82-
83-
#[derive(Diagnostic)]
84-
#[diag("`#[doc({$attr_name} = \"...\")]` should be used on modules")]
85-
pub(crate) struct DocKeywordAttributeNotMod {
76+
#[diag("`#[doc({$attr_name} = \"...\")]` should be used on anonymous constants")]
77+
pub(crate) struct DocKeywordAttributeNotAnonConst {
8678
#[primary_span]
8779
pub span: Span,
8880
pub attr_name: &'static str,

library/core/src/attribute_docs.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
///
8383
/// [`unused_must_use`]: ../rustc/lints/listing/warn-by-default.html#unused-must-use
8484
/// [the `must_use` attribute]: ../reference/attributes/diagnostics.html#the-must_use-attribute
85-
mod must_use_attribute {}
85+
const _: () = ();
8686

8787
#[doc(attribute = "allow")]
8888
//
@@ -144,7 +144,7 @@ mod must_use_attribute {}
144144
/// [`forbid`]: ./attribute.forbid.html
145145
/// [`warn`]: ./attribute.warn.html
146146
/// [`deny`]: ./attribute.deny.html
147-
mod allow_attribute {}
147+
const _: () = ();
148148

149149
#[doc(attribute = "cfg")]
150150
//
@@ -192,7 +192,7 @@ mod allow_attribute {}
192192
/// [`cfg_attr`]: ../reference/conditional-compilation.html#the-cfg_attr-attribute
193193
/// [the `cfg` attribute]: ../reference/conditional-compilation.html#the-cfg-attribute
194194
/// [`if`]: ./keyword.if.html
195-
mod cfg_attribute {}
195+
const _: () = ();
196196

197197
#[doc(attribute = "deny")]
198198
//
@@ -240,7 +240,7 @@ mod cfg_attribute {}
240240
/// [`allow`]: ./attribute.allow.html
241241
/// [`warn`]: ./attribute.warn.html
242242
/// [`deny`]: ./attribute.deny.html
243-
mod deny_attribute {}
243+
const _: () = ();
244244

245245
#[doc(attribute = "forbid")]
246246
//
@@ -276,7 +276,7 @@ mod deny_attribute {}
276276
/// [the `forbid` attribute]: ../reference/attributes/diagnostics.html#lint-check-attributes
277277
/// [`allow`]: ./attribute.allow.html
278278
/// [`warn`]: ./attribute.warn.html
279-
mod forbid_attribute {}
279+
const _: () = ();
280280

281281
#[doc(attribute = "deprecated")]
282282
//
@@ -302,7 +302,7 @@ mod forbid_attribute {}
302302
/// For more information, see the Reference on [the `deprecated` attribute].
303303
///
304304
/// [the `deprecated` attribute]: ../reference/attributes/diagnostics.html#the-deprecated-attribute
305-
mod deprecated_attribute {}
305+
const _: () = ();
306306

307307
#[doc(attribute = "warn")]
308308
//
@@ -348,7 +348,7 @@ mod deprecated_attribute {}
348348
/// [`allow`]: ./attribute.allow.html
349349
/// [`deny`]: ./attribute.deny.html
350350
/// [`forbid`]: ./attribute.forbid.html
351-
mod warn_attribute {}
351+
const _: () = ();
352352

353353
#[doc(attribute = "no_std")]
354354
//
@@ -404,7 +404,7 @@ mod warn_attribute {}
404404
/// [`Option`]: option::Option
405405
/// [`Result`]: result::Result
406406
/// [the `no_std` attribute]: ../reference/names/preludes.html#the-no_std-attribute
407-
mod no_std_attribute {}
407+
const _: () = ();
408408

409409
#[doc(attribute = "inline")]
410410
//
@@ -444,7 +444,7 @@ mod no_std_attribute {}
444444
/// For more information, see the Reference on [the `inline` attribute].
445445
///
446446
/// [the `inline` attribute]: ../reference/attributes/codegen.html#the-inline-attribute
447-
mod inline_attribute {}
447+
const _: () = ();
448448

449449
#[doc(attribute = "cold")]
450450
//
@@ -474,7 +474,7 @@ mod inline_attribute {}
474474
/// For more information, see the Reference on [the `cold` attribute].
475475
///
476476
/// [the `cold` attribute]: ../reference/attributes/codegen.html#the-cold-attribute
477-
mod cold_attribute {}
477+
const _: () = ();
478478

479479
#[doc(attribute = "track_caller")]
480480
//
@@ -505,7 +505,7 @@ mod cold_attribute {}
505505
/// [`Location::caller`]: panic::Location::caller
506506
/// [`Option::unwrap`]: Option::unwrap
507507
/// [the `track_caller` attribute]: ../reference/attributes/codegen.html#the-track_caller-attribute
508-
mod track_caller_attribute {}
508+
const _: () = ();
509509

510510
#[doc(attribute = "proc_macro")]
511511
//
@@ -554,7 +554,7 @@ mod track_caller_attribute {}
554554
/// [`TokenStream`]: ../proc_macro/struct.TokenStream.html
555555
/// [function-like procedural macros]: ../reference/procedural-macros.html#the-proc_macro-attribute
556556
/// [`proc_macro`]: ../proc_macro/index.html
557-
mod proc_macro_attribute {}
557+
const _: () = ();
558558

559559
#[doc(attribute = "link_section")]
560560
//
@@ -580,4 +580,4 @@ mod proc_macro_attribute {}
580580
/// For more information, see the Reference on [the `link_section` attribute].
581581
///
582582
/// [the `link_section` attribute]: ../reference/abi.html#the-link_section-attribute
583-
mod link_section_attribute {}
583+
const _: () = ();

0 commit comments

Comments
 (0)