Commit Graph

2112 Commits

Author SHA1 Message Date
Michael Goulet 90e51f110c
Rollup merge of #112537 - compiler-errors:dont-record-adjustments-twice, r=cjgillot
Don't record adjustments twice in `note_source_of_type_mismatch_constraint`

We call `lookup_method` a few times in `note_source_of_type_mismatch_constraint`, but that function has side-effects to the typeck results. Replace it with a less side-effect-y variant of the function for use in diagnostics.

Specifically the ICE in #112532 happens because we're recording deref adjustments twice for a call receiver, which causes `ExprUseVisitor` to be angry.

Fixes #112532
2023-06-18 13:17:05 -07:00
bors 939786223f Auto merge of #112636 - clubby789:no-capture-array-ref, r=cjgillot
Don't capture `&[T; N]` when contents isn't read

Fixes the check in #111831
Fixes #112607, although I decided to test the root cause rather than including the example in the issue as a test.
cc `@BoxyUwU`
2023-06-18 15:48:08 +00:00
bors a8a29070f0 Auto merge of #100036 - DrMeepster:box_free_free_box, r=oli-obk
Remove `box_free` lang item

This PR removes the `box_free` lang item, replacing it with `Box`'s `Drop` impl. Box dropping is still slightly magic because the contained value is still dropped by the compiler.
2023-06-17 16:10:57 +00:00
Matthias Krüger 7051c84326
Rollup merge of #112683 - asquared31415:asm_clobber_ice, r=compiler-errors
fix ICE on specific malformed asm clobber_abi

fixes #112635
2023-06-17 12:43:30 +02:00
bors 0cc541e4b2 Auto merge of #108860 - oli-obk:tait_alias, r=compiler-errors
Add `AliasKind::Weak` for type aliases.

`type Foo<T: Debug> = Bar<T>;` does not check `T: Debug` at use sites of `Foo<NotDebug>`, because in contrast to a

```rust
trait Identity {
    type Identity;
}
impl<T: Debug> Identity for T {
    type Identity = T;
}
<NotDebug as Identity>::Identity
```

type aliases do not exist in the type system, but are expanded to their aliased type immediately when going from HIR to the type layer.

Similarly:

* a private type alias for a public type is a completely fine thing, even though it makes it a bit hard to write out complex times sometimes
* rustdoc expands the type alias, even though often times users use them for documentation purposes
* diagnostics show the expanded type, which is confusing if the user wrote a type alias and the diagnostic talks about another type that they don't know about.

For type alias impl trait, these issues do not actually apply in most cases, but sometimes you have a type alias impl trait like `type Foo<T: Debug> = (impl Debug, Bar<T>);`, which only really checks it for `impl Debug`, but by accident prevents `Bar<T>` from only being instantiated after proving `T: Debug`. This PR makes sure that we always check these bounds explicitly and don't rely on an implementation accident.

To not break all the type aliases out there, we only use it when the type alias contains an opaque type. We can decide to do this for all type aliases over an edition.

Or we can later extend this to more types if we figure out the back-compat concerns with suddenly checking such bounds.

As a side effect, easily allows fixing https://github.com/rust-lang/rust/issues/108617, which I did.

fixes https://github.com/rust-lang/rust/issues/108617
2023-06-17 00:33:29 +00:00
asquared31415 3dc793e625 fix ICE on specific malformed asm clobber_abi 2023-06-16 19:51:01 -04:00
DrMeepster a5c6cb888e remove box_free and replace with drop impl 2023-06-16 13:41:06 -07:00
Michael Goulet a5f8859937
Rollup merge of #112684 - saethlin:ignore-windows-alignment, r=wesleywiser
Disable alignment checks on i686-pc-windows-msvc

r? `@wesleywiser` Because you were in the Zulip discussion of this: https://rust-lang.zulipchat.com/#narrow/stream/238009-t-compiler.2Fmeetings/topic/.5Bweekly.5D.202023-06-15

cc #112480
2023-06-16 12:53:23 -07:00
Oli Scherer f3b7dd6388 Add `AliasKind::Weak` for type aliases.
Only use it when the type alias contains an opaque type.

