Commit Graph

36648 Commits

Author SHA1 Message Date
Michael Goulet
91274c84b9 Uplift TypeRelation and Relate 2024-06-06 07:50:19 -04:00
Michael Goulet
82ef3ad980 Uplift TypeError 2024-06-06 07:49:47 -04:00
Michael Goulet
c74efbca71 Make middle not rely on next_trait_solver 2024-06-06 07:49:47 -04:00
bors
2d28b6384e Auto merge of #124482 - spastorino:unsafe-extern-blocks, r=oli-obk
Unsafe extern blocks

This implements RFC 3484.

Tracking issue #123743 and RFC https://github.com/rust-lang/rfcs/pull/3484

This is better reviewed commit by commit.
2024-06-06 08:14:58 +00:00
bors
2b6a34273d Auto merge of #126056 - matthiaskrgr:rollup-ytwg62v, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #124731 (Add translation support by mdbook-i18n-helpers to bootstrap)
 - #125168 (Match ergonomics 2024: align implementation with RFC)
 - #125925 (Don't trigger `unsafe_op_in_unsafe_fn` for deprecated safe fns)
 - #125987 (When `derive`ing, account for HRTB on `BareFn` fields)
 - #126045 (check_expr_struct_fields: taint context with errors if struct definit…)
 - #126048 (Fix typos in cargo-specifics.md)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-06-06 05:56:06 +00:00
bors
003a902792 Auto merge of #125958 - BoxyUwU:remove_const_ty, r=lcnr
Remove the `ty` field from type system `Const`s

Fixes #125556
Fixes #122908

Part of the work on `adt_const_params`/`generic_const_param_types`/`min_generic_const_exprs`/generally making the compiler nicer. cc rust-lang/project-const-generics#44

Please review commit-by-commit otherwise I wasted a lot of time not just squashing this into a giant mess (and also it'll be SO much nicer because theres a lot of fluff changes mixed in with other more careful changes if looking via File Changes

---

Why do this?
- The `ty` field keeps causing ICEs and weird behaviour due to it either being treated as "part of the const" or it being forgotten about leading to ICEs.
- As we move forward with `adt_const_params` and a potential `min_generic_const_exprs` it's going to become more complex to actually lower the correct `Ty<'tcx>`
- It muddles the idea behind how we check `Const` arguments have the correct type. By having the `ty` field it may seem like we ought to be relating it when we relate two types, or that its generally important information about the `Const`.
- Brings the compiler more in line with `a-mir-formality` as that also tracks the type of type system `Const`s via `ConstArgHasType` bounds in the env instead of on the `Const` itself.
- A lot of stuff is a lot nicer when you dont have to pass around the type of a const lol. Everywhere we construct `Const` is now significantly nicer 😅

See #125671's description for some more information about the `ty` field

---

General summary of changes in this PR:

- Add `Ty` to `ConstKind::Value` as otherwise there is no way to implement `ConstArgHasType` to ensure that const arguments are correctly typed for the parameter when we stop creating anon consts for all const args. It's also just incredibly difficult/annoying to thread the correct `Ty` around to a bunch of ctfe functions otherwise.
-  Fully implement `ConstArgHasType` in both the old and new solver. Since it now has no reliance on the `ty` field it serves its originally intended purpose of being able to act as a double check that trait vs impls have correctly typed const parameters. It also will now be able to be responsible for checking types of const arguments to parameters under `min_generic_const_exprs`.
- Add `Ty` to `mir::Const::Ty`. I dont have a great understanding of why mir constants are setup like this to be honest. Regardless they need to be able to determine the type of the const and the easiest way to make this happen was to simply store the `Ty` along side the `ty::Const`. Maybe we can do better here in the future but I'd have to spend way more time looking at everywhere we use `mir::Const`.
- rustdoc has its own `Const` which also has a `ty` field. It was relatively easy to remove this.

---

r? `@lcnr` `@compiler-errors`
2024-06-06 03:41:23 +00:00
Matthias Krüger
3121a5ca3b
Rollup merge of #126045 - olafes:master, r=compiler-errors
check_expr_struct_fields: taint context with errors if struct definit…

Taint errors while checking `struct { field: 1 }` below if struct definition has duplicated fields so that we don't pass it to const eval.

fixes #125842, fixes #124464, fixes #124552
```rust
struct Struct {
    field: Option<u8>,
    field: u8,
}

static STATIC: Struct = Struct {
    field: 1,
};

pub fn main() {}
```
(This was #125947 but i messed something up, sorry)
r? ``@compiler-errors``
2024-06-06 04:17:27 +02:00
Matthias Krüger
55b76f4720
Rollup merge of #125987 - estebank:issue-122622, r=Nadrieril
When `derive`ing, account for HRTB on `BareFn` fields

When given

```rust
trait SomeTrait {
    type SomeType<'a>;
}

#[derive(Clone)]
struct Foo<T: SomeTrait> {
    x: for<'a> fn(T::SomeType<'a>)
}
```

expand to

```rust
impl<T: ::core::clone::Clone + SomeTrait> ::core::clone::Clone for Foo<T>
    where for<'a> T::SomeType<'a>: ::core::clone::Clone {
    #[inline]
    fn clone(&self) -> Foo<T> {
        Foo { x: ::core::clone::Clone::clone(&self.x) }
    }
}
```

instead of the previous invalid

```
impl<T: ::core::clone::Clone + SomeTrait> ::core::clone::Clone for Foo<T>
    where T::SomeType<'a>: ::core::clone::Clone {
    #[inline]
    fn clone(&self) -> Foo<T> {
        Foo { x: ::core::clone::Clone::clone(&self.x) }
    }
}
```

Fix #122622.

<!--
If this PR is related to an unstable feature or an otherwise tracked effort,
please link to the relevant tracking issue here. If you don't know of a related
tracking issue or there are none, feel free to ignore this.

This PR will get automatically assigned to a reviewer. In case you would like
a specific user to review your work, you can assign it to them by using

    r​? <reviewer name>
-->
2024-06-06 04:17:26 +02:00
Matthias Krüger
8f04878dee
Rollup merge of #125925 - tbu-:pr_unsafe_env_unsafe_op_in_unsafe_fn, r=Nadrieril
Don't trigger `unsafe_op_in_unsafe_fn` for deprecated safe fns

Fixes #125875.

Tracking:

- #124866
2024-06-06 04:17:26 +02:00
Matthias Krüger
2611b292c4
Rollup merge of #125168 - Jules-Bertholet:match-ergonomics-2024-align-with-rfc, r=Nadrieril
Match ergonomics 2024: align implementation with RFC

- Remove eat-two-layers (`ref_pat_everywhere`)
- Consolidate `mut_preserve_binding_mode_2024` into `ref_pat_eat_one_layer_2024`
- `&mut` no longer peels off `&`
- Apply "no `ref mut` behind `&`" rule on all editions with `ref_pat_eat_one_layer_2024`
- Require `mut_ref` feature gate for all mutable by-reference bindings

r? ``@Nadrieril``

cc https://github.com/rust-lang/rust/issues/123076

``@rustbot`` label A-edition-2024 A-patterns
2024-06-06 04:17:26 +02:00
bors
d0ccb5413e Auto merge of #122505 - oli-obk:visit_nested_body2, r=tmiasko
Don't walk the bodies of free constants for reachability.

follow-up to #122371

cc #119214

This avoids codegening items (e.g. functions) that are only used during const eval, but do not reach their final constant value (e.g. via function pointers).

r? `@tmiasko`
2024-06-06 01:33:14 +00:00
Tobias Bucher
bb901a114f Don't trigger unsafe_op_in_unsafe_fn for deprecated safe fns
Fixes #125875.
2024-06-05 23:44:59 +02:00
Boxy
7fa98d0c01 ty::Expr reviews 2024-06-05 22:25:42 +01:00
Boxy
56092a345b Misc fixes (pattern type lowering, cfi, pretty printing) 2024-06-05 22:25:42 +01:00
Boxy
a454da3b1c Misc fixes to cranelift/clippy/miri 2024-06-05 22:25:42 +01:00
Boxy
60a5bebbe5 Add Ty to mir::Const::Ty 2024-06-05 22:25:41 +01:00
Boxy
8d6705cdb8 Fully implement ConstArgHasType 2024-06-05 22:25:41 +01:00
Boxy
a9702a6668 Add Ty to ConstKind::Value 2024-06-05 22:25:41 +01:00
Boxy
58feec9b85 Basic removal of Ty from places (boring) 2024-06-05 22:25:38 +01:00
bors
72fdf913c5 Auto merge of #126038 - matthiaskrgr:rollup-h4rm3x2, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - #124840 (resolve: mark it undetermined if single import is not has any bindings)
 - #125622 (Winnow private method candidates instead of assuming any candidate of the right name will apply)
 - #125648 (Remove unused(?) `~/rustsrc` folder from docker script)
 - #125672 (Add more ABI test cases to miri (RFC 3391))
 - #125800 (Fix `mut` static task queue in SGX target)
 - #125871 (Orphanck[old solver]: Consider opaque types to never cover type parameters)
 - #125893 (Handle all GVN binops in a single place.)
 - #126008 (Port `tests/run-make-fulldeps/issue-19371` to ui-fulldeps)
 - #126032 (Update description of the `IsTerminal` example)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-06-05 20:53:32 +00:00
Olaf Siwiński
743c41757c
check_expr_struct_fields: taint context with errors if struct definition is malformed 2024-06-05 21:54:22 +02:00
Matthias Krüger
33c02c3712
Rollup merge of #125893 - cjgillot:gvn-newops, r=oli-obk
Handle all GVN binops in a single place.

<!--
If this PR is related to an unstable feature or an otherwise tracked effort,
please link to the relevant tracking issue here. If you don't know of a related
tracking issue or there are none, feel free to ignore this.

This PR will get automatically assigned to a reviewer. In case you would like
a specific user to review your work, you can assign it to them by using

    r​? <reviewer name>
-->

Addresses https://github.com/rust-lang/rust/pull/125359/files#r1608185319
r? ``@oli-obk``
2024-06-05 18:21:14 +02:00
Matthias Krüger
9c8e46d08a
Rollup merge of #125871 - fmease:fix-orphanck-opaques, r=lcnr
Orphanck[old solver]: Consider opaque types to never cover type parameters

This fixes an oversight of mine in #117164. The change itself has already been FCP'ed.

This only affects the old solver, the next solver already correctly rejects the added test since #117164.

r? ``@lcnr``
2024-06-05 18:21:14 +02:00
Matthias Krüger
dd2e1a3b34
Rollup merge of #126022 - lcnr:generalize-alias-bivariant, r=compiler-errors
set `has_unconstrained_ty_var` when generalizing aliases in bivariant contexts

this previously prevented the `regression-31157` benchmark from building

r? `@compiler-errors`
2024-06-05 18:21:12 +02:00
Matthias Krüger
36cab1260d
Rollup merge of #125672 - Lokathor:update-miri-result-ffi, r=RalfJung
Add more ABI test cases to miri (RFC 3391)

Part of https://github.com/rust-lang/rust/issues/110503

cc `@RalfJung`
2024-06-05 18:21:12 +02:00
Matthias Krüger
79bb336b9c
Rollup merge of #125921 - Zalathar:buckets, r=oli-obk
coverage: Carve out hole spans in a separate early pass

When extracting spans from MIR for use in coverage instrumentation, we sometimes need to identify *hole spans* (currently just closures), and carve up the other spans so that they don't overlap with holes.

This PR simplifies the main coverage-span-refiner by extracting the hole-carving process into a separate early pass. That pass produces a series of independent buckets, and we run the span-refiner on each bucket separately.

There is almost no difference in the resulting mappings, other than in some edge cases involving macros.
2024-06-05 18:21:11 +02:00
Matthias Krüger
9abf8b105e
Rollup merge of #125622 - oli-obk:define_opaque_types15, r=compiler-errors
Winnow private method candidates instead of assuming any candidate of the right name will apply

partially reverts https://github.com/rust-lang/rust/pull/60721

My original motivation was just to avoid the `delay_span_bug` (by attempting to thread the `ErrorGuaranteed` through to here). But then I realized that the error message is wrong. It refers to the `Foo<A>::foo` instead of `Foo<B>::foo`. This is almost invisible, because both functions are the same, but on different lines, so `-Zui-testing` makes it so the test is the same no matter which of these two functions is referenced.

But there's a much more obvious bug: If `Foo<B>` does not have a `foo` method at all, but `Foo<A>` has a private `foo` method, then we'll refer to that one. This has now been fixed, and we report a normal `method not found` error.

The way this is done is by creating a list of all possible private functions (just like we create a list of the public functions that can actually be called), and then winnowing it by analyzing where bounds and `Self` types to see if any of the found methods can actually apply (again, just like with the list of public functions).

I wonder if there is room for doing the same thing with unstable functions instead of running all of method resolution twice.

r? ``@compiler-errors`` for method resolution stuff
2024-06-05 18:21:11 +02:00
Matthias Krüger
69a8c139f1
Rollup merge of #124840 - bvanjoi:fix-124490, r=petrochenkov
resolve: mark it undetermined if single import is not has any bindings

- Fixes #124490
- Fixes #125013

This issue arises from incorrect resolution updates, for example:

```rust
mod a {
    pub mod b {
        pub mod c {}
    }
}

