Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
0f47327
Remove i686-unknown-dragonfly target
tuxillo Dec 12, 2019
641ccd5
Fix signature of `__wasilibc_find_relpath`
alexcrichton Dec 12, 2019
8f3021b
Get active features dynamically by their `Symbol`
ecstatic-morse Dec 10, 2019
57959b2
Add feature gate for `const_loop`
ecstatic-morse Dec 10, 2019
8f59902
Put MIR checks for loops behind the feature flag
ecstatic-morse Dec 10, 2019
ee233c0
Restructue HIR const-checker to handle features with multiple gates
ecstatic-morse Dec 10, 2019
99e132d
Extend control flow basics tests with loops
ecstatic-morse Dec 11, 2019
1122404
Add qualif smoke tests for const loops
ecstatic-morse Dec 11, 2019
caa7c99
Bless unrelated tests with new help message
ecstatic-morse Dec 11, 2019
3325671
Bless modified tests
ecstatic-morse Dec 11, 2019
2add77d
Improve message when active feature indexing panics
ecstatic-morse Dec 11, 2019
a8e997c
Improve comment
ecstatic-morse Dec 11, 2019
a2a0774
Look for "unstable feature" error code in test
ecstatic-morse Dec 11, 2019
b3aecd0
Fix grammar in test description
ecstatic-morse Dec 11, 2019
2b5ae1c
Apply suggestions from review
ecstatic-morse Dec 11, 2019
80581be
Replace `Index` impl with `enabled` method
ecstatic-morse Dec 11, 2019
34ce0ba
Use better name for local containing required feature gates
ecstatic-morse Dec 11, 2019
598bed6
Ensure test actually uses dataflow, not simulation
ecstatic-morse Dec 11, 2019
029725f
Use correct nightly version for feature
ecstatic-morse Dec 11, 2019
0f0bfc9
Document `Features::enabled`
ecstatic-morse Dec 12, 2019
faa52d1
Correctly mark things as `min_const_fn`
ecstatic-morse Dec 13, 2019
b65c6ec
Fix incorrect example code of OpenOptions::open
pjw91 Dec 13, 2019
f5e9bda
doc comments: Less attribute mimicking
petrochenkov Dec 7, 2019
d720440
Rollup merge of #67151 - petrochenkov:docomm, r=estebank
Centril Dec 14, 2019
0e2fb73
Rollup merge of #67216 - ecstatic-morse:const-loop, r=oli-obk
Centril Dec 14, 2019
393ddd6
Rollup merge of #67255 - tuxillo:remove-i686-unknown-dragonfly, r=ale…
Centril Dec 14, 2019
18cbf24
Rollup merge of #67267 - alexcrichton:update-wasi-libc, r=Dylan-DPC
Centril Dec 14, 2019
389aa5f
Rollup merge of #67282 - pjw91:patch-1, r=Dylan-DPC
Centril Dec 14, 2019
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
Prev Previous commit
Next Next commit
doc comments: Less attribute mimicking
  • Loading branch information
