Skip to content

Commit 4ba94e2

Browse files
committed
rustc: Don't allocate a cnum to syntax crates
Syntax-only crates are no longer registered with the cstore, so there's no need to allocate crate numbers to them. This ends up leaving gaps in the crate numbering scheme which is not expected in the rest of the compiler. Closes #13560
1 parent 12391df commit 4ba94e2

File tree

5 files changed

+79
-4
lines changed

5 files changed

+79
-4
lines changed

src/librustc/metadata/creader.rs

+11-4
Original file line numberDiff line numberDiff line change
@@ -300,10 +300,6 @@ fn resolve_crate<'a>(e: &mut Env,
300300
dylib, rlib, metadata
301301
} = load_ctxt.load_library_crate(root);
302302

303-
// Claim this crate number and cache it
304-
let cnum = e.next_crate_num;
305-
e.next_crate_num += 1;
306-
307303
// Stash paths for top-most crate locally if necessary.
308304
let crate_paths = if root.is_none() {
309305
Some(CratePaths {
@@ -324,6 +320,17 @@ fn resolve_crate<'a>(e: &mut Env,
324320
@RefCell::new(HashMap::new())
325321
};
326322

323+
// Claim this crate number and cache it if we're linking to the
324+
// crate, otherwise it's a syntax-only crate and we don't need to
325+
// reserve a number
326+
let cnum = if should_link {
327+
let n = e.next_crate_num;
328+
e.next_crate_num += 1;
329+
n
330+
} else {
331+
-1
332+
};
333+
327334
let cmeta = @cstore::crate_metadata {
328335
name: load_ctxt.crate_id.name.to_owned(),
329336
data: metadata,

src/test/auxiliary/issue-13560-1.rs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright 2014 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+
// no-prefer-dynamic
12+
13+
#![crate_type = "dylib"]

src/test/auxiliary/issue-13560-2.rs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright 2014 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+
// no-prefer-dynamic
12+
13+
#![crate_type = "rlib"]

src/test/auxiliary/issue-13560-3.rs

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2014 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+
// no-prefer-dynamic
12+
13+
#![crate_type = "rlib"]
14+
#![feature(phase)]
15+
16+
#[phase(syntax)] extern crate t1 = "issue-13560-1";
17+
#[phase(syntax, link)] extern crate t2 = "issue-13560-2";
18+
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2014 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:issue-13560-1.rs
12+
// aux-build:issue-13560-2.rs
13+
// aux-build:issue-13560-3.rs
14+
// ignore-stage1
15+
// ignore-android
16+
// ignore-cross-compile #12102
17+
18+
// Regression test for issue #13560, the test itself is all in the dependent
19+
// libraries. The fail which previously failed to compile is the one numbered 3.
20+
21+
extern crate t2 = "issue-13560-2";
22+
extern crate t3 = "issue-13560-3";
23+
24+
fn main() {}

0 commit comments

Comments
 (0)