-
Notifications
You must be signed in to change notification settings - Fork 13.6k
More intra-doc links, add explicit exception list to linkchecker #74485
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
a594603
d6d48b4
3168b7d
4c48ac3
26ba0e1
e53fea7
9392a5e
a968093
4a324b8
8d470b5
ea70cc0
ec966ae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -23,6 +23,31 @@ use std::rc::Rc; | |||||
|
||||||
use crate::Redirect::*; | ||||||
|
||||||
// Add linkcheck exceptions here | ||||||
// If at all possible you should use intra-doc links to avoid linkcheck issues. These | ||||||
// are cases where that does not work | ||||||
const LINKCHECK_EXCEPTIONS: &[(&str, &[&str])] = &[ | ||||||
// These are methods on slice, and `Self` does not work on primitive impls | ||||||
// in intra-doc links (intra-doc links are weird) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 😆 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I actually meant to say "primitive impls are weird" lol |
||||||
// https://github.com/rust-lang/rust/issues/62834 is necessary to be | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you meant the issue on primitive types.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh, in my mind the generic issue is also what blocks slice, but your thing works |
||||||
// able to link to slices | ||||||
( | ||||||
"std/io/struct.IoSlice.html", | ||||||
&[ | ||||||
"#method.as_mut_ptr", | ||||||
"#method.sort_by_key", | ||||||
"#method.make_ascii_uppercase", | ||||||
"#method.make_ascii_lowercase", | ||||||
], | ||||||
), | ||||||
// These try to link to std::collections, but are defined in alloc | ||||||
// https://github.com/rust-lang/rust/issues/74481 | ||||||
("std/collections/btree_map/struct.BTreeMap.html", &["#insert-and-complex-keys"]), | ||||||
("std/collections/btree_set/struct.BTreeSet.html", &["#insert-and-complex-keys"]), | ||||||
("alloc/collections/btree_map/struct.BTreeMap.html", &["#insert-and-complex-keys"]), | ||||||
("alloc/collections/btree_set/struct.BTreeSet.html", &["#insert-and-complex-keys"]), | ||||||
]; | ||||||
|
||||||
macro_rules! t { | ||||||
($e:expr) => { | ||||||
match $e { | ||||||
|
@@ -111,30 +136,20 @@ fn walk(cache: &mut Cache, root: &Path, dir: &Path, errors: &mut bool) { | |||||
} | ||||||
} | ||||||
|
||||||
fn is_exception(file: &Path, link: &str) -> bool { | ||||||
if let Some(entry) = LINKCHECK_EXCEPTIONS.iter().find(|&(f, _)| file.ends_with(f)) { | ||||||
entry.1.contains(&link) | ||||||
} else { | ||||||
false | ||||||
} | ||||||
} | ||||||
|
||||||
fn check(cache: &mut Cache, root: &Path, file: &Path, errors: &mut bool) -> Option<PathBuf> { | ||||||
// Ignore non-HTML files. | ||||||
if file.extension().and_then(|s| s.to_str()) != Some("html") { | ||||||
return None; | ||||||
} | ||||||
|
||||||
// Unfortunately we're not 100% full of valid links today to we need a few | ||||||
// exceptions to get this past `make check` today. | ||||||
// FIXME(#32129) | ||||||
if file.ends_with("std/io/struct.IoSlice.html") | ||||||
{ | ||||||
return None; | ||||||
} | ||||||
|
||||||
// FIXME(#32130) | ||||||
if file.ends_with("alloc/collections/btree_map/struct.BTreeMap.html") | ||||||
|| file.ends_with("alloc/collections/btree_set/struct.BTreeSet.html") | ||||||
|| file.ends_with("std/collections/btree_map/struct.BTreeMap.html") | ||||||
|| file.ends_with("std/collections/btree_set/struct.BTreeSet.html") | ||||||
|| file.ends_with("std/collections/hash_set/struct.HashSet.html") | ||||||
{ | ||||||
return None; | ||||||
} | ||||||
|
||||||
let res = load_file(cache, root, file, SkipRedirect); | ||||||
let (pretty_file, contents) = match res { | ||||||
Ok(res) => res, | ||||||
|
@@ -249,17 +264,20 @@ fn check(cache: &mut Cache, root: &Path, file: &Path, errors: &mut bool) -> Opti | |||||
let entry = &mut cache.get_mut(&pretty_path).unwrap(); | ||||||
entry.parse_ids(&pretty_path, &contents, errors); | ||||||
|
||||||
if !entry.ids.contains(*fragment) { | ||||||
if !entry.ids.contains(*fragment) && !is_exception(file, &format!("#{}", fragment)) | ||||||
{ | ||||||
*errors = true; | ||||||
print!("{}:{}: broken link fragment ", pretty_file.display(), i + 1); | ||||||
println!("`#{}` pointing to `{}`", fragment, pretty_path.display()); | ||||||
}; | ||||||
} | ||||||
} else { | ||||||
*errors = true; | ||||||
print!("{}:{}: broken link - ", pretty_file.display(), i + 1); | ||||||
let pretty_path = path.strip_prefix(root).unwrap_or(&path); | ||||||
println!("{}", pretty_path.display()); | ||||||
if !is_exception(file, pretty_path.to_str().unwrap()) { | ||||||
*errors = true; | ||||||
print!("{}:{}: broken link - ", pretty_file.display(), i + 1); | ||||||
println!("{}", pretty_path.display()); | ||||||
} | ||||||
} | ||||||
}); | ||||||
Some(pretty_file) | ||||||
|
Uh oh!
There was an error while loading. Please reload this page.