235251 Commits

Author SHA1 Message Date
Guillaume Gomez
7a27acfdbb
Rollup merge of #113383 - joshtriplett:style-bugs, r=compiler-errors
style-guide: Add section on bugs, and resolving bugs
2023-09-19 20:23:18 +02:00
Ralf Jung
ea22adbabd adjust constValue::Slice to work for arbitrary slice types 2023-09-19 20:17:43 +02:00
Ralf Jung
028c78c6c7 explain mysterious addition in float minimum/maximum 2023-09-19 20:13:04 +02:00
bors
42f5828b01 Auto merge of #115627 - compiler-errors:icedump-no-std, r=m-ou-se
Don't modify libstd to dump rustc ICEs

Do a much simpler thing and just dump a `std::backtrace::Backtrace` to file.

r? `@estebank` `@oli-obk`

Fixes #115610
2023-09-19 16:56:25 +00:00
Martin Kröning
4241f942b6
chore(miri): bump env_logger to 0.10
This reduces the amount of dependencies pulling in atty.

```
    Removing env_logger v0.9.3
```

Signed-off-by: Martin Kröning <martin.kroening@eonerc.rwth-aachen.de>
2023-09-19 18:39:13 +02:00
Martin Kröning
7928c7e25d
chore(Cargo.lock): bump colored and tracing-tree
This reduces the amount of dependencies pulling in atty.

```
    Updating colored v2.0.0 -> v2.0.4
    Updating tracing-tree v0.2.3 -> v0.2.4
```

Signed-off-by: Martin Kröning <martin.kroening@eonerc.rwth-aachen.de>
2023-09-19 18:39:12 +02:00
Eduardo Sánchez Muñoz
c599761140 rustc_hir_analysis: add a helper to check function the signature mismatches
This function is now used to check `#[panic_handler]`, `start` lang item, `main`, `#[start]` and intrinsic functions.

The diagnosis produced are now closer to the ones produced by trait/impl method signature mismatch.
2023-09-19 18:15:23 +02:00
bors
59105177cc Auto merge of #3054 - Vanille-N:spurious-fail, r=RalfJung
Issue discovered in TB: spurious reads are not (yet) possible in a concurrent setting

We discovered a week ago that in general, the current model of TB does not allow spurious reads because although reads provably never invalidate other reads, they migh invalidate writes.

Consider the code
```rs
fn f1(x: &u8) {}
fn f2(y: &mut u8) -> &mut u8 { &mut *y }

let mut data = 0;
let _ = thread::spawn(|| {
    f1(&mut data)
};
let _ = thread::spawn(|| {
    let y = f2(&mut data);
    *y = 42;
});
```
of which one possible interleaving is
```rs
1: retag x (&, protect) // x: [P]Frozen
2: retag y (&mut, protect) // y: [P]Reserved, x: [P]Frozen
1: return f1 // x: [P]Frozen -> Frozen, y: [P]Reserved
2: return f2 // x: Frozen, y: [P]Reserved -> Reserved
2: write y // x: Disabled, y: Active
```
that does not have UB.

Assume enough barriers to force this specific interleaving, and consider that the compiler could choose to insert a spurious read throug `x` during the call to `f1` which would produce
```rs
1: retag x (&, protect) // x: [P]Frozen
2: retag y (&mut, protect) // y: [P]Reserved, x: [P]Frozen
1: spurious read x // x:  [P]Frozen, y: [P]Reserved -> [P]Frozen
1: return f1 // x: [P]Frozen -> Frozen, y: [P]Frozen
2: return f2 // x: Frozen, y: [P]Frozen -> Frozen
2: write y // UB
```
Thus the target of the optimization (with a spurious read) has UB when the source did not.

This is bad.

SB is not affected because the code would be UB as early as `retag y`, this happens because we're trying to be a bit more subtle than that, and because the effects of a foreign read on a protected `&mut` bleed outside of the boundaries of the protector. Fortunately we have a fix planned, but in the meantime here are some `#[should_panic]` exhaustive tests to illustrate the issue.

The error message printed by the `#[should_panic]` tests flags the present issue in slightly more general terms: it says that the sequence `retag x (&, protect); retag y (&mut, protect);` produces the configuration `C_source := x: [P]Frozen, x: [P]Reserved`, and that inserting a spurious read through `x` turns it into `C_target := x: [P]Frozen, y: [P]Reserved`.
It then says that `C_source` is distinguishable from `C_target`, which means that there exists a sequence of instructions applied to both that triggers UB in `C_target` but not in `C_source`.
It happens that one such sequence is `1: return f1; 2: return f2; 2: write y;` as shown above, but it is not the only one, as for example the interleaving `1: return f1; 2: write y;` is also problematic.
2023-09-19 15:46:28 +00:00
Neven Villani
3ca6c4916e
Issue of the current model: spurious reads are not possible
This occurs because in some interleavings, inserting
a spurious read turns a Reserved into Frozen.
We show here an exhaustive test (including arbitrary unknown
code in two different threads) that makes this issue
observable.
2023-09-19 17:31:53 +02:00
Guillaume Gomez
295ec09b63 Update tests for custom classes 2023-09-19 17:29:39 +02:00
Guillaume Gomez
6bed1c6061 Allow more characters in custom classes 2023-09-19 17:29:30 +02:00
bors
0692db1a90 Auto merge of #115865 - RalfJung:mir-mod, r=oli-obk
move things out of mir/mod.rs

This moves a bunch of things out of `mir/mod.rs`:
- all const-related stuff to a new file consts.rs
- all statement/place/operand-related stuff to a new file statement.rs
- all pretty-printing related stuff to pretty.rs

`mod.rs` started out with 3100 lines and ends up with 1600. :)

Also there was some pretty-printing stuff in terminator.rs, that also got moved to pretty.rs, and I reordered things in pretty.rs so that it can be grouped by functionality.

Only the commit "use pretty_print_const_value from MIR constant 'extra' printing" has any behavior changes; it resolves the issue of having a fancy and a very crude pretty-printer for `ConstValue`.

r? `@oli-obk`
2023-09-19 13:22:48 +00:00
Matthew Jasper
b49140295c Add more if let guard tests 2023-09-19 12:48:40 +00:00
Guillaume Gomez
88b070aa92 Return early in check_custom_code_classes check if the feature is enabled 2023-09-19 13:20:18 +02:00
Guillaume Gomez
494fdcd8ec Add new rustdoc-ui test for custom_code_classes_in_docs feature 2023-09-19 13:19:15 +02:00
bors
8769c26989 Auto merge of #115960 - GuillaumeGomez:rollup-8tky3qu, r=GuillaumeGomez
Rollup of 6 pull requests

Successful merges:

 - #112725 (rustdoc-search: add support for type parameters)
 - #114941 (Don't resolve generic impls that may be shadowed by dyn built-in impls)
 - #115625 (Explain HRTB + infer limitations of old solver)
 - #115839 (Bump libc to 0.2.148)
 - #115924 (Don't complain on a single non-exhaustive 1-ZST)
 - #115946 (panic when encountering an illegal cpumask in thread::available_parallelism)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-09-19 11:18:06 +00:00
Kriskras99
cdf25c904e
Replace 'mutex' with 'lock' in RwLock documentation
When copying the documentation for `clear_poison` from Mutex, not every occurence of 'mutex' was replaced with 'lock'.
2023-09-19 12:46:53 +02:00
msizanoen
4d4c13bbd6 tests/ui/abi: Enable repr(transparent) union ABI tests on RISC-V 2023-09-19 12:22:45 +02:00
msizanoen
751ecde064 rustc_target/riscv: Fix passing of transparent unions with only one non-ZST member
This ensures that `MaybeUninit<T>` has the same ABI as `T` when passed
through an `extern "C"` function.

Fixes https://github.com/rust-lang/rust/issues/115481.
2023-09-19 12:06:33 +02:00
cui fliter
0944860f35 fix mismatched symbols
Signed-off-by: cui fliter <imcusg@gmail.com>
2023-09-19 18:01:32 +08:00
Guillaume Gomez
57f1f91a9c
Rollup merge of #115946 - the8472:panic-on-sched_getaffinity-bug, r=Mark-Simulacrum
panic when encountering an illegal cpumask in thread::available_parallelism

Fixes #115868 by panicking instead of returning an invalid `NonZeroUsize`
2023-09-19 11:35:52 +02:00
Guillaume Gomez
f1edecfaab
Rollup merge of #115924 - compiler-errors:non-exhaustive-1-zst, r=RalfJung
Don't complain on a single non-exhaustive 1-ZST

r? RalfJung, though you mentioned being busy, so feel free to reassign.

This doesn't actually attempt to make the diagnostic better, so when we have two non-exhaustive 1-ZSTs in a struct, we still just point to one. 🤷

Fixes #115922
2023-09-19 11:35:51 +02:00
Guillaume Gomez
6cfc6a8705
Rollup merge of #115839 - Dirreke:bump-libc, r=dtolnay
Bump libc to 0.2.148
2023-09-19 11:35:51 +02:00
Guillaume Gomez
c452090597
Rollup merge of #115625 - compiler-errors:hrtb-infer-err, r=b-naber
Explain HRTB + infer limitations of old solver

Add a helpful message when we hit the limitation of the old trait solver where we don't properly normalize GATs with infer vars + bound vars, leading to too-eagerly reporting trait errors that would be later satisfied due to inference.
2023-09-19 11:35:50 +02:00
Guillaume Gomez
66b7bdf279
Rollup merge of #114941 - compiler-errors:inline-shadowed-by-dyn, r=lcnr
Don't resolve generic impls that may be shadowed by dyn built-in impls

**NOTE:** This is a hack. This is not trying to be a general fix for the issue that we've allowed overlapping built-in trait object impls and user-written impls for quite a long time, and traits like `Any` rely on this (#57893) -- this PR specifically aims to mitigate a new unsoundness that is uncovered by the MIR inliner (#114928) that interacts with this pre-existing issue.

Builtin `dyn Trait` impls may overlap with user-provided blanket impls (`impl<T: ?Sized> Trait for T`) in generic contexts. This leads to bugs when instances are resolved in polymorphic contexts, since we typically prefer object candidates over impl candidates.

This PR implements a (hacky) heuristic to `resolve_associated_item` to account for that unfortunate hole in the type system -- we now bail with ambiguity if we try to resolve a non-rigid instance whose self type is not known to be sized. This makes sure we can still inline instances like `impl<T: Sized> Trait for T`, which can never overlap with `dyn Trait`'s built-in impl, but we avoid inlining an impl that may be shadowed by a `dyn Trait`.

Fixes #114928
2023-09-19 11:35:50 +02:00
Guillaume Gomez
3f68468bc6
Rollup merge of #112725 - notriddle:notriddle/advanced-search, r=GuillaumeGomez
rustdoc-search: add support for type parameters

r? `@GuillaumeGomez`

## Preview

* https://notriddle.com/rustdoc-html-demo-4/advanced-search/rustdoc/read-documentation/search.html
* https://notriddle.com/rustdoc-html-demo-4/advanced-search/std/index.html?search=option%3Coption%3CT%3E%3E%20-%3E%20option%3CT%3E
* https://notriddle.com/rustdoc-html-demo-4/advanced-search/std/index.html?search=option%3CT%3E,%20E%20-%3E%20result%3CT,%20E%3E
* https://notriddle.com/rustdoc-html-demo-4/advanced-search/std/index.html?search=-%3E%20option%3CT%3E

## Description

When writing a type-driven search query in rustdoc, specifically one with more than one query element, non-existent types become generic parameters instead of auto-correcting (which is currently only done for single-element queries) or giving no result. You can also force a generic type parameter by writing `generic:T` (and can force it to not use a generic type parameter with something like `struct:T` or whatever, though if this happens it means the thing you're looking for doesn't exist and will give you no results).

There is no syntax provided for specifying type constraints for generic type parameters.

