Commit Graph

247423 Commits

Author SHA1 Message Date
Philipp Krones f99056bd87
Update Cargo.lock 2024-02-27 15:50:23 +01:00
Philipp Krones ad7513e874
Merge commit '10136170fe9ed01e46aeb4f4479175b79eb0e3c7' into clippy-subtree-update 2024-02-27 15:50:17 +01:00
bors 10136170fe Auto merge of #12363 - oli-obk:bump_ui_test, r=flip1995
lower `bstr` version requirement to `1.6.0`

test changes are due to https://github.com/oli-obk/ui_test/pull/201 (cc `@Jarcho)`

changelog: none
2024-02-27 13:46:14 +00:00
Oli Scherer 592fe89997 lower `bstr` version requirement to `1.6.0` 2024-02-27 13:34:01 +00:00
bors 1c28a2c1b0 Auto merge of #121667 - pitaj:diag_items-legacy_numeric_constants, r=Nilstrieb
syms for legacy numeric constants diag items

Missed these in #121272 and #121361, woops.

For https://github.com/rust-lang/rust-clippy/pull/12312

r? `@Nilstrieb`
2024-02-27 06:04:54 +00:00
bors e33cba523a Auto merge of #12126 - teor2345:patch-1, r=llogiq
Fix sign-handling bugs and false negatives in `cast_sign_loss`

**Note: anyone should feel free to move this PR forward, I might not see notifications from reviewers.**

changelog: [`cast_sign_loss`]: Fix sign-handling bugs and false negatives

This PR fixes some arithmetic bugs and false negatives in PR #11883 (and maybe earlier PRs).
Cc `@J-ZhengLi`

I haven't updated the tests yet. I was hoping for some initial feedback before adding tests to cover the cases listed below.

Here are the issues I've attempted to fix:

#### `abs()` can return a negative value in release builds

Example:
```rust
i32::MIN.abs()
```
https://play.rust-lang.org/?version=stable&mode=release&edition=2021&gist=022d200f9ef6ee72f629c0c9c1af11b8

Docs: https://doc.rust-lang.org/std/primitive.i32.html#method.abs

Other overflows that produce negative values could cause false negatives (and underflows could produce false positives), but they're harder to detect.

#### Values with uncertain signs can be positive or negative

Any number of values with uncertain signs cause the whole expression to have an uncertain sign, because an uncertain sign can be positive or negative.

Example (from UI tests):
```rust
fn main() {
    foo(a: i32, b: i32, c: i32) -> u32 {
        (a * b * c * c) as u32
        //~^ ERROR: casting `i32` to `u32` may lose the sign of the value
    }

    println!("{}", foo(1, -1, 1));
}
```
https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=165d2e2676ee8343b1b9fe60db32aadd

#### Handle `expect()` the same way as `unwrap()`

Since we're ignoring `unwrap()` we might as well do the same with `expect()`.

This doesn't seem to have tests but I'm happy to add some like `Some(existing_test).unwrap() as u32`.

#### A negative base to an odd exponent is guaranteed to be negative

An integer `pow()`'s sign is only uncertain when its operants are uncertain. (Ignoring overflow.)

Example:
```rust
((-2_i32).pow(3) * -2) as u32
```

This offsets some of the false positives created by one or more uncertain signs producing an uncertain sign. (Rather than just an odd number of uncertain signs.)

#### Both sides of a multiply or divide should be peeled recursively

I'm not sure why the lhs was peeled recursively, and the rhs was left intact. But the sign of any sequence of multiplies and divides is determined by the signs of its operands. (Ignoring overflow.)

I'm not sure what to use as an example here, because most expressions I want to use are const-evaluable.

