Skip to content

Commit d1b0274

Browse files
committed
Turn deprecation lint legacy_imports into a hard error
1 parent 935a2f1 commit d1b0274

File tree

9 files changed

+35
-160
lines changed

9 files changed

+35
-160
lines changed

src/doc/rustc/src/lints/listing/deny-by-default.md

-37
Original file line numberDiff line numberDiff line change
@@ -91,43 +91,6 @@ The legacy_directory_ownership warning is issued when
9191
The warning can be fixed by renaming the parent module to "mod.rs" and moving
9292
it into its own directory if appropriate.
9393

94-
## legacy-imports
95-
96-
This lint detects names that resolve to ambiguous glob imports. Some example
97-
code that triggers this lint:
98-
99-
```rust,ignore
100-
pub struct Foo;
101-
102-
mod bar {
103-
struct Foo;
104-
105-
mod baz {
106-
use *;
107-
use bar::*;
108-
fn f(_: Foo) {}
109-
}
110-
}
111-
```
112-
113-
This will produce:
114-
115-
```text
116-
error: `Foo` is ambiguous
117-
--> src/main.rs:9:17
118-
|
119-
7 | use *;
120-
| - `Foo` could refer to the name imported here
121-
8 | use bar::*;
122-
| ------ `Foo` could also refer to the name imported here
123-
9 | fn f(_: Foo) {}
124-
| ^^^
125-
|
126-
= note: #[deny(legacy_imports)] on by default
127-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
128-
= note: for more information, see issue #38260 <https://github.com/rust-lang/rust/issues/38260>
129-
```
130-
13194

13295
## missing-fragment-specifier
13396

src/librustc/lint/builtin.rs

-7
Original file line numberDiff line numberDiff line change
@@ -176,12 +176,6 @@ declare_lint! {
176176
not named `mod.rs`"
177177
}
178178

179-
declare_lint! {
180-
pub LEGACY_IMPORTS,
181-
Deny,
182-
"detects names that resolve to ambiguous glob imports with RFC 1560"
183-
}
184-
185179
declare_lint! {
186180
pub LEGACY_CONSTRUCTOR_VISIBILITY,
187181
Deny,
@@ -314,7 +308,6 @@ impl LintPass for HardwiredLints {
314308
SAFE_PACKED_BORROWS,
315309
PATTERNS_IN_FNS_WITHOUT_BODY,
316310
LEGACY_DIRECTORY_OWNERSHIP,
317-
LEGACY_IMPORTS,
318311
LEGACY_CONSTRUCTOR_VISIBILITY,
319312
MISSING_FRAGMENT_SPECIFIER,
320313
PARENTHESIZED_PARAMS_IN_TYPES_AND_MODULES,

src/librustc_lint/lib.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -224,11 +224,6 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
224224
reference: "issue #37872 <https://github.com/rust-lang/rust/issues/37872>",
225225
edition: None,
226226
},
227-
FutureIncompatibleInfo {
228-
id: LintId::of(LEGACY_IMPORTS),
229-
reference: "issue #38260 <https://github.com/rust-lang/rust/issues/38260>",
230-
edition: None,
231-
},
232227
FutureIncompatibleInfo {
233228
id: LintId::of(LEGACY_CONSTRUCTOR_VISIBILITY),
234229
reference: "issue #39207 <https://github.com/rust-lang/rust/issues/39207>",
@@ -317,6 +312,8 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
317312
"converted into hard error, see https://github.com/rust-lang/rust/issues/36892");
318313
store.register_removed("extra_requirement_in_impl",
319314
"converted into hard error, see https://github.com/rust-lang/rust/issues/37166");
315+
store.register_removed("legacy_imports",
316+
"converted into hard error, see https://github.com/rust-lang/rust/issues/38260");
320317
store.register_removed("coerce_never",
321318
"converted into hard error, see https://github.com/rust-lang/rust/issues/48950");
322319
store.register_removed("resolve_trait_on_defaulted_unit",

src/librustc_resolve/lib.rs

+14-44
Original file line numberDiff line numberDiff line change
@@ -1225,12 +1225,10 @@ enum NameBindingKind<'a> {
12251225
binding: &'a NameBinding<'a>,
12261226
directive: &'a ImportDirective<'a>,
12271227
used: Cell<bool>,
1228-
legacy_self_import: bool,
12291228
},
12301229
Ambiguity {
12311230
b1: &'a NameBinding<'a>,
12321231
b2: &'a NameBinding<'a>,
1233-
legacy: bool,
12341232
}
12351233
}
12361234

