Commit graph

7232 commits

Author SHA1 Message Date
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
Boxy f74119a2e4 Bless tests and handle tests/crashes 2024-06-05 22:25:42 +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
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 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 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 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
lcnr a8e091de4a bivariant alias: set has_unconstrained_ty_var 2024-06-05 11:48:03 +02:00
Jubilee f12fe3a33e
Rollup merge of #126004 - compiler-errors:captures-soundness-test, r=lcnr
Add another test for hidden types capturing lifetimes that outlive but arent mentioned in substs

Another test to make sure future implementations of https://github.com/rust-lang/rust/pull/116040 don't have any subtle unsoundness 🤔

r? types
2024-06-05 01:14:35 -07: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
Jubilee 9ccc7b78ec
Rollup merge of #123168 - joshtriplett:size-of-prelude, r=Amanieu
Add `size_of` and `size_of_val` and `align_of` and `align_of_val` to the prelude

(Note: need to update the PR to add `align_of` and `align_of_val`, and remove the second commit with the myriad changes to appease the lint.)

Many, many projects use `size_of` to get the size of a type. However,
it's also often equally easy to hardcode a size (e.g. `8` instead of
`size_of::<u64>()`). Minimizing friction in the use of `size_of` helps
ensure that people use it and make code more self-documenting.

The name `size_of` is unambiguous: the name alone, without any prefix or
path, is self-explanatory and unmistakeable for any other functionality.
Adding it to the prelude cannot produce any name conflicts, as any local
definition will silently shadow the one from the prelude. Thus, we don't
need to wait for a new edition prelude to add it.
2024-06-05 01:14:29 -07:00
Michael Goulet dd6bca56ec Add another test for hidden types capturing lifetimes that outlive but arent mentioned in substs 2024-06-04 21:06:29 -04:00
Tomasz Miąsko 5d26f58423 Closures are recursively reachable 2024-06-04 22:50:35 +02:00
Guillaume Gomez fa96e2cb4f
Rollup merge of #125596 - nnethercote:rental-hard-error, r=estebank
Convert `proc_macro_back_compat` lint to an unconditional error.

We still check for the `rental`/`allsorts-rental` crates. But now if they are detected we just emit a fatal error, instead of emitting a warning and providing alternative behaviour.

The original "hack" implementing alternative behaviour was added in #73345.

The lint was added in #83127.

The tracking issue is #83125.

The direct motivation for the change is that providing the alternative behaviour is interfering with #125174 and follow-on work.

r? ``@estebank``
2024-06-04 21:41:33 +02:00
bors 44701e070c Auto merge of #123536 - compiler-errors:simplify-int-float, r=lcnr
Simplify `IntVarValue`/`FloatVarValue`

r? `@ghost`
2024-06-04 17:07:13 +00:00
León Orell Valerian Liehr 874670399c
Orphanck: Consider opaque types to never cover type parameters 2024-06-04 18:57:19 +02:00
Oli Scherer ffb1b2c148 Add test description 2024-06-04 15:34:04 +00:00
Oli Scherer 81895065bb Give test a more useful name 2024-06-04 15:33:51 +00:00
Oli Scherer 7894a11483 Move tests to a more appropriate directory 2024-06-04 15:33:20 +00:00
Oli Scherer 7d151fa3b0 Turn a delayed bug back into a normal bug by winnowing private method candidates instead of assuming any candidate of the right name will apply. 2024-06-04 15:32:41 +00:00
Oli Scherer 14f9c63759 Show that it will pick up the entirely wrong function as a private candidate 2024-06-04 15:32:37 +00:00
Michael Goulet a5dc684eee
Rollup merge of #125968 - BoxyUwU:shrink_ty_expr, r=oli-obk
Store the types of `ty::Expr` arguments in the `ty::Expr`

Part of #125958

In attempting to remove the `ty` field on `Const` it will become necessary to store the `Ty<'tcx>` inside of `Expr<'tcx>`. In order to do this without blowing up the size of `ConstKind`, we start storing the type/const args as `GenericArgs`

r? `@oli-obk`
2024-06-04 08:52:15 -04:00
Michael Goulet 7699da4858
Rollup merge of #125865 - ajwock:ice_not_fully_resolved, r=fee1-dead
Fix ICE caused by ignoring EffectVars in type inference

Fixes #119830
​r? ```@matthiaskrgr```
2024-06-04 08:52:13 -04:00
Michael Goulet 7e5528fa55
Rollup merge of #125795 - lucasscharenbroch:undescore-prefix-suggestion, r=compiler-errors
Improve renaming suggestion for names with leading underscores

Fixes #125650

Before:
```
error[E0425]: cannot find value `p` in this scope
 --> test.rs:2:13
  |
2 |     let _ = p;
  |             ^
  |
help: a local variable with a similar name exists, consider renaming `_p` into `p`
  |
1 | fn a(p: i32) {
  |      ~
```