But if `p()` is [a non-const function that returns a positive value](https://doc.rust-lang.org/std/primitive.i32.html#method.isqrt), and if the lint handles unary negation, these should all lint:
```rust
fn peel_all(x: i32) {
    (-p(x) * -p(x) * -p(x)) as u32;
    ((-p(x) * -p(x)) * -p(x)) as u32;
    (-p(x) * (-p(x) * -p(x))) as u32;
}
```

#### The right hand side of a Rem doesn't change the sign

Unlike Mul and Div,
> Given remainder = dividend % divisor, the remainder will have the same sign as the dividend.
https://doc.rust-lang.org/reference/expressions/operator-expr.html#arithmetic-and-logical-binary-operators

I'm not sure what to use as an example here, because most expressions I want to use are const-evaluable.

But if `p()` is [a non-const function that returns a positive value](https://doc.rust-lang.org/std/primitive.i32.html#method.isqrt), and if the lint handles unary negation, only the first six expressions should lint.

The expressions that start with a constant should lint (or not lint) regardless of whether the lint supports `p()` or unary negation, because only the dividend's sign matters.

Example:
```rust
fn rem_lhs(x: i32) {
    (-p(x) % -1) as u32;
    (-p(x) % 1) as u32;
    (-1 % -p(x)) as u32;
    (-1 % p(x)) as u32;
    (-1 % -x) as u32;
    (-1 % x) as u32;
    // These shouldn't lint:
    (p(x) % -1) as u32;
    (p(x) % 1) as u32;
    (1 % -p(x)) as u32;
    (1 % p(x)) as u32;
    (1 % -x) as u32;
    (1 % x) as u32;
}
```

#### There's no need to bail on other expressions

When peeling, any other operators or expressions can be left intact and sent to the constant evaluator.

If these expressions can be evaluated, this offsets some of the false positives created by one or more uncertain signs producing an uncertain sign. If not, they end up marked as having uncertain sign.
2024-02-27 05:38:40 +00:00
bors fb060815b3 Auto merge of #11136 - y21:enhance_read_line_without_trim, r=dswij
[`read_line_without_trim`]: detect string literal comparison and `.ends_with()` calls

This lint now also realizes that a comparison like `s == "foo"` and calls such as `s.ends_with("foo")` will fail if `s` was initialized by a call to `Stdin::read_line` (because of the trailing newline).

changelog: [`read_line_without_trim`]: detect string literal comparison and `.ends_with()` calls

r? `@giraffate` assigning you because you reviewed #10970 that added this lint, so this is kinda a followup PR ^^
2024-02-27 03:36:12 +00:00
bors 91cae1dcdc Auto merge of #121635 - 823984418:remove_archive_builder_lifetime_a, r=nnethercote
Remove useless lifetime of ArchiveBuilder

`trait ArchiveBuilder<'a>` has a seemingly useless lifetime a, so I remove it. If this is intentional, please reject this PR.

```rust
pub trait ArchiveBuilder<'a> {
    fn add_file(&mut self, path: &Path);

    fn add_archive(
        &mut self,
        archive: &Path,
        skip: Box<dyn FnMut(&str) -> bool + 'static>,
    ) -> io::Result<()>;

    fn build(self: Box<Self>, output: &Path) -> bool;
}
```
2024-02-27 03:27:48 +00:00
bors 71ffdf7ff7 Auto merge of #121655 - matthiaskrgr:rollup-qpx3kks, r=matthiaskrgr
Rollup of 4 pull requests

Successful merges:

 - #121598 (rename 'try' intrinsic to 'catch_unwind')
 - #121639 (Update books)
 - #121648 (Update Vec and String `{from,into}_raw_parts`-family docs)
 - #121651 (Properly emit `expected ;` on `#[attr] expr`)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-02-27 00:55:14 +00:00
Peter Jaszkowiak 2ea33225c2 syms for legacy numeric constants diag items 2024-02-26 17:37:12 -07:00
Matthias Krüger ec5c5b7da8
Rollup merge of #121651 - ShE3py:issue-121647, r=estebank
Properly emit `expected ;` on `#[attr] expr`

Fixes #121647

See #118182, #120586

---
r? estebank
2024-02-27 00:40:01 +01:00
Matthias Krüger 94609dbb03
Rollup merge of #121648 - jieyouxu:from-into-raw-parts-docs, r=Nilstrieb
Update Vec and String `{from,into}_raw_parts`-family docs

- Fix documentation argument order to match the code argument order for consistency.
- Add return argument description for `{Vec,String}::into_raw_parts` to match their `from*` counterparts.
2024-02-27 00:40:01 +01:00
Matthias Krüger e47d814a33
Rollup merge of #121639 - rustbot:docs-update, r=ehuss
Update books

## rust-lang/book

1 commits in 71352deb20727b4dda9ebfe8182709d5bf17dfea..19c40bfd2d57641d962f3119a1c343355f1b3c5e
2024-02-19 20:39:35 UTC to 2024-02-19 20:39:35 UTC

- Rust upgrades (rust-lang/book#3844)

## rust-lang/edition-guide

3 commits in 76bd48a273a0e0413a3bf22c699112d41497b99e..e1eead1181a691e56299294d5f1d62fe7a26d317
2024-02-24 21:15:28 UTC to 2024-02-17 21:44:36 UTC

- Rename static_mut_refs (rust-lang/edition-guide#293)
- Add 2024 prelude (rust-lang/edition-guide#292)
- Add some more initial stub docs for 2024. (rust-lang/edition-guide#291)

## rust-lang/reference

5 commits in 8227666de13f6e7bb32dea9dc42e841adb5ce4b7..3417f866932cb1c09c6be0f31d2a02ee01b4b95d
2024-02-25 19:37:14 UTC to 2024-02-15 13:28:59 UTC

- Document `target_abi` (rust-lang/reference#1446)
- Add `rust-toolchain.toml` and revise README (rust-lang/reference#1474)
- Clarify semantics of the various pointer to pointer casts (rust-lang/reference#1451)
- Update aarch64 target feature docs to match LLVM (rust-lang/reference#1470)
- Fix grammar for TypePathFn (rust-lang/reference#1281)

## rust-lang/rust-by-example

4 commits in e188d5d466f7f3ff9f1d518393235f4fe951be46..57f1e708f5d5850562bc385aaf610e6af14d6ec8
2024-02-24 18:31:19 UTC to 2024-02-14 13:06:53 UTC

- bug: fix typo (rust-lang/rust-by-example#1822)
- Fix typo in attribute.md (rust-lang/rust-by-example#1818)
- Add Japanese translation (rust-lang/rust-by-example#1794)
- Remove unused .travis.yml file (rust-lang/rust-by-example#1816)

## rust-lang/rustc-dev-guide

9 commits in 1f30cc7cca9a3433bc1872abdc98960b36c21ca0..7b0ef5b0bea5e3ce3b9764aa5754a60e2cc05c52
2024-02-22 19:15:52 UTC to 2024-02-13 12:13:06 UTC

- Update compiletest directives to be in `ui_test` style `//`@`` (rust-lang/rustc-dev-guide#1895)
- Add notes on tweak rust-analyzer.check.overrideCommand (rust-lang/rustc-dev-guide#1890)
- Fix more links (rust-lang/rustc-dev-guide#1884)
- Remove references to -Z ast-json and -Z ast-json-noexpand (rust-lang/rustc-dev-guide#1893)
- Specify ui test suite directives and add note on ignore-tidy directives (rust-lang/rustc-dev-guide#1892)
- Update docs about ui tests now using `//`@`` headers (rust-lang/rustc-dev-guide#1885)
- Make git rebase commands more bulletproof (rust-lang/rustc-dev-guide#1889)
- updating-llvm.md: command does not work (rust-lang/rustc-dev-guide#1887)
- fix update llvm build command (rust-lang/rustc-dev-guide#1886)
2024-02-27 00:40:00 +01:00
Matthias Krüger d95c321062
Rollup merge of #121598 - RalfJung:catch_unwind, r=oli-obk
rename 'try' intrinsic to 'catch_unwind'

The intrinsic has nothing to do with `try` blocks, and corresponds to the stable `catch_unwind` function, so this makes a lot more sense IMO.

Also rename Miri's special function while we are at it, to reflect the level of abstraction it works on: it's an unwinding mechanism, on which Rust implements panics.
2024-02-27 00:40:00 +01:00
bors d12b53e481 Auto merge of #12116 - J-ZhengLi:issue12101, r=Alexendoo
fix suggestion error in [`useless_vec`]

fixes: #12101

---

changelog: fix suggestion error in [`useless_vec`]

r+ `@matthiaskrgr` since they opened the issue?
2024-02-26 22:38:24 +00:00
bors 5c786a7fe3 Auto merge of #121516 - RalfJung:platform-intrinsics-begone, r=oli-obk
remove platform-intrinsics ABI; make SIMD intrinsics be regular intrinsics

`@Amanieu` `@workingjubilee` I don't think there is any reason these need to be "special"? The [original RFC](https://rust-lang.github.io/rfcs/1199-simd-infrastructure.html) indicated eventually making them stable, but I think that is no longer the plan, so seems to me like we can clean this up a bit.

Blocked on https://github.com/rust-lang/stdarch/pull/1538, https://github.com/rust-lang/rust/pull/121542.
2024-02-26 22:24:16 +00:00
teor 1e3c55eea2
Remove redundant uncertain_counts 2024-02-27 07:34:18 +10:00
Lieselotte 1658ca082a
Properly emit `expected ;` on `#[attr] expr` 2024-02-26 21:47:10 +01:00
bors fc3800f657 Auto merge of #121646 - ibraheemdev:patch-17, r=ChrisDenton
Fix race between block initialization and receiver disconnection

Port of https://github.com/crossbeam-rs/crossbeam/pull/1084. Closes https://github.com/rust-lang/rust/issues/121582.
2024-02-26 19:46:01 +00:00
许杰友 Jieyou Xu (Joe) bfeea294cc
Document args returned from `String::into_raw_parts` 2024-02-26 19:32:32 +00:00
许杰友 Jieyou Xu (Joe) dd24a462d5
Document args returned from `Vec::into_raw_parts{,_with_alloc}` 2024-02-26 19:32:32 +00:00
许杰友 Jieyou Xu (Joe) 26bdf2900a
Rearrange `String::from_raw_parts` doc argument order to match code argument order 2024-02-26 19:32:26 +00:00
许杰友 Jieyou Xu (Joe) a1b93e8fed
Rearrange `Vec::from_raw_parts{,_in}` doc argument order to match code argument order 2024-02-26 19:32:17 +00:00
y21 fd85db3636 restructure lint code, update description, more cases 2024-02-26 20:24:46 +01:00
y21 cfddd91c91 [`read_line_without_trim`]: catch string eq checks 2024-02-26 20:19:15 +01:00
Ibraheem Ahmed 580b003edd
fix race between block initialization and receiver disconnection 2024-02-26 13:53:35 -05:00
bors 1c5094878b Auto merge of #12342 - lucarlig:empty-docs, r=llogiq
Empty docs

Fixes https://github.com/rust-lang/rust-clippy/issues/9931

changelog: [`empty_doc`]: Detects documentation that is empty.
changelog: Doc comment lints now trigger for struct field and enum variant documentation
2024-02-26 18:03:13 +00:00
bors d71899573a Auto merge of #12355 - Ethiraric:fix-11927, r=Alexendoo
[`box_default`]: Preserve required path segments

When encountering code such as:
```rs
Box::new(outer::Inner::default())
```
clippy would suggest replacing with `Box::<Inner>::default()`, dropping the `outer::` segment. This behavior is incorrect and that commit fixes it.

What it does is it checks the contents of the `Box::new` and, if it is of the form `A::B::default`, does a text replacement, inserting `A::B` in the `Box`'s quickfix generic list.
If the source does not match that pattern (including `Vec::from(..)` or other `T::new()` calls), we then fallback to the original code.

Fixes #11927

*Please write a short comment explaining your change (or "none" for internal only changes)*

changelog: [`box_default`]: Preserve required path segments
2024-02-26 17:25:43 +00:00
bors 829308e9af Auto merge of #121636 - matthiaskrgr:rollup-1tt2o5n, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #121389 (llvm-wrapper: fix few warnings)
 - #121493 (By changing some attributes to only_local, reducing encoding attributes in the crate metadate.)
 - #121615 (Move `emit_stashed_diagnostic` call in rustfmt.)
 - #121617 (Actually use the right closure kind when checking async Fn goals)
 - #121628 (Do not const prop unions)
 - #121629 (fix some references to no-longer-existing ReprOptions.layout_seed)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-02-26 17:14:13 +00:00
rustbot 67bd410cac Update books 2024-02-26 12:00:42 -05:00
Ethiraric 97dc4b22c6 [`box_default`]: Preserve required path segments
When encountering code such as:
```
Box::new(outer::Inner::default())
```
clippy would suggest replacing with `Box::<Inner>::default()`, dropping
the `outer::` segment. This behavior is incorrect and that commit fixes
it.

What it does is it checks the contents of the `Box::new` and, if it is
of the form `A::B::default`, does a text replacement, inserting `A::B`
in the `Box`'s quickfix generic list.
If the source does not match that pattern (including `Vec::from(..)`
or other `T::new()` calls), we then fallback to the original code.

Fixes #11927
2024-02-26 17:39:00 +01:00
bors a11875bd22 Auto merge of #12353 - lucarlig:book, r=flip1995
add cargo.toml lint section way of adding lints in the book

changelog: add cargo.toml lint section way of adding lints in the book

as from [discussion on zulip](https://rust-lang.zulipchat.com/#narrow/stream/257328-clippy/topic/.E2.9C.94.20clippy.20config)
2024-02-26 15:53:46 +00:00
Philipp Krones 6d0b70e08f
Clean up Allowing/Denying Lints section 2024-02-26 16:43:05 +01:00
lucarlig fca77c0976 docs and imports 2024-02-26 19:15:44 +04:00
Matthias Krüger 81eddb3dac
Rollup merge of #121629 - RalfJung:field-shuffle-seed, r=oli-obk
fix some references to no-longer-existing ReprOptions.layout_seed

Seems like the field got renamed but some comments not updated.
2024-02-26 16:06:05 +01:00
Matthias Krüger 218be2771d
Rollup merge of #121628 - gurry:121534-ice-asymm-binop, r=oli-obk
Do not const prop unions

Unions can produce values whose types don't match their underlying layout types which can lead to ICEs on eval.

Fixes #121534
2024-02-26 16:06:04 +01:00
Matthias Krüger 4f167b4baf
Rollup merge of #121617 - compiler-errors:async-closure-kind-check, r=oli-obk
Actually use the right closure kind when checking async Fn goals

Dumb copy-paste mistake on my part from #120712. Sorry!

r? oli-obk

Fixes #121599
2024-02-26 16:06:04 +01:00
Matthias Krüger 9d5ab73523
Rollup merge of #121615 - nnethercote:fix-121517, r=oli-obk
Move `emit_stashed_diagnostic` call in rustfmt.

This call was added to `parse_crate_mod` in #121487, to fix a case where a stashed diagnostic wasn't emitted. But there is another path where a stashed diagnostic might fail to be emitted if there's a parse error, if the `build` call in `parse_crate_inner` fails before `parse_crate_mod` is reached.

So this commit moves the `emit_stashed_diagnostic` call outwards, from `parse_crate_mod` to `format_project`, just after the `Parser::parse_crate` call. This should be far out enough to catch any parsing errors.

Fixes #121517.

r? `@oli-obk`
cc `@ytmimi`
2024-02-26 16:06:03 +01:00
Matthias Krüger 6e3ece3aac
Rollup merge of #121493 - surechen:edit_attribute_only_local, r=lcnr
By changing some attributes to only_local, reducing encoding attributes in the crate metadate.

Thank you.
This is part of changing attributes to only_local. I hope get your opinion  whether I should split into multiple PRs, or submit in one.

According to [try to not rely on attributes from extern crates](https://github.com/rust-lang/compiler-team/issues/505) and lcnr's guidance.
2024-02-26 16:06:03 +01:00
Matthias Krüger 6700714394
Rollup merge of #121389 - klensy:llvm-warn-fix, r=nikic
llvm-wrapper: fix few warnings

Two fixes: first one is simple unsigned -> uint64_t, but how second one is more subtile, see commit description.
2024-02-26 16:06:02 +01:00
lucarlig 80bafa5d45 add cargo.toml lint section way of adding lints 2024-02-26 18:59:05 +04:00
bors b79db437dc Auto merge of #120586 - ShE3py:exprkind-err, r=fmease
Add `ErrorGuaranteed` to `ast::ExprKind::Err`

See #119967 for context
```
      \
       \
          _~^~^~_
      \) /  o o  \ (/
        '_   -   _'
        / '-----' \
```

r? fmease
2024-02-26 14:43:15 +00:00
823984418 0c082b7fa9 remove useless lifetime of ArchiveBuilder 2024-02-26 22:37:04 +08:00
bors b8de591b65 Auto merge of #119106 - lcnr:decrement-universes, r=BoxyUwU
avoid generalization inside of aliases

The basic idea of this PR is that we don't generalize aliases when the instantiation could fail later on, either due to the *occurs check* or because of a universe error. We instead replace the whole alias with an inference variable and emit a nested `AliasRelate` goal. This `AliasRelate` then fully normalizes the alias before equating it with the inference variable, at which point the alias can be treated like any other rigid type.

We now treat aliases differently depending on whether they are *rigid* or not. To detect whether an alias is rigid we check whether `NormalizesTo` fails. While we already do so inside of `AliasRelate` anyways, also doing so when instantiating a query response would be both ugly/difficult and likely inefficient. To avoid that I change `instantiate_and_apply_query_response` to relate types completely structurally. This change generally removes a lot of annoying complexity, which is nice. It's implemented by adding a flag to `Equate` to change it to structurally handle aliases.

We currently always apply constraints from canonical queries right away. By providing all the necessary information to the canonical query, we can guarantee that instantiating the query response never fails, which further simplifies the implementation. This does add the invariant that *any information which could cause instantiating type variables to fail must also be available inside of the query*.

While it's acceptable for canonicalization to result in more ambiguity, we must not cause the solver to incompletely structurally relate aliases by erasing information. This means we have to be careful when merging universes during canonicalization. As we only generalize for type and const variables we have to make sure that anything nameable by such a type or const variable inside of the canonical query is also nameable outside of it. Because of this we both stop merging universes of existential variables when canonicalizing inputs, we put all uniquified regions into a higher universe which is not nameable by any type or const variable.

I will look into always replacing aliases with inference variables when generalizing in a later PR unless the alias references bound variables. This should both pretty much fix https://github.com/rust-lang/trait-system-refactor-initiative/issues/4. This may allow us to merge the universes of existential variables again by changing generalize to not consider their universe when deciding whether to generalize aliases. This requires some additional non-trivial changes to alias-relate, so I am leaving that as future work.

Fixes https://github.com/rust-lang/trait-system-refactor-initiative/issues/79. While it would be nice to decrement universe indices when existing a `forall`, that was surprisingly difficult and not necessary to fix this issue. I am really happy with the approach in this PR think it is the correct way forward to also fix the remaining cases of https://github.com/rust-lang/trait-system-refactor-initiative/issues/8.
2024-02-26 12:11:58 +00:00
lcnr 3b3514acec consider placeholders in `fn term_is_fully_unconstrained` 2024-02-26 11:51:01 +01:00
Ralf Jung a3c0f3af9c miri: rename miri_start_panic → miri_start_unwind 2024-02-26 11:10:18 +01:00
Ralf Jung b4ca582b89 rename 'try' intrinsic to 'catch_unwind' 2024-02-26 11:10:18 +01:00
lcnr 1c264ca9ca add regression tests 2024-02-26 11:01:31 +01:00
lcnr 2c7ede8f52 update tests 2024-02-26 10:57:46 +01:00
lcnr a788be0aae use fulfillment in `Coerce::unify'
only checking whether nested goals hold means that we don't consider
their inference constraints. Given that we now emit `AliasRelate` when relating
aliases and infer vars, this previously resulted in an "unconstrained" inference var
in `coerce_unsized`.
2024-02-26 10:57:38 +01:00