Skip to content

Rollup of 23 pull requests #37269

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

Merged
merged 66 commits into from
Oct 19, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
b0eee76
Include attributes on generic parameter bindings in pretty printer.
pnkfelix Oct 10, 2016
4bb68be
Add feature gate for `dropck_eyepatch` feature (RFC 1327).
pnkfelix Oct 11, 2016
e8ccc68
Thread `pure_wrt_drop` field through lifetime and type parameters.
pnkfelix Oct 11, 2016
7d2d5bc
Code for enforcing `#[may_dangle]` attribute.
pnkfelix Oct 11, 2016
9a649c3
Require destructors using `#[may_dangle]` to use `unsafe impl`.
pnkfelix Oct 12, 2016
e185cd5
Fix bug in test for E0199 and add test for E0198.
pnkfelix Oct 12, 2016
fa7f69c
tests for `#[may_dangle]` attribute.
pnkfelix Oct 11, 2016
b486a87
add test case for changing private methods
nikomatsakis Oct 12, 2016
8dd9493
placate diagnostic checking tests by fixing sample code in E0569.
pnkfelix Oct 12, 2016
c239fee
fix typo in diagnostic sample code
pnkfelix Oct 13, 2016
029dcee
Avoid many CrateConfig clones.
nnethercote Oct 13, 2016
094c3a2
test: Don't write files into the source tree
alexcrichton Oct 14, 2016
06d173a
Add AppVeyor configuration to the repo
alexcrichton Oct 7, 2016
ac42f3f
correct erroneous pluralization of '1 type argument' error messages
zackmdavis Oct 15, 2016
d902963
Refactor `syntax::ext::base::Resolver::resolve_invoc`.
jseyfried Oct 14, 2016
33e3da8
Use the macro namespace for custom derives.
jseyfried Oct 15, 2016
aac6dca
Treat custom derive extern crates like empty modules.
jseyfried Oct 15, 2016
5afd6d8
Run rustfmt on libcore/sync folder
srinivasreddy Oct 16, 2016
e4ed345
impl Debug for ReadDir
diwic Oct 16, 2016
49e6b46
Mark enums with non-zero discriminant as non-zero
petrochenkov Oct 12, 2016
88fde7f
Don't process cycles when stalled
jonas-schievink Oct 17, 2016
ed50159
Expand .zip() specialization to .map() and .cloned()
bluss Oct 17, 2016
0271a9a
Fix Subst construction: use subst from adt_def rather than Drop impl'…
pnkfelix Oct 17, 2016
818ac08
remove fixme that i no longer think appropriate.
pnkfelix Oct 17, 2016
85d2e4d
Review feedback: add linebreak and reindent to make braces match better.
pnkfelix Oct 17, 2016
0d8f716
Review feedback: expand comment and simplify some code.
pnkfelix Oct 17, 2016
4124d8e
Moved new dropck-eyepatch compile-fail tests to the `ui/` subtree.
pnkfelix Oct 17, 2016
d07523c
ICH: Use 128-bit Blake2b hash instead of 64-bit SipHash for incr. com…
michaelwoerister Oct 7, 2016
0a0efcb
std::collections: Reexport libcollections's range module
bluss Oct 17, 2016
0c844d2
Set stalled=false when encountering an error
jonas-schievink Oct 17, 2016
c560ca4
Fix typo
michaelwoerister Oct 17, 2016
9578e1a
Fix partially consumed tokens in macro matchers.
jseyfried Oct 16, 2016
95a9e2a
Add regression test.
jseyfried Oct 16, 2016
a29b503
Add stable example to TypeId
Oct 18, 2016
1e4241a
Optimize `Substs::super_fold_with`.
nnethercote Oct 12, 2016
10a58ac
Incorporate review feedback: code formatting fixes, expand a comment.
pnkfelix Oct 18, 2016
1cc1dcc
run rustfmt on libpanic_unwind
srinivasreddy Oct 18, 2016
b260617
run rustfmt on librustc_errors folder
srinivasreddy Oct 18, 2016
4a91a80
Fix some pretty printing tests
petrochenkov Oct 12, 2016
93417fa
Add invalid doc comment help message
GuillaumeGomez Oct 4, 2016
d3c5905
Allow bootstrapping without a key. Fixes #36548
brson Oct 18, 2016
016f69f
Optimize `write_metadata`.
nnethercote Oct 19, 2016
ab5dcff
Format comment in a nicer way.
eddyb Oct 19, 2016
fdcdcac
Rollup merge of #36964 - GuillaumeGomez:comment_error, r=jonathandturner
eddyb Oct 19, 2016
6e3a72d
Rollup merge of #37108 - nnethercote:substs-experimentation, r=eddyb
eddyb Oct 19, 2016
373fcd1
Rollup merge of #37117 - pnkfelix:may-dangle-attr, r=nikomatsakis
eddyb Oct 19, 2016
a88ca4b
Rollup merge of #37124 - nikomatsakis:incr-comp-benchmark, r=michaelw…
eddyb Oct 19, 2016
aaed275
Rollup merge of #37161 - nnethercote:no-cfg-cloning, r=nrc
eddyb Oct 19, 2016
5c64343
Rollup merge of #37176 - alexcrichton:no-write-to-root, r=brson
eddyb Oct 19, 2016
fc8f9b9
Rollup merge of #37182 - alexcrichton:appveyor, r=brson
eddyb Oct 19, 2016
c38324d
Rollup merge of #37193 - zackmdavis:pluralization_of_expected_type_ar…
eddyb Oct 19, 2016
a6788d0
Rollup merge of #37198 - jseyfried:future_proof_macros_11, r=nrc
eddyb Oct 19, 2016
4568318
Rollup merge of #37202 - petrochenkov:pretty, r=nrc
eddyb Oct 19, 2016
094eaf0
Rollup merge of #37208 - jseyfried:fix_partially_consumed_tokens_in_m…
eddyb Oct 19, 2016
eae11c3
Rollup merge of #37218 - srinivasreddy:sync, r=nrc
eddyb Oct 19, 2016
184ee98
Rollup merge of #37221 - diwic:6a-readdir-debug, r=alexcrichton
eddyb Oct 19, 2016
beaa4c5
Rollup merge of #37224 - petrochenkov:nz, r=eddyb
eddyb Oct 19, 2016
7b0eb10
Rollup merge of #37230 - bluss:zip-specialization-for-map, r=alexcric…
eddyb Oct 19, 2016
6ae80c6
Rollup merge of #37231 - jonas-schievink:obligation-forest-the-quest-…
eddyb Oct 19, 2016
7343291
Rollup merge of #37233 - michaelwoerister:blake2-for-ich, r=nikomatsakis
eddyb Oct 19, 2016
ad241df
Rollup merge of #37236 - bluss:range-argument, r=alexcrichton
eddyb Oct 19, 2016
3d57d42
Rollup merge of #37240 - jethrogb:typeid_doc, r=sfackler
eddyb Oct 19, 2016
a09b94b
Rollup merge of #37254 - srinivasreddy:master, r=alexcrichton
eddyb Oct 19, 2016
903e1f9
Rollup merge of #37257 - srinivasreddy:librustc_errors, r=eddyb
eddyb Oct 19, 2016
9888313
Rollup merge of #37265 - brson:bootstrap, r=alexcrichton
eddyb Oct 19, 2016
f354d72
Rollup merge of #37267 - nnethercote:opt-write_metadata, r=eddyb
eddyb Oct 19, 2016
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
Use the macro namespace for custom derives.
  • Loading branch information
