Commit graph

256499 commits

Author SHA1 Message Date
Tobias Bucher f7c51a2d2f Directly add extension instead of using Path::with_extension
`Path::with_extension` has a nice footgun when the original path doesn't
contain an extension: Anything after the last dot gets removed.
2024-06-04 22:12:31 +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
bors 30ea1a2693 Auto merge of #125976 - compiler-errors:rollup-xt3le7w, r=compiler-errors
Rollup of 8 pull requests

Successful merges:

 - #125667 (Silence follow-up errors directly based on error types and regions)
 - #125717 (Refactor `#[diagnostic::do_not_recommend]` support)
 - #125795 (Improve renaming suggestion for names with leading underscores)
 - #125865 (Fix ICE caused by ignoring EffectVars in type inference)
 - #125953 (Streamline `nested` calls.)
 - #125959 (Reduce `pub` exposure in `rustc_mir_build`)
 - #125967 (Split smir `Const` into `TyConst` and `MirConst`)
 - #125968 (Store the types of `ty::Expr` arguments in the `ty::Expr`)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-06-04 14:49:54 +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 288727ef42
Rollup merge of #125967 - BoxyUwU:split_smir_const, r=oli-obk
Split smir `Const` into `TyConst` and `MirConst`

Part of #125958

Building a `smir::Const` currently requires accessing the `Ty<'tcx>` of a `ty::Const`. This will stop being possible in the future. Replicate the split in rustc of having a representation of type level constants and mir constants with the latter being able to store the former. Ideally we wouldnt have `MirConst::Ty` but 🤷‍♀️

r? `@oli-obk`
2024-06-04 08:52:15 -04:00
Michael Goulet 8272c6d8cc
Rollup merge of #125959 - nnethercote:rustc_mir_build-cleanups, r=compiler-errors
Reduce `pub` exposure in `rustc_mir_build`

r? compiler
2024-06-04 08:52:14 -04:00
Michael Goulet 23f39a21db
Rollup merge of #125953 - nnethercote:streamline-nested-calls, r=lqd
Streamline `nested` calls.

`TyCtxt` impls `PpAnn` in `compiler/rustc_middle/src/hir/map/mod.rs`. We can call that impl, which then calls the one on `intravisit::Map`, instead of calling the one on `intravisit::Map` directly, avoiding a cast and extra references.

r? `@lqd`
2024-06-04 08:52:14 -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
bors bc33782c23 Auto merge of #125948 - nnethercote:rustfmt-more-tests, r=lqd
rustfmt more tests

This finishes the formatting of tests begun in #125759 and continued in #125912.

r? `@lqd`
2024-06-04 11:51:35 +00:00
Oli Scherer 67a73f265f bless privacy tests (only diagnostic duplication) 2024-06-04 11:27:54 +00:00
bors 85f90a4612 Auto merge of #125960 - jieyouxu:rollup-1s7f6lr, r=jieyouxu
Rollup of 8 pull requests

Successful merges:

 - #124486 (Add tracking issue and unstable book page for `"vectorcall"` ABI)
 - #125504 (Change pedantically incorrect OnceCell/OnceLock wording)
 - #125608 (Avoid follow-up errors if the number of generic parameters already doesn't match)
 - #125690 (ARM Target Docs Update)
 - #125750 (Align `Term` methods with `GenericArg` methods, add `Term::expect_*`)
 - #125818 (Handle no values cfgs with `--print=check-cfg`)
 - #125909 (rustdoc: add a regression test for a former blanket impl synthesis ICE)
 - #125919 (Remove stray "this")

r? `@ghost`
`@rustbot` modify labels: rollup
2024-06-04 09:38:16 +00:00
Boxy 7e08f80b34 Split smir Const into TyConst and MirConst 2024-06-04 10:14:45 +01:00
Boxy f076dec336 Downsize ty::Expr 2024-06-04 10:13:38 +01:00
许杰友 Jieyou Xu (Joe) a04a6038bb
Rollup merge of #125919 - tbu-:pr_fix_typo, r=lqd
Remove stray "this"
2024-06-04 08:25:49 +01:00
许杰友 Jieyou Xu (Joe) 6abb7fba12
Rollup merge of #125909 - fmease:rustdoc-add-test-synth-blanket-impls, r=GuillaumeGomez
rustdoc: add a regression test for a former blanket impl synthesis ICE

