Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tweaks and fixes for doc(include) #46858

Merged
merged 5 commits into from
Dec 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion src/librustc_lint/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
18 changes: 11 additions & 7 deletions src/libsyntax/ext/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1111,15 +1111,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(),
Expand All @@ -1133,9 +1137,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 {
Expand Down
16 changes: 16 additions & 0 deletions src/test/compile-fail/external-doc-error.rs
Original file line number Diff line number Diff line change
@@ -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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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() {}
2 changes: 1 addition & 1 deletion src/test/run-make/include_bytes_deps/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
1 change: 1 addition & 0 deletions src/test/run-make/include_bytes_deps/input.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Hello, world!
5 changes: 5 additions & 0 deletions src/test/run-make/include_bytes_deps/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
1 change: 1 addition & 0 deletions src/test/rustdoc/auxiliary/external-cross.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
// except according to those terms.

#![feature(external_doc)]
#![deny(missing_doc)]

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