]> git.lizzy.rs Git - rust.git/commitdiff
Turn deprecation lint `legacy_imports` into a hard error
authorVadim Petrochenkov <vadim.petrochenkov@gmail.com>
Mon, 14 May 2018 22:24:34 +0000 (01:24 +0300)
committerVadim Petrochenkov <vadim.petrochenkov@gmail.com>
Mon, 14 May 2018 23:25:04 +0000 (02:25 +0300)
src/doc/rustc/src/lints/listing/deny-by-default.md
src/librustc/lint/builtin.rs
src/librustc_lint/lib.rs
src/librustc_resolve/lib.rs
src/librustc_resolve/macros.rs
src/librustc_resolve/resolve_imports.rs
src/test/compile-fail/issue-38293.rs
src/test/ui/imports/rfc-1560-warning-cycle.rs
src/test/ui/imports/rfc-1560-warning-cycle.stderr

index ef76295f04d587a469fcfa38a2e0fbc4b35478fc..3a85a40fd1fdb9af606df8414f8289b4330949ee 100644 (file)
@@ -91,43 +91,6 @@ The legacy_directory_ownership warning is issued when
 The warning can be fixed by renaming the parent module to "mod.rs" and moving
 it into its own directory if appropriate.
 
-## legacy-imports
-
-This lint detects names that resolve to ambiguous glob imports. Some example
-code that triggers this lint:
-
-```rust,ignore
-pub struct Foo;
-
-mod bar {
-    struct Foo;
-
-    mod baz {
-        use *;
-        use bar::*;
-        fn f(_: Foo) {}
-    }
-}
-```
-
-This will produce:
-
-```text
-error: `Foo` is ambiguous
- --> src/main.rs:9:17
-  |
-7 |         use *;
-  |             - `Foo` could refer to the name imported here
-8 |         use bar::*;
-  |             ------ `Foo` could also refer to the name imported here
-9 |         fn f(_: Foo) {}
-  |                 ^^^
-  |
-  = note: #[deny(legacy_imports)] on by default
-  = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
-  = note: for more information, see issue #38260 <https://github.com/rust-lang/rust/issues/38260>
-```
-
 
 ## missing-fragment-specifier
 
index 4f015ed1ce161c5163c7b1fe8b61306e91f606f9..e3ccdf6872cfbc15e7f00b8e37e9264bd62ab3b5 100644 (file)
      not named `mod.rs`"
 }
 
-declare_lint! {
-    pub LEGACY_IMPORTS,
-    Deny,
-    "detects names that resolve to ambiguous glob imports with RFC 1560"
-}
-
 declare_lint! {
     pub LEGACY_CONSTRUCTOR_VISIBILITY,
     Deny,
@@ -314,7 +308,6 @@ fn get_lints(&self) -> LintArray {
             SAFE_PACKED_BORROWS,
             PATTERNS_IN_FNS_WITHOUT_BODY,
             LEGACY_DIRECTORY_OWNERSHIP,
-            LEGACY_IMPORTS,
             LEGACY_CONSTRUCTOR_VISIBILITY,
             MISSING_FRAGMENT_SPECIFIER,
             PARENTHESIZED_PARAMS_IN_TYPES_AND_MODULES,
index 39f550a4b459a7d0501d31e9d04845441af00cdb..ddcc1c1bf3ab48ee1cd1a6a43e5061578e62d46a 100644 (file)
@@ -224,11 +224,6 @@ macro_rules! add_lint_group {
             reference: "issue #37872 <https://github.com/rust-lang/rust/issues/37872>",
             edition: None,
         },
-        FutureIncompatibleInfo {
-            id: LintId::of(LEGACY_IMPORTS),
-            reference: "issue #38260 <https://github.com/rust-lang/rust/issues/38260>",
-            edition: None,
-        },
         FutureIncompatibleInfo {
             id: LintId::of(LEGACY_CONSTRUCTOR_VISIBILITY),
             reference: "issue #39207 <https://github.com/rust-lang/rust/issues/39207>",
@@ -317,6 +312,8 @@ macro_rules! add_lint_group {
         "converted into hard error, see https://github.com/rust-lang/rust/issues/36892");
     store.register_removed("extra_requirement_in_impl",
         "converted into hard error, see https://github.com/rust-lang/rust/issues/37166");
+    store.register_removed("legacy_imports",
+        "converted into hard error, see https://github.com/rust-lang/rust/issues/38260");
     store.register_removed("coerce_never",
         "converted into hard error, see https://github.com/rust-lang/rust/issues/48950");
     store.register_removed("resolve_trait_on_defaulted_unit",
index 0f931d4374e59337a7e43c78ff7f1cc6f579b030..51361133e944404edaeb21c6360c069eea359e4a 100644 (file)
@@ -1225,12 +1225,10 @@ enum NameBindingKind<'a> {
         binding: &'a NameBinding<'a>,
         directive: &'a ImportDirective<'a>,
         used: Cell<bool>,
-        legacy_self_import: bool,
     },
     Ambiguity {
         b1: &'a NameBinding<'a>,
         b2: &'a NameBinding<'a>,
-        legacy: bool,
     }
 }
 
@@ -1252,7 +1250,6 @@ struct AmbiguityError<'a> {
     lexical: bool,
     b1: &'a NameBinding<'a>,
     b2: &'a NameBinding<'a>,
-    legacy: bool,
 }
 
 impl<'a> NameBinding<'a> {
@@ -1260,7 +1257,6 @@ fn module(&self) -> Option<Module<'a>> {
         match self.kind {
             NameBindingKind::Module(module) => Some(module),
             NameBindingKind::Import { binding, .. } => binding.module(),
-            NameBindingKind::Ambiguity { legacy: true, b1, .. } => b1.module(),
             _ => None,
         }
     }
@@ -1270,7 +1266,6 @@ fn def(&self) -> Def {
             NameBindingKind::Def(def) => def,
             NameBindingKind::Module(module) => module.def().unwrap(),
             NameBindingKind::Import { binding, .. } => binding.def(),
-            NameBindingKind::Ambiguity { legacy: true, b1, .. } => b1.def(),
             NameBindingKind::Ambiguity { .. } => Def::Err,
         }
     }
