Fix source-links for files with absolute-paths
`clean_srcpath` tries to make the source-path relative to `src_root`, but this didn't work since `src_root` itself wasn't absolute.
This commit is contained in:
parent
27ca2507de
commit
cf76fcf30d
3 changed files with 33 additions and 8 deletions
|
@ -46,7 +46,7 @@ use std::io::prelude::*;
|
|||
use std::io::{self, BufWriter, BufReader};
|
||||
use std::iter::repeat;
|
||||
use std::mem;
|
||||
use std::path::{PathBuf, Path};
|
||||
use std::path::{PathBuf, Path, Component};
|
||||
use std::str;
|
||||
use std::sync::Arc;
|
||||
|
||||
|
@ -810,16 +810,17 @@ fn clean_srcpath<F>(src_root: &Path, p: &Path, keep_filename: bool, mut f: F) wh
|
|||
// make it relative, if possible
|
||||
let p = p.strip_prefix(src_root).unwrap_or(p);
|
||||
|
||||
let mut iter = p.iter().map(|x| x.to_str().unwrap()).peekable();
|
||||
let mut iter = p.components().peekable();
|
||||
|
||||
while let Some(c) = iter.next() {
|
||||
if !keep_filename && iter.peek().is_none() {
|
||||
break;
|
||||
}
|
||||
|
||||
if ".." == c {
|
||||
f("up");
|
||||
} else {
|
||||
f(c)
|
||||
match c {
|
||||
Component::ParentDir => f("up"),
|
||||
Component::Normal(c) => f(c.to_str().unwrap()),
|
||||
_ => continue,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -871,7 +872,7 @@ impl<'a> DocFolder for SourceCollector<'a> {
|
|||
// entire crate. The other option is maintaining this mapping on a
|
||||
// per-file basis, but that's probably not worth it...
|
||||
self.cx
|
||||
.include_sources = match self.emit_source(&item.source .filename) {
|
||||
.include_sources = match self.emit_source(&item.source.filename) {
|
||||
Ok(()) => true,
|
||||
Err(e) => {
|
||||
println!("warning: source code was requested to be rendered, \
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue