Skip to content

Commit 86d3520

Browse files
author
Keegan McAllister
committed
---
yaml --- r: 170895 b: refs/heads/try c: bbbb85a h: refs/heads/master i: 170893: a053e5b 170891: 31a1da9 170887: 24c0c23 170879: fafa0b2 v: v3
1 parent 7ca9106 commit 86d3520

File tree

4 files changed

+41
-4
lines changed

4 files changed

+41
-4
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: 73a25f55ad748b4d3516417c711b99ce446591af
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 5b3cd3900ceda838f5798c30ab96ceb41f962534
5-
refs/heads/try: c2e26972e307a2e82b9ff7a5345a5bff47a99501
5+
refs/heads/try: bbbb85a4ec029e961c01fa95725ee065621c07dc
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
88
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596

branches/try/src/librustc/plugin/load.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use std::dynamic_lib::DynamicLibrary;
2020
use std::collections::HashSet;
2121
use syntax::ast;
2222
use syntax::attr;
23+
use syntax::codemap::Span;
2324
use syntax::parse::token;
2425
use syntax::ptr::P;
2526
use syntax::visit;
@@ -45,6 +46,7 @@ pub struct Plugins {
4546

4647
struct PluginLoader<'a> {
4748
sess: &'a Session,
49+
span_whitelist: HashSet<Span>,
4850
reader: CrateReader<'a>,
4951
plugins: Plugins,
5052
}
@@ -54,6 +56,7 @@ impl<'a> PluginLoader<'a> {
5456
PluginLoader {
5557
sess: sess,
5658
reader: CrateReader::new(sess),
59+
span_whitelist: HashSet::new(),
5760
plugins: Plugins {
5861
macros: vec!(),
5962
registrars: vec!(),
@@ -66,6 +69,14 @@ impl<'a> PluginLoader<'a> {
6669
pub fn load_plugins(sess: &Session, krate: &ast::Crate,
6770
addl_plugins: Option<Plugins>) -> Plugins {
6871
let mut loader = PluginLoader::new(sess);
72+
73+
// We need to error on `#[macro_use] extern crate` when it isn't at the
74+
// crate root, because `$crate` won't work properly. Identify these by
75+
// spans, because the crate map isn't set up yet.
76+
for vi in krate.module.view_items.iter() {
77+
loader.span_whitelist.insert(vi.span);
78+
}
79+
6980
visit::walk_crate(&mut loader, krate);
7081

7182
let mut plugins = loader.plugins;
@@ -158,6 +169,11 @@ impl<'a, 'v> Visitor<'v> for PluginLoader<'a> {
158169
};
159170
let load_registrar = plugin_attr.is_some();
160171

172+
if load_macros && !self.span_whitelist.contains(&vi.span) {
173+
self.sess.span_err(vi.span, "an `extern crate` loading macros must be at \
174+
the crate root");
175+
}
176+
161177
if load_macros || load_registrar {
162178
let pmd = self.reader.read_plugin_metadata(vi);
163179
if load_macros {

branches/try/src/test/compile-fail/lint-stability.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,14 @@
1919
#![deny(experimental)]
2020
#![allow(dead_code)]
2121

22+
#[macro_use]
23+
extern crate lint_stability; //~ ERROR: use of unmarked item
24+
2225
mod cross_crate {
2326
extern crate stability_cfg1;
2427
extern crate stability_cfg2; //~ ERROR: use of experimental item
2528

26-
#[macro_use]
27-
extern crate lint_stability; //~ ERROR: use of unmarked item
28-
use self::lint_stability::*;
29+
use lint_stability::*;
2930

3031
fn test() {
3132
let foo = MethodTester;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// aux-build:macro_crate_nonterminal.rs
12+
// ignore-stage1
13+
14+
mod foo {
15+
#[macro_use]
16+
extern crate macro_crate_nonterminal; //~ ERROR must be at the crate root
17+
}
18+
19+
fn main() {
20+
}

0 commit comments

Comments
 (0)