Commit Graph

33480 Commits

Author SHA1 Message Date
Oli Scherer
bf5fc6e5d7 Remove some depgraph edges on the HIR by invoking the intrinsic query instead of checking the attribute 2024-03-04 16:13:51 +00:00
Oli Scherer
b3dcbc2931 Avoid some boolean argument footguns 2024-03-04 16:13:51 +00:00
Oli Scherer
1e57df1969 Add a scheme for moving away from extern "rust-intrinsic" entirely 2024-03-04 16:13:50 +00:00
Oli Scherer
f2612daf58 Return a struct from query intrinsic to be able to add another field in the next commit 2024-03-04 16:13:50 +00:00
Oli Scherer
aa2ae6b491 Add is_intrinsic helper 2024-03-04 16:13:50 +00:00
bors
7606c13961 Auto merge of #121964 - matthiaskrgr:rollup-rtcju5m, r=matthiaskrgr
Rollup of 3 pull requests

Successful merges:

 - #121130 (Suggest moving definition if non-found macro_rules! is defined later)
 - #121912 (Properly deal with GATs when looking for method chains to point at)
 - #121927 (Add a proper `with_no_queries` to printing)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-03-04 08:07:34 +00:00
Matthias Krüger
de95c39a78
Rollup merge of #121927 - Zoxc:print-no-query, r=estebank
Add a proper `with_no_queries` to printing
2024-03-04 07:57:57 +01:00
Matthias Krüger
cd9e5b5f43
Rollup merge of #121912 - fmease:diag-method-chains-gat, r=compiler-errors,estebank
Properly deal with GATs when looking for method chains to point at

Fixes #121898.

~~While it prevents an ICE and the structured suggestion is correct, the method chain diagnostic notes are weird / useless / incorrect judging by a quick look. I guess I should improve that in this PR.~~ Sufficiently taken care of.

