Skip to content

Commit 0df9b85

Browse files
committed
auto merge of #10696 : fhahn/rust/issue9543-remove-extern-mod-foo, r=pcwalton
This patch for #9543 throws an `obsolete syntax` error for `extern mod foo (name="bar")` . I was wondering if [this](https://github.com/fhahn/rust/compare/mozilla:master...fhahn:issue9543-remove-extern-mod-foo?expand=1#diff-da9d34ca1d0f6beee2838cf02e07345cR4444) is the correct place to do this? I think the wording of the error message could probably be improved as well. If this approach is OK, I'm going to run the whole test suite tomorrow and update the old syntax to the new one.
2 parents c29b1be + 4cb13ed commit 0df9b85

File tree

18 files changed

+62
-37
lines changed

18 files changed

+62
-37
lines changed

src/librustc/front/std_inject.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use syntax::fold;
2121
use syntax::opt_vec;
2222
use syntax::util::small_vector::SmallVector;
2323

24-
static STD_VERSION: &'static str = "0.9-pre";
24+
pub static VERSION: &'static str = "0.9-pre";
2525

2626
pub fn maybe_inject_libstd_ref(sess: Session, crate: ast::Crate)
2727
-> ast::Crate {
@@ -57,12 +57,10 @@ struct StandardLibraryInjector {
5757

5858
impl fold::ast_fold for StandardLibraryInjector {
5959
fn fold_crate(&mut self, crate: ast::Crate) -> ast::Crate {
60-
let version = STD_VERSION.to_managed();
61-
let vers_item = attr::mk_name_value_item_str(@"vers", version);
6260
let mut vis = ~[ast::view_item {
6361
node: ast::view_item_extern_mod(self.sess.ident_of("std"),
64-
None,
65-
~[vers_item.clone()],
62+
Some((format!("std\\#{}", VERSION).to_managed(),
63+
ast::CookedStr)),
6664
ast::DUMMY_NODE_ID),
6765
attrs: ~[],
6866
vis: ast::private,
@@ -72,17 +70,17 @@ impl fold::ast_fold for StandardLibraryInjector {
7270
if use_uv(&crate) && !self.sess.building_library.get() {
7371
vis.push(ast::view_item {
7472
node: ast::view_item_extern_mod(self.sess.ident_of("green"),
75-
None,
76-
~[vers_item],
73+
Some((format!("green\\#{}", VERSION).to_managed(),
74+
ast::CookedStr)),
7775
ast::DUMMY_NODE_ID),
7876
attrs: ~[],
7977
vis: ast::private,
8078
span: DUMMY_SP
8179
});
8280
vis.push(ast::view_item {
8381
node: ast::view_item_extern_mod(self.sess.ident_of("rustuv"),
84-
None,
85-
~[vers_item],
82+
Some((format!("rustuv\\#{}", VERSION).to_managed(),
83+
ast::CookedStr)),
8684
ast::DUMMY_NODE_ID),
8785
attrs: ~[],
8886
vis: ast::private,

src/librustc/front/test.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use driver::session;
1515
use front::config;
16+
use front::std_inject::VERSION;
1617

1718
use std::cell::RefCell;
1819
use std::vec;
@@ -291,8 +292,10 @@ fn mk_std(cx: &TestCtxt) -> ast::view_item {
291292
path_node(~[id_extra]),
292293
ast::DUMMY_NODE_ID))])
293294
} else {
294-
let mi = attr::mk_name_value_item_str(@"vers", @"0.9-pre");
295-
ast::view_item_extern_mod(id_extra, None, ~[mi], ast::DUMMY_NODE_ID)
295+
ast::view_item_extern_mod(id_extra,
296+
Some((format!("extra\\#{}", VERSION).to_managed(),
297+
ast::CookedStr)),
298+
ast::DUMMY_NODE_ID)
296299
};
297300
ast::view_item {
298301
node: vi,

src/librustc/metadata/creader.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ fn visit_crate(e: &Env, c: &ast::Crate) {
132132

133133
fn visit_view_item(e: &mut Env, i: &ast::view_item) {
134134
match i.node {
135-
ast::view_item_extern_mod(ident, path_opt, _, id) => {
135+
ast::view_item_extern_mod(ident, path_opt, id) => {
136136
let ident = token::ident_to_str(&ident);
137137
debug!("resolving extern mod stmt. ident: {:?} path_opt: {:?}",
138138
ident, path_opt);

src/librustc/middle/resolve.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1507,7 +1507,7 @@ impl Resolver {
15071507
}
15081508
}
15091509

1510-
view_item_extern_mod(name, _, _, node_id) => {
1510+
view_item_extern_mod(name, _, node_id) => {
15111511
// n.b. we don't need to look at the path option here, because cstore already did
15121512
match self.session.cstore.find_extern_mod_stmt_cnum(node_id) {
15131513
Some(crate_id) => {

src/librustdoc/clean.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -994,15 +994,15 @@ impl Clean<Item> for ast::view_item {
994994

995995
#[deriving(Clone, Encodable, Decodable)]
996996
pub enum ViewItemInner {
997-
ExternMod(~str, Option<~str>, ~[Attribute], ast::NodeId),
997+
ExternMod(~str, Option<~str>, ast::NodeId),
998998
Import(~[ViewPath])
999999
}
10001000

10011001
impl Clean<ViewItemInner> for ast::view_item_ {
10021002
fn clean(&self) -> ViewItemInner {
10031003
match self {
1004-
&ast::view_item_extern_mod(ref i, ref p, ref mi, ref id) =>
1005-
ExternMod(i.clean(), p.map(|(ref x, _)| x.to_owned()), mi.clean(), *id),
1004+
&ast::view_item_extern_mod(ref i, ref p, ref id) =>
1005+
ExternMod(i.clean(), p.map(|(ref x, _)| x.to_owned()), *id),
10061006
&ast::view_item_use(ref vp) => Import(vp.clean())
10071007
}
10081008
}

src/librustdoc/html/render.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -995,7 +995,7 @@ fn item_module(w: &mut Writer, cx: &Context,
995995

996996
clean::ViewItemItem(ref item) => {
997997
match item.inner {
998-
clean::ExternMod(ref name, ref src, _, _) => {
998+
clean::ExternMod(ref name, ref src, _) => {
999999
write!(w, "<tr><td><code>extern mod {}",
10001000
name.as_slice());
10011001
match *src {

src/librustpkg/path_util.rs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414

1515
pub use crate_id::CrateId;
1616
pub use target::{OutputType, Main, Lib, Test, Bench, Target, Build, Install};
17-
pub use version::{Version, NoVersion, split_version_general, try_parsing_version};
17+
pub use version::{Version, ExactRevision, NoVersion, split_version, split_version_general,
18+
try_parsing_version};
1819
pub use rustc::metadata::filesearch::rust_path;
1920
use rustc::metadata::filesearch::libdir;
2021
use rustc::driver::driver::host_triple;
@@ -213,8 +214,9 @@ pub fn library_in_workspace(path: &Path, short_name: &str, where: Target,
213214
}
214215

215216
// rustc doesn't use target-specific subdirectories
216-
pub fn system_library(sysroot: &Path, lib_name: &str) -> Option<Path> {
217-
library_in(lib_name, &NoVersion, &sysroot.join(libdir()))
217+
pub fn system_library(sysroot: &Path, crate_id: &str) -> Option<Path> {
218+
let (lib_name, version) = split_crate_id(crate_id);
219+
library_in(lib_name, &version, &sysroot.join(libdir()))
218220
}
219221

220222
fn library_in(short_name: &str, version: &Version, dir_to_search: &Path) -> Option<Path> {
@@ -268,6 +270,7 @@ fn library_in(short_name: &str, version: &Version, dir_to_search: &Path) -> Opti
268270
}
269271
None => break
270272
}
273+
271274
}
272275
_ => { f_name = f_name.slice(0, i); }
273276
}
@@ -293,6 +296,22 @@ fn library_in(short_name: &str, version: &Version, dir_to_search: &Path) -> Opti
293296
abs_path
294297
}
295298

299+
fn split_crate_id<'a>(crate_id: &'a str) -> (&'a str, Version) {
300+
match split_version(crate_id) {
301+
Some((name, vers)) =>
302+
match vers {
303+
ExactRevision(ref v) => match v.find('-') {
304+
Some(pos) => (name, ExactRevision(v.slice(0, pos).to_owned())),
305+
None => (name, ExactRevision(v.to_owned()))
306+
},
307+
_ => (name, vers)
308+
},
309+
None => (crate_id, NoVersion)
310+
}
311+
}
312+
313+
314+
296315
/// Returns the executable that would be installed for <crateid>
297316
/// in <workspace>
298317
/// As a side effect, creates the bin-dir if it doesn't exist

src/librustpkg/util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ impl<'a> Visitor<()> for ViewItemVisitor<'a> {
461461

462462
match vi.node {
463463
// ignore metadata, I guess
464-
ast::view_item_extern_mod(lib_ident, path_opt, _, _) => {
464+
ast::view_item_extern_mod(lib_ident, path_opt, _) => {
465465
let lib_name = match path_opt {
466466
Some((p, _)) => p,
467467
None => self.sess.str_of(lib_ident)

src/libsyntax/ast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1057,7 +1057,7 @@ pub enum view_item_ {
10571057
// optional @str: if present, this is a location (containing
10581058
// arbitrary characters) from which to fetch the crate sources
10591059
// For example, extern mod whatever = "github.com/mozilla/rust"
1060-
view_item_extern_mod(Ident, Option<(@str, StrStyle)>, ~[@MetaItem], NodeId),
1060+
view_item_extern_mod(Ident, Option<(@str, StrStyle)>, NodeId),
10611061
view_item_use(~[@view_path]),
10621062
}
10631063

src/libsyntax/ast_util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ impl<'a, O: IdVisitingOperation> Visitor<()> for IdVisitor<'a, O> {
419419

420420
fn visit_view_item(&mut self, view_item: &view_item, env: ()) {
421421
match view_item.node {
422-
view_item_extern_mod(_, _, _, node_id) => {
422+
view_item_extern_mod(_, _, node_id) => {
423423
self.operation.visit_id(node_id)
424424
}
425425
view_item_use(ref view_paths) => {

0 commit comments

Comments
 (0)