Commit graph

1932 commits

Author SHA1 Message Date
bors 8ebf04225d Auto merge of #112198 - compiler-errors:rollup-o2xe4of, r=compiler-errors
Rollup of 7 pull requests

Successful merges:

 - #111670 (Require that const param tys implement `ConstParamTy`)
 - #111914 (CFI: Fix cfi with async: transform_ty: unexpected GeneratorWitness(Bi…)
 - #112030 (Migrate `item_trait_alias` to Askama)
 - #112150 (Support 128-bit atomics on all x86_64 Apple targets)
 - #112174 (Fix broken link)
 - #112190 (Improve comments on `TyCtxt` and `GlobalCtxt`.)
 - #112193 (Check tuple elements are `Sized` in `offset_of`)

Failed merges:

 - #112071 (Group rfcs tests)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-06-02 07:57:21 +00:00
Michael Goulet ebb7f642e4
Rollup merge of #112193 - clubby789:offset-of-tuple-sized, r=est31
Check tuple elements are `Sized` in `offset_of`

Fixes #112186
2023-06-01 23:07:39 -07:00
Michael Goulet ceec2250a3
Rollup merge of #111914 - rcvalle:rust-cfi-fix-111184, r=compiler-errors
CFI: Fix cfi with async: transform_ty: unexpected GeneratorWitness(Bi…

Fixes https://github.com/rust-lang/rust/issues/111184 by encoding ty::Generator parent substs only.
2023-06-01 23:07:37 -07:00
Michael Goulet 24404e6409
Rollup merge of #111670 - compiler-errors:const-param-ty, r=BoxyUwU
Require that const param tys implement `ConstParamTy`

1. Require that const param tys implement `ConstParamTy` instead of using `search_for_adt_const_param_violation`
2. Add `StructuralPartialEq` as a supertrait for `ConstParamTy`, since we need to make sure that we derive *both* `PartialEq` and `Eq`
3. Implement `ConstParamTy` for tuples up to 12 (or whatever the default for tuples is)
4. Add some custom diagnostics to `ConstParamTy` errors, to avoid regressions from (1.). It's still not as great as it could be -- will point out inline in comments.

r? `@BoxyUwU`
2023-06-01 23:07:36 -07:00
bors 33c3d10128 Auto merge of #111677 - fee1-dead-contrib:rustc_const_eval-translatable, r=oli-obk,RalfJung
Use translatable diagnostics in `rustc_const_eval`

This PR:

* adds a `no_span` parameter to `note` / `help` attributes when using `Subdiagnostic` to allow adding notes/helps without using a span
* has minor tweaks and changes to error messages
2023-06-02 05:11:49 +00:00
clubby789 d722f27684 Test invalid tuple field identifiers 2023-06-02 01:33:09 +00:00
clubby789 731601ccd1 Check tuple elements are Sized in offset_of 2023-06-02 01:18:59 +00:00
Ramon de C Valle 76ff5ec886 CFI: Fix cfi with async: transform_ty: unexpected GeneratorWitness(Binde
Fixes #111184 by encoding ty::Generator parent substs only.
2023-06-01 23:22:54 +00:00
Matthias Krüger 20b25d233a
Rollup merge of #112147 - zirconium-n:issue-110934, r=compiler-errors
add inline-const test for elided lifetimes being infer vars

Fixes #110934
2023-06-01 22:47:32 +02:00
Michael Goulet 847d50453c Implement custom diagnostic for ConstParamTy 2023-06-01 18:21:42 +00:00
Michael Goulet a9fcb524ff Impl ConstParamTy for tuples, make PartialStructuralEq a supertrait too 2023-06-01 18:21:42 +00:00
Deadbeef 4f83717cf7 Use translatable diagnostics in rustc_const_eval 2023-06-01 14:45:18 +00:00
bors fabf929863 Auto merge of #112164 - Dylan-DPC:rollup-93zj7jw, r=Dylan-DPC
Rollup of 7 pull requests

Successful merges:

 - #108459 (rustdoc: Fix LinkReplacer link matching)
 - #111318 (Add a distinct `OperandValue::ZeroSized` variant for ZSTs)
 - #111892 (rustdoc: add interaction delays for tooltip popovers)
 - #111980 (Preserve substs in opaques recorded in typeck results)
 - #112024 (Don't suggest break through nested items)
 - #112128 (Don't compute inlining status of mono items in advance.)
 - #112141 (remove reference to Into in ? operator core/std docs, fix #111655)

Failed merges:

 - #112071 (Group rfcs tests)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-06-01 08:06:07 +00:00
Dylan DPC 02c4b4b279
Rollup merge of #112024 - compiler-errors:dont-break-thru-item, r=WaffleLapkin
Don't suggest break through nested items

Fixes #112020
2023-06-01 11:09:44 +05:30
Dylan DPC ccf99bd769
Rollup merge of #111980 - compiler-errors:unmapped-substs, r=lcnr
Preserve substs in opaques recorded in typeck results

This means that we now prepopulate MIR with opaques with the right substs.

The first commit is a hack that I think we discussed, having to do with `DefiningAnchor::Bubble` basically being equivalent to `DefiningAnchor::Error` in the new solver, so having to use `DefiningAnchor::Bind` instead, lol.

r? `@lcnr`
2023-06-01 11:09:43 +05:30
bors 23f93a1266 Auto merge of #103877 - oli-obk:const_eval_step_limit, r=fee1-dead
Replace const eval limit by a lint and add an exponential backoff warning

The lint triggers at the first power of 2 that comes after 1 million function calls or traversed back-edges (takes less than a second on usual programs). After the first emission, an unsilenceable warning is repeated at every following power of 2 terminators, causing it to get reported less and less the longer the evaluation runs.

cc `@rust-lang/wg-const-eval`

fixes #93481
closes #67217
2023-06-01 05:32:00 +00:00
bors ba1690bedd Auto merge of #111567 - Urgau:uplift_cast_ref_to_mut, r=b-naber
Uplift `clippy::cast_ref_to_mut` lint

This PR aims at uplifting the `clippy::cast_ref_to_mut` lint into rustc.

## `cast_ref_to_mut`

(deny-by-default)

The `cast_ref_to_mut` lint checks for casts of `&T` to `&mut T` without using interior mutability.

### Example

```rust,compile_fail
fn x(r: &i32) {
    unsafe {
        *(r as *const i32 as *mut i32) += 1;
    }
}
```

### Explanation

Casting `&T` to `&mut T` without interior mutability is undefined behavior, as it's a violation of Rust reference aliasing requirements.

-----

Mostly followed the instructions for uplifting a clippy lint described here: https://github.com/rust-lang/rust/pull/99696#pullrequestreview-1134072751

`@rustbot` label: +I-lang-nominated
r? compiler

-----

For Clippy:

changelog: Moves: Uplifted `clippy::cast_ref_to_mut` into rustc
2023-06-01 01:27:32 +00:00
bors 9af3865dec Auto merge of #110807 - petrochenkov:strictflavor, r=lqd,wesleywiser
linker: Report linker flavors incompatible with the current target

The linker flavor is checked for target compatibility even if linker is never used (e.g. we are producing a rlib).
If it causes trouble, we can move the check to `link.rs` so it will run if the linker (flavor) is actually used.

And also feature gate explicitly specifying linker flavors for tier 3 targets.

The next step is supporting all the internal linker flavors in user-visible interfaces (command line and json).
2023-05-31 22:40:25 +00:00
Ziru Niu e8c831a03b add inline-const test for elided lifetimes being infer vars 2023-06-01 02:28:31 +08:00
Michael Goulet df1c1afdaf Check that RPITs are compatible with the opaques inferred during HIR typeck too 2023-05-31 17:45:45 +00:00
Michael Goulet 0a51ab93cf Don't suggest break through nested items 2023-05-31 16:51:25 +00:00
bors 871b595202 Auto merge of #111913 - oli-obk:valtrees2, r=lcnr
Only rewrite valtree-constants to patterns and keep other constants opaque

Now that we can reliably fall back to comparing constants with `PartialEq::eq` to the match scrutinee, we can

1. eagerly try to convert constants to valtrees
2. then deeply convert the valtree to a pattern
3. if the to-valtree conversion failed, create an "opaque constant" pattern.

This PR specifically avoids any behavioral changes or major cleanups. What we can now do as follow ups is

* move the two remaining call sites to `destructure_mir_constant` off that query
* make valtree to pattern conversion infallible
    * this needs to be done after careful analysis of the effects. There may be user visible changes from that.

based on https://github.com/rust-lang/rust/pull/111768
2023-05-31 16:36:51 +00:00
Oli Scherer d030ece6f7 Only rewrite valtree-constants to patterns and keep other constants opaque 2023-05-31 14:02:57 +00:00
bors ad8304a0d5 Auto merge of #111076 - notriddle:notriddle/silence-private-dep-trait-impl-suggestions, r=cjgillot
diagnostics: exclude indirect private deps from trait impl suggest

Fixes #88696
2023-05-31 13:47:36 +00:00
Urgau 32d4e1c3c7 Adjust tests for newly uplifted cast_ref_to_mut lint 2023-05-31 13:42:53 +02:00
bors e4f7ad8e68 Auto merge of #112132 - matthiaskrgr:rollup-x2l75gf, r=matthiaskrgr
Rollup of 5 pull requests

Successful merges:

 - #111772 (Fix linkage for large binaries on mips64 platforms)
 - #111975 (Stop normalizing so many different prefixes)
 - #111979 (Respect CARGOFLAGS in bootstrap.py)
 - #112089 (Add `--warnings warn` flag to `x.py`)
 - #112103 (Bootstrap update to 1.71 beta)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-05-31 11:03:00 +00:00
Urgau 5da606779c Uplift clippy::cast_ref_to_mut to rustc 2023-05-31 12:28:38 +02:00
Oli Scherer 05eae08233 Remove const eval limit and implement an exponential backoff lint instead 2023-05-31 10:24:17 +00:00
Matthias Krüger ef82bd4b55
Rollup merge of #111975 - jyn514:normalization, r=cjgillot
Stop normalizing so many different prefixes

Previously, we would normalize *all* of
- the absolute path to the repository checkout
- the /rustc/$sha for stage1 (if `remap-debuginfo` was enabled)
- the /rustc/$sha for download-rustc
- the sysroot for download-rustc

Now, we consistently only normalize /rustc/FAKE_PREFIX. Not only is this much simpler, but it also avoids ongoing maintenance for download-rustc and makes it much less likely that tests break by accident.

- Change `tests/ui/track-diagnostics/track6.rs` to use a relative path instead of an absolute one. I am not actually sure why `track_caller` works here, but it does seem to work 🤷

- Pass `-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX` to all suites, not just UI. In particular, mir-opt tests emit /rustc/ paths in their output.

r? ```@cjgillot``` since you reviewed https://github.com/rust-lang/rust/pull/110699 - this is the test that it doesn't regress :)
2023-05-31 11:19:07 +02:00
bors e29821ff85 Auto merge of #111623 - BoxyUwU:move_eval_hack, r=compiler-errors
move `super_relate_consts` hack to `normalize_param_env_or_error`

`super_relate_consts` has as hack in it to work around the fact that `normalize_param_env_or_error` is broken. When relating two constants we attempt to evaluate them (aka normalize them). This is not an issue in any way specific to const generics, type aliases also have the same issue as demonstrated in [this code](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=84b6d3956a2c852a04b60782476b56c9).

Since the hack in `super_relate_consts` only exists to make `normalize_param_env_or_error` emit less errors move it to `normalize_param_env_or_error`. This makes `super_relate_consts` act more like the normal plain structural equality its supposed to and should help ensure that the hack doesnt accidentally affect other situations.

r? `@compiler-errors`
2023-05-31 08:25:28 +00:00
Matthias Krüger f5894517ec
Rollup merge of #112069 - clubby789:offset-of-sized-fields, r=WaffleLapkin
offset_of: don't require type to be `Sized`

Fixes #112051

~~The RFC [explicitly forbids](https://rust-lang.github.io/rfcs/3308-offset_of.html#limitations) non-`Sized` types, but it looks like only the fields being recursed into were checked. The sized check also seemed to have been completely missing for tuples~~
2023-05-31 07:07:01 +02:00
Boxy 21cf9ea7ed update test to not rely on super_relate_consts hack 2023-05-31 02:14:15 +01:00
bors e6e4f7ed15 Auto merge of #112070 - lcnr:disjoint-closure-capture-ub, r=oli-obk
change `BorrowKind::Unique` to be a mutating `PlaceContext`

fixes #112056

I believe that `BorrowKind::Unique` is a footgun in general, so I added a FIXME and opened https://github.com/rust-lang/rust/issues/112072. This is a bit too involved for this PR though.
2023-05-31 00:24:39 +00:00
bors f0411ffceb Auto merge of #111881 - lcnr:leak-check, r=nikomatsakis,jackh726
refactor and cleanup the leak check, add it to new solver

ended up being a bit more involved than I wanted but is hopefully still easy enough to review as a single PR, can split it into separate ones otherwise.

this can be reviewed commit by commit:
a473d55cdb9284aa2b01282d1b529a2a4d26547b 31a686646534ca006d906ec757ece4e771d6f973 949039c107852a5e36361c08b62821a0613656f5 242917bf5170d9a723c6c8e23e9d9d0c2fa8dc9d ed2b25a7aa28be3184be9e3022c2796a30eaad87 are all pretty straightforward.

03dd83b4c3f4ff27558f5c8ab859bd9f83db1d04 makes it easier to refactor coherence in a later commit, see the commit description, cc `@oli-obk`

4fe311d807a77b6270f384e41689bf5d58f46aec I don't quite remember what we wanted to test here, this definitely doesn't test that the occurs check doesn't cause incorrect errors in coherence, also cc `@oli-obk` here. I may end up writing a new test for this myself later.

5c200d88a91b75bd0875b973150655bd581ef97a is the main refactor of the leak check, changing it to take the `outer_universe` instead of getting it from a snapshot. Using a snapshot requires us to be in a probe which we aren't in the new solver, it also just feels dirty as snapshots don't really have anything to do with universes.

with all of this cfc230d54188d9c7ed867a9a0d1f51be77b485f9 is now kind of trivial.

r? `@nikomatsakis`
2023-05-30 18:48:12 +00:00
lcnr dccc8db17d coinductive cycle leak check test 2023-05-30 13:04:27 +02:00
lcnr 5119f7da18 directory size limit :< 2023-05-30 13:04:25 +02:00
lcnr 6f9041bd15 add the leak check to the new solver 2023-05-30 13:03:40 +02:00
lcnr 04056b5c04 update revision names 2023-05-30 13:03:40 +02:00
Nilstrieb cc121828ee
Rollup merge of #112100 - jieyouxu:issue-106929, r=oli-obk
Don't typecheck recovered method call from suggestion

Only make the use-dot-operator-to-call-method suggestion, but do not double down and use the recovered type to perform method call typechecking as it will produce confusing diagnostics relevant for the *fixed* code.

### Code Sample

```rust
struct Client;

impl Client {
    fn post<T: std::ops::Add>(&self, _: T, _: T) {}
}

fn f() {
    let c = Client;
    post(c, ());
}
```

### Before This PR

```
error[[E0277]](https://doc.rust-lang.org/stable/error_codes/E0277.html): cannot add `()` to `()`
 --> src/lib.rs:9:5
  |
9 |     post(c, ());
  |     ^^^^^^^^^^^ no implementation for `() + ()`
  |
  = help: the trait `Add` is not implemented for `()`
note: required by a bound in `Client::post`
 --> src/lib.rs:4:16
  |
4 |     fn post<T: std::ops::Add>(&self, _: T, _: T) {}
  |                ^^^^^^^^^^^^^ required by this bound in `Client::post`

error[[E0061]](https://doc.rust-lang.org/stable/error_codes/E0061.html): this function takes 2 arguments but 1 argument was supplied
 --> src/lib.rs:9:5
  |
9 |     post(c, ());
  |     ^^^^ an argument of type `()` is missing
  |
note: method defined here
 --> src/lib.rs:4:8
  |
4 |     fn post<T: std::ops::Add>(&self, _: T, _: T) {}
  |        ^^^^                   -----  ----  ----
help: provide the argument
  |
9 |     post((), ())(c, ());
  |         ++++++++

error[[E0425]](https://doc.rust-lang.org/stable/error_codes/E0425.html): cannot find function `post` in this scope
 --> src/lib.rs:9:5
  |
9 |     post(c, ());
  |     ^^^^ not found in this scope
  |
help: use the `.` operator to call the method `post` on `&Client`
  |
9 -     post(c, ());
9 +     c.post(());
  |

Some errors have detailed explanations: E0061, E0277, E0425.
For more information about an error, try `rustc --explain E0061`.
```

### After This PR

```
error[E0425]: cannot find function `post` in this scope
 --> tests/ui/typeck/issue-106929.rs:9:5
  |
9 |     post(c, ());
  |     ^^^^ not found in this scope
  |
help: use the `.` operator to call the method `post` on `&Client`
  |
9 -     post(c, ());
9 +     c.post(());
  |

error: aborting due to previous error

For more information about this error, try `rustc --explain E0425`.
```

Fixes #106929.
2023-05-30 12:57:41 +02:00
Nilstrieb 0c9f87c986
Rollup merge of #111872 - bvanjoi:fix-103646, r=cjgillot
fix: dedup `static_candidates` before report

Fixes https://github.com/rust-lang/rust/issues/103646

`record_static_candidate` had been executed twice, resulting in the presence of two identical `CandidateSource::Trait(Cat)`  in static_candidates. This PR aims to deduplication the `static_candidates` list, allowing it to execute `suggest_associated_call_syntax` properly.
2023-05-30 12:57:39 +02:00
Nilstrieb 7a4006cc52
Rollup merge of #111543 - Urgau:uplift_invalid_utf8_in_unchecked, r=WaffleLapkin
Uplift `clippy::invalid_utf8_in_unchecked` lint

This PR aims at uplifting the `clippy::invalid_utf8_in_unchecked` lint into two lints.

## `invalid_from_utf8_unchecked`

(deny-by-default)

The `invalid_from_utf8_unchecked` lint checks for calls to `std::str::from_utf8_unchecked` and `std::str::from_utf8_unchecked_mut` with an invalid UTF-8 literal.

### Example

```rust
unsafe {
    std::str::from_utf8_unchecked(b"cl\x82ippy");
}
```

### Explanation

Creating such a `str` would result in undefined behavior as per documentation for `std::str::from_utf8_unchecked` and `std::str::from_utf8_unchecked_mut`.

## `invalid_from_utf8`

(warn-by-default)

The `invalid_from_utf8` lint checks for calls to `std::str::from_utf8` and `std::str::from_utf8_mut` with an invalid UTF-8 literal.

### Example

```rust
std::str::from_utf8(b"ru\x82st");
```

### Explanation

Trying to create such a `str` would always return an error as per documentation for `std::str::from_utf8` and `std::str::from_utf8_mut`.

-----

Mostly followed the instructions for uplifting a clippy lint described here: https://github.com/rust-lang/rust/pull/99696#pullrequestreview-1134072751

````@rustbot```` label: +I-lang-nominated
r? compiler

-----

For Clippy:

changelog: Moves: Uplifted `clippy::invalid_utf8_in_unchecked` into rustc
2023-05-30 12:57:38 +02:00
lcnr 2a4467da9f add FIXME to a test which seems wrong. 2023-05-30 12:40:35 +02:00
lcnr aa13288e22 remove unused revision 2023-05-30 12:40:35 +02:00
lcnr 0a6ae29fe8 coherence: don't add hidden types for opaques
we can otherwise assign a hidden type to the opaque which
causes ICE if we don't use `take_opaque_types` during
coherence. This is annoying so I didn't bother. Added a test
showing the behavior this prevents.
2023-05-30 12:40:35 +02:00
许杰友 Jieyou Xu (Joe) e11ffb62df
Don't typecheck suggested method call
Only make the use-dot-operator-to-call-method suggestion, but do not
double down and use the recovered type to perform method call
typechecking as it will produce confusing diagnostics on the "fixed"
code.
2023-05-30 17:57:37 +08:00
clubby789 6c18d1ecef offset_of: Don't require type to be sized 2023-05-29 21:56:10 +00:00
Matthias Krüger 880da380f1
Rollup merge of #112057 - MU001999:fix/self-sugg, r=compiler-errors
Suggest correct `self_ty`

Fixes #112036
2023-05-29 21:34:18 +02:00
Matthias Krüger ef9a681183
Rollup merge of #112022 - compiler-errors:coercion-check-deep, r=lcnr
Check nested obligations during coercion unify in new solver

Found when triaging failing opaque tests with new solver.

r? `@lcnr`
2023-05-29 21:34:17 +02:00
Matthias Krüger 9f83e56f0d
Rollup merge of #111988 - BoxyUwU:make_tykind_debug_good, r=compiler-errors
Make `TyKind: Debug` have less verbose output

Current `TyKind: Debug` impl is basically unusable for debugging, its too verbose even for verbose debugging 🤣 This PR replaces the debug logic for `TyKind` with a more manual debug impl instead of a hand expanded derived impl. This should help make #107084 more reasonable to land since the output of `Ty: Debug` will be better.

This isn't a fully completed change to the `Debug` impl of `TyKind` as there's still logic from the derive macro for some variants. Some of the variants are also not consisten with the `-Zverbose` printing of `Ty`, ideally `-Zverbose` printing of `Ty` would also just defer to the debug impl instead of having lots of checks in pretty printing. I plan on fixing this in follow up PRs since it seems tricky to do in this one and its already a large PR 😅
2023-05-29 21:34:17 +02:00
Matthias Krüger 9e47e90071
Rollup merge of #111558 - c410-f3r:t3st3ss, r=WaffleLapkin
Move tests

r? `@petrochenkov`
2023-05-29 21:34:16 +02:00