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

Support slice::get && Ignore trait predicates when not visible to local. #1434

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ziqiaozhou
Copy link
Collaborator

  • Why: trait SliceIndex<T: ?Sized>: private_slice_index::Sealed
  • Add spec for slice::get

By submitting this pull request, I confirm that my contribution is made under the terms of the MIT license.

* Why: trait SliceIndex<T: ?Sized>: private_slice_index::Sealed
* Add spec for slice::get
@ziqiaozhou ziqiaozhou marked this pull request as ready for review February 5, 2025 22:28
let mut visible = tcx.visibility(td.def_id).is_visible_locally();
let mut def_id = td.def_id;
while let Some(parent_def_id) = tcx.opt_parent(def_id) {
if !tcx.visibility(parent_def_id).is_visible_locally() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

It looks like this is rejecting some traits that actually are visible, like Iterator:

td.def_id = DefId(2:8781 ~ core[145f]::iter::traits::iterator::Iterator)
parent_def_id = DefId(2:8736 ~ core[145f]::iter::traits::iterator)

In https://github.com/rust-lang/rust/blob/master/library/core/src/iter/traits/mod.rs , it looks like Iterator is made visible via a pub use after being initially declared in a private module:

mod accum;
mod collect;
mod double_ended;
mod exact_size;
mod iterator;
mod marker;
mod unchecked_iterator;

#[unstable(issue = "none", feature = "inplace_iteration")]
pub use self::marker::InPlaceIterable;
#[unstable(issue = "none", feature = "trusted_fused")]
pub use self::marker::TrustedFused;
#[unstable(feature = "trusted_step", issue = "85731")]
pub use self::marker::TrustedStep;
pub(crate) use self::unchecked_iterator::UncheckedIterator;
#[stable(feature = "rust1", since = "1.0.0")]
pub use self::{
    accum::{Product, Sum},
    collect::{Extend, FromIterator, IntoIterator},
    double_ended::DoubleEndedIterator,
    exact_size::ExactSizeIterator,
    iterator::Iterator,
    marker::{FusedIterator, TrustedLen},
};

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh. I see. Then I do not know how to check whether a trait is reacheable. I did not find a correct helper function from TyCtxt. Maybe do a hard check on path?

let path = tcx.def_path_str(tp.trait_ref.def_id);
if path == "core::slice::index::private_slice_index::Sealed" {
    false
} else if

if !visible {
// Skip private trait bounds
let path = tcx.def_path_str(tp.trait_ref.def_id);
if path == "core::slice::index::private_slice_index::Sealed" {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This would be better as a call to verus_items::get_rust_item, but otherwise it's fine.

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.

2 participants