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

+7-9
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

+5-2
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

+1-1
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

+1-1
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

+3-3
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

+1-1
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

+22-3
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

+1-1
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

+1-1
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

+1-1
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) => {

src/libsyntax/fold.rs

-2
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,9 @@ pub trait ast_fold {
6666
let inner_view_item = match vi.node {
6767
view_item_extern_mod(ref ident,
6868
string,
69-
ref meta_items,
7069
node_id) => {
7170
view_item_extern_mod(ident.clone(),
7271
string,
73-
self.fold_meta_items(*meta_items),
7472
self.new_id(node_id))
7573
}
7674
view_item_use(ref view_paths) => {

src/libsyntax/parse/obsolete.rs

+6
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ pub enum ObsoleteSyntax {
4545
ObsoleteBoxedClosure,
4646
ObsoleteClosureType,
4747
ObsoleteMultipleImport,
48+
ObsoleteExternModAttributesInParens
4849
}
4950

5051
impl to_bytes::IterBytes for ObsoleteSyntax {
@@ -145,6 +146,11 @@ impl ParserObsoleteMethods for Parser {
145146
"multiple imports",
146147
"only one import is allowed per `use` statement"
147148
),
149+
ObsoleteExternModAttributesInParens => (
150+
"`extern mod` with linkage attribute list",
151+
"use `extern mod foo = \"bar\";` instead of \
152+
`extern mod foo (name = \"bar\")`"
153+
)
148154
};
149155

150156
self.report(sp, kind, kind_str, desc);

src/libsyntax/parse/parser.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -4446,11 +4446,18 @@ impl Parser {
44464446
self.span_err(*self.span, "an ABI may not be specified here");
44474447
}
44484448

4449+
4450+
if *self.token == token::LPAREN {
4451+
// `extern mod foo (name = "bar"[,vers = "version"]) is obsolete,
4452+
// `extern mod foo = "bar#[version]";` should be used.
4453+
// Parse obsolete options to avoid wired parser errors
4454+
self.parse_optional_meta();
4455+
self.obsolete(*self.span, ObsoleteExternModAttributesInParens);
4456+
}
44494457
// extern mod foo;
4450-
let metadata = self.parse_optional_meta();
44514458
self.expect(&token::SEMI);
44524459
iovi_view_item(ast::view_item {
4453-
node: view_item_extern_mod(ident, maybe_path, metadata, ast::DUMMY_NODE_ID),
4460+
node: view_item_extern_mod(ident, maybe_path, ast::DUMMY_NODE_ID),
44544461
attrs: attrs,
44554462
vis: visibility,
44564463
span: mk_sp(lo, self.last_span.hi)

src/libsyntax/print/pprust.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -1952,7 +1952,7 @@ pub fn print_view_item(s: @ps, item: &ast::view_item) {
19521952
print_outer_attributes(s, item.attrs);
19531953
print_visibility(s, item.vis);
19541954
match item.node {
1955-
ast::view_item_extern_mod(id, ref optional_path, ref mta, _) => {
1955+
ast::view_item_extern_mod(id, ref optional_path, _) => {
19561956
head(s, "extern mod");
19571957
print_ident(s, id);
19581958
for &(ref p, style) in optional_path.iter() {
@@ -1961,11 +1961,6 @@ pub fn print_view_item(s: @ps, item: &ast::view_item) {
19611961
space(s.s);
19621962
print_string(s, *p, style);
19631963
}
1964-
if !mta.is_empty() {
1965-
popen(s);
1966-
commasep(s, consistent, *mta, |p, &i| print_meta_item(p, i));
1967-
pclose(s);
1968-
}
19691964
}
19701965

19711966
ast::view_item_use(ref vps) => {

src/libsyntax/visit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ pub fn walk_mod<E:Clone, V:Visitor<E>>(visitor: &mut V, module: &_mod, env: E) {
139139

140140
pub fn walk_view_item<E:Clone, V:Visitor<E>>(visitor: &mut V, vi: &view_item, env: E) {
141141
match vi.node {
142-
view_item_extern_mod(name, _, _, _) => {
142+
view_item_extern_mod(name, _, _) => {
143143
visitor.visit_ident(vi.span, name, env)
144144
}
145145
view_item_use(ref paths) => {

src/test/run-pass/crateresolve8.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
#[crate_id="crateresolve8#0.1"];
1515

16-
extern mod crateresolve8(vers = "0.1", package_id="crateresolve8#0.1");
16+
extern mod crateresolve8 = "crateresolve8#0.1";
1717
//extern mod crateresolve8(vers = "0.1");
1818

1919
pub fn main() {

src/test/run-pass/extern-crosscrate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// xfail-fast
1212
//aux-build:extern-crosscrate-source.rs
1313

14-
extern mod externcallback(vers = "0.1");
14+
extern mod externcallback = "externcallback#0.1";
1515

1616
fn fact(n: uint) -> uint {
1717
unsafe {

src/test/run-pass/issue-6919.rs

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
// xfail-fast
1313

1414
#[crate_id="issue-6919"];
15-
1615
extern mod issue6919_3;
1716

1817
pub fn main() {

0 commit comments

Comments
 (0)