Also does wf-checking on such type aliases.
2023-06-16 19:39:48 +00:00
Ben Kimock c54672e25f Disable alignment checks on i686-pc-windows-msvc 2023-06-16 09:06:12 -04:00
Dylan DPC c2e109744d
Rollup merge of #112642 - compiler-errors:interp-lit-err, r=nnethercote
Handle interpolated literal errors

Not sure why it was doing a whole dance to re-match on the token kind when it seems like `Lit::from_token` does the right thing for both macro-arg and regular literals. Nothing seems to have regressed diagnostics-wise from the change, though.

Fixes #112622

r? ``@nnethercote``
2023-06-16 14:46:17 +05:30
Dylan DPC 64f6c00772
Rollup merge of #112443 - compiler-errors:next-solver-opportunistically-resolve-regions, r=lcnr
Opportunistically resolve regions in new solver

Use `opportunistic_resolve_var` during canonicalization to collapse some regions.

We have to start using `CanonicalVarValues::is_identity_modulo_regions`. We also have to modify that function to consider responses like `['static, ^0, '^1, ^2]` to be an "identity" response, since because we opportunistically resolve regions, there's no longer a 1:1 mapping between canonical var values and bound var indices in the response...

There's one nasty side-effect -- one test (`tests/ui/dyn-star/param-env-infer.rs`) starts to ICE because the certainty goes from `Yes` to `Maybe(Overflow)`... Not exactly sure why, though? Putting this up for discussion/investigation.

r? ```@lcnr```
2023-06-16 14:46:15 +05:30
Dylan DPC b41db841e8
Rollup merge of #112399 - compiler-errors:closure-substs-root-universe, r=lcnr
Instantiate closure synthetic substs in root universe

In the UI test example, we end up generalizing an associated type (something like `<Map<Option<i32>, [closure upvars=?0]> as IntoIterator>::Item` generalizes into `<Map<Option<i32>, [closure upvars=?1]> as IntoIterator>::Item`) then assigning it to itself, emitting an alias-relate goal. This trivially holds via one of the normalizes-to candidates, instead of relating substs, so when closure analysis eventually sets `?0` to the actual upvars, `?1` never gets constrained. This ends up being reported as an ambiguity error during writeback.

Instead, we can take advantage of the fact that we *know* the closure substs live in the root universe. This will prevent them being generalized, since they always can be named, and the alias-relate above never gets emitted at all.

We can probably do this to a handful of other `next_ty_var` calls in typeck for variables that are clearly associated with the body of the program, but I wanted to limit this for now. Eventually, if we end up representing universes more faithfully like a tree or whatever, we can remove this and turn it back to just a call to `next_ty_var`.

Note: This is incredibly order-dependent -- we need to be assigning a type variable that was created *before* the closure substs, and we also need to actually have an unnormalized type at the time of the assignment. This currently seems easiest to trigger during call argument analysis just due to the fact that we instantiate the call's substs, normalize, THEN check args.

r? ```@lcnr```
2023-06-16 14:46:14 +05:30
Dylan DPC c563296a4f
Rollup merge of #112163 - bvanjoi:fix-105231-2, r=compiler-errors
fix: inline `predicate_may_hold_fatal` and remove expect call in it

- Fixes #105231
- Discussion: https://github.com/rust-lang/rust/pull/111985#discussion_r1208888821

r? ``@compiler-errors``
2023-06-16 14:46:14 +05:30
bohan b7921981d5 fix: inline `predicate_may_hold_fatal` 2023-06-16 11:09:53 +08:00
Guillaume Gomez 6b9b55ac98
Rollup merge of #112654 - aliemjay:closure-output-normalize, r=compiler-errors
normalize closure output in equate_inputs_and_outputs

Fixes #112604
2023-06-15 22:04:57 +02:00
Guillaume Gomez af955a647e
Rollup merge of #112614 - lukas-code:apit-unsized-suggestion, r=compiler-errors
tweak suggestion for argument-position `impl ?Sized`