r? estebank or compiler-errors (#105332, #105674).
2024-03-04 07:57:56 +01:00
Matthias Krüger
c620ae5be9
Rollup merge of #121130 - chenyukang:yukang-fix-121061-macro-later, r=matthiaskrgr
Suggest moving definition if non-found macro_rules! is defined later

Fixes #121061
2024-03-04 07:57:56 +01:00
bors
f7cb53e54b Auto merge of #121900 - chenyukang:yukang-fix-121425-repr-pack-error, r=compiler-errors
Fix misleading message in struct repr alignment and packed

Fixes #121425

By the way, fix the spans for the argument in the second commit.
2024-03-04 05:32:26 +00:00
bors
89b78304e8 Auto merge of #121955 - matthiaskrgr:rollup-1i3lo0j, r=matthiaskrgr
Rollup of 5 pull requests

Successful merges:

 - #121248 (Move some tests)
 - #121528 (Consider middle segments of paths in `unused_qualifications`)
 - #121749 (Don't lint on executable crates with `non_snake_case` names)
 - #121935 (library/ptr: mention that ptr::without_provenance is equivalent to deriving from the null ptr)
 - #121945 (Run some ui-fulldeps tests on stage 1 again)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-03-04 00:37:20 +00:00
bors
70aa0b86c0 Auto merge of #121665 - erikdesjardins:ptradd, r=nikic
Always generate GEP i8 / ptradd for struct offsets

This implements #98615, and goes a bit further to remove `struct_gep` entirely.

Upstream LLVM is in the beginning stages of [migrating to `ptradd`](https://discourse.llvm.org/t/rfc-replacing-getelementptr-with-ptradd/68699). LLVM 19 will [canonicalize](https://github.com/llvm/llvm-project/pull/68882) all constant-offset GEPs to i8, which has roughly the same effect as this change.

Fixes #121719.

Split out from #121577.

r? `@nikic`
2024-03-03 22:21:53 +00:00
Matthias Krüger
10234fc246
Rollup merge of #121749 - jieyouxu:issue-45127-fix, r=petrochenkov
Don't lint on executable crates with `non_snake_case` names

Revives #111130, cc `@GilShoshan94.`
Closes #45127.
2024-03-03 22:56:13 +01:00
Matthias Krüger
ed6d17523a
Rollup merge of #121528 - Alexendoo:unused_qualifications, r=petrochenkov
Consider middle segments of paths in `unused_qualifications`

Currently `unused_qualifications` looks at the last segment of a path to see if it can be trimmed, this PR extends the check to the middle segments also

```rust
// currently linted
use std::env::args();
std::env::args(); // Removes `std::env::`
```
```rust
// newly linted
use std::env;
std::env::args(); // Removes `std::`
```

Paths with generics in them are now linted as long as the part being trimmed is before any generic args, e.g. it will now suggest trimming `std::vec::` from `std::vec::Vec<usize>`

Paths with any segments that are from an expansion are no longer linted

Fixes #100979
Fixes #96698
2024-03-03 22:56:13 +01:00
John Kåre Alsaker
6fb4ac64ec Add a proper with_no_queries to printing 2024-03-03 21:12:04 +01:00
bors
516b6162a2 Auto merge of #121763 - clubby789:llvm-old-comment, r=cjgillot
Update outdated LLVM comment

The first path no longer exists, but the second does.
2024-03-03 19:59:03 +00:00
Alex Macleod
4ea9f72c72 Consider middle segments of paths in unused_qualifications 2024-03-03 19:14:28 +00:00
bors
26907374b9 Auto merge of #121937 - GuillaumeGomez:rollup-9684vg3, r=GuillaumeGomez
Rollup of 3 pull requests

Successful merges:

 - #121917 (Add new `pattern_complexity` attribute to add possibility to limit and check recursion in pattern matching)
 - #121933 (Add missing get_name for wasm::thread.)
 - #121934 (rustc_log: expose tracing-tree "wraparound" in an env var)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-03-03 14:01:47 +00:00
Guillaume Gomez
e634a0a51b
Rollup merge of #121934 - RalfJung:tree-wraparound, r=oli-obk
rustc_log: expose tracing-tree "wraparound" in an env var

This would be RUSTC_LOG_WRAPTREE, but I am open to other names.

r? `@oli-obk`
2024-03-03 14:07:44 +01:00
Guillaume Gomez
7d8f74f8b2
Rollup merge of #121917 - GuillaumeGomez:pattern-complexity_limit.rs, r=Nadrieril
Add new `pattern_complexity` attribute to add possibility to limit and check recursion in pattern matching

Needed for https://github.com/rust-lang/rust-analyzer/issues/9528.

This PR adds a new attribute only available when running rust testsuite called `pattern_complexity` which allows to set the maximum recursion for the pattern matching. It is quite useful to ensure the complexity doesn't grow, like in `tests/ui/pattern/usefulness/issue-118437-exponential-time-on-diagonal-match.rs`.

r? `@Nadrieril`
2024-03-03 14:07:43 +01:00
Guillaume Gomez
be31b6b6cd Add new pattern_complexity attribute to add possibility to limit and check recursion in pattern matching 2024-03-03 13:10:15 +01:00
bors
9e73597e5a Auto merge of #121903 - Nilstrieb:rename-qnx-file, r=WaffleLapkin
Remove underscore from QNX target file name

For consistency with the other QNX targets and the actual target names.
2024-03-03 11:34:21 +00:00
Ralf Jung
90162ea7b1 rustc_log: expose tracing-tree "wraparound" in an env var 2024-03-03 12:33:26 +01:00
yukang
53dba7fb55 fix spans of arguments in diagnostic 2024-03-03 10:48:40 +08:00
León Orell Valerian Liehr
6035e8735a
Properly deal with GATs when looking for method chains to point at 2024-03-03 00:42:03 +01:00
bors
0decdac390 Auto merge of #121914 - Nadrieril:rollup-ol98ncg, r=Nadrieril
Rollup of 5 pull requests

Successful merges:

 - #120761 (Add initial support for DataFlowSanitizer)
 - #121622 (Preserve same vtable pointer when cloning raw waker, to fix Waker::will_wake)
 - #121716 (match lowering: Lower bindings in a predictable order)
 - #121731 (Now that inlining, mir validation and const eval all use reveal-all, we won't be constraining hidden types here anymore)
 - #121841 (`f16` and `f128` step 2: intrinsics)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-03-02 22:59:19 +00:00
Guillaume Boisseau
4c65eef269
Rollup merge of #121841 - tgross35:f16-f128-step2-intrinsics, r=compiler-errors
`f16` and `f128` step 2: intrinsics

Continuation of https://github.com/rust-lang/rust/pull/121728, another portion of https://github.com/rust-lang/rust/pull/114607.

This PR adds `f16` and `f128` intrinsics, and hooks them up to both HIR and LLVM. This is all still unexposed to the frontend, which will probably be the next step. Also update itanium mangling per `@rcvalle's` in https://github.com/rust-lang/rust/pull/121728/files#r1506570300, and fix a typo from step 1.

Once these types are usable in code, I will add the codegen tests from #114607 (codegen is passing on that branch)

This does add more `unimplemented!`s to Clippy, but I still don't think we can do better until library support is added.

r? `@compiler-errors`
cc `@Nilstrieb`
`@rustbot` label +T-compiler +F-f16_and_f128
2024-03-02 20:13:24 +01:00
Guillaume Boisseau
200019c199
Rollup merge of #121731 - oli-obk:eager_opaque_checks, r=compiler-errors
Now that inlining, mir validation and const eval all use reveal-all, we won't be constraining hidden types here anymore

r? `@compiler-errors`

one bubble down, two more to go

the test is unrelated, just something I noticed would be good to test in both the old solver and the new.
2024-03-02 20:13:23 +01:00
Guillaume Boisseau
30976fbe2b
Rollup merge of #121716 - Nadrieril:simple-binding-order, r=matthewjasper
match lowering: Lower bindings in a predictable order

After the recent refactorings, we can now lower bindings in a truly predictable order. The order in https://github.com/rust-lang/rust/pull/120214 was an improvement but not very clear. With this PR, we lower bindings from left to right, with the special case that `x @ pat` is traversed as `pat @ x` (i.e. `x` is lowered after any bindings in `pat`).

This description only applies in the absence of or-patterns. Or-patterns make everything complicated, because the binding place depends on the subpattern. Until I have a better idea I leave them to be handled in whatever weird order arises from today's code.

r? `@matthewjasper`
2024-03-02 20:13:23 +01:00
Guillaume Boisseau
8653c09087
Rollup merge of #120761 - rcvalle:rust-dfsan, r=nikic
Add initial support for DataFlowSanitizer

Adds initial support for DataFlowSanitizer to the Rust compiler. It currently supports `-Zsanitizer-dataflow-abilist`. Additional options for it can be passed to LLVM command line argument processor via LLVM arguments using `llvm-args` codegen option (e.g., `-Cllvm-args=-dfsan-combine-pointer-labels-on-load=false`).
2024-03-02 20:13:22 +01:00
Matthias Krüger
fcf58059c2
Rollup merge of #121895 - matthiaskrgr:devec, r=fee1-dead
avoid collecting into vecs in some places
2024-03-02 16:53:17 +01:00
Matthias Krüger
7bacfced95
Rollup merge of #121892 - Zalathar:expr-kind-let, r=Nadrieril
The ordinary lowering of `thir::ExprKind::Let` is unreachable

After desugaring, `let` expressions should only appear inside `if` expressions or `match` guards, possibly nested within a let-chain. In both cases they are specifically handled by the lowerings of those expressions, so this case is currently unreachable.

---

Context: https://rust-lang.zulipchat.com/#narrow/stream/182449-t-compiler.2Fhelp/topic/Lowering.20of.20.60thir.3A.3AExprKind.3A.3ALet.60.20is.20unreachable

My conclusions are partly based on the observation that stubbing out this match arm doesn't cause any test failures. So either this really is unreachable, or it can be reached in some obscure circumstances that our test suite doesn't cover.

If we end up needing this code (or something like it) for an implementation of https://github.com/rust-lang/rfcs/pull/3573, it should be easy enough to pull it back out of version control history.

I looked into having the `if`/`match` lowerings call back into `expr_into_dest`, but from what I can tell that won't work well, because there are extra scoping considerations that require some awareness of the enclosing if/match.

r? ```@Nadrieril```
2024-03-02 16:53:16 +01:00
Nilstrieb
8ca9b8dbf7 Remove underscore from QNX target file name
For consistency with the other QNX targets and the actual target names.
2024-03-02 16:50:03 +01:00
yukang
5a5c6dfb33 Fix misleading message when using a named constant as a struct alignment/pack 2024-03-02 23:15:39 +08:00
Matthias Krüger
7a48987006 avoid collecting into vecs in some places 2024-03-02 14:18:47 +01:00
bors
5257aee7dd Auto merge of #121890 - matthiaskrgr:rollup-mv26uwt, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - #109263 (fix typo in documentation for std::fs::Permissions)
 - #120684 (Update E0716.md for clarity)
 - #121715 (match lowering: pre-simplify or-patterns too)
 - #121739 (Display short types for unimplemented trait)
 - #121815 (Move `gather_comments`.)
 - #121835 (Move `HandleStore` into `server.rs`.)
 - #121847 (Remove hidden use of Global)
 - #121861 (Use the guaranteed precision of a couple of float functions in docs)
 - #121875 ( Account for unmet T: !Copy in E0277 message)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-03-02 11:21:44 +00:00
Zalathar
972d8daf47 The ordinary lowering of thir::ExprKind::Let is unreachable
After desugaring, `let` expressions should only appear inside `if` expressions
or `match` guards, possibly nested within a let-chain. In both cases they are
specifically handled by the lowerings of those expressions, so this case is
currently unreachable.
2024-03-02 20:49:29 +11:00
Matthias Krüger
07bd4590fb
Rollup merge of #121875 - estebank:e0277-drive-by, r=compiler-errors
Account for unmet T: !Copy in E0277 message

```
error[E0277]: the trait bound `T: !Copy` is not satisfied
  --> $DIR/simple.rs:10:16
   |
LL |     not_copy::<T>();
   |                ^ the trait bound `T: !Copy` is not satisfied
```
instead of the current

```
error[E0277]: the trait bound `T: !Copy` is not satisfied
  --> $DIR/simple.rs:10:16
   |
LL |     not_copy::<T>();
   |                ^ the trait `!Copy` is not implemented for `T`
```
2024-03-02 10:09:38 +01:00
Matthias Krüger
9b2644030a
Rollup merge of #121815 - nnethercote:mv-gather_comments, r=est31
Move `gather_comments`.

To the module where it is used, so it doesn't have to be `pub`.

r? ```@est31```
2024-03-02 10:09:36 +01:00
Matthias Krüger
3432d1b087
Rollup merge of #121739 - jieyouxu:loooong-typename, r=estebank
Display short types for unimplemented trait

Shortens unimplemented trait diagnostics. Now shows:

```
error[E0277]: `Option<Option<Option<...>>>` doesn't implement `std::fmt::Display`
  --> $DIR/on_unimplemented_long_types.rs:4:17
   |
LL |   pub fn foo() -> impl std::fmt::Display {
   |                   ^^^^^^^^^^^^^^^^^^^^^^ `Option<Option<Option<...>>>` cannot be formatted with the default formatter
LL |
LL | /     Some(Some(Some(Some(Some(Some(Some(Some(Some(S...
LL | |         Some(Some(Some(Some(Some(Some(Some(Some(So...
LL | |             Some(Some(Some(Some(Some(Some(Some(Som...
LL | |                 Some(Some(Some(Some(Some(Some(Some...
...  |
LL | |         ))))))))))),
LL | |     )))))))))))
   | |_______________- return type was inferred to be `Option<Option<Option<...>>>` here
   |
   = help: the trait `std::fmt::Display` is not implemented for `Option<Option<Option<...>>>`
   = note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0277`.
```

I'm not 100% sure if this is desirable, or if we should just let the long types remain long. This is also kinda a short-term bandaid solution. The real long term solution is to properly migrate `rustc_trait_selection`'s error reporting to use translatable diagnostics and then properly handle type name printing.

Fixes #121687.
2024-03-02 10:09:36 +01:00
Matthias Krüger
b2c933a1b9
Rollup merge of #121715 - Nadrieril:testcase-or, r=matthewjasper
match lowering: pre-simplify or-patterns too

This is the final part of my work to simplify match pairs early: now we do it for or-patterns too. This makes it possible to collect fake borrows separately from the main match lowering algorithm. That'll enable more simplifications of or-pattern handling.

Note: I was tempted to have `Candidate` contain a `FlatPat`, but there are so many places that use `candidate.match_pairs` etc directly that I chose not to.

r? `@matthewjasper`
2024-03-02 10:09:35 +01:00
Matthias Krüger
1c724ee110
Rollup merge of #120684 - carschandler:patch-1, r=nnethercote
Update E0716.md for clarity

When reading through this, I got slightly hung up thinking the `let` it was referring to was the `let tmp` on line 25, which was confusing considering the comment states that the temporary is freed at the end of the block. I think adding this clarification could potentially help some beginners like myself without being overly verbose.
2024-03-02 10:09:35 +01:00
bors
2e3581bca9 Auto merge of #121864 - compiler-errors:type-relating-variances, r=aliemjay
Don't grab variances in `TypeRelating` relation if we're invariant

Since `Invariant.xform(var) = Invariant` always, so just copy what the generalizer relation does.

Fixes #110106
2024-03-02 08:52:26 +00:00
bors
4cdd20584c Auto merge of #121657 - estebank:issue-119665, r=davidtwco
Detect more cases of `=` to `:` typo

When a `Local` is fully parsed, but not followed by a `;`, keep the `:` span arround and mention it. If the type could continue being parsed as an expression, suggest replacing the `:` with a `=`.

```
error: expected one of `!`, `+`, `->`, `::`, `;`, or `=`, found `.`
 --> file.rs:2:32
  |
2 |     let _: std::env::temp_dir().join("foo");
  |          -                     ^ expected one of `!`, `+`, `->`, `::`, `;`, or `=`
  |          |
  |          while parsing the type for `_`
  |          help: use `=` if you meant to assign
```

Fix #119665.
2024-03-02 05:03:46 +00:00
Ramon de C Valle
dee4e02102 Add initial support for DataFlowSanitizer
Adds initial support for DataFlowSanitizer to the Rust compiler. It
currently supports `-Zsanitizer-dataflow-abilist`. Additional options
for it can be passed to LLVM command line argument processor via LLVM
arguments using `llvm-args` codegen option (e.g.,
`-Cllvm-args=-dfsan-combine-pointer-labels-on-load=false`).
2024-03-01 18:50:40 -08:00
Esteban Küber
7f97dfe700 Account for unmet T: !Copy in E0277 message 2024-03-02 01:53:37 +00:00
carschandler
50ff36239a
Update E0716.md
Clearer wording
2024-03-01 17:31:02 -06:00
Matthias Krüger
63e916e26c
Rollup merge of #121824 - celinval:smir-scalar, r=oli-obk
Implement missing ABI structures in StableMIR

Add implementations for Scalar, Primitive and WrappingRange for StableMIR.

FYI, I thought about reusing the `rustc_abi` module, since it is designed to not necessarily depend on the `rustc` internals, but the maintenance burden to maintain this crate in crates.io doesn't seem worth it at this point.

Fixes https://github.com/rust-lang/project-stable-mir/issues/58
2024-03-01 22:38:50 +01:00
Matthias Krüger
06ca0de91c
Rollup merge of #121803 - estebank:dont-mention-type-error-e0277, r=compiler-errors
Never say "`Trait` is implemented for `{type error}`"

When a trait bound error occurs, we look for alternative types that would have made the bound succeed. For some reason `{type error}` sometimes would appear as a type that would do so.

We now remove `{type error}` from the list in every case to avoid nonsensical `note`s.
2024-03-01 22:38:49 +01:00
Matthias Krüger
0d2205f9a6
Rollup merge of #121750 - Nadrieril:switchkind-if, r=matthewjasper
match lowering: Separate the `bool` case from other integers in `TestKind`

`TestKind::SwitchInt` had a special case for `bool` essentially everywhere it's used, so I made `TestKind::If` to handle the bool case on its own.

r? `@matthewjasper`
2024-03-01 22:38:49 +01:00