rust/src
Matthias Krüger ae71900ef6
Rollup merge of #121364 - Urgau:unary_precedence, r=compiler-errors
Implement lint against ambiguous negative literals

This PR implements a lint against ambiguous negative literals with a literal and method calls right after it.

## `ambiguous_negative_literals`

(deny-by-default)

The `ambiguous_negative_literals` lint checks for cases that are confusing between a negative literal and a negation that's not part of the literal.

### Example

```rust,compile_fail
-1i32.abs(); // equals -1, while `(-1i32).abs()` equals 1
```

### Explanation

Method calls take precedence over unary precedence. Setting the precedence explicitly makes the code clearer and avoid potential bugs.

<details>
<summary>Old proposed lint</summary>

## `ambiguous_unary_precedence`

(deny-by-default)

The `ambiguous_unary_precedence` lint checks for use the negative unary operator with a literal and method calls.

### Example

```rust
-1i32.abs(); // equals -1, while `(-1i32).abs()` equals 1
```

### Explanation

Unary operations take precedence on binary operations and method calls take precedence over unary precedence. Setting the precedence explicitly makes the code clearer and avoid potential bugs.

</details>

-----

Note: This is a strip down version of https://github.com/rust-lang/rust/pull/117161, without the binary op precedence.

Fixes https://github.com/rust-lang/rust/issues/117155
`@rustbot` labels +I-lang-nominated
cc `@scottmcm`
r? compiler
2024-07-25 16:48:17 +02:00
..
bootstrap Rollup merge of #128108 - onur-ozkan:ensure-std-for-precompiled-rustc, r=Kobzol 2024-07-24 05:05:37 +02:00
ci Bump Fuchsia 2024-07-23 20:30:24 -07:00
doc Auto merge of #127755 - no1wudi:master, r=michaelwoerister 2024-07-23 09:45:28 +00:00
etc Rewrite test-float-parse in Rust 2024-07-20 11:39:34 -05:00
librustdoc rustdoc: clean up and fix ord violations in item sorting 2024-07-24 11:08:44 -07:00
llvm-project@c54cff0e6e Update LLVM submodule 2024-07-05 22:06:57 +08:00
rustdoc-json-types Add rustdoc-json support for use<> 2024-07-12 05:24:51 -04:00
tools Rollup merge of #121364 - Urgau:unary_precedence, r=compiler-errors 2024-07-25 16:48:17 +02:00
README.md
stage0 bump stage0 compiler 2024-06-11 15:10:03 +02:00
version Bump to 1.82 2024-07-20 10:30:39 -04:00

This directory contains some source code for the Rust project, including:

  • The bootstrapping build system
  • Various submodules for tools, like cargo, tidy, etc.

For more information on how various parts of the compiler work, see the rustc dev guide.