diff options
| author | Nick Cameron <ncameron@mozilla.com> | 2015-09-18 18:07:05 +1200 |
|---|---|---|
| committer | Brian Anderson <banderson@mozilla.com> | 2015-10-16 15:47:32 -0700 |
| commit | 667584d6344bd36925630ce41bc0bd604d712e16 (patch) | |
| tree | 172ca779c9b1c8a5b63a1189b39a5b1f0d6204a2 | |
| parent | b672349a23e6e0587589cbfd9f2b7ff176218ec2 (diff) | |
| download | rust-667584d6344bd36925630ce41bc0bd604d712e16.tar.gz rust-667584d6344bd36925630ce41bc0bd604d712e16.zip | |
Warn on `pub extern crate`.
Temporary 'fix' for #26775
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 17 | ||||
| -rw-r--r-- | src/test/compile-fail/warn-pub-extern-crate.rs | 18 |
2 files changed, 30 insertions, 5 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index ff622859cf0..8d50cc099bd 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -5116,12 +5116,19 @@ impl<'a> Parser<'a> { try!(self.expect(&token::Semi)); let last_span = self.last_span; + + if visibility == ast::Public { + self.span_warn(mk_sp(lo, last_span.hi), + "`pub extern crate` does not work as expected and should not be used. \ + Likely to become an error. Prefer `extern crate` and `pub use`."); + } + Ok(self.mk_item(lo, - last_span.hi, - ident, - ItemExternCrate(maybe_path), - visibility, - attrs)) + last_span.hi, + ident, + ItemExternCrate(maybe_path), + visibility, + attrs)) } /// Parse `extern` for foreign ABIs diff --git a/src/test/compile-fail/warn-pub-extern-crate.rs b/src/test/compile-fail/warn-pub-extern-crate.rs new file mode 100644 index 00000000000..fec0b8e1a4c --- /dev/null +++ b/src/test/compile-fail/warn-pub-extern-crate.rs @@ -0,0 +1,18 @@ +// 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 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Check that `pub extern crate` gives a warning. + + +pub extern crate core; //~WARN `pub extern crate` does not work +//~^ ERROR core + +fn main() { +} |
