Skip to content

Subcrate's privates leak, and then cause linker errors #1690

@bfops

Description

@bfops

I'm getting a parent crate to "accidentally" use private functions from a sub-crate private module. The compile succeeds, but then the link fails!

main.rs:

extern crate bar;

fn main() {
  let bar = bar::Bar::new();
  bar.foo.foo();
}

bar/mod.rs

mod priv_bar;

pub struct Bar {
  pub foo: priv_bar::Foo,
}

impl Bar {
  pub fn new() -> Bar {
    Bar { foo: priv_bar::Foo }
  }
}

bar/priv_bar.rs:

pub struct Foo;

impl Foo {
  pub fn foo(&self) {
    println!("hello world");
  }
}

If bar/priv_bar.rs is inlined into bar/mod.rs, this doesn't happen; the correct error message is printed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions