Commit Graph

246900 Commits

Author SHA1 Message Date
Matthias Krüger
86a7fc840f compiler: clippy::complexity fixes 2024-02-23 19:56:35 +01:00
bors
b6a23b8537 Auto merge of #121454 - reitermarkus:generic-nonzero-library, r=dtolnay
Use generic `NonZero` everywhere in `library`.

Tracking issue: https://github.com/rust-lang/rust/issues/120257

Use generic `NonZero` everywhere (except stable examples).

r? `@dtolnay`
2024-02-23 14:27:33 +00:00
bors
52cea084bd Auto merge of #121491 - matthiaskrgr:rollup-wkzqawy, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #121434 (Fix #121208 fallout)
 - #121471 (When encountering `<&T as Clone>::clone(x)` because `T: Clone`, suggest `#[derive(Clone)]`)
 - #121476 (remove `llvm.assertions=true` in compiler profile)
 - #121479 (fix generalizer unsoundness)
 - #121480 (Fix more #121208 fallout)
 - #121482 (Allow for a missing `adt_def` in `NamePrivacyVisitor`.)
 - #121484 (coverage: Use variable name `this` in `CoverageGraph::from_mir`)
 - #121487 (Explicitly call `emit_stashed_diagnostics`.)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-02-23 12:12:49 +00:00
bors
ea2cc4368e Auto merge of #121442 - lcnr:region-var-universe-uwu, r=compiler-errors
region unification: update universe of region vars

necessary for #119106. see inline comment for why this is necessary

r? `@compiler-errors` `@BoxyUwU`
2024-02-23 10:13:35 +00:00
Matthias Krüger
6ee43bc7de
Rollup merge of #121487 - nnethercote:fix-121450, r=oli-obk
Explicitly call `emit_stashed_diagnostics`.

Commit 72b172b in #121206 changed things so that
`emit_stashed_diagnostics` is only called from `run_compiler`. But rustfmt doesn't use `run_compiler`, so it needs to call `emit_stashed_diagnostics` itself to avoid an abort in `DiagCtxtInner::drop` when stashed diagnostics occur.

Fixes #121450.

r? `@oli-obk`
2024-02-23 09:42:14 +01:00
Matthias Krüger
3f693a1320
Rollup merge of #121484 - Zalathar:this, r=oli-obk
coverage: Use variable name `this` in `CoverageGraph::from_mir`

A tiny little improvement, extracted from #120013.

This makes it easier to see that we're manipulating the instance that is being constructed, and is a lot less verbose than `basic_coverage_blocks`.
2024-02-23 09:42:13 +01:00
Matthias Krüger
52805b0cb4
Rollup merge of #121482 - nnethercote:fix-121455, r=oli-obk
Allow for a missing `adt_def` in `NamePrivacyVisitor`.

This was caused by 72b172bdf6 in #121206. That commit removed an early return from `analysis` when there are stashed errors. As a result, it's possible to reach privacy analysis when there are stashed errors, which means more code paths can be reached. One such code path was handled in that commit, where a `span_bug` was changed to a `span_delayed_bug`.

This commit handles another such code path uncovered by fuzzing, in much the same way.

Fixes #121455.

r? `@oli-obk`
2024-02-23 09:42:13 +01:00
Matthias Krüger
5de3a4ce0e
Rollup merge of #121480 - nnethercote:fix-more-121208-fallout, r=lcnr
Fix more #121208 fallout

#121208 converted lots of delayed bugs to bugs. Unsurprisingly, there were a few invalid conversion found via fuzzing.

r? `@lcnr`
2024-02-23 09:42:12 +01:00
Matthias Krüger
7ae95b266e
Rollup merge of #121479 - lcnr:fix-generalize, r=compiler-errors
fix generalizer unsoundness

I ended up getting confused while trying to flip the variances when flipping the order. Should be all right now.

