Commit Graph

230433 Commits

Author SHA1 Message Date
Martin Nordholts
38e0d58d7d Add regression test for --cap-lints allow and trait bounds warning
I have verified that the test fails if stderr begins to contain output
by making sure the test fails when I add

    eprintln!("some output on stderr");

to the compiler (I added it to `fn build_session()`).
2023-07-28 11:11:29 +02:00
bors
a6236fa460 Auto merge of #102757 - pcc:android-std-tests, r=workingjubilee
Make std tests pass on newer Android

Newer versions of Android forbid the creation of hardlinks as well as Unix domain sockets in the /data filesystem via SELinux rules, which causes several tests depending on this behavior to fail. So let's skip these tests on Android if we see an EACCES from one of these syscalls. To achieve this, introduce a macro with the horrible name of or_panic_or_skip_on_android_eacces (better suggestions welcome) which skips (returns from) the test if an EACCES return value is seen on Android.
2023-07-26 07:57:32 +00:00
bors
cf34adb0dd Auto merge of #113583 - asquared31415:tidy_no_issue_tests, r=workingjubilee
add tidy check that forbids issue-XXXX and ice-XXXX test filenames

Helps with #113345 by preventing any future tests with non-descriptive names from being added.

This PR only checks modified ui test files because there are far too many existing problematic tests to be fixed at once:
3063/15424 (~19.86%) `*.rs` ui test files match `^issue[-_ ]?\d+$`.
Another 1349 files, totaling ~28.60% of all ui test files, contain that pattern in addition to some other text, where they should probably omit it in favor of a comment.

note: between the creation of this PR and 2023-07-25 (14 days), 10 more tests were added that failed this check.

r? `@workingjubilee`
2023-07-26 04:35:37 +00:00
asquared31415
13e2abf6b3 add tidy check that forbids issue ui test filenames 2023-07-26 00:03:10 -04:00
bors
98db99f5f6 Auto merge of #113928 - nicholasbishop:bishop-update-cb-4, r=workingjubilee
Bump compiler_builtins to 0.1.98

Change list: https://github.com/rust-lang/compiler-builtins/compare/0.1.95...0.1.98
2023-07-26 02:50:58 +00:00
bors
bd1ae282f1 Auto merge of #113893 - mdibaiee:type-name-spill-flag, r=compiler-errors
new unstable option: -Zwrite-long-types-to-disk

This option guards the logic of writing long type names in files and instead using short forms in error messages in rustc_middle/ty/error behind a flag. The main motivation for this change is to disable this behaviour when running ui tests.

This logic can be triggered by running tests in a directory that has a long enough path, e.g. /my/very-long-path/where/rust-codebase/exists/

This means ui tests can fail depending on how long the path to their file is.

Some ui tests actually rely on this behaviour for their assertions, so for those we enable the flag manually.
2023-07-26 00:46:06 +00:00
bors
0dd5730e0f Auto merge of #114076 - matthiaskrgr:rollup-cpqq1n9, r=matthiaskrgr
Rollup of 5 pull requests

Successful merges:

 - #112995 (Check for `<&NotClone as Clone>::clone()` calls and suggest to add Clone trait appropriately)
 - #113578 (Don't say that a type is uncallable if its fn signature has errors in it)
 - #113661 (Double check that hidden types match the expected hidden type)
 - #114044 (factor out more stable impls)
 - #114062 (CI: split nested GHA groups instead of panicking)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-07-25 22:37:08 +00:00
Matthias Krüger
c80a9fa870
Rollup merge of #114062 - Kobzol:ci-group-splitting, r=Mark-Simulacrum
CI: split nested GHA groups instead of panicking

Bootstrap uses Github Actions groups to reduce clutter in CI job output. However, GHA doesn't support group nesting, and currently, when a group would be nested, bootstrap would panic. This is causing intermittent CI failures, because it's not trivial to make sure that groups won't be nested, and subtle changes in bootstrap (or even in caches being present) can cause nesting.

This PR changes the logic so that groups are never nested. Instead, when a group would be nested, the previous group is ended, and only then is the subgroup started. When the subgroup finishes, it will then restart any previously ended parent group.

r? `@Mark-Simulacrum`
2023-07-25 23:34:08 +02:00
Matthias Krüger
f9b8e6bb62
Rollup merge of #114044 - ericmarkmartin:more-stable-impls, r=spastorino
factor out more stable impls

I saw some logic must resembling stable impls and thought it might be nice to factor it out

r? `@spastorino`
2023-07-25 23:34:08 +02:00
Matthias Krüger
0b13deb548
Rollup merge of #113661 - oli-obk:tait_wtf, r=lcnr
Double check that hidden types match the expected hidden type

Fixes https://github.com/rust-lang/rust/issues/113278 specifically, but I left a TODO for where we should also add some hardening.

It feels a bit like papering over the issue, but at least this way we don't get unsoundness, but just surprising errors. Errors will be improved and given spans before this PR lands.

r? `@compiler-errors` `@lcnr`
2023-07-25 23:34:07 +02:00
Matthias Krüger
a6bf68d8d0
Rollup merge of #113578 - compiler-errors:uncallable-sig, r=b-naber
Don't say that a type is uncallable if its fn signature has errors in it

This is fallout from #106309, where we don't consider param-env candidates that reference errors because they unify with everything. This means, however, that we don't consider an APIT like `impl Fn(MissingType)` isn't considered to implement `Fn`, for example.

