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

Forbid pineapple on pizza #70645

Closed

Conversation

pietroalbini
Copy link
Member

This PR adds a new forbid-by-default lint to the Rust compiler, preventing users from writing wildly untasteful types such as Pizza<Pineapple>.

error

r? @estebank
cc @steveklabnik, what do you think is the best way to document this feature?

This was inspired by @sgrif's awesome RustConf 2017 talk. Check it out!

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 1, 2020
@killercup
Copy link
Member

I work with a lot of international people and even some linguists so our code bases are always fully translated. For increased coverage, can you maybe also disallow "ananas"?

@dns2utf8
Copy link
Contributor

dns2utf8 commented Apr 1, 2020

I love Ananas on Pizza, can I invert the lint too?

#[allow(pinapple_on_pizza)]  // for liberals
#[enforce(pinapple_on_pizza)] // for me ;)

| |
| this is the pizza you ruined
|
= note: `#[forbid(pineapple_on_pizza)]` on by default
Copy link
Contributor

Choose a reason for hiding this comment

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

Given the atrocious crime against taste that has been committed here, I wonder if we should delete the file from the user's hard-drive. Although, I'm not sure how to test that... 🤔

Copy link
Member

@phansch phansch Apr 1, 2020

Choose a reason for hiding this comment

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

We could get close by obtaining the whole span of the file and adding a removal suggestion to remove the complete span. Since we have rustfix tests this should be easily testable 🤔

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah that's clever! @pietroalbini Can you adjust the PR to do that?

Copy link
Contributor

@jcdyer jcdyer Apr 2, 2020

Choose a reason for hiding this comment

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

Can you get the span of the whole crate?

Sigourney Weaver in Aliens saying, "It's the only way to be sure."

@jamesmunns
Copy link
Member

I think it is irresponsible to land these kinds of changes without an associated RFC. I, for one, find pineapple based toppings wonderful. For example, this would disrupt my workflow around creating my favorite pizza:

#[allow(pineapple_on_pizza)] // UNACCEPTABLE!
let _: Pizza<(Pepperoni, Pineapple, Jalapeno)>;

If I was forced to allow this lint every time I instantiate my favorite pizza, I think this would be a total blocker for my use of Rust.

@Dexterp37
Copy link

Please, let's merge this ASAP. I would make my life so much easier if this would become a de-facto standard.

@kornelski
Copy link
Contributor

kornelski commented Apr 1, 2020

I think this feature is overly specific. For example, I'd also like to have warnings about Anchovies.

And it doesn't work for Marmite/Vegemite types.

@Dylan-DPC-zz
Copy link

We need an fcp for this.

@bjorn3
Copy link
Member

bjorn3 commented Apr 1, 2020

Does this need a fcp with all teams? This concerns preventing a crime against the taste of everybody.