This is only exploitable when generalizing if the `ambient_variance` of the relation is `Contravariant`. This can currently only be the case in the NLL generalizer which only rarely generalizes, causing us to miss this regression. Very much an issue with #121462 however.
2024-02-23 09:42:12 +01:00
Matthias Krüger
977bbb4d50
Rollup merge of #121476 - onur-ozkan:update-compiler-profile, r=compiler-errors
remove `llvm.assertions=true` in compiler profile

Having this set to true disrupts compiler development workflows for people who use `llvm.download-ci-llvm = true` because we don't provide ci-llvm on the `rustc-alt-builds` server. Therefore, it is kept off by default.

cc `@Nilstrieb` `@compiler-errors`

For more context, see https://rust-lang.zulipchat.com/#narrow/stream/242791-t-infra/topic/CI.20LLVM.20for.20aarch64
2024-02-23 09:42:11 +01:00
Matthias Krüger
86727df4ed
Rollup merge of #121471 - estebank:lint-clone, r=TaKO8Ki
When encountering `<&T as Clone>::clone(x)` because `T: Clone`, suggest `#[derive(Clone)]`

CC #40699.

```
warning: call to `.clone()` on a reference in this situation does nothing
  --> $DIR/noop-method-call.rs:23:71
   |
LL |     let non_clone_type_ref_clone: &PlainType<u32> = non_clone_type_ref.clone();
   |                                                                       ^^^^^^^^
   |
   = note: the type `PlainType<u32>` does not implement `Clone`, so calling `clone` on `&PlainType<u32>` copies the reference, which does not do anything and can be removed
help: remove this redundant call
   |
LL -     let non_clone_type_ref_clone: &PlainType<u32> = non_clone_type_ref.clone();
LL +     let non_clone_type_ref_clone: &PlainType<u32> = non_clone_type_ref;
   |
help: if you meant to clone `PlainType<u32>`, implement `Clone` for it
   |
LL + #[derive(Clone)]
LL | struct PlainType<T>(T);
   |
```
2024-02-23 09:42:11 +01:00
Matthias Krüger
6e00f0d189
Rollup merge of #121434 - nnethercote:fix-121208-fallout, r=lcnr
Fix #121208 fallout

#121208 converted lots of delayed bugs to bugs. Unsurprisingly, there were a few invalid conversion found via fuzzing.

r? `@lcnr`
2024-02-23 09:42:10 +01:00
bors
6dadb6eb23 Auto merge of #121448 - klensy:bump-22-02-24, r=clubby789
bump few deps

Bumps `sysinfo`, `tabled`; dedupes `env_logger`; drops `is-terminal`
https://github.com/zhiburt/tabled/blob/v0.15.1/CHANGELOG.md
https://github.com/GuillaumeGomez/sysinfo/blob/v0.30.5/CHANGELOG.md
2024-02-23 07:42:50 +00:00
bors
dda102c190 Auto merge of #121432 - mj10021:issue-119851-fix, r=nnethercote
Move as many tests from tests/ui/numbers-arithmetic to tests/ui/lint as possible

Fixes #119851 , and also consolidates as many individual tests as possible from numbers-arithmetic.  I might have moved the tests in too aggressively, so let me know
2024-02-23 05:42:20 +00:00
Nicholas Nethercote
41da3d6f2f Explicitly call emit_stashed_diagnostics.
Commit 72b172b in #121206 changed things so that
`emit_stashed_diagnostics` is only called from `run_compiler`. But
rustfmt doesn't use `run_compiler`, so it needs to call
`emit_stashed_diagnostics` itself to avoid an abort in
`DiagCtxtInner::drop` when stashed diagnostics occur.

Fixes #121450.
2024-02-23 16:09:51 +11:00
bors
71ff1c6246 Auto merge of #121341 - GrigorenkoPV:bootstrap-rustup-cargo, r=onur-ozkan
bootstrap: don't resolve symlinks for initial_cargo

I have put the following in my `config.toml`:

