Skip to content

legacy_ctor_visibility -> hard error #63240

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 0 additions & 35 deletions src/doc/rustc/src/lints/listing/deny-by-default.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,41 +45,6 @@ error: defaults for type parameters are only allowed in `struct`, `enum`, `type`
= note: for more information, see issue #36887 <https://github.com/rust-lang/rust/issues/36887>
```

## legacy-constructor-visibility

[RFC 1506](https://github.com/rust-lang/rfcs/blob/master/text/1506-adt-kinds.md) modified some
visibility rules, and changed the visibility of struct constructors. Some
example code that triggers this lint:

```rust,ignore
mod m {
pub struct S(u8);

fn f() {
// this is trying to use S from the 'use' line, but because the `u8` is
// not pub, it is private
::S;
}
}

use m::S;
```

This will produce:

```text
error: private struct constructors are not usable through re-exports in outer modules
--> src/main.rs:5:9
|
5 | ::S;
| ^^^
|
= note: `#[deny(legacy_constructor_visibility)]` 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 #39207 <https://github.com/rust-lang/rust/issues/39207>
```


## legacy-directory-ownership

The legacy_directory_ownership warning is issued when
Expand Down
7 changes: 0 additions & 7 deletions src/librustc/lint/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,6 @@ declare_lint! {
not named `mod.rs`"
}

declare_lint! {
pub LEGACY_CONSTRUCTOR_VISIBILITY,
Deny,
"detects use of struct constructors that would be invisible with new visibility rules"
}

declare_lint! {
pub MISSING_FRAGMENT_SPECIFIER,
Deny,
Expand Down Expand Up @@ -427,7 +421,6 @@ declare_lint_pass! {
SAFE_PACKED_BORROWS,
PATTERNS_IN_FNS_WITHOUT_BODY,
LEGACY_DIRECTORY_OWNERSHIP,
LEGACY_CONSTRUCTOR_VISIBILITY,
MISSING_FRAGMENT_SPECIFIER,
PARENTHESIZED_PARAMS_IN_TYPES_AND_MODULES,
LATE_BOUND_LIFETIME_ARGUMENTS,
Expand Down
7 changes: 2 additions & 5 deletions src/librustc_lint/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,11 +336,6 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
reference: "issue #37872 <https://github.com/rust-lang/rust/issues/37872>",
edition: None,
},
FutureIncompatibleInfo {
id: LintId::of(LEGACY_CONSTRUCTOR_VISIBILITY),
reference: "issue #39207 <https://github.com/rust-lang/rust/issues/39207>",
edition: None,
},
FutureIncompatibleInfo {
id: LintId::of(MISSING_FRAGMENT_SPECIFIER),
reference: "issue #40107 <https://github.com/rust-lang/rust/issues/40107>",
Expand Down Expand Up @@ -488,6 +483,8 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
"converted into hard error, see https://github.com/rust-lang/rust/issues/57742");
store.register_removed("incoherent_fundamental_impls",
"converted into hard error, see https://github.com/rust-lang/rust/issues/46205");
store.register_removed("legacy_constructor_visibility",
"converted into hard error, see https://github.com/rust-lang/rust/issues/39207");
}

pub fn register_internals(store: &mut lint::LintStore, sess: Option<&Session>) {
Expand Down
19 changes: 1 addition & 18 deletions src/librustc_resolve/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3495,24 +3495,7 @@ impl<'a> Resolver<'a> {
if is_expected(partial_res.base_res()) || partial_res.base_res() == Res::Err {
partial_res
} else {
// Add a temporary hack to smooth the transition to new struct ctor
// visibility rules. See #38932 for more details.
let mut res = None;
if let Res::Def(DefKind::Struct, def_id) = partial_res.base_res() {
if let Some((ctor_res, ctor_vis))
= self.struct_constructors.get(&def_id).cloned() {
if is_expected(ctor_res) && self.is_accessible(ctor_vis) {
let lint = lint::builtin::LEGACY_CONSTRUCTOR_VISIBILITY;
self.session.buffer_lint(lint, id, span,
"private struct constructors are not usable through \
re-exports in outer modules",
);
res = Some(PartialRes::new(ctor_res));
}
}
}

res.unwrap_or_else(|| report_errors(self, Some(partial_res.base_res())))
report_errors(self, Some(partial_res.base_res()))
}
}
Some(partial_res) if source.defer_to_typeck() => {
Expand Down
7 changes: 1 addition & 6 deletions src/test/ui/privacy/legacy-ctor-visibility.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
// ignore-tidy-linelength

#![allow(unused)]

use m::S;

mod m {
Expand All @@ -11,8 +7,7 @@ mod m {
use S;
fn f() {
S(10);
//~^ ERROR private struct constructors are not usable through re-exports in outer modules
//~| WARN this was previously accepted
//~^ ERROR expected function, found struct `S`
}
}
}
Expand Down
11 changes: 4 additions & 7 deletions src/test/ui/privacy/legacy-ctor-visibility.stderr
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
error: private struct constructors are not usable through re-exports in outer modules
--> $DIR/legacy-ctor-visibility.rs:13:13
error[E0423]: expected function, found struct `S`
--> $DIR/legacy-ctor-visibility.rs:9:13
|
LL | S(10);
| ^
|
= note: `#[deny(legacy_constructor_visibility)]` 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 #39207 <https://github.com/rust-lang/rust/issues/39207>
| ^ help: a function with a similar name exists: `f`

error: aborting due to previous error

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