declare_lint! {
pub PINEAPPLE_ON_PIZZA,
Forbid,
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 think this needs its own lint group. It should go with other similar lints, like allow(bad_style).

Copy link
Member

Choose a reason for hiding this comment

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

Not allow(bad_style), but allow(bad_taste).

Copy link

@EvanCarroll EvanCarroll Apr 1, 2020

Choose a reason for hiding this comment

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

I don't think we should allow pineapple pizza to be instantiated regardless of the pragma or directive. We shouldn't permit terrorism.

@Ixrec
Copy link
Contributor

Ixrec commented Apr 1, 2020

Unfortunately toppings are generally chosen at runtime, by the user, so a compile-time lint would catch almost nothing in practice.

Clearly, the only proper solution here is a full-blown effect system with dependent typing (and probably generic modules just to be sure), so we can statically verify that e.g. calling .sort() on a VecWithPineappleAtTheEnd turns into a VecWithPineappleWherever. That will definitely require an RFC. Or fifty.

@Dylan-DPC-zz
Copy link

I work with a lot of international people and even some linguists so our code bases are always fully translated. For increased coverage, can you maybe also disallow "ananas"?

You need to contact the localisation team for that. I've added it to their non-existent agenda.

@cuviper cuviper added the D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. label Apr 1, 2020
struct Pineapple;

fn main() {
let _: Pizza<Pineapple>; //~ERROR pineapple doesn't go on pizza
Copy link
Member

Choose a reason for hiding this comment

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

A test is necessary to ensure that this lint fires regardless of the order in which – or count of – ingredients are applied to the base.

@Centril Centril added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Apr 1, 2020
@amanjeev
Copy link
Member

amanjeev commented Apr 1, 2020

Removing Pineapple will reduce the cost of pizza as well. Isn't something zero cost something a thing here?

@bjorn3
Copy link
Member

bjorn3 commented Apr 1, 2020

I don't believe we allow negative cost abstractions.

@Centril
Copy link
Contributor

Centril commented Apr 1, 2020

We should have accepted @Gankra's RFC (rust-lang/rfcs#1963) which enabled NCAs!

@jebrosen
Copy link
Contributor

jebrosen commented Apr 1, 2020

Does this (and should this) PR see through type aliases? It would be good to document whether type Mushroom = Pineapple; is a suitable workaround for this lint.

@cuviper
Copy link
Member

cuviper commented Apr 1, 2020

It would be good to document whether type Mushroom = Pineapple; is a suitable workaround for this lint.

Speaking as a fan of both, that alias is an abomination.

@Dowwie
Copy link

Dowwie commented Apr 1, 2020

Pizza<Pineapple>, one of the most unsound combinations, deserves its own CVE.

@Dylan-DPC-zz
Copy link

Folks, pineapple is UB

Copy link

@kush-patel-hs kush-patel-hs left a comment

Choose a reason for hiding this comment

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

LGTM

continue;
}
for arg in args.args {
if let hir::GenericArg::Type(hir::Ty {
Copy link
Member

Choose a reason for hiding this comment

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

This should be extended to support const generics:

Pizza<pineapple()>

should not be allowed, since there is no value to having pineapple on pizza.

@estebank
Copy link
Contributor

estebank commented Apr 1, 2020

I am uncomfortable with adding this to rustc, this clearly belongs in clippy for many reasons, not the least of which that I like pineapple in pizza.

{
for pineapple_segment in path.segments {
if pineapple_segment.ident.name.as_str().to_lowercase()
== "pineapple"
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't correctly interact with non_ascii_idents, it should also account for 🍍 and 🍕. For future compatibility it should probably also support 🍕ZWJ🍍.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also account for people try to sneak things into the codebase with 🌲ZWJ🍎.

@timClicks
Copy link
Contributor

This needs to be more general to justify inclusion imo. Perhaps it be possible to include the Linnaean taxonomy into the Rust type system somehow? That would allow taxa to specified unambiguously and could scale to include whole branches. Implementation is left as an exercise for the reader.

@amanjeev
Copy link
Member

amanjeev commented Apr 1, 2020

@estebank fork your own please

@octavonce
Copy link

Not even a month in quarantine and I see this...

When do we merge? 😄

@jdonszelmann
Copy link
Contributor

I think that it would be way easier to whitelist only certain pizza ingredients and combinations, instead of blacklisting pineapples. That way we could remove a lot of corner cases like the kiwi.

@hollmmax
Copy link

hollmmax commented Apr 1, 2020

What happens if you transmute Pineapple to any other topping?

fn main() {
    unsafe {
        let topping = std::mem::transmute::<Pineapple, Topping>(Pineapple);
    }
    let pizza = Pizza(Topping);
}

One solution would be to forbid all instances of Pineapple. But I think the fruit market won't be happy with that decision

This would be undefined behavior, since Pineapple is not a Topping.

Pineapple is a valid Topping, just not for any food implementing the Salty trait.
Instead the problem is in the unsafe wrapping, he's just putting pineapples into tortillas, and pretending that's fine. Highly unsafe.

@hollmmax
Copy link

hollmmax commented Apr 1, 2020

I think that it would be way easier to whitelist only certain pizza ingredients and combinations, instead of blacklisting pineapples. That way we could remove a lot of corner cases like the kiwi.

unacceptable, this would remove local ingredient, such as traditional cheese and salami, which did not gain international notoriety. Instead, we could disallow all ingredients implementing the Sweet trait, which would also prevent other abominations such as chocolate pizza.

@randysecrist
Copy link

I would like this feature in 30 minutes or less or I want my money back.

@AZon8
Copy link

AZon8 commented Apr 1, 2020

Unfortunately toppings are generally chosen at runtime, by the user, so a compile-time lint would catch almost nothing in practice.

Clearly, the only proper solution here is a full-blown effect system with dependent typing (and probably generic modules just to be sure), so we can statically verify that e.g. calling .sort() on a VecWithPineappleAtTheEnd turns into a VecWithPineappleWherever. That will definitely require an RFC. Or fifty.

I agree. Trying to prevent the user from constructing a logical error through identifying common patterns is a waste of time. Any solution should at least be able to solve the halting problem before we get half baked solutions like this.

My approach to this problem is set up as follows:

I'm exposing a Seed struct implementing a future that resolves to a Fruit enum.
A user can await it for multiple years. However, i plan to build my API such that when the plant is pending , i.e. planding, the API prevents the construction of a Pizza struct as this would allow the user to get a mutilated reference by unpinning the basis of a civilized world.

@thefallentree
Copy link

:triggered:

@jvantuyl
Copy link

jvantuyl commented Apr 2, 2020

Please add this! It’s the last thing stopping me from moving entirely to Rust from PHP! (We all know it really means Pizza Hates Pineapple, right?)
🚫 🍕 🍍

@mark-i-m
Copy link
Member

mark-i-m commented Apr 2, 2020

I actually originally came to this thread expecting it to be about a parser change or something. I'm pretty sure the A-pizza label should be added.

@ccfb3ee765a58cae
Copy link

If we're going to have an option to #[allow(pinapple_on_pizza)], can we at least have pineapple_on_pizza.await!() syntax?

@Havvy
Copy link
Contributor

Havvy commented Apr 2, 2020

This would break code showcased in Rustconf 2017: https://www.youtube.com/watch?v=wxPehGkoNOw&list=PL85XCvVPmGQhUSX_QBkxb4g1-o56cCqI9&index=7&t=527s

@DutchGhost
Copy link
Contributor

what about people who write Pizza<Banana> ? Banana doesn't belong on Pizza either!

@trondhe
Copy link

trondhe commented Apr 2, 2020

Clearly unsound behaviour.

@Daksh14
Copy link

Daksh14 commented Apr 2, 2020

We should be writing lints for various illegal toppings, them being on pizza should be UB

  1. Pineapples
  2. Bananas
  3. Strawberries
  4. Kiwis

ASAP.

@nagisa
Copy link
Member

nagisa commented Apr 2, 2020

Now that entirety of the planet managed to survive April the 1st, closing.

@nagisa nagisa closed this Apr 2, 2020
@pietroalbini pietroalbini deleted the nonstandard-taste branch April 2, 2020 13:18
@Mark-Simulacrum Mark-Simulacrum removed A-slice-patterns Area: Slice patterns, https://github.com/rust-lang/rust/issues/23121 C-enhancement Category: An issue proposing an enhancement or a PR with one. D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. I-needs-decision Issue: In need of a decision. I-unsound Issue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness S-waiting-on-bikeshed Status: Awaiting a decision on trivial things. labels Apr 2, 2020
@joshtriplett joshtriplett added the april-1st Started on the 1st of April label Apr 2, 2020
@JimLynchCodes
Copy link

I agree with OP, but come on @Daksh14- kiwi pizza isn't that bad... in fact, I would propose kiwi pizza to be America's new pastime (since organized sports are a thing if the past now)!

@mauro-balades
Copy link

Dear Pineapple Prohibition Committee,

Thank you for your meticulous review and subsequent rejection of the PR proposing a pineapple-free pizza policy in our source code. It seems our attempt to banish the tropical intruder has met with a resistance fiercer than a chef guarding his secret marinara recipe.

While our intentions were noble, aiming to protect the sanctity of traditional pizza toppings, we recognize that our efforts have been in vain. We accept that pineapple on pizza is a matter of personal taste, much like coding styles or preferred text editors.

We propose a truce. Let's embrace the diversity of pizza toppings as we do our coding languages. Whether you're a pineapple enthusiast or a purist, there's room for everyone at the pizza table. After all, it's the melting pot of flavors (and opinions) that makes our community so deliciously unique.

May our code remain as versatile as our pizza choices. 🍕🍍

Sincerely,
The Anti-Pineapple Pizza Task Force (Retired)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
april-1st Started on the 1st of April
Projects
None yet
Development

Successfully merging this pull request may close these issues.