From 4ba94e2c24faf7b327567f67a7cf1e49cf0ffcce Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 16 Apr 2014 11:42:22 -0700 Subject: [PATCH] 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 --- src/librustc/metadata/creader.rs | 15 ++++++++++---- src/test/auxiliary/issue-13560-1.rs | 13 ++++++++++++ src/test/auxiliary/issue-13560-2.rs | 13 ++++++++++++ src/test/auxiliary/issue-13560-3.rs | 18 +++++++++++++++++ src/test/run-pass-fulldeps/issue-13560.rs | 24 +++++++++++++++++++++++ 5 files changed, 79 insertions(+), 4 deletions(-) create mode 100644 src/test/auxiliary/issue-13560-1.rs create mode 100644 src/test/auxiliary/issue-13560-2.rs create mode 100644 src/test/auxiliary/issue-13560-3.rs create mode 100644 src/test/run-pass-fulldeps/issue-13560.rs diff --git a/src/librustc/metadata/creader.rs b/src/librustc/metadata/creader.rs index e6b7049f4f8fa..799da4150c5d3 100644 --- a/src/librustc/metadata/creader.rs +++ b/src/librustc/metadata/creader.rs @@ -300,10 +300,6 @@ fn resolve_crate<'a>(e: &mut Env, dylib, rlib, metadata } = load_ctxt.load_library_crate(root); - // Claim this crate number and cache it - let cnum = e.next_crate_num; - e.next_crate_num += 1; - // Stash paths for top-most crate locally if necessary. let crate_paths = if root.is_none() { Some(CratePaths { @@ -324,6 +320,17 @@ fn resolve_crate<'a>(e: &mut Env, @RefCell::new(HashMap::new()) }; + // Claim this crate number and cache it if we're linking to the + // crate, otherwise it's a syntax-only crate and we don't need to + // reserve a number + let cnum = if should_link { + let n = e.next_crate_num; + e.next_crate_num += 1; + n + } else { + -1 + }; + let cmeta = @cstore::crate_metadata { name: load_ctxt.crate_id.name.to_owned(), data: metadata, diff --git a/src/test/auxiliary/issue-13560-1.rs b/src/test/auxiliary/issue-13560-1.rs new file mode 100644 index 0000000000000..858d7269cd874 --- /dev/null +++ b/src/test/auxiliary/issue-13560-1.rs @@ -0,0 +1,13 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// no-prefer-dynamic + +#![crate_type = "dylib"] diff --git a/src/test/auxiliary/issue-13560-2.rs b/src/test/auxiliary/issue-13560-2.rs new file mode 100644 index 0000000000000..8e46acca1244f --- /dev/null +++ b/src/test/auxiliary/issue-13560-2.rs @@ -0,0 +1,13 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// no-prefer-dynamic + +#![crate_type = "rlib"] diff --git a/src/test/auxiliary/issue-13560-3.rs b/src/test/auxiliary/issue-13560-3.rs new file mode 100644 index 0000000000000..3b77b244ce879 --- /dev/null +++ b/src/test/auxiliary/issue-13560-3.rs @@ -0,0 +1,18 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// no-prefer-dynamic + +#![crate_type = "rlib"] +#![feature(phase)] + +#[phase(syntax)] extern crate t1 = "issue-13560-1"; +#[phase(syntax, link)] extern crate t2 = "issue-13560-2"; + diff --git a/src/test/run-pass-fulldeps/issue-13560.rs b/src/test/run-pass-fulldeps/issue-13560.rs new file mode 100644 index 0000000000000..24010c7c8b18c --- /dev/null +++ b/src/test/run-pass-fulldeps/issue-13560.rs @@ -0,0 +1,24 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// aux-build:issue-13560-1.rs +// aux-build:issue-13560-2.rs +// aux-build:issue-13560-3.rs +// ignore-stage1 +// ignore-android +// ignore-cross-compile #12102 + +// Regression test for issue #13560, the test itself is all in the dependent +// libraries. The fail which previously failed to compile is the one numbered 3. + +extern crate t2 = "issue-13560-2"; +extern crate t3 = "issue-13560-3"; + +fn main() {}