Skip to content

Commit 696e951

Browse files
authored
Rollup merge of rust-lang#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")]` (rust-lang#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.
2 parents 256bf2b + cbbb73b commit 696e951

File tree

7 files changed

+56
-9
lines changed

7 files changed

+56
-9
lines changed

src/librustc_lint/builtin.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,27 @@ impl MissingDoc {
349349
}
350350
}
351351

352-
let has_doc = attrs.iter().any(|a| a.is_value_str() && a.check_name("doc"));
352+
fn has_doc(attr: &ast::Attribute) -> bool {
353+
if !attr.check_name("doc") {
354+
return false;
355+
}
356+
357+
if attr.is_value_str() {
358+
return true;
359+
}
360+
361+
if let Some(list) = attr.meta_item_list() {
362+
for meta in list {
363+
if meta.check_name("include") {
364+
return true;
365+
}
366+
}
367+
}
368+
369+
false
370+
}
371+
372+
let has_doc = attrs.iter().any(|a| has_doc(a));
353373
if !has_doc {
354374
cx.span_lint(MISSING_DOCS,
355375
cx.tcx.sess.codemap().def_span(sp),

src/libsyntax/ext/expand.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,15 +1115,19 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> {
11151115
match File::open(&filename).and_then(|mut f| f.read_to_end(&mut buf)) {
11161116
Ok(..) => {}
11171117
Err(e) => {
1118-
self.cx.span_warn(at.span,
1119-
&format!("couldn't read {}: {}",
1120-
filename.display(),
1121-
e));
1118+
self.cx.span_err(at.span,
1119+
&format!("couldn't read {}: {}",
1120+
filename.display(),
1121+
e));
11221122
}
11231123
}
11241124

11251125
match String::from_utf8(buf) {
11261126
Ok(src) => {
1127+
// Add this input file to the code map to make it available as
1128+
// dependency information
1129+
self.cx.codemap().new_filemap_and_lines(&filename, &src);
1130+
11271131
let include_info = vec![
11281132
dummy_spanned(ast::NestedMetaItemKind::MetaItem(
11291133
attr::mk_name_value_item_str("file".into(),
@@ -1137,9 +1141,9 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> {
11371141
attr::mk_list_item("include".into(), include_info))));
11381142
}
11391143
Err(_) => {
1140-
self.cx.span_warn(at.span,
1141-
&format!("{} wasn't a utf-8 file",
1142-
filename.display()));
1144+
self.cx.span_err(at.span,
1145+
&format!("{} wasn't a utf-8 file",
1146+
filename.display()));
11431147
}
11441148
}
11451149
} else {
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2012-2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![feature(external_doc)]
12+
13+
#[doc(include = "not-a-file.md")] //~ ERROR: couldn't read
14+
pub struct SomeStruct;
15+
16+
fn main() {}

src/test/run-make/include_bytes_deps/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ ifneq ($(shell uname),FreeBSD)
88
ifndef IS_WINDOWS
99
all:
1010
$(RUSTC) --emit dep-info main.rs
11-
$(CGREP) "input.txt" "input.bin" < $(TMPDIR)/main.d
11+
$(CGREP) "input.txt" "input.bin" "input.md" < $(TMPDIR)/main.d
1212
else
1313
all:
1414

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Hello, world!

src/test/run-make/include_bytes_deps/main.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
#![feature(external_doc)]
12+
13+
#[doc(include="input.md")]
14+
pub struct SomeStruct;
15+
1116
pub fn main() {
1217
const INPUT_TXT: &'static str = include_str!("input.txt");
1318
const INPUT_BIN: &'static [u8] = include_bytes!("input.bin");

src/test/rustdoc/auxiliary/external-cross.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
// except according to those terms.
1010

1111
#![feature(external_doc)]
12+
#![deny(missing_doc)]
1213

1314
#[doc(include="external-cross-doc.md")]
1415
pub struct NeedMoreDocs;

0 commit comments

Comments
 (0)