Skip to content

Commit dbfa9c8

Browse files
committed
legacy-ctor-visibility -> hard error
1 parent 8e917f4 commit dbfa9c8

File tree

6 files changed

+8
-78
lines changed

6 files changed

+8
-78
lines changed

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

-35
Original file line numberDiff line numberDiff line change
@@ -45,41 +45,6 @@ error: defaults for type parameters are only allowed in `struct`, `enum`, `type`
4545
= note: for more information, see issue #36887 <https://github.com/rust-lang/rust/issues/36887>
4646
```
4747

48-
## legacy-constructor-visibility
49-
50-
[RFC 1506](https://github.com/rust-lang/rfcs/blob/master/text/1506-adt-kinds.md) modified some
51-
visibility rules, and changed the visibility of struct constructors. Some
52-
example code that triggers this lint:
53-
54-
```rust,ignore
55-
mod m {
56-
pub struct S(u8);
57-
58-
fn f() {
59-
// this is trying to use S from the 'use' line, but because the `u8` is
60-
// not pub, it is private
61-
::S;
62-
}
63-
}
64-
65-
use m::S;
66-
```
67-
68-
This will produce:
69-
70-
```text
71-
error: private struct constructors are not usable through re-exports in outer modules
72-
--> src/main.rs:5:9
73-
|
74-
5 | ::S;
75-
| ^^^
76-
|
77-
= note: `#[deny(legacy_constructor_visibility)]` on by default
78-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
79-
= note: for more information, see issue #39207 <https://github.com/rust-lang/rust/issues/39207>
80-
```
81-
82-
8348
## legacy-directory-ownership
8449

8550
The legacy_directory_ownership warning is issued when

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_CONSTRUCTOR_VISIBILITY,
181-
Deny,
182-
"detects use of struct constructors that would be invisible with new visibility rules"
183-
}
184-
185179
declare_lint! {
186180
pub MISSING_FRAGMENT_SPECIFIER,
187181
Deny,
@@ -427,7 +421,6 @@ declare_lint_pass! {
427421
SAFE_PACKED_BORROWS,
428422
PATTERNS_IN_FNS_WITHOUT_BODY,
429423
LEGACY_DIRECTORY_OWNERSHIP,
430-
LEGACY_CONSTRUCTOR_VISIBILITY,
431424
MISSING_FRAGMENT_SPECIFIER,
432425
PARENTHESIZED_PARAMS_IN_TYPES_AND_MODULES,
433426
LATE_BOUND_LIFETIME_ARGUMENTS,

src/librustc_lint/lib.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -336,11 +336,6 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
336336
reference: "issue #37872 <https://github.com/rust-lang/rust/issues/37872>",
337337
edition: None,
338338
},
339-
FutureIncompatibleInfo {
340-
id: LintId::of(LEGACY_CONSTRUCTOR_VISIBILITY),
341-
reference: "issue #39207 <https://github.com/rust-lang/rust/issues/39207>",
342-
edition: None,
343-
},
344339
FutureIncompatibleInfo {
345340
id: LintId::of(MISSING_FRAGMENT_SPECIFIER),
346341
reference: "issue #40107 <https://github.com/rust-lang/rust/issues/40107>",
@@ -488,6 +483,8 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
488483
"converted into hard error, see https://github.com/rust-lang/rust/issues/57742");
489484
store.register_removed("incoherent_fundamental_impls",
490485
"converted into hard error, see https://github.com/rust-lang/rust/issues/46205");
486+
store.register_removed("legacy_constructor_visibility",
487+
"converted into hard error, see https://github.com/rust-lang/rust/issues/39207");
491488
}
492489

493490
pub fn register_internals(store: &mut lint::LintStore, sess: Option<&Session>) {

src/librustc_resolve/lib.rs

+1-18
Original file line numberDiff line numberDiff line change
@@ -3495,24 +3495,7 @@ impl<'a> Resolver<'a> {
34953495
if is_expected(partial_res.base_res()) || partial_res.base_res() == Res::Err {
34963496
partial_res
34973497
} else {
3498-
// Add a temporary hack to smooth the transition to new struct ctor
3499-
// visibility rules. See #38932 for more details.
3500-
let mut res = None;
3501-
if let Res::Def(DefKind::Struct, def_id) = partial_res.base_res() {
3502-
if let Some((ctor_res, ctor_vis))
3503-
= self.struct_constructors.get(&def_id).cloned() {
3504-
if is_expected(ctor_res) && self.is_accessible(ctor_vis) {
3505-
let lint = lint::builtin::LEGACY_CONSTRUCTOR_VISIBILITY;
3506-
self.session.buffer_lint(lint, id, span,
3507-
"private struct constructors are not usable through \
3508-
re-exports in outer modules",
3509-
);
3510-
res = Some(PartialRes::new(ctor_res));
3511-
}
3512-
}
3513-
}
3514-
3515-
res.unwrap_or_else(|| report_errors(self, Some(partial_res.base_res())))
3498+
report_errors(self, Some(partial_res.base_res()))
35163499
}
35173500
}
35183501
Some(partial_res) if source.defer_to_typeck() => {

src/test/ui/privacy/legacy-ctor-visibility.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
// ignore-tidy-linelength
2-
3-
#![allow(unused)]
4-
51
use m::S;
62

73
mod m {
@@ -11,8 +7,7 @@ mod m {
117
use S;
128
fn f() {
139
S(10);
14-
//~^ ERROR private struct constructors are not usable through re-exports in outer modules
15-
//~| WARN this was previously accepted
10+
//~^ ERROR expected function, found struct `S`
1611
}
1712
}
1813
}
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
error: private struct constructors are not usable through re-exports in outer modules
2-
--> $DIR/legacy-ctor-visibility.rs:13:13
1+
error[E0423]: expected function, found struct `S`
2+
--> $DIR/legacy-ctor-visibility.rs:9:13
33
|
44
LL | S(10);
5-
| ^
6-
|
7-
= note: `#[deny(legacy_constructor_visibility)]` on by default
8-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
9-
= note: for more information, see issue #39207 <https://github.com/rust-lang/rust/issues/39207>
5+
| ^ help: a function with a similar name exists: `f`
106

117
error: aborting due to previous error
128

9+
For more information about this error, try `rustc --explain E0423`.

0 commit comments

Comments
 (0)