Fixes #119792 (also passes in #125907 in case you were wondering).

r? rustdoc
2024-06-04 08:25:49 +01:00
许杰友 Jieyou Xu (Joe) 756af9d5bc
Rollup merge of #125818 - Urgau:print-check-cfg-no-values, r=petrochenkov
Handle no values cfgs with `--print=check-cfg`

This PR fix a bug with `--print=check-cfg`, where no values cfgs where not printed since we only printed cfgs that had at least one values.

The representation I choose is `CFG=`, since it doesn't correspond to any valid config, it also IMO nicely complements the `values()` (to indicate no values). Representing the absence of value by the absence of the value.

So for `cfg(feature, values())` we would print `feature=`.

I also added the missing tracking issue number in the doc.

r? ```@petrochenkov```
2024-06-04 08:25:48 +01:00
许杰友 Jieyou Xu (Joe) b477f89041
Rollup merge of #125750 - compiler-errors:expect, r=lcnr
Align `Term` methods with `GenericArg` methods, add `Term::expect_*`

* `Term::ty` -> `Term::as_type`.
* `Term::ct` -> `Term::as_const`.
* Adds `Term::expect_type` and `Term::expect_const`, and uses them in favor of `.ty().unwrap()`, etc.

I could also shorten these to `as_ty` and then do `GenericArg::as_ty` as well, but I do think the `as_` is important to signal that this is a conversion method, and not a getter, like `Const::ty` is.

r? types
2024-06-04 08:25:48 +01:00
许杰友 Jieyou Xu (Joe) 6c2cf0b038
Rollup merge of #125690 - Lokathor:arm-maintainer-reorg, r=ehuss
ARM Target Docs Update

Updates the ARM target docs, drawing more attention to the `arm-none-eabi` target group by placing all targets *within* that group as a sub-list in the Table of Contents.

Also updates the `armv4t-none-eabi` page (maintainer signoff: I'm that target's maintainer) to clarify that the page covers the arm version and the thumb version of the target, but that the target group page has the full info because there's nothing really specific to say for those targets.
2024-06-04 08:25:47 +01: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) d5a04221ef
Rollup merge of #125504 - mqudsi:once_nominal, r=cuviper
Change pedantically incorrect OnceCell/OnceLock wording

While the semantic intent of a OnceCell/OnceLock is that it can only be written to once (upon init), the fact of the matter is that both these types offer a `take(&mut self) -> Option<T>` mechanism that, when successful, resets the cell to its initial state, thereby [technically allowing it to be written to again](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=415c023a6ae1ef35f371a2d3bb1aa735)

Despite the fact that this can only happen with a mutable reference (generally only used during the construction of the OnceCell/OnceLock), it would be incorrect to say that the type itself as a whole *categorically* prevents being initialized or written to more than once (since it is possible to imagine an identical type only without the `take()` method that actually fulfills that contract).

To clarify, change "that cannot be.." to "that nominally cannot.." and add a note to OnceCell about what can be done with an `&mut Self` reference.