@@ -1252,15 +1250,13 @@ struct AmbiguityError<'a> {
12521250
lexical: bool,
12531251
b1: &'a NameBinding<'a>,
12541252
b2: &'a NameBinding<'a>,
1255-
legacy: bool,
12561253
}
12571254

12581255
impl<'a> NameBinding<'a> {
12591256
fn module(&self) -> Option<Module<'a>> {
12601257
match self.kind {
12611258
NameBindingKind::Module(module) => Some(module),
12621259
NameBindingKind::Import { binding, .. } => binding.module(),
1263-
NameBindingKind::Ambiguity { legacy: true, b1, .. } => b1.module(),
12641260
_ => None,
12651261
}
12661262
}
@@ -1270,7 +1266,6 @@ impl<'a> NameBinding<'a> {
12701266
NameBindingKind::Def(def) => def,
12711267
NameBindingKind::Module(module) => module.def().unwrap(),
12721268
NameBindingKind::Import { binding, .. } => binding.def(),
1273-
NameBindingKind::Ambiguity { legacy: true, b1, .. } => b1.def(),
12741269
NameBindingKind::Ambiguity { .. } => Def::Err,
12751270
}
12761271
}
@@ -1853,27 +1848,20 @@ impl<'a> Resolver<'a> {
18531848
fn record_use(&mut self, ident: Ident, ns: Namespace, binding: &'a NameBinding<'a>, span: Span)
18541849
-> bool /* true if an error was reported */ {
18551850
match binding.kind {
1856-
NameBindingKind::Import { directive, binding, ref used, legacy_self_import }
1851+
NameBindingKind::Import { directive, binding, ref used }
18571852
if !used.get() => {
18581853
used.set(true);
18591854
directive.used.set(true);
1860-
if legacy_self_import {
1861-
self.warn_legacy_self_import(directive);
1862-
return false;
1863-
}
18641855
self.used_imports.insert((directive.id, ns));
18651856
self.add_to_glob_map(directive.id, ident);
18661857
self.record_use(ident, ns, binding, span)
18671858
}
18681859
NameBindingKind::Import { .. } => false,
1869-
NameBindingKind::Ambiguity { b1, b2, legacy } => {
1860+
NameBindingKind::Ambiguity { b1, b2 } => {
18701861
self.ambiguity_errors.push(AmbiguityError {
1871-
span: span, name: ident.name, lexical: false, b1: b1, b2: b2, legacy,
1862+
span, name: ident.name, lexical: false, b1, b2,
18721863
});
1873-
if legacy {
1874-
self.record_use(ident, ns, b1, span);
1875-
}
1876-
!legacy
1864+
true
18771865
}
18781866
_ => false
18791867
}
@@ -4074,7 +4062,7 @@ impl<'a> Resolver<'a> {
40744062
self.report_proc_macro_import(krate);
40754063
let mut reported_spans = FxHashSet();
40764064

4077-
for &AmbiguityError { span, name, b1, b2, lexical, legacy } in &self.ambiguity_errors {
4065+
for &AmbiguityError { span, name, b1, b2, lexical } in &self.ambiguity_errors {
40784066
if !reported_spans.insert(span) { continue }
40794067
let participle = |binding: &NameBinding| {
40804068
if binding.is_import() { "imported" } else { "defined" }
@@ -4090,27 +4078,15 @@ impl<'a> Resolver<'a> {
40904078
format!("macro-expanded {} do not shadow when used in a macro invocation path",
40914079
if b1.is_import() { "imports" } else { "items" })
40924080
};
4093-
if legacy {
4094-
let id = match b2.kind {
4095-
NameBindingKind::Import { directive, .. } => directive.id,
4096-
_ => unreachable!(),
4097-
};
4098-
let mut span = MultiSpan::from_span(span);
4099-
span.push_span_label(b1.span, msg1);
4100-
span.push_span_label(b2.span, msg2);
4101-
let msg = format!("`{}` is ambiguous", name);
4102-
self.session.buffer_lint(lint::builtin::LEGACY_IMPORTS, id, span, &msg);
4103-
} else {
4104-
let mut err =
4105-
struct_span_err!(self.session, span, E0659, "`{}` is ambiguous", name);
4106-
err.span_note(b1.span, &msg1);
4107-
match b2.def() {
4108-
Def::Macro(..) if b2.span == DUMMY_SP =>
4109-
err.note(&format!("`{}` is also a builtin macro", name)),
4110-
_ => err.span_note(b2.span, &msg2),
4111-
};
4112-
err.note(&note).emit();
4113-
}
4081+
4082+
let mut err = struct_span_err!(self.session, span, E0659, "`{}` is ambiguous", name);
4083+
err.span_note(b1.span, &msg1);
4084+
match b2.def() {
4085+
Def::Macro(..) if b2.span == DUMMY_SP =>
4086+
err.note(&format!("`{}` is also a builtin macro", name)),
4087+
_ => err.span_note(b2.span, &msg2),
4088+
};
4089+
err.note(&note).emit();
41144090
}
41154091

41164092
for &PrivacyError(span, name, binding) in &self.privacy_errors {
@@ -4261,12 +4237,6 @@ impl<'a> Resolver<'a> {
42614237
self.name_already_seen.insert(name, span);
42624238
}
42634239

4264-
fn warn_legacy_self_import(&self, directive: &'a ImportDirective<'a>) {
4265-
let (id, span) = (directive.id, directive.span);
4266-
let msg = "`self` no longer imports values";
4267-
self.session.buffer_lint(lint::builtin::LEGACY_IMPORTS, id, span, msg);
4268-
}
4269-
42704240
fn check_proc_macro_attrs(&mut self, attrs: &[ast::Attribute]) {
42714241
if self.proc_macro_enabled { return; }
42724242

src/librustc_resolve/macros.rs

-1
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,6 @@ impl<'a> Resolver<'a> {
528528
b1: shadower,
529529
b2: binding,
530530
lexical: true,
531-
legacy: false,
532531
});
533532
return potential_illegal_shadower;
534533
}

src/librustc_resolve/resolve_imports.rs

+1-43
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,6 @@ impl<'a> Resolver<'a> {
179179
lexical: false,
180180
b1: binding,
181181
b2: shadowed_glob,
182-
legacy: false,
183182
});
184183
}
185184
}
@@ -351,7 +350,6 @@ impl<'a> Resolver<'a> {
351350
binding,
352351
directive,
353352
used: Cell::new(false),
354-
legacy_self_import: false,
355353
},
356354
span: directive.span,
357355
vis,
@@ -400,7 +398,7 @@ impl<'a> Resolver<'a> {
400398
pub fn ambiguity(&self, b1: &'a NameBinding<'a>, b2: &'a NameBinding<'a>)
401399
-> &'a NameBinding<'a> {
402400
self.arenas.alloc_name_binding(NameBinding {
403-
kind: NameBindingKind::Ambiguity { b1: b1, b2: b2, legacy: false },
401+
kind: NameBindingKind::Ambiguity { b1, b2 },
404402
vis: if b1.vis.is_at_least(b2.vis, self) { b1.vis } else { b2.vis },
405403
span: b1.span,
406404
expansion: Mark::root(),
@@ -687,7 +685,6 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
687685
binding,
688686
directive,
689687
used: Cell::new(false),
690-
legacy_self_import: false,
691688
},
692689
vis: directive.vis.get(),
693690
span: directive.span,
@@ -747,7 +744,6 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
747744
};
748745

749746
let mut all_ns_err = true;
750-
let mut legacy_self_import = None;
751747
self.per_ns(|this, ns| if !type_ns_only || ns == TypeNS {
752748
if let Ok(binding) = result[ns].get() {
753749
all_ns_err = false;
@@ -756,30 +752,9 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
756752
Some(this.dummy_binding);
757753
}
758754
}
759-
} else if let Ok(binding) = this.resolve_ident_in_module(module,
760-
ident,
761-
ns,
762-
false,
763-
false,
764-
directive.span) {
765-
legacy_self_import = Some(directive);
766-
let binding = this.arenas.alloc_name_binding(NameBinding {
767-
kind: NameBindingKind::Import {
768-
binding,
769-
directive,
770-
used: Cell::new(false),
771-
legacy_self_import: true,
772-
},
773-
..*binding
774-
});
775-
let _ = this.try_define(directive.parent, ident, ns, binding);
776755
});
777756

778757
if all_ns_err {
779-
if let Some(directive) = legacy_self_import {
780-
self.warn_legacy_self_import(directive);
781-
return None;
782-
}
783758
let mut all_ns_failed = true;
784759
self.per_ns(|this, ns| if !type_ns_only || ns == TypeNS {
785760
match this.resolve_ident_in_module(module, ident, ns, false, true, span) {
@@ -1026,23 +1001,6 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
10261001
err.emit();
10271002
}
10281003
}
1029-
NameBindingKind::Ambiguity { b1, b2, .. }
1030-
if b1.is_glob_import() && b2.is_glob_import() => {
1031-
let (orig_b1, orig_b2) = match (&b1.kind, &b2.kind) {
1032-
(&NameBindingKind::Import { binding: b1, .. },
1033-
&NameBindingKind::Import { binding: b2, .. }) => (b1, b2),
1034-
_ => continue,
1035-
};
1036-
let (b1, b2) = match (orig_b1.vis, orig_b2.vis) {
1037-
(ty::Visibility::Public, ty::Visibility::Public) => continue,
1038-
(ty::Visibility::Public, _) => (b1, b2),
1039-
(_, ty::Visibility::Public) => (b2, b1),
1040-
_ => continue,
1041-
};
1042-
resolution.binding = Some(self.arenas.alloc_name_binding(NameBinding {
1043-
kind: NameBindingKind::Ambiguity { b1: b1, b2: b2, legacy: true }, ..*b1
1044-
}));
1045-
}
10461004
_ => {}
10471005
}
10481006
}

src/test/compile-fail/issue-38293.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,17 @@
1010

1111
// Test that `fn foo::bar::{self}` only imports `bar` in the type namespace.
1212

13-
#![allow(unused)]
14-
1513
mod foo {
1614
pub fn f() { }
1715
}
18-
use foo::f::{self};
19-
//~^ ERROR `self` no longer imports values
20-
//~| WARN hard error
16+
use foo::f::{self}; //~ ERROR unresolved import `foo::f`
2117

2218
mod bar {
2319
pub fn baz() {}
2420
pub mod baz {}
2521
}
2622
use bar::baz::{self};
27-
//~^ ERROR `self` no longer imports values
28-
//~| WARN hard error
2923

3024
fn main() {
31-
baz();
25+
baz(); //~ ERROR expected function, found module `baz`
3226
}

src/test/ui/imports/rfc-1560-warning-cycle.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#![allow(unused)]
12-
1311
pub struct Foo;
1412

1513
mod bar {
@@ -18,9 +16,7 @@ mod bar {
1816
mod baz {
1917
use *;
2018
use bar::*;
21-
fn f(_: Foo) {}
22-
//~^ ERROR `Foo` is ambiguous
23-
//~| WARN hard error in a future release
19+
fn f(_: Foo) {} //~ ERROR `Foo` is ambiguous
2420
}
2521
}
2622

Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
1-
error: `Foo` is ambiguous
2-
--> $DIR/rfc-1560-warning-cycle.rs:21:17
1+
error[E0659]: `Foo` is ambiguous
2+
--> $DIR/rfc-1560-warning-cycle.rs:19:17
33
|
4-
LL | use *;
5-
| - `Foo` could refer to the name imported here
6-
LL | use bar::*;
7-
| ------ `Foo` could also refer to the name imported here
8-
LL | fn f(_: Foo) {}
4+
LL | fn f(_: Foo) {} //~ ERROR `Foo` is ambiguous
95
| ^^^
106
|
11-
= note: #[deny(legacy_imports)] on by default
12-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
13-
= note: for more information, see issue #38260 <https://github.com/rust-lang/rust/issues/38260>
7+
note: `Foo` could refer to the name imported here
8+
--> $DIR/rfc-1560-warning-cycle.rs:17:13
9+
|
10+
LL | use *;
11+
| ^
12+
note: `Foo` could also refer to the name imported here
13+
--> $DIR/rfc-1560-warning-cycle.rs:18:13
14+
|
15+
LL | use bar::*;
16+
| ^^^^^^
17+
= note: consider adding an explicit import of `Foo` to disambiguate
1418

1519
error: aborting due to previous error
1620

21+
For more information about this error, try `rustc --explain E0659`.

0 commit comments

Comments
 (0)