Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Existential type complains about private type in public interface if concrete type is not pub #53546

Closed

Description

@Arnavion
#![feature(existential_type)]

pub mod foo {
    pub existential type Foo: ::std::fmt::Debug;
    pub fn foo() -> Foo {
        S
    }

    #[derive(Debug)] struct S;
}

gives

warning: private type `foo::S` in public interface (error E0446)
 --> src/lib.rs:4:5
  |
4 |     pub existential type Foo: ::std::fmt::Debug;
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: #[warn(private_in_public)] 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 #34537 <https://github.com/rust-lang/rust/issues/34537>

Returning impl ::std::fmt::Debug does not have this restriction.

Activity

  1. jonhoo commented on Jan 10, 2019

    @jonhoo
    Contributor

    This also happens with closures:

    #![feature(existential_type)]
    pub existential type X: FnOnce();
    pub fn foo() -> X {
        || ()
    }

    gives

    warning: private type `[closure@src/lib.rs:5:5: 5:10]` in public interface (error E0446)
     --> src/lib.rs:3:1
      |
    3 | pub existential type X: FnOnce();
      | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      |
      = note: #[warn(private_in_public)] 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 #34537 <https://github.com/rust-lang/rust/issues/34537>
    
        Finished dev [unoptimized + debuginfo] target(s) in 0.36s
    

    And as far as I can tell, there isn't a way to work around this?

  2. jonhoo commented on Jan 10, 2019

    @jonhoo
    Contributor

    This should probably be tagged T-compiler, A-impl-trait, and A-lint.

  3. self-assigned this
    on Jan 10, 2019
  4. petrochenkov commented on Jan 10, 2019

    @petrochenkov
    Contributor

    I'll look what happens.
    The underlying type should not be revealed during privacy checking of impl Trait types.

  5. added
    A-visibility
    A-impl-trait
    on Jan 10, 2019
  6. jonhoo commented on Jan 10, 2019

    @jonhoo
    Contributor

    For some weird reason, I'm getting a hard error instead of a warning for this when it's happening in a much larger crate of mine on nightly-2019-01-09. I'm not using deny(private_in_public). Not sure whether that's related:

    error[E0446]: private type `[closure@noria/src/table.rs:295:31: 295:44]` in public interface
       --> noria/src/table.rs:219:5
        |
    219 |     existential type Future: Future<Item = Tagged<()>, Error = TableError>;
        |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private type
    ...
    295 |                     .fold((), |_, _| Ok(()))
        |                               ------------- `[closure@noria/src/table.rs:295:31: 295:44]` declared as private
    
  7. jonhoo commented on Jan 11, 2019

    @jonhoo
    Contributor

    Ouch, when this is an error, it's really hard to work around. @petrochenkov any luck trying to figure out the cause of this?

  8. petrochenkov commented on Jan 12, 2019

    @petrochenkov
    Contributor

    Fixed in #57556

  9. removed their assignment
    on Jan 12, 2019
  10. zroug commented on Jan 15, 2019

    @zroug

    I still get the warning for this example:

    #![feature(existential_type)]
    
    pub trait Test {
        type Foo;
        fn foo() -> Self::Foo;
    }
    
    struct FooImpl;
    
    impl Test for () {
        existential type Foo: ;
        fn foo() -> Self::Foo {
            FooImpl
        }
    }

    https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=944fd033d23b9698f766485ec9e452c8

  11. petrochenkov commented on Jan 15, 2019

    @petrochenkov
    Contributor

    Reopening to investigate #53546 (comment)

  12. self-assigned this
    on Jan 15, 2019
  13. petrochenkov commented on Jan 15, 2019

    @petrochenkov
    Contributor
  14. added 2 commits that reference this issue on Jan 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-impl-traitA-visibility

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions