about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorVadim Petrochenkov <vadim.petrochenkov@gmail.com>2019-01-13 00:58:45 +0300
committerVadim Petrochenkov <vadim.petrochenkov@gmail.com>2019-01-13 01:50:53 +0300
commit6aa78563697245ff7835a57c7e7eb331e9ecec08 (patch)
tree7cf7add93229adabd076281195fc523f22447175 /src
parentd6525ef539a04cb43de40080bdabc5f2f5a4a197 (diff)
downloadrust-6aa78563697245ff7835a57c7e7eb331e9ecec08.tar.gz
rust-6aa78563697245ff7835a57c7e7eb331e9ecec08.zip
resolve: Mark extern crate items as used in more cases
Diffstat (limited to 'src')
-rw-r--r--src/librustc_resolve/lib.rs3
-rw-r--r--src/test/ui/imports/extern-crate-used.rs28
-rw-r--r--src/test/ui/imports/extern-crate-used.stderr38
3 files changed, 69 insertions, 0 deletions
diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs
index cf949b62a63..378f1c9fd66 100644
--- a/src/librustc_resolve/lib.rs
+++ b/src/librustc_resolve/lib.rs
@@ -5089,6 +5089,9 @@ impl<'a> Resolver<'a> {
         }
         self.extern_prelude.get(&ident.modern()).cloned().and_then(|entry| {
             if let Some(binding) = entry.extern_crate_item {
+                if !speculative && entry.introduced_by_item {
+                    self.record_use(ident, TypeNS, binding, false);
+                }
                 Some(binding)
             } else {
                 let crate_id = if !speculative {
diff --git a/src/test/ui/imports/extern-crate-used.rs b/src/test/ui/imports/extern-crate-used.rs
new file mode 100644
index 00000000000..2d91cbc00f2
--- /dev/null
+++ b/src/test/ui/imports/extern-crate-used.rs
@@ -0,0 +1,28 @@
+// Extern crate items are marked as used if they are used
+// through extern prelude entries introduced by them.
+
+// edition:2018
+
+#![deny(unused_extern_crates)]
+
+extern crate core as iso1; //~ ERROR `extern crate` is not idiomatic in the new edition
+extern crate core as iso2; //~ ERROR `extern crate` is not idiomatic in the new edition
+extern crate core as iso3; //~ ERROR `extern crate` is not idiomatic in the new edition
+extern crate core as iso4; //~ ERROR `extern crate` is not idiomatic in the new edition
+
+// Doesn't introduce its extern prelude entry, so it's still considered unused.
+extern crate core; //~ ERROR unused extern crate
+
+mod m {
+    use iso1::any as are_you_okay1;
+    use ::iso2::any as are_you_okay2;
+    type AreYouOkay1 = iso3::any::Any;
+    type AreYouOkay2 = ::iso4::any::Any;
+
+    use core::any as are_you_okay3;
+    use ::core::any as are_you_okay4;
+    type AreYouOkay3 = core::any::Any;
+    type AreYouOkay4 = ::core::any::Any;
+}
+
+fn main() {}
diff --git a/src/test/ui/imports/extern-crate-used.stderr b/src/test/ui/imports/extern-crate-used.stderr
new file mode 100644
index 00000000000..3f9aab9dc79
--- /dev/null
+++ b/src/test/ui/imports/extern-crate-used.stderr
@@ -0,0 +1,38 @@
+error: `extern crate` is not idiomatic in the new edition
+  --> $DIR/extern-crate-used.rs:8:1
+   |
+LL | extern crate core as iso1; //~ ERROR `extern crate` is not idiomatic in the new edition
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: convert it to a `use`
+   |
+note: lint level defined here
+  --> $DIR/extern-crate-used.rs:6:9
+   |
+LL | #![deny(unused_extern_crates)]
+   |         ^^^^^^^^^^^^^^^^^^^^
+
+error: `extern crate` is not idiomatic in the new edition
+  --> $DIR/extern-crate-used.rs:9:1
+   |
+LL | extern crate core as iso2; //~ ERROR `extern crate` is not idiomatic in the new edition
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: convert it to a `use`
+
+error: `extern crate` is not idiomatic in the new edition
+  --> $DIR/extern-crate-used.rs:10:1
+   |
+LL | extern crate core as iso3; //~ ERROR `extern crate` is not idiomatic in the new edition
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: convert it to a `use`
+
+error: `extern crate` is not idiomatic in the new edition
+  --> $DIR/extern-crate-used.rs:11:1
+   |
+LL | extern crate core as iso4; //~ ERROR `extern crate` is not idiomatic in the new edition
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: convert it to a `use`
+
+error: unused extern crate
+  --> $DIR/extern-crate-used.rs:14:1
+   |
+LL | extern crate core; //~ ERROR unused extern crate
+   | ^^^^^^^^^^^^^^^^^^ help: remove it
+
+error: aborting due to 5 previous errors
+