use a::*;

use b::c;
use c as b;

fn main() {}
```

1. In the first loop, binding `(root, b)` is refer to `root:🅰️:b` due to `use a::*`.
    1. However, binding `(root, c)` isn't defined by `use b::c` during this stage because `use c as b` falls under the `single_imports` of `(root, b)`, where the `imported_module` hasn't been computed yet. This results in marking the `path_res` for `b` as `Indeterminate`.
    2. Then, the `imported_module` for `use c as b` will be recorded.
2. In the second loop, `use b::c` will be processed again:
    1. Firstly, it attempts to find the `path_res` for `(root, b)`.
    2. It will iterate through the `single_imports` of `use b::c`, encounter `use c as b`, attempt to resolve `c` in `root`, and ultimately return `Err(Undetermined)`, thus passing the iterator.
    3. Use the binding `(root, b)` -> `root:🅰️:b` introduced by `use a::*` and ultimately return `root:🅰️:b` as the `path_res` of `b`.
    4. Then define the binding `(root, c)` -> `root:🅰️🅱️:c`.
3. Then process `use c as b`, update the resolution for `(root, b)` to refer to `root:🅰️🅱️:c`, ultimately causing inconsistency.

In my view, step `2.2` has an issue where it should exit early, similar to the behavior when there's no `imported_module`. Therefore, I've added an attribute called `indeterminate` to `ImportData`. This will help us handle only those single imports that have at least one determined binding.

r? ``@petrochenkov``
2024-06-05 18:21:11 +02:00
Matthias Krüger
e2ea7d82b1
Rollup merge of #125861 - name1e5s:fix/rpath_null_panic, r=michaelwoerister
rustc_codegen_ssa: fix `get_rpath_relative_to_output` panic when lib only contains file name

<!--
If this PR is related to an unstable feature or an otherwise tracked effort,
please link to the relevant tracking issue here. If you don't know of a related
tracking issue or there are none, feel free to ignore this.

This PR will get automatically assigned to a reviewer. In case you would like
a specific user to review your work, you can assign it to them by using

    r​? <reviewer name>
-->

When compiles program with `-C rpath=yes` but with no output filename specified, or with filename ONLY, we will get an ICE for now. Fix it by treat empty `output` path in `get_rpath_relative_to_output`  as current dir.

Before this patch:

```bash
rustc -C prefer_dynamic=yes -C rpath=yes -O h.rs  # ICE, no output filename specified
rustc -o hello -C prefer_dynamic=yes -C rpath=yes -O h.rs # ICE, output filename has no path
rustc -o ./hello -C prefer_dynamic=yes -C rpath=yes -O h.rs # Works
```

All those examples work after the patch.

Close #119571.
Close #125785.
2024-06-05 18:21:10 +02:00
Matthias Krüger
94c19c6522
Rollup merge of #125819 - oli-obk:localize, r=fmease
Various `HirTyLowerer` cleanups

Previously there was some ad-hoc specialization going on, because you could call `allows_infer`, which basically was deciding between whether the trait object was backed by `FnCtxt` or by `ItemCtxt`. I moved all the different logic into dedicated methods on `HirTyLowerer` and removed `allows_infer`

best reviewed commit-by-commit
2024-06-05 18:21:10 +02:00
Matthias Krüger
e1745122ae
Rollup merge of #125792 - compiler-errors:dont-drop-upcast-cand, r=lcnr
Don't drop `Unsize` candidate in intercrate mode

Fixes #125767
2024-06-05 18:21:09 +02:00
Matthias Krüger
efc3fdc74d
Rollup merge of #125505 - aDotInTheVoid:middle-idl, r=pnkfelix
Add intra-doc-links to rustc_middle crate-level docs.

Makes it slightly faster to find these modules, as you don't need to hunt for them in the big list.
2024-06-05 18:21:09 +02:00
Matthias Krüger
49f950434b
Rollup merge of #125407 - pacak:no-lending-iterators, r=pnkfelix
Detect when user is trying to create a lending `Iterator` and give a custom explanation

The scope for this diagnostic is to detect lending iterators specifically and it's main goal is to help beginners to understand that what they are trying to implement might not be possible for `Iterator` trait specifically.

I ended up to changing the wording from originally proposed in the ticket because it might be misleading otherwise: `Data` might have a lifetime parameter but it can be unrelated to items user is planning to return.

Fixes https://github.com/rust-lang/rust/issues/125337
2024-06-05 18:21:08 +02:00
Matthias Krüger
28deff4244
Rollup merge of #124746 - OliverKillane:E0582-explain-assoc-types-improvement, r=pnkfelix
`rustc --explain E0582` additional example

## Context
*From #124744*

Expands the example for E0582, an error ensuring that lifetime in a function's return type is sufficiently constrained (e.g. actually tied to some input type), to show an additional example where one sees the lifetime occurring syntactically among the relevant function input types, but is nonetheless rejected by rustc because a syntactic occurrence is not always sufficient.
2024-06-05 18:21:08 +02:00
Oli Scherer
a0358f44b3 Also support generic constants 2024-06-05 15:40:11 +00:00
Oli Scherer
22d0073d47 Don't walk the bodies of free constants for reachability. 2024-06-05 15:40:11 +00:00
Ben Kimock
b710404f3b Update the interpreter to handle the new cases 2024-06-05 09:04:37 -04:00
Santiago Pastorino
1afc7d716c
Make MISSING_UNSAFE_ON_EXTERN lint emit future compat info with suggestion to prepend unsafe 2024-06-05 09:36:01 -03:00
Santiago Pastorino
0380321e78
Add unsafe_extern_blocks feature flag 2024-06-05 09:35:57 -03:00
lcnr
a8e091de4a bivariant alias: set has_unconstrained_ty_var 2024-06-05 11:48:03 +02:00
Oli Scherer
c8a331ac52 Unify optional param info with object lifetime default boolean into an enum that exhaustively supports all call sites 2024-06-05 09:16:55 +00:00
Oli Scherer
4146b8280a Remove some unnecessary explicit lifetimes 2024-06-05 09:16:55 +00:00
Oli Scherer
78706740d5 Remove allows_infer now that every use of it is delegated to HirTyLowerer 2024-06-05 09:16:55 +00:00
Oli Scherer
6a2e15a6f0 Only collect infer vars to error about in case infer vars are actually forbidden 2024-06-05 09:16:55 +00:00
Oli Scherer
abd308b886 Remove an Option and instead eagerly create error lifetimes 2024-06-05 09:16:55 +00:00
Oli Scherer
9d387d14e0 Simplify some code paths and remove an unused field
`ct_infer` and `lower_ty` will correctly result in an error constant or type respectively, as they go through a `HirTyLowerer` method (just like `HirTyLowerer::allow_infer` is a method implemented by both implementors
2024-06-05 08:43:37 +00:00
Oli Scherer
dc020ae5d8 Use a LocalDefId for HirTyLowerer::item_def_id, since we only ever (can) use it for local items 2024-06-05 08:43:37 +00:00
Jubilee
eb2819e706
Rollup merge of #125996 - tmiasko:closure-recursively-reachable, r=oli-obk
Closures are recursively reachable

Fixes #126012.
2024-06-05 01:14:34 -07:00
Jubilee
2b89c1b9ae
Rollup merge of #125920 - bjorn3:allow_static_mut_linkage_def, r=Urgau
Allow static mut definitions with #[linkage]

Unlike static declarations with #[linkage], for definitions rustc doesn't rewrite it to add an extra indirection.

This was accidentally disallowed in https://github.com/rust-lang/rust/pull/125046.

cc https://github.com/rust-lang/rust/pull/125800#issuecomment-2143776298
2024-06-05 01:14:32 -07:00
Jubilee
78d9a7e107
Rollup merge of #125906 - compiler-errors:simplify-method-error-args, r=fmease
Remove a bunch of redundant args from `report_method_error`

Rebased on top of #125397 because I had originally asked there (https://github.com/rust-lang/rust/pull/125397#discussion_r1610124799) for this change to be made, but I just chose to do it myself.

r? fmease
2024-06-05 01:14:32 -07:00