File tree 3 files changed +27
-2
lines changed
3 files changed +27
-2
lines changed Original file line number Diff line number Diff line change @@ -266,8 +266,16 @@ impl ExternalCrate {
266
266
let as_primitive = |res : Res < !> | {
267
267
let Res :: Def ( DefKind :: Mod , def_id) = res else { return None } ;
268
268
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
271
279
} )
272
280
} ;
273
281
Original file line number Diff line number Diff line change
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 number Diff line number Diff line change
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
+
You can’t perform that action at this time.
0 commit comments