1
Fork 0

legacy_ctor_visibility -> error

This commit is contained in:
Mazdak Farrokhzad 2019-08-03 16:59:05 +02:00
parent e8b190ac4a
commit c0056c04f6
6 changed files with 13 additions and 79 deletions

View file

@ -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> = 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 ## legacy-directory-ownership
The legacy_directory_ownership warning is issued when The legacy_directory_ownership warning is issued when

View file

@ -218,16 +218,6 @@ declare_lint! {
}; };
} }
declare_lint! {
pub LEGACY_CONSTRUCTOR_VISIBILITY,
Deny,
"detects use of struct constructors that would be invisible with new visibility rules",
@future_incompatible = FutureIncompatibleInfo {
reference: "issue #39207 <https://github.com/rust-lang/rust/issues/39207>",
edition: None,
};
}
declare_lint! { declare_lint! {
pub MISSING_FRAGMENT_SPECIFIER, pub MISSING_FRAGMENT_SPECIFIER,
Deny, Deny,
@ -560,7 +550,6 @@ declare_lint_pass! {
SAFE_PACKED_BORROWS, SAFE_PACKED_BORROWS,
PATTERNS_IN_FNS_WITHOUT_BODY, PATTERNS_IN_FNS_WITHOUT_BODY,
LEGACY_DIRECTORY_OWNERSHIP, LEGACY_DIRECTORY_OWNERSHIP,
LEGACY_CONSTRUCTOR_VISIBILITY,
MISSING_FRAGMENT_SPECIFIER, MISSING_FRAGMENT_SPECIFIER,
PARENTHESIZED_PARAMS_IN_TYPES_AND_MODULES, PARENTHESIZED_PARAMS_IN_TYPES_AND_MODULES,
LATE_BOUND_LIFETIME_ARGUMENTS, LATE_BOUND_LIFETIME_ARGUMENTS,

View file

@ -334,6 +334,8 @@ fn register_builtins(store: &mut lint::LintStore, no_interleave_lints: bool) {
"converted into hard error, see https://github.com/rust-lang/rust/issues/57742"); "converted into hard error, see https://github.com/rust-lang/rust/issues/57742");
store.register_removed("incoherent_fundamental_impls", store.register_removed("incoherent_fundamental_impls",
"converted into hard error, see https://github.com/rust-lang/rust/issues/46205"); "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");
} }
fn register_internals(store: &mut lint::LintStore) { fn register_internals(store: &mut lint::LintStore) {

View file

@ -1539,25 +1539,7 @@ impl<'a, 'b> LateResolutionVisitor<'a, '_> {
if is_expected(partial_res.base_res()) || partial_res.base_res() == Res::Err { if is_expected(partial_res.base_res()) || partial_res.base_res() == Res::Err {
partial_res partial_res
} else { } else {
// Add a temporary hack to smooth the transition to new struct ctor report_errors(self, Some(partial_res.base_res()))
// 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.r.struct_constructors.get(&def_id).cloned() {
if is_expected(ctor_res) &&
self.r.is_accessible_from(ctor_vis, self.parent_scope.module) {
let lint = lint::builtin::LEGACY_CONSTRUCTOR_VISIBILITY;
self.r.lint_buffer.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())))
} }
} }
Some(partial_res) if source.defer_to_typeck() => { Some(partial_res) if source.defer_to_typeck() => {

View file

@ -1,7 +1,3 @@
// ignore-tidy-linelength
#![allow(unused)]
use m::S; use m::S;
mod m { mod m {
@ -11,8 +7,7 @@ mod m {
use S; use S;
fn f() { fn f() {
S(10); S(10);
//~^ ERROR private struct constructors are not usable through re-exports in outer modules //~^ ERROR expected function, tuple struct or tuple variant, found struct `S`
//~| WARN this was previously accepted
} }
} }
} }

View file

@ -1,12 +1,13 @@
error: private struct constructors are not usable through re-exports in outer modules error[E0423]: expected function, tuple struct or tuple variant, found struct `S`
--> $DIR/legacy-ctor-visibility.rs:13:13 --> $DIR/legacy-ctor-visibility.rs:9:13
| |
LL | S(10); LL | / fn f() {
| ^ LL | | S(10);
| | | ^ help: a function with a similar name exists: `f`
= note: `#[deny(legacy_constructor_visibility)]` on by default LL | |
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! LL | | }
= note: for more information, see issue #39207 <https://github.com/rust-lang/rust/issues/39207> | |_________- similarly named function `f` defined here
error: aborting due to previous error error: aborting due to previous error
For more information about this error, try `rustc --explain E0423`.