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

Arbitrary self types v2: no deshadow pre feature. #134524

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

adetaylor
Copy link
Contributor

The arbitrary self types v2 work introduces a check for shadowed methods, whereby a method in some "outer" smart pointer type may called in preference to a method in the inner referent. This is bad if the outer pointer adds a method later, as it may change behavior, so we ensure we error in this circumstance.

It was intended that this new shadowing detection system only comes into play for users who enable the arbitrary_self_types feature (or of course everyone later if it's stabilized). It was believed that the new deshadowing code couldn't be reached without building the custom smart pointers that arbitrary_self_types enables, and therefore there was no risk of this code impacting existing users.

However, it turns out that cunning use of Pin::get_ref can cause this type of shadowing error to be emitted now. This commit adds a test for this case.

As we want this test to pass without arbitrary_self_types, but fail with it, I've split it into two files (one with run-pass and one without). If there's a better way I can amend it.

Part of #44874

r? @wesleywiser

The arbitrary self types v2 work introduces a check for shadowed
methods, whereby a method in some "outer" smart pointer type may called
in preference to a method in the inner referent. This is bad if the
outer pointer adds a method later, as it may change behavior, so we
ensure we error in this circumstance.

It was intended that this new shadowing detection system only comes into
play for users who enable the `arbitrary_self_types` feature (or of
course everyone later if it's stabilized). It was believed that the
new deshadowing code couldn't be reached without building the custom
smart pointers that `arbitrary_self_types` enables, and therefore there
was no risk of this code impacting existing users.

However, it turns out that cunning use of `Pin::get_ref` can cause
this type of shadowing error to be emitted now. This commit adds a test
for this case.

As we want this test to pass without arbitrary_self_types, but fail with
it, I've split it into two files (one with run-pass and one without). If
there's a better way I can amend it.
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Dec 19, 2024
// as we don't enable arbitrary self types.
// This will turn into an error if arbitrary_self_types feature is enabled.

//@ run-pass
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't need to be run pass if it's not exercising any runtime behavior.

Also you should use revisions rather than making two tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I couldn't figure out how to do that. This is what I know how to do:

//@ revisions: default feature
#![cfg_attr(feature, feature(arbitrary_self_types))]

but I want it to compile in one case, and not in the other. Even without the //@ run-pass it still complains at me unless both revisions emit a compile error. Can you advise?

Copy link
Member

Choose a reason for hiding this comment

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

it should be //@[feature] check-pass

and check-pass since as i said above you're not exercising runtime behavior

@jieyouxu jieyouxu self-assigned this Dec 19, 2024
let pinned_a: Pin<&mut A> = pin!(A);
let pinned_a: Pin<&A> = pinned_a.as_ref();
let _ = pinned_a.get_ref();
//~^ ERROR: multiple applicable items
Copy link
Member

Choose a reason for hiding this comment

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

I don't want to hold up this PR because adding the feature gate check is absolutely necessary as the other test case shows, but what is the plan for stabilizing the feature with regards to this check?

We can't just report this error when the feature is stabilized because that could break existing code. If we need to log an unresolved question for this, that's fine!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants