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

#[no_override] for default methods #7649

Closed
huonw opened this issue Jul 8, 2013 · 5 comments
Closed

#[no_override] for default methods #7649

huonw opened this issue Jul 8, 2013 · 5 comments
Labels
A-attributes Area: #[attributes(..)]

Comments

@huonw
Copy link
Member

huonw commented Jul 8, 2013

If there was a #[no_override] attribute that made it impossible to override a default method, there would be very little need for the FooUtil traits (with this attribute default methods would have almost exactly the same properties as *Util, except the seperate trait can be imported separately). i.e.

trait Foo {
  fn bar(&self);

  #[no_override]
  fn call_bar(&self) { self.bar(); }
}
impl Foo for int {
  fn bar(&self) {}

  fn call_bar(&self) {} // error!
}

This would provide a workaround for #5898 that is a proper solution in its own right.

@metajack
Copy link
Contributor

This probably warrants some discussion on the mailing list or in a meeting. We need some kind of decision before we can take action here.

@sanxiyn sanxiyn added the B-RFC label Feb 10, 2014
@sanxiyn
Copy link
Member

sanxiyn commented Feb 10, 2014

Triage. Tagging RFC.

@sfackler
Copy link
Member

I think the current situation needs some work, even if it only affects rustdoc output. We have some very common traits like Writer and Iterator that have a couple of required methods and a huge number of default methods one of which should sometimes be overridden (e.g. Writer::flush and Iterator::size_hint). The fact that those methods, as opposed to any others are supposed to be overridden is exceptionally undiscoverable from looking at the rustdoc for the traits, IMO.

I think there's probably cases where it would be appropriate to override things like read_be_i32 or flat_map so I wouldn't want to forbid overriding, but some annotation that would cause rustdoc to split the definitions into Default Methods and Extension Methods (or something) would help.

@sanxiyn
Copy link
Member

sanxiyn commented Jul 29, 2014

Any update here?

@rust-highfive
Copy link
Collaborator

This issue has been moved to the RFCs repo: rust-lang/rfcs#291

flip1995 pushed a commit to flip1995/rust that referenced this issue Sep 28, 2021
Backport remerge

This is to keep the backported commit in the repository before force pushing the new beta branch.

r? `@ghost`

changelog: none
(literally none)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-attributes Area: #[attributes(..)]
Projects
None yet
Development

No branches or pull requests

5 participants