petrochenkov committed Dec 14, 2019
commit f5e9bda989afc0d5e2a40927b9eff8ebda357982
6 changes: 5 additions & 1 deletion src/librustc_lint/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,10 @@ pub struct MissingDoc {
impl_lint_pass!(MissingDoc => [MISSING_DOCS]);

fn has_doc(attr: &ast::Attribute) -> bool {
if attr.is_doc_comment() {
return true;
}

if !attr.check_name(sym::doc) {
return false;
}
Expand Down Expand Up @@ -751,7 +755,7 @@ impl UnusedDocComment {

let span = sugared_span.take().unwrap_or_else(|| attr.span);

if attr.check_name(sym::doc) {
if attr.is_doc_comment() || attr.check_name(sym::doc) {
let mut err = cx.struct_span_lint(UNUSED_DOC_COMMENTS, span, "unused doc comment");

err.span_label(
Expand Down
4 changes: 4 additions & 0 deletions src/librustc_lint/unused.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedAttributes {
fn check_attribute(&mut self, cx: &LateContext<'_, '_>, attr: &ast::Attribute) {
debug!("checking attribute: {:?}", attr);

if attr.is_doc_comment() {
return;
}

let attr_info = attr.ident().and_then(|ident| self.builtin_attributes.get(&ident.name));

if let Some(&&(name, ty, ..)) = attr_info {
Expand Down
39 changes: 19 additions & 20 deletions src/librustc_parse/validate_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@ use crate::parse_in;

use rustc_errors::{PResult, Applicability};
use rustc_feature::{AttributeTemplate, BUILTIN_ATTRIBUTE_MAP};
use syntax::ast::{self, Attribute, AttrKind, Ident, MacArgs, MacDelimiter, MetaItem, MetaItemKind};
use syntax::attr::mk_name_value_item_str;
use syntax::ast::{self, Attribute, MacArgs, MacDelimiter, MetaItem, MetaItemKind};
use syntax::early_buffered_lints::ILL_FORMED_ATTRIBUTE_INPUT;
use syntax::tokenstream::DelimSpan;
use syntax::sess::ParseSess;
use syntax_pos::{Symbol, sym};

pub fn check_meta(sess: &ParseSess, attr: &Attribute) {
if attr.is_doc_comment() {
return;
}

let attr_info =
attr.ident().and_then(|ident| BUILTIN_ATTRIBUTE_MAP.get(&ident.name)).map(|a| **a);

Expand All @@ -28,25 +31,21 @@ pub fn check_meta(sess: &ParseSess, attr: &Attribute) {
}

pub fn parse_meta<'a>(sess: &'a ParseSess, attr: &Attribute) -> PResult<'a, MetaItem> {
Ok(match attr.kind {
AttrKind::Normal(ref item) => MetaItem {
span: attr.span,
path: item.path.clone(),
kind: match &attr.get_normal_item().args {
MacArgs::Empty => MetaItemKind::Word,
MacArgs::Eq(_, t) => {
let v = parse_in(sess, t.clone(), "name value", |p| p.parse_unsuffixed_lit())?;
MetaItemKind::NameValue(v)
}
MacArgs::Delimited(dspan, delim, t) => {
check_meta_bad_delim(sess, *dspan, *delim, "wrong meta list delimiters");
let nmis = parse_in(sess, t.clone(), "meta list", |p| p.parse_meta_seq_top())?;
MetaItemKind::List(nmis)
}
let item = attr.get_normal_item();
Ok(MetaItem {
span: attr.span,
path: item.path.clone(),
kind: match &item.args {
MacArgs::Empty => MetaItemKind::Word,
MacArgs::Eq(_, t) => {
let v = parse_in(sess, t.clone(), "name value", |p| p.parse_unsuffixed_lit())?;
MetaItemKind::NameValue(v)
}
MacArgs::Delimited(dspan, delim, t) => {
check_meta_bad_delim(sess, *dspan, *delim, "wrong meta list delimiters");
let nmis = parse_in(sess, t.clone(), "meta list", |p| p.parse_meta_seq_top())?;
MetaItemKind::List(nmis)
}
},
AttrKind::DocComment(comment) => {
mk_name_value_item_str(Ident::new(sym::doc, attr.span), comment, attr.span)
}
})
}
Expand Down
18 changes: 9 additions & 9 deletions src/librustc_save_analysis/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -883,15 +883,15 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
let mut result = String::new();

for attr in attrs {
if attr.check_name(sym::doc) {
if let Some(val) = attr.value_str() {
if attr.is_doc_comment() {
result.push_str(&strip_doc_comment_decoration(&val.as_str()));
} else {
result.push_str(&val.as_str());
}
result.push('\n');
} else if let Some(meta_list) = attr.meta_item_list() {
if let Some(val) = attr.doc_str() {
if attr.is_doc_comment() {
result.push_str(&strip_doc_comment_decoration(&val.as_str()));
} else {
result.push_str(&val.as_str());
}
result.push('\n');
} else if attr.check_name(sym::doc) {
if let Some(meta_list) = attr.meta_item_list() {
meta_list.into_iter()
.filter(|it| it.check_name(sym::include))
.filter_map(|it| it.meta_item_list().map(|l| l.to_owned()))
Expand Down
67 changes: 21 additions & 46 deletions src/librustdoc/clean/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ use rustc::ty::layout::VariantIdx;
use rustc::util::nodemap::{FxHashMap, FxHashSet};
use rustc_index::vec::IndexVec;
use rustc_target::spec::abi::Abi;
use syntax::ast::{self, Attribute, AttrStyle, AttrKind, Ident};
use syntax::ast::{self, AttrStyle, Ident};
use syntax::attr;
use syntax::util::comments;
use syntax::util::comments::strip_doc_comment_decoration;
use syntax::source_map::DUMMY_SP;
use syntax_pos::hygiene::MacroKind;
use syntax_pos::symbol::{Symbol, sym};
Expand Down Expand Up @@ -507,51 +507,26 @@ impl Attributes {
let mut cfg = Cfg::True;
let mut doc_line = 0;

/// If `attr` is a doc comment, strips the leading and (if present)
/// trailing comments symbols, e.g. `///`, `/**`, and `*/`. Otherwise,
/// returns `attr` unchanged.
pub fn with_doc_comment_markers_stripped<T>(
attr: &Attribute,
f: impl FnOnce(&Attribute) -> T,
) -> T {
match attr.kind {
AttrKind::Normal(_) => {
f(attr)
}
AttrKind::DocComment(comment) => {
let comment =
Symbol::intern(&comments::strip_doc_comment_decoration(&comment.as_str()));
f(&Attribute {
kind: AttrKind::DocComment(comment),
id: attr.id,
style: attr.style,
span: attr.span,
})
}
}
}

let other_attrs = attrs.iter().filter_map(|attr| {
with_doc_comment_markers_stripped(attr, |attr| {
if attr.check_name(sym::doc) {
if let Some(mi) = attr.meta() {
if let Some(value) = mi.value_str() {
// Extracted #[doc = "..."]
let value = value.to_string();
let line = doc_line;
doc_line += value.lines().count();
if let Some(value) = attr.doc_str() {
let (value, mk_fragment): (_, fn(_, _, _) -> _) = if attr.is_doc_comment() {
(strip_doc_comment_decoration(&value.as_str()), DocFragment::SugaredDoc)
} else {
(value.to_string(), DocFragment::RawDoc)
};

if attr.is_doc_comment() {
doc_strings.push(DocFragment::SugaredDoc(line, attr.span, value));
} else {
doc_strings.push(DocFragment::RawDoc(line, attr.span, value));
}
let line = doc_line;
doc_line += value.lines().count();
doc_strings.push(mk_fragment(line, attr.span, value));

if sp.is_none() {
sp = Some(attr.span);
}
return None;
} else if let Some(cfg_mi) = Attributes::extract_cfg(&mi) {
if sp.is_none() {
sp = Some(attr.span);
}
None
} else {
if attr.check_name(sym::doc) {
if let Some(mi) = attr.meta() {
if let Some(cfg_mi) = Attributes::extract_cfg(&mi) {
// Extracted #[doc(cfg(...))]
match Cfg::parse(cfg_mi) {
Ok(new_cfg) => cfg &= new_cfg,
Expand All @@ -570,7 +545,7 @@ impl Attributes {
}
}
Some(attr.clone())
})
}
}).collect();

// treat #[target_feature(enable = "feat")] attributes as if they were
Expand All @@ -589,7 +564,7 @@ impl Attributes {
}

let inner_docs = attrs.iter()
.filter(|a| a.check_name(sym::doc))
.filter(|a| a.doc_str().is_some())
.next()
.map_or(true, |a| a.style == AttrStyle::Inner);

Expand Down
4 changes: 0 additions & 4 deletions src/libsyntax/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2362,10 +2362,6 @@ pub enum AttrKind {
/// A doc comment (e.g. `/// ...`, `//! ...`, `/** ... */`, `/*! ... */`).
/// Doc attributes (e.g. `#[doc="..."]`) are represented with the `Normal`
/// variant (which is much less compact and thus more expensive).
///
/// Note: `self.has_name(sym::doc)` and `self.check_name(sym::doc)` succeed
/// for this variant, but this may change in the future.
/// ```
DocComment(Symbol),
}

Expand Down
1 change: 1 addition & 0 deletions src/libsyntax/attr/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use rustc_macros::HashStable_Generic;
use rustc_error_codes::*;

pub fn is_builtin_attr(attr: &Attribute) -> bool {
attr.is_doc_comment() ||
attr.ident().filter(|ident| is_builtin_attr_name(ident.name)).is_some()
}

Expand Down
22 changes: 15 additions & 7 deletions src/libsyntax/attr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ impl Attribute {
pub fn has_name(&self, name: Symbol) -> bool {
match self.kind {
AttrKind::Normal(ref item) => item.path == name,
AttrKind::DocComment(_) => name == sym::doc,
AttrKind::DocComment(_) => false,
}
}

Expand All @@ -168,7 +168,7 @@ impl Attribute {
None
}
}
AttrKind::DocComment(_) => Some(Ident::new(sym::doc, self.span)),
AttrKind::DocComment(_) => None,
}
}
pub fn name_or_empty(&self) -> Symbol {
Expand All @@ -180,7 +180,7 @@ impl Attribute {
AttrKind::Normal(ref item) => {
item.meta(self.span).and_then(|meta| meta.value_str())
}
AttrKind::DocComment(comment) => Some(comment),
AttrKind::DocComment(..) => None,
}
}

Expand Down Expand Up @@ -294,26 +294,34 @@ impl Attribute {
}
}

pub fn doc_str(&self) -> Option<Symbol> {
match self.kind {
AttrKind::DocComment(symbol) => Some(symbol),
AttrKind::Normal(ref item) if item.path == sym::doc =>
item.meta(self.span).and_then(|meta| meta.value_str()),
_ => None,
}
}

pub fn get_normal_item(&self) -> &AttrItem {
match self.kind {
AttrKind::Normal(ref item) => item,
AttrKind::DocComment(_) => panic!("unexpected sugared doc"),
AttrKind::DocComment(_) => panic!("unexpected doc comment"),
}
}

pub fn unwrap_normal_item(self) -> AttrItem {
match self.kind {
AttrKind::Normal(item) => item,
AttrKind::DocComment(_) => panic!("unexpected sugared doc"),
AttrKind::DocComment(_) => panic!("unexpected doc comment"),
}
}

/// Extracts the MetaItem from inside this Attribute.
pub fn meta(&self) -> Option<MetaItem> {
match self.kind {
AttrKind::Normal(ref item) => item.meta(self.span),
AttrKind::DocComment(comment) =>
Some(mk_name_value_item_str(Ident::new(sym::doc, self.span), comment, self.span)),
AttrKind::DocComment(..) => None,
}
}
}
Expand Down
12 changes: 5 additions & 7 deletions src/libsyntax_expand/parse/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ use crate::tests::{matches_codepattern, string_to_stream, with_error_checking_pa

use rustc_parse::new_parser_from_source_str;
use syntax::ast::{self, Name, PatKind};
use syntax::attr::first_attr_value_str_by_name;
use syntax::sess::ParseSess;
use syntax::token::{self, Token};
use syntax::print::pprust::item_to_string;
use syntax::ptr::P;
use syntax::source_map::FilePathMapping;
use syntax::symbol::{kw, sym};
use syntax::symbol::{kw, sym, Symbol};
use syntax::tokenstream::{DelimSpan, TokenTree, TokenStream};
use syntax::visit;
use syntax::with_default_globals;
Expand Down Expand Up @@ -238,22 +237,21 @@ let mut fflags: c_int = wb();
let source = "/// doc comment\r\nfn foo() {}".to_string();
let item = parse_item_from_source_str(name_1, source, &sess)
.unwrap().unwrap();
let doc = first_attr_value_str_by_name(&item.attrs, sym::doc).unwrap();
let doc = item.attrs.iter().filter_map(|at| at.doc_str()).next().unwrap();
assert_eq!(doc.as_str(), "/// doc comment");

let name_2 = FileName::Custom("crlf_source_2".to_string());
let source = "/// doc comment\r\n/// line 2\r\nfn foo() {}".to_string();
let item = parse_item_from_source_str(name_2, source, &sess)
.unwrap().unwrap();
let docs = item.attrs.iter().filter(|a| a.has_name(sym::doc))
.map(|a| a.value_str().unwrap().to_string()).collect::<Vec<_>>();
let b: &[_] = &["/// doc comment".to_string(), "/// line 2".to_string()];
let docs = item.attrs.iter().filter_map(|at| at.doc_str()).collect::<Vec<_>>();
let b: &[_] = &[Symbol::intern("/// doc comment"), Symbol::intern("/// line 2")];
assert_eq!(&docs[..], b);

let name_3 = FileName::Custom("clrf_source_3".to_string());
let source = "/** doc comment\r\n * with CRLF */\r\nfn foo() {}".to_string();
let item = parse_item_from_source_str(name_3, source, &sess).unwrap().unwrap();
let doc = first_attr_value_str_by_name(&item.attrs, sym::doc).unwrap();
let doc = item.attrs.iter().filter_map(|at| at.doc_str()).next().unwrap();
assert_eq!(doc.as_str(), "/** doc comment\n * with CRLF */");
});
}
Expand Down