@@ -1853,27 +1848,20 @@ fn new_module(
     fn record_use(&mut self, ident: Ident, ns: Namespace, binding: &'a NameBinding<'a>, span: Span)
                   -> bool /* true if an error was reported */ {
         match binding.kind {
-            NameBindingKind::Import { directive, binding, ref used, legacy_self_import }
+            NameBindingKind::Import { directive, binding, ref used }
                     if !used.get() => {
                 used.set(true);
                 directive.used.set(true);
-                if legacy_self_import {
-                    self.warn_legacy_self_import(directive);
-                    return false;
-                }
                 self.used_imports.insert((directive.id, ns));
                 self.add_to_glob_map(directive.id, ident);
                 self.record_use(ident, ns, binding, span)
             }
             NameBindingKind::Import { .. } => false,
-            NameBindingKind::Ambiguity { b1, b2, legacy } => {
+            NameBindingKind::Ambiguity { b1, b2 } => {
                 self.ambiguity_errors.push(AmbiguityError {
-                    span: span, name: ident.name, lexical: false, b1: b1, b2: b2, legacy,
+                    span, name: ident.name, lexical: false, b1, b2,
                 });
-                if legacy {
-                    self.record_use(ident, ns, b1, span);
-                }
-                !legacy
+                true
             }
             _ => false
         }
@@ -4074,7 +4062,7 @@ fn report_errors(&mut self, krate: &Crate) {
         self.report_proc_macro_import(krate);
         let mut reported_spans = FxHashSet();
 
-        for &AmbiguityError { span, name, b1, b2, lexical, legacy } in &self.ambiguity_errors {
+        for &AmbiguityError { span, name, b1, b2, lexical } in &self.ambiguity_errors {
             if !reported_spans.insert(span) { continue }
             let participle = |binding: &NameBinding| {
                 if binding.is_import() { "imported" } else { "defined" }
@@ -4090,27 +4078,15 @@ fn report_errors(&mut self, krate: &Crate) {
                 format!("macro-expanded {} do not shadow when used in a macro invocation path",
                         if b1.is_import() { "imports" } else { "items" })
             };
-            if legacy {
-                let id = match b2.kind {
-                    NameBindingKind::Import { directive, .. } => directive.id,
-                    _ => unreachable!(),
-                };
-                let mut span = MultiSpan::from_span(span);
-                span.push_span_label(b1.span, msg1);
-                span.push_span_label(b2.span, msg2);
-                let msg = format!("`{}` is ambiguous", name);
-                self.session.buffer_lint(lint::builtin::LEGACY_IMPORTS, id, span, &msg);
-            } else {
-                let mut err =
-                    struct_span_err!(self.session, span, E0659, "`{}` is ambiguous", name);
-                err.span_note(b1.span, &msg1);
-                match b2.def() {
-                    Def::Macro(..) if b2.span == DUMMY_SP =>
-                        err.note(&format!("`{}` is also a builtin macro", name)),
-                    _ => err.span_note(b2.span, &msg2),
-                };
-                err.note(&note).emit();
-            }
+
+            let mut err = struct_span_err!(self.session, span, E0659, "`{}` is ambiguous", name);
+            err.span_note(b1.span, &msg1);
+            match b2.def() {
+                Def::Macro(..) if b2.span == DUMMY_SP =>
+                    err.note(&format!("`{}` is also a builtin macro", name)),
+                _ => err.span_note(b2.span, &msg2),
+            };
+            err.note(&note).emit();
         }
 
         for &PrivacyError(span, name, binding) in &self.privacy_errors {
@@ -4261,12 +4237,6 @@ fn report_conflict<'b>(&mut self,
         self.name_already_seen.insert(name, span);
     }
 
-    fn warn_legacy_self_import(&self, directive: &'a ImportDirective<'a>) {
-        let (id, span) = (directive.id, directive.span);
-        let msg = "`self` no longer imports values";
-        self.session.buffer_lint(lint::builtin::LEGACY_IMPORTS, id, span, msg);
-    }
-
     fn check_proc_macro_attrs(&mut self, attrs: &[ast::Attribute]) {
         if self.proc_macro_enabled { return; }
 
index 4afc621ad8b3e2751c8d6cccd2daac8ef9c2e51b..0a0e8bac9e2e9c22e074899db6076be737c99e92 100644 (file)
@@ -528,7 +528,6 @@ pub fn resolve_lexical_macro_path_segment(&mut self,
                                 b1: shadower,
                                 b2: binding,
                                 lexical: true,
-                                legacy: false,
                             });
                             return potential_illegal_shadower;
                         }
index 6a5a31a885fb9855c880239da9df6a23358da1cc..111b4e448c74db83554f93447d75f74a974cead9 100644 (file)
@@ -179,7 +179,6 @@ pub fn resolve_ident_in_module_unadjusted(&mut self,
                             lexical: false,
                             b1: binding,
                             b2: shadowed_glob,
-                            legacy: false,
                         });
                     }
                 }
@@ -351,7 +350,6 @@ pub fn import(&self, binding: &'a NameBinding<'a>, directive: &'a ImportDirectiv
                 binding,
                 directive,
                 used: Cell::new(false),
-                legacy_self_import: false,
             },
             span: directive.span,
             vis,
@@ -400,7 +398,7 @@ pub fn try_define(&mut self,
     pub fn ambiguity(&self, b1: &'a NameBinding<'a>, b2: &'a NameBinding<'a>)
                      -> &'a NameBinding<'a> {
         self.arenas.alloc_name_binding(NameBinding {
-            kind: NameBindingKind::Ambiguity { b1: b1, b2: b2, legacy: false },
+            kind: NameBindingKind::Ambiguity { b1, b2 },
             vis: if b1.vis.is_at_least(b2.vis, self) { b1.vis } else { b2.vis },
             span: b1.span,
             expansion: Mark::root(),
@@ -687,7 +685,6 @@ fn finalize_import(&mut self, directive: &'b ImportDirective<'b>) -> Option<(Spa
                                 binding,
                                 directive,
                                 used: Cell::new(false),
-                                legacy_self_import: false,
                             },
                             vis: directive.vis.get(),
                             span: directive.span,
@@ -747,7 +744,6 @@ fn finalize_import(&mut self, directive: &'b ImportDirective<'b>) -> Option<(Spa
         };
 
         let mut all_ns_err = true;
-        let mut legacy_self_import = None;
         self.per_ns(|this, ns| if !type_ns_only || ns == TypeNS {
             if let Ok(binding) = result[ns].get() {
                 all_ns_err = false;
@@ -756,30 +752,9 @@ fn finalize_import(&mut self, directive: &'b ImportDirective<'b>) -> Option<(Spa
                         Some(this.dummy_binding);
                 }
             }
-        } else if let Ok(binding) = this.resolve_ident_in_module(module,
-                                                                 ident,
-                                                                 ns,
-                                                                 false,
-                                                                 false,
-                                                                 directive.span) {
-            legacy_self_import = Some(directive);
-            let binding = this.arenas.alloc_name_binding(NameBinding {
-                kind: NameBindingKind::Import {
-                    binding,
-                    directive,
-                    used: Cell::new(false),
-                    legacy_self_import: true,
-                },
-                ..*binding
-            });
-            let _ = this.try_define(directive.parent, ident, ns, binding);
         });
 
         if all_ns_err {
-            if let Some(directive) = legacy_self_import {
-                self.warn_legacy_self_import(directive);
-                return None;
-            }
             let mut all_ns_failed = true;
             self.per_ns(|this, ns| if !type_ns_only || ns == TypeNS {
                 match this.resolve_ident_in_module(module, ident, ns, false, true, span) {
@@ -1026,23 +1001,6 @@ fn finalize_resolutions_in(&mut self, module: Module<'b>) {
                             err.emit();
                     }
                 }
-                NameBindingKind::Ambiguity { b1, b2, .. }
-                        if b1.is_glob_import() && b2.is_glob_import() => {
-                    let (orig_b1, orig_b2) = match (&b1.kind, &b2.kind) {
-                        (&NameBindingKind::Import { binding: b1, .. },
-                         &NameBindingKind::Import { binding: b2, .. }) => (b1, b2),
-                        _ => continue,
-                    };
-                    let (b1, b2) = match (orig_b1.vis, orig_b2.vis) {
-                        (ty::Visibility::Public, ty::Visibility::Public) => continue,
-                        (ty::Visibility::Public, _) => (b1, b2),
-                        (_, ty::Visibility::Public) => (b2, b1),
-                        _ => continue,
-                    };
-                    resolution.binding = Some(self.arenas.alloc_name_binding(NameBinding {
-                        kind: NameBindingKind::Ambiguity { b1: b1, b2: b2, legacy: true }, ..*b1
-                    }));
-                }
                 _ => {}
             }
         }
index bd352b204bddf2339f924fc62dada670e8652008..1867bafa7e3d255286625a36848cf61f38a89bbc 100644 (file)
 
 // Test that `fn foo::bar::{self}` only imports `bar` in the type namespace.
 
-#![allow(unused)]
-
 mod foo {
     pub fn f() { }
 }
-use foo::f::{self};
-//~^ ERROR `self` no longer imports values
-//~| WARN hard error
+use foo::f::{self}; //~ ERROR unresolved import `foo::f`
 
 mod bar {
     pub fn baz() {}
     pub mod baz {}
 }
 use bar::baz::{self};
-//~^ ERROR `self` no longer imports values
-//~| WARN hard error
 
 fn main() {
-    baz();
+    baz(); //~ ERROR expected function, found module `baz`
 }
index f94fc3633e341819ebbb7e1f8a5bd857c8d47f54..5b62c5fcd3f31cfcfc6c2c1b8bfbc1cad80a2ab8 100644 (file)
@@ -8,8 +8,6 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-#![allow(unused)]
-
 pub struct Foo;
 
 mod bar {
@@ -18,9 +16,7 @@ mod bar {
     mod baz {
         use *;
         use bar::*;
-        fn f(_: Foo) {}
-        //~^ ERROR `Foo` is ambiguous
-        //~| WARN hard error in a future release
+        fn f(_: Foo) {} //~ ERROR `Foo` is ambiguous
     }
 }
 
index 452fcc4c1a9195ebc2e3dac6c81b27fd1342536f..5a01680fc1921dcc4371215afa46986a4582c60c 100644 (file)
@@ -1,16 +1,21 @@
-error: `Foo` is ambiguous
-  --> $DIR/rfc-1560-warning-cycle.rs:21:17
+error[E0659]: `Foo` is ambiguous
+  --> $DIR/rfc-1560-warning-cycle.rs:19:17
    |
-LL |         use *;
-   |             - `Foo` could refer to the name imported here
-LL |         use bar::*;
-   |             ------ `Foo` could also refer to the name imported here
-LL |         fn f(_: Foo) {}
+LL |         fn f(_: Foo) {} //~ ERROR `Foo` is ambiguous
    |                 ^^^
    |
-   = note: #[deny(legacy_imports)] on by default
-   = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
-   = note: for more information, see issue #38260 <https://github.com/rust-lang/rust/issues/38260>
+note: `Foo` could refer to the name imported here
+  --> $DIR/rfc-1560-warning-cycle.rs:17:13
+   |
+LL |         use *;
+   |             ^
+note: `Foo` could also refer to the name imported here
+  --> $DIR/rfc-1560-warning-cycle.rs:18:13
+   |
+LL |         use bar::*;
+   |             ^^^^^^
+   = note: consider adding an explicit import of `Foo` to disambiguate
 
 error: aborting due to previous error
 
+For more information about this error, try `rustc --explain E0659`.