Rollup merge of #46858 - QuietMisdreavus:external-doc-error, r=estebank

tweaks and fixes for doc(include)

This PR makes a handful of changes around `#[doc(include="file.md")]` (https://github.com/rust-lang/rust/issues/44732):

* Turns errors when loading files into full errors. This matches the original RFC text.
* Makes the `missing_docs` lint check for `#[doc(include="file.md")]` as well as regular `#[doc="text"]` attributes.
* Loads files included by `#[doc(include="file.md")]` into dep-info, mirroring the behavior of `include_str!()` and friends.
* Adds or modifies tests to check for all of these.
This commit is contained in:
kennytm
2017-12-22 02:50:53 +08:00
committed by GitHub
7 changed files with 56 additions and 9 deletions

View File

@@ -1115,15 +1115,19 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> {
match File::open(&filename).and_then(|mut f| f.read_to_end(&mut buf)) {
Ok(..) => {}
Err(e) => {
self.cx.span_warn(at.span,
&format!("couldn't read {}: {}",
filename.display(),
e));
self.cx.span_err(at.span,
&format!("couldn't read {}: {}",
filename.display(),
e));
}
}
match String::from_utf8(buf) {
Ok(src) => {
// Add this input file to the code map to make it available as
// dependency information
self.cx.codemap().new_filemap_and_lines(&filename, &src);
let include_info = vec![
dummy_spanned(ast::NestedMetaItemKind::MetaItem(
attr::mk_name_value_item_str("file".into(),
@@ -1137,9 +1141,9 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> {
attr::mk_list_item("include".into(), include_info))));
}
Err(_) => {
self.cx.span_warn(at.span,
&format!("{} wasn't a utf-8 file",
filename.display()));
self.cx.span_err(at.span,
&format!("{} wasn't a utf-8 file",
filename.display()));
}
}
} else {