jseyfried committed Oct 15, 2016
commit 33e3da831c8b517c94d85599edf2bcd259128181
3 changes: 1 addition & 2 deletions src/librustc/middle/cstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ use session::Session;
use session::search_paths::PathKind;
use util::nodemap::{NodeSet, DefIdMap};
use std::path::PathBuf;
use std::rc::Rc;
use syntax::ast;
use syntax::attr;
use syntax::ext::base::MultiItemModifier;
Expand Down Expand Up @@ -425,7 +424,7 @@ pub struct LoadedMacro {

pub enum LoadedMacroKind {
Def(ast::MacroDef),
CustomDerive(String, Rc<MultiItemModifier>),
CustomDerive(String, Box<MultiItemModifier>),
}

pub trait CrateLoader {
Expand Down
3 changes: 1 addition & 2 deletions src/librustc_metadata/macro_import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
//! Used by `rustc` when loading a crate with exported macros.

use std::collections::HashSet;
use std::rc::Rc;
use std::env;
use std::mem;

Expand Down Expand Up @@ -212,7 +211,7 @@ impl<'a> CrateLoader<'a> {
fn register_custom_derive(&mut self,
trait_name: &str,
expand: fn(TokenStream) -> TokenStream) {
let derive = Rc::new(CustomDerive::new(expand));
let derive = Box::new(CustomDerive::new(expand));
self.0.push(LoadedMacro {
kind: LoadedMacroKind::CustomDerive(trait_name.to_string(), derive),
import_site: self.1,
Expand Down
51 changes: 26 additions & 25 deletions src/librustc_resolve/build_reduced_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use syntax::parse::token;
use syntax::ast::{self, Block, ForeignItem, ForeignItemKind, Item, ItemKind};
use syntax::ast::{Mutability, StmtKind, TraitItem, TraitItemKind};
use syntax::ast::{Variant, ViewPathGlob, ViewPathList, ViewPathSimple};
use syntax::ext::base::{MultiItemModifier, Resolver as SyntaxResolver};
use syntax::ext::base::{SyntaxExtension, Resolver as SyntaxResolver};
use syntax::ext::hygiene::Mark;
use syntax::feature_gate::{self, emit_feature_err};
use syntax::ext::tt::macro_rules;
Expand Down Expand Up @@ -195,33 +195,45 @@ impl<'b> Resolver<'b> {
// We need to error on `#[macro_use] extern crate` when it isn't at the
// crate root, because `$crate` won't work properly.
let is_crate_root = self.current_module.parent.is_none();
let import_macro = |this: &mut Self, name, ext, span| {
let shadowing = this.builtin_macros.insert(name, Rc::new(ext)).is_some();
if shadowing && expansion != Mark::root() {
let msg = format!("`{}` is already in scope", name);
this.session.struct_span_err(span, &msg)
.note("macro-expanded `#[macro_use]`s may not shadow \
existing macros (see RFC 1560)")
.emit();
}
};

let mut custom_derive_crate = false;
for loaded_macro in self.crate_loader.load_macros(item, is_crate_root) {
match loaded_macro.kind {
LoadedMacroKind::Def(mut def) => {
let name = def.ident.name;
if def.use_locally {
let ext =
Rc::new(macro_rules::compile(&self.session.parse_sess, &def));
if self.builtin_macros.insert(name, ext).is_some() &&
expansion != Mark::root() {
let msg = format!("`{}` is already in scope", name);
self.session.struct_span_err(loaded_macro.import_site, &msg)
.note("macro-expanded `#[macro_use]`s may not shadow \
existing macros (see RFC 1560)")
.emit();
}
self.macro_names.insert(name);
self.macro_names.insert(def.ident.name);
let ext = macro_rules::compile(&self.session.parse_sess, &def);
import_macro(self, def.ident.name, ext, loaded_macro.import_site);
}
if def.export {
def.id = self.next_node_id();
self.exported_macros.push(def);
}
}
LoadedMacroKind::CustomDerive(name, ext) => {
self.insert_custom_derive(&name, ext, item.span);
custom_derive_crate = true;
let ext = SyntaxExtension::CustomDerive(ext);
import_macro(self, token::intern(&name), ext, loaded_macro.import_site);
}
}
}

if custom_derive_crate && !self.session.features.borrow().proc_macro {
let issue = feature_gate::GateIssue::Language;
let msg = "loading custom derive macro crates is experimentally supported";
emit_feature_err(&self.session.parse_sess, "proc_macro", item.span, issue, msg);
}

self.crate_loader.process_item(item, &self.definitions);

// n.b. we don't need to look at the path option here, because cstore already did
Expand Down Expand Up @@ -504,17 +516,6 @@ impl<'b> Resolver<'b> {

false
}

fn insert_custom_derive(&mut self, name: &str, ext: Rc<MultiItemModifier>, sp: Span) {
if !self.session.features.borrow().proc_macro {
let sess = &self.session.parse_sess;
let msg = "loading custom derive macro crates is experimentally supported";
emit_feature_err(sess, "proc_macro", sp, feature_gate::GateIssue::Language, msg);
}
if self.derive_modes.insert(token::intern(name), ext).is_some() {
self.session.span_err(sp, &format!("cannot shadow existing derive mode `{}`", name));
}
}
}

pub struct BuildReducedGraphVisitor<'a, 'b: 'a> {
Expand Down
3 changes: 0 additions & 3 deletions src/librustc_resolve/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ use rustc::ty;
use rustc::hir::{Freevar, FreevarMap, TraitCandidate, TraitMap, GlobMap};
use rustc::util::nodemap::{NodeMap, NodeSet, FnvHashMap, FnvHashSet};

use syntax::ext::base::MultiItemModifier;
use syntax::ext::hygiene::Mark;
use syntax::ast::{self, FloatTy};
use syntax::ast::{CRATE_NODE_ID, Name, NodeId, IntTy, UintTy};
Expand Down Expand Up @@ -1080,7 +1079,6 @@ pub struct Resolver<'a> {
new_import_semantics: bool, // true if `#![feature(item_like_imports)]`

pub exported_macros: Vec<ast::MacroDef>,
pub derive_modes: FnvHashMap<Name, Rc<MultiItemModifier>>,
crate_loader: &'a mut CrateLoader,
macro_names: FnvHashSet<Name>,
builtin_macros: FnvHashMap<Name, Rc<SyntaxExtension>>,
Expand Down Expand Up @@ -1271,7 +1269,6 @@ impl<'a> Resolver<'a> {
new_import_semantics: session.features.borrow().item_like_imports,

exported_macros: Vec::new(),
derive_modes: FnvHashMap(),
crate_loader: crate_loader,
macro_names: FnvHashSet(),
builtin_macros: FnvHashMap(),
Expand Down
6 changes: 1 addition & 5 deletions src/librustc_resolve/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use std::cell::Cell;
use std::rc::Rc;
use syntax::ast;
use syntax::errors::DiagnosticBuilder;
use syntax::ext::base::{self, Determinacy, MultiModifier, MultiDecorator, MultiItemModifier};
use syntax::ext::base::{self, Determinacy, MultiModifier, MultiDecorator};
use syntax::ext::base::{NormalTT, SyntaxExtension};
use syntax::ext::expand::Expansion;
use syntax::ext::hygiene::Mark;
Expand Down Expand Up @@ -186,10 +186,6 @@ impl<'a> base::Resolver for Resolver<'a> {
}
})
}

fn resolve_derive_mode(&mut self, ident: ast::Ident) -> Option<Rc<MultiItemModifier>> {
self.derive_modes.get(&ident.name).cloned()
}
}

impl<'a> Resolver<'a> {
Expand Down
4 changes: 2 additions & 2 deletions src/libsyntax/ext/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,8 @@ pub enum SyntaxExtension {
/// the block.
///
IdentTT(Box<IdentMacroExpander>, Option<Span>, bool),

CustomDerive(Box<MultiItemModifier>),
}

pub type NamedSyntaxExtension = (Name, SyntaxExtension);
Expand All @@ -524,7 +526,6 @@ pub trait Resolver {
fn find_attr_invoc(&mut self, attrs: &mut Vec<Attribute>) -> Option<Attribute>;
fn resolve_macro(&mut self, scope: Mark, path: &ast::Path, force: bool)
-> Result<Rc<SyntaxExtension>, Determinacy>;
fn resolve_derive_mode(&mut self, ident: ast::Ident) -> Option<Rc<MultiItemModifier>>;
}

#[derive(Copy, Clone, Debug)]
Expand All @@ -545,7 +546,6 @@ impl Resolver for DummyResolver {
fn add_expansions_at_stmt(&mut self, _id: ast::NodeId, _macros: Vec<Mark>) {}

fn find_attr_invoc(&mut self, _attrs: &mut Vec<Attribute>) -> Option<Attribute> { None }
fn resolve_derive_mode(&mut self, _ident: ast::Ident) -> Option<Rc<MultiItemModifier>> { None }
fn resolve_macro(&mut self, _scope: Mark, _path: &ast::Path, _force: bool)
-> Result<Rc<SyntaxExtension>, Determinacy> {
Err(Determinacy::Determined)
Expand Down
15 changes: 14 additions & 1 deletion src/libsyntax/ext/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,15 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
let tok_result = mac.expand(self.cx, attr.span, attr_toks, item_toks);
self.parse_expansion(tok_result, kind, name, attr.span)
}
_ => unreachable!(),
SyntaxExtension::CustomDerive(_) => {
self.cx.span_err(attr.span, &format!("`{}` is a derive mode", name));
kind.dummy(attr.span)
}
_ => {
let msg = &format!("macro `{}` may not be used in attributes", name);
self.cx.span_err(attr.span, &msg);
kind.dummy(attr.span)
}
}
}

Expand Down Expand Up @@ -439,6 +447,11 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
return kind.dummy(span);
}

SyntaxExtension::CustomDerive(..) => {
self.cx.span_err(path.span, &format!("`{}` is a derive mode", extname));
return kind.dummy(span);
}

SyntaxExtension::ProcMacro(ref expandfun) => {
if ident.name != keywords::Invalid.name() {
let msg =
Expand Down
24 changes: 17 additions & 7 deletions src/libsyntax_ext/deriving/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

use syntax::ast::{self, MetaItem};
use syntax::attr::HasAttrs;
use syntax::ext::base::{Annotatable, ExtCtxt};
use syntax::ext::base::{Annotatable, ExtCtxt, SyntaxExtension};
use syntax::ext::build::AstBuilder;
use syntax::feature_gate;
use syntax::codemap;
Expand Down Expand Up @@ -158,10 +158,14 @@ pub fn expand_derive(cx: &mut ExtCtxt,
let tword = titem.word().unwrap();
let tname = tword.name();

let derive_mode = ast::Ident::with_empty_ctxt(intern(&tname));
let derive_mode = cx.resolver.resolve_derive_mode(derive_mode);
if is_builtin_trait(&tname) || derive_mode.is_some() {
return true
if is_builtin_trait(&tname) || {
let derive_mode =
ast::Path::from_ident(titem.span, ast::Ident::with_empty_ctxt(intern(&tname)));
cx.resolver.resolve_macro(cx.current_expansion.mark, &derive_mode, false).map(|ext| {
if let SyntaxExtension::CustomDerive(_) = *ext { true } else { false }
}).unwrap_or(false)
} {
return true;
}

if !cx.ecfg.enable_custom_derive() {
Expand Down Expand Up @@ -216,7 +220,9 @@ pub fn expand_derive(cx: &mut ExtCtxt,
.next();
if let Some((i, titem)) = macros_11_derive {
let tname = ast::Ident::with_empty_ctxt(intern(&titem.name().unwrap()));
let ext = cx.resolver.resolve_derive_mode(tname).unwrap();
let path = ast::Path::from_ident(titem.span, tname);
let ext = cx.resolver.resolve_macro(cx.current_expansion.mark, &path, false).unwrap();

traits.remove(i);
if traits.len() > 0 {
item = item.map(|mut i| {
Expand All @@ -232,7 +238,11 @@ pub fn expand_derive(cx: &mut ExtCtxt,
intern_and_get_ident("derive"),
vec![titem]);
let item = Annotatable::Item(item);
return ext.expand(cx, mitem.span, &mitem, item)
if let SyntaxExtension::CustomDerive(ref ext) = *ext {
return ext.expand(cx, mitem.span, &mitem, item);
} else {
unreachable!()
}
}

// Ok, at this point we know that there are no old-style `#[derive_Foo]` nor
Expand Down