fixes this invalid suggestion:
```text
help: consider removing the `?Sized` bound to make the type parameter `Sized`
  |
1 - fn foo(_: impl ?Sized) {}
1 + fn foo(_: impl ) {}
  |
```
2023-06-15 22:04:56 +02:00
Guillaume Gomez d233522418
Rollup merge of #112529 - jieyouxu:block-expr-unused-must-use, r=oli-obk
Extend `unused_must_use` to cover block exprs

Given code like

```rust
#[must_use]
fn foo() -> i32 {
    42
}

fn warns() {
    {
        foo();
    }
}

fn does_not_warn() {
    {
        foo()
    };
}

fn main() {
    warns();
    does_not_warn();
}
```

### Before This PR

```
warning: unused return value of `foo` that must be used
 --> test.rs:8:9
  |
8 |         foo();
  |         ^^^^^
  |
  = note: `#[warn(unused_must_use)]` on by default
help: use `let _ = ...` to ignore the resulting value
  |
8 |         let _ = foo();
  |         +++++++

warning: 1 warning emitted
```

### After This PR

```
warning: unused return value of `foo` that must be used
 --> test.rs:8:9
  |
8 |         foo();
  |         ^^^^^
  |
  = note: `#[warn(unused_must_use)]` on by default
help: use `let _ = ...` to ignore the resulting value
  |
8 |         let _ = foo();
  |         +++++++

warning: unused return value of `foo` that must be used
  --> test.rs:14:9
   |
14 |         foo()
   |         ^^^^^
   |
help: use `let _ = ...` to ignore the resulting value
   |
14 |         let _ = foo();
   |         +++++++      +

