From 06fbd599cf55b9e49dc54f5f7f356d19e4c2ffec Mon Sep 17 00:00:00 2001 From: QuietMisdreavus Date: Tue, 19 Dec 2017 15:04:03 -0600 Subject: [PATCH 1/5] turn errors with external docs into actual errors --- src/libsyntax/ext/expand.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index edf3d40be94a6..735588d29495d 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -1111,10 +1111,10 @@ 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)); } } @@ -1133,9 +1133,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 { From 8fc0d47581a42138dba0840bb5abf144c142bdd7 Mon Sep 17 00:00:00 2001 From: QuietMisdreavus Date: Tue, 19 Dec 2017 15:25:06 -0600 Subject: [PATCH 2/5] make the missing_docs lint check for doc(include) --- src/librustc_lint/builtin.rs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index 07874a8cc69dd..5438b6407a71b 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -349,7 +349,27 @@ impl MissingDoc { } } - let has_doc = attrs.iter().any(|a| a.is_value_str() && a.check_name("doc")); + fn has_doc(attr: &ast::Attribute) -> bool { + if !attr.check_name("doc") { + return false; + } + + if attr.is_value_str() { + return true; + } + + if let Some(list) = attr.meta_item_list() { + for meta in list { + if meta.check_name("include") { + return true; + } + } + } + + false + } + + let has_doc = attrs.iter().any(|a| has_doc(a)); if !has_doc { cx.span_lint(MISSING_DOCS, sp, From 95b87d18c0ba2ce019cab6fb75ab52460e6899e7 Mon Sep 17 00:00:00 2001 From: QuietMisdreavus Date: Tue, 19 Dec 2017 16:43:32 -0600 Subject: [PATCH 3/5] add files loaded through doc(include) into dep-info --- src/libsyntax/ext/expand.rs | 4 ++++ src/test/run-make/include_bytes_deps/Makefile | 2 +- src/test/run-make/include_bytes_deps/input.md | 1 + src/test/run-make/include_bytes_deps/main.rs | 5 +++++ 4 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 src/test/run-make/include_bytes_deps/input.md diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 735588d29495d..2b648f3d52b34 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -1120,6 +1120,10 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> { 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(), diff --git a/src/test/run-make/include_bytes_deps/Makefile b/src/test/run-make/include_bytes_deps/Makefile index f7b1d21ace281..1293695b79977 100644 --- a/src/test/run-make/include_bytes_deps/Makefile +++ b/src/test/run-make/include_bytes_deps/Makefile @@ -8,7 +8,7 @@ ifneq ($(shell uname),FreeBSD) ifndef IS_WINDOWS all: $(RUSTC) --emit dep-info main.rs - $(CGREP) "input.txt" "input.bin" < $(TMPDIR)/main.d + $(CGREP) "input.txt" "input.bin" "input.md" < $(TMPDIR)/main.d else all: diff --git a/src/test/run-make/include_bytes_deps/input.md b/src/test/run-make/include_bytes_deps/input.md new file mode 100644 index 0000000000000..2a19b7405f795 --- /dev/null +++ b/src/test/run-make/include_bytes_deps/input.md @@ -0,0 +1 @@ +# Hello, world! diff --git a/src/test/run-make/include_bytes_deps/main.rs b/src/test/run-make/include_bytes_deps/main.rs index 579b2a452a112..27ca1a46a500d 100644 --- a/src/test/run-make/include_bytes_deps/main.rs +++ b/src/test/run-make/include_bytes_deps/main.rs @@ -8,6 +8,11 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(external_doc)] + +#[doc(include="input.md")] +pub struct SomeStruct; + pub fn main() { const INPUT_TXT: &'static str = include_str!("input.txt"); const INPUT_BIN: &'static [u8] = include_bytes!("input.bin"); From f873c55709f9ad20523e347456feccd0f18f5aa0 Mon Sep 17 00:00:00 2001 From: QuietMisdreavus Date: Tue, 19 Dec 2017 16:43:46 -0600 Subject: [PATCH 4/5] test for missing_doc in the external_doc test --- src/test/rustdoc/auxiliary/external-cross.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/rustdoc/auxiliary/external-cross.rs b/src/test/rustdoc/auxiliary/external-cross.rs index cb14fec7abe7a..767fb05313adc 100644 --- a/src/test/rustdoc/auxiliary/external-cross.rs +++ b/src/test/rustdoc/auxiliary/external-cross.rs @@ -9,6 +9,7 @@ // except according to those terms. #![feature(external_doc)] +#![deny(missing_doc)] #[doc(include="external-cross-doc.md")] pub struct NeedMoreDocs; From cbbb73b56ff8137f38611233d36455294613d0ea Mon Sep 17 00:00:00 2001 From: QuietMisdreavus Date: Tue, 19 Dec 2017 16:50:53 -0600 Subject: [PATCH 5/5] add compile-fail error for external_doc errors --- src/test/compile-fail/external-doc-error.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/test/compile-fail/external-doc-error.rs diff --git a/src/test/compile-fail/external-doc-error.rs b/src/test/compile-fail/external-doc-error.rs new file mode 100644 index 0000000000000..1ae0d0bd2760a --- /dev/null +++ b/src/test/compile-fail/external-doc-error.rs @@ -0,0 +1,16 @@ +// Copyright 2012-2015 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![feature(external_doc)] + +#[doc(include = "not-a-file.md")] //~ ERROR: couldn't read +pub struct SomeStruct; + +fn main() {}