Skip to content

Commit 0517b86

Browse files
committed
---
yaml --- r: 172670 b: refs/heads/try c: 9f5f706 h: refs/heads/master v: v3
1 parent 572f3e0 commit 0517b86

File tree

3 files changed

+41
-18
lines changed

3 files changed

+41
-18
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: 170c4399e614fe599c3d41306b3429ca8b3b68c6
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 5b3cd3900ceda838f5798c30ab96ceb41f962534
5-
refs/heads/try: efaf613497da355fa3afaeaa75eaf95b55991e4e
5+
refs/heads/try: 9f5f706f96e5940a6149257feda6a70844067d7a
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
88
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596

branches/try/src/librustc/metadata/creader.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,7 @@ impl<'a> CrateReader<'a> {
516516
}
517517
}
518518

519+
#[deriving(Copy)]
519520
pub enum CrateOrString<'a> {
520521
Krate(&'a ast::ViewItem),
521522
Str(&'a str)

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

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,21 @@ impl<'a, 'v> Visitor<'v> for PluginLoader<'a> {
160160
}
161161
}
162162

163+
self.load_plugin(CrateOrString::Krate(vi), plugin_attr, macro_selection, reexport)
164+
}
165+
166+
fn visit_mac(&mut self, _: &ast::Mac) {
167+
// bummer... can't see plugins inside macros.
168+
// do nothing.
169+
}
170+
}
171+
172+
impl<'a> PluginLoader<'a> {
173+
pub fn load_plugin<'b>(&mut self,
174+
c: CrateOrString<'b>,
175+
plugin_attr: Option<P<ast::MetaItem>>,
176+
macro_selection: Option<HashSet<token::InternedString>>,
177+
reexport: HashSet<token::InternedString>) {
163178
let mut macros = vec![];
164179
let mut registrar = None;
165180

@@ -169,13 +184,15 @@ impl<'a, 'v> Visitor<'v> for PluginLoader<'a> {
169184
};
170185
let load_registrar = plugin_attr.is_some();
171186

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-
}
187+
if let CrateOrString::Krate(vi) = c {
188+
if load_macros && !self.span_whitelist.contains(&vi.span) {
189+
self.sess.span_err(vi.span, "an `extern crate` loading macros must be at \
190+
the crate root");
191+
}
192+
}
176193

177194
if load_macros || load_registrar {
178-
let pmd = self.reader.read_plugin_metadata(CrateOrString::Krate(vi));
195+
let pmd = self.reader.read_plugin_metadata(c);
179196
if load_macros {
180197
macros = pmd.exported_macros();
181198
}
@@ -195,24 +212,17 @@ impl<'a, 'v> Visitor<'v> for PluginLoader<'a> {
195212
}
196213

197214
if let Some((lib, symbol)) = registrar {
198-
let fun = self.dylink_registrar(vi, lib, symbol);
215+
let fun = self.dylink_registrar(c, lib, symbol);
199216
self.plugins.registrars.push(PluginRegistrar {
200217
fun: fun,
201218
args: plugin_attr.unwrap(),
202219
});
203220
}
204221
}
205222

206-
fn visit_mac(&mut self, _: &ast::Mac) {
207-
// bummer... can't see plugins inside macros.
208-
// do nothing.
209-
}
210-
}
211-
212-
impl<'a> PluginLoader<'a> {
213223
// Dynamically link a registrar function into the compiler process.
214-
fn dylink_registrar(&mut self,
215-
vi: &ast::ViewItem,
224+
fn dylink_registrar<'b>(&mut self,
225+
c: CrateOrString<'b>,
216226
path: Path,
217227
symbol: String) -> PluginRegistrarFun {
218228
// Make sure the path contains a / or the linker will search for it.
@@ -223,7 +233,13 @@ impl<'a> PluginLoader<'a> {
223233
// this is fatal: there are almost certainly macros we need
224234
// inside this crate, so continue would spew "macro undefined"
225235
// errors
226-
Err(err) => self.sess.span_fatal(vi.span, &err[])
236+
Err(err) => {
237+
if let CrateOrString::Krate(cr) = c {
238+
self.sess.span_fatal(cr.span, &err[])
239+
} else {
240+
self.sess.fatal(&err[])
241+
}
242+
}
227243
};
228244

229245
unsafe {
@@ -233,7 +249,13 @@ impl<'a> PluginLoader<'a> {
233249
mem::transmute::<*mut u8,PluginRegistrarFun>(registrar)
234250
}
235251
// again fatal if we can't register macros
236-
Err(err) => self.sess.span_fatal(vi.span, &err[])
252+
Err(err) => {
253+
if let CrateOrString::Krate(cr) = c {
254+
self.sess.span_fatal(cr.span, &err[])
255+
} else {
256+
self.sess.fatal(&err[])
257+
}
258+
}
237259
};
238260

239261
// Intentionally leak the dynamic library. We can't ever unload it

0 commit comments

Comments
 (0)