-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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 support for trait-objects without a principal #56837
Conversation
03e5829
to
1cc08c2
Compare
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
cc someone who knows rustdoc (e.g., @QuietMisdreavus) about the last commit. |
src/librustc_privacy/lib.rs
Outdated
if let Some(principal_def_id) = obj.principal_def_id() { | ||
principal_def_id | ||
} else { | ||
return Some(AccessLevel::Public) |
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.
What this code (and other uses of ty::Dynamic
in rustc_privacy) really wants is to treat all the bounds (principal and not principal) uniformly and find minimum or maximum on them.
It's using principal because when it was written only Send
and Sync
could be non-principal components, and they could always be considered public.
Now things changed, non-principal components can be private auto traits, so this behavior is actually a bug.
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 this behavior is actually a bug.
It was a bug before, wasn't it?
Which of them is it - minimum or maximum? I'll fix it, especially if you can provide a test.
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.
Yes, this is a pre-existing issue.
I'll try to come up with some tests.
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.
Fixed in #56878
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.
Did a quick pass. This approach seems nice.
src/librustc/traits/coherence.rs
Outdated
ty::Dynamic(ref data, ..) => tcx.has_attr(data.principal().def_id(), "fundamental"), | ||
ty::Dynamic(ref data, ..) => { | ||
if let Some(principal) = data.principal() { | ||
// FIXME: this does not look quite correct! |
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.
Can you elaborate on this FIXME? I think we decided to just not make trait objects fundamental anyway, right? So maybe it's a moot point?
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.
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.
I'll rebase this when that PR lands, to avoid annoying rebase cascades.
@@ -579,13 +579,18 @@ impl<'a, 'gcx, 'tcx> Binder<ExistentialPredicate<'tcx>> { | |||
impl<'tcx> serialize::UseSpecializedDecodable for &'tcx List<ExistentialPredicate<'tcx>> {} | |||
|
|||
impl<'tcx> List<ExistentialPredicate<'tcx>> { | |||
pub fn principal(&self) -> ExistentialTraitRef<'tcx> { | |||
pub fn principal(&self) -> Option<ExistentialTraitRef<'tcx>> { |
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.
Seems like a good place for a comment =)
} | ||
} | ||
// FIXME: also check auto-trait def-ids? (e.g. `impl Sync for Foo+Sync`)? |
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.
Seems like a bug, yes. We'll have to handle the more general version of this check eventually, I imagine.
(I really wish we had just banned implementing traits for object types, but we didn't...)
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.
You mean, made object types "orphan everywhere"?
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.
Also, not related to this PR. I'll report an issue.
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.
This is #56934. I might actually fix it in a later commit on this PR.
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.
You mean, made object types "orphan everywhere"?
Yes, basically.
44e506a
to
b55bc4e
Compare
Your PR failed on Travis (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem. Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
☔ The latest upstream changes (presumably #56481) made this pull request unmergeable. Please resolve the merge conflicts. |
privacy: Use common `DefId` visiting infrastructure for all privacy visitors One repeating pattern in privacy checking is going through a type, visiting all `DefId`s inside it and doing something with them. This is the case because visibilities and reachabilities are attached to `DefId`s. Previously various privacy visitors visited types slightly differently using their own methods, with most recently written `TypePrivacyVisitor` being the "gold standard". This mostly worked okay, but differences could manifest in overly conservative reachability analysis, some errors being reported twice, some private-in-public lints (not errors) being wrongly reported or not reported. This PR does something that I wanted to do since #32674 (comment) - factoring out the common visiting logic! Now all the common logic is contained in `struct DefIdVisitorSkeleton`, with specific privacy visitors deciding only what to do with visited `DefId`s (via `trait DefIdVisitor`). A bunch of cleanups is also applied in the process. This area is somewhat tricky due to lots of easily miss-able details, but thankfully it's was well covered by tests in #46083 and previous PRs, so I'm relatively sure in the refactoring correctness. Fixes #56837 (comment) in particular. Also this will help with implementing #48054.
b55bc4e
to
ae924b4
Compare
ae924b4
to
0b511b7
Compare
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
Annoying instability. How does this happen? |
This makes sure they are printed in a compiler-version-independent order, avoiding ui test instability.
@bors r+ |
📌 Commit c213b0d has been approved by |
…akis Add support for trait-objects without a principal The hard-error version of #56481 - should be merged after we do something about the `traitobject` crate. Fixes #33140. Fixes #57057. r? @nikomatsakis
☀️ Test successful - status-appveyor, status-travis |
Changes: ```` Revert "tests: used_underscore_binding_macro: disable random_state lint." Revert "Auto merge of rust-lang#3603 - xfix:random-state-lint, r=phansch" rustup rust-lang#56837 rustup (don't know the exact PR unfortunately) Add itertools to integration tests tests: used_underscore_binding_macro: disable random_state lint. Trigger `use_self` lint in local macros Add run-rustfix where it already passes rustup: rust-lang#55517 Make clippy work with parallel rustc Add ui/for_kv_map test for false positive in rust-lang#1279 Update to latest compiletest-rs release add testcase for rust-lang#3462 deps: bump rustc_tools_util version from 0.1.0 to 0.1.1 just in case... Use compiletest's aux-build header instead of include macro rustc_tool_utils: fix failure to create proper non-repo version string when used in crates on crates.io, bump version rustfmt UI test cleanup: Extract ifs_same_cond tests Extract IteratorFalsePositives into option_helpers.rs UI test cleanup: Extract for_kv_map lint tests UI test cleanup: Extract lint from methods.rs test Fix test for rust-lang#57250 Limit infinite_iter collect() check to known types Some improvements to util documentation Use hashset for name blacklist Reformat random_state tests Use node_id_to_type_opt instead of node_it_to_type in random_state Check pattern equality while checking declaration equality random_state lint Move constant write checks to temporary_assignment lint Use an FxHashSet for valid idents in documentation lint Fix suggestion for unnecessary_ref lint Update CONTRIBUTING.md for rustfix tests Update .fixed files via update-references.sh Run rustfix on first UI test Use WIP branch for compiletest_rs ````
Changes: ```` Revert "tests: used_underscore_binding_macro: disable random_state lint." Revert "Auto merge of rust-lang#3603 - xfix:random-state-lint, r=phansch" rustup rust-lang#56837 rustup (don't know the exact PR unfortunately) Add itertools to integration tests tests: used_underscore_binding_macro: disable random_state lint. Trigger `use_self` lint in local macros Add run-rustfix where it already passes rustup: rust-lang#55517 Make clippy work with parallel rustc Add ui/for_kv_map test for false positive in rust-lang#1279 Update to latest compiletest-rs release add testcase for rust-lang#3462 deps: bump rustc_tools_util version from 0.1.0 to 0.1.1 just in case... Use compiletest's aux-build header instead of include macro rustc_tool_utils: fix failure to create proper non-repo version string when used in crates on crates.io, bump version rustfmt UI test cleanup: Extract ifs_same_cond tests Extract IteratorFalsePositives into option_helpers.rs UI test cleanup: Extract for_kv_map lint tests UI test cleanup: Extract lint from methods.rs test Fix test for rust-lang#57250 Limit infinite_iter collect() check to known types Some improvements to util documentation Use hashset for name blacklist Reformat random_state tests Use node_id_to_type_opt instead of node_it_to_type in random_state Check pattern equality while checking declaration equality random_state lint Move constant write checks to temporary_assignment lint Use an FxHashSet for valid idents in documentation lint Fix suggestion for unnecessary_ref lint Update CONTRIBUTING.md for rustfix tests Update .fixed files via update-references.sh Run rustfix on first UI test Use WIP branch for compiletest_rs ````
Changes: ```` Revert "tests: used_underscore_binding_macro: disable random_state lint." Revert "Auto merge of rust-lang#3603 - xfix:random-state-lint, r=phansch" rustup rust-lang/rust#56837 rustup (don't know the exact PR unfortunately) Add itertools to integration tests tests: used_underscore_binding_macro: disable random_state lint. Trigger `use_self` lint in local macros Add run-rustfix where it already passes rustup: rust-lang/rust#55517 Make clippy work with parallel rustc Add ui/for_kv_map test for false positive in rust-lang#1279 Update to latest compiletest-rs release add testcase for rust-lang#3462 deps: bump rustc_tools_util version from 0.1.0 to 0.1.1 just in case... Use compiletest's aux-build header instead of include macro rustc_tool_utils: fix failure to create proper non-repo version string when used in crates on crates.io, bump version rustfmt UI test cleanup: Extract ifs_same_cond tests Extract IteratorFalsePositives into option_helpers.rs UI test cleanup: Extract for_kv_map lint tests UI test cleanup: Extract lint from methods.rs test Fix test for rust-lang/rust#57250 Limit infinite_iter collect() check to known types Some improvements to util documentation Use hashset for name blacklist Reformat random_state tests Use node_id_to_type_opt instead of node_it_to_type in random_state Check pattern equality while checking declaration equality random_state lint Move constant write checks to temporary_assignment lint Use an FxHashSet for valid idents in documentation lint Fix suggestion for unnecessary_ref lint Update CONTRIBUTING.md for rustfix tests Update .fixed files via update-references.sh Run rustfix on first UI test Use WIP branch for compiletest_rs ````
The hard-error version of #56481 - should be merged after we do something about the
traitobject
crate.Fixes #33140.
Fixes #57057.
r? @nikomatsakis