After:
```
error[E0425]: cannot find value `p` in this scope
 --> test.rs:2:13
  |
1 | fn a(_p: i32) {
  |      -- `_p` defined here
2 |     let _ = p;
  |             ^
  |
help: the leading underscore in `_p` marks it as unused, consider renaming it to `p`
  |
1 | fn a(p: i32) {
  |      ~
```

This change doesn't exactly conform to what was proposed in the issue:

1. I've kept the suggested code instead of solely replacing it with the label
2. I've removed the "...similar name exists..." message instead of relocating to the usage span
3. You could argue that it still isn't completely clear that the change is referring to the definition (not the usage), but I'm not sure how to do this without playing down the fact that the error was caused by the usage of an undefined name.
2024-06-04 08:52:13 -04:00
Michael Goulet 46a033958a
Rollup merge of #125717 - weiznich:move/do_not_recommend_to_diganostic_namespace, r=compiler-errors
Refactor `#[diagnostic::do_not_recommend]` support

This commit refactors the `#[do_not_recommend]` support in the old parser to also apply to projection errors and not only to selection errors. This allows the attribute to be used more widely.

Part of #51992

r? `@compiler-errors`

<!--
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-04 08:52:12 -04:00
Michael Goulet 5019bb608a
Rollup merge of #125667 - oli-obk:taintify, r=TaKO8Ki
Silence follow-up errors directly based on error types and regions

During type_of, we used to just return an error type if there were any errors encountered. This is problematic, because it means a struct declared as `struct Foo<'static>` will end up not finding any inherent or trait impls because those impl blocks' `Self` type will be `{type error}` instead of `Foo<'re_error>`. Now it's the latter, silencing nonsensical follow-up errors about `Foo` not having any methods.

Unfortunately that now allows for new follow-up errors, because borrowck treats `'re_error` as `'static`, causing nonsensical errors about non-error lifetimes not outliving `'static`. So what I also did was to just strip all outlives bounds that borrowck found, thus never letting it check them. There are probably more nuanced ways to do this, but I worried there would be other nonsensical errors if some outlives bounds were missing. Also from the test changes, it looked like an improvement everywhere.
2024-06-04 08:52:12 -04:00
Oli Scherer 67a73f265f bless privacy tests (only diagnostic duplication) 2024-06-04 11:27:54 +00:00
许杰友 Jieyou Xu (Joe) 0dc65501cb
Rollup merge of #125608 - oli-obk:subsequent_lifetime_errors, r=BoxyUwU
Avoid follow-up errors if the number of generic parameters already doesn't match

fixes #125604

best reviewed commit-by-commit
2024-06-04 08:25:47 +01:00
许杰友 Jieyou Xu (Joe) aa13b892c7
Rollup merge of #124486 - beetrees:vectorcall-tracking-issue, r=ehuss
Add tracking issue and unstable book page for `"vectorcall"` ABI

Originally added in 2015 by #30567, the Windows `"vectorcall"` ABI didn't have a tracking issue until now.

Tracking issue: #124485
2024-06-04 08:25:46 +01:00
bors 27529d5c25 Auto merge of #125525 - joboet:tls_accessor, r=cuviper
Make TLS accessors closures that return pointers

The current TLS macros generate a function that returns an `Option<&'static T>`. This is both risky as we lie about lifetimes, and necessitates that those functions are `unsafe`. By returning a `*const T` instead, the accessor function do not have safety requirements any longer and can be made closures without hassle. This PR does exactly that!

For native TLS, the closure approach makes it trivial to select the right accessor function at compile-time, which could result in a slight speed-up (I have the hope that the accessors are now simple enough for the MIR-inliner to kick in).
2024-06-04 05:03:52 +00:00
bohan f67a0eb2b7 resolve: mark it undetermined if single import is not has any bindings 2024-06-04 12:40:41 +08:00
Michael Goulet 8f08625443 Remove a bunch of redundant args from report_method_error 2024-06-03 20:29:09 -04:00
Michael Goulet de6b219803 Make WHERE_CLAUSES_OBJECT_SAFETY a regular object safety violation 2024-06-03 09:49:04 -04:00
Oli Scherer adb2ac0165 Mark all extraneous generic args as errors 2024-06-03 13:21:17 +00:00
Oli Scherer 2e3842b6d0 Mark all missing generic args as errors 2024-06-03 13:16:56 +00:00
Oli Scherer 61c4b7f1a7 Hide some follow-up errors 2024-06-03 13:03:53 +00:00
Oli Scherer aebe8a7ed3 Add regression test 2024-06-03 13:03:52 +00:00
Andrew Wock 66a13861ae Fix ICE caused by ignoring EffectVars in type inference
Signed-off-by: Andrew Wock <ajwock@gmail.com>
2024-06-03 07:18:24 -04:00
bjorn3 07dc3ebf5c Allow static mut definitions with #[linkage]
Unlike static declarations with #[linkage], for definitions rustc
doesn't rewrite it to add an extra indirection.
2024-06-03 10:45:16 +00:00
bors 8768db9912 Auto merge of #125912 - nnethercote:rustfmt-tests-mir-opt, r=oli-obk
rustfmt `tests/mir-opt`

