Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
6e85f46
Initial implementation of or-pattern usefulness checking
Nadrieril Nov 21, 2019
0030a77
Add some more tests
Nadrieril Nov 21, 2019
3b1c742
Add as_mut_ptr method to atomic types.
pitdicker Nov 23, 2019
23c5e58
Use as_mut_ptr instead of casts
pitdicker Nov 24, 2019
b5ec4d1
Address reviews
Nadrieril Nov 25, 2019
f8a4b6d
impl TrustedLen for vec::Drain
CAD97 Nov 25, 2019
cdc844e
Make the ice a fatal error
Nadrieril Nov 26, 2019
0881750
Move tests to ui, split them and add some
Nadrieril Nov 26, 2019
b41b1d3
Use LLVMAddAnalysisPasses instead of Rust's wrapper
Nov 29, 2019
45c4e11
SimplifyArmIdentity only for locals with the same type
tmiasko Nov 29, 2019
de30d31
rustc: fix ty::Const::eval's handling of inference variables.
eddyb Nov 29, 2019
584ede5
rustc_typeck: gate AnonConst's generics on feature(const_generics).
eddyb Nov 29, 2019
3d080a4
introduce crate rustc_feature and move active, accepted, and removed …
Centril Nov 29, 2019
048201f
move Stability to rustc_feature
Centril Nov 29, 2019
8ad4d15
move AttributeTemplate to builtin_attrs
Centril Nov 29, 2019
6cab02c
simplify gated cfgs logic
Centril Nov 30, 2019
4d9fde5
builtin_attrs: inline some strings
Centril Nov 30, 2019
d04b838
move is_builtin_attr to syntax::attr
Centril Nov 30, 2019
70234f1
builtin_attrs.rs -> rustc_feature
Centril Nov 30, 2019
db89679
inline two explanation constants
Centril Nov 30, 2019
b45f21d
move UnstableFeatures -> rustc_feature
Centril Nov 30, 2019
9626181
check.rs: inline a constant
Centril Nov 30, 2019
d353a4c
Make dec2flt_table compatible with rustfmt
dtolnay Nov 30, 2019
f4cff27
Make libcore/unicode/printable.rs compatible with rustfmt
dtolnay Nov 30, 2019
28eb31f
Make libcore/unicode/tables.rs compatible with rustfmt
dtolnay Nov 30, 2019
b756b7d
tidy: adjust feature gating path
Centril Nov 30, 2019
91fcd40
update rustc_feature crate docs
Centril Nov 30, 2019
79077f1
move GateIssue to rustc_feature & simplify emit_feature_err
Centril Nov 30, 2019
ded177a
derive(Default) for Features
Centril Nov 30, 2019
f34990e
Remove unneeded prelude imports in libcore tests
dtolnay Nov 30, 2019
4843173
Document why as_mut_ptr is safe
pitdicker Nov 30, 2019
d34090a
Fill tracking issue
pitdicker Nov 30, 2019
0f4c5fb
Apply suggestions from code review
Nadrieril Nov 30, 2019
3af14f9
Rollup merge of #66612 - Nadrieril:or-patterns-initial, r=varkor
Centril Nov 30, 2019
123406c
Rollup merge of #66705 - pitdicker:atomic_mut_ptr, r=KodrAus
Centril Nov 30, 2019
9ae7fb3
Rollup merge of #66759 - CAD97:patch-3, r=KodrAus
Centril Nov 30, 2019
2378651
Rollup merge of #66858 - 0dvictor:capi, r=rkruppe
Centril Nov 30, 2019
472bee2
Rollup merge of #66870 - tmiasko:simplify-ty, r=oli-obk
Centril Nov 30, 2019
c85f635
Rollup merge of #66883 - eddyb:we-cant-have-nice-things, r=oli-obk
Centril Nov 30, 2019
2e83c6d
Rollup merge of #66889 - dtolnay:fmt6, r=rkruppe
Centril Nov 30, 2019
b4bffce
Rollup merge of #66894 - dtolnay:prelude, r=Centril
Centril Nov 30, 2019
b772b5b
Rollup merge of #66895 - Centril:rustc_feature, r=oli-obk
Centril Nov 30, 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
move AttributeTemplate to builtin_attrs
  • Loading branch information
Centril committed Nov 29, 2019
commit 8ad4d15f3888f1339d52632d40e0a47697dd2a24
4 changes: 2 additions & 2 deletions src/librustc_lint/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ use rustc_feature::Stability;
use syntax::tokenstream::{TokenTree, TokenStream};
use syntax::ast::{self, Expr};
use syntax::ptr::P;
use syntax::attr::{self, HasAttrs, AttributeTemplate};
use syntax::attr::{self, HasAttrs};
use syntax::source_map::Spanned;
use syntax::edition::Edition;
use syntax::feature_gate::{AttributeGate, AttributeType};
use syntax::feature_gate::{AttributeGate, AttributeTemplate, AttributeType};
use syntax::feature_gate::deprecated_attributes;
use syntax_pos::{BytePos, Span};
use syntax::symbol::{Symbol, kw, sym};
Expand Down
17 changes: 14 additions & 3 deletions src/librustc_parse/validate_attr.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
//! Meta-syntax validation logic of attributes for post-expansion.