```toml
# Includes one of the default files in src/bootstrap/defaults
profile = "compiler"
change-id = 121203

[build]
cargo = "/usr/bin/cargo"
rustc = "/usr/bin/rustc"
rustfmt = "/usr/bin/rustfmt"
```

I have rustup installed from Arch's repos, which has all of the above paths be symlinks to `/usr/bin/rustup`. This works just fine with the `argv[0]` trick that rustup uses.

However, `bootstrap` resolves symlinks to check whether `cargo` exists and then uses the resolved path, so it ends up calling `rustup` directly expecting it to behave like `cargo`. Which it doesn't.

This PR removes the canonicalization step, in turn fixing the issue, but sacrificing a pretty error message. However, this exact thing is checked by `x.py` in advance, so I hope it is not a big deal?
2024-02-23 03:44:47 +00:00
bors
a28d221a4b Auto merge of #120730 - estebank:confusable-api, r=oli-obk
Provide suggestions through `rustc_confusables` annotations

Help with common API confusion, like asking for `push` when the data structure really has `append`.

```
error[E0599]: no method named `size` found for struct `Vec<{integer}>` in the current scope
  --> $DIR/rustc_confusables_std_cases.rs:17:7
   |
LL |     x.size();
   |       ^^^^
   |
help: you might have meant to use `len`
   |
LL |     x.len();
   |       ~~~
help: there is a method with a similar name
   |
LL |     x.resize();
   |       ~~~~~~
```

Fix #59450 (we can open subsequent tickets for specific cases).

Fix #108437:

```
error[E0599]: `Option<{integer}>` is not an iterator
   --> f101.rs:3:9
    |
3   |     opt.flat_map(|val| Some(val));
    |         ^^^^^^^^ `Option<{integer}>` is not an iterator
    |
   ::: /home/gh-estebank/rust/library/core/src/option.rs:571:1
    |
571 | pub enum Option<T> {
    | ------------------ doesn't satisfy `Option<{integer}>: Iterator`
    |
    = note: the following trait bounds were not satisfied:
            `Option<{integer}>: Iterator`
            which is required by `&mut Option<{integer}>: Iterator`
help: you might have meant to use `and_then`
    |
3   |     opt.and_then(|val| Some(val));
    |         ~~~~~~~~
```

On type error of method call arguments, look at confusables for suggestion. Fix #87212:

```
error[E0308]: mismatched types
    --> f101.rs:8:18
     |
8    |     stuff.append(Thing);
     |           ------ ^^^^^ expected `&mut Vec<Thing>`, found `Thing`
     |           |
     |           arguments to this method are incorrect
     |
     = note: expected mutable reference `&mut Vec<Thing>`
                           found struct `Thing`
note: method defined here
    --> /home/gh-estebank/rust/library/alloc/src/vec/mod.rs:2025:12
     |
2025 |     pub fn append(&mut self, other: &mut Self) {
     |            ^^^^^^
help: you might have meant to use `push`
     |
8    |     stuff.push(Thing);
     |           ~~~~
```
2024-02-23 00:42:56 +00:00
Zalathar
9137c1e01e coverage: Use variable name this in CoverageGraph::from_mir
This makes it easier to see that we're manipulating the instance that is being
constructed, and is a lot less verbose than `basic_coverage_blocks`.
2024-02-23 11:42:28 +11:00
Nicholas Nethercote
938e594d62 Remove an unnecessary if let. 2024-02-23 11:12:04 +11:00
Nicholas Nethercote
21bb1a4359 Allow for a missing adt_def in NamePrivacyVisitor.
This was caused by 72b172bdf6 in #121206. That commit removed an early
return from `analysis` when there are stashed errors. As a result, it's
possible to reach privacy analysis when there are stashed errors, which
means more code paths can be reached. One such code path was handled in
that commit, where a `span_bug` was changed to a `span_delayed_bug`.

This commit handles another such code path uncovered by fuzzing, in much
the same way.

