Skip to content

Reach the body of functions returning impl Trait but don't treat it as public #52348

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

Merged
merged 1 commit into from
Jul 15, 2018
Merged
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
6 changes: 1 addition & 5 deletions src/librustc_privacy/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,10 +433,6 @@ impl<'b, 'a, 'tcx> ReachEverythingInTheInterfaceVisitor<'b, 'a, 'tcx> {

fn ty(&mut self) -> &mut Self {
let ty = self.ev.tcx.type_of(self.item_def_id);
self.walk_ty(ty)
}

fn walk_ty(&mut self, ty: Ty<'tcx>) -> &mut Self {
ty.visit_with(self);
if let ty::TyFnDef(def_id, _) = ty.sty {
if def_id == self.item_def_id {
Expand Down Expand Up @@ -1568,7 +1564,7 @@ impl<'a, 'tcx> Visitor<'tcx> for PrivateItemsInPublicInterfacesVisitor<'a, 'tcx>
// where `X` is the `impl Iterator<Item=T>` itself,
// stored in `predicates_of`, not in the `Ty` itself.

self.check(item.id, self.inner_visibility).predicates();
self.check(item.id, item_visibility).predicates();
}
// Subitems of these items have inherited publicity
hir::ItemConst(..) | hir::ItemStatic(..) | hir::ItemFn(..) |
Expand Down
6 changes: 5 additions & 1 deletion src/test/run-pass/impl-trait/auxiliary/xcrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ fn some_internal_fn() -> u32 {
1
}

fn other_internal_fn() -> u32 {
1
}

// See #40839
pub fn return_closure_accessing_internal_fn() -> impl Fn() -> u32 {
|| {
Expand All @@ -25,5 +29,5 @@ pub fn return_closure_accessing_internal_fn() -> impl Fn() -> u32 {
}

pub fn return_internal_fn() -> impl Fn() -> u32 {
some_internal_fn
other_internal_fn
}
35 changes: 35 additions & 0 deletions src/test/ui/impl-trait/issue-52128.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// compile-pass

#![deny(warnings)]

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() {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing newline at the end of a few files.