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

[RFC] Disabling warnings #12166

Closed
beta-ziliani opened this issue Jun 28, 2022 · 2 comments
Closed

[RFC] Disabling warnings #12166

beta-ziliani opened this issue Jun 28, 2022 · 2 comments

Comments

@beta-ziliani
Copy link
Member

Feature Request

Warnings are nice, but sometimes it's useful to disable them. Either because a new warning is issued and we prefer ignore it for the moment (e.g., false positives: #12150), or because we now the invariants of our program render the warning useless, or we prefer to tackle deprecations when they really become a problem...

However, currently we only have two choices: let warnings pollute the output of our build process, or let them fail, having to fix the program even when there's no need for a fix. What I propose is to add an annotation to eliminate such warnings.

In OCaml, for instance, you can suppress warnings using an attribute (akin to an annotation) (ref):

let [@warning "-8"] foo = function
  Some x -> Printf.printf "I know there's something here"

If I remove [@warning "-8"], the compiler will warn me that the case None isn't handled.

Additionally, they can be removed for an entire build with a given flag in the compiler.

Proposal

In my proposal, I would associate a name for each warning (instead of a number):

@[IgnoreWarnings("deprecated")]
def i_know_its_been_deprecated(errno) =
  SystemError.from_errno errno

It could take several warnings @[IgnoreWarnings("a", "b").

Implementation

Luckily, most of the ingredients are already there. For local-only warnings (like in the example above), we need to extend the definition of warnings_exclude to include the block of code and which warnings to suppress. For global ones, we need to replace warnings with a Set(String) instead of an enum.

@HertzDevil
Copy link
Contributor

Duplicate of #11044?

@beta-ziliani
Copy link
Member Author

@HertzDevil yup, I couldn't find it because it was framed differently. Thanks! (BTW 🙏 👁️ 📨)

@beta-ziliani beta-ziliani closed this as not planned Won't fix, can't repro, duplicate, stale Jun 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants