Commit Graph

251917 Commits

Author SHA1 Message Date
bors
537aab7a2e Auto merge of #120131 - oli-obk:pattern_types_syntax, r=compiler-errors
Implement minimal, internal-only pattern types in the type system

rebase of https://github.com/rust-lang/rust/pull/107606

You can create pattern types with `std::pat::pattern_type!(ty is pat)`. The feature is incomplete and will panic on you if you use any pattern other than integral range patterns. The only way to create or deconstruct a pattern type is via `transmute`.

This PR's implementation differs from the MCP's text. Specifically

> This means you could implement different traits for different pattern types with the same base type. Thus, we just forbid implementing any traits for pattern types.

is violated in this PR. The reason is that we do need impls after all in order to make them usable as fields. constants of type `std::time::Nanoseconds` struct are used in patterns, so the type must be structural-eq, which it only can be if you derive several traits on it. It doesn't need to be structural-eq recursively, so we can just manually implement the relevant traits on the pattern type and use the pattern type as a private field.

Waiting on:

* [x] move all unrelated commits into their own PRs.
* [x] fix niche computation (see 2db07f94f44f078daffe5823680d07d4fded883f)
* [x] add lots more tests
* [x] T-types MCP https://github.com/rust-lang/types-team/issues/126 to finish
* [x] some commit cleanup
* [x] full self-review
* [x] remove 61bd325da19a918cc3e02bbbdce97281a389c648, it's not necessary anymore I think.
* [ ] ~~make sure we never accidentally leak pattern types to user code (add stability checks or feature gate checks and appopriate tests)~~ we don't even do this for the new float primitives
* [x] get approval that [the scope expansion to trait impls](https://rust-lang.zulipchat.com/#narrow/stream/326866-t-types.2Fnominated/topic/Pattern.20types.20types-team.23126/near/427670099) is ok

r? `@BoxyUwU`
2024-04-08 16:25:23 +00:00
bors
ab3dba92db Auto merge of #123628 - matthiaskrgr:rollup-6otgb94, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #115984 (extending filesystem support for Hermit)
 - #120144 (privacy: Stabilize lint `unnameable_types`)
 - #122807 (Add consistency with phrases "meantime" and "mean time")
 - #123089 (Add invariant to VecDeque::pop_* that len < cap if pop successful)
 - #123595 (Documentation fix)
 - #123625 (Stop exporting `TypeckRootCtxt` and `FnCtxt`.)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-04-08 14:15:48 +00:00
Matthias Krüger
f8252712a5
Rollup merge of #123625 - oli-obk:private_fnctxt, r=fee1-dead
Stop exporting `TypeckRootCtxt` and `FnCtxt`.

While they have many convenient APIs, it is better to expose dedicated functions for them

noticed in #122213
2024-04-08 14:31:12 +02:00
Matthias Krüger
5c3559df63
Rollup merge of #123595 - balaganesh102004:master, r=joboet
Documentation fix

Changed "It must not be an identical residual when interconversion is involved" to "The residual is not mandated to be identical when interconversion is involved." as the previous parenthetical appears to state that the residual is not permitted to be identical when interconversion is involved. However the intention of the original wording was to convey that the residual is not required to be identical when interconversion is involved, which makes more sense contextually.
2024-04-08 14:31:11 +02:00
Matthias Krüger
17c94b5f12
Rollup merge of #123089 - Philippe-Cholet:vecdeque_pop_assume_cap, r=Nilstrieb
Add invariant to VecDeque::pop_* that len < cap if pop successful

Similar to #114370 for VecDeque instead of Vec.

I initially come from https://github.com/rust-itertools/itertools/pull/899 where we noticed that `pop_front;push_back;` was slower than expected so `@scottmcm` suggested I file an issue which lead to https://internals.rust-lang.org/t/vecdeque-pop-front-push-back/20483 where **kornel** mentionned #114334 (fixed by #114370).

This is my first time with codegen tests, I based the test on what was done for Vec.
2024-04-08 14:31:11 +02:00
Matthias Krüger
98fbf86af9
Rollup merge of #122807 - danielhuang:fix-1, r=davidtwco
Add consistency with phrases "meantime" and "mean time"

"mean time" is used in a few places while "meantime" is used everywhere else; this would make usage consistent throughout the codebase.
2024-04-08 14:31:10 +02:00
Matthias Krüger
337be99bb6
Rollup merge of #120144 - petrochenkov:unty, r=davidtwco
privacy: Stabilize lint `unnameable_types`

This is the last piece of ["RFC #2145: Type privacy and private-in-public lints"](https://github.com/rust-lang/rust/issues/48054).

Having unstable lints is not very useful because you cannot even dogfood them in the compiler/stdlib in this case (https://github.com/rust-lang/rust/pull/113284).
The worst thing that may happen when a lint is removed are some `removed_lints` warnings, but I haven't heard anyone suggesting removing this specific lint.

This lint is allow-by-default and is supposed to be enabled explicitly.
Some false positives are expected, because sometimes unnameable types are a legitimate pattern.
This lint also have some unnecessary false positives, that can be fixed - see https://github.com/rust-lang/rust/issues/120146 and https://github.com/rust-lang/rust/issues/120149.

Closes https://github.com/rust-lang/rust/issues/48054.
2024-04-08 14:31:10 +02:00
Matthias Krüger
beaca9ce08
Rollup merge of #115984 - hermit-os:fuse, r=m-ou-se
extending filesystem support for Hermit

Extending `std` to create, change and read a directory for Hermit.

Hermit is a tier 3 platform and this PR changes only files, wich are related to the tier 3 platform.
2024-04-08 14:31:09 +02:00
bors
75fd074338 Auto merge of #123608 - Mark-Simulacrum:no-demangle-dbg, r=Kobzol
Remove debuginfo from rustc-demangle too

This is done for the same reason as the other dependencies in this list.
2024-04-08 12:08:17 +00:00
Oli Scherer
18ff131c4e Normalize layout test to protect against android alignment differences 2024-04-08 12:06:28 +00:00
Oli Scherer
84acfe86de Actually create ranged int types in the type system. 2024-04-08 12:02:19 +00:00
Oli Scherer
6b24a9cf70 Test macros 2024-04-08 12:02:12 +00:00
Oli Scherer
1d6cd8daf0 Start handling pattern types at the HIR -> Ty conversion boundary 2024-04-08 12:01:50 +00:00
Oli Scherer
c4efc25bfa Thread pattern types through the HIR 2024-04-08 12:00:07 +00:00
Oli Scherer
a9edbfda32 Stop exporting TypeckRootCtxt and FnCtxt.
While they have many convenient APIs, it is better to expose dedicated functions for them
2024-04-08 11:59:13 +00:00
Oli Scherer
c340e67dec Add pattern types to parser 2024-04-08 11:57:17 +00:00
Oli Scherer
fc27a91880 Add pattern types to ast 2024-04-08 11:54:22 +00:00
Philippe-Cholet
7a2678de7d Add invariant to VecDeque::pop_* that len < cap if pop successful
Similar to #114370 for VecDeque instead of Vec. It now uses `core::hint::assert_unchecked`.
2024-04-08 12:12:13 +02:00
bors
0e5f520788 Auto merge of #123577 - Urgau:prep-work-for-compiletest-check-cfg, r=oli-obk
Do some preparation work for compiletest check-cfg

This PR does several preparation work for having always-on check-cfg in compiletest.

In particular, this PR does two main things:
 - It unifies all the *always-false* cfgs under the `FALSE` cfg (as it seems to be the convention under `tests/ui`)
 - It also removes some useless conditions

This is done ahead of the introduction of the always-on check-cfg in compiletest to reduce the amount of changes in that follow-up work. I also think that this is useful even without that follow-up work.
2024-04-08 09:34:44 +00:00
bors
7a495cc13d Auto merge of #123616 - bzEq:fix-be-test, r=jhpratt
[Test] issue-122805.rs should limit to little endian target

In issue-122805.rs, codegen on big endian target is different from little endian target.
```llvm
%0 = load <8 x i16>, ptr %value, align 2
store <8 x i16> %0, ptr %_0, align 1
ret void
```
This is expected since the conversion is unnecessary on BE target for this case.
2024-04-08 04:16:16 +00:00
Kai Luo
d8d1e6ce21 Limited to little endian target 2024-04-08 11:11:11 +08:00
bors
f2c8013393 Auto merge of #123569 - c410-f3r:testsssssss, r=jieyouxu
Move some tests

r? `@petrochenkov`
2024-04-08 02:13:05 +00:00
bors
a2c72ce594 Auto merge of #123506 - RalfJung:miri-test-libstd, r=Mark-Simulacrum
check-aux: test core, alloc, std in Miri

Let's see if this works, and how long it takes.
2024-04-08 00:08:44 +00:00
Mark Rousskov
f946bf4f2e Remove debuginfo from rustc-demangle too
This is done for the same reason as the other dependencies in this list.
2024-04-07 19:19:11 -04:00
bors
f65f84feb0 Auto merge of #123597 - Gbd199:patch-1, r=jhpratt
Fix typo in library/core/src/iter/traits/iterator.rs
2024-04-07 22:04:40 +00:00
Caio
ab8994d93e Move tests 2024-04-07 17:38:07 -03:00
bors
9d5cdf75aa Auto merge of #123601 - jieyouxu:compiletest-run-rustfix-revisions, r=WaffleLapkin
compiletest: properly handle revisioned run-rustfix tests

Before this PR, if you have a revisioned `//@ run-rustfix` test like `//`@[foo]` run-rustfix`, you would run into an error saying crate name cannot contain `.` characters because the fixed test file trying to be compiled is named `<test-name>.<revision>.fixed`, from which `rustc` infers the crate name to be `<test-name>.<revision>` which is not a valid crate name.

This PR fixes the problem by constructing a synthetic crate name from `<test-name>.<revision>`, by

1. replacing all `-` with `_`, and
2. replacing all `.` with `__`

and pass that constructed crate name with `--crate-name` to rustc to compile the fixed file.

Fixes https://github.com/rust-lang/rust/issues/123596.
2024-04-07 18:22:55 +00:00
许杰友 Jieyou Xu (Joe)
de3857e553 tests/ui: remove workaround for broken revisioned run-rustfix test 2024-04-07 17:06:15 +00:00
许杰友 Jieyou Xu (Joe)
5dc276c0da compiletest: properly handle revisioned run-rustfix tests 2024-04-07 17:06:15 +00:00
Gabriel Dolberg
a1d4066e53
Fix typo in library/core/src/iter/traits/iterator.rs 2024-04-07 18:55:28 +03:00
BALAGANESH
8f6ebf608d Made changes in documentation 2024-04-07 15:07:25 +00:00
bors
e78913baef Auto merge of #123592 - matthiaskrgr:rollup-3k1pq8s, r=matthiaskrgr
Rollup of 2 pull requests

Successful merges:

 - #123584 (Emit an error when `rustc_doc_primitive` has an unknown value)
 - #123589 (sys_common::thread_local_key: make a note that this is not used on Windows)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-04-07 14:51:54 +00:00
Matthias Krüger
e5bdd7ebc1
Rollup merge of #123589 - RalfJung:nowin, r=ChrisDenton
sys_common::thread_local_key: make a note that this is not used on Windows

This just confused me for a while. I don't have the time to clean it up but I can at least leave a note for the next wary traveler.
2024-04-07 14:50:00 +02:00
Matthias Krüger
f64e97100c
Rollup merge of #123584 - tgross35:rustc_doc_primitive-usage-error, r=fmease
Emit an error when `rustc_doc_primitive` has an unknown value

Currently rustdoc silently does nothing. Change this to raise an error instead.
2024-04-07 14:49:59 +02:00
bors
4e431fad67 Auto merge of #123561 - saethlin:str-unchecked-sub-index, r=scottmcm
Use unchecked_sub in str indexing

https://github.com/rust-lang/rust/pull/108763 applied this logic to indexing for slices, but of course `str` has its own separate impl.

Found this by skimming over the codegen for https://github.com/oxidecomputer/hubris/; their dist builds enable overflow checks so the lack of `unchecked_sub` was producing an impossible-to-hit overflow check and also inhibiting some inlining.

r? scottmcm
2024-04-07 12:49:15 +00:00
bors
fc1a4c5cc9 Auto merge of #123221 - pacak:cache_emit, r=fmease,jieyouxu
Save/restore more items in cache with incremental compilation

Right now they don't play very well together, consider a simple example:

```
$ export RUSTFLAGS="--emit asm"
$ cargo new --lib foo
     Created library `foo` package
$ cargo build -q
$ touch src/lib.rs
$ cargo build
error: could not copy
  "/path/to/foo/target/debug/deps/foo-e307cc7fa7b6d64f.4qbzn9k8mosu50a5.rcgu.s"
  to "/path/to/foo/target/debug/deps/foo-e307cc7fa7b6d64f.s":
  No such file or directory (os error 2)
```

Touch triggers the rebuild, incremental compilation detects no changes (yay) and everything explodes while trying to copy files were they should go.

This pull request fixes it by copying and restoring more files in the incremental compilation cache

Fixes https://github.com/rust-lang/rust/issues/89149
Fixes https://github.com/rust-lang/rust/issues/88829

Related: https://internals.rust-lang.org/t/interaction-between-incremental-compilation-and-emit/20551
2024-04-07 10:46:50 +00:00
Ralf Jung
b1d1ad9f8c sys_common::thread_local_key: make a note that this is not used on Windows 2024-04-07 12:23:47 +02:00
bors
8f2c255ae0 Auto merge of #123585 - matthiaskrgr:rollup-dexaj7a, r=matthiaskrgr
Rollup of 4 pull requests

Successful merges:

 - #123410 (Relax framework linking test)
 - #123446 (Fix incorrect 'llvm_target' value used on watchOS target)
 - #123579 (add some more tests)
 - #123581 (Add `f16` and `f128` to rustdoc's `PrimitiveType`)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-04-07 08:44:19 +00:00
Ralf Jung
596908bb9a also test core+alloc on a 32bit big-endian target 2024-04-07 10:06:06 +02:00
Ralf Jung
d0346c50bc disable debug assertions to speed up the check-aux job 2024-04-07 10:06:06 +02:00
Ralf Jung
24089812db run some std tests on more targets 2024-04-07 10:06:06 +02:00
Ralf Jung
a986c0a100 make a doctest less slow in Miri 2024-04-07 10:06:06 +02:00
Ralf Jung
1242093da2 also test parts of std
requires disabling some tests that do not work
2024-04-07 10:05:57 +02:00
Ralf Jung
c0b564b767 disable benches in Miri 2024-04-07 09:58:10 +02:00
Ralf Jung
7b89445cc3 check-aux: test core and alloc in Miri 2024-04-07 09:58:10 +02:00
Trevor Gross
695514e8d8 rustdoc: error when rustc_doc_primitive has an unknown type
Currently rustdoc silently does nothing if it isn't aware of the
specified primitive type. Change this to raise an error instead.
2024-04-07 03:21:22 -04:00
Matthias Krüger
549d85d13f
Rollup merge of #123581 - tgross35:f16-f128-rustdoc-updates, r=fmease
Add `f16` and `f128` to rustdoc's `PrimitiveType`

Fix a few places where these primitives were missing from librustdoc. This should fix the CI failures from doc links in https://github.com/rust-lang/rust/pull/122470.
2024-04-07 09:17:16 +02:00
Matthias Krüger
bbc7807b42
Rollup merge of #123579 - matthiaskrgr:I_Love_Tests, r=jieyouxu
add some more tests

Fixes https://github.com/rust-lang/rust/issues/115806
Fixes https://github.com/rust-lang/rust/issues/116710
Fixes https://github.com/rust-lang/rust/issues/123145
Fixes https://github.com/rust-lang/rust/issues/105488
Fixes https://github.com/rust-lang/rust/issues/122488
Fixes https://github.com/rust-lang/rust/issues/123078
2024-04-07 09:17:15 +02:00
Matthias Krüger
dc387cf295
Rollup merge of #123446 - crazytonyli:fix-watchos-llvm-target, r=estebank
Fix incorrect 'llvm_target' value used on watchOS target

## Issue

`xcodebuild -create-xcframework` command doesn't recognize static libraries that are built on "arm64_32-apple-watchos" target.

Here are steps to reproduce the issue on a Mac:
1. Install nightly toolchain `nightly-2024-03-27`. Needs this specific version, because newer nightly versions are broken on watchos target.
1. Create an empty library: `mkdir watchos-lib && cd watchos-lib && cargo init --lib`.
1. Add configuration `lib.crate-type=["staticlib"]` to Cargo.toml.
1. Build the library: `cargo +nightly-2024-03-27 build --release -Zbuild-std --target arm64_32-apple-watchos`
1. Run `xcodebuild -create-xcframework` to put the static library into a xcframework, which results in an error:

```
$ xcodebuild -create-xcframework -library target/arm64_32-apple-watchos/release/libwatchos_lib.a -output test.xcframework
error: unable to determine the platform for the given binary '.../watchos-lib/target/arm64_32-apple-watchos/release/libwatchos_lib.a'; check your deployment version settings
```

## Fix

The root cause of this error is `xcodebuild` couldn't read `LC_BUILD_VERSION` from the static library to determine the library's target platform. And the reason it's missing is that an incorrect `llvm_target` value is used in `arm64_32-apple-watchos` target. The expected value is `<arch>-apple-watchos<major>.<minor>.0`, i.e. "arm64_32-apple-watchos8.0.0".

The [.../apple/mod.rs](43f4f2a3b1/compiler/rustc_target/src/spec/base/apple/mod.rs (L321)) file contains functions that construct such string. There is an existing function `watchos_sim_llvm_target` which returns llvm target value for watchOS simulator. But there is none for watchOS device. This PR adds that missing function to align watchOS with other Apple platform targets.

To verify the fix, you can simply build a toolchain on this PR branch and repeat the steps above using the built local toolchain to verify the `xcodebuild -create-xcframework` command can create a xcframework successfully.

Furthermore, you can verify `LC_BUILD_VERSION` contains correct info by using the simple shell script below to print `LC_BUILD_VERSION` of the static library that's built on watchos target:

```shell
bin=target/arm64_32-apple-watchos/release/libwatchos_lib.a
file=$(ar -t "$bin" | grep -E '\.o$' | head -n 1)
ar -x "$bin" "$file"
vtool -show-build-version "$file"
```

Here is an example output from my machine:

```
watchos_rust-495d6aaf3bccc08d.watchos_rust.35ba42bf9255ca9d-cgu.0.rcgu.o:
Load command 1
      cmd LC_BUILD_VERSION
  cmdsize 24
 platform WATCHOS
    minos 8.0
      sdk n/a
   ntools 0
```
2024-04-07 09:17:15 +02:00
Matthias Krüger
4eef6e313e
Rollup merge of #123410 - madsmtm:relax-framework-linking-test, r=fmease
Relax framework linking test

This test was introduced by myself in https://github.com/rust-lang/rust/pull/118644, but was over-specified in that it assumed the path of the linker was always `cc`, which [causes a test failure for Chromium](https://issues.chromium.org/issues/332562251).
2024-04-07 09:17:14 +02:00