Fixes #121455.
2024-02-23 10:57:11 +11:00
Nicholas Nethercote
109321ac47 Revert some span_bugs to span_delayed_bug.
Fixes #121445.
Fixes #121457.
2024-02-23 10:04:32 +11:00
lcnr
dabacb7431 fix CI 2024-02-22 23:10:46 +01:00
Nicholas Nethercote
4f83e50f98 Revert some span_bugs to span_delayed_bug.
Fixes #121410.
Fixes #121414.
Fixes #121418.
Fixes #121431.
2024-02-23 08:35:18 +11:00
lcnr
fa2921bdca woops, soundly generalizing is hard
I ended up getting confused while trying to flip the
variances when flipping the order. Should be
all right now
2024-02-22 22:24:12 +01:00
bors
397937d812 Auto merge of #119989 - lcnr:sub_relations-bye-bye, r=compiler-errors
remove `sub_relations` from the `InferCtxt`

While doing so, I tried to remove the `delay_span_bug` in `rematch_impl` again, which lead me to discover another `freshen` bug, fixing that one in the second commit. See commit descriptions for the reasoning behind each change.

r? `@compiler-errors`
2024-02-22 20:45:24 +00:00
onur-ozkan
52227edfaf set llvm.assertions to false in compiler profile
Having this set to true disrupts compiler development workflows for people who use `llvm.download-ci-llvm = true`
because we don't provide ci-llvm on the `rustc-alt-builds` server. Therefore, it is kept off by default.

Signed-off-by: onur-ozkan <work@onurozkan.dev>
2024-02-22 22:15:05 +03:00
bors
d9ae43c787 Auto merge of #121469 - matthiaskrgr:rollup-oaoxuo2, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #120598 (No need to `validate_alias_bound_self_from_param_env` in `assemble_alias_bound_candidates`)
 - #121386 (test that we do not support higher-ranked regions in opaque type inference)
 - #121393 (match lowering: Introduce a `TestCase` enum to replace most matching on `PatKind`)
 - #121401 (Fix typo in serialized.rs)
 - #121427 (Fix panic when compiling `Rocket`.)
 - #121439 (Fix typo in metadata.rs doc comment)
 - #121441 (`DefId`  to `LocalDefId`)
 - #121452 (Add new maintainers to nto-qnx.md)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-02-22 18:39:34 +00:00
Esteban Küber
91d0b371ef Fix rebase 2024-02-22 18:38:10 +00:00
Esteban Küber
d67dcf5a8b review comment: remove unnused return value 2024-02-22 18:05:28 +00:00
Esteban Küber
fdaaaa1951 fix test 2024-02-22 18:05:28 +00:00
Esteban Küber
28c028737d Deduplicate some logic and reword output 2024-02-22 18:05:28 +00:00
Esteban Küber
b59bd7fd16 review comments: clean up 2024-02-22 18:05:28 +00:00
Esteban Küber
f566867ace Add flatmap/flat_map -> and_then suggestions 2024-02-22 18:05:28 +00:00
Esteban Küber
caa216d245 Tweak wording of "implemented trait isn't imported" suggestion 2024-02-22 18:05:27 +00:00
Esteban Küber
14277ef201 Better account for associated const found for fn call expr 2024-02-22 18:04:55 +00:00
Esteban Küber
76885673d6 fix test 2024-02-22 18:04:55 +00:00
Esteban Küber
e1e4da2b0a Make confusable suggestions verbose 2024-02-22 18:04:55 +00:00
Esteban Küber
385eea1d46 Consider methods from traits when suggesting typos
Do not provide a structured suggestion when the arguments don't match.

```
error[E0599]: no method named `test_mut` found for struct `Vec<{integer}>` in the current scope
  --> $DIR/auto-ref-slice-plus-ref.rs:7:7
   |
LL |     a.test_mut();
   |       ^^^^^^^^
   |
   = help: items from traits can only be used if the trait is implemented and in scope
note: `MyIter` defines an item `test_mut`, perhaps you need to implement it
  --> $DIR/auto-ref-slice-plus-ref.rs:14:1
   |
LL | trait MyIter {
   | ^^^^^^^^^^^^
help: there is a method `get_mut` with a similar name, but with different arguments
  --> $SRC_DIR/core/src/slice/mod.rs:LL:COL
```