use errors::{PResult, Applicability};
use syntax::ast::{self, Attribute, AttrKind, Ident, MetaItem};
use syntax::attr::{AttributeTemplate, mk_name_value_item_str};
use syntax::feature_gate::AttributeTemplate;
use syntax::ast::{self, Attribute, AttrKind, Ident, MetaItem, MetaItemKind};
use syntax::attr::mk_name_value_item_str;
use syntax::early_buffered_lints::BufferedEarlyLintId;
use syntax::feature_gate::BUILTIN_ATTRIBUTE_MAP;
use syntax::token;
Expand Down Expand Up @@ -41,6 +42,16 @@ pub fn parse_meta<'a>(sess: &'a ParseSess, attr: &Attribute) -> PResult<'a, Meta
})
}

/// Checks that the given meta-item is compatible with this `AttributeTemplate`.
fn is_attr_template_compatible(template: &AttributeTemplate, meta: &ast::MetaItemKind) -> bool {
match meta {
MetaItemKind::Word => template.word,
MetaItemKind::List(..) => template.list.is_some(),
MetaItemKind::NameValue(lit) if lit.kind.is_str() => template.name_value_str.is_some(),
MetaItemKind::NameValue(..) => false,
}
}

pub fn check_builtin_attribute(
sess: &ParseSess,
attr: &Attribute,
Expand All @@ -57,7 +68,7 @@ pub fn check_builtin_attribute(
name == sym::test || name == sym::bench;

match parse_meta(sess, attr) {
Ok(meta) => if !should_skip(name) && !template.compatible(&meta.kind) {
Ok(meta) => if !should_skip(name) && !is_attr_template_compatible(&template, &meta.kind) {
let error_msg = format!("malformed `{}` attribute input", name);
let mut msg = "attribute must be of the form ".to_owned();
let mut suggestions = vec![];
Expand Down
25 changes: 0 additions & 25 deletions src/libsyntax/attr/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,6 @@ enum AttrError {
UnsupportedLiteral(&'static str, /* is_bytestr */ bool),
}

/// A template that the attribute input must match.
/// Only top-level shape (`#[attr]` vs `#[attr(...)]` vs `#[attr = ...]`) is considered now.
#[derive(Clone, Copy)]
pub struct AttributeTemplate {
pub word: bool,
pub list: Option<&'static str>,
pub name_value_str: Option<&'static str>,
}

impl AttributeTemplate {
pub fn only_word() -> Self {
Self { word: true, list: None, name_value_str: None }
}

/// Checks that the given meta-item is compatible with this template.
pub fn compatible(&self, meta_item_kind: &ast::MetaItemKind) -> bool {
match meta_item_kind {
ast::MetaItemKind::Word => self.word,
ast::MetaItemKind::List(..) => self.list.is_some(),
ast::MetaItemKind::NameValue(lit) if lit.kind.is_str() => self.name_value_str.is_some(),
ast::MetaItemKind::NameValue(..) => false,
}
}
}

fn handle_errors(sess: &ParseSess, span: Span, error: AttrError) {
let diag = &sess.span_diagnostic;
match error {
Expand Down
17 changes: 16 additions & 1 deletion src/libsyntax/feature_gate/builtin_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ use super::check::{EXPLAIN_ALLOW_INTERNAL_UNSAFE, EXPLAIN_ALLOW_INTERNAL_UNSTABL
use rustc_feature::{Features, Stability};

use crate::ast;
use crate::attr::AttributeTemplate;
use crate::sess::ParseSess;

use syntax_pos::symbol::{Symbol, sym};
use syntax_pos::Span;
use rustc_data_structures::fx::FxHashMap;
use lazy_static::lazy_static;


type GateFn = fn(&Features) -> bool;

macro_rules! cfg_fn {
Expand Down Expand Up @@ -108,6 +108,21 @@ impl AttributeGate {
}
}

/// A template that the attribute input must match.
/// Only top-level shape (`#[attr]` vs `#[attr(...)]` vs `#[attr = ...]`) is considered now.
#[derive(Clone, Copy)]
pub struct AttributeTemplate {
pub word: bool,
pub list: Option<&'static str>,
pub name_value_str: Option<&'static str>,
}

impl AttributeTemplate {
pub fn only_word() -> Self {
Self { word: true, list: None, name_value_str: None }
}
}

/// A convenience macro for constructing attribute templates.
/// E.g., `template!(Word, List: "description")` means that the attribute
/// supports forms `#[attr]` and `#[attr(description)]`.
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ pub mod feature_gate {
};
mod builtin_attrs;
pub use builtin_attrs::{
AttributeGate, AttributeType, GatedCfg,
AttributeGate, AttributeTemplate, AttributeType, GatedCfg,
BuiltinAttribute, BUILTIN_ATTRIBUTES, BUILTIN_ATTRIBUTE_MAP,
deprecated_attributes, is_builtin_attr, is_builtin_attr_name,
};
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax_ext/util.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use rustc_parse::validate_attr;
use syntax_pos::Symbol;
use syntax::ast::MetaItem;
use syntax::attr::AttributeTemplate;
use syntax::feature_gate::AttributeTemplate;
use syntax_expand::base::ExtCtxt;

pub fn check_builtin_macro_attribute(ecx: &ExtCtxt<'_>, meta_item: &MetaItem, name: Symbol) {
Expand Down