This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +59
-0
lines changed
src/tools/jsondoclint/src Expand file tree Collapse file tree 2 files changed +59
-0
lines changed Original file line number Diff line number Diff line change @@ -60,6 +60,8 @@ impl<'a> Validator<'a> {
6060
6161 fn check_item ( & mut self , id : & ' a Id ) {
6262 if let Some ( item) = & self . krate . index . get ( id) {
63+ item. links . values ( ) . for_each ( |id| self . add_any_id ( id) ) ;
64+
6365 match & item. inner {
6466 ItemEnum :: Import ( x) => self . check_import ( x) ,
6567 ItemEnum :: Union ( x) => self . check_union ( x) ,
@@ -376,6 +378,10 @@ impl<'a> Validator<'a> {
376378 }
377379 }
378380
381+ fn add_any_id ( & mut self , id : & ' a Id ) {
382+ self . add_id_checked ( id, |_| true , "any kind of item" ) ;
383+ }
384+
379385 fn add_field_id ( & mut self , id : & ' a Id ) {
380386 self . add_id_checked ( id, Kind :: is_struct_field, "StructField" ) ;
381387 }
@@ -446,3 +452,6 @@ fn set_remove<T: Hash + Eq + Clone>(set: &mut HashSet<T>) -> Option<T> {
446452 None
447453 }
448454}
455+
456+ #[ cfg( test) ]
457+ mod tests;
Original file line number Diff line number Diff line change 1+ use std:: collections:: HashMap ;
2+
3+ use rustdoc_json_types:: { Crate , Item , Visibility } ;
4+
5+ use super :: * ;
6+
7+ #[ track_caller]
8+ fn check ( krate : & Crate , errs : & [ Error ] ) {
9+ let mut validator = Validator :: new ( krate) ;
10+ validator. check_crate ( ) ;
11+
12+ assert_eq ! ( errs, & validator. errs[ ..] ) ;
13+ }
14+
15+ fn id ( s : & str ) -> Id {
16+ Id ( s. to_owned ( ) )
17+ }
18+
19+ #[ test]
20+ fn errors_on_missing_links ( ) {
21+ let k = Crate {
22+ root : id ( "0" ) ,
23+ crate_version : None ,
24+ includes_private : false ,
25+ index : HashMap :: from_iter ( [ (
26+ id ( "0" ) ,
27+ Item {
28+ name : Some ( "root" . to_owned ( ) ) ,
29+ id : id ( "" ) ,
30+ crate_id : 0 ,
31+ span : None ,
32+ visibility : Visibility :: Public ,
33+ docs : None ,
34+ links : HashMap :: from_iter ( [ ( "Not Found" . to_owned ( ) , id ( "1" ) ) ] ) ,
35+ attrs : vec ! [ ] ,
36+ deprecation : None ,
37+ inner : ItemEnum :: Module ( Module {
38+ is_crate : true ,
39+ items : vec ! [ ] ,
40+ is_stripped : false ,
41+ } ) ,
42+ } ,
43+ ) ] ) ,
44+ paths : HashMap :: new ( ) ,
45+ external_crates : HashMap :: new ( ) ,
46+ format_version : rustdoc_json_types:: FORMAT_VERSION ,
47+ } ;
48+
49+ check ( & k, & [ Error { kind : ErrorKind :: NotFound , id : id ( "1" ) } ] ) ;
50+ }
You can’t perform that action at this time.
0 commit comments