```@rustbot``` label +A-rustdocs
2024-06-04 08:25:46 +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
Nicholas Nethercote 5a5e2489c5 Reduce pub exposure.
A lot of errors don't need to be visible outside the crate, and some
other things as well.
2024-06-04 16:55:55 +10:00
Nicholas Nethercote 6b47c5e24d Remove out-of-date comment.
Exhaustiveness and usefulness checking are now in
`rustc_pattern_analysis`.
2024-06-04 15:18:35 +10:00
Nicholas Nethercote 4798c20d31 Streamline nested calls.
`TyCtxt` impls `PpAnn` in `compiler/rustc_middle/src/hir/map/mod.rs`. We
can call that impl, which then calls the one on `intravisit::Map`,
instead of calling the one on `intravisit::Map` directly, avoiding a
cast and extra references.
2024-06-04 15:08:08 +10: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
Nicholas Nethercote d2ea692e2d Explain why tests/ui-fulldeps/ is unformatted. 2024-06-04 14:15:45 +10:00
Nicholas Nethercote 758d49e5c8 Explain why tests/ui/ is unformatted. 2024-06-04 14:15:45 +10:00
Nicholas Nethercote 1be65925d7 Explain why tests/rustdoc-ui/ is unformatted. 2024-06-04 14:15:44 +10:00
Nicholas Nethercote 50185807d7 rustfmt tests/rustdoc-js-std/.
This is trivial, because the directory contains no `.rs` files.
2024-06-04 14:15:29 +10:00
Nicholas Nethercote 9f16362ab4 rustfmt tests/rustdoc-json/. 2024-06-04 14:15:19 +10:00
Nicholas Nethercote c6fb703c05 rustfmt tests/rustdoc-js/. 2024-06-04 14:15:06 +10:00
Nicholas Nethercote 98d65d62c5 Explain why tests/rustdoc-gui/ is unformatted. 2024-06-04 14:14:35 +10:00
bors 90d6255d82 Auto merge of #125380 - compiler-errors:wc-obj-safety, r=oli-obk
Make `WHERE_CLAUSES_OBJECT_SAFETY` a regular object safety violation

#### The issue

In #50781, we have known about unsound `where` clauses in function arguments:

```rust
trait Impossible {}

trait Foo {
    fn impossible(&self)
    where
        Self: Impossible;
}

impl Foo for &() {
    fn impossible(&self)
    where
        Self: Impossible,
    {}
}

// `where` clause satisfied for the object, meaning that the function now *looks* callable.
impl Impossible for dyn Foo {}

fn main() {
    let x: &dyn Foo = &&();
    x.impossible();
}
```

... which currently segfaults at runtime because we try to call a method in the vtable that doesn't exist. :(

#### What did u change

This PR removes the `WHERE_CLAUSES_OBJECT_SAFETY` lint and instead makes it a regular object safety violation. I choose to make this into a hard error immediately rather than a `deny` because of the time that has passed since this lint was authored, and the single (1) regression (see below).

That means that it's OK to mention `where Self: Trait` where clauses in your trait, but making such a trait into a `dyn Trait` object will report an object safety violation just like `where Self: Sized`, etc.

```rust
trait Impossible {}

trait Foo {
    fn impossible(&self)
    where
        Self: Impossible; // <~ This definition is valid, just not object-safe.
}

impl Foo for &() {
    fn impossible(&self)
    where
        Self: Impossible,
    {}
}

fn main() {
    let x: &dyn Foo = &&(); // <~ THIS is where we emit an error.
}
```

#### Regressions

From a recent crater run, there's only one crate that relies on this behavior: https://github.com/rust-lang/rust/pull/124305#issuecomment-2122381740. The crate looks unmaintained and there seems to be no dependents.

#### Further

We may later choose to relax this (e.g. when the where clause is implied by the supertraits of the trait or something), but this is not something I propose to do in this FCP.

For example, given:

```
trait Tr {
  fn f(&self) where Self: Blanket;
}

impl<T: ?Sized> Blanket for T {}
```

Proving that some placeholder `S` implements `S: Blanket` would be sufficient to prove that the same (blanket) impl applies for both `Concerete: Blanket` and `dyn Trait: Blanket`.

Repeating here that I don't think we need to implement this behavior right now.

----

r? lcnr
2024-06-04 02:34:20 +00:00
Michael Goulet 273b990554 Align Term methods with GenericArg methods 2024-06-03 20:36:27 -04:00
bors 1689a5a531 Auto merge of #122597 - pacak:master, r=bjorn3
Show files produced by `--emit foo` in json artifact notifications

Right now it is possible to ask `rustc` to save some intermediate representation into one or more files with `--emit=foo`, but figuring out what exactly was produced is difficult. This pull request adds information about `llvm_ir` and `asm` intermediate files into notifications produced by `--json=artifacts`.

Related discussion: https://internals.rust-lang.org/t/easier-access-to-files-generated-by-emit-foo/20477

Motivation - `cargo-show-asm` parses those intermediate files and presents them in a user friendly way, but right now I have to apply some dirty hacks. Hacks make behavior confusing: https://github.com/hintron/computer-enhance/issues/35

This pull request introduces a new behavior: now `rustc` will emit a new artifact notification for every artifact type user asked to `--emit`, for example for `--emit asm` those will include all the `.s` files.

Most users won't notice this behavior, to be affected by it all of the following must hold:
- user must use `rustc` binary directly (when `cargo` invokes `rustc` - it consumes artifact notifications and doesn't emit anything)
- user must specify both `--emit xxx` and `--json artifacts`
- user must refuse to handle unknown artifact types
- user must disable incremental compilation (or deal with it better than cargo does, or use a workaround like `save-temps`) in order not to hit #88829 / #89149
2024-06-04 00:05:56 +00:00
Nicholas Nethercote e372bf8e33 Explain why tests/rustdoc/ is unformatted. 2024-06-04 09:53:02 +10:00
Nicholas Nethercote a78e1202dd rustfmt tests/run-pass-valgrind/. 2024-06-04 09:53:02 +10:00
Nicholas Nethercote d161d06241 rustfmt tests/run-make-fulldeps/.
Note: I inserted blank lines between the items in
`pretty-expanded/input.rs` because it looked better that way.
2024-06-04 09:53:02 +10:00
Nicholas Nethercote 5875f3fff3 Explain why tests/pretty/ is unformatted. 2024-06-04 09:53:02 +10:00
bors 7c52d2db63 Auto merge of #125383 - Oneirical:bundle-them-up, r=jieyouxu
Rewrite `emit`, `mixing-formats` and `bare-outfile` `run-make` tests in `rmake.rs` format

Part of #121876 and the associated [Google Summer of Code project](https://blog.rust-lang.org/2024/05/01/gsoc-2024-selected-projects.html).

try-job: x86_64-msvc
2024-06-03 18:35:54 +00:00
bors eb5e2449c5 Auto merge of #125864 - compiler-errors:opt-in-error-reporting, r=lcnr
Opt-in to `FulfillmentError` generation to avoid doing extra work in the new solver

In the new solver, we do additional trait solving in order to generate fulfillment errors, because all we have is the root obligation. This is problematic because there are many cases where we don't need the full error information, and instead are just calling `ObligationCtxt::select_all_or_error` to probe whether a predicate holds or not. This is also problematic because we use `ObligationCtxt`s within the error reporting machinery itself, and so we can definitely cause stack overflows:

a94483a5f2/compiler/rustc_trait_selection/src/solve/inspect/analyse.rs (L75-L84)

So instead, make `TraitEngine` and `ObligationCtxt` generic over `E: FulfillmentErrorLike<'tcx>`, and introduce a new `ScrubbedTraitError` which only stores whether the failure was due to a "true error" or an ambiguity. Then, introduce `ObligationCtxt::new_with_diagnostics` for the callsites that actually inspect their `FulfillmentError`s.

r? `@lcnr`

Number-wise, there are:
```
     39 ObligationCtxt::new
     32 ObligationCtxt::new_with_diagnostics
      1 ObligationCtxt::new_generic
```
calls to each `ObligationCtxt` constructor, which suggests that there are indeed a lot of callsites that don't care about diagnostics.
2024-06-03 15:43:06 +00:00
Michael Goulet a41c44f21c Nits and formatting 2024-06-03 10:02:08 -04:00
Michael Goulet 511f1cf7c8 check_is_object_safe -> is_object_safe 2024-06-03 09:49:30 -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 d498eb5937 Provide previous generic arguments to provided_kind 2024-06-03 13:48:54 +00:00
Oli Scherer 108a1e5f4b Always provide previous generic arguments 2024-06-03 13:45:36 +00:00
Oli Scherer 063b26af6b Explain some code duplication 2024-06-03 13:28:49 +00:00