Continuing the work started in #125759. Details in individual commit log messages.

r? `@oli-obk`
2024-06-03 10:25:12 +00:00
bors 1d52972dd8 Auto merge of #125778 - estebank:issue-67100, r=compiler-errors
Use parenthetical notation for `Fn` traits

Always use the `Fn(T) -> R` format when printing closure traits instead of `Fn<(T,), Output = R>`.

Address #67100:

```
error[E0277]: expected a `Fn()` closure, found `F`
 --> file.rs:6:13
  |
6 |     call_fn(f)
  |     ------- ^ expected an `Fn()` closure, found `F`
  |     |
  |     required by a bound introduced by this call
  |
  = note: wrap the `F` in a closure with no arguments: `|| { /* code */ }`
note: required by a bound in `call_fn`
 --> file.rs:1:15
  |
1 | fn call_fn<F: Fn() -> ()>(f: &F) {
  |               ^^^^^^^^^^ required by this bound in `call_fn`
help: consider further restricting this bound
  |
5 | fn call_any<F: std::any::Any + Fn()>(f: &F) {
  |                              ++++++
```
2024-06-03 08:14:03 +00:00
Nicholas Nethercote ac24299636 Reformat mir! macro invocations to use braces.
The `mir!` macro has multiple parts:
- An optional return type annotation.
- A sequence of zero or more local declarations.
- A mandatory starting anonymous basic block, which is brace-delimited.
- A sequence of zero of more additional named basic blocks.

Some `mir!` invocations use braces with a "block" style, like so:
```
mir! {
    let _unit: ();
    {
	let non_copy = S(42);
	let ptr = std::ptr::addr_of_mut!(non_copy);
	// Inside `callee`, the first argument and `*ptr` are basically
	// aliasing places!
	Call(_unit = callee(Move(*ptr), ptr), ReturnTo(after_call), UnwindContinue())
    }
    after_call = {
	Return()
    }
}
```
Some invocations use parens with a "block" style, like so:
```
mir!(
    let x: [i32; 2];
    let one: i32;
    {
	x = [42, 43];
	one = 1;
	x = [one, 2];
	RET = Move(x);
	Return()
    }
)
```
And some invocations uses parens with a "tighter" style, like so:
```
mir!({
    SetDiscriminant(*b, 0);
    Return()
})
```
This last style is generally used for cases where just the mandatory
starting basic block is present. Its braces are placed next to the
parens.

This commit changes all `mir!` invocations to use braces with a "block"
style. Why?

- Consistency is good.

- The contents of the invocation is a block of code, so it's odd to use
  parens. They are more normally used for function-like macros.

- Most importantly, the next commit will enable rustfmt for
  `tests/mir-opt/`. rustfmt is more aggressive about formatting macros
  that use parens than macros that use braces. Without this commit's
  changes, rustfmt would break a couple of `mir!` macro invocations that
  use braces within `tests/mir-opt` by inserting an extraneous comma.
  E.g.:
  ```
  mir!(type RET = (i32, bool);, { // extraneous comma after ';'
      RET.0 = 1;
      RET.1 = true;
      Return()
  })
  ```
  Switching those `mir!` invocations to use braces avoids that problem,
  resulting in this, which is nicer to read as well as being valid
  syntax:
  ```
  mir! {
      type RET = (i32, bool);
      {
	  RET.0 = 1;
	  RET.1 = true;
	  Return()
      }
  }
  ```
2024-06-03 13:24:44 +10:00
bors 865eaf96be Auto merge of #125397 - gurry:125303-wrong-builder-suggestion, r=compiler-errors
Do not suggest unresolvable builder methods

Fixes #125303

The issue was that when a builder method cannot be resolved we are suggesting alternatives that themselves cannot be resolved. This PR adds a check that filters them from the list of suggestions.
2024-06-03 03:16:35 +00:00
Jubilee ca9dd62c05
Rollup merge of #125311 - calebzulawski:repr-packed-simd-intrinsics, r=workingjubilee
Make repr(packed) vectors work with SIMD intrinsics

In #117116 I fixed `#[repr(packed, simd)]` by doing the expected thing and removing padding from the layout.  This should be the last step in providing a solution to rust-lang/portable-simd#319
2024-06-02 05:06:47 -07:00
bors f67a1acc04 Auto merge of #125863 - fmease:rej-CVarArgs-in-parse_ty_for_where_clause, r=compiler-errors
Reject `CVarArgs` in `parse_ty_for_where_clause`

Fixes #125847. This regressed in #77035 where the `parse_ty` inside `parse_ty_where_predicate` was replaced with the at the time new `parse_ty_for_where_clause` which incorrectly stated it would permit CVarArgs (maybe a copy/paste error).

r? parser
2024-06-01 21:13:52 +00:00
León Orell Valerian Liehr 89386092f1
Reject CVarArgs in parse_ty_for_where_clause 2024-06-01 20:57:15 +02:00