warning: 2 warnings emitted
```

Fixes #104253.
2023-06-15 22:04:56 +02:00
Guillaume Gomez db7d8374c1
Rollup merge of #112517 - fee1-dead-contrib:sus-op-no-borrow, r=compiler-errors
`suspicious_double_ref_op`: don't lint on `.borrow()`

closes #112489
2023-06-15 22:04:55 +02:00
Matthias Krüger c0a089e118
Rollup merge of #112634 - mj10021:issue-112438-fix, r=compiler-errors
add InlineConst check

add check to close #112438
2023-06-15 17:52:38 +02:00
Matthias Krüger 82eb4a0208
Rollup merge of #112486 - jieyouxu:issue-112472, r=oli-obk
Fix suggestion for E0404 not dealing with multiple generics

Fixes #112472.
2023-06-15 17:52:36 +02:00
Matthias Krüger f530016f50
Rollup merge of #111212 - nicklimmm:issue-107896-fix, r=pnkfelix
Add casting suggestion when assigning negative 2's complement bin or hex literal to a size compatible signed integer

Fixes #107896

The issue stated the case for `iX::MIN` variants. This PR extends the cases for other negative values (in the 2's complement).

Leveraged sign bits to detect such cases.

Example cases:
- <img width="845" alt="image" src="https://user-images.githubusercontent.com/65026286/236289682-19859f59-a9c5-48c5-b15f-78a935fbfcec.png">
- <img width="831" alt="image" src="https://user-images.githubusercontent.com/65026286/236289805-5b16488d-9138-4363-a1b6-a5c027c50aba.png">
- <img width="912" alt="image" src="https://user-images.githubusercontent.com/65026286/236290065-685a9777-034b-4def-83a8-cc4e20b1ed0c.png">
2023-06-15 17:52:35 +02:00
Ali MJ Al-Nasrawy c75e6e0f6c normalize closure output before relation 2023-06-15 12:49:49 +00:00
clubby789 e72618a897 Don't capture &[T; N] when contents isn't read 2023-06-15 11:42:20 +00:00
James Dietz b1f7ab2ea2 add test 2023-06-15 06:50:56 -04:00
许杰友 Jieyou Xu (Joe) 32ae8810fc
Fix suggestion for E0404 not dealing with multiple generics 2023-06-15 18:19:09 +08:00
Lukas Markeffsky b6a3f126c0 change `std::marker::Sized` to just `Sized` 2023-06-15 12:01:38 +02:00
Lukas Markeffsky ee7e717322 tweak suggestion for argument-position `impl ?Sized` 2023-06-15 12:00:57 +02:00
许杰友 Jieyou Xu (Joe) 72b3b58efc
Extend `unused_must_use` to cover block exprs 2023-06-15 17:59:13 +08:00
Michael Goulet 9ef580fa6f Handle interpolated literal errors 2023-06-15 01:55:37 +00:00
bors 6ee4265ca6 Auto merge of #104455 - the8472:dont-drain-on-drop, r=Amanieu
Don't drain-on-drop in DrainFilter impls of various collections.

This removes drain-on-drop behavior from various unstable DrainFilter impls (not yet for HashSet/Map) because that behavior [is problematic](https://github.com/rust-lang/rust/issues/43244#issuecomment-641638196) (because it can lead to panic-in-drop when user closures panic) and may become forbidden if [this draft RFC passes](https://github.com/rust-lang/rfcs/pull/3288).

closes #101122

[ACP](https://github.com/rust-lang/libs-team/issues/136)

affected tracking issues
* #43244
* #70530
* #59618

Related hashbrown update: https://github.com/rust-lang/hashbrown/pull/374
2023-06-15 00:03:10 +00:00
bors 8c74a5d27c Auto merge of #112625 - matthiaskrgr:rollup-jcobj3g, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #112584 (loongarch64-none*: Remove environment component from llvm target)
 - #112600 (Introduce a `Stable` trait to translate MIR to SMIR)
 - #112605 (Improve docs/clean up negative overlap functions)
 - #112611 (Error on unconstrained lifetime in RPITIT)
 - #112612 (Fix explicit-outlives-requirements lint span)
 - #112613 (Fix rustdoc-gui tests on Windows)
 - #112620 (Fix small typo)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-06-14 20:20:40 +00:00
Matthias Krüger 41d5aeccec
Rollup merge of #112612 - sginnett:issue-105150, r=compiler-errors
Fix explicit-outlives-requirements lint span

Fixes #105150 which caused the span reported by the explicit-outlives-requirements lint to be incorrect when
1) the lint should suggest the entire where clause to be removed and
2) there are inline bounds present that are not inferable outlives requirements

In particular, this would cause rustfix to leave a dangling empty where clause.
2023-06-14 18:10:31 +02:00
Matthias Krüger 8aff1122c6
Rollup merge of #112611 - compiler-errors:unconstrained-lt-in-rpitit, r=oli-obk
Error on unconstrained lifetime in RPITIT

Fixes #109468

The only thing is that I had to split `tests/ui/impl-trait/in-trait/method-signature-matches.rs` into a bunch of different revisions because some error aren't being emitted if all the different examples are all together in one file 🤔

r? `@oli-obk` just because i know you'll review it, feel free to re-roll
2023-06-14 18:10:31 +02:00
Matthias Krüger c1b4d075a2
Rollup merge of #112506 - compiler-errors:const-infer-ice, r=b-naber
Properly check associated consts for infer placeholders

We only reported an error if it was in a "suggestable" position (according to `is_suggestable_infer_ty`) -- this isn't correct for infer tys that can show up in other places in the constant's type, like behind a dyn trait.

fixes #112491
2023-06-14 18:10:30 +02:00
bors 7b0eac438a Auto merge of #112400 - WaffleLapkin:vtable_stats, r=compiler-errors
Collect VTable stats & add `-Zprint-vtable-sizes`

This is a bit hacky/buggy, but I'm not entirely sure how to fix it, so I want to ask reviewers for help...

To try this, use either of those:
- `cargo clean && RUSTFLAGS="-Zprint-vtable-sizes" cargo +toolchain b`
- `cargo clean && cargo rustc +toolchain -Zprint-vtable-sizes`
- `rustc +toolchain -Zprint-vtable-sizes ./file.rs`
2023-06-14 11:24:42 +00:00
bors 3ed2a10d17 Auto merge of #110662 - bryangarza:safe-transmute-reference-types, r=compiler-errors
Safe Transmute: Enable handling references

This patch enables support for references in Safe Transmute, by generating nested obligations during trait selection. Specifically, when we call `confirm_transmutability_candidate(...)`, we now recursively traverse the `rustc_transmute::Answer` tree and create obligations for all the `Answer` variants, some of which include multiple nested `Answer`s.
2023-06-14 08:26:22 +00:00
The 8472 114d5f221c s/drain_filter/extract_if/ for Vec, Btree{Map,Set} and LinkedList 2023-06-14 09:28:54 +02:00
Sam Ginnett 72531b7463 Fix explicit-outlives-requirements lint span 2023-06-13 23:04:00 -07:00
Michael Goulet bc78d0cbf1 Error on unconstrained lifetime in RPITIT 2023-06-14 05:20:31 +00:00
Matthias Krüger 269ea4bd6b
Rollup merge of #112520 - chenyukang:yukang-fix-112505, r=fee1-dead
Fix the overflow issue for transmute_generic_consts

Fixes #112505
2023-06-14 06:25:49 +02:00
Matthias Krüger 98f6e9644b
Rollup merge of #112495 - bvanjoi:fix-109153, r=petrochenkov
fix(resolve): update shadowed_glob more precision

- Fixes #109153
- Fixes #109962

## Why does it panic?

We use #109153 as an illustration.

The process of `resolve_imports` is:

| Iter | resolve     | resolution of **`(Mod(root), Ident(bar) in type ns)`** |
| -    | -           | -      |
| 0 | `use foo::*`   | `binding` -> foo::bar, `shallowed_glob` -> `None` |
| 1 | `use bar::bar` | `binding` -> foo::bar::bar, `shallowed_glob` -> foo::bar    |
| 2 | `use bar::*`   | `binding` -> foo::bar::bar, `shallowed_glob` -> foo::bar::bar::bar |

So during `finalize_import`, the `root::bar` in `use bar::bar` had been pointed to `foo::bar::bar::bar`, which is different from the `initial_module` valued of `foo::bar`, therefore, the panic had been triggered.

## Try to solve it

~I think #109153 should check-pass rather than throw an ambiguous error. Following this idea, there are two ways to solve this problem:~

~1. Give up the `initial_module` and update `import.imported_module` after each resolution update. However, I think this method may have too much impact.~
~2. Do not update the `shadowed_glob` when it is defined.~

~To be honest, I am not sure if this is the right way to solve this ICE. Perhaps there is a better resolution.~

Edit: we had made the `resolution.shadowed_glob` update more detailed.

r? `@petrochenkov`
2023-06-14 06:25:48 +02:00
Matthias Krüger 6fc50dacd4
Rollup merge of #112197 - compiler-errors:next-solver-erase, r=lcnr
Erase regions even if normalization fails in writeback (in new solver)

Or else we ICE during writeback on some programs that error
2023-06-14 06:25:48 +02:00
bors 6330daade9 Auto merge of #112062 - lukas-code:unsized-layout, r=wesleywiser
Make struct layout not depend on unsizeable tail

fixes (after backport) https://github.com/rust-lang/rust/issues/112048

Since unsizing `Ptr<Foo<T>>` -> `Ptr<Foo<U>` just copies the pointer and adds the metadata, the layout of `Foo` must not depend on niches in and alignment of the tail `T`.

Nominating for beta 1.71, because it will have this issue: `@rustbot` label beta-nominated
2023-06-13 22:34:59 +00:00
Michael Goulet 01377e8064 opportunistically resolve regions 2023-06-13 22:10:51 +00:00
Michael Goulet 7ff79cf4aa Move test 2023-06-13 21:54:11 +00:00
Michael Goulet c92342d58d Erase regions even if normalization fails in writeback 2023-06-13 21:53:01 +00:00
Wesley Wiser b982f3a988 Add test case for unsizing with niche 2023-06-13 15:32:42 -04:00
bohan f7330eb752 fix(resolve): update `shadowed_glob` more precision 2023-06-14 01:38:35 +08:00
bors 5683791ebb Auto merge of #112017 - Nemo157:unsafe-block-rustfix, r=eholk
Add MVP suggestion for `unsafe_op_in_unsafe_fn`

Rebase of https://github.com/rust-lang/rust/pull/99827

cc tracking issue https://github.com/rust-lang/rust/issues/71668

No real changes since the original PR, just migrated the new suggestion to use fluent messages and added a couple more testcases, AFAICT from the discussion there were no outstanding changes requested.
2023-06-13 15:57:59 +00:00