Consider methods beyond inherent ones when suggesting typos.

```
error[E0599]: no method named `owned` found for reference `&dyn Foo` in the current scope
  --> $DIR/object-pointer-types.rs:11:7
   |
LL |     fn owned(self: Box<Self>);
   |                    --------- the method might not be found because of this arbitrary self type
...
LL |     x.owned();
   |       ^^^^^ help: there is a method with a similar name: `to_owned`
```

Fix #101013.
2024-02-22 18:04:55 +00:00
Esteban Küber
d30dfb0af7 Provide more and more accurate suggestions when calling the wrong method
```
error[E0308]: mismatched types
  --> $DIR/rustc_confusables_std_cases.rs:20:14
   |
LL |     x.append(42);
   |       ------ ^^ expected `&mut Vec<{integer}>`, found integer
   |       |
   |       arguments to this method are incorrect
   |
   = note: expected mutable reference `&mut Vec<{integer}>`
                           found type `{integer}`
note: method defined here
  --> $SRC_DIR/alloc/src/vec/mod.rs:LL:COL
help: you might have meant to use `push`
   |
LL |     x.push(42);
   |       ~~~~
```
2024-02-22 18:04:55 +00:00
Esteban Küber
e13d452111 drive-by fmt cleanup 2024-02-22 18:04:55 +00:00
Esteban Küber
0e89465672 On type error of method call arguments, look at confusables for suggestion 2024-02-22 18:04:55 +00:00
Esteban Küber
e5b3c7ef14 Add rustc_confusables annotations to some stdlib APIs
Help with common API confusion, like asking for `push` when the data structure really has `append`.

```
error[E0599]: no method named `size` found for struct `Vec<{integer}>` in the current scope
  --> $DIR/rustc_confusables_std_cases.rs:17:7
   |
LL |     x.size();
   |       ^^^^
   |
help: you might have meant to use `len`
   |
LL |     x.len();
   |       ~~~
help: there is a method with a similar name
   |
LL |     x.resize();
   |       ~~~~~~
```

#59450
2024-02-22 18:04:55 +00:00
Esteban Küber
6017de46f7 When encountering <&T as Clone>::clone(x) because T: Clone, suggest #[derive(Clone)]
CC #40699.
2024-02-22 18:01:20 +00:00
lcnr
16350d76d8 add comment 2024-02-22 18:54:51 +01:00
lcnr
db950efbc3 region unification update universe of region vars 2024-02-22 18:54:51 +01:00
lcnr
c71484eefd change error messages to be incorrect, but more helpful 2024-02-22 18:18:33 +01:00
Matthias Krüger
4537e6d120
Rollup merge of #121452 - jonathanpallant:patch-1, r=Amanieu
Add new maintainers to nto-qnx.md

[Ferrous Systems](https://ferrous-systems.com) are volunteering myself and `@japaric` as co-maintainers of the QNX targets.
2024-02-22 18:09:55 +01:00
Matthias Krüger
5401098ead
Rollup merge of #121441 - lcnr:typesystem-cleanup, r=compiler-errors
`DefId`  to `LocalDefId`
2024-02-22 18:09:55 +01:00
Matthias Krüger
e064bf639b
Rollup merge of #121439 - jrudolph:patch-1, r=bjorn3
Fix typo in metadata.rs doc comment
2024-02-22 18:09:55 +01:00
Matthias Krüger
01ec4eb319
Rollup merge of #121427 - nnethercote:fix-Rocket, r=oli-obk
Fix panic when compiling `Rocket`.

This panic was reported [here](https://github.com/rust-lang/rust/pull/120576#issuecomment-1957515484).

r? ``@oli-obk``
2024-02-22 18:09:54 +01:00