When you have a generic type parameter in a search query, it will only match up with generic type parameters in the actual function, not concrete types that match, not concrete types that implement a trait. It also strictly matches based on when they're the same or different, so `option<T>, option<U> -> option<U>` matches `Option::and`, but not `Option::or`. Similarly, `option<T>, option<T> -> option<T>` matches `Option::or`, but not `Option::and`.

## Motivation

This feature is motivated by the many "combinitor"-type functions found in generic libraries, such as Option, Future, Iterator, and Entry. These highly-generic functions have names that are almost completely arbitrary, and a type signature that tells you what it actually does.

This PR is a major step towards[^closure] being able to easily search for generic functions by their type signature instead of by name. Some examples of combinators that can be found using this PR (try them out in the preview):

* `option<option<T>> -> option<T>` returns Option::flatten
* `option<T> -> result<T>` returns Option::ok_or
* `option<result<T>> -> result<option<T>>` returns Option::transpose
* `entry<K, V>, FnOnce -> V` returns `Entry::or_insert_with` (and `or_insert_with_key`, since there's no way to specify the generics on FnOnce)

[^closure]:

    For this feature to be as useful as it ought to be, you should be able to search for *trait-associated types* and *closures*. This PR does not implement either of these: they are **Future possibilities**.

    Trait-associated types would allow queries like `option<T> -> iterator<item=T>` to return `Option::iter`. We should also allow `option<T> -> iterator<T>` to match the associated type version.

    Closures would make a good way to query for things like `Option::map`. Closure support needs associated types to be represented in the search index, since `FnOnce() -> i32` desugars to `FnOnce<Output=i32, ()>`, so associated trait types should be implemented first. Also, we'd want to expose an easy way to query closures without specifying which of the three traits you want.
2023-09-19 11:35:49 +02:00
Nikita Popov
531830cecd Update to LLVM 17.0.0
This rebases our LLVM fork to 17.0.0.

Fixes #115681.
2023-09-19 11:14:35 +02:00
Ralf Jung
d14e601661 comment on the difference between mir::ConstantKind::Unevaluated and mir::ConstantKind::Ty(ty::ConstKind::Unevaluated) 2023-09-19 11:11:03 +02:00
Ralf Jung
b30cefc775 move ConstValue into mir
this way we have mir::ConstValue and ty::ValTree as reasonably parallel
2023-09-19 11:11:02 +02:00
Ralf Jung
5a0a1ff0cd move ConstValue into mir
this way we have mir::ConstValue and ty::ValTree as reasonably parallel
2023-09-19 11:11:02 +02:00
Ralf Jung
be8f5f6e7f organize mir pretty.rs and move more things into it; move statement-related things out of mir/mod.rs 2023-09-19 11:06:32 +02:00
Ralf Jung
57444cf9f3 use pretty_print_const_value from MIR constant 'extra' printing 2023-09-19 11:06:32 +02:00
Ralf Jung
10a822be38 move some MIR const pretty-printing into pretty.rs 2023-09-19 11:06:32 +02:00
Ralf Jung
49f5b17cdb more MIR const types to separate file 2023-09-19 11:06:27 +02:00
bors
ae9c330629 Auto merge of #104101 - betrusted-io:xous-libstd-initial, r=bjorn3
Add initial libstd support for Xous

This patchset adds some minimal support to the tier-3 target `riscv32imac-unknown-xous-elf`. The following features are supported:

* alloc
* thread creation and joining
* thread sleeping
* thread_local
* panic_abort
* mutex
* condvar
* stdout

Additionally, internal support for the various Xous primitives surrounding IPC have been added as part of the Xous FFI. These may be exposed as part of `std::os::xous::ffi` in the future, however for now they are not public.

This represents the minimum viable product. A future patchset will add support for networking and filesystem support.
2023-09-19 07:38:20 +00:00
Michael Goulet
fd36553aa7 Don't complain on a single non-exhaustive 1-zst 2023-09-19 06:01:24 +00:00
bors
81cd774bd0 Auto merge of #3064 - rust-lang:rustup-2023-09-19, r=RalfJung
Automatic sync from rustc
2023-09-19 05:51:07 +00:00
Michael Goulet
a30ad3a5a6 Don't resolve generic instances if they may be shadowed by dyn 2023-09-19 05:42:23 +00:00
The Miri Conjob Bot
1e2813fa0f Merge from rustc 2023-09-19 05:32:09 +00:00
The Miri Conjob Bot
aa6d6ba6c5 Preparing for merge from rustc 2023-09-19 05:25:27 +00:00
Michael Goulet
976d377f7f Explain HRTB + infer limitations of old solver 2023-09-19 05:14:14 +00:00
Michael Goulet
55ce976e06 Failing test 2023-09-19 04:55:51 +00:00
bors
af78bae565 Auto merge of #115289 - compiler-errors:adjust-comments, r=estebank
Add some needed comments in `adjust_fulfillment_errors.rs`

r? `@estebank`
2023-09-19 03:52:48 +00:00
bors
19dd953540 Auto merge of #115644 - danakj:catalyst-asan, r=cjgillot,thomcc
Enable ASAN/LSAN/TSAN for *-apple-ios-macabi

The -macabi targets are iOS running on MacOS, and they use the runtime libraries for MacOS, thus they have the same sanitizers available as the *-apple-darwin targets.

This is based on the work of aacf3213b1.

Closes #113935.
2023-09-19 01:47:23 +00:00
bors
f3984ce5bb Auto merge of #115952 - matthiaskrgr:rollup-qzk8t4e, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #115869 (Avoid blessing cargo deps's source code in ui tests)
 - #115873 (Make `TyKind::Adt`'s `Debug` impl be more pretty)
 - #115879 (Migrate diagnostics in `hir_typeck/src/cast.rs`)
 - #115930 (coverage: Fix an unstable-sort inconsistency in coverage spans)
 - #115931 (Move mobile topbar title creation entirely into JS)
 - #115941 (Add myself to .mailmap)
 - #115943 (compiletest: Don't swallow some error messages.)
 - #115949 (Update browser-ui-test version)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-09-19 00:02:42 +00:00
Matthias Krüger
aa55d7d730
Rollup merge of #115949 - GuillaumeGomez:update-browser-ui-test, r=notriddle
Update browser-ui-test version

It includes the fix from `@notriddle` (https://github.com/GuillaumeGomez/browser-UI-test/pull/537).

r? `@notriddle`
2023-09-19 01:29:45 +02:00
Matthias Krüger
8c5fc204bd
Rollup merge of #115943 - ehuss:compiletest-errors, r=compiler-errors
compiletest: Don't swallow some error messages.

This updates some error handling in compiletest to display the underlying error rather than discarding it. There have been cases where the lack of error information makes it difficult to understand what went wrong.
2023-09-19 01:29:44 +02:00
Matthias Krüger
3ddad3773d
Rollup merge of #115941 - lnicola:lnicola-mailmap, r=Mark-Simulacrum
Add myself to .mailmap
2023-09-19 01:29:43 +02:00
Matthias Krüger
575e091b5c
Rollup merge of #115931 - GuillaumeGomez:remove-empty-h2, r=notriddle
Move mobile topbar title creation entirely into JS

I was looking at potential size improvements and saw that we had an empty `h2` tag for the mobile topbar title that was filled with JS. So at this point, I think it's fine to just completely generate it from JS, like that the w3c HTML validator will emit one less warning.

r? `@notriddle`
2023-09-19 01:29:43 +02:00
Matthias Krüger
3cf5a6beaa
Rollup merge of #115930 - Zalathar:spans-bug, r=compiler-errors
coverage: Fix an unstable-sort inconsistency in coverage spans

This code was calling `sort_unstable_by`, but failed to impose a total order on the initial spans. That resulted in unpredictable handling of closure spans, producing inconsistencies in the coverage maps and in user-visible coverage reports.

This PR fixes the problem by always sorting closure spans before otherwise-identical non-closure spans, and also switches to a stable sort in case the ordering is still not total.

---

In addition to the fix itself, this PR also contains a cleanup to the comparison function that I was working on when I discovered the bug.
2023-09-19 01:29:42 +02:00