Skip to content
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

add a description of pub restricted #548

Merged
merged 2 commits into from
Aug 14, 2017

Conversation

driftluo
Copy link
Member

关于 pub(restricted) 的简单描述


这段代码编译无法通过,因为 `J` 无法在 `mod c` 的外部访问,而 `fn semisecret` 尝试在 `mod a` 中访问 `J`.

在 rust1.18 之前,正确的写法是,将 `fn semisecret` 移动到 `mod c` 中,并将其 `pub`,之后根据需要可以重新导出 `semisecret`。
Copy link
Member

Choose a reason for hiding this comment

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

正确的做法难道不是在 mod ause self::b::c::J; 么?

Copy link
Member Author

Choose a reason for hiding this comment

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

mod ause self::b::c::J 是不行的,会被编译器拒绝,http://play.integer32.com/?gist=0257ccea97fb26a26c52ebf1ed0970f6&version=stable

Copy link
Member

Choose a reason for hiding this comment

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

当然。你需要设置 J 为 pub吧。。。

Copy link
Member Author

@driftluo driftluo Aug 11, 2017

Choose a reason for hiding this comment

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

实际上,需要 mod cJ 同时设为 pub,或者 pub J 同时在 bpub use self::c::J;

}
```

这种情况可以正常工作,但是,这里有个严重的问题:无法明确的说明 `fn semiseret` 是为什么要 `pub`。同时,如果在 `a` 中使用 `pub use self::b::semisecret` ,那么所有人都可以通过 `use` 访问 `fn semiseret`,但是实际上,这个函数只需要让 `mod a` 访问就可以了。
Copy link
Member

Choose a reason for hiding this comment

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

没弄懂。。。这种情况下不用 pub use 来 re-export 不好么。。。

Copy link
Member

Choose a reason for hiding this comment

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

看了下面明白了,这里应该是 mod c 需要限制 mod a 的 re-export

Copy link
Member Author

Choose a reason for hiding this comment

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

这段,我翻译的有点问题,句子不知道应该怎么翻译了,这是原文

This works, but there is a serious issue with it: One cannot easily tell exactly how "public" fn semisecret is. In particular, understanding who can access semisecret requires reasoning about (1.) all of the pub use's (aka re-exports) of semisecret, and (2.) the pub-ness of every module in a path leading to fn semisecret or one of its re-exports.

Choose a reason for hiding this comment

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

nimenzaishuoshemme

@driftluo
Copy link
Member Author

@wayslog 改了一点用词,你看看?

@wayslog wayslog merged commit e7e580b into rustcc:master Aug 14, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants