Empowering everyone to build reliable and efficient software.
Go to file
León Orell Valerian Liehr 35ea48d588
Rollup merge of #118833 - Urgau:lint_function_pointer_comparisons, r=cjgillot
Add lint against function pointer comparisons

This is kind of a follow-up to https://github.com/rust-lang/rust/pull/117758 where we added a lint against wide pointer comparisons for being ambiguous and unreliable; well function pointer comparisons are also unreliable. We should IMO follow a similar logic and warn people about it.

-----

## `unpredictable_function_pointer_comparisons`

*warn-by-default*

The `unpredictable_function_pointer_comparisons` lint checks comparison of function pointer as the operands.

### Example

```rust
fn foo() {}
let a = foo as fn();

let _ = a == foo;
```

### Explanation

Function pointers comparisons do not produce meaningful result since they are never guaranteed to be unique and could vary between different code generation units. Furthermore different function could have the same address after being merged together.

----

This PR also uplift the very similar `clippy::fn_address_comparisons` lint, which only linted on if one of the operand was an `ty::FnDef` while this PR lints proposes to lint on all `ty::FnPtr` and `ty::FnDef`.

```@rustbot``` labels +I-lang-nominated

~~Edit: Blocked on https://github.com/rust-lang/libs-team/issues/323 being accepted and it's follow-up pr~~
2024-12-05 07:29:53 +01:00
.github
compiler Rollup merge of #118833 - Urgau:lint_function_pointer_comparisons, r=cjgillot 2024-12-05 07:29:53 +01:00
library Rollup merge of #118833 - Urgau:lint_function_pointer_comparisons, r=cjgillot 2024-12-05 07:29:53 +01:00
LICENSES
src Rollup merge of #118833 - Urgau:lint_function_pointer_comparisons, r=cjgillot 2024-12-05 07:29:53 +01:00
tests Rollup merge of #118833 - Urgau:lint_function_pointer_comparisons, r=cjgillot 2024-12-05 07:29:53 +01:00
.clang-format
.editorconfig
.git-blame-ignore-revs
.gitattributes Stop git from merging generated files 2024-12-04 11:06:37 +00:00
.gitignore
.gitmodules Update LLVM to 19.1.5 2024-12-03 21:12:47 +08:00
.ignore
.mailmap
Cargo.lock Update wasm-component-ld to 0.5.11 2024-12-03 10:22:08 -08:00
Cargo.toml
CODE_OF_CONDUCT.md
config.example.toml
configure
CONTRIBUTING.md
COPYRIGHT
INSTALL.md
LICENSE-APACHE
license-metadata.json
LICENSE-MIT
README.md
RELEASES.md
REUSE.toml
rust-bors.toml
rustfmt.toml
triagebot.toml
x
x.ps1
x.py

This is the main source code repository for Rust. It contains the compiler, standard library, and documentation.

Why Rust?

  • Performance: Fast and memory-efficient, suitable for critical services, embedded devices, and easily integrate with other languages.

  • Reliability: Our rich type system and ownership model ensure memory and thread safety, reducing bugs at compile-time.

  • Productivity: Comprehensive documentation, a compiler committed to providing great diagnostics, and advanced tooling including package manager and build tool (Cargo), auto-formatter (rustfmt), linter (Clippy) and editor support (rust-analyzer).

Quick Start

Read "Installation" from The Book.

Installing from Source

If you really want to install from source (though this is not recommended), see INSTALL.md.

Getting Help

See https://www.rust-lang.org/community for a list of chat platforms and forums.

Contributing

See CONTRIBUTING.md.

License

Rust is primarily distributed under the terms of both the MIT license and the Apache License (Version 2.0), with portions covered by various BSD-like licenses.

See LICENSE-APACHE, LICENSE-MIT, and COPYRIGHT for details.

Trademark

The Rust Foundation owns and protects the Rust and Cargo trademarks and logos (the "Rust Trademarks").

If you want to use these names or brands, please read the media guide.

Third-party logos may be subject to third-party copyrights and trademarks. See Licenses for details.