Skip to content

Commit 62bc421

Browse files
committed
Emit an error when rustc_doc_primitive has an unknown value
Currently rustdoc silently does nothing. Change this to raise an error instead.
1 parent 087ae97 commit 62bc421

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

src/librustdoc/clean/types.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,16 @@ impl ExternalCrate {
266266
let as_primitive = |res: Res<!>| {
267267
let Res::Def(DefKind::Mod, def_id) = res else { return None };
268268
tcx.get_attrs(def_id, sym::rustc_doc_primitive).find_map(|attr| {
269-
// FIXME: should warn on unknown primitives?
270-
Some((def_id, PrimitiveType::from_symbol(attr.value_str()?)?))
269+
let attr_value = attr.value_str().expect("syntax should already be validated");
270+
if let Some(prim) = PrimitiveType::from_symbol(attr_value) {
271+
return Some((def_id, prim));
272+
}
273+
274+
tcx.dcx()
275+
.struct_span_err(attr.span, format!("unrecognized primitive `{attr_value}`"))
276+
.with_help("primitive must be a member of rustdoc's `PrimitiveType` enum")
277+
.emit();
278+
None
271279
})
272280
};
273281

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#![crate_type = "lib"]
2+
#![feature(rustc_attrs)]
3+
4+
#[rustc_doc_primitive = "fakeprimitive"]
5+
//~^ ERROR unrecognized primitive `fakeprimitive`
6+
/// hello
7+
mod fakeprimitive {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error: unrecognized primitive `fakeprimitive`
2+
--> $DIR/rustc_doc_primitive-invalid.rs:4:1
3+
|
4+
LL | #[rustc_doc_primitive = "fakeprimitive"]
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= help: primitive must be a member of rustdoc's `PrimitiveType` enum
8+
9+
error: aborting due to 1 previous error
10+

0 commit comments

Comments
 (0)