We can double-check that with a weaker heuristic [`extract_callable_info`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir_typeck/fn_ctxt/struct.FnCtxt.html#method.extract_callable_info), and suppress the knock-down error using that.

Fixes #113566
2023-07-25 23:34:07 +02:00
Matthias Krüger
c5c0aa143c
Rollup merge of #112995 - strottos:ref-clone-suggestions, r=fee1-dead
Check for `<&NotClone as Clone>::clone()` calls and suggest to add Clone trait appropriately

Added recursive checking back up the HIR to see if a `Clone` suggestion would be helpful.

Addresses https://github.com/rust-lang/rust/issues/112857

Largely based on: https://github.com/rust-lang/rust/pull/112977
2023-07-25 23:34:06 +02:00
bors
864bdf7843 Auto merge of #114027 - arlosi:update-cargo, r=ehuss
Update cargo

8 commits in 1b15556767f4b78a64e868eedf4073c423f02b93..7ac9416d82cd4fc5e707c9ec3574d22dff6466e5
2023-07-18 14:44:47 +0000 to 2023-07-24 14:29:38 +0000
- fix(cargo-credential): should enable feature `serde/derive` (rust-lang/cargo#12396)
- fix: encode URL params correctly for SourceId in Cargo.lock (rust-lang/cargo#12280)
- docs: format config override caveat as a note (rust-lang/cargo#12392)
- credential provider implementation (rust-lang/cargo#12334)
- feat(crates-io): expose HTTP headers and Error type (rust-lang/cargo#12310)
- chore: Don't update test data (rust-lang/cargo#12380)
- fix: only skip mtime check on `~/.cargo/{git,registry}` (rust-lang/cargo#12369)
- Update docs for artifact JSON debuginfo levels. (rust-lang/cargo#12376)

Since rust-lang/cargo#12334 makes built-in credential providers part of the cargo binary, it's no longer needed to build them in bootstrap.
2023-07-25 20:48:51 +00:00
Jakub Beránek
7d46885dc1
Split nested GHA groups instead of panicking 2023-07-25 21:16:57 +02:00
bors
18fa7b9104 Auto merge of #114063 - matthiaskrgr:rollup-c90czu6, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #114008 (coverage: Obtain the `__llvm_covfun` section name outside a per-function loop)
 - #114014 (builtin_macros: expect raw strings too)
 - #114043 (docs(LazyLock): add example pass local LazyLock variable to struct)
 - #114051 (Add regression test for invalid "unused const" in method)
 - #114052 (Suggest `{Option,Result}::as_ref()` instead of `cloned()` in some cases)
 - #114058 (Add help for crate arg when crate name is invalid)
 - #114060 (abi: unsized field in union - assert to delay bug )

r? `@ghost`
`@rustbot` modify labels: rollup
2023-07-25 18:58:30 +00:00
Arlo Siemsen
ecfac686af Remove credential providers from bootstrap
since they are now built-in to the Cargo binary
2023-07-25 12:23:52 -05:00
Matthias Krüger
ba6982b8a0
Rollup merge of #114060 - davidtwco:issue-113279, r=wesleywiser
abi: unsized field in union - assert to delay bug

Fixes #113279.

> Unions cannot have unsized fields, and as such, layout computation for
unions asserts that each union field is sized (as this would normally
have halted compilation earlier).
>
> However, if a generator ends up with an unsized local - a circumstance
in which an error will always have been emitted earlier, for example, if
attempting to dereference a `&str` - then the generator transform will
produce a union with an unsized field.
>
> Since https://github.com/rust-lang/rust/pull/110107, later passes will be run, such as constant propagation,
and can attempt layout computation on the generator, which will result
in layout computation of `str` in the context of it being a field of a
union - and so the aforementioned assertion would cause an ICE.
>
> It didn't seem appropriate to try and detect this case in the MIR body
and skip this specific pass; tainting the MIR body or delaying a bug
from the generator transform (or elsewhere) wouldn't prevent this either
(as neither would prevent the later pass from running); and tainting when
the deref of `&str` is reported, if that's possible, would unnecessarily
prevent potential other errors from being reported later in compilation,
and is very tailored to this specific case of getting a unsized type in
a generator.
>
> Given that this circumstance can only happen when an error should have
already been reported, the correct fix appears to be just changing the
assert to a delayed bug. This will still assert if there is some
circumstance where this occurs and no error has been reported, but it
won't crash the compiler in this instance.

While debugging this, I noticed a translation ICE in a delayed bug, so I fixed that too:

> During borrowck, the `MultiSpan` from a buffered diagnostic is cloned and
used to emit a delayed bug indicating a diagnostic was buffered - when
the buffered diagnostic is translated, then the cloned `MultiSpan` may
contain labels which can only render with the diagnostic's arguments, but
the delayed bug being emitted won't have those arguments. Adds a function
which clones `MultiSpan` without also cloning the contained labels, and
use this function when creating the buffered diagnostic delayed bug.
2023-07-25 19:21:39 +02:00
Matthias Krüger
de5228e489
Rollup merge of #114058 - chenyukang:yukang-fix-113981-crate-arg, r=fmease,oli-obk
Add help for crate arg when crate name is invalid

Fixes #113981
2023-07-25 19:21:38 +02:00
Matthias Krüger
b7a1ff2aaa
Rollup merge of #114052 - clubby789:suggest-option-asref, r=WaffleLapkin
Suggest `{Option,Result}::as_ref()` instead of `cloned()` in some cases

Fixes #114050

When we have an expr available that produces the type expectation, we can suggest appending `.as_ref()` to the span, instead of cloning the expr producing the mismatch
2023-07-25 19:21:38 +02:00
Matthias Krüger
99f404aa73
Rollup merge of #114051 - Enselic:const-local-var, r=cjgillot
Add regression test for invalid "unused const" in method

The warning can be reproduced with 1.63 but not with 1.64.

    $ rustc +1.63 tests/ui/lint/unused/const-local-var.rs
    warning: constant `F` is never used
      --> tests/ui/lint/unused/const-local-var.rs:14:9
       |
    14 |         const F: i32 = 2;
       |         ^^^^^^^^^^^^^^^^^
       |
       = note: `#[warn(dead_code)]` on by default
    $ rustc +1.64 tests/ui/lint/unused/const-local-var.rs

Add a regression test to prevent the problem from re-appearing.

Closes #69016
2023-07-25 19:21:38 +02:00
Matthias Krüger
91d1d7aa44
Rollup merge of #114043 - cathaysia:doc_lazy_lock, r=thomcc
docs(LazyLock): add example pass local LazyLock variable to struct
2023-07-25 19:21:37 +02:00
Matthias Krüger
8ecaf2ae57
Rollup merge of #114014 - davidtwco:issue-114010-env-rawstr, r=cjgillot
builtin_macros: expect raw strings too

Fixes #114010.

`expr_to_string` allows raw strings through so this code should be expected to handle those.
2023-07-25 19:21:37 +02:00
Matthias Krüger
24e34e2014
Rollup merge of #114008 - Zalathar:covfun-section-name, r=cjgillot
coverage: Obtain the `__llvm_covfun` section name outside a per-function loop

This section name is always constant for a given target, but obtaining it from LLVM requires a few intermediate allocations. There's no need to do so repeatedly from inside a per-function loop.
2023-07-25 19:21:36 +02:00
bors
8327047b23 Auto merge of #113393 - compiler-errors:next-solver-unsize-rhs, r=lcnr
Normalize the RHS of an `Unsize` goal in the new solver

`Unsize` goals are... tricky. Not only do they structurally match on their self type, but they're also structural on their other type parameter. I'm pretty certain that it is both incomplete and also just plain undesirable to not consider normalizing the RHS of an unsize goal. More practically, I'd like for this code to work:

```rust
trait A {}
trait B: A {}

impl A for usize {}
impl B for usize {}

trait Mirror {
    type Assoc: ?Sized;
}

impl<T: ?Sized> Mirror for T {
    type Assoc = T;
}

fn main() {
    // usize: Unsize<dyn B>
    let x = Box::new(1usize) as Box<<dyn B as Mirror>::Assoc>;
    // dyn A: Unsize<dyn B>
    let y = x as Box<<dyn A as Mirror>::Assoc>;
}
```

---

In order to achieve this, we add `EvalCtxt::normalize_non_self_ty` (naming modulo bikeshedding), which *must* be used for all non-self type arguments that are structurally matched in candidate assembly. Currently this is only necessary for `Unsize`'s argument, but I could see future traits requiring this (hopefully rarely) in the future. It uses `repeat_while_none` to limit infinite looping, and normalizes the self type until it is no longer an alias.

Also, we need to fix feature gate detection for `trait_upcasting` and `unsized_tuple_coercion` when HIR typeck has unnormalized types. We can do that by checking the `ImplSource` returned by selection, which necessitates adding a new impl source for tuple upcasting.
2023-07-25 17:10:31 +00:00
Michael Goulet
a7ed9c1da7 Make everything builtin! 2023-07-25 16:08:58 +00:00
yukang
e0c479eea2 Add help for crate arg when crate name is invalid 2023-07-26 00:05:00 +08:00
Michael Goulet
de81007d13 Consolidate trait upcasting and unsize into one normalization 2023-07-25 15:15:25 +00:00
Michael Goulet
c02d1a6553 Restore tuple unsizing feature gate 2023-07-25 15:15:25 +00:00
Michael Goulet
24eefd08e2 Make sure to detect trait upcasting coercion even after normalization 2023-07-25 15:15:25 +00:00
Michael Goulet
7e66c0b7ed Normalize the RHS of an unsize goal 2023-07-25 15:15:25 +00:00
David Wood
037b27430b
abi: unsized field in union - assert to delay bug
Unions cannot have unsized fields, and as such, layout computation for
unions asserts that each union field is sized (as this would normally
have halted compilation earlier).

However, if a generator ends up with an unsized local - a circumstance
in which an error will always have been emitted earlier, for example, if
attempting to dereference a `&str` - then the generator transform will
produce a union with an unsized field.

Since #110107, later passes will be run, such as constant propagation,
and can attempt layout computation on the generator, which will result
in layout computation of `str` in the context of it being a field of a
union - and so the aforementioned assertion would cause an ICE.

It didn't seem appropriate to try and detect this case in the MIR body
and skip this specific pass; tainting the MIR body or delaying a bug
from the generator transform (or elsewhere) wouldn't prevent this either
(as neither would prevent the later pass from running); and tainting when
the deref of `&str` is reported, if that's possible, would unnecessarily
prevent potential other errors from being reported later in compilation,
and is very tailored to this specific case of getting a unsized type in
a generator.

Given that this circumstance can only happen when an error should have
already been reported, the correct fix appears to be just changing the
assert to a delayed bug. This will still assert if there is some
circumstance where this occurs and no error has been reported, but it
won't crash the compiler in this instance.

Signed-off-by: David Wood <david@davidtw.co>
2023-07-25 15:50:39 +01:00
bors
4fc6b33474 Auto merge of #114011 - RalfJung:place-projection, r=oli-obk
interpret: Unify projections for MPlaceTy, PlaceTy, OpTy

For ~forever, we didn't really have proper shared code for handling projections into those three types. This is mostly because `PlaceTy` projections require `&mut self`: they might have to `force_allocate` to be able to represent a project part-way into a local.

This PR finally fixes that, by enhancing `Place::Local` with an `offset` so that such an optimized place can point into a part of a place without having requiring an in-memory representation. If we later write to that place, we will still do `force_allocate` -- for now we don't have an optimized path in `write_immediate` that would avoid allocation for partial overwrites of immediately stored locals. But in `write_immediate` we have `&mut self` so at least this no longer pollutes all our type signatures.

(Ironically, I seem to distantly remember that many years ago, `Place::Local` *did* have an `offset`, and I removed it to simplify things. I guess I didn't realize why it was so useful... I am also not sure if this was actually used to achieve place projection on `&self` back then.)

The `offset` had type `Option<Size>`, where `None` represent "no projection was applied". This is needed because locals *can* be unsized (when they are arguments) but `Place::Local` cannot store metadata: if the offset is `None`, this refers to the entire local, so we can use the metadata of the local itself (which must be indirect); if a projection gets applied, since the local is indirect, it will turn into a `Place::Ptr`. (Note that even for indirect locals we can have `Place::Local`: when the local appears in MIR, we always start with `Place::Local`, and only check `frame.locals` later. We could eagerly normalize to `Place::Ptr` but I don't think that would actually simplify things much.)

Having done all that, we can finally properly abstract projections: we have a new `Projectable` trait that has the basic methods required for projecting, and then all projection methods are implemented for anything that implements that trait. We can even implement it for `ImmTy`! (Not that we need that, but it seems neat.) The visitor can be greatly simplified; it doesn't need its own trait any more but it can use the `Projectable` trait. We also don't need the separate `Mut` visitor any more; that was required only to reflect that projections on `PlaceTy` needed `&mut self`.

It is possible that there are some more `&mut self` that can now become `&self`... I guess we'll notice that over time.

r? `@oli-obk`
2023-07-25 14:18:08 +00:00
Oli Scherer
df4bfd9e97 Try explaining where Inner is in the signature better 2023-07-25 13:40:04 +00:00
clubby789
c83dfe9aed Suggest {Option,Result}::as_ref() instead of cloned() in some cases 2023-07-25 13:19:27 +00:00
Ralf Jung
d127600511 add some sanity checks in write_immediate_no_validate 2023-07-25 14:30:58 +02:00
Ralf Jung
4ea2bd1c8f bless more 2023-07-25 14:30:58 +02:00
Ralf Jung
14a674c88c interpret: read_discriminant: only return VariantIdx 2023-07-25 14:30:58 +02:00
Ralf Jung
a2bcafa500 interpret: refactor projection code to work on a common trait, and use that for visitors 2023-07-25 14:30:58 +02:00
bors
23405bb123 Auto merge of #113476 - fee1-dead-contrib:c-str-lit, r=petrochenkov
Reimplement C-str literals

This reverts #113334, cc `@fmease.`

While converting lexer tokens to ast Tokens in `rustc_parse`, we check the edition of the span of the token. If the edition < 2021, we split the token into two, one being the identifier and other being the str literal.
2023-07-25 12:04:34 +00:00
Mahdi Dibaiee
b2d052b22d write-long-types-to-disk: update tests 2023-07-25 12:08:44 +01:00
David Wood
516a56581e
clippy: env! invocations can't be b"" literals
Signed-off-by: David Wood <david@davidtw.co>
2023-07-25 11:56:54 +01:00
Martin Nordholts
5d32fd1b06 Add regression test for invalid unused const in method
The warning can be reproduced with 1.63 but not with 1.64.

    $ rustc +1.63 tests/ui/lint/unused/const-local-var.rs
    warning: constant `F` is never used
      --> tests/ui/lint/unused/const-local-var.rs:14:9
       |
    14 |         const F: i32 = 2;
       |         ^^^^^^^^^^^^^^^^^
       |
       = note: `#[warn(dead_code)]` on by default
    $ rustc +1.64 tests/ui/lint/unused/const-local-var.rs

Add a regression test to prevent the problem from re-appearing.
2023-07-25 12:49:19 +02:00
David Wood
75df62d4a2
builtin_macros: raw str in diagnostic output
If a raw string was used in the `env!` invocation, then it should also
be shown in the diagnostic messages as a raw string.

Signed-off-by: David Wood <david@davidtw.co>
2023-07-25 11:12:52 +01:00
Deadbeef
a0376e9ec2 extract common code 2023-07-25 09:24:12 +00:00
bors
ff8fe76c0e Auto merge of #112646 - vn971:document-thread-names-for-sgx-target, r=m-ou-se
Document thread names for SGX compilation target

`@raoulstrackx` `@Mkaynov` `@jethrogb`
2023-07-25 09:14:11 +00:00
Steven Trotter
25db1fac81 Added recursive checking back up to see if a Clone suggestion would be helpful. 2023-07-25 10:09:26 +01:00
bors
c026d6a400 Auto merge of #114020 - steffahn:hide-specialized-ToString-impls, r=thomcc
Hide `ToString` implementations that specialize the default one

The status quo is highly confusing, since the overlap is not apparent, and specialization is not a feature of Rust. This change addresses #87545; I'm not certain if it closes/fixes it entirely, since that issue might also be tracking the question of a *general* solution for hiding the documentation for specializing impls automatically.

Before
![Screenshot_20230724_234210](https://github.com/rust-lang/rust/assets/3986214/54bbe659-1790-4e95-a5d8-5426e710ceb8)

After
![Screenshot_20230724_234255](https://github.com/rust-lang/rust/assets/3986214/ee645d6e-c1c0-40c0-a0d3-a5c5f3dae65e)
2023-07-25 07:31:15 +00:00
bors
5b1dc9de77 Auto merge of #113980 - bvanjoi:fix-113953, r=petrochenkov
fix(resolve): skip panic when resolution is dummy

Fixes #113953

Skip the panic when the binding refers to a dummy node during the finalization.

r? `@petrochenkov`
2023-07-25 05:25:11 +00:00
Eric Mark Martin
0a0ce4905d factor out more stable impls 2023-07-25 00:49:49 -04:00
DragonBillow
40dd5a337c
docs(LazyLock): add example pass local LazyLock variable to struct
Signed-off-by: DragonBillow <DragonBillow@outlook.com>
2023-07-25 12:21:30 +08:00