Commit Graph

38211 Commits

Author SHA1 Message Date
Trevor Gross
36ea06827b
Rollup merge of #126699 - Bryanskiy:delegation-coercion, r=compiler-errors
Delegation: support coercion for target expression

(solves https://github.com/rust-lang/rust/issues/118212#issuecomment-2160723092)

The implementation consist of 2 parts. Firstly, method call is generated instead of fully qualified call in AST->HIR lowering if there were no generic arguments or `Qpath` were provided. These restrictions are imposed due to the loss of information after desugaring. For example in

```rust
trait Trait {
  fn foo(&self) {}
}

reuse <u8 as Trait>::foo;
```

We would like to generate such a code:

```rust
fn foo<u8: Trait>(x: &u8) {
  x.foo(x)
}
```

however, the signature is inherited during HIR analysis where `u8` was discarded.

Then, we probe the single pre-resolved method.

P.S In the future, we would like to avoid restrictions on the callee path by `Self` autoref/autoderef in fully qualified calls, but at the moment it didn't work out.

r? `@petrochenkov`
2024-07-16 16:15:14 -05:00
Trevor Gross
63f239c89f
Rollup merge of #124033 - bjorn3:ar_archive_writer_0_3_0, r=davidtwco
Sync ar_archive_writer to LLVM 18.1.3

From LLVM 15.0.0-rc3. This adds support for COFF archives containing Arm64EC object files and has various fixes for AIX big archive files.
2024-07-16 16:15:13 -05:00
Folkert
09b620d179
stop running code samples in the error code .md 2024-07-16 21:28:09 +02:00
Folkert
1a7960603f
another attempt at fixing the examples in the error codes .md 2024-07-16 20:36:55 +02:00
Folkert
c7ff46c971
move cmse ABI validation into its own module
Co-authored-by: Tamme Dittrich <tamme@tweedegolf.com>
2024-07-16 18:45:03 +02:00
Folkert
36d23713fb
make function pub in error_codes markdown file
the error is only generated for functions that are actually codegen'd
2024-07-16 18:38:42 +02:00
Matthias Krüger
ab4cc440dd
Rollup merge of #127818 - oli-obk:ast_validation_simplifications, r=petrochenkov
Various ast validation simplifications

Changes pulled out of https://github.com/rust-lang/rust/pull/127524

These are needed to make ast validation a mutable visitor, as we can't keep immutable references to the AST around in that case. But I think they are simplifying things in general and can stand on their own
2024-07-16 18:09:14 +02:00
Matthias Krüger
862852fd33
Rollup merge of #127817 - oli-obk:mut_visitor_fix, r=petrochenkov
Fix a bunch of sites that were walking instead of visiting, making it impossible for visitor impls to look at these values

This doesn't affects anything right now, but a `MutVisitor` impl could be surprised by this.

The reason this doesn't affect anything is that no one overrrides `visit_lifetime` or `visit_param_bounds` currently.
2024-07-16 18:09:13 +02:00
Matthias Krüger
8fd1df8c5f
Rollup merge of #127808 - oli-obk:tainting_visitors2, r=lcnr,nnethercote
Make ErrorGuaranteed discoverable outside types, consts, and lifetimes

types like `PatKind` could contain `ErrorGuaranteed`, but not return them via `tainted_by_errors` or `error_reported` (see https://github.com/rust-lang/rust/pull/127687#discussion_r1679027883). Now this happens, but it's a bit fragile as you can see with the `TypeSuperVisitable for Ty` impl.

We will catch any problems around Ty, Region or Const at runtime with an assert, and everything using derives will not have such issues, as it will just invoke the `TypeVisitable for ErrorGuaranteed` impl
2024-07-16 18:09:12 +02:00
Matthias Krüger
73028fe483
Rollup merge of #127730 - compiler-errors:ed-2024-unsafe, r=petrochenkov
Fix and enforce `unsafe_op_in_unsafe_fn` in compiler

In preparation for edition 2024, this PR previews the fallout of enabling the `unsafe_op_in_unsafe_fn` lint in the compiler, since it's defaulting to warn in the new edition (#112038).

The major annoyance comes primarily from the `rustc_codegen_llvm` module, where there's a ton of unsafe calls. I tended to wrap individual calls to unsafe fns in `unsafe {}`, but there a handful of places I chose to just wrap several calls in an `unsafe {}` block just because it would've been excessive to wrap each call individually.

This doesn't enable the lint for the standard library, since I'm not totally certain what T-libs prefers w/ this lint.
2024-07-16 18:09:10 +02:00
Matthias Krüger
7409a5281d
Rollup merge of #127707 - Zalathar:expand-until, r=Nadrieril
match lowering: Use an iterator to find `expand_until`

A small cleanup that I noticed while looking at #127164.

This makes it easier to see that the split point is always the index after the found item, or the whole list if no stopping point was found.

r? `@Nadrieril`
2024-07-16 18:09:09 +02:00
Michael Goulet
d0a1851ec2 Deny keyword lifetimes pre-expansion 2024-07-16 12:06:25 -04:00
Oli Scherer
117ff0a4fd Fix a bunch of sites that were walking instead of visiting, making it impossible for visitor impls to look at these values 2024-07-16 15:50:36 +00:00
Oli Scherer
d9f9592924 Remove a boilerplaty abstraction 2024-07-16 15:46:45 +00:00
Oli Scherer
b879e29864 Remove a needless borrow 2024-07-16 15:46:45 +00:00
Oli Scherer
9a4c1058fa Just store a span instead of the whole item 2024-07-16 15:44:17 +00:00
Oli Scherer
6ce78bea03 Update method name to reflect changes to its internals 2024-07-16 15:34:35 +00:00
Bryanskiy
7ee97f93da Delegation: support coercion for target expression 2024-07-16 18:03:15 +03:00
Oli Scherer
53f7f8ce5c Remove an unnecessary impl 2024-07-16 14:15:44 +00:00
yukang
48ddf5e323 Fix the issue of invalid suggestion for a reference of iterator 2024-07-16 22:01:55 +08:00
Folkert
50ba821e12
add rust error message for CMSE stack spill
when the `C-cmse-nonsecure-call` ABI is used, arguments and return values must be passed via registers. Failing to do so (i.e. spilling to the stack) causes an LLVM error down the line, but now rustc will properly emit an error a bit earlier in the chain
2024-07-16 15:58:33 +02:00
Oli Scherer
fb98fbb759 Make ErrorGuaranteed discoverable outside types, consts, and lifetimes 2024-07-16 11:31:04 +00:00
Trevor Gross
1abed9fa06
Rollup merge of #127780 - compiler-errors:zip-args, r=jieyouxu
Make sure trait def ids match before zipping args in `note_function_argument_obligation`

Fixes #126416
Fixes #127745

Didn't add both tests b/c I felt like it was unnecessary.
2024-07-16 02:02:25 -05:00
Trevor Gross
47600074fe
Rollup merge of #127709 - Zalathar:pair-mod, r=Nadrieril
match lowering: Move `MatchPair` tree creation to its own module

This makes it easier to see that `MatchPair::new` has only one non-recursive caller, because the recursive callers are all in this module. No functional changes.

---

I have used `git diff --color-moved` to verify that the moved code is identical to the old code, except for reduced visibility on the helper methods.
2024-07-16 02:02:24 -05:00
Trevor Gross
12fd2f94b3
Rollup merge of #120990 - chenyukang:yukang-fix-120327-dbg, r=oli-obk
Suggest a borrow when using dbg

Fixes #120327
r? ````@estebank````
2024-07-16 02:02:23 -05:00
Nicholas Nethercote
9c4f3dbd06 Remove references to maybe_whole_expr.
It was removed in #126571.
2024-07-16 16:40:35 +10:00
Nicholas Nethercote
8cb6bc3b5a Fix a comment. 2024-07-16 16:39:19 +10:00
Nicholas Nethercote
96b39f1204 Inline and remove Parser::parse_expr_dot_or_call_with_.
It only has two call sites, and it extremely similar to
`Parser::parse_expr_dot_or_call_with`, in both name and behaviour. The
only difference is the latter has an `attrs` argument and an
`ensure_sufficient_stack` call. We can pass in an empty `attrs` as
necessary, as is already done at some `parse_expr_dot_or_call_with` call
sites.
2024-07-16 16:16:38 +10:00
Nicholas Nethercote
96cc9c99b2 Inline and remove Parser::parse_and_disallow_postfix_after_cast.
It has a single call site. Removing it removes the need for an
`ExprKind` check. The commit also clarifies the relevant comment.
2024-07-16 16:09:36 +10:00
Nicholas Nethercote
d247489ac2 Reorder Parser::parse_expr_dot_or_call_with arguments.
Put `attrs` before `e0` because that matches the order in the source
code, where outer attributes appear before expressions.
2024-07-16 15:54:34 +10:00
Nicholas Nethercote
48cdfc388d Inline Parser::parse_item_common_.
It has a single call site, it isn't that big, and its name is
confusingly similar to `Parser::parse_item_common`.
2024-07-16 15:07:42 +10:00
Nicholas Nethercote
2f305ff460 Remove an unnecessary ?. 2024-07-16 15:03:25 +10:00
Michael Goulet
28503d69ac Fix unsafe_op_in_unsafe_fn in compiler 2024-07-16 00:02:44 -04:00
Michael Goulet
71eb49c318 fmt 2024-07-16 00:02:36 -04:00
bors
5c84886056 Auto merge of #127638 - adwinwhite:cache_string, r=oli-obk
Add cache for `allocate_str`

Best effort cache for string allocation in const eval.

Fixes [rust-lang/miri#3470](https://github.com/rust-lang/miri/issues/3470).
2024-07-16 02:41:07 +00:00
Zalathar
e37b92ffd8 Use an iterator to find expand_until
This makes it easier to see that the split point is always the index after the
found item, or the whole list if no stopping point was found.
2024-07-16 11:51:52 +10:00
Michael Goulet
e86fbcfd70 Move rustc_infer::infer::error_reporting to rustc_infer::error_reporting::infer 2024-07-15 20:16:12 -04:00
Mohammad Omidvar
9b80250abb Move compiler_builtin check to the use case 2024-07-15 23:43:52 +00:00
bors
cae4a84146 Auto merge of #127629 - tesuji:suggest-option-ref-unwrap_or, r=estebank
Suggest using `map_or` when `Option<&T>::unwrap_or where T: Deref` fails

Fix #127545

Split from https://github.com/rust-lang/rust/pull/127596#pullrequestreview-2171898588
2024-07-15 23:36:22 +00:00
Michael Goulet
841b30f63e Make sure trait def ids match before zipping args in note_function_argument_obligation 2024-07-15 17:53:22 -04:00
Mohammad Omidvar
14430e66be Use the hook on tcx instead of the local function 2024-07-15 19:58:44 +00:00
Mohammad Omidvar
0d508bb0cd Introduce and provide a hook for should_codegen_locally 2024-07-15 19:54:47 +00:00
Matthias Krüger
e5d65e46ed
Rollup merge of #127758 - Zalathar:expression-used, r=oli-obk
coverage: Restrict `ExpressionUsed` simplification to `Code` mappings

In the future, branch and MC/DC mappings might have expressions that don't correspond to any single point in the control-flow graph. That makes it trickier to keep track of which expressions should expect an `ExpressionUsed` node.

We therefore sidestep that complexity by only performing `ExpressionUsed` simplification for expressions associated directly with ordinary `Code` mappings.

(This simplification step is inherited from the original coverage implementation, which only supported `Code` mappings anyway, so there's no particular reason to extend it to other kinds of mappings unless we specifically choose to.)

Relevant to:
- #124154
- #126677
- #124278

```@rustbot``` label +A-code-coverage
2024-07-15 21:11:50 +02:00
Matthias Krüger
3f13562acd
Rollup merge of #127729 - compiler-errors:ed-2024-gen, r=oli-obk
Stop using the `gen` identifier in the compiler

In preparation for edition 2024, this PR previews the fallout of removing usages of `gen` since it's being reserved as a keyword.

There are two notable changes here:
1. Had to rename `fn gen(..)` in gen/kill analysis to `gen_`. Not certain there's a better name than that.
2. There are (false?[^1]) positives in `rustc_macros` when using synstructure, which uses `gen impl` to mark an implementation. We could suppress this in a one-off way, or perhaps just ignore `gen` in macros altogether, since if an identifier ends up in expanded code then it'll get properly denied anyways.

Not relevant to the compiler, but it's gonna be really annoying to change `rand`'s `gen` fn in the library and miri...

[^1]: I haven't looked at the synstructure proc macro code itself so I'm not certain if it'll start to fail when converted to ed2024 (or, e.g., when syn starts parsing `gen` as a kw).
2024-07-15 21:11:49 +02:00
Matthias Krüger
2b82729b91
Rollup merge of #127407 - estebank:parser-suggestions, r=oli-obk
Make parse error suggestions verbose and fix spans

Go over all structured parser suggestions and make them verbose style.

When suggesting to add or remove delimiters, turn them into multiple suggestion parts.
2024-07-15 21:11:48 +02:00
Matthias Krüger
78529d9841
Rollup merge of #124921 - RalfJung:offset-from-same-addr, r=oli-obk
offset_from: always allow pointers to point to the same address

This PR implements the last remaining part of the t-opsem consensus in https://github.com/rust-lang/unsafe-code-guidelines/issues/472: always permits offset_from when both pointers have the same address, no matter how they are computed. This is required to achieve *provenance monotonicity*.

Tracking issue: https://github.com/rust-lang/rust/issues/117945

### What is provenance monotonicity and why does it matter?

Provenance monotonicity is the property that adding arbitrary provenance to any no-provenance pointer must never make the program UB. More specifically, in the program state, data in memory is stored as a sequence of [abstract bytes](https://rust-lang.github.io/unsafe-code-guidelines/glossary.html#abstract-byte), where each byte can optionally carry provenance. When a pointer is stored in memory, all of the bytes it is stored in carry that provenance. Provenance monotonicity means: if we take some byte that does not have provenance, and give it some arbitrary provenance, then that cannot change program behavior or introduce UB into a UB-free program.

We care about provenance monotonicity because we want to allow the optimizer to remove provenance-stripping operations. Removing a provenance-stripping operation effectively means the program after the optimization has provenance where the program before the optimization did not -- since the provenance removal does not happen in the optimized program. IOW, the compiler transformation added provenance to previously provenance-free bytes. This is exactly what provenance monotonicity lets us do.

We care about removing provenance-stripping operations because `*ptr = *ptr` is, in general, (likely) a provenance-stripping operation. Specifically, consider `ptr: *mut usize` (or any integer type), and imagine the data at `*ptr` is actually a pointer (i.e., we are type-punning between pointers and integers). Then `*ptr` on the right-hand side evaluates to the data in memory *without* any provenance (because [integers do not have provenance](https://rust-lang.github.io/rfcs/3559-rust-has-provenance.html#integers-do-not-have-provenance)). Storing that back to `*ptr` means that the abstract bytes `ptr` points to are the same as before, except their provenance is now gone. This makes  `*ptr = *ptr`  a provenance-stripping operation  (Here we assume `*ptr` is fully initialized. If it is not initialized, evaluating `*ptr` to a value is UB, so removing `*ptr = *ptr` is trivially correct.)

### What does `offset_from` have to do with provenance monotonicity?

With `ptr = without_provenance(N)`, `ptr.offset_from(ptr)` is always well-defined and returns 0. By provenance monotonicity, I can now add provenance to the two arguments of `offset_from` and it must still be well-defined. Crucially, I can add *different* provenance to the two arguments, and it must still be well-defined. In other words, this must always be allowed: `ptr1.with_addr(N).offset_from(ptr2.with_addr(N))` (and it returns 0). But the current spec for `offset_from` says that the two pointers must either both be derived from an integer or both be derived from the same allocation, which is not in general true for arbitrary `ptr1`, `ptr2`.

To obtain provenance monotonicity, this PR hence changes the spec for offset_from to say that if both pointers have the same address, the function is always well-defined.

### What further consequences does this have?

It means the compiler can no longer transform `end2 = begin.offset(end.offset_from(begin))` into `end2 = end`. However, it can still be transformed into `end2 = begin.with_addr(end.addr())`, which later parts of the backend (when provenance has been erased) can trivially turn into `end2 = end`.

The only alternative I am aware of is a fundamentally different handling of zero-sized accesses, where a "no provenance" pointer is not allowed to do zero-sized accesses and instead we have a special provenance that indicates "may be used for zero-sized accesses (and nothing else)". `offset` and `offset_from` would then always be UB on a "no provenance" pointer, and permit zero-sized offsets on a "zero-sized provenance" pointer. This achieves provenance monotonicity. That is, however, a breaking change as it contradicts what we landed in https://github.com/rust-lang/rust/pull/117329. It's also a whole bunch of extra UB, which doesn't seem worth it just to achieve that transformation.

### What about the backend?

LLVM currently doesn't have an intrinsic for pointer difference, so we anyway cast to integer and subtract there. That's never UB so it is compatible with any relaxation we may want to apply.

If LLVM gets a `ptrsub` in the future, then plausibly it will be consistent with `ptradd` and [consider two equal pointers to be inbounds](https://github.com/rust-lang/rust/pull/124921#issuecomment-2205795829).
2024-07-15 21:11:47 +02:00
yukang
317952677a Suggest a borrow when using dbg 2024-07-16 02:48:47 +08:00
Michael Goulet
172cf9bef3 Fix unsoundness when associated types dont actually come from supertraits 2024-07-15 14:17:32 -04:00
Michael Goulet
8edf9b8084 Item bounds can reference self projections and still be object safe 2024-07-15 14:16:48 -04:00
Michael Goulet
7e1c4afb1d The rustc crate feature is called jemalloc 2024-07-15 13:01:20 -04:00
Michael Goulet
324d2e51ee Fix feature gating on rustc_index to not use implicit features 2024-07-15 12:44:24 -04:00
Michael Goulet
247ad3385c Use dep: for crate dependencies 2024-07-15 12:40:10 -04:00
Lzu Tao
bdc9df2478 Use multipart_suggestion to avoid place holder in span_to_snippet
CO-AUTHORED-BY: Esteban Küber <esteban@kuber.com.ar>
2024-07-15 12:54:00 +00:00
Lzu Tao
9c3c278b54 Add support for `Result<&T, _>' 2024-07-15 12:54:00 +00:00
Zalathar
d4f1f92426 coverage: Restrict ExpressionUsed simplification to Code mappings
In the future, branch and MC/DC mappings might have expressions that don't
correspond to any single point in the control-flow graph. That makes it
trickier to keep track of which expressions should expect an `ExpressionUsed`
node.

We therefore sidestep that complexity by only performing `ExpressionUsed`
simplification for expressions associated directly with ordinary `Code`
mappings.
2024-07-15 20:54:28 +10:00
Zalathar
741ed01646 coverage: Store a copy of num_bcbs in ExtractedMappings
This makes it possible to allocate per-BCB data structures without needing
access to the whole graph.
2024-07-15 20:37:14 +10:00
bors
adeb79d3f5 Auto merge of #127265 - harmou01:dev/harmou01/target-spec-metadata, r=Nilstrieb
Fill out target-spec metadata for all targets

**What does this PR try to resolve?**

This PR completes the target-spec metadata fields for all targets. This is required for a corresponding Cargo PR which adds a check for whether a target supports building the standard library when the `-Zbuild-std=std` flag is passed ([see this issue](https://github.com/rust-lang/wg-cargo-std-aware/issues/87). This functionality in Cargo is reliant on the output of `--print=target-spec-json`.

**How should we test and review this PR?**

Check that a given target-spec metadata has been updated with:
```
$ ./x.py build library/std
$ build/host/stage1/bin/rustc --print=target-spec-json --target <target_name> -Zunstable-options
```

**Additional Information**

A few things to note:
* Where a targets 'std' or 'host tools' support is listed as '?' in the rust docs, these are left as 'None' with this PR. The corresponding changes in cargo will only reject an attempt to build std if the 'std' field is 'Some(false)'. In the case it is 'None', cargo will continue trying to build
* There's no rush for this to be merged. I understand that the format for this is not finalised yet.
* Related: #120745
2024-07-15 08:37:39 +00:00
bors
8b72d7a9d7 Auto merge of #127718 - cjgillot:find_field, r=compiler-errors
find_field does not need to be a query.

The current implementation is quadratic in the number of nested fields.

r? `@davidtwco` as you reviewed https://github.com/rust-lang/rust/pull/115367
Fixes https://github.com/rust-lang/rust/issues/121755
2024-07-14 23:35:45 +00:00
Matthias Krüger
79000d2a8f
Rollup merge of #127630 - compiler-errors:type-ascription, r=chenyukang
Remove lang feature for type ascription (since it's a lib feature now)

It's not necessary since it's a library feature now, via the type ascription macro. We can't (and shouldn't) register it as a removed feature since I think that would give "this feature has been removed" errors even for people using the macro (well, I'm pretty sure, though I didn't check).

r? `@Nilstrieb`
2024-07-14 20:24:59 +02:00
Matthias Krüger
5d1f9e21cf
Rollup merge of #127587 - compiler-errors:all-features-at-once, r=Nilstrieb
Report usage of lib features in ast validation

No idea why it was split between ast validation for lang features and a later pass for lang features.

r? `@Nilstrieb`
2024-07-14 20:24:58 +02:00
Matthias Krüger
febe4423c1
Rollup merge of #127273 - nnethercote:fix-DebugParser, r=workingjubilee
Fix `DebugParser`.

I tried using this and it didn't work at all. `prev_token` is never eof, so the accumulator is always false, which means the `then_some` always returns `None`, which means `scan` always returns `None`, and `tokens` always ends up an empty vec. I'm not sure how this code was supposed to work.

(An aside: I find `Iterator::scan` to be a pretty wretched function, that produces code which is very hard to understand. Probably why this is just one of two uses of it in the entire compiler.)

This commit changes it to a simpler imperative style that produces a valid `tokens` vec.

r? `@workingjubilee`
2024-07-14 20:24:58 +02:00
Michael Goulet
f08c43afc7 Suppress some fallout from gen in synstructure 2024-07-14 14:22:11 -04:00
Michael Goulet
dc20733913 Stop using the gen keyword in the compiler 2024-07-14 14:01:01 -04:00
Adwin White
e595f3d13f Add cache for allocate_str 2024-07-14 22:11:46 +08:00
Camille GILLOT
b494d98b18 find_field does not need to be a query. 2024-07-14 13:25:25 +00:00
bors
88fa119c77 Auto merge of #127670 - compiler-errors:no-type-length-limit, r=jackh726
Gate the type length limit check behind a nightly flag

Effectively disables the type length limit by introducing a `-Zenforce-type-length-limit` which defaults to **`false`**, since making the length limit actually be enforced ended up having a worse fallout than expected. We still keep the code around, but the type length limit attr is now a noop (except for its usage in some diagnostics code?).

r? `@lcnr` -- up to you to decide what team consensus we need here since this reverses an FCP decision.

Reopens #125460 (if we decide to reopen it or keep it closed)
Effectively reverses the decision FCP'd in #125507
Closes #127346
2024-07-14 12:44:07 +00:00
Gurinder Singh
e13eb37eeb Fix malformed suggestion for repeated maybe unsized bounds 2024-07-14 17:46:25 +05:30
bors
a241cf1c49 Auto merge of #127713 - matthiaskrgr:rollup-zxlyexf, r=matthiaskrgr
Rollup of 5 pull requests

Successful merges:

 - #127083 (Add release notes for 1.80)
 - #127322 (handle ci-rustc incompatible options during config parse)
 - #127697 (use std for file mtime and atime modifications)
 - #127704 (Fix minor typos in std::process doc on Win argv)
 - #127710 (clarify the meaning of the version number for accepted/removed features)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-07-14 10:22:01 +00:00
Matthias Krüger
82f13e7215
Rollup merge of #127710 - RalfJung:features, r=compiler-errors
clarify the meaning of the version number for accepted/removed features

For accepted features this is pretty clear, we even use the version number in the warning that says "feature has been stabilized, please remove feature gate".

For removed features we are inconsistent. [This PR](8cece636b2 (diff-a82bdbaaa3c79096a30755dce8896aaf2885128a7f3f3a290072b767f05b6095)) set the version to when it got removed, but [here](https://github.com/rust-lang/rust/pull/116958/files#diff-1ff08f89ad7e972538827e989fa63732c5918b4d0216ccd921de08698d6e18ca) they just got copied over so the version says when the feature was originally added. As far as I can tell, this version number is not actually used anywhere in user-visible diagnostics.
2024-07-14 10:05:22 +02:00
bors
0ffbddd09e Auto merge of #127087 - cjgillot:small-map, r=oli-obk
Only track mentioned places for jump threading

This PR aims to reduce the state space size in jump threading and dataflow const-prop opts.

The current implementation walks the types of all locals, and creates a place for each possible projection. This can easily lead to a large number of places and tracked values, most being useless to the actual pass.

With this PR, we instead collect places that appear syntactically in the MIR (first commit). However, this is not sufficient (second commit), and we miss places that we could track in aggregate assignments. The third commit tracks such assignments to mirror place projections, see the inline comment.

This is complementary to https://github.com/rust-lang/rust/pull/127036

r? `@oli-obk`
2024-07-14 08:01:21 +00:00
Ralf Jung
2dd5369eda clarify the meaning of the version number for accepted/removed features 2024-07-14 08:18:03 +02:00
Zalathar
f7508f8816 Improve internal docs for MatchPair 2024-07-14 15:01:02 +10:00
Zalathar
ce86b2ae96 Move MatchPair tree creation to its own module
This makes it easier to see that `MatchPair::new` has only one non-recursive
caller, because the recursive callers are all in this module.
2024-07-14 15:00:57 +10:00
long-long-float
332b41dbce Use ordinal number in argument error
Fix error message

Fix tests

Format
2024-07-14 13:50:09 +09:00
Jubilee
125343e7ab
Rollup merge of #127558 - nnethercote:more-Attribute-cleanups, r=petrochenkov
More attribute cleanups

A follow-up to #127308.

r? ```@petrochenkov```
2024-07-13 20:19:46 -07:00
Jubilee
1c8ea14272
Rollup merge of #127477 - nnethercote:tweak-inner_attr_ranges, r=petrochenkov
Clear `inner_attr_ranges` regularly.

There's a comment saying we don't do it for performance reasons, but it doesn't actually affect performance.

The commit also tweaks the control flow, to make clearer that two code paths are mutually exclusive.

r? ````@petrochenkov````
2024-07-13 20:19:46 -07:00
Jubilee
1d59d22ac1
Rollup merge of #127434 - onur-ozkan:use-bootstrap-instead-of-rustbuild, r=Mark-Simulacrum
use "bootstrap" instead of "rustbuild" in comments and docs

Let's stick with the single name "bootstrap" to refer to the bootstrap project to avoid confusion. This should make it clearer, especially for new contributors.
2024-07-13 20:19:45 -07:00
bjorn3
6ff363f0ff Merge commit '659243d85c7489412bd0faa1c068d904a6042941' into sync_cg_clif-2024-07-13 2024-07-13 18:39:03 +00:00
Camille GILLOT
7ac7f135e3 Propagate places through assignments. 2024-07-13 12:02:10 +00:00
Camille GILLOT
76f5bc6a9f Create mapped places upon seeing them in the body. 2024-07-13 11:54:25 +00:00
Nicholas Nethercote
aa0e8e1475 Fix DebugParser.
It currently doesn't work at all. This commit changes it to a simpler
imperative style that produces a valid `tokens` vec.

(An aside: I find `Iterator::scan` to be a pretty wretched function,
that produces code which is very hard to understand. Probably why this
is just one of two uses of it in the entire compiler.)
2024-07-13 16:42:00 +10:00
Nicholas Nethercote
cf2dfb2ced Add a test for Parser::debug_lookahead.
That method is currently badly broken, and the test output reflects
this. The obtained tokens list is always empty, except in the case where
we go two `bump`s past the final token, whereupon it will produce as
many `Eof` tokens as asked for.
2024-07-13 15:55:40 +10:00
Jacob Pratt
cb1ccc1842
Rollup merge of #127654 - nikic:llvm-ndebug-fix, r=cuviper
Fix incorrect NDEBUG handling in LLVM bindings

We currently compile our LLVM bindings using `-DNDEBUG` if debuginfo for LLVM is disabled. However, `NDEBUG` doesn't have any relation to debuginfo, it controls whether assertions are enabled.

Split the LLVM_NDEBUG environment variable into two, so that assertions and debuginfo are controlled independently.

After this change, `LLVMRustDIBuilderInsertDeclareAtEnd` triggers an assertion failure on LLVM 19 due to an incorrect cast. Fix it by removing the unused return value entirely.

r? `@cuviper`
2024-07-13 00:24:35 -04:00
Nicholas Nethercote
69f6145ad8 Change look from a macro to a function.
Using `#[track_caller]` works if the assertion is moved outside of the
closure.
2024-07-13 12:02:12 +10:00
Michael Goulet
938ed369ad Gate the type length limit check behind a nightly flag 2024-07-12 21:16:09 -04:00
bors
336e89bd15 Auto merge of #127665 - workingjubilee:rollup-g90yr21, r=workingjubilee
Rollup of 11 pull requests

Successful merges:

 - #126502 (Ignore allocation bytes in some mir-opt tests)
 - #126922 (add lint for inline asm labels that look like binary)
 - #127209 (Added the `xop` target-feature and the `xop_target_feature` feature gate)
 - #127310 (Fix import suggestion ice)
 - #127338 (Migrate `extra-filename-with-temp-outputs` and `issue-85019-moved-src-dir` `run-make` tests to rmake)
 - #127381 (Migrate `issue-83045`, `rustc-macro-dep-files` and `env-dep-info` `run-make` tests to rmake)
 - #127535 (Fire unsafe_code lint on unsafe extern blocks)
 - #127619 (Suggest using precise capturing for hidden type that captures region)
 - #127631 (Remove `fully_normalize`)
 - #127632 (Implement `precise_capturing` support for rustdoc)
 - #127660 (Rename the internal `const_strlen` to just `strlen`)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-07-12 22:59:30 +00:00
Jubilee
c0d949909f
Rollup merge of #127632 - compiler-errors:precise-capturing-rustdoc, r=fmease
Implement `precise_capturing` support for rustdoc

Implements rustdoc (+json) support for local (i.e. non-cross-crate-inlined) RPITs with `use<...>` precise capturing syntax.

Tests kinda suck. They're really hard to write 😰

r? `@fmease` or re-roll if you're too busy!
also cc `@aDotInTheVoid` for the json side

Tracking:
* https://github.com/rust-lang/rust/issues/127228#issuecomment-2201443216 (not fully fixed for cross-crate-inlined opaques)
* https://github.com/rust-lang/rust/issues/123432
2024-07-12 13:47:10 -07:00
Jubilee
4bfc10617a
Rollup merge of #127631 - compiler-errors:yeet-fully-norm, r=lcnr
Remove `fully_normalize`

Yeet this function and replace it w/ some `ObligationCtxt` instead. It wasn't called very often anyways.

r? lcnr
2024-07-12 13:47:09 -07:00
Jubilee
20cf4eb3b0
Rollup merge of #127619 - compiler-errors:precise-capturing-better-sugg, r=oli-obk
Suggest using precise capturing for hidden type that captures region

Adjusts the "add `+ '_`" suggestion for opaques to instead suggest adding or reusing the `+ use<>` in the opaque.

r? oli-obk or please re-roll if you're busy!
2024-07-12 13:47:09 -07:00
Jubilee
2e0591b1e9
Rollup merge of #127535 - spastorino:unsafe_code-unsafe_extern_blocks, r=oli-obk
Fire unsafe_code lint on unsafe extern blocks

Fixes #126738
2024-07-12 13:47:08 -07:00
Jubilee
afb2fbf692
Rollup merge of #127310 - chenyukang:yukang-fix-suggest-import-ice, r=estebank
Fix import suggestion ice

Fixes #127302

#127302 only crash in edition 2015
#120074 can only reproduced in edition 2021
so I added revisions in test file.
2024-07-12 13:47:07 -07:00
Jubilee
a6a7129827
Rollup merge of #127209 - sayantn:xop, r=Amanieu
Added the `xop` target-feature and the `xop_target_feature` feature gate

This is an effort towards #127208. This adds the `xop` target feature gated by `xop_target_feature`.
2024-07-12 13:47:06 -07:00
Jubilee
fc0136e4f4
Rollup merge of #126922 - asquared31415:asm_binary_label, r=estebank
add lint for inline asm labels that look like binary

fixes #94426

Due to a bug/feature in LLVM, labels composed of only the digits `0` and `1` can sometimes be confused with binary literals, even if a binary literal would not be valid in that position.

This PR adds detection for such labels and also as a drive-by change, adds a note to cases such as `asm!(include_str!("file"))` that the label that it found came from an expansion of a macro, it wasn't found in the source code.

I expect this PR to upset some people that were using labels `0:` or `1:` without issue because they never hit the case where LLVM got it wrong, but adding a heuristic to the lint to prevent this is not feasible - it would involve writing a whole assembly parser for every target that we have assembly support for.

[zulip discussion](https://rust-lang.zulipchat.com/#narrow/stream/238009-t-compiler.2Fmeetings/topic/.5Bweekly.5D.202024-06-20/near/445870628)

r? ``@estebank``
2024-07-12 13:47:05 -07:00
Jubilee
5d56572f06
Rollup merge of #126502 - cuviper:dump-mir-exclude-alloc-bytes, r=estebank
Ignore allocation bytes in some mir-opt tests

This adds `rustc -Zdump-mir-exclude-alloc-bytes` to skip writing allocation bytes in MIR dumps, and applies it to tests that were failing on s390x due to its big-endian byte order.

Fixes #126261
2024-07-12 13:47:05 -07:00
bors
c6727fc9b5 Auto merge of #123351 - beetrees:x86-ret-snan-rust, r=nikic,workingjubilee
Ensure floats are returned losslessly by the Rust ABI on 32-bit x86

Solves #115567 for the (default) `"Rust"` ABI. When compiling for 32-bit x86, this PR changes the `"Rust"` ABI to return floats indirectly instead of in x87 registers (with the exception of single `f32`s, which this PR returns in general purpose registers as they are small enough to fit in one). No change is made to the `"C"` ABI as that ABI requires x87 register usage and therefore will need a different solution.
2024-07-12 20:36:43 +00:00
Nikita Popov
8dfd3a455d Remove LLVMRustDIBuilderInsertDeclareAtEnd return value
The return value changed from an Instruction to a DbgRecord in
LLVM 19. As we don't actually use the result, drop the return
value entirely to support both.
2024-07-12 22:15:10 +02:00
Nikita Popov
776b0adaaf Fix incorrect NDEBUG handling in LLVM bindings
We currently compile our LLVM bindings using `-DNDEBUG` if
debuginfo for LLVM is disabled. However, `NDEBUG` doesn't have
any relation to debuginfo, it controls whether assertions are
enabled.

Rename the environment variable to `LLVM_ASSERTIONS` and drive
it using the `llvm_assertions` option. Also drop the explicit
`debug(false)` call, as cc already sets this up using the
cargo `DEBUG` environment variable.
2024-07-12 22:13:56 +02:00
Esteban Küber
cf09cba20c When finding item gated behind a cfg flat, point at it
Previously we would only mention that the item was gated out, and opportunisitically mention the feature flag name when possible. We now point to the place where the item was gated, which can be behind layers of macro indirection, or in different modules.

```
error[E0433]: failed to resolve: could not find `doesnt_exist` in `inner`
  --> $DIR/diagnostics-cross-crate.rs:18:23
   |
LL |     cfged_out::inner::doesnt_exist::hello();
   |                       ^^^^^^^^^^^^ could not find `doesnt_exist` in `inner`
   |
note: found an item that was configured out
  --> $DIR/auxiliary/cfged_out.rs:6:13
   |
LL |     pub mod doesnt_exist {
   |             ^^^^^^^^^^^^
note: the item is gated here
  --> $DIR/auxiliary/cfged_out.rs:5:5
   |
LL |     #[cfg(FALSE)]
   |     ^^^^^^^^^^^^^
```
2024-07-12 18:52:52 +00:00
Pavel Grigorenko
59f88d3db9 Silence clippy::derived_hash_with_manual_eq for now 2024-07-12 21:52:29 +03:00
Pavel Grigorenko
168096f663 rustc_type_ir: derivative -> derive-where 2024-07-12 21:52:04 +03:00
Pavel Grigorenko
70a11c7ba9 rustc_next_trait_solver: derivative -> derive-where 2024-07-12 21:48:16 +03:00
Pavel Grigorenko
35ba700d5e rustc_span: derivative -> derive-where 2024-07-12 21:37:43 +03:00
Pavel Grigorenko
fd16a0efeb rustc_middle: derivative -> derive-where 2024-07-12 21:33:02 +03:00
sayantn
1fd0311eab Added the xop target feature and xop_target_feature gate 2024-07-12 23:30:22 +05:30
bors
62c068feea Auto merge of #127636 - nnethercote:fix-Parser-look_ahead, r=oli-obk
Fix `Parser::look_ahead`

`Parser::look_ahead` has a slow but simple general case, and a fast special case that is hit most of the time. But the special case is buggy and behaves differently to the general case. There are also no unit tests. This PR fixes all of this, resulting in a `Parser::look_ahead` that is equally fast, slightly simpler, more correct, and better tested.

r? `@davidtwco`
2024-07-12 17:28:21 +00:00
bors
5d76a13bbe Auto merge of #127653 - matthiaskrgr:rollup-72bqgvp, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #124980 (Generalize `fn allocator` for Rc/Arc.)
 - #126639 (Add AMX target-features and `x86_amx_intrinsics` feature flag)
 - #126827 (Use pidfd_spawn for faster process spawning when a PidFd is requested)
 - #127433 (Stabilize const_cstr_from_ptr (CStr::from_ptr, CStr::count_bytes))
 - #127552 (remove unnecessary `git` usages)
 - #127613 (Update dist-riscv64-linux to binutils 2.40)
 - #127627 (generalize search graph to enable fuzzing)
 - #127648 (Lower timeout of CI jobs to 4 hours)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-07-12 14:55:25 +00:00
Matthias Krüger
526da2366a
Rollup merge of #127627 - lcnr:rustc_search_graph, r=compiler-errors
generalize search graph to enable fuzzing

I do not believe it to be feasible to correctly implement the search graph without fuzzing. This PR enables this by requiring a fuzzer to only implement three new traits:
- `Cx`: implemented by all `I: Interner`
- `ProofTreeBuilder`: implemented by `struct ProofTreeBuilder<D>` for all `D: SolverDelegate`
- `Delegate`: implemented for a new `struct SearchGraphDelegate<D>` for all `D: SolverDelegate`

It also moves the evaluation cache implementation into `rustc_type_ir`, requiring `Interner` to provide methods to create and access arbitrary `WithDepNode<T>` and to provide mutable access to a given `GlobalCache`. It otherwise does not change the API surface for users of the shared library.

This change should not impact behavior in any way.

r? ``@compiler-errors``
2024-07-12 14:38:00 +02:00
Matthias Krüger
18152d72a4
Rollup merge of #126639 - sayantn:amx, r=Amanieu
Add AMX target-features and `x86_amx_intrinsics` feature flag

This is an effort towards #126622. This adds support for all 5 target-features for `AMX`, and introduces the feature flag `x86_amx_intrinsics`, which would gate these target-features and the yet-to-be-implemented amx intrinsics in stdarch.
2024-07-12 14:37:57 +02:00
bors
05eac57ef6 Auto merge of #127479 - Urgau:rustc-stable-hash, r=michaelwoerister
Use rustc-stable-hash in the compiler

Following https://github.com/rust-lang/compiler-team/issues/755 and the release of the crate on crates.io, let's now use it in the compiler and remove the old implementation.

cc `@michaelwoerister`
r? ghost
2024-07-12 12:34:31 +00:00
lcnr
15f770b143 enable fuzzing of SearchGraph
fully move it into `rustc_type_ir` and make it
independent of `Interner`.
2024-07-12 06:30:19 -04:00
Michael Goulet
843f5dd93b Add rustdoc support for use<> in (local) RPITs 2024-07-12 05:24:51 -04:00
Lzu Tao
5e1cabe982 Add suggestion to use Option::map_or over erroneous Option::unwrap_or 2024-07-12 08:43:28 +00:00
bors
b286722878 Auto merge of #127635 - matthiaskrgr:rollup-foopajr, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #127164 (match lowering: Clarify the main loop of the algorithm)
 - #127422 (as_simd: fix doc comment to be in line with align_to)
 - #127596 (More suggestion for converting `Option<&Vec<T>>` to `Option<&[T]>`)
 - #127607 (compiletest: Better error message for bad `normalize-*` headers)
 - #127622 (Mark `builtin_syntax` as internal)
 - #127625 (Revert accidental comment deletion)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-07-12 03:40:38 +00:00
Nicholas Nethercote
100f3fd133 Add a new special case to Parser::look_ahead.
This new special case is simpler than the old special case because it
only is used when `dist == 1`. But that's still enough to cover ~98% of
cases. This results in equivalent performance to the old special case,
and identical behaviour as the general case.
2024-07-12 13:35:24 +10:00
Nicholas Nethercote
ebe1305b1e Remove the bogus special case from Parser::look_ahead.
The general case at the bottom of `look_ahead` is slow, because it
clones the token cursor. Above it there is a special case for
performance that is hit most of the time and avoids the cloning.
Unfortunately, its behaviour differs from the general case in two ways.

- When within a pair of delimiters, if you look any distance past the
  closing delimiter you get the closing delimiter instead of what comes
  after the closing delimiter.

- It uses `tree_cursor.look_ahead(dist - 1)` which totally confuses
  tokens with token trees. This means that only the first token in a
  token tree will be seen. E.g. in a sequence like `{ a }` the `a` and
  `}` will be skipped over. Bad!

It's likely that these differences weren't noticed before now because
the use of `look_ahead` in the parser is limited to small distances and
relatively few contexts.

Removing the special case causes slowdowns up of to 2% on a range of
benchmarks. The next commit will add a new, correct special case to
regain that lost performance.
2024-07-12 13:33:38 +10:00
Nicholas Nethercote
dad95578b0 Add unit tests for Parser::look_ahead.
It's currently buggy, so some of the test results are surprising, as
described in the `FIXME` comments. The bugs will be fixed in subsequent
commits.
2024-07-12 13:30:00 +10:00
Esteban Küber
71f16bdb32 Make ; suggestions inline 2024-07-12 03:22:32 +00:00
Esteban Küber
b6f518877f fix unused binding 2024-07-12 03:04:06 +00:00
Esteban Küber
377d14be88 More accurate incorrect use of await suggestion 2024-07-12 03:02:58 +00:00
Esteban Küber
b5f94c61f7 Use more accurate span for : to :: suggestion 2024-07-12 03:02:58 +00:00
Esteban Küber
c2b3287483 Make impl and ! removal suggestion short 2024-07-12 03:02:57 +00:00
Esteban Küber
692bc344d5 Make parse error suggestions verbose and fix spans
Go over all structured parser suggestions and make them verbose style.

When suggesting to add or remove delimiters, turn them into multiple suggestion parts.
2024-07-12 03:02:57 +00:00
sayantn
ec05c4ea3f Add the feature gate and target-features 2024-07-11 19:00:49 -07:00
Matthias Krüger
c2b7842555
Rollup merge of #127625 - SkiFire13:revert-comment-deletion, r=workingjubilee
Revert accidental comment deletion

This reverts an accidental comment deletion made in #113128

See also https://github.com/rust-lang/rust/pull/113128#discussion_r1674614882
2024-07-12 03:43:36 +02:00
Matthias Krüger
ca576eae4e
Rollup merge of #127622 - compiler-errors:builtin-internal, r=lqd
Mark `builtin_syntax` as internal

Tracking issue literally says:

> There will never be a general stabilization.

cc #110680 `@est31`
2024-07-12 03:43:36 +02:00
Matthias Krüger
83d1a1b252
Rollup merge of #127596 - tesuji:help-unwrap-or, r=compiler-errors
More suggestion for converting `Option<&Vec<T>>` to `Option<&[T]>`

Please review commit-by-commit.
2024-07-12 03:43:35 +02:00
Matthias Krüger
58fe37f2c3
Rollup merge of #127164 - Nadrieril:clean-lowering-loop, r=matthewjasper
match lowering: Clarify the main loop of the algorithm

Now that we expand or-patterns in a single place in the algorithm, we can move it (back) to the main part of the loop. This makes the call-graph of the main loop rather simple: `match_candidates` has three branches that each call back to `match_candidates`. The remaining tricky part is `finalize_or_candidate`.

I also factored out the whole "process a prefix of the candidates then process the rest" thing which I think helps legibility.

The first two commits are a fix for an indexing mistake I introduced in https://github.com/rust-lang/rust/pull/126553, already sumitted in https://github.com/rust-lang/rust/pull/127028 but feel free to merge this first.

r? `@matthewjasper`
2024-07-12 03:43:34 +02:00
bors
4a31a6c32a Auto merge of #127382 - estebank:const-let, r=compiler-errors
Use verbose style when suggesting changing `const` with `let`
2024-07-12 01:18:12 +00:00
Michael Goulet
a36fcc8969 Remove lang feature for type ascription 2024-07-11 20:40:38 -04:00
Michael Goulet
2c8bbeebf1 Remove fully_normalize 2024-07-11 19:15:04 -04:00
bors
5e311f933d Auto merge of #127614 - matthiaskrgr:rollup-8geziwi, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #124599 (Suggest borrowing on fn argument that is `impl AsRef`)
 - #127572 (Don't mark `DEBUG_EVENT` struct as `repr(packed)`)
 - #127588 (core: Limit remaining f16 doctests to x86_64 linux)
 - #127591 (Make sure that labels are defined after the primary span in diagnostics)
 - #127598 (Allows `#[diagnostic::do_not_recommend]` to supress trait impls in suggestions as well)
 - #127599 (Rename `lazy_cell_consume` to `lazy_cell_into_inner`)
 - #127601 (check is_ident before parse_ident)
 - #127605 (Remove extern "wasm" ABI)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-07-11 22:56:52 +00:00
Lzu Tao
a776e5f922 Add doc for deconstruct_option_or_result 2024-07-11 22:50:23 +00:00
Lzu Tao
872d7b82e1 Add suggestion for Option<&Vec<T>> -> Option<&[T] 2024-07-11 22:50:23 +00:00
Esteban Küber
cbe75486f7 Account for let foo = expr; to suggest const foo: Ty = expr; 2024-07-11 20:39:24 +00:00
Esteban Küber
b56dc8ee90 Use verbose style when suggesting changing const with let 2024-07-11 20:39:24 +00:00
Giacomo Stevanato
d9021791eb Revert accidental comment deletion 2024-07-11 22:38:34 +02:00
Michael Goulet
b77d3ef7c4 Mark builtin syntax as internal 2024-07-11 15:31:39 -04:00
Michael Goulet
42653c0045 Make it translatable too 2024-07-11 14:14:17 -04:00
Michael Goulet
03bee1e1e5 Suggest using precise capturing for hidden type that captures region 2024-07-11 14:01:29 -04:00
Matthias Krüger
fa3ce50f0b
Rollup merge of #127605 - nikic:remove-extern-wasm, r=oli-obk
Remove extern "wasm" ABI

Remove the unstable `extern "wasm"` ABI (`wasm_abi` feature tracked in #83788).

As discussed in https://github.com/rust-lang/rust/pull/127513#issuecomment-2220410679 and following, this ABI is a failed experiment that did not end up being used for anything. Keeping support for this ABI in LLVM 19 would require us to switch wasm targets to the `experimental-mv` ABI, which we do not want to do.

It should be noted that `Abi::Wasm` was internally used for two things: The `-Z wasm-c-abi=legacy` ABI that is still used by default on some wasm targets, and the `extern "wasm"` ABI. Despite both being `Abi::Wasm` internally, they were not the same. An explicit `extern "wasm"` additionally enabled the `+multivalue` feature.

I've opted to remove `Abi::Wasm` in this patch entirely, instead of keeping it as an ABI with only internal usage. Both `-Z wasm-c-abi` variants are now treated as part of the normal C ABI, just with different different treatment in
adjust_for_foreign_abi.
2024-07-11 17:01:41 +02:00
Matthias Krüger
d433f176ef
Rollup merge of #127601 - trevyn:issue-127600, r=compiler-errors
check is_ident before parse_ident

Closes #127600
2024-07-11 17:01:40 +02:00
Matthias Krüger
a10b4d1463
Rollup merge of #127598 - weiznich:diagnostic_do_not_recommend_also_skips_help, r=compiler-errors
Allows `#[diagnostic::do_not_recommend]` to supress trait impls in suggestions as well

This commit changes the error reporting mechanism for not implemented traits to skip impl marked as `#[diagnostic::do_not_recommend]` in the help part of the error message ("the following other types implement trait `Foo`:"). The main use case here is to allow crate authors to skip non-meaningful confusing suggestions. A common example for this are fully generic impls on tuples.

Related to https://github.com/rust-lang/rust/issues/51992

r? `@compiler-errors`
2024-07-11 17:01:39 +02:00
Matthias Krüger
73c500b3a7
Rollup merge of #127591 - compiler-errors:label-after-primary, r=lcnr
Make sure that labels are defined after the primary span in diagnostics

Putting a `#[label]` before a `#[primary_span]` results in that label being overwritten, due to the semantics of `Diagnostic::span` and the fact that labels are stored in the `MultiSpan` of the diagnostic.

This isn't possible to fix in general, since a lot of code actually *relies* in this overwriting behavior (e.g. `rustc_on_unimplemented`). However, it's useful to enforce this for derive-diagnostics, since this is certainly never what you intend to do in a derived diagnostic, where all the fields are meaningful parts of the diagnostic being rendered.

This only matters for `#[label]`, since those are the ones stored in the `MultiSpan` of the error.

We could also make this "just work" by sorting the attrs or processing the primary span attr first, however I think it's kinda pointless to do.

There was 1 case where this mattered, but we literally didn't have a test exercising that diagnostic 🙃
2024-07-11 17:01:38 +02:00
Matthias Krüger
8de487fdbd
Rollup merge of #124599 - estebank:issue-41708, r=wesleywiser
Suggest borrowing on fn argument that is `impl AsRef`

When encountering a move conflict, on an expression that is `!Copy` passed as an argument to an `fn` that is `impl AsRef`, suggest borrowing the expression.

```
error[E0382]: use of moved value: `bar`
  --> f204.rs:14:15
   |
12 |     let bar = Bar;
   |         --- move occurs because `bar` has type `Bar`, which does not implement the `Copy` trait
13 |     foo(bar);
   |         --- value moved here
14 |     let baa = bar;
   |               ^^^ value used here after move
   |
help: borrow the value to avoid moving it
   |
13 |     foo(&bar);
   |         +
```

Fix #41708
2024-07-11 17:01:36 +02:00
Urgau
977439d9b8 Use uplifted rustc-stable-hash crate in rustc_data_structures 2024-07-11 16:51:16 +02:00
bors
bcf1f6db45 Auto merge of #127487 - tgross35:f16-f128-simd, r=Amanieu
Add `f16` and `f128` as simd types in LLVM

`@sayantn` is working on adding SIMD for `f16` and hitting the `FloatingPointVector` error. This should fix it and unblock adding support for `simd_fma` and `simd_fabs` in stdarch.
2024-07-11 14:08:58 +00:00
lcnr
f56b2074c6 solve -> solve/mod 2024-07-11 15:39:17 +02:00
bors
c92a8e4d4d Auto merge of #127311 - oli-obk:do_not_count_errors, r=compiler-errors
Avoid follow-up errors and ICEs after missing lifetime errors on data structures

Tuple struct constructors are functions, so when we call them typeck will use the signature tuple struct constructor function to provide type hints. Since typeck mostly ignores and erases lifetimes, we end up never seeing the error lifetime in writeback, thus not tainting the typeck result.

Now, we eagerly taint typeck results by tainting from `resolve_vars_if_possible`, which is called all over the place.

I did not carry over all the `crashes` test suite tests, as they are really all the same cause (missing or unknown lifetime names in tuple struct definitions or generic arg lists).

fixes #124262
fixes #124083
fixes #125155
fixes #125888
fixes #125992
fixes #126666
fixes #126648
fixes #127268
fixes #127266
fixes #127304
2024-07-11 11:51:33 +00:00
Oli Scherer
dce98c52ff Avoid follow-up errors and ICEs after missing lifetime errors on data structures 2024-07-11 11:00:15 +00:00
Nikita Popov
8a50bcbdce Remove extern "wasm" ABI
Remove the unstable `extern "wasm"` ABI (`wasm_abi` feature tracked
in #83788).

As discussed in https://github.com/rust-lang/rust/pull/127513#issuecomment-2220410679
and following, this ABI is a failed experiment that did not end
up being used for anything. Keeping support for this ABI in LLVM 19
would require us to switch wasm targets to the `experimental-mv`
ABI, which we do not want to do.

It should be noted that `Abi::Wasm` was internally used for two
things: The `-Z wasm-c-abi=legacy` ABI that is still used by
default on some wasm targets, and the `extern "wasm"` ABI. Despite
both being `Abi::Wasm` internally, they were not the same. An
explicit `extern "wasm"` additionally enabled the `+multivalue`
feature.

I've opted to remove `Abi::Wasm` in this patch entirely, instead
of keeping it as an ABI with only internal usage. Both
`-Z wasm-c-abi` variants are now treated as part of the normal
C ABI, just with different different treatment in
adjust_for_foreign_abi.
2024-07-11 12:20:26 +02:00
trevyn
a01f49e7f3 check is_ident before parse_ident 2024-07-11 12:12:00 +04:00
bors
9b0043095a Auto merge of #127097 - compiler-errors:async-closure-lint, r=oli-obk
Implement simple, unstable lint to suggest turning closure-of-async-block into async-closure

We want to eventually suggest people to turn `|| async {}` to `async || {}`. This begins doing that. It's a pretty rudimentary lint, but I wanted to get something down so I wouldn't lose the code.

Tracking:
* #62290
2024-07-11 06:59:10 +00:00
Georg Semmler
27d5db166e
Allows #[diagnostic::do_not_recommend] to supress trait impls in suggestions as well
This commit changes the error reporting mechanism for not implemented
traits to skip impl marked as `#[diagnostic::do_not_recommend]` in the
help part of the error message ("the following other types implement
trait `Foo`:"). The main use case here is to allow crate authors to skip
non-meaningful confusing suggestions. A common example for this are
fully generic impls on tuples.
2024-07-11 08:14:28 +02:00
Michael Goulet
de88bc5c89 And additionally enforce ? and async/const aren't mixed 2024-07-11 00:00:03 -04:00
bors
8c39ac9ecc Auto merge of #127575 - chenyukang:yukang-fix-struct-fields-ice, r=compiler-errors
Avoid "no field" error and ICE on recovered ADT variant

Fixes https://github.com/rust-lang/rust/issues/126744
Fixes https://github.com/rust-lang/rust/issues/126344, a more general fix compared with https://github.com/rust-lang/rust/pull/127426

r? `@oli-obk`

From `@compiler-errors` 's comment https://github.com/rust-lang/rust/pull/127502#discussion_r1669538204
Seems most of the ADTs don't have taint, so maybe it's not proper to change `TyCtxt::type_of` query.
2024-07-11 03:12:38 +00:00
Michael Goulet
12ae282987 Fix diagnostic and add a test for it 2024-07-10 18:56:06 -04:00
Michael Goulet
df72e478b0 Make sure that labels are defined after the primary span in diagnostics 2024-07-10 18:55:45 -04:00
Urgau
de560c3065 Implement ambiguous_negative_literals lint 2024-07-11 00:46:47 +02:00
bors
3ad5f459b3 Auto merge of #127560 - oli-obk:safe_clobber, r=nnethercote
Make `visit_clobber`'s impl safe

This was originally introduced in #58061 but I didn't see any perf discussion about it, so let's see what perf says.

r? `@nnethercote`
2024-07-10 22:01:02 +00:00
Michael Goulet
898ed2ffa6 Enforce that ? and for<...> are not combined 2024-07-10 17:49:50 -04:00
Michael Goulet
32c8bfdb11 Improve error message 2024-07-10 17:15:02 -04:00
Michael Goulet
e8445818d4 Reorder modifiers and polarity to be *after* binder in trait bounds 2024-07-10 17:15:02 -04:00
Michael Goulet
153a381104 Report usage of lib features in ast validation 2024-07-10 16:53:41 -04:00
bors
0c81f94b9a Auto merge of #127419 - trevyn:issue-125446, r=fee1-dead
Add suggestions for possible missing `fn`, `struct`, or `enum` keywords

Closes #125446
Closes #65381
2024-07-10 18:27:32 +00:00
yukang
07e6dd95bd report pat no field error no recoverd struct variant 2024-07-11 00:18:47 +08:00
Matthias Krüger
22df186d6f
Rollup merge of #127570 - lcnr:normalize-cool, r=compiler-errors
small normalization improvement

r? `@compiler-errors`
2024-07-10 17:54:29 +02:00
Matthias Krüger
7faef5d5ed
Rollup merge of #127568 - lcnr:undo-leakcheck, r=oli-obk
instantiate higher ranked goals in candidate selection again

This reverts #119820 as that PR has a significant impact and breaks code which *feels like it should work*. The impact ended up being larger than we expected during the FCP and we've ended up with some ideas for how we can work around this issue in the next solver. This has been discussed in the previous high bandwidth t-types meeting: https://rust-lang.zulipchat.com/#narrow/stream/326132-t-types.2Fmeetings/topic/2024-07-09.20high.20bandwidth.20meeting.

We'll therefore keep this inconsistency between the two solvers for now and will have to deal with it before stabilizating the use of the new solver outside of coherence: https://github.com/rust-lang/trait-system-refactor-initiative/issues/120.

fixes #125194 after a beta-backport.

The pattern which is more widely used than expected and feels like it should work, especially without deep knowledge of the type system is
```rust
trait Trait<'a> {}
impl<'a, T> Trait<'a> for T {}

fn trait_bound<T: for<'a> Trait<'a>>() {}

// A function with a where-bound which is more restrictive than the impl.
fn function1<T: Trait<'static>>() {
    // stable: ok
    // with #119820: error as we prefer the where-bound over the impl
    // with this PR: back to ok
    trait_bound::<T>();
}

```

r? `@rust-lang/types`
2024-07-10 17:54:28 +02:00
Matthias Krüger
a7fe30d82a
Rollup merge of #127094 - Borgerr:E0191-suggestion-correction, r=fmease
E0191 suggestion correction, inserts turbofish

closes #91997
2024-07-10 17:54:26 +02:00
lcnr
e00fd781c9 simplify and future-proof needs_normalization 2024-07-10 15:56:20 +02:00
Alex Macleod
5824ab178b Support lists and stylings in more places for rustc --explain 2024-07-10 13:41:36 +00:00
lcnr
f77394fdf3 instantiate higher ranked goals in candidate selection
reverts #119820
2024-07-10 14:13:16 +02:00
Guillaume Gomez
541b32c8ab Update Cargo.lock and remove duplicated impl 2024-07-10 13:02:26 +02:00
Guillaume Gomez
7cbe50e209 Merge commit '98ed962c7d3eebe12c97588e61245273d265e72f' into master 2024-07-10 12:44:23 +02:00
Zalathar
83e1efb254 Replace a long inline "autoref" comment with method docs
This comment has two problems:

- It is very long, making the flow of the enclosing method hard to follow.
- It starts by talking about an `autoref` flag that hasn't existed since #59114.

This PR therefore replaces the long inline comment with a revised doc comment
on `bind_matched_candidate_for_guard`, and some shorter inline comments.

For readers who want more historical context, we also link to the PR that added
the old comment, and the PR that removed the `autoref` flag.
2024-07-10 20:25:54 +10:00
Oli Scherer
3562ec74ca Make visit_clobber's impl safe 2024-07-10 07:54:17 +00:00
Nicholas Nethercote
478ba59026 Add some comments.
Explaining things that took me some time to work out.
2024-07-10 17:03:58 +10:00
Nicholas Nethercote
d6ebbbfcb2 Factor out AttrsTarget flattening code.
This commit does the following.
- Pulls the code out of `AttrTokenStream::to_token_trees` into a new
  function `attrs_and_tokens_to_token_trees`.
- Simplifies `TokenStream::from_ast` by calling the new function. This
  is nicer than the old way, which created a temporary
  `AttrTokenStream` containing a single `AttrsTarget` (which required
  some cloning) just to call `to_token_trees` on it. (It is good to
  remove this use of `AttrsTarget` which isn't related to `cfg_attr`
  expansion.)
2024-07-10 17:03:17 +10:00
bors
649feb9c1a Auto merge of #127549 - jhpratt:rollup-o1mbmhr, r=jhpratt
Rollup of 8 pull requests

Successful merges:

 - #124211 (Bump `elided_lifetimes_in_associated_constant` to deny)
 - #125627 (migration lint for `expr2024` for the edition 2024)
 - #127091 (impl FusedIterator and a size hint for the error sources iter)
 - #127461 (Fixup failing fuchsia tests)
 - #127484 (`#[doc(alias)]`'s doc: say that ASCII spaces are allowed)
 - #127508 (small search graph refactor)
 - #127521 (Remove spastorino from SMIR)
 - #127532 (documentation: update cmake version)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-07-10 06:35:04 +00:00
Nicholas Nethercote
d8b6aa6d0d Use cfg_attr as a name more.
In various functions where the attribute being processed is known to be
a `#[cfg_attr(...)]` attribute. I find this a helpful reminder.
2024-07-10 15:11:57 +10:00
Nicholas Nethercote
fee152556f Rework Attribute::get_tokens.
Returning `Vec<TokenTree>` works better for the call sites than
returning `TokenStream`.
2024-07-10 14:51:41 +10:00
Nicholas Nethercote
8a390bae06 Change empty replace range condition.
The new condition is equivalent in practice, but it's much more obvious
that it would result in an empty range, because the condition lines up
with the contents of the iterator.
2024-07-10 14:41:39 +10:00
Jacob Pratt
64695adbd7
Rollup merge of #127508 - lcnr:search-graph-prep, r=compiler-errors
small search graph refactor

small improvements which shouldn't impact behavior.

r? ``````@compiler-errors``````
2024-07-10 00:37:12 -04:00
Jacob Pratt
21a0e86234
Rollup merge of #125627 - vincenzopalazzo:macros/cargo-fix-expr2024, r=compiler-errors,eholk
migration lint for `expr2024` for the edition 2024

This is adding a migration lint for the current (in the 2021 edition and previous)
to move expr to expr_2021 from expr

Issue https://github.com/rust-lang/rust/issues/123742

I created also a repository to test out the migration https://github.com/vincenzopalazzo/expr2024-cargo-fix-migration

Co-Developed-by: ``@eholk``
2024-07-10 00:37:10 -04:00
Jacob Pratt
de143cf992
Rollup merge of #124211 - compiler-errors:bump-elided_lifetimes_in_associated_constant, r=BoxyUwU
Bump `elided_lifetimes_in_associated_constant` to deny

It's been 5 versions since this was last bumped. Let's bump it up again.
2024-07-10 00:37:10 -04:00
bors
7caf6726db Auto merge of #127496 - tgross35:f16-f128-pattern-fixme, r=Nadrieril
Update `f16`/`f128` FIXMEs that needed `(NEG_)INFINITY`

Just a small fix to the pattern matching tests now that we can. Also contains a small unrelated comment tweak.
2024-07-10 04:20:32 +00:00
bors
956deab788 Auto merge of #127495 - compiler-errors:more-trait-error-reworking, r=lcnr
More trait error reworking

More work on #127492, specifically those sub-bullets under "Move trait error reporting to `error_reporting::traits`". Stacked on top of #127493.

This does introduce new `TypeErrCtxt.*Ext` traits, but those will be deleted soon. Splitting this work into bite-sized pieces is the only way that it's gonna be feasible to both author and review ❤️

r? lcnr
2024-07-10 02:08:19 +00:00
Ashton Hunt
7c88bda1cb E0191 suggestion correction, inserts turbofish without dyn (#91997) 2024-07-09 17:21:31 -06:00
bors
7d640b670e Auto merge of #127358 - oli-obk:taint_itemctxt, r=fmease
Automatically taint when reporting errors from ItemCtxt

This isn't very robust yet, as you need to use `itemctxt.dcx()` instead of `tcx.dcx()` for it to take effect, but it's at least more convenient than sprinkling `set_tainted_by_errors` calls in individual places.

based on https://github.com/rust-lang/rust/pull/127357

r? `@fmease`
2024-07-09 23:03:01 +00:00
Nadrieril
42772e98e0 Address review comments 2024-07-09 22:47:35 +02:00
Nadrieril
3e030b38ef Return the otherwise_block instead of passing it as argument
This saves a few blocks and matches the common `unpack!` paradigm.
2024-07-09 22:47:35 +02:00
Nadrieril
fc40247c6b Factor out the "process remaining candidates" cases 2024-07-09 22:47:35 +02:00
Nadrieril
8a222ffd6b Don't try to save an extra block
This is preparation for the next commit.
2024-07-09 22:47:35 +02:00
Nadrieril
c5062f7318 Move or-pattern expansion inside the main part of the algorithm 2024-07-09 22:47:35 +02:00
Nadrieril
bff4d213fa Factor out the special handling of or-patterns 2024-07-09 22:47:35 +02:00
Nadrieril
5bf50e66f9 Move a function 2024-07-09 22:47:35 +02:00
Santiago Pastorino
a3ef94e80e
Fire unsafe_code lint on unsafe extern blocks 2024-07-09 17:35:51 -03:00
bors
6be96e3865 Auto merge of #127234 - ZhuUx:inlined-expr, r=davidtwco,Zalathar
[Coverage][MCDC] Group mcdc tests and fix panic when generating mcdc code for inlined expressions.

### Changes

1. Group all mcdc tests to one directory.
2. Since mcdc instruments different mappings for boolean expressions with normal branch coverage as #125766 introduces, it would be better also trace branch coverage results in mcdc tests.
3. So far rustc does not call `CoverageInfoBuilderMethods::init_coverage` for inlined functions. As a result, it could panic if it tries to instrument mcdc statements for inlined functions due to uninitialized cond bitmaps. We can reproduce this issue by current nightly rustc and [the test](https://github.com/rust-lang/rust/pull/127234/files#diff-c81af6bf4869aa42f5c7334e3e86344475de362f673f54ce439ec75fcb5ac3e5) with flag `--release`. This patch fixes it.
2024-07-09 20:24:30 +00:00
Vincenzo Palazzo
25637e2c8e Adds expr_2024 migration lit
This is adding a migration lint for the current (in the 2021 edition and previous)
to move expr to expr_2021 from expr

Co-Developed-by: Eric Holk
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
2024-07-09 17:41:13 +00:00
bors
9dcaa7f92c Auto merge of #127028 - Nadrieril:fix-or-pat-expansion, r=matthewjasper
Fix regression in the MIR lowering of or-patterns

In https://github.com/rust-lang/rust/pull/126553 I made a silly indexing mistake and regressed the MIR lowering of or-patterns. This fixes it.

r? `@compiler-errors` because I'd like this to be merged quickly 🙏
2024-07-09 16:33:59 +00:00
Michael Goulet
bbbff80603 Split out fulfillment error reporting a bit more 2024-07-09 09:57:16 -04:00
Michael Goulet
cd68a28daa Move some stuff into the ambiguity and suggestion modules 2024-07-09 09:51:56 -04:00
Michael Goulet
7af825fea4 Split out overflow handling into its own module 2024-07-09 09:51:56 -04:00
bors
f25e92bd42 Auto merge of #127500 - compiler-errors:consolidate-region-errors, r=lcnr
Consolidate region error reporting in `rustc_infer`

More work on https://github.com/rust-lang/rust/issues/127492. Separate but important step, since I'm gonna likely pull everything else here into another module.

I don't think I'm confident whether `nice_region_error` should be a submodule of the new `rustc_infer::infer::error_reporting::region` module, so I left it alone for now.

r? lcnr
2024-07-09 13:43:15 +00:00
Nicholas Nethercote
f5527949f2 Move Spacing into FlatToken.
It's only needed for the `FlatToken::Token` variant. This makes things a
little more concise.
2024-07-09 21:54:32 +10:00
bors
a2d58197a7 Auto merge of #127493 - compiler-errors:crate-level-import, r=lcnr
Move trait selection error reporting to its own top-level module

This effectively moves `rustc_trait_selection::traits::error_reporting` to `rustc_trait_selection::error_reporting::traits`. There are only a couple of actual changes to the code, like moving the `pretty_impl_header` fn out of the specialization module for privacy reasons.

This is quite pointless on its own, but having `error_reporting` as a top-level module in `rustc_trait_selection` is very important to make sure we have a meaningful file structure for when we move **type** error reporting (and region error reporting, with which it's incredibly entangled currently) into `rustc_trait_selection`. I've opened a tracking issue here: #127492

r? lcnr
2024-07-09 11:23:13 +00:00
Alan Egerton
5e2cc5793a
Terminate --print link-args output with newline 2024-07-09 10:40:26 +01:00
bors
8672b2b763 Auto merge of #127001 - beetrees:f16-debuginfo, r=michaelwoerister
Add Natvis visualiser and debuginfo tests for `f16`

To render `f16`s in debuggers on MSVC targets, this PR changes the compiler to output `f16`s as `struct f16 { bits: u16 }`, and includes a Natvis visualiser that manually converts the `f16`'s bits to a `float` which is can then be displayed by debuggers. `gdb`, `lldb` and `cdb` tests are also included for `f16` .

`f16`/`f128` MSVC debug info issue: #121837
Tracking issue: #116909
2024-07-09 09:07:42 +00:00
lcnr
dd175feb25 cycle_participants to nested_goals 2024-07-09 09:51:50 +02:00
Oli Scherer
aece06482e Remove HirTyLowerer::set_tainted_by_errors, since it is now redundant 2024-07-09 07:44:17 +00:00
Oli Scherer
fd9a92542c Automatically taint when reporting errors from ItemCtxt 2024-07-09 07:44:17 +00:00
lcnr
e38109d7f0 use update_parent_goal for lazy updates 2024-07-09 09:22:58 +02:00
lcnr
7097dbc50c exhaustively destructure external constraints 2024-07-09 09:10:19 +02:00
bors
5be2ec7245 Auto merge of #127200 - fee1-dead-contrib:trait_def_const_trait, r=compiler-errors
Add `constness` to `TraitDef`

Second attempt at fixing the regression @ https://github.com/rust-lang/rust/pull/120639#issuecomment-2198373716

r? project-const-traits
2024-07-09 06:51:35 +00:00
zhuyunxing
83fa6b726a coverage. Fix panic when generating mcdc code for inlined functions 2024-07-09 14:28:40 +08:00
bors
cd3d98b3be Auto merge of #127357 - oli-obk:structureddiag, r=fmease
Remove `StructuredDiag`

follow-up to https://github.com/rust-lang/rust/pull/127319

This trait was an experiment that didn't pan out.
2024-07-09 04:31:11 +00:00
beetrees
b058de90a3
Add Natvis visualiser and debuginfo tests for f16 2024-07-09 03:47:50 +01:00
asquared31415
87856c4461 add lint for inline asm labels that look like binary 2024-07-09 01:23:49 +00:00
Michael Goulet
9a92526b98 Consolidate region error reporting in rustc_infer 2024-07-08 20:35:30 -04:00
Trevor Gross
96a791662a Update a f16/f128 FIXME to be more accurate 2024-07-08 18:55:26 -04:00
Michael Goulet
fe4c995ccb Move trait selection error reporting to its own top-level module 2024-07-08 16:04:47 -04:00
Oli Scherer
af9ab1b026 Remove structured_errors module 2024-07-08 19:29:55 +00:00
Oli Scherer
2f0368c902 Remove StructuredDiag 2024-07-08 19:29:55 +00:00
Oli Scherer
9e7918f70e Remove another StructuredDiag impl 2024-07-08 19:29:55 +00:00
Guillaume Gomez
72199b2c52
Rollup merge of #127482 - compiler-errors:closure-two-par-sig-inference, r=oli-obk
Infer async closure signature from (old-style) two-part `Fn` + `Future` bounds

When an async closure is passed to a function that has a "two-part" `Fn` and `Future` trait bound, like:

```rust
use std::future::Future;

fn not_exactly_an_async_closure(_f: F)
where
    F: FnOnce(String) -> Fut,
    Fut: Future<Output = ()>,
{}
```

The we want to be able to extract the signature to guide inference in the async closure, like:

```rust
not_exactly_an_async_closure(async |string| {
    for x in string.split('\n') { ... }
    //~^ We need to know that the type of `string` is `String` to call methods on it.
})
```

Closure signature inference will see two bounds: `<?F as FnOnce<Args>>::Output = ?Fut`, `<?Fut as Future>::Output = String`. We need to extract the signature by looking through both projections.

### Why?

I expect the ecosystem's move onto `async Fn` trait bounds (which are not affected by this PR, and already do signature inference fine) to be slow. In the mean time, I don't see major overhead to supporting this "old–style" of trait bounds that were used to model async closures.

r? oli-obk
Fixes #127468
Fixes #127425
2024-07-08 20:23:41 +02:00
Trevor Gross
04caa5555a Add f16 and f128 as SIMD types in LLVM 2024-07-08 13:59:39 -04:00
Michael Goulet
f4f678f27e Infer async closure signature from old-style two-part Fn + Future bounds 2024-07-08 12:56:54 -04:00
bors
a06e9c83f6 Auto merge of #127486 - matthiaskrgr:rollup-lvv018b, r=matthiaskrgr
Rollup of 5 pull requests

Successful merges:

 - #120248 (Make casts of pointers to trait objects stricter)
 - #127355 (Mark format! with must_use hint)
 - #127399 (Verify that allocations output by GVN are sufficiently aligned.)
 - #127460 (clarify `sys::unix::fd::FileDesc::drop` comment)
 - #127467 (bootstrap: once_cell::sync::Lazy -> std::sync::LazyLock)

Failed merges:

 - #127357 (Remove `StructuredDiag`)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-07-08 16:01:38 +00:00
Matthias Krüger
3e8e8df7c0
Rollup merge of #127399 - cjgillot:issue-127396, r=oli-obk
Verify that allocations output by GVN are sufficiently aligned.

Fixes #127396

r? `@oli-obk`
2024-07-08 16:28:16 +02:00
Matthias Krüger
c4ee2df539
Rollup merge of #120248 - WaffleLapkin:bonk-ptr-object-casts, r=compiler-errors,oli-obk,lnicola
Make casts of pointers to trait objects stricter

This is an attempt to `fix` https://github.com/rust-lang/rust/issues/120222 and https://github.com/rust-lang/rust/issues/120217.

This is done by adding restrictions on casting pointers to trait objects.

Before this PR the rules were as follows:

> When casting `*const X<dyn A>` -> `*const Y<dyn B>`, principal traits in `A` and `B` must refer to the same trait definition (or no trait).

With this PR the rules are changed to

> When casting `*const X<dyn Src>` -> `*const Y<dyn Dst>`
> - if `Dst` has a principal trait `DstP`,
>   - `Src` must have a principal trait `SrcP`
>   - `dyn SrcP` and `dyn DstP` must be the same type (modulo the trait object lifetime, `dyn T+'a` -> `dyn T+'b` is allowed)
>   - Auto traits in `Dst` must be a subset of auto traits in `Src`
>     - Not adhering to this is currently a FCW (warn-by-default + `FutureReleaseErrorReportInDeps`), instead of an error
> - if `Src` has a principal trait `Dst` must as well
>   - this restriction will be removed in a follow up PR

This ensures that
1. Principal trait's generic arguments match (no `*const dyn Tr<A>` -> `*const dyn Tr<B>` casts, which are a problem for [#120222](https://github.com/rust-lang/rust/issues/120222))
2. Principal trait's lifetime arguments match (no `*const dyn Tr<'a>` -> `*const dyn Tr<'b>` casts, which are a problem for [#120217](https://github.com/rust-lang/rust/issues/120217))
3. No auto traits can be _added_ (this is a problem for arbitrary self types, see [this comment](https://github.com/rust-lang/rust/pull/120248#discussion_r1463835350))

Some notes:
 - We only care about the metadata/last field, so you can still cast `*const dyn T` to `*const WithHeader<dyn T>`, etc
- The lifetime of the trait object itself (`dyn A + 'lt`) is not checked, so you can still cast `*mut FnOnce() + '_` to `*mut FnOnce() + 'static`, etc
  - This feels fishy, but I couldn't come up with a reason it must be checked

The diagnostics are currently not great, to say the least, but as far as I can tell this correctly fixes the issues.

cc `@oli-obk` `@compiler-errors` `@lcnr`
2024-07-08 16:28:15 +02:00
bors
cfd7cf5a0e Auto merge of #127199 - Zalathar:hir-holes, r=oli-obk
coverage: Extract hole spans from HIR instead of MIR

This makes it possible to treat more kinds of nested item/code as holes, instead of being restricted to closures.

(It also potentially opens up the possibility of using HIR holes to modify branch or MC/DC spans, though we currently don't actually do this.)

Thus, this new implementation treats the following as holes:
- Closures (as before, including `async` and coroutines)
- All nested items
- Inline `const` (because why not)

This gives more accurate coverage reports, because lines occupied by holes don't show the execution count from the enclosing function.

Fixes #126626.
2024-07-08 13:24:50 +00:00
Zalathar
63c04f05e6 coverage: Extract hole spans from HIR instead of MIR
This makes it possible to treat more kinds of nested item/code as holes,
instead of being restricted to closures.
2024-07-08 21:22:56 +10:00
bors
59a4f02f83 Auto merge of #127438 - compiler-errors:compute-outlives-visitor, r=lcnr
Make `push_outlives_components` into a `TypeVisitor`

This involves removing the `visited: &mut SsoHashSet<GenericArg<'tcx>>` that is being passed around the `VerifyBoundCx`. The fact that we were using it when decomposing different type tests seems sketchy, so I don't think, though it may technically result in us registering more redundant outlives components 🤷

I did end up deleting some of the comments that referred back to RFC 1214 during this refactor. I can add them back if you think they were useful.

r? lcnr
2024-07-08 10:56:15 +00:00
Nicholas Nethercote
a88c4d67d9 Split the stack in make_attr_token_stream.
It makes for shorter code, and fewer allocations.
2024-07-08 19:04:13 +10:00
Nicholas Nethercote
b16201317e Use iterator normally in make_attr_token_stream.
In a `for` loop, instead of a `while` loop.
2024-07-08 19:04:13 +10:00
Nicholas Nethercote
a47ae57a18 Use an @ pattern to shorten some code. 2024-07-08 19:03:50 +10:00
Nicholas Nethercote
99721c8469 Clear inner_attr_ranges regularly.
There's a comment saying we don't do it for performance reasons, but it
doesn't actually affect performance.

The commit also tweaks the control flow, to make clearer that two code
paths are mutually exclusive.
2024-07-08 16:53:10 +10:00
bors
7fdefb804e Auto merge of #127476 - jieyouxu:rollup-16wyb0b, r=jieyouxu
Rollup of 10 pull requests

Successful merges:

 - #126841 ([`macro_metavar_expr_concat`] Add support for literals)
 - #126881 (Make `NEVER_TYPE_FALLBACK_FLOWING_INTO_UNSAFE` a deny-by-default lint in edition 2024)
 - #126921 (Give VaList its own home)
 - #127367 (Run alloc sync tests)
 - #127431 (Use field ident spans directly instead of the full field span in diagnostics on local fields)
 - #127437 (Uplift trait ref is knowable into `rustc_next_trait_solver`)
 - #127439 (Uplift elaboration into `rustc_type_ir`)
 - #127451 (Improve `run-make/output-type-permutations` code and improve `filename_not_in_denylist` API)
 - #127452 (Fix intrinsic const parameter counting with `effects`)
 - #127459 (rustdoc-json: add type/trait alias tests)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-07-08 06:47:12 +00:00
trevyn
b40adc9d3b Add suggestions for possible missing fn, struct, or enum keywords 2024-07-08 10:04:03 +04:00
许杰友 Jieyou Xu (Joe)
73593b9aca
Rollup merge of #127452 - fee1-dead-contrib:fx-intrinsic-counting, r=fmease
Fix intrinsic const parameter counting with `effects`

r? project-const-traits
2024-07-08 13:04:34 +08:00
许杰友 Jieyou Xu (Joe)
ffb93361b4
Rollup merge of #127439 - compiler-errors:uplift-elaborate, r=lcnr
Uplift elaboration into `rustc_type_ir`

Allows us to deduplicate and consolidate elaboration (including these stupid elaboration duplicate fns i added for pretty printing like 3 years ago) so I'm pretty hyped about this change :3

r? lcnr
2024-07-08 13:04:33 +08:00
许杰友 Jieyou Xu (Joe)
928d71f17b
Rollup merge of #127437 - compiler-errors:uplift-trait-ref-is-knowable, r=lcnr
Uplift trait ref is knowable into `rustc_next_trait_solver`

Self-explanatory. Eliminates one more delegate method.

r? lcnr cc ``@fmease``
2024-07-08 13:04:32 +08:00
许杰友 Jieyou Xu (Joe)
bd4ab30e9c
Rollup merge of #127431 - oli-obk:feed_item_attrs, r=compiler-errors
Use field ident spans directly instead of the full field span in diagnostics on local fields

This improves diagnostics and avoids having to store the `DefId`s of fields
2024-07-08 13:04:32 +08:00
许杰友 Jieyou Xu (Joe)
29c1a43403
Rollup merge of #126881 - WaffleLapkin:unsafe-code-affected-by-fallback-hard-in-2024, r=compiler-errors
Make `NEVER_TYPE_FALLBACK_FLOWING_INTO_UNSAFE` a deny-by-default lint in edition 2024

I don't actually really care about this, but ``@traviscross`` asked me to do this, because lang team briefly discussed this before.

(TC here:)

Specifically, our original FCPed plan included this step:

- Add a lint against fallback affecting a generic that is passed to an `unsafe` function.
   - Perhaps make this lint `deny-by-default` or a hard error in Rust 2024.

That is, we had left as an open question strengthening this in Rust 2024, and had marked it as an open question on the tracking issue.  We're nominating here to address the open question.  (Closing the remaining open question helps us to fully mark this off for Rust 2024.)

r? ``@compiler-errors``

Tracking:

- https://github.com/rust-lang/rust/issues/123748
2024-07-08 13:04:30 +08:00
许杰友 Jieyou Xu (Joe)
2c16d65c1e
Rollup merge of #126841 - c410-f3r:concat-again, r=petrochenkov
[`macro_metavar_expr_concat`] Add support for literals

Adds support for things like `${concat($variable, 123)}` or `${concat("hello", "_world")}` .

cc #124225
2024-07-08 13:04:30 +08:00
bors
9af6fee87d Auto merge of #113128 - WaffleLapkin:become_trully_unuwuable, r=oli-obk,RalfJung
Support tail calls in mir via `TerminatorKind::TailCall`

This is one of the interesting bits in tail call implementation — MIR support.

This adds a new `TerminatorKind` which represents a tail call:
```rust
    TailCall {
        func: Operand<'tcx>,
        args: Vec<Operand<'tcx>>,
        fn_span: Span,
    },
```

*Structurally* this is very similar to a normal `Call` but is missing a few fields:
- `destination` — tail calls don't write to destination, instead they pass caller's destination to the callee (such that eventual `return` will write to the caller of the function that used tail call)
- `target` — similarly to `destination` tail calls pass the caller's return address to the callee, so there is nothing to do
- `unwind` — I _think_ this is applicable too, although it's a bit confusing
- `call_source` — `become` forbids operators and is not created as a lowering of something else; tail calls always come from HIR (at least for now)

It might be helpful to read the interpreter implementation to understand what `TailCall` means exactly, although I've tried documenting it too.

-----

There are a few `FIXME`-questions still left, ideally we'd be able to answer them during review ':)

-----

r? `@oli-obk`
cc `@scottmcm` `@DrMeepster` `@JakobDegen`
2024-07-08 04:35:04 +00:00
Zalathar
1cf4eb2ad2 Stop using unpack! for BlockAnd<()> 2024-07-08 12:05:41 +10:00
Zalathar
4fe8dd05ed Remove the non-assigning form of unpack!
This kind of unpacking can be expressed as an ordinary method on
`BlockAnd<()>`.
2024-07-08 12:04:09 +10:00
bors
b1de36ff34 Auto merge of #127421 - cjgillot:cache-iter, r=fmease
Cache hir_owner_nodes in ParentHirIterator.

Lint level computation may traverse deep HIR trees using that iterator. This calls `hir_owner_nodes` many times for the same HIR owner, which is wasterful.

This PR caches the value to allow a more efficient iteration scheme.

r? ghost for perf
2024-07-08 01:19:32 +00:00
bors
89aefb9c53 Auto merge of #127172 - compiler-errors:full-can_eq-everywhere, r=lcnr
Make `can_eq` process obligations (almost) everywhere

Move `can_eq` to an extension trait on `InferCtxt` in `rustc_trait_selection`, and change it so that it processes obligations. This should strengthen it to be more accurate in some cases, but is most important for the new trait solver which delays relating aliases to `AliasRelate` goals. Without this, we always basically just return true when passing aliases to `can_eq`, which can lead to weird errors, for example #127149.

I'm not actually certain if we should *have* `can_eq` be called on the good path. In cases where we need `can_eq`, we probably should just be using a regular probe.

Fixes #127149

r? lcnr
2024-07-07 23:03:48 +00:00
Maybe Lapkin
39eaefc15d Fixup conflict with r-l/r/126567 2024-07-07 20:16:48 +02:00
Maybe Lapkin
f3c13bf280 Allow casting *mut dyn T->*mut (dyn T + Send) if T has Send super trait 2024-07-07 20:07:01 +02:00
bjorn3
cd3f2f68c0 Fix review comments 2024-07-07 17:08:55 +00:00
bjorn3
72223e205d Fix building on LLVM 17 2024-07-07 17:08:42 +00:00
bjorn3
58e551433d Sync ar_archive_writer to LLVM 18.1.3
From LLVM 15.0.0-rc3. This adds support for COFF archives containing
Arm64EC object files and has various fixes for AIX big archive files.
2024-07-07 16:56:35 +00:00
Maybe Lapkin
7fd0c55a1a Fix conflicts after rebase
- r-l/r 126784
- r-l/r 127113
- r-l/miri 3562
2024-07-07 18:16:38 +02:00
Maybe Lapkin
54e11cf378 add an assertion that machine hook doesn't return NoCleanup 2024-07-07 18:16:38 +02:00
Maybe Waffle
dd5a447b5a Do renames proposed by review 2024-07-07 18:16:38 +02:00
Maybe Waffle
236352024b make StackPop field names less confusing 2024-07-07 18:16:38 +02:00
Maybe Waffle
cda6f0c25d doc fixups from review 2024-07-07 18:16:38 +02:00
Maybe Waffle
6d4995f4e6 add miri tests and a fixme 2024-07-07 18:16:38 +02:00
Maybe Waffle
cda25e56c8 Refactor & fixup interpreter implementation of tail calls 2024-07-07 18:16:38 +02:00
Michael Goulet
15d16f1cd6 Finish uplifting supertraits 2024-07-07 11:28:01 -04:00
Michael Goulet
66eb346770 Get rid of the redundant elaboration in middle 2024-07-07 11:28:01 -04:00
Michael Goulet
90423a7abb Uplift elaboration 2024-07-07 11:28:01 -04:00
Michael Goulet
c895985e75 Make push_outlives_components into a visitor 2024-07-07 11:22:52 -04:00
Maybe Waffle
5f4caae11c Fix unconditional recursion lint wrt tail calls 2024-07-07 17:11:05 +02:00
Maybe Waffle
45c70318f7 Refactor common part of evaluating Call&TailCall in the interpreter 2024-07-07 17:11:05 +02:00
Maybe Waffle
3b5a5ee6c8 Support tail calls in the interpreter 2024-07-07 17:11:05 +02:00
DrMeepster
4187cdc013 Properly handle drops for tail calls 2024-07-07 17:11:05 +02:00
Maybe Waffle
484152d562 Support tail calls in mir via TerminatorKind::TailCall 2024-07-07 17:11:04 +02:00
Michael Goulet
ab27c2fa77 Get rid of trait_ref_is_knowable from delegate 2024-07-07 11:10:48 -04:00
Michael Goulet
a982471e07 Uplift trait_ref_is_knowable and friends 2024-07-07 11:10:32 -04:00
Michael Goulet
b2e30bdec4 Add fundamental to trait def 2024-07-07 11:10:32 -04:00
Matthias Krüger
1ee6345b7b
Rollup merge of #127409 - gurry:127332-ice-with-expr-not-struct, r=oli-obk
Emit a wrap expr span_bug only if context is not tainted

Fixes #127332

The ICE occurs because of this `span_bug`: 51917e2e69/compiler/rustc_hir_typeck/src/expr_use_visitor.rs (L732-L738)
which is triggered by the fact that we're trying to use an `enum` in a `with` expression instead of a `struct`.

The issue originates in commit 814bfe9335   from PR #127202. As per the title of that commit the ICEing code should not be reachable any more, but looks like it still is.

This PR changes the code so that the `span_bug` will be emitted only if the context is not tainted by a previous error.
2024-07-07 14:22:02 +02:00
Matthias Krüger
510020ad4c
Rollup merge of #127308 - nnethercote:Attribute-cleanups, r=petrochenkov
Attribute cleanups

More refactoring done while trying to fix the final remaining test failure for #124141.

r? `@petrochenkov`
2024-07-07 14:22:01 +02:00
Deadbeef
4f54193ccf Fix intrinsic const parameter counting with effects 2024-07-07 11:30:03 +00:00
Gurinder Singh
9da3638c6a Move a span_bug under a condition that cx is tainted
Fixes an ICE caused when a with expression is not a struct
2024-07-07 15:44:55 +05:30
Nicholas Nethercote
9e0aab71a4 Use filter_map instead of flat_map in configure_tokens.
All the branches produce either zero or one elements.
2024-07-07 16:34:29 +10:00
Nicholas Nethercote
9f16f1f6f6 Add an size assertion.
`Option<LazyAttrTokenStream>` is the type that's actually used in all
the aST nodes.
2024-07-07 16:25:22 +10:00
Nicholas Nethercote
022582ca46 Remove Clone derive from LazyAttrTokenStreamImpl. 2024-07-07 16:24:51 +10:00
Nicholas Nethercote
3a5c4b6e4e Rename some attribute types for consistency.
- `AttributesData` -> `AttrsTarget`
- `AttrTokenTree::Attributes` -> `AttrTokenTree::AttrsTarget`
- `FlatToken::AttrTarget` -> `FlatToken::AttrsTarget`
2024-07-07 16:14:30 +10:00
Nicholas Nethercote
9d33a8fe51 Simplify ReplaceRange.
Currently the second element is a `Vec<(FlatToken, Spacing)>`. But the
vector always has zero or one elements, and the `FlatToken` is always
`FlatToken::AttrTarget` (which contains an `AttributesData`), and the
spacing is always `Alone`. So we can simplify it to
`Option<AttributesData>`.

An assertion in `to_attr_token_stream` can can also be removed, because
`new_tokens.len()` was always 0 or 1, which means than `range.len()`
is always greater than or equal to it, because `range.is_empty()` is
always false (as per the earlier assertion).
2024-07-07 15:58:36 +10:00
Nicholas Nethercote
b261501b71 Remove HasSpan trait.
The only place it is meaningfully used is in a panic message in
`TokenStream::from_ast`. But `node.span()` doesn't need to be printed
because `node` is also printed and it must contain the span.
2024-07-07 15:58:34 +10:00
Nicholas Nethercote
88373e9f0c Remove an unnecessary local variable. 2024-07-07 15:58:12 +10:00
Nicholas Nethercote
14b859fa3b Rename Attribute::tokens (the inherent method).
To distinguish it from the `HasTokens` method.
2024-07-07 15:58:10 +10:00
Michael Goulet
58aad3c72c iter_identity is a better name 2024-07-07 00:12:35 -04:00
bors
9e27377bec Auto merge of #127404 - compiler-errors:rpitit-entailment-false-positive, r=oli-obk
Don't try to label `ObligationCauseCode::CompareImplItem` for an RPITIT, since it has no name

The old (current) trait solver has a limitation that when a where clause in param-env must be normalized using the same where clause, then we get spurious errors in `normalize_param_env_or_error`. I don't think there's an issue tracking it, but it's the root cause for many of the "fixed-by-next-solver" labeled issues.

Specifically, these errors may occur when checking predicate entailment of the GAT that comes out of desugaring RPITITs. Since we use `ObligationCauseCode::CompareImplItem` for these predicates, we try calling `item_name` on an RPITIT which fails, since the RPITIT has no name.

We simply suppress this logic when we're reporting a predicate entailment error for an RPITIT. RPITITs should never have predicate entailment errors, *by construction*, but they may due to this bug in the old solver.

Addresses the ICE in #127331, though doesn't fix the underlying issue (which is fundamental to the old solver).

r? types
2024-07-07 03:22:12 +00:00
bors
6ba80a9f8d Auto merge of #126987 - petrochenkov:atvisord2, r=pnkfelix
out_of_scope_macro_calls: Detect calls inside attributes more precisely

Fixes https://github.com/rust-lang/rust/issues/126984.
2024-07-06 22:53:07 +00:00
Michael Goulet
87d61f2540 Don't track visited outlives bounds when decomposing verify for alias 2024-07-06 18:49:20 -04:00
onur-ozkan
48192701e0 use "bootstrap" instead of "rustbuild" in comments and docs
Signed-off-by: onur-ozkan <work@onurozkan.dev>
2024-07-07 00:07:08 +03:00
Caio
c990e00f15 Add support for literals 2024-07-06 18:00:04 -03:00
Oli Scherer
8c2ea715e9 Use field ident spans directly instead of the full field span in diagnostics on local fields 2024-07-06 19:22:05 +00:00
Michael Goulet
d6276b37ea Don't try to label ObligationCauseCode::CompareImplItem for an RPITIT, since it has no name 2024-07-06 15:20:37 -04:00
Michael Goulet
413345c61d
Rollup merge of #127417 - chenyukang:yukang-method-output-diff, r=oli-obk
Show fnsig's unit output  explicitly when there is output diff in diagnostics

Fixes #127263
2024-07-06 14:55:25 -04:00
Michael Goulet
9352026d26
Rollup merge of #127410 - trevyn:patch-1, r=compiler-errors
Correct description of E0502

Closes #126495
2024-07-06 14:55:24 -04:00
Michael Goulet
f664171cb5
Rollup merge of #127405 - compiler-errors:uplift-predicate-emitting-relation, r=lcnr
uplift `PredicateEmittingRelation`

Small follow-up to #127333

r? lcnr
2024-07-06 14:55:24 -04:00
Michael Goulet
dfc02d28c7
Rollup merge of #127386 - compiler-errors:uplift-outlives-components, r=lcnr
Uplift outlives components to `rustc_type_ir`

We need this to uplift `push_outlives_components`, since the elaborator uses `push_outlives_components` to elaborate type outlives obligations and I want to uplift elaboration.

This ends up reworking and inlining a fair portion of the `GenericArg::walk_shallow` function, whose only callsite was this one. I believe I got the logic correct, but may be worthwhile to look at it closely just in case. Unfortunately github was too dumb to understand that this is a rename + change -- I could also rework the git history to split the "copy the file over" part from the actual logical changes if that makes this easier to review.

r? lcnr
2024-07-06 14:55:23 -04:00
bors
8a8ad3433e Auto merge of #127388 - compiler-errors:elaboration-tweaks, r=lcnr
Elaboration tweaks

Removes `Filter::OnlySelfThatDefines` and reimplements `transitive_bounds_that_define_assoc_item` as a separate function, since I don't want to have to uplift that mode since it's both an implementation detail (only exists to avoid cycles in astconv) and requires exposing `Ident` as an associated type on `Interner`.

r? lcnr
2024-07-06 15:56:16 +00:00
yukang
81c86ddf8e show fnsig's output when there is difference 2024-07-06 23:29:58 +08:00
Ralf Jung
f6c377c350 offset_from intrinsic: always allow pointers to point to the same address 2024-07-06 17:14:26 +02:00
Michael Goulet
c2a88ea6ca Remove walk_shallow 2024-07-06 10:47:46 -04:00
Michael Goulet
cc6c5de39d Import via rustc_type_ir::outlives
We could use rustc_middle::ty::outlives I guess?
2024-07-06 10:47:46 -04:00
Michael Goulet
23c6f23b21 Uplift push_outlives_components 2024-07-06 10:47:46 -04:00
Michael Goulet
e5d6a416e8 Uplift PredicateEmittingRelation first 2024-07-06 10:05:49 -04:00
yukang
f46c4129e0 show unit output when there is only output diff in diagnostics 2024-07-06 21:00:30 +08:00
Vadim Petrochenkov
83cf471361 out_of_scope_macro_calls: Detect calls inside attributes more precisely 2024-07-06 15:36:30 +03:00
Camille GILLOT
0184c6f52e Cache hir_owner_nodes in ParentHirIterator. 2024-07-06 11:56:37 +00:00
Matthias Krüger
1e0028197f
Rollup merge of #127391 - estebank:null_mut, r=cjgillot
Use verbose suggestion for `ptr::null_mut()`
2024-07-06 13:26:26 +02:00
Matthias Krüger
2137d19ef6
Rollup merge of #127275 - RalfJung:offset-from-isize-min, r=Amanieu
offset_from, offset: clearly separate safety requirements the user needs to prove from corollaries that automatically follow

By landing https://github.com/rust-lang/rust/pull/116675 we decided that objects larger than `isize::MAX` cannot exist in the address space of a Rust program, which lets us simplify these rules.

For `offset_from`, we can even state that the *absolute* distance fits into an `isize`, and therefore exclude `isize::MIN`. This PR also changes Miri to treat an `isize::MIN` difference like the other isize-overflowing cases.
2024-07-06 13:26:25 +02:00
Camille Gillot
12edc8db87
Update compiler/rustc_mir_transform/src/gvn.rs
Co-authored-by: Michael Goulet <michael@errs.io>
2024-07-06 12:45:23 +02:00
Jubilee
853148752f
Rollup merge of #127392 - estebank:arg-type, r=jieyouxu
Use verbose suggestion for changing arg type
2024-07-05 23:23:36 -07:00
Jubilee
d0f61ce214
Rollup merge of #127383 - estebank:arg-removal, r=compiler-errors
Use verbose style for argument removal suggestion
2024-07-05 23:23:36 -07:00
Jubilee
3ba4195a68
Rollup merge of #127369 - Jules-Bertholet:match-ergonomics-2021, r=Nadrieril
Match ergonomics 2024: align with RFC again

- `&` matches `&mut` on old editions
- Add some more tests

r? ``@Nadrieril``

cc https://github.com/rust-lang/rust/issues/123076

``@rustbot`` label A-edition-2024 A-patterns
2024-07-05 23:23:35 -07:00
trevyn
09b3fcebf4
Correct description of E0502 2024-07-06 09:13:14 +03:00
Michael Goulet
aeb1a65dbf
Rollup merge of #127368 - YohDeadfall:dots-in-docs, r=fmease
Added dots at the sentence ends of rustc AST doc

Just a tiny improvement for the AST documentation by bringing consistency to sentence ends. I intentionally didn't terminate every sentence, there are still some members not having them, but at least there's no mixing style on the type level.
2024-07-05 20:49:34 -04:00
Michael Goulet
a3535b963b
Rollup merge of #127366 - oli-obk:falliblevisitor, r=compiler-errors
Use `ControlFlow` results for visitors that are only looking for a single value

These visitors all had a `Option<Value>` or `bool` field, that, once set, was never unset or modified again. They have been refactored by removing the field and returning `ControlFlow` directly from the visitor
2024-07-05 20:49:34 -04:00
Michael Goulet
16ba4b773d
Rollup merge of #127333 - compiler-errors:infer_ctxt_like-again, r=lcnr
Split `SolverDelegate` back out from `InferCtxtLike`

This is because in order to uplift things like the `Generalizer` and other `TypeRelation`s, we want to be able to interface with `InferCtxtLike` (and `InferCtxt` as its implementation), rather that `SolverDelegate`, which only really exists as a hack to be able to define some downstream methods in `rustc_type_ir`.

r? lcnr
2024-07-05 20:49:32 -04:00
Michael Goulet
865518d1f2
Rollup merge of #127221 - Urgau:check-cfg-std-diag, r=pnkfelix
Improve well known value check-cfg diagnostic for the standard library

This PR adjust the current logic for hidding the rustc/Cargo suggestion to add a value to a well-known name to exclude the standard library and rustc crates.

This is done in order to improve the contributor experience, in particular when adding a new target, which often requires adding some cfgs like `target_os` which may not be available yet in stage0.

<details>

The diagnostic code would look like this.

```text
error: unexpected `cfg` condition value: `blable`
   --> library/core/src/lib.rs:369:7
    |
369 | #[cfg(target_os = "blable")]
    |       ^^^^^^^^^^^^^^^^^^^^
    |
    = note: expected values for `target_os` are: `aix`, `android`, `cuda`, `dragonfly`, `emscripten`, `espidf`, `freebsd`, `fuchsia`, `haiku`, `hermit`, `horizon`, `hurd`, `illumos`, `ios`, `l4re`, `linux`, `macos`, `netbsd`, `none`, `nto`, `openbsd`, `psp`, `redox`, `solaris`, `solid_asp3`, `teeos`, `tvos`, `uefi`, `unknown`, `visionos`, `vita`, `vxworks`, `wasi`, `watchos`, and `windows` and 2 more
    = help: consider using a Cargo feature instead
    = help: or consider adding in `Cargo.toml` the `check-cfg` lint config for the lint:
             [lints.rust]
             unexpected_cfgs = { level = "warn", check-cfg = ['cfg(target_os, values("blable"))'] }
    = help: or consider adding `println!("cargo::rustc-check-cfg=cfg(target_os, values(\"blable\"))");` to the top of the `build.rs`
    = note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg/cargo-specifics.html> for more information about checking conditional configuration
    = note: `-D unexpected-cfgs` implied by `-D warnings`
    = help: to override `-D warnings` add `#[allow(unexpected_cfgs)]`
```

</details>
2024-07-05 20:49:32 -04:00
Michael Goulet
31fe9628cf
Rollup merge of #127107 - mu001999-contrib:dead/enhance-2, r=pnkfelix
Improve dead code analysis

Fixes #120770

1. check impl items later if self ty is private although the trait method is public, cause we must use the ty firstly if it's private
2. mark the adt live if it appears in pattern, like generic argument, this implies the use of the adt
3. based on the above, we can handle the case that private adts impl Default, so that we don't need adding rustc_trivial_field_reads on Default, and the logic in should_ignore_item

r? ``@pnkfelix``
2024-07-05 20:49:31 -04:00
Michael Goulet
99429a6a18 Split out transitive_bounds_that_define_assoc_item 2024-07-05 20:21:16 -04:00
Camille GILLOT
b97f83b27f Verify that allocations output by GVN are sufficiently aligned. 2024-07-05 22:59:10 +00:00
Esteban Küber
75692056e1 Use verbose suggestion for changing arg type 2024-07-05 20:58:33 +00:00
Michael Goulet
27588d1de3 Split SolverDelegate back out from InferCtxtLike 2024-07-05 16:39:39 -04:00
Esteban Küber
fca286a39e Use verbose suggestion for ptr::null_mut() 2024-07-05 20:38:21 +00:00
Maybe Lapkin
073f3a263b Equate types instead of using Unsize 2024-07-05 22:35:14 +02:00
Michael Goulet
e5412da723 Supertrait elaboration doesn't need to use Predicates 2024-07-05 15:51:53 -04:00
Esteban Küber
8e9a3661a8 Use verbose style for argument removal suggestion 2024-07-05 19:40:09 +00:00
Michael Goulet
465e7d546e Rework receiver_is_valid 2024-07-05 11:59:54 -04:00
Michael Goulet
fb8d5f1e13 Actually just make can_eq process obligations (almost) everywhere 2024-07-05 11:59:54 -04:00
Michael Goulet
fdde66acee Process alias-relate obligations when proving receiver_is_valid 2024-07-05 11:59:52 -04:00
Jules Bertholet
5a35fc446e
Match ergonomics 2024: & matches &mut on old editions 2024-07-05 11:17:13 -04:00
Yoh Deadfall
291ed596f7 Added dots at the sentence ends of rustc AST doc 2024-07-05 18:10:05 +03:00
Oli Scherer
7dca61b68b Use ControlFlow results for visitors that are only looking for a single value 2024-07-05 15:00:40 +00:00
Alona Enraght-Moony
f763d62149 Fix a few doc comment for compiler-interal API docs.
They only used `//` instead of `///` so weren't picked up by rustdoc.
2024-07-05 14:14:35 +00:00
bors
11dd90f761 Auto merge of #127360 - GuillaumeGomez:rollup-f0zs1qr, r=GuillaumeGomez
Rollup of 7 pull requests

Successful merges:

 - #124290 (DependencyList: removed outdated comment)
 - #126709 (Migrate `include_bytes_deps`, `optimization-remarks-dir-pgo`, `optimization-remarks-dir`, `issue-40535` and `rmeta-preferred` `run-make` tests to rmake)
 - #127214 (Use the native unwind function in miri where possible)
 - #127320 (Update windows-bindgen to 0.58.0)
 - #127349 (Tweak `-1 as usize` suggestion)
 - #127352 (coverage: Rename `mir::coverage::BranchInfo` to `CoverageInfoHi`)
 - #127359 (Improve run make llvm ident code)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-07-05 11:32:40 +00:00
Guillaume Gomez
e4d7f7c9e6
Rollup merge of #127352 - Zalathar:coverage-info, r=oli-obk
coverage: Rename `mir::coverage::BranchInfo` to `CoverageInfoHi`

This opens the door to collecting and storing coverage information that is unrelated to branch coverage or MC/DC, during MIR building.

There is no change to the output of coverage instrumentation, but one deliberate change is that functions now *always* have an attached `CoverageInfoHi` (if coverage is enabled and they are eligible), even if they didn't collect any interesting branch information.

---

`@rustbot` label +A-code-coverage
2024-07-05 11:33:17 +02:00
Guillaume Gomez
6d3f2b1040
Rollup merge of #127349 - estebank:negative-unsigned-literal, r=petrochenkov
Tweak `-1 as usize` suggestion

When writing a negative unsigned integer literal, use a verbose suggestion and account for `as` casting.
2024-07-05 11:33:17 +02:00
Guillaume Gomez
7a79392c82
Rollup merge of #124290 - klensy:dep-format, r=jieyouxu
DependencyList: removed outdated comment

Comment was outdated. Didn't updated description, as `Linkage` enum have descriptive names.

Also added fixme about moving this file to rustc_metadata.
2024-07-05 11:33:14 +02:00
bors
2ad6630673 Auto merge of #127008 - Jules-Bertholet:tc-ergonomics, r=Nadrieril
Match ergonomics 2024: Implement TC's match ergonomics proposal

Under gate `ref_pat_eat_one_layer_2024_structural`. Enabling `ref_pat_eat_one_layer_2024` at the same time allows the union of what the individual gates allow. `@traviscross`

r? `@Nadrieril`

cc https://github.com/rust-lang/rust/issues/123076

`@rustbot` label A-edition-2024 A-patterns
2024-07-05 09:10:17 +00:00
Zalathar
f96f443631 Tweak how the extra newline is printed after coverage info 2024-07-05 13:53:05 +10:00
Zalathar
f095de4bf1 coverage: Rename mir::coverage::BranchInfo to CoverageInfoHi
This opens the door to collecting and storing coverage information that is
unrelated to branch coverage or MC/DC.
2024-07-05 13:53:05 +10:00
bors
51917ba8f2 Auto merge of #126171 - RalfJung:simd_bitmask_multibyte, r=workingjubilee
simd_bitmask intrinsic: add a non-power-of-2 multi-byte example

r? `@calebzulawski` `@workingjubilee`
2024-07-05 01:58:22 +00:00
Esteban Küber
86a19467c1 Tweak -1 as usize suggestion
When writing a negative unsigned integer literal, use a verbose suggestion and account for `as` casting.
2024-07-05 00:52:01 +00:00
bors
489233170a Auto merge of #123781 - RalfJung:miri-fn-identity, r=oli-obk
Miri function identity hack: account for possible inlining

Having a non-lifetime generic is not the only reason a function can be duplicated. Another possibility is that the function may be eligible for cross-crate inlining. So also take into account the inlining attribute in this Miri hack for function pointer identity.

That said, `cross_crate_inlinable` will still sometimes return true even for `inline(never)` functions:
- when they are `DefKind::Ctor(..) | DefKind::Closure` -- I assume those cannot be `InlineAttr::Never` anyway?
- when `cross_crate_inline_threshold == InliningThreshold::Always`

so maybe this is still not quite the right criterion to use for function pointer identity.
2024-07-04 23:45:56 +00:00
Nicholas Nethercote
dd790ab8ef Remove some unnecessary integer conversions.
These should have been removed in #127233 when the positions were
changed from `usize` to `u32`.
2024-07-05 08:27:17 +10:00
bors
cc8da78a03 Auto merge of #127288 - lqd:typelen-cache, r=compiler-errors
cache type sizes in type-size limit visitor

This is basically https://github.com/rust-lang/rust/pull/125507#issuecomment-2206813779 as lcnr can't open the PR now.

Locally it reduces the `itertools` regression by quite a bit, to "only +50%" compared to nightly (that includes overhead from the local lack of artifact post-processing, and is just a data point to compare to the 10-20x timings without the cache).

```console
Benchmark 1: cargo +stage1 build --release
  Time (mean ± σ):      2.721 s ±  0.009 s    [User: 2.446 s, System: 0.325 s]
  Range (min … max):    2.710 s …  2.738 s    10 runs

Benchmark 2: cargo +nightly build --release
  Time (mean ± σ):      1.784 s ±  0.005 s    [User: 1.540 s, System: 0.279 s]
  Range (min … max):    1.778 s …  1.792 s    10 runs

Summary
  cargo +nightly build --release ran
    1.52 ± 0.01 times faster than cargo +stage1 build --release
```

On master, it's from 34s to the 2.7s above.

r? compiler-errors
2024-07-04 21:17:19 +00:00
Maybe Lapkin
56de9da1f8 Sort trait names before printing 2024-07-04 18:38:18 +02:00
bors
8a9cccb100 Auto merge of #127326 - matthiaskrgr:rollup-kz7vd3w, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - #123043 (Disable dead variant removal for `#[repr(C)]` enums.)
 - #126405 (Migrate some rustc_builtin_macros to SessionDiagnostic)
 - #127037 (Remove some duplicated tests)
 - #127283 (Reject SmartPointer constructions not serving the purpose)
 - #127301 (Tweak some structured suggestions to be more verbose and accurate)
 - #127307 (Allow to have different types for arguments of `Rustc::remap_path_prefix`)
 - #127309 (jsondocck: add `$FILE` built-in variable)
 - #127314 (Trivial update on tidy bless note)
 - #127319 (Remove a use of `StructuredDiag`, which is incompatible with automatic error tainting and error translations)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-07-04 16:37:39 +00:00
Matthias Krüger
dd42f7a0a6
Rollup merge of #127319 - oli-obk:fail2taint, r=compiler-errors
Remove a use of `StructuredDiag`, which is incompatible with automatic error tainting and error translations

fixes #127219

I want to remove all of `StructuredDiag`, but it's a bit more involved as it is also used from the `ItemCtxt`, which doesn't support tainting yet.
2024-07-04 18:16:26 +02:00
Matthias Krüger
54bd3a7b8d
Rollup merge of #127301 - estebank:fix-suggestions, r=Urgau
Tweak some structured suggestions to be more verbose and accurate

Addressing some issues I found while working on #127282.
```
error: this URL is not a hyperlink
  --> $DIR/auxiliary/include-str-bare-urls.md:1:11
   |
LL | HEADS UP! https://example.com MUST SHOW UP IN THE STDERR FILE!
   |           ^^^^^^^^^^^^^^^^^^^
   |
   = note: bare URLs are not automatically turned into clickable links
note: the lint level is defined here
  --> $DIR/include-str-bare-urls.rs:14:9
   |
LL | #![deny(rustdoc::bare_urls)]
   |         ^^^^^^^^^^^^^^^^^^
help: use an automatic link instead
   |
LL | HEADS UP! <https://example.com> MUST SHOW UP IN THE STDERR FILE!
   |           +                   +
```
```
error[E0384]: cannot assign twice to immutable variable `v`
  --> $DIR/assign-imm-local-twice.rs:7:5
   |
LL |     v = 1;
   |     ----- first assignment to `v`
LL |     println!("v={}", v);
LL |     v = 2;
   |     ^^^^^ cannot assign twice to immutable variable
   |
help: consider making this binding mutable
   |
LL |     let mut v: isize;
   |         +++
```
```
error[E0393]: the type parameter `Rhs` must be explicitly specified
  --> $DIR/issue-22560.rs:9:23
   |
LL | trait Sub<Rhs=Self> {
   | ------------------- type parameter `Rhs` must be specified for this
...
LL | type Test = dyn Add + Sub;
   |                       ^^^
   |
   = note: because of the default `Self` reference, type parameters must be specified on object types
help: set the type parameter to the desired type
   |
LL | type Test = dyn Add + Sub<Rhs>;
   |                          +++++
```
```
error[E0596]: cannot borrow `v` as mutable, as it is not declared as mutable
  --> $DIR/issue-33819.rs:4:34
   |
LL |         Some(ref v) => { let a = &mut v; },
   |                                  ^^^^^^ cannot borrow as mutable
   |
help: try removing `&mut` here
   |
LL -         Some(ref v) => { let a = &mut v; },
LL +         Some(ref v) => { let a = v; },
   |
```
```
help: remove the invocation before committing it to a version control system
   |
LL -     dbg!();
   |
```
```
error[E0308]: mismatched types
  --> $DIR/issue-39974.rs:1:21
   |
LL | const LENGTH: f64 = 2;
   |                     ^ expected `f64`, found integer
   |
help: use a float literal
   |
LL | const LENGTH: f64 = 2.0;
   |                      ++
```
```
error[E0529]: expected an array or slice, found `Vec<i32>`
  --> $DIR/match-ergonomics.rs:8:9
   |
LL |         [&v] => {},
   |         ^^^^ pattern cannot match with input type `Vec<i32>`
   |
help: consider slicing here
   |
LL |     match x[..] {
   |            ++++
```
```
error[E0609]: no field `0` on type `[u32; 1]`
  --> $DIR/parenthesized-deref-suggestion.rs:10:21
   |
LL |     (x as [u32; 1]).0;
   |                     ^ unknown field
   |
help: instead of using tuple indexing, use array indexing
   |
LL |     (x as [u32; 1])[0];
   |                    ~ +
```
2024-07-04 18:16:24 +02:00