diff options
| author | Yuki Okushi <huyuumi.dev+love@gmail.com> | 2022-12-03 12:51:29 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-12-03 12:51:29 +0900 |
| commit | 9afa850d39965d27502f0eaadeea879f156e5ae0 (patch) | |
| tree | eaff43adecf7cd678c3df26bdde6ef4cbec17536 /src/tools | |
| parent | 8f368666b55e4573f1399eb71ac4ee024234dfbb (diff) | |
| parent | 79d897b22a3b091f8300fffe96ffb68a0dbd1293 (diff) | |
| download | rust-9afa850d39965d27502f0eaadeea879f156e5ae0.tar.gz rust-9afa850d39965d27502f0eaadeea879f156e5ae0.zip | |
Rollup merge of #105182 - aDotInTheVoid:rdj-no-foreign-traits, r=Enselic,GuillaumeGomez
Rustdoc-Json: Don't inline foreign traits It wasn't done correctly, and [we want to move towards only having local items in the index, and making foreign items easier to resolved](https://rust-lang.zulipchat.com/#narrow/stream/266220-rustdoc/topic/Rustdoc.20JSON.3A.20Include.20All.20Foreign.20Items.3F) Fixes #105025. This means #105015 is included to test this Fixes #105022 r? `@GuillaumeGomez`
Diffstat (limited to 'src/tools')
| -rw-r--r-- | src/tools/jsondoclint/src/validator.rs | 9 | ||||
| -rw-r--r-- | src/tools/jsondoclint/src/validator/tests.rs | 50 |
2 files changed, 59 insertions, 0 deletions
diff --git a/src/tools/jsondoclint/src/validator.rs b/src/tools/jsondoclint/src/validator.rs index 5046ab9c7cb..e15f5fe3ccc 100644 --- a/src/tools/jsondoclint/src/validator.rs +++ b/src/tools/jsondoclint/src/validator.rs @@ -60,6 +60,8 @@ impl<'a> Validator<'a> { fn check_item(&mut self, id: &'a Id) { if let Some(item) = &self.krate.index.get(id) { + item.links.values().for_each(|id| self.add_any_id(id)); + match &item.inner { ItemEnum::Import(x) => self.check_import(x), ItemEnum::Union(x) => self.check_union(x), @@ -376,6 +378,10 @@ impl<'a> Validator<'a> { } } + fn add_any_id(&mut self, id: &'a Id) { + self.add_id_checked(id, |_| true, "any kind of item"); + } + fn add_field_id(&mut self, id: &'a Id) { self.add_id_checked(id, Kind::is_struct_field, "StructField"); } @@ -446,3 +452,6 @@ fn set_remove<T: Hash + Eq + Clone>(set: &mut HashSet<T>) -> Option<T> { None } } + +#[cfg(test)] +mod tests; diff --git a/src/tools/jsondoclint/src/validator/tests.rs b/src/tools/jsondoclint/src/validator/tests.rs new file mode 100644 index 00000000000..c4aeee9c53b --- /dev/null +++ b/src/tools/jsondoclint/src/validator/tests.rs @@ -0,0 +1,50 @@ +use std::collections::HashMap; + +use rustdoc_json_types::{Crate, Item, Visibility}; + +use super::*; + +#[track_caller] +fn check(krate: &Crate, errs: &[Error]) { + let mut validator = Validator::new(krate); + validator.check_crate(); + + assert_eq!(errs, &validator.errs[..]); +} + +fn id(s: &str) -> Id { + Id(s.to_owned()) +} + +#[test] +fn errors_on_missing_links() { + let k = Crate { + root: id("0"), + crate_version: None, + includes_private: false, + index: HashMap::from_iter([( + id("0"), + Item { + name: Some("root".to_owned()), + id: id(""), + crate_id: 0, + span: None, + visibility: Visibility::Public, + docs: None, + links: HashMap::from_iter([("Not Found".to_owned(), id("1"))]), + attrs: vec![], + deprecation: None, + inner: ItemEnum::Module(Module { + is_crate: true, + items: vec![], + is_stripped: false, + }), + }, + )]), + paths: HashMap::new(), + external_crates: HashMap::new(), + format_version: rustdoc_json_types::FORMAT_VERSION, + }; + + check(&k, &[Error { kind: ErrorKind::NotFound, id: id("1") }]); +} |
