File tree 2 files changed +59
-0
lines changed
src/tools/jsondoclint/src
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> {
60
60
61
61
fn check_item ( & mut self , id : & ' a Id ) {
62
62
if let Some ( item) = & self . krate . index . get ( id) {
63
+ item. links . values ( ) . for_each ( |id| self . add_any_id ( id) ) ;
64
+
63
65
match & item. inner {
64
66
ItemEnum :: Import ( x) => self . check_import ( x) ,
65
67
ItemEnum :: Union ( x) => self . check_union ( x) ,
@@ -376,6 +378,10 @@ impl<'a> Validator<'a> {
376
378
}
377
379
}
378
380
381
+ fn add_any_id ( & mut self , id : & ' a Id ) {
382
+ self . add_id_checked ( id, |_| true , "any kind of item" ) ;
383
+ }
384
+
379
385
fn add_field_id ( & mut self , id : & ' a Id ) {
380
386
self . add_id_checked ( id, Kind :: is_struct_field, "StructField" ) ;
381
387
}
@@ -446,3 +452,6 @@ fn set_remove<T: Hash + Eq + Clone>(set: &mut HashSet<T>) -> Option<T> {
446
452
None
447
453
}
448
454
}
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