Skip to content

Private in public lint wrong in presence of impl trait #52128

Closed
@bjorn3

Description

@bjorn3

https://play.rust-lang.org/?gist=6cba607fa159813cf9ba964e5780541e&version=nightly&mode=debug&edition=2015

Works on beta, but not on nightly.

This breaks miri.

use std::collections::BTreeMap;

pub struct RangeMap {
    map: BTreeMap<Range, u8>,
}

#[derive(Eq, PartialEq, Ord, PartialOrd)]
struct Range;

impl RangeMap {
    fn iter_with_range<'a>(&'a self) -> impl Iterator<Item = (&'a Range, &'a u8)> + 'a {
        self.map.range(Range..Range)
    }

    pub fn iter<'a>(&'a self) -> impl Iterator<Item = &'a u8> + 'a {
        self.iter_with_range().map(|(_, data)| data)
    }

}

fn main() {}
error[E0446]: private type `Range` in public interface
  --> src/main.rs:11:41
   |
8  | struct Range;
   | - `Range` declared as private
...
11 |     fn iter_with_range<'a>(&'a self) -> impl Iterator<Item = (&'a Range, &'a u8)> + 'a {
   |                                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private type

error: aborting due to previous error

Metadata

Metadata

Assignees

Labels

P-highHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-nightlyPerformance or correctness regression from stable to nightly.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions