From cf535a3b8fa63fb1e7539fa06e087c1886d48c0a Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Fri, 30 Jan 2015 09:48:23 -0800 Subject: [PATCH] rustc: Use --extern to always override Previously if --extern was specified it would not override crates in the standard distribution, leading to issues like #21771. This commit alters the behavior such that if --extern is passed then it will always override any other choice of crates and no previous match will be used (unless it is the same path as --extern). Closes #21771 --- src/librustc/metadata/creader.rs | 1 + .../extern-overrides-distribution/Makefile | 5 +++++ .../extern-overrides-distribution/libc.rs | 13 +++++++++++++ .../extern-overrides-distribution/main.rs | 16 ++++++++++++++++ 4 files changed, 35 insertions(+) create mode 100644 src/test/run-make/extern-overrides-distribution/Makefile create mode 100644 src/test/run-make/extern-overrides-distribution/libc.rs create mode 100644 src/test/run-make/extern-overrides-distribution/main.rs diff --git a/src/librustc/metadata/creader.rs b/src/librustc/metadata/creader.rs index 7b71120ba64..16141b171ff 100644 --- a/src/librustc/metadata/creader.rs +++ b/src/librustc/metadata/creader.rs @@ -330,6 +330,7 @@ impl<'a> CrateReader<'a> { if found { ret = Some(cnum); } + return } // Alright, so we've gotten this far which means that `data` has the diff --git a/src/test/run-make/extern-overrides-distribution/Makefile b/src/test/run-make/extern-overrides-distribution/Makefile new file mode 100644 index 00000000000..110db9f068d --- /dev/null +++ b/src/test/run-make/extern-overrides-distribution/Makefile @@ -0,0 +1,5 @@ +-include ../tools.mk + +all: + $(RUSTC) libc.rs + $(RUSTC) main.rs --extern libc=$(TMPDIR)/liblibc.rlib diff --git a/src/test/run-make/extern-overrides-distribution/libc.rs b/src/test/run-make/extern-overrides-distribution/libc.rs new file mode 100644 index 00000000000..a489d834a92 --- /dev/null +++ b/src/test/run-make/extern-overrides-distribution/libc.rs @@ -0,0 +1,13 @@ +// Copyright 2015 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. + +#![crate_type = "lib"] + +pub fn foo() {} diff --git a/src/test/run-make/extern-overrides-distribution/main.rs b/src/test/run-make/extern-overrides-distribution/main.rs new file mode 100644 index 00000000000..92b353c892a --- /dev/null +++ b/src/test/run-make/extern-overrides-distribution/main.rs @@ -0,0 +1,16 @@ +// Copyright 2015 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. + +extern crate libc; + +fn main() { + libc::foo(); +} +