Make #[doc(include)] paths behave like other paths

This makes them relative to the containing file instead of the crate
root
This commit is contained in:
Jonas Schievink
2019-05-18 15:56:53 +02:00
parent ba78db310b
commit 138e08ccf6
2 changed files with 34 additions and 21 deletions

View File

@@ -17,6 +17,7 @@ use crate::symbol::{sym, Symbol};
use crate::tokenstream::{TokenStream, TokenTree};
use crate::visit::{self, Visitor};
use crate::util::map_in_place::MapInPlace;
use crate::util::path;
use errors::{Applicability, FatalError};
use smallvec::{smallvec, SmallVec};
@@ -1253,7 +1254,7 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
return noop_visit_attribute(at, self);
}
let filename = self.cx.root_path.join(file.to_string());
let filename = path::resolve(&*file.as_str(), it.span(), self.cx.source_map());
match fs::read_to_string(&filename) {
Ok(src) => {
let src_interned = Symbol::intern(&src);
@@ -1302,10 +1303,6 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
);
err.span_label(lit.span, "couldn't read file");
if e.kind() == ErrorKind::NotFound {
err.help("external doc paths are relative to the crate root");
}
err.emit();
}
}