Skip to content

Commit bae70ac

Browse files
committed
---
yaml --- r: 275965 b: refs/heads/master c: 009a649 h: refs/heads/master i: 275963: ccc9baf
1 parent 4e96d6f commit bae70ac

File tree

17 files changed

+669
-692
lines changed

17 files changed

+669
-692
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 5bda576cd6b3be40f62a37e134ee7245e911fb8b
2+
refs/heads/master: 009a64916e7f51df7e4e4e1df603eb4be1c7a6d8
33
refs/heads/snap-stage3: 235d77457d80b549dad3ac36d94f235208a1eafb
44
refs/heads/try: 49312a405e14a449b98fe0056b12a40ac128be4a
55
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105

trunk/src/librustc_driver/driver.rs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -528,19 +528,13 @@ pub fn phase_2_configure_and_expand(sess: &Session,
528528
middle::recursion_limit::update_recursion_limit(sess, &krate);
529529
});
530530

531-
time(time_passes, "gated macro checking", || {
532-
sess.track_errors(|| {
533-
let features =
534-
syntax::feature_gate::check_crate_macros(sess.codemap(),
535-
&sess.parse_sess.span_diagnostic,
536-
&krate);
537-
538-
// these need to be set "early" so that expansion sees `quote` if enabled.
539-
*sess.features.borrow_mut() = features;
540-
})
531+
// these need to be set "early" so that expansion sees `quote` if enabled.
532+
sess.track_errors(|| {
533+
*sess.features.borrow_mut() =
534+
syntax::feature_gate::get_features(&sess.parse_sess.span_diagnostic,
535+
&krate);
541536
})?;
542537

543-
544538
krate = time(time_passes, "crate injection", || {
545539
syntax::std_inject::maybe_inject_crates_ref(krate, sess.opts.alt_std_name.clone())
546540
});

trunk/src/librustc_plugin/load.rs

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -51,27 +51,32 @@ pub fn load_plugins(sess: &Session,
5151
addl_plugins: Option<Vec<String>>) -> Vec<PluginRegistrar> {
5252
let mut loader = PluginLoader::new(sess, cstore, crate_name);
5353

54-
for attr in &krate.attrs {
55-
if !attr.check_name("plugin") {
56-
continue;
57-
}
58-
59-
let plugins = match attr.meta_item_list() {
60-
Some(xs) => xs,
61-
None => {
62-
call_malformed_plugin_attribute(sess, attr.span);
54+
// do not report any error now. since crate attributes are
55+
// not touched by expansion, every use of plugin without
56+
// the feature enabled will result in an error later...
57+
if sess.features.borrow().plugin {
58+
for attr in &krate.attrs {
59+
if !attr.check_name("plugin") {
6360
continue;
6461
}
65-
};
6662

67-
for plugin in plugins {
68-
if plugin.value_str().is_some() {
69-
call_malformed_plugin_attribute(sess, attr.span);
70-
continue;
63+
let plugins = match attr.meta_item_list() {
64+
Some(xs) => xs,
65+
None => {
66+
call_malformed_plugin_attribute(sess, attr.span);
67+
continue;
68+
}
69+
};
70+
71+
for plugin in plugins {
72+
if plugin.value_str().is_some() {
73+
call_malformed_plugin_attribute(sess, attr.span);
74+
continue;
75+
}
76+
77+
let args = plugin.meta_item_list().map(ToOwned::to_owned).unwrap_or_default();
78+
loader.load_plugin(plugin.span, &plugin.name(), args);
7179
}
72-
73-
let args = plugin.meta_item_list().map(ToOwned::to_owned).unwrap_or_default();
74-
loader.load_plugin(plugin.span, &plugin.name(), args);
7580
}
7681
}
7782

trunk/src/librustdoc/clean/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1721,7 +1721,7 @@ impl<'tcx> Clean<Type> for ty::Ty<'tcx> {
17211721
where_predicates: Vec::new()
17221722
},
17231723
decl: (cx.map.local_def_id(0), &fty.sig).clean(cx),
1724-
abi: fty.abi.to_string(),
1724+
abi: fty.abi,
17251725
}),
17261726
ty::TyStruct(def, substs) |
17271727
ty::TyEnum(def, substs) => {
@@ -2143,7 +2143,7 @@ pub struct BareFunctionDecl {
21432143
pub unsafety: hir::Unsafety,
21442144
pub generics: Generics,
21452145
pub decl: FnDecl,
2146-
pub abi: String,
2146+
pub abi: Abi,
21472147
}
21482148

21492149
impl Clean<BareFunctionDecl> for hir::BareFnTy {
@@ -2156,7 +2156,7 @@ impl Clean<BareFunctionDecl> for hir::BareFnTy {
21562156
where_predicates: Vec::new()
21572157
},
21582158
decl: self.decl.clean(cx),
2159-
abi: self.abi.to_string(),
2159+
abi: self.abi,
21602160
}
21612161
}
21622162
}

trunk/src/librustdoc/html/format.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -468,11 +468,7 @@ impl fmt::Display for clean::Type {
468468
clean::BareFunction(ref decl) => {
469469
write!(f, "{}{}fn{}{}",
470470
UnsafetySpace(decl.unsafety),
471-
match &*decl.abi {
472-
"" => " extern ".to_string(),
473-
"\"Rust\"" => "".to_string(),
474-
s => format!(" extern {} ", s)
475-
},
471+
AbiSpace(decl.abi),
476472
decl.generics,
477473
decl.decl)
478474
}
@@ -788,7 +784,7 @@ impl fmt::Display for AbiSpace {
788784
match self.0 {
789785
Abi::Rust => Ok(()),
790786
Abi::C => write!(f, "extern "),
791-
abi => write!(f, "extern {} ", abi),
787+
abi => write!(f, "extern &quot;{}&quot; ", abi.name()),
792788
}
793789
}
794790
}

trunk/src/librustdoc/html/render.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2158,8 +2158,6 @@ fn render_assoc_item(w: &mut fmt::Formatter,
21582158
d: &clean::FnDecl,
21592159
link: AssocItemLink)
21602160
-> fmt::Result {
2161-
use syntax::abi::Abi;
2162-
21632161
let name = meth.name.as_ref().unwrap();
21642162
let anchor = format!("#{}.{}", shortty(meth), name);
21652163
let href = match link {
@@ -2186,10 +2184,7 @@ fn render_assoc_item(w: &mut fmt::Formatter,
21862184
{generics}{decl}{where_clause}",
21872185
ConstnessSpace(vis_constness),
21882186
UnsafetySpace(unsafety),
2189-
match abi {
2190-
Abi::Rust => String::new(),
2191-
a => format!("extern {} ", a.to_string())
2192-
},
2187+
AbiSpace(abi),
21932188
href = href,
21942189
name = name,
21952190
generics = *g,

trunk/src/libsyntax/ext/expand.rs

Lines changed: 37 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,26 @@ use std_inject;
3535
use std::collections::HashSet;
3636
use std::env;
3737

38+
// this function is called to detect use of feature-gated or invalid attributes
39+
// on macro invoations since they will not be detected after macro expansion
40+
fn check_attributes(attrs: &[ast::Attribute], fld: &MacroExpander) {
41+
for attr in attrs.iter() {
42+
feature_gate::check_attribute(&attr, &fld.cx.parse_sess.span_diagnostic,
43+
&fld.cx.parse_sess.codemap(),
44+
&fld.cx.ecfg.features.unwrap());
45+
}
46+
}
47+
3848
pub fn expand_expr(e: P<ast::Expr>, fld: &mut MacroExpander) -> P<ast::Expr> {
3949
let expr_span = e.span;
4050
return e.and_then(|ast::Expr {id, node, span, attrs}| match node {
4151

4252
// expr_mac should really be expr_ext or something; it's the
4353
// entry-point for all syntax extensions.
4454
ast::ExprKind::Mac(mac) => {
55+
if let Some(ref attrs) = attrs {
56+
check_attributes(attrs, fld);
57+
}
4558

4659
// Assert that we drop any macro attributes on the floor here
4760
drop(attrs);
@@ -70,10 +83,12 @@ pub fn expand_expr(e: P<ast::Expr>, fld: &mut MacroExpander) -> P<ast::Expr> {
7083

7184
ast::ExprKind::InPlace(placer, value_expr) => {
7285
// Ensure feature-gate is enabled
73-
feature_gate::check_for_placement_in(
74-
fld.cx.ecfg.features,
75-
&fld.cx.parse_sess.span_diagnostic,
76-
expr_span);
86+
if !fld.cx.ecfg.features.unwrap().placement_in_syntax {
87+
feature_gate::emit_feature_err(
88+
&fld.cx.parse_sess.span_diagnostic, "placement_in_syntax", expr_span,
89+
feature_gate::GateIssue::Language, feature_gate::EXPLAIN_PLACEMENT_IN
90+
);
91+
}
7792

7893
let placer = fld.fold_expr(placer);
7994
let value_expr = fld.fold_expr(value_expr);
@@ -370,6 +385,8 @@ pub fn expand_item_mac(it: P<ast::Item>,
370385
_ => fld.cx.span_bug(it.span, "invalid item macro invocation")
371386
});
372387

388+
check_attributes(&attrs, fld);
389+
373390
let fm = fresh_mark();
374391
let items = {
375392
let expanded = match fld.cx.syntax_env.find(extname) {
@@ -444,18 +461,6 @@ pub fn expand_item_mac(it: P<ast::Item>,
444461
let allow_internal_unstable = attr::contains_name(&attrs,
445462
"allow_internal_unstable");
446463

447-
// ensure any #[allow_internal_unstable]s are
448-
// detected (including nested macro definitions
449-
// etc.)
450-
if allow_internal_unstable && !fld.cx.ecfg.enable_allow_internal_unstable() {
451-
feature_gate::emit_feature_err(
452-
&fld.cx.parse_sess.span_diagnostic,
453-
"allow_internal_unstable",
454-
span,
455-
feature_gate::GateIssue::Language,
456-
feature_gate::EXPLAIN_ALLOW_INTERNAL_UNSTABLE)
457-
}
458-
459464
let export = attr::contains_name(&attrs, "macro_export");
460465
let def = ast::MacroDef {
461466
ident: ident,
@@ -519,6 +524,10 @@ fn expand_stmt(stmt: Stmt, fld: &mut MacroExpander) -> SmallVector<Stmt> {
519524
_ => return expand_non_macro_stmt(stmt, fld)
520525
};
521526

527+
if let Some(ref attrs) = attrs {
528+
check_attributes(attrs, fld);
529+
}
530+
522531
// Assert that we drop any macro attributes on the floor here
523532
drop(attrs);
524533

@@ -1066,7 +1075,7 @@ fn expand_impl_item(ii: ast::ImplItem, fld: &mut MacroExpander)
10661075
attrs: ii.attrs,
10671076
vis: ii.vis,
10681077
defaultness: ii.defaultness,
1069-
node: match ii.node {
1078+
node: match ii.node {
10701079
ast::ImplItemKind::Method(sig, body) => {
10711080
let (sig, body) = expand_and_rename_method(sig, body, fld);
10721081
ast::ImplItemKind::Method(sig, body)
@@ -1075,13 +1084,11 @@ fn expand_impl_item(ii: ast::ImplItem, fld: &mut MacroExpander)
10751084
},
10761085
span: fld.new_span(ii.span)
10771086
}),
1078-
ast::ImplItemKind::Macro(_) => {
1079-
let (span, mac) = match ii.node {
1080-
ast::ImplItemKind::Macro(mac) => (ii.span, mac),
1081-
_ => unreachable!()
1082-
};
1087+
ast::ImplItemKind::Macro(mac) => {
1088+
check_attributes(&ii.attrs, fld);
1089+
10831090
let maybe_new_items =
1084-
expand_mac_invoc(mac, span,
1091+
expand_mac_invoc(mac, ii.span,
10851092
|r| r.make_impl_items(),
10861093
|meths, mark| meths.move_map(|m| mark_impl_item(m, mark)),
10871094
fld);
@@ -1348,14 +1355,14 @@ impl<'feat> ExpansionConfig<'feat> {
13481355
}
13491356

13501357
feature_tests! {
1351-
fn enable_quotes = allow_quote,
1352-
fn enable_asm = allow_asm,
1353-
fn enable_log_syntax = allow_log_syntax,
1354-
fn enable_concat_idents = allow_concat_idents,
1355-
fn enable_trace_macros = allow_trace_macros,
1358+
fn enable_quotes = quote,
1359+
fn enable_asm = asm,
1360+
fn enable_log_syntax = log_syntax,
1361+
fn enable_concat_idents = concat_idents,
1362+
fn enable_trace_macros = trace_macros,
13561363
fn enable_allow_internal_unstable = allow_internal_unstable,
1357-
fn enable_custom_derive = allow_custom_derive,
1358-
fn enable_pushpop_unsafe = allow_pushpop_unsafe,
1364+
fn enable_custom_derive = custom_derive,
1365+
fn enable_pushpop_unsafe = pushpop_unsafe,
13591366
}
13601367
}
13611368

0 commit comments

Comments
 (0)