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

Tighten up the auto-deref algorithm #13542

Closed
brson opened this issue Apr 16, 2014 · 9 comments
Closed

Tighten up the auto-deref algorithm #13542

brson opened this issue Apr 16, 2014 · 9 comments
Assignees
Milestone

Comments

@brson
Copy link
Contributor

brson commented Apr 16, 2014

@nikomatsakis has mentioned that it has some unpredictable interactions with type checking. Hard to spec and understand as-is. Nominating.

@eddyb
Copy link
Member

eddyb commented Apr 16, 2014

Is this a dupe of #12825?

@nikomatsakis
Copy link
Contributor

No. I think what @brson was thinking of was an idea I had to make auto-deref behavior more predictable. The basic plan was to say that we always autoderef until we find a type T where one of the following conditions is true:

  1. The type T is defined in the current module or some ancestor of the current module.
  2. The type T is not derefable (does not implement Deref, not a built-in derefable type).

Such a plan would probably best go through the RFC process, and it might need some fine-tuning as well. I had planned to do some local experiments first. There are a fair number of pre-requisites, among them #5527 (which I think encompasses #12825).

@pnkfelix
Copy link
Member

Assigning P-backcompat-lang, 1.0.

@pnkfelix pnkfelix added this to the 1.0 milestone Apr 17, 2014
@nikomatsakis
Copy link
Contributor

Specifically: can we make it possible to add methods to smart pointers without breaking backwards compatibility for users of those smart pointers?

Also, is there a way to make smart pointers able to explicitly identify methods that they DO want to override? For example, Rc<T> may want clone() to be callable so users can write my_rc.clone().

One issue with my proposal in general is that if I implement a trait on a pointer type, you still won't be able to use that trait with method notation.

In other words,

trait Foo { fn foo(self); }
impl Foo for &T { fn foo(self); }

and

trait Foo { fn foo(&self); }
impl Foo for T { fn foo(&self); }

cannot be used in an equivalent way (in fact, they are not quite equivalent in the trait method resolution algorithm I already proposed; that's something I ... kind of forgot about and was meaning to rectify. But it's not too hard to rectify today).

@pcwalton
Copy link
Contributor

@nikomatsakis Is there an RFC on this? If so, could you link to it? If not, could you make one?

@nikomatsakis
Copy link
Contributor

I have not made an RFC. I've been hoping to finish #5527 / UFCS and do some experiments. Perhaps that is too conservative. I'll try to write something up, sure.

@pcwalton
Copy link
Contributor

After talking with Niko I'd like to nominate this for removal from 1.0. We don't have clear ideas on what to do here.

@pnkfelix
Copy link
Member

(postponing to triage where at least one of {patrick, niko} is present.)

@pnkfelix
Copy link
Member

(okay patrick came back.)

@pcwalton relays that during a 1:1 discussion with niko, their consensus is that the potential cures they could conceive seemed potentially worse than the disease here.

So taking off the 1.0 milestone, at least until someone proposed an RFC that is actually a net improvement.

In the meantime, the safest way to defend the issues described here that I can see is to use top-level functions rather than methods to manipulate the state of the smart pointer itself and avoid the auto-deref'ing.

Closing.

flip1995 pushed a commit to flip1995/rust that referenced this issue Oct 18, 2024
…r=y21

[`implicit_saturating_sub`] Fix suggestion with a less volatile approach

Related to rust-lang#13533, such and obvious mistake got pass my watch, quite embarassing :/

Revert rust-lang#13533 and implement a more robust solution.

Revert "Fix span issue on `implicit_saturating_sub`
This reverts commit 140a127.

changelog: [`lint_name`]: Fix suggestion for `if {} else if {} else {}` cases

r? `@y21`
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

No branches or pull requests

5 participants