-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Remove gensym in format_args #63114
Remove gensym in format_args #63114
Conversation
Oh, this is interesting. It would be good to implement some pre-requisites before doing that.
|
|
So, I think the problem with |
Otherwise, LGTM. |
OK, so I've have a local rework of the handling of reachability through macros and ran into this case: #![feature(decl_macro)]
mod n {
pub struct B(pub(crate) p::C);
impl B {
pub fn new() -> Self {
B(p::C)
}
}
mod p {
pub struct C;
impl C {
pub fn foo(&self) -> i32 {
33
}
}
}
}
// This macro can (currently) be called cross-crate
pub macro m() {
n::B::new().0.foo()
} I'm currently handling this by making the field of |
Fields are also "ephemeral", but can link to non-ephemeral things like new reachable types with public methods. The situation is pretty similar to modules, I think. mod m {
pub struct Z;
impl Z {
pub fn public() {}
}
}
pub struct S {
field: m::Z,
} Both module (An alternative would be to use two flags like "reachable for propagation" and "reachable for checking" or something.) |
Actually, it may be possible to just calculate reachability in two passes - first reach everything ignoring nominal visibilities like it's done now, then visit everything again and reset anything with non- |
* Allow items to be accessible through private modules and fields when a macro can access them. * Don't mark type-private items as reachable. * Never make items exported/public via macros
They were reachable through opaque macros defined in `core`
ae048c4
to
d9d9246
Compare
@matthewjasper |
Yes, it's ready. |
@bors r+ Sorry for the delay, I wanted to write some comments, but all of them are non-blocking, so I'll just write them later. |
📌 Commit d9d9246 has been approved by |
… r=petrochenkov Remove gensym in format_args This also fixes some things to allow us to export opaque macros from libcore: * Don't consider items that are only reachable through opaque macros as public/exported (so they aren't linted as needing docs) * Mark private items reachable from the root of libcore as unstable - they are now reachable (in principle) in other crates via macros in libcore r? @petrochenkov
Rollup of 7 pull requests Successful merges: - #62672 (Deprecate `try!` macro) - #62950 (Check rustbook links on all platforms when running locally) - #63114 (Remove gensym in format_args) - #63397 (Add tests for some ICEs) - #63403 (Improve test output) - #63404 (enable flt2dec tests in Miri) - #63407 (reduce some test sizes in Miri) Failed merges: r? @ghost
// No type privacy, so can be directly marked as reachable. | ||
DefKind::Const | ||
| DefKind::Macro(_) | ||
| DefKind::Static |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Statics are actually protected by a kind of extension to type privacy, since they are real items existing during linking:
rust/src/librustc_privacy/lib.rs
Lines 1107 to 1110 in 813a3a5
// Additionally, until better reachability analysis for macros 2.0 is available, | |
// we prohibit access to private statics from other crates, this allows to give | |
// more code internal visibility at link time. (Access to private functions | |
// is already prohibited by type privacy for function types.) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other things in this list are also "ephemeral" and we need to "reach through" them rather than mark them as reachable themselves.
This optimization probably not too important though (no examples in libcore) and it would be better to somehow introduce the distinction between "reach including" and "reach excluding" nodes in the reachability visitor in general rather than in its macro part only.
@@ -826,7 +948,12 @@ impl DefIdVisitor<'tcx> for ReachEverythingInTheInterfaceVisitor<'_, 'tcx> { | |||
fn tcx(&self) -> TyCtxt<'tcx> { self.ev.tcx } | |||
fn visit_def_id(&mut self, def_id: DefId, _kind: &str, _descr: &dyn fmt::Display) -> bool { | |||
if let Some(hir_id) = self.ev.tcx.hir().as_local_hir_id(def_id) { | |||
self.ev.update(hir_id, self.access_level); | |||
if let ((ty::Visibility::Public, ..), _) | |||
| (_, Some(AccessLevel::ReachableFromImplTrait)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, the consequence is that we don't mark Priv
as reachable in situations like this:
pub fn foo() where Priv: Condition { ... }
This case is not covered by type privacy and foo
can be used from other crates.
Is Priv
required to be reachable at link time in this case? I think no, so what this PR does is ok.
Anyway, if something breaks we'll get bug reports and add them into the test suite.
Fix nested eager expansions in arguments of `format_args` Fixes rust-lang#63460 Fixes rust-lang#63685 (regression from making `format_args` opaque - rust-lang#63114) r? @matthewjasper
This also fixes some things to allow us to export opaque macros from libcore:
r? @petrochenkov