Commit Graph

33049 Commits

Author SHA1 Message Date
Mads Marquart
dae22a598b Fix cfg(target_abi = "sim") on i386-apple-ios
i386-apple-ios is also a simulator target
2024-02-17 01:15:08 +01:00
Michael Goulet
228441dbd6 Use fulfillment in next trait solver coherence 2024-02-16 23:53:09 +00:00
Nicholas Nethercote
ede99234c4 Make CodegenBackend::join_codegen infallible.
Because they all are, in practice.
2024-02-17 10:51:35 +11:00
lcnr
f65e743748 add fixme 2024-02-17 00:26:57 +01:00
lcnr
42e7338eae rename needs_wf and clarify comment 2024-02-17 00:25:49 +01:00
Nicholas Nethercote
e72e7e9ae3 Merge CompilerError::CompilationFailed and CompilerError::ICE.
`CompilerError` has `CompilationFailed` and `ICE` variants, which seems
reasonable at first. But the way it identifies them is flawed:
- If compilation errors out, i.e. `RunCompiler::run` returns an `Err`,
  it uses `CompilationFailed`, which is reasonable.
- If compilation panics with `FatalError`, it catches the panic and uses
  `ICE`. This is sometimes right, because ICEs do cause `FatalError`
  panics, but sometimes wrong, because certain compiler errors also
  cause `FatalError` panics. (The compiler/rustdoc/clippy/whatever just
  catches the `FatalError` with `catch_with_exit_code` in `main`.)

In other words, certain non-ICE compilation failures get miscategorized
as ICEs. It's not possible to reliably distinguish the two cases, so
this commit merges them. It also renames the combined variant as just
`Failed`, to better match the existing `Interrupted` and `Skipped`
variants.

Here is an example of a non-ICE failure that causes a `FatalError`
panic, from `tests/ui/recursion_limit/issue-105700.rs`:
```
 #![recursion_limit="4"]
 #![invalid_attribute]
 #![invalid_attribute]
 #![invalid_attribute]
 #![invalid_attribute]
 #![invalid_attribute]
 //~^ERROR recursion limit reached while expanding

 fn main() {{}}
```
2024-02-17 09:40:44 +11:00
Oli Scherer
dd40a80102 Give the (un)likely intrinsics fallback bodies 2024-02-16 22:26:01 +00:00
Oli Scherer
6a671bdbf1 Give the assume intrinsic a fallback body 2024-02-16 22:24:50 +00:00
Tshepang Mbambo
3a917cdfcb make "invalid fragment specifier" translatable 2024-02-16 20:15:07 +02:00
Guillaume Gomez
f82875e242
Rollup merge of #121181 - oli-obk:normalize_with_conflicting_impls, r=cjgillot
Fix an ICE in the recursion lint

fixes #121170

I looked into it, and there is no good path towards tainting mir_build (where the ICE happens), but using `try_normalize` in a lint seems generally better anyway
2024-02-16 17:08:14 +01:00
Guillaume Gomez
0c92146034
Rollup merge of #121179 - RalfJung:zst-mutable-refs, r=oli-obk
allow mutable references in const values when they point to no memory

Fixes https://github.com/rust-lang/rust/issues/120450

The second commit is just some drive-by test suite cleanup.

r? `@oli-obk`
2024-02-16 17:08:13 +01:00
Guillaume Gomez
f60576b3df
Rollup merge of #121137 - GuillaumeGomez:add-clippy-cfg, r=Urgau,Nilstrieb
Add clippy into the known `cfg` list

In clippy, we are removing the `feature = "cargo-clippy"` cfg to replace it with `clippy` in https://github.com/rust-lang/rust-clippy/pull/12292. But for it to work, we need to declare `clippy` as cfg. It makes it more coherent with other existing tools like rustdoc.

cc `@flip1995`
2024-02-16 17:08:13 +01:00
Guillaume Gomez
670bdbf808
Rollup merge of #121111 - trevyn:associated-type-suggestion, r=davidtwco
For E0038, suggest associated type if available

Closes #116434
2024-02-16 17:08:12 +01:00
Guillaume Gomez
e5a743c4c2
Rollup merge of #121020 - oli-obk:diagnostics_ice, r=davidtwco
Avoid an ICE in diagnostics

fixes #121004

just a slice usage in diagnostics code. Sadly we can't yet bubble the `ErrorGuaranteed` from wf check to borrowck for these cases, as that causes cycle errors iirc
2024-02-16 17:08:12 +01:00
Guillaume Gomez
f81fd901db
Rollup merge of #119928 - d-sonuga:into-iter-sugg, r=compiler-errors
suggest `into_iter()` when `Iterator` method called on `impl IntoIterator`

Fix for issue #117711.
2024-02-16 17:08:11 +01:00
Michael Goulet
f624d55ea7 Nits 2024-02-16 15:07:37 +00:00
Michael Goulet
a9dbf63087 Move trait into attr so it's greppable 2024-02-16 15:07:37 +00:00
Michael Goulet
9c25823bb4 Use extension trait derive 2024-02-16 15:07:37 +00:00
Michael Goulet
3250e95305 Add a simple extension trait derive 2024-02-16 15:07:37 +00:00
bors
dfa88b328f Auto merge of #120500 - oli-obk:intrinsics2.0, r=WaffleLapkin
Implement intrinsics with fallback bodies

fixes #93145 (though we can port many more intrinsics)
cc #63585

The way this works is that the backend logic for generating custom code for intrinsics has been made fallible. The only failure path is "this intrinsic is unknown". The `Instance` (that was `InstanceDef::Intrinsic`) then gets converted to `InstanceDef::Item`, which represents the fallback body. A regular function call to that body is then codegenned. This is currently implemented for

* codegen_ssa (so llvm and gcc)
* codegen_cranelift

other backends will need to adjust, but they can just keep doing what they were doing if they prefer (though adding new intrinsics to the compiler will then require them to implement them, instead of getting the fallback body).

cc `@scottmcm` `@WaffleLapkin`

### todo

* [ ] miri support
* [x] default intrinsic name to name of function instead of requiring it to be specified in attribute
* [x] make sure that the bodies are always available (must be collected for metadata)
2024-02-16 09:53:01 +00:00
Oli Scherer
db4ba498d9 Fix an ICE in the recursion lint 2024-02-16 09:29:39 +00:00
Ralf Jung
0702701297 allow mutable references in const values when they point to no memory 2024-02-16 10:09:12 +01:00
bors
1be468815c Auto merge of #120486 - reitermarkus:use-generic-nonzero, r=dtolnay
Use generic `NonZero` internally.

Tracking issue: https://github.com/rust-lang/rust/issues/120257
2024-02-16 07:46:31 +00:00
Esteban Küber
9b3fcf9ad4 Detect when method call on argument could be removed to fulfill failed trait bound
When encountering

```rust
struct Foo;
struct Bar;
impl From<Bar> for Foo {
    fn from(_: Bar) -> Self { Foo }
}
fn qux(_: impl From<Bar>) {}
fn main() {
    qux(Bar.into());
}
```

Suggest removing `.into()`:

```
error[E0283]: type annotations needed
 --> f100.rs:8:13
  |
8 |     qux(Bar.into());
  |     ---     ^^^^
  |     |
  |     required by a bound introduced by this call
  |
  = note: cannot satisfy `_: From<Bar>`
note: required by a bound in `qux`
 --> f100.rs:6:16
  |
6 | fn qux(_: impl From<Bar>) {}
  |                ^^^^^^^^^ required by this bound in `qux`
help: try using a fully qualified path to specify the expected types
  |
8 |     qux(<Bar as Into<T>>::into(Bar));
  |         +++++++++++++++++++++++   ~
help: consider removing this method call, as the receiver has type `Bar` and `Bar: From<Bar>` can be fulfilled
  |
8 -     qux(Bar.into());
8 +     qux(Bar);
  |
```

Fix #71252
2024-02-16 04:28:05 +00:00
Zalathar
cd9021e8cb coverage: Discard spans that fill the entire function body
When we try to extract coverage-relevant spans from MIR, sometimes we see MIR
statements/terminators whose spans cover the entire function body. Those spans
tend to be unhelpful for coverage purposes, because they often represent
compiler-inserted code, e.g. the implicit return value of `()`.
2024-02-16 10:57:03 +11:00
Guillaume Gomez
e84a1dd87f
Rollup merge of #121147 - tmiasko:no-debug-body, r=compiler-errors
Avoid debug logging entire MIR body

If there is a need to examine the MIR body there is -Zmir-dump.
2024-02-16 00:27:35 +01:00
Guillaume Gomez
77eaa80d5c
Rollup merge of #121146 - compiler-errors:ignore-diverging-arms, r=estebank
Only point out non-diverging arms for match suggestions

Fixes #121144

There is no reason to point at diverging arms, which will always coerce to whatever is the match block's evaluated type.

This also removes the suggestion from #106601, since as I pointed out in https://github.com/rust-lang/rust/issues/72634#issuecomment-1946210898 the added suggestion is not firing in the right cases, but instead only when one of the match arms already *actually* evaluates to `()`.

r? estebank
2024-02-16 00:27:34 +01:00
Guillaume Gomez
d6e2fc5589
Rollup merge of #121145 - adamgemmell:dev/adagem01/combined-target-features, r=Amanieu
Update aarch64 target feature docs to match LLVM

https://github.com/rust-lang/stdarch/issues/1432 https://github.com/rust-lang/stdarch/pull/1527

r? ```@Amanieu```
2024-02-16 00:27:34 +01:00
Guillaume Gomez
12a73a6bbe
Rollup merge of #121141 - compiler-errors:closure-kind-docs, r=nnethercote
Fix closure kind docs

I didn't review this close enough lol -- the old code snippet didn't use substs correctly, and had a malformed `if let`
2024-02-16 00:27:34 +01:00
Guillaume Gomez
ddad818b7a
Rollup merge of #121119 - compiler-errors:async-fn-kind-errs, r=oli-obk
Make `async Fn` trait kind errors better

1. Make it so that async closures with the wrong closurekind actually report a useful error
2. Explain why async closures can sometimes not implement `Fn`/`FnMut` (because they capture things)

r? oli-obk
2024-02-16 00:27:33 +01:00
Guillaume Gomez
c73aa787f6
Rollup merge of #121109 - nnethercote:TyKind-Err-guar-2, r=oli-obk
Add an ErrorGuaranteed to ast::TyKind::Err (attempt 2)

This makes it more like `hir::TyKind::Err`, and avoids a `has_errors` assertion in `LoweringContext::lower_ty_direct`.

r? ```@oli-obk```
2024-02-16 00:27:32 +01:00
bors
a4472498d7 Auto merge of #121133 - tmiasko:skip-coroutines, r=cjgillot
Skip coroutines in jump threading to avoid query cycles

Fixes #121094
2024-02-15 21:30:25 +00:00
bors
b656f5171b Auto merge of #119338 - compiler-errors:upcast-plus-autos, r=lcnr
Consider principal trait ref's auto-trait super-traits in dyn upcasting

Given traits like:

```rust
trait Subtrait: Supertrait + Send {}
trait Supertrait {}
```

We should be able to upcast `dyn Subtrait` to `dyn Supertrait + Send`. This is not currently possible, because when upcasting, we look at the list of auto traits in the object type (`dyn Subtrait`, which has no auto traits in its bounds) and compare them to the target's auto traits (`dyn Supertrait + Send`, which has `Send` in its bound).

Since the target has auto traits that are not present in the source, the upcasting fails. This is overly restrictive, since `dyn Subtrait` will always implement `Send` via its built-in object impl. I propose to loosen this restriction here.

r? types

---

### ~~Aside: Fix this in astconv instead?~~

### edit: This causes too many failures. See https://github.com/rust-lang/rust/pull/119825#issuecomment-1890847150

We may also fix this by by automatically elaborating all auto-trait supertraits during `AstConv::conv_object_ty_poly_trait_ref`. That is, we can make it so that `dyn Subtrait` is elaborated into the same type of `dyn Subtrait + Send`.

I'm open to considering this solution instead, but it would break coherence in the following example:

```rust
trait Foo: Send {}

trait Bar {}
impl Bar for dyn Foo {}
impl Bar for dyn Foo + Send {}
//~^ This would begin to be an overlapping impl.
```
2024-02-15 19:16:06 +00:00
Michael Goulet
954d56591c Fix closure kind docs 2024-02-15 18:44:49 +00:00
Michael Goulet
6018e21d8a Remove a suggestion that is redundant 2024-02-15 17:20:44 +00:00
bors
cbddf31863 Auto merge of #121142 - GuillaumeGomez:rollup-5qmksjw, r=GuillaumeGomez
Rollup of 8 pull requests

Successful merges:

 - #120449 (Document requirements for unsized {Rc,Arc}::from_raw)
 - #120505 (Fix BTreeMap's Cursor::remove_{next,prev})
 - #120672 (std::thread update freebsd stack guard handling.)
 - #121088 (Implicitly enable evex512 if avx512 is enabled)
 - #121104 (Ignore unsized types when trying to determine the size of the original type)
 - #121107 (Fix msg for verbose suggestions with confusable capitalization)
 - #121113 (Continue compilation even if inherent impl checks fail)
 - #121120 (Add `ErrorGuaranteed` to `ast::LitKind::Err`, `token::LitKind::Err`.)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-02-15 17:00:55 +00:00
Michael Goulet
acb201af54 make better async fn kind errors 2024-02-15 15:59:35 +00:00
Michael Goulet
c763f833d1 Only point out non-diverging arms for match suggestions 2024-02-15 15:44:46 +00:00
Michael Goulet
ec8e898193 Consider principal trait ref's auto-trait super-traits in dyn upcasting 2024-02-15 15:38:11 +00:00
Tomasz Miąsko
5d65b1954e Avoid debug logging entire MIR body
If there is a need to examine the MIR body there is -Zmir-dump.
2024-02-15 15:54:28 +01:00
Adam Gemmell
cc7b4e02be Update aarch64 target feature docs to match LLVM 2024-02-15 14:36:29 +00:00
Guillaume Gomez
533e3f0a84 Add comment to remind devs to update the unstable book related chapter if the check-cfg list is updated 2024-02-15 15:23:07 +01:00
Guillaume Gomez
06f53dd316
Rollup merge of #121120 - nnethercote:LitKind-Err-guar, r=fmease
Add `ErrorGuaranteed` to `ast::LitKind::Err`, `token::LitKind::Err`.

Similar to recent work doing the same for `ExprKind::Err` (#120586) and `TyKind::Err` (#121109).

r? `@oli-obk`
2024-02-15 14:33:03 +01:00
Guillaume Gomez
e878439d39
Rollup merge of #121113 - oli-obk:track_errors10, r=compiler-errors
Continue compilation even if inherent impl checks fail

We should not be hiding errors behind unrelated errors
2024-02-15 14:33:02 +01:00
Guillaume Gomez
3c8705402a
Rollup merge of #121107 - estebank:capitalization-suggestion, r=michaelwoerister
Fix msg for verbose suggestions with confusable capitalization

When encountering a verbose/multipart suggestion that has changes that are only caused by different capitalization of ASCII letters that have little differenciation, expand the message to highlight that fact (like we already do for inline suggestions).

The logic to do this was already present, but implemented incorrectly.
2024-02-15 14:33:02 +01:00
Guillaume Gomez
12d70af446
Rollup merge of #121104 - Urgau:bigger_layout-fix-fp, r=compiler-errors
Ignore unsized types when trying to determine the size of the original type

Fixes https://github.com/rust-lang/rust/issues/121074 a regression from https://github.com/rust-lang/rust/pull/118983
2024-02-15 14:33:01 +01:00
Guillaume Gomez
7d6c99dd06
Rollup merge of #121088 - nikic:evex512, r=Amanieu
Implicitly enable evex512 if avx512 is enabled

LLVM 18 requires the evex512 feature to allow use of zmm registers. LLVM automatically sets it when using a generic CPU, but not when `-C target-cpu` is specified. This will result either in backend legalization crashes, or code unexpectedly using ymm instead of zmm registers.

For now, make sure that `avx512*` features imply `evex512`. Long term we'll probably have to deal with the AVX10 mess somehow.

Fixes https://github.com/rust-lang/rust/issues/121081.

r? `@Amanieu`
2024-02-15 14:33:01 +01:00
Guillaume Gomez
0860fc14ae Add clippy into the known cfg list 2024-02-15 14:18:19 +01:00
bors
fa9f77ff35 Auto merge of #120931 - chenyukang:yukang-cleanup-hashmap, r=michaelwoerister
Clean up potential_query_instability with FxIndexMap and UnordMap

From https://github.com/rust-lang/rust/pull/120485#issuecomment-1916437191

r? `@michaelwoerister`
2024-02-15 12:36:37 +00:00
David Wood
b80fc5d4e8
errors: only eagerly translate subdiagnostics
Subdiagnostics don't need to be lazily translated, they can always be
eagerly translated. Eager translation is slightly more complex as we need
to have a `DiagCtxt` available to perform the translation, which involves
slightly more threading of that context.

This slight increase in complexity should enable later simplifications -
like passing `DiagCtxt` into `AddToDiagnostic` and moving Fluent messages
into the diagnostic structs rather than having them in separate files
(working on that was what led to this change).

Signed-off-by: David Wood <david@davidtw.co>
2024-02-15 10:34:41 +00:00
bors
6a4222b511 Auto merge of #116564 - oli-obk:evaluated_static_in_metadata, r=RalfJung,cjgillot
Store static initializers in metadata instead of the MIR of statics.

This means that adding generic statics would be even more difficult, as we can't evaluate statics from other crates anymore, but the subtle issue I have encountered make me think that having this be an explicit problem is better.

The issue is that

```rust
static mut FOO: &mut u32 = &mut 42;
static mut BAR = unsafe { FOO };
```

gets different allocations, instead of referring to the same one. This is also true for non-static mut, but promotion makes `static FOO: &u32 = &42;` annoying to demo.

Fixes https://github.com/rust-lang/rust/issues/61345

## Why is this being done?

In order to ensure all crates see the same nested allocations (which is the last issue that needs fixing before we can stabilize [`const_mut_refs`](https://github.com/rust-lang/rust/issues/57349)), I am working on creating anonymous (from the Rust side, to LLVM it's like a regular static item) static items for the nested allocations in a static. If we evaluate the static item in a downstream crate again, we will end up duplicating its nested allocations (and in some cases, like the `match` case, even duplicate the main allocation).
2024-02-15 10:28:31 +00:00
Oli Scherer
73b38c661d Do not allocate a second "background" alloc id for the main allocation of a static.
Instead we re-use the static's alloc id within the interpreter for its initializer to refer to the `Allocation` that only exists within the interpreter.
2024-02-15 10:25:18 +00:00
Oli Scherer
e2386270df Return ConstAllocation from eval_static_initializer query directly 2024-02-15 10:25:18 +00:00
Oli Scherer
be6ccf13e3 Store static initializers in metadata instead of the MIR of statics. 2024-02-15 10:25:18 +00:00
Oli Scherer
95004e5ae2 Add new query just for static initializers 2024-02-15 10:25:18 +00:00
Oli Scherer
fc9d1a8133 Split a bool argument into two named functions 2024-02-15 10:25:18 +00:00
bors
4ae1e79876 Auto merge of #121131 - matthiaskrgr:rollup-mo3b8nz, r=matthiaskrgr
Rollup of 10 pull requests

Successful merges:

 - #111106 (Add known issue of let binding to format_args doc)
 - #118749 (Make contributing to windows bindings easier)
 - #120982 (Add APIs for fetching foreign items )
 - #121022 (rustdoc: cross-crate re-exports: correctly render late-bound params in source order even if early-bound params are present)
 - #121082 (Clarified docs on non-atomic oprations on owned/mut refs to atomics)
 - #121084 (Make sure `tcx.create_def` also depends on the forever red node, instead of just `tcx.at(span).create_def`)
 - #121098 (Remove unnecessary else block from `thread_local!` expanded code)
 - #121105 (Do not report overflow errors on ConstArgHasType goals)
 - #121116 (Reinstate some delayed bugs.)
 - #121122 (Enforce coroutine-closure layouts are identical)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-02-15 08:29:42 +00:00
Matthias Krüger
829b59a47d
Rollup merge of #121122 - compiler-errors:identical-layouts, r=oli-obk
Enforce coroutine-closure layouts are identical

Enforce that for an async closure, the by-ref and by-move coroutine layouts are identical. This is just a sanity check to make sure that optimizations aren't doing anything fishy.

r? oli-obk
2024-02-15 09:20:23 +01:00
Matthias Krüger
4899108109
Rollup merge of #121116 - nnethercote:fix-121103-121108, r=oli-obk
Reinstate some delayed bugs.

These were changed to `has_errors` assertions in #121071 because that seemed reasonable, but evidently not.

Fixes #121103.
Fixes #121108.
2024-02-15 09:20:21 +01:00
Matthias Krüger
888fe709e6
Rollup merge of #121105 - compiler-errors:no-const-ty-overflow, r=oli-obk
Do not report overflow errors on ConstArgHasType goals

This is 10% of a fix for #121090, since it at least means that we no longer mention the `ConstArgHasType` goal as the cause for the overflow. Instead, now we mention:
```
overflow evaluating the requirement `{closure@$DIR/overflow-during-mono.rs:13:41: 13:44}: Sized`
```
which is not much better, but slightly.

r? oli-obk
2024-02-15 09:20:21 +01:00
Matthias Krüger
f62d981a18
Rollup merge of #121084 - oli-obk:create_def_forever_red2, r=WaffleLapkin
Make sure `tcx.create_def` also depends on the forever red node, instead of just `tcx.at(span).create_def`

oversight from https://github.com/rust-lang/rust/pull/119136

Not actually an issue, because all uses of `tcx.create_def` were in the resolver, which is `eval_always`, but still good to harden against future uses of `create_def`

cc `@petrochenkov` `@WaffleLapkin`
2024-02-15 09:20:20 +01:00
Matthias Krüger
71466ca804
Rollup merge of #120982 - momvart:smir-61-foreign_kind, r=oli-obk
Add APIs for fetching foreign items

Closes https://github.com/rust-lang/project-stable-mir/issues/61
2024-02-15 09:20:18 +01:00
Markus Reiter
a90cc05233
Replace NonZero::<_>::new with NonZero::new. 2024-02-15 08:09:42 +01:00
Markus Reiter
746a58d435
Use generic NonZero internally. 2024-02-15 08:09:42 +01:00
Nicholas Nethercote
ac47f6c666 Add suffixes to LitError.
To avoid some unwrapping.
2024-02-15 15:47:24 +11:00
Nicholas Nethercote
25ed6e43b0 Add ErrorGuaranteed to ast::LitKind::Err, token::LitKind::Err.
This mostly works well, and eliminates a couple of delayed bugs.

One annoying thing is that we should really also add an
`ErrorGuaranteed` to `proc_macro::bridge::LitKind::Err`. But that's
difficult because `proc_macro` doesn't have access to `ErrorGuaranteed`,
so we have to fake it.
2024-02-15 14:46:08 +11:00
Eric Huss
217e5e484d Fix SmallCStr conversion from CStr 2024-02-14 18:40:53 -08:00
Nicholas Nethercote
332c57723a Make emit_unescape_error return Option<ErrorGuaranteed>.
And use the result in `cook_common` to decide whether to return an error
token.
2024-02-15 12:58:18 +11:00
Nicholas Nethercote
a513bb20c3 Make report_lit_error return ErrorGuaranteed.
This will be helpful for subsequent commits.
2024-02-15 12:58:18 +11:00
Nicholas Nethercote
8b35f8e41e Remove LitError::LexerError.
`cook_lexer_literal` can emit an error about an invalid int literal but
then return a non-`Err` token. And then `integer_lit` has to account for
this to avoid printing a redundant error message.

This commit changes `cook_lexer_literal` to return `Err` in that case.
Then `integer_lit` doesn't need the special case, and
`LitError::LexerError` can be removed.
2024-02-15 12:58:18 +11:00
Michael Goulet
e6a21f549e Enforce coroutine-closure layouts are identical 2024-02-15 01:18:09 +00:00
Tomasz Miąsko
5f4e4baddb Skip coroutines in jump threading to avoid query cycles 2024-02-15 00:00:00 +00:00
Nicholas Nethercote
5233bc91da Add an ErrorGuaranteed to ast::TyKind::Err.
This makes it more like `hir::TyKind::Err`, and avoids a
`span_delayed_bug` call in `LoweringContext::lower_ty_direct`.

It also requires adding `ast::TyKind::Dummy`, now that
`ast::TyKind::Err` can't be used for that purpose in the absence of an
error emission.

There are a couple of cases that aren't as neat as I would have liked,
marked with `FIXME` comments.
2024-02-15 09:35:11 +11:00
Nicholas Nethercote
64a9c9cfea Reinstate some delayed bugs.
These were changed to `has_errors` assertions in #121071 because that
seemed reasonable, but evidently not.

Fixes #121103.
Fixes #121108.
2024-02-15 09:26:45 +11:00
Oli Scherer
c1bb352c8b Continue compilation even if inherent impl checks fail 2024-02-14 21:04:51 +00:00
trevyn
220e8a7484 For E0038, suggest associated type if available 2024-02-14 12:42:32 -08:00
Esteban Küber
8d4d572e4d Fix msg for verbose suggestions with confusable capitalization
When encountering a verbose/multipart suggestion that has changes
that are only caused by different capitalization of ASCII letters that have
little differenciation, expand the message to highlight that fact (like we
already do for inline suggestions).

The logic to do this was already present, but implemented incorrectly.
2024-02-14 20:15:13 +00:00
bors
ee9c7c940c Auto merge of #120847 - oli-obk:track_errors9, r=compiler-errors
Continue compilation after check_mod_type_wf errors

The ICEs fixed here were probably reachable through const eval gymnastics before, but now they are easily reachable without that, too.

The new errors are often bugfixes, where useful errors were missing, because they were reported after the early abort. In other cases sometimes they are just duplication of already emitted errors, which won't be user-visible due to deduplication.

fixes https://github.com/rust-lang/rust/issues/120860
2024-02-14 18:32:19 +00:00
Urgau
ddec8c5edc Ignore unsized types when trying to determine the size of a type 2024-02-14 19:23:20 +01:00
Michael Goulet
01c974ff98 Do not report overflow errors on ConstArgHasType goals 2024-02-14 18:02:55 +00:00
Mohammad Omidvar
2e691a5c12 Rewrite foreign item kind query using DefKind 2024-02-14 17:38:36 +00:00
Oli Scherer
55f9aed9c7 Move all the heavy lifting from TyCtxtAt::create_def into TyCtxt::create_def 2024-02-14 16:03:49 +00:00
Nikita Popov
369fff6c06 Implicitly enable evex512 if avx512 is enabled
LLVM 18 requires the evex512 feature to allow use of zmm registers.
LLVM automatically sets it when using a generic CPU, but not when
`-C target-cpu` is specified. This will result either in backend
legalization crashes, or code unexpectedly using ymm instead of
zmm registers.

For now, make sure that `avx512*` features imply `evex512`. Long
term we'll probably have to deal with the AVX10 mess somehow.
2024-02-14 16:26:20 +01:00
Guillaume Gomez
2062325145
Rollup merge of #121084 - oli-obk:create_def_forever_red2, r=WaffleLapkin
Make sure `tcx.create_def` also depends on the forever red node, instead of just `tcx.at(span).create_def`

oversight from https://github.com/rust-lang/rust/pull/119136

Not actually an issue, because all uses of `tcx.create_def` were in the resolver, which is `eval_always`, but still good to harden against future uses of `create_def`

cc `@petrochenkov` `@WaffleLapkin`
2024-02-14 15:41:30 +01:00
Guillaume Gomez
c2ae07d20d
Rollup merge of #121083 - GuillaumeGomez:doc-to_opt_closure_kind, r=compiler-errors
Extend documentation for `Ty::to_opt_closure_kind` method

This API was... surprising to use. With a little extra documentation, the weirdness can be reduced quite a lot. :)

r? `@compiler-errors`
2024-02-14 15:41:29 +01:00
Guillaume Gomez
18c935d000
Rollup merge of #121075 - chenyukang:yukang-fix-121070-lint-range, r=oli-obk
Fix false positive with if let and ranges

Fixes #121070
2024-02-14 15:41:28 +01:00
Guillaume Gomez
8e690fdd6a
Rollup merge of #120966 - chenyukang:yukang-fix-120599-resolve, r=pnkfelix
Remove importing suggestions when there is a shadowed typo candidate

Fixes #120559
2024-02-14 15:41:27 +01:00
Guillaume Gomez
9ef9f737ca Extend documentation for Ty::to_opt_closure_kind method 2024-02-14 15:24:44 +01:00
Oli Scherer
2e900edde1 Make sure tcx.create_def also depends on the forever red node, instead of just tcx.at(span).create_def 2024-02-14 14:08:19 +00:00
Oli Scherer
5f6390f947 Continue compilation after check_mod_type_wf errors 2024-02-14 11:00:30 +00:00
Oli Scherer
638f5259fe
Rollup merge of #121071 - nnethercote:fewer-delayed-bugs, r=oli-obk
Use fewer delayed bugs.

For some cases where it's clear that an error has already occurred, e.g.:
- there's a comment stating exactly that, or
- things like HIR lowering, where we are lowering an error kind

The commit also tweaks some comments around delayed bug sites.

r? `@oli-obk`
2024-02-14 11:53:42 +01:00
Oli Scherer
9e31121985
Rollup merge of #121049 - estebank:issue-121009, r=fmease
Do not point at `#[allow(_)]` as the reason for compat lint triggering

Fix #121009.
2024-02-14 11:53:42 +01:00
Oli Scherer
93bc34073e
Rollup merge of #121039 - cjgillot:gvn-adjust, r=compiler-errors
Correctly compute adjustment casts in GVN

Fixes https://github.com/rust-lang/rust/issues/120925

r? `@oli-obk`
2024-02-14 11:53:41 +01:00
Oli Scherer
bad2cb08de
Rollup merge of #121015 - nnethercote:opt-delayed-bug, r=oli-obk
Optimize `delayed_bug` handling.

Once we have emitted at least one error, delayed bugs won't be used. So we can (a) we can (a) discard any existing delayed bugs, and (b) stop recording any new delayed bugs.

This eliminates a longstanding `FIXME` comment. There should be no soundness issues because it's not possible to un-emit an error.

r? `@oli-obk`
2024-02-14 11:53:40 +01:00
Oli Scherer
f3e66edd63
Rollup merge of #120915 - OdenShirataki:master, r=fmease
Fix suggestion span for `?Sized` when param type has default

Fixes #120878

Diagnostic suggests adding `: ?Sized` in an incorrect place if a type parameter default is present

r? `@fmease`
2024-02-14 11:53:39 +01:00
Oli Scherer
c4371a79de
Rollup merge of #120530 - trevyn:issue-116434, r=compiler-errors
Be less confident when `dyn` suggestion is not checked for object safety

#120275 no longer checks bare traits for object safety when making a `dyn` suggestion on Rust < 2021. In this case, qualify the suggestion with a note that the trait must be object safe, to prevent user confusion as seen in #116434

r? ```@fmease```
2024-02-14 11:53:39 +01:00
Oli Scherer
cc54612ac3
Rollup merge of #120498 - compiler-errors:type-flags, r=lcnr
Uplift `TypeVisitableExt` into `rustc_type_ir`

This uplifts `TypeVisitableExt` into `rustc_type_ir` so it can be used in an interner-agnostic way. It also moves some `TypeSuperVisitable` bounds onto `Interner` since we don't expect to support libraries that have types which aren't foldable by default.

This restores a couple of asserts in the canonicalizer code we uplifted, and also makes it so that we can use type-flags-based helpers in the solver code, which I'm interested in uplifting.

r? lcnr
2024-02-14 11:53:38 +01:00
yukang
3f27e4b3ea clean up potential_query_instability with FxIndexMap and UnordMap 2024-02-14 18:36:37 +08:00
Nicholas Nethercote
05849e8c2f Use fewer delayed bugs.
For some cases where it's clear that an error has already occurred,
e.g.:
- there's a comment stating exactly that, or
- things like HIR lowering, where we are lowering an error kind

The commit also tweaks some comments around delayed bug sites.
2024-02-14 20:30:37 +11:00
bors
bb89df6903 Auto merge of #121018 - oli-obk:impl_unsafety, r=TaKO8Ki
Fully stop using the HIR in trait impl checks

At least I hope I found all happy path usages. I'll need to check if I can figure out a way to make queries declare that they don't access the HIR except in error paths
2024-02-14 07:27:11 +00:00
yukang
2fe73cea5e Fix false positive with if let and ranges 2024-02-14 15:15:22 +08:00
yukang
2a229c96e8 remove importing suggestions when there is a shadowed typo canddiate 2024-02-14 14:08:51 +08:00
bors
cc1c0990ab Auto merge of #120454 - clubby789:cargo-update, r=Nilstrieb
`cargo update`

Run `cargo update`, with some pinning and fixes necessitated by that. This *should* unblock #112865

There's a couple of places where I only pinned a dependency in one location - this seems like a bit of a hack, but better than duplicating the FIXME across all `Cargo.toml` where a dependency is introduced.

cc `@Nilstrieb`
2024-02-14 05:27:31 +00:00
bors
7508c3e4c1 Auto merge of #121055 - matthiaskrgr:rollup-bzn5sda, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #118882 (Check normalized call signature for WF in mir typeck)
 - #120999 (rustdoc: replace `clean::InstantiationParam` with `clean::GenericArg`)
 - #121002 (remove unnecessary calls to `commit_if_ok`)
 - #121005 (Remove jsha from the rustdoc review rotation)
 - #121014 (Remove `force_print_diagnostic`)
 - #121043 (add lcnr to the compiler-team assignment group)
 - #121046 (Fix incorrect use of `compile_fail`)
 - #121047 (Do not assemble candidates for default impls)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-02-14 03:21:31 +00:00
bors
37b65339c8 Auto merge of #120942 - compiler-errors:deep-assoc-hang, r=lcnr
Ignore own item bounds in parent alias types in `for_each_item_bound`

Fixes #120912

I want to get a vibe check on this approach, which is very obviously a hack, but I believe something that is forwards-compatible with a more thorough solution and "good enough for now".

The problem here is that for a really deep rigid associated type, we are now repeatedly considering unrelated item bounds from the parent alias types, meaning we're doing a *lot* of extra work in the MIR inliner for deeply substituted rigid projections.

This feels intimately related to #107614. In that PR, we split *supertrait* bounds (bound which share the same `Self` type as the predicate which is being elaborated) and *implied* bounds (anything that is implied by elaborating the predicate).

The problem here is related to the fact that we don't maintain the split between these two for `item_bounds`. If we did, then when recursing into a parent alias type, we'd want to consider only the bounds that are given by [`PredicateFilter::All`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir_analysis/astconv/enum.PredicateFilter.html#variant.SelfOnly) **except** those given by [`PredicateFilter::SelfOnly`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir_analysis/astconv/enum.PredicateFilter.html#variant.SelfOnly).
2024-02-14 01:23:46 +00:00
Matthias Krüger
ab1fa19d08
Rollup merge of #121047 - compiler-errors:default-impls, r=lcnr
Do not assemble candidates for default impls

There is no reason (as far as I can tell?) that we should assemble an impl candidate for a default impl. This candidate itself does not prove that the impl holds, and any time that it *does* hold, there will be a more specializing non-default impl that also is assembled.

This is because `default impl<T> Foo for T {}` actually expands to `impl<T> Foo for T where T: Foo {}`. The only way to satisfy that where clause (without coinduction) is via *another* implementation that does hold -- precisely an impl that specializes it.

This should fix the specialization related regressions for #116494. That should lead to one root crate regression that doesn't have to do with specialization, which I think we can regress.

r? lcnr cc ``@rust-lang/types``

cc #31844
2024-02-13 22:51:57 +01:00
Matthias Krüger
8c0d54fad6
Rollup merge of #121014 - nnethercote:rm-force_print_diagnostic, r=oli-obk
Remove `force_print_diagnostic`

More diagnostic cleanups, best reviewed one at a time.

r? `@oli-obk`
2024-02-13 22:51:55 +01:00
Matthias Krüger
147fd3f236
Rollup merge of #121002 - lcnr:cleanup-commit_if_ok, r=oli-obk
remove unnecessary calls to `commit_if_ok`

we propagate the error outwards, so anything which wants to discard the error should do so itself.

r? types
2024-02-13 22:51:55 +01:00
Matthias Krüger
db9591cfb6
Rollup merge of #118882 - compiler-errors:normalized-sig-wf, r=lcnr
Check normalized call signature for WF in mir typeck

Unfortunately we don't check that the built-in implementations for `Fn*` traits are actually well-formed in the same way that we do for user-provided impls.

Essentially, when checking a call terminator, we end up with a signature that references an unnormalized `<[closure] as FnOnce<...>>::Output` in its output. That output type, due to the built-in impl, doesn't follow the expected rule that `WF(ty)` implies `WF(normalized(ty))`. We fix this by also checking the normalized signature here.

**See** boxy's detailed and useful explanation comment which explains this in more detail: https://github.com/rust-lang/rust/issues/114936#issuecomment-1710388741

Fixes #114936
Fixes #118876

r? types
cc ``@BoxyUwU`` ``@lcnr``
2024-02-13 22:51:53 +01:00
Nicholas Nethercote
71f2e3a095 Optimize delayed_bug handling.
Once we have emitted at least one error, delayed bugs won't be used. So
we can (a) we can (a) discard any existing delayed bugs, and (b) stop
recording any new delayed bugs.

This eliminates a longstanding `FIXME` comment. There should be no
soundness issues because it's not possible to un-emit an error.
2024-02-14 08:13:06 +11:00
clubby789
002181f3ce Pin cc version 2024-02-13 21:13:06 +00:00
clubby789
36a16798f7 Pin memchr version 2024-02-13 21:03:34 +00:00
clubby789
4de3a3af4a Bump indexmap
`swap` has been deprecated in favour of `swap_remove` - the behaviour
is the same though.
2024-02-13 21:03:34 +00:00
Nicholas Nethercote
56b451a67a Fix DiagCtxtInner::reset_err_count.
Several fields were not being reset. Using destructuring makes it much
harder to miss a field.
2024-02-14 07:54:05 +11:00
Nicholas Nethercote
c1ffb0b675 Remove force_print_diagnostic.
There are a couple of places where we call
`inner.emitter.emit_diagnostic` directly rather than going through
`inner.emit_diagnostic`, to guarantee the diagnostic is printed. This
feels dubious to me, particularly the bypassing of `TRACK_DIAGNOSTIC`.

This commit removes those.
- In `print_error_count`, it uses `ForceWarning` instead of `Warning`.
- It removes `DiagCtxtInner::failure_note`, because it only has three
  uses and direct use of `emit_diagnostic` is consistent with other
  similar locations.
- It removes `force_print_diagnostic`, and adds `struct_failure_note`,
  and updates `print_query_stack` accordingly, which makes it more
  normal. That location doesn't seem to need forced printing anyway.
2024-02-14 07:51:53 +11:00
Nicholas Nethercote
bdc6d82f9a Make struct_span_note call struct_note.
So it follows the same pattern as all the other `struct_span_*` methods.
2024-02-14 07:50:54 +11:00
Esteban Küber
24b52fd9df Do not point at #[allow(_)] as the reason for compat lint triggering
Fix #121009.
2024-02-13 20:27:43 +00:00
Michael Goulet
b4eee2e8b3 Do not assemble candidates for default impls 2024-02-13 19:20:13 +00:00
bors
a84bb95a1f Auto merge of #121036 - matthiaskrgr:rollup-ul05q8e, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #114877 (unstable-book: add quick-edit link)
 - #120548 (rustdoc: Fix handling of doc_auto_cfg feature for cfg attributes on glob reexport)
 - #120549 (modify alias-relate to also normalize ambiguous opaques)
 - #120959 (Remove good path delayed bugs)
 - #120978 (match lowering: simplify block creation)
 - #121019 (coverage: Simplify some parts of the coverage span refiner)
 - #121021 (Extend intra-doc link chapter in the rustdoc book)
 - #121031 (RustWrapper: adapt for coverage mapping API changes)

Failed merges:

 - #121014 (Remove `force_print_diagnostic`)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-02-13 17:27:25 +00:00
Camille GILLOT
a97e4afb67 Fix handling of adjustment casts. 2024-02-13 17:22:56 +00:00
Matthias Krüger
8dffa39367
Rollup merge of #121031 - TimNN:lh-fix-20240213, r=durin42
RustWrapper: adapt for coverage mapping API changes

There've been a number of changes to the coverage mapping API today, but the end result is that specifying the MCDC parameters is now optional (they've been moved to the end of the argument list and now default to `std::monostate`).

`@rustbot` label: +llvm-main

r? `@durin42`
2024-02-13 17:38:12 +01:00
Matthias Krüger
e36a7f4c65
Rollup merge of #121019 - Zalathar:covspans, r=oli-obk
coverage: Simplify some parts of the coverage span refiner

This is another incremental step on my quest to dismantle the coverage span refiner into something more understandable and maintainable.

The biggest change here is splitting up `CoverageSpan` into several more specific structs. Doing so reveals that most of the places that were using that struct only need a subset of its fields and methods.

We can also get rid of separate tracking of `curr_original_span` and `prev_original_span`, by observing that `curr.span` never actually needs to be mutated, and that we can store `prev_original_span` directly in the dedicated struct for `prev`.

`@rustbot` label +A-code-coverage
2024-02-13 17:38:11 +01:00
Matthias Krüger
b785fdb80b
Rollup merge of #120978 - Nadrieril:sane-blocks, r=matthewjasper
match lowering: simplify block creation

Match lowering was doing complicated things with block creation. As far as I can tell it was trying to avoid creating unneeded blocks, but of the three places that start out with `otherwise = &mut None`, two of them called `otherwise.unwrap_or_else(|| self.cfg.start_new_block())` anyway. As far as I can tell the only place where this PR makes a difference is in `lower_match_tree`, which did indeed sometimes avoid creating the unreachable final block + FakeRead. Unless this is important I propose we do the naive thing instead.

I have not checked all the graph isomorphisms by hand, but at a glance the test diff looks sensible.

r? `@matthewjasper`
2024-02-13 17:38:11 +01:00
Matthias Krüger
93e9579b5d
Rollup merge of #120959 - nnethercote:rm-good_path, r=oli-obk
Remove good path delayed bugs

Because they're not that useful, and kind of annoying. Details in the individual commits.

r? ```@compiler-errors```
2024-02-13 17:38:10 +01:00
Matthias Krüger
65ab663266
Rollup merge of #120549 - lcnr:errs-showcase, r=compiler-errors
modify alias-relate to also normalize ambiguous opaques

allows a bunch of further cleanups and generally simplifies the type system. To handle https://github.com/rust-lang/trait-system-refactor-initiative/issues/8 we'll have to add a some additional complexity to the `(Alias, Infer)` branches in alias-relate, so removing the opaque type special case here is really valuable.

It does worsen `deduce_closure_signature` and friends even more as they now receive an inference variable which is only constrained via an `AliasRelate` goal. These probably have to look into alias relate goals somehow. Leaving that for a future PR as this is something we'll have to tackle regardless.

r? `@compiler-errors`
2024-02-13 17:38:10 +01:00
Michael Goulet
2b4a2b95dd Check normalized call signature for WF in mir typeck 2024-02-13 16:00:01 +00:00
Michael Goulet
7e80867f3c Move visitable bounds up into interner 2024-02-13 15:53:15 +00:00
Michael Goulet
edc5053352 Add assertions back to canonicalizer 2024-02-13 15:40:59 +00:00
Michael Goulet
f4e886323c Uplift TypeVisitableExt into rustc_type_ir 2024-02-13 15:40:55 +00:00
bors
eaff1af8fd Auto merge of #120055 - nikic:llvm-18, r=cuviper
Update to LLVM 18

LLVM 18 final is planned to be released on Mar 5th. Rust 1.78 is planned to be released on May 2nd.

Tested images: dist-x86_64-linux, dist-s390x-linux, dist-aarch64-linux, dist-riscv64-linux, dist-loongarch64-linux, dist-x86_64-freebsd, dist-x86_64-illumos, dist-x86_64-musl, x86_64-linux-integration, test-various, armhf-gnu, i686-msvc, x86_64-msvc, i686-mingw, x86_64-mingw, x86_64-apple-1, x86_64-apple-2, dist-aarch64-apple

r? `@ghost`
2024-02-13 15:07:28 +00:00
Oli Scherer
e9cda9b139 Continue reporting remaining errors instead of silently dropping them 2024-02-13 14:56:20 +00:00
Tim Neumann
14ec3b6c91 RustWrapper: adapt for coverage mapping API changes 2024-02-13 15:15:14 +01:00
Zalathar
e67db4c3b8 coverage: Simplify code for adding prev to pending dups
If we only check for duplicate spans when `prev` is unmodified, we reduce the
number of situations that `update_pending_dups` needs to handle.

This could potentially change the coverage spans we produce in some unknown
corner cases, but none of our current coverage tests indicate any change.
2024-02-13 21:48:03 +11:00
Zalathar
499609d8a4 coverage: Move prev_original_span into PrevCovspan
Now that `prev` has its own dedicated struct, we can store the original span in
that struct, instead of in a separate field in the refiner.
2024-02-13 21:48:03 +11:00
Zalathar
a6183216d8 coverage: Split CoverageSpan into several distinct structs
This requires some extra boilerplate, but in exchange it becomes much easier to
see how each field and method is actually used.
2024-02-13 21:48:03 +11:00
Oli Scherer
d3a89cd214 Avoid an ICE in diagnostics 2024-02-13 10:44:54 +00:00
Oli Scherer
7320623f3a Just pass the checker instead of individual fields 2024-02-13 10:23:06 +00:00
Oli Scherer
251c33ce2a Remove an impl_polarity call where the information is already available in the header 2024-02-13 10:18:05 +00:00
Zalathar
5a569b1b80 coverage: Don't track curr_original_span explicitly
Now that we never mutate `curr.span`, we don't need to store its original span
separately.
2024-02-13 21:01:17 +11:00
Zalathar
412c86cf03 coverage: When merging spans, keep prev and merge curr into it
Swapping the direction of this merge produces the same results, but means that
we never need to mutate `curr`.
2024-02-13 21:01:17 +11:00
Oli Scherer
75de6cf9a3 Avoid using the HIR span in the happy path 2024-02-13 09:49:08 +00:00
Oli Scherer
40b3cb0eb1 Don't reinvoke trait_header query twice 2024-02-13 09:38:13 +00:00
Nikita Popov
a911c8ce23 Use MCSubtargetInfo::getAllProcessorFeatures()
This method is now available in upstream LLVM \o/
2024-02-13 10:33:40 +01:00
Oli Scherer
55bbb054c9 Invoke trait_def query only once
This may be a small performance boost as we have to hash less to lookup the value
2024-02-13 09:29:31 +00:00
Oli Scherer
11a73f6d4d Store impl unsafety in impl trait header 2024-02-13 09:21:34 +00:00
Matthias Krüger
70ea26d349
Rollup merge of #120995 - durin42:llvm-19-pgo-coldfuncopt, r=cuviper
PassWrapper: adapt for llvm/llvm-project@93cdd1b5cf

Should be no functional change.

`@rustbot` label: +llvm-main
2024-02-13 06:27:41 +01:00
Matthias Krüger
21d8fb272b
Rollup merge of #120988 - tshepang:fix-comment, r=cjgillot
fix comment
2024-02-13 06:27:41 +01:00
Matthias Krüger
7427460ea9
Rollup merge of #120987 - tshepang:redundant, r=compiler-errors
remove redundant logic

Made redundant in 3f697b85f2
2024-02-13 06:27:40 +01:00
Matthias Krüger
fa3ec02057
Rollup merge of #120974 - zmodem:exportas, r=durin42
llvm-wrapper: adapt for LLVM API change: Add support for EXPORTAS name types

Adapt for llvm/llvm-project@8f23464.
2024-02-13 06:27:39 +01:00
Matthias Krüger
30057f0266
Rollup merge of #120802 - oli-obk:drop_elab_ice, r=compiler-errors
Bail out of drop elaboration when encountering error types

fixes  #120788
2024-02-13 06:27:38 +01:00
Matthias Krüger
1b396913a9
Rollup merge of #120751 - estebank:issue-68982, r=nnethercote
Provide more suggestions on invalid equality where bounds

```
error: equality constraints are not yet supported in `where` clauses
  --> $DIR/equality-bound.rs:50:9
   |
LL |         IntoIterator::Item = A
   |         ^^^^^^^^^^^^^^^^^^^^^^ not supported
   |
   = note: see issue #20041 <https://github.com/rust-lang/rust/issues/20041> for more information
help: if `IntoIterator::Item` is an associated type you're trying to set, use the associated type binding syntax
   |
LL ~     fn from_iter<T: IntoIterator<Item = A>>(_: T) -> Self
LL ~
   |

error: equality constraints are not yet supported in `where` clauses
  --> $DIR/equality-bound.rs:63:9
   |
LL |         T::Item = A
   |         ^^^^^^^^^^^ not supported
   |
   = note: see issue #20041 <https://github.com/rust-lang/rust/issues/20041> for more information
help: if `IntoIterator::Item` is an associated type you're trying to set, use the associated type binding syntax
   |
LL ~     fn from_iter<T: IntoIterator<Item = A>>(_: T) -> Self
LL ~
   |
```

Fix #68982.
2024-02-13 06:27:37 +01:00
Matthias Krüger
020e84652d
Rollup merge of #120696 - estebank:issue-115405, r=oli-obk
Properly handle `async` block and `async fn` in `if` exprs without `else`

When encountering a tail expression in the then arm of an `if` expression without an `else` arm, account for `async fn` and `async` blocks to suggest `return`ing the value and pointing at the return type of the `async fn`.

We now also account for AFIT when looking for the return type to point at.

Fix #115405.
2024-02-13 06:27:37 +01:00
lcnr
ae92334c0f remove questionable calls to commit_if_ok 2024-02-13 05:44:46 +01:00
lcnr
3e3e207ad7 use alias-relate to structurally normalize in the solver 2024-02-13 05:08:51 +01:00
lcnr
bbe2f6c0b2 also try to normalize opaque types in alias-relate
with this, alias-relate treats all aliases the same way
and it can be used for structural normalization.
2024-02-13 04:47:32 +01:00
bors
d26b417112 Auto merge of #120919 - oli-obk:impl_polarity, r=compiler-errors
Merge `impl_polarity` and `impl_trait_ref` queries

Hopefully this is perf neutral. I want to finish https://github.com/rust-lang/rust/pull/120835 and stop using the HIR in `coherent_trait`, which should then give us a perf improvement.
2024-02-13 02:48:49 +00:00
bors
0a5b998c57 Auto merge of #120991 - matthiaskrgr:rollup-f8kw2st, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #118983 (Warn on references casting to bigger memory layout)
 - #119451 (Gate PR CI on clippy correctness lints)
 - #120273 (compiletest: few naive improvements)
 - #120950 (Fix async closures in CTFE)
 - #120958 (Dejargonize `subst`)
 - #120965 (Add lahfsahf and prfchw target feature)
 - #120970 (add another test for promoteds-in-static)
 - #120979 (Update books)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-02-13 00:31:53 +00:00
Augie Fackler
9d1bd2e067 PassWrapper: adapt for llvm/llvm-project@93cdd1b5cf
Should be no functional change.

@rustbot label: +llvm-main
2024-02-12 19:13:09 -05:00
Nicholas Nethercote
9f2aa09765 Remove good_path_delayed_bug.
It's only has a single remaining purpose: to ensure that a diagnostic is
printed when `trimmed_def_paths` is used. It's an annoying mechanism:
weak, with odd semantics, badly named, and gets in the way of other
changes.

This commit replaces it with a simpler `must_produce_diag` mechanism,
getting rid of a diagnostic `Level` along the way.
2024-02-13 09:33:35 +11:00
Matthias Krüger
7075502b15
Rollup merge of #120965 - ChrisDenton:sahf, r=michaelwoerister
Add lahfsahf and prfchw target feature

This adds target features for LAHF/SAHF and PrefetchW. These came up. along with the existing CMPXCHG16b. as [baseline features](https://download.microsoft.com/download/c/1/5/c150e1ca-4a55-4a7e-94c5-bfc8c2e785c5/Windows%2010%20Minimum%20Hardware%20Requirements.pdf) required for x86_64 Windows 10+.
2024-02-12 23:18:54 +01:00
Matthias Krüger
cb0d74be28
Rollup merge of #120958 - ShoyuVanilla:remove-subst, r=oli-obk
Dejargonize `subst`

In favor of #110793, replace almost every occurence of `subst` and `substitution` from rustc codes, but they still remains in subtrees under `src/tools/` like clippy and test codes (I'd like to replace them after this)
2024-02-12 23:18:54 +01:00
Matthias Krüger
15896bdd18
Rollup merge of #120950 - compiler-errors:miri-async-closurs, r=RalfJung,oli-obk
Fix async closures in CTFE

First commit renames `is_coroutine_or_closure` into `is_closure_like`, because `is_coroutine_or_closure_or_coroutine_closure` seems confusing and long.

Second commit fixes some forgotten cases where we want to handle `TyKind::CoroutineClosure` the same as closures and coroutines.

The test exercises the change to `ValidityVisitor::aggregate_field_path_elem` which is the source of #120946, but not the change to `UsedParamsNeedSubstVisitor`, though I feel like it's not that big of a deal. Let me know if you'd like for me to look into constructing a test for the latter, though I have no idea what it'd look like (we can't assert against `TooGeneric` anywhere?).

Fixes #120946

r? oli-obk cc ``@RalfJung``
2024-02-12 23:18:53 +01:00
Matthias Krüger
74f5e1f140
Rollup merge of #118983 - Urgau:invalid_ref_casting-bigger-layout, r=oli-obk
Warn on references casting to bigger memory layout

This PR extends the [`invalid_reference_casting`](https://doc.rust-lang.org/rustc/lints/listing/deny-by-default.html#invalid-reference-casting) lint (*deny-by-default*) which currently lint on `&T -> &mut T` casting to also lint on `&(mut) A -> &(mut) B` where `size_of::<B>() > size_of::<A>()` (bigger memory layout requirement).

The goal is to detect such cases:

```rust
let u8_ref: &u8 = &0u8;
let u64_ref: &u64 = unsafe { &*(u8_ref as *const u8 as *const u64) };
//~^ ERROR casting references to a bigger memory layout is undefined behavior

let mat3 = Mat3 { a: Vec3(0i32, 0, 0), b: Vec3(0, 0, 0), c: Vec3(0, 0, 0) };
let mat3 = unsafe { &*(&mat3 as *const _ as *const [[i64; 3]; 3]) };
//~^ ERROR casting references to a bigger memory layout is undefined behavior
```

This is added to help people who write unsafe code, especially when people have matrix struct that they cast to simple array of arrays.

EDIT: One caveat, due to the [`&Header`](https://github.com/rust-lang/unsafe-code-guidelines/issues/256) uncertainty the lint only fires when it can find the underline allocation.

~~I have manually tested all the new expressions that warn against Miri, and they all report immediate UB.~~

r? ``@est31``
2024-02-12 23:18:52 +01:00
bors
74c3f5a146 Auto merge of #120324 - Nadrieril:remove-interior-mutability, r=compiler-errors
pattern_analysis: track usefulness without interior mutability

Because of or-patterns, exhaustiveness needs to be able to lint if a sub-pattern is redundant, e.g. in `Some(_) | Some(true)`. So far the only sane solution I had found was interior mutability. This is a bit of an abstraction leak, and would become a footgun if we ever reused the same `DeconstructedPat`. This PR replaces interior mutability with an address-indexed hashmap, which is logically equivalent.
2024-02-12 22:16:58 +00:00
Nicholas Nethercote
173dbc9e13 Remove TypeErrCtxt::drop.
The check within changed from `delay_span_bug` to `delay_good_path_bug`
in #110476, and removing the check altogether was considered. It's a
very weak sanity check and gets in the way of removing good path delayed
bugs altogether, so this PR just removes it.
2024-02-13 08:34:42 +11:00
Tshepang Mbambo
882396cbd0 fix comment 2024-02-12 23:22:49 +02:00
demilade
e99766d885 suggest into_iter() when Iterator method called on impl IntoIterator 2024-02-12 22:11:48 +01:00
Tshepang Mbambo
c51b9ff8ba remove redundant logic
Made redundant in 3f697b85f2
2024-02-12 23:08:00 +02:00
Esteban Küber
d07195fe6b Remove visitor use 2024-02-12 20:26:40 +00:00
Esteban Küber
37d2ea2fa0 Properly handle async blocks and fns in if exprs without else
When encountering a tail expression in the then arm of an `if` expression
without an `else` arm, account for `async fn` and `async` blocks to
suggest `return`ing the value and pointing at the return type of the
`async fn`.

We now also account for AFIT when looking for the return type to point at.

Fix #115405.
2024-02-12 20:26:34 +00:00
Mohammad Omidvar
213748749e Add APIs for fetching foreign items including foreign modules, their ABIs, and their items 2024-02-12 19:44:35 +00:00
Urgau
6a8f50e907 Introduce small cache to avoid recomputing the same value twice 2024-02-12 19:40:17 +01:00
Urgau
915200fbe0 Lint on reference casting to bigger underlying allocation 2024-02-12 19:40:17 +01:00
Oli Scherer
f35a2bd401 Support safe intrinsics with fallback bodies
Turn `is_val_statically_known` into such an intrinsic to demonstrate. It is perfectly safe to call after all.
2024-02-12 17:55:36 +00:00
Oli Scherer
6b73fe2d09 Give const_deallocate a default body 2024-02-12 17:52:05 +00:00
Oli Scherer
9a0743747f Teach llvm backend how to fall back to default bodies 2024-02-12 17:50:39 +00:00
Oli Scherer
432635a9ea Create ret_dest as late as possible in all code paths 2024-02-12 17:48:20 +00:00
Oli Scherer
55200e75da Do the entire ReturnDest computation within make_return_dest 2024-02-12 17:48:04 +00:00
Oli Scherer
8549c0a3e6 Add intrinsic body fallback to cranelift and use it 2024-02-12 17:44:55 +00:00
Oli Scherer
531505f182 Check signature of intrinsics with fallback bodies 2024-02-12 17:44:53 +00:00
bors
b381d3ab27 Auto merge of #120980 - matthiaskrgr:rollup-dsjsqql, r=matthiaskrgr
Rollup of 11 pull requests

Successful merges:

 - #120765 (Reorder diagnostics API)
 - #120833 (More internal emit diagnostics cleanups)
 - #120899 (Gracefully handle non-WF alias in `assemble_alias_bound_candidates_recur`)
 - #120917 (Remove a bunch of dead parameters in functions)
 - #120928 (Add test for recently fixed issue)
 - #120933 (check_consts: fix duplicate errors, make importance consistent)
 - #120936 (improve `btree_cursors` functions documentation)
 - #120944 (Check that the ABI of the instance we are inlining is correct)
 - #120956 (Clean inlined type alias with correct param-env)
 - #120962 (Add myself to library/std review)
 - #120972 (fix ICE for deref coercions with type errors)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-02-12 17:06:22 +00:00
Matthias Krüger
8e5f722ece
Rollup merge of #120972 - lukas-code:autoderef-type-error, r=compiler-errors
fix ICE for deref coercions with type errors

Follow-up to https://github.com/rust-lang/rust/pull/120895, where I made types with errors go through the full coercion code, which is necessary if we want to build MIR for bodies with errors (https://github.com/rust-lang/rust/pull/120550).

The code for coercing `&T` to `&U` currently assumes that autoderef for `&T` will succeed for at least two steps (`&T` and `T`):

b17491c8f6/compiler/rustc_hir_typeck/src/coercion.rs (L339-L464)

But for types with errors, we previously only returned the no-op autoderef step (`&{type error}` -> `&{type error}`) and then stopped early. This PR changes autoderef for types with errors to still go through the built-in derefs (e.g. `&&{type error}` -> `&{type error}` -> `{type error}`) and only stop early when it would have to go looking for `Deref` trait impls.

fixes https://github.com/rust-lang/rust/issues/120945

r? ``@compiler-errors`` or compiler
2024-02-12 18:04:11 +01:00
Matthias Krüger
8ec144d738
Rollup merge of #120944 - compiler-errors:inliner-abi, r=oli-obk
Check that the ABI of the instance we are inlining is correct

When computing the `CallSite` in the mir inliner, double check that the instance of the function that we are inlining is compatible with the signature from the trait definition that we acquire from the MIR.

Fixes #120940

r? ``@oli-obk`` or ``@cjgillot``
2024-02-12 18:04:10 +01:00
Matthias Krüger
3f67169a5f
Rollup merge of #120933 - RalfJung:const-check-misc, r=oli-obk
check_consts: fix duplicate errors, make importance consistent

This is stuff I noticed while working on https://github.com/rust-lang/rust/pull/120932, but it's orthogonal to that PR.

r? ``@oli-obk``
2024-02-12 18:04:09 +01:00
Matthias Krüger
ebe36ac815
Rollup merge of #120917 - chenyukang:yukang-dead-parameters, r=compiler-errors
Remove a bunch of dead parameters in functions

Found this kind of issue when working on https://github.com/rust-lang/rust/pull/119650
I wrote a trivial toy lint and manual review to find these.
2024-02-12 18:04:08 +01:00
Matthias Krüger
733f93d60c
Rollup merge of #120899 - compiler-errors:non-wf-alias, r=lcnr
Gracefully handle non-WF alias in `assemble_alias_bound_candidates_recur`

See explanation in test. I think it's fine to delay a bug here -- I don't believe we ever construct a non-wf alias on the good path? If so, then we can just remove the delay.

Fixes #120891

r? lcnr
2024-02-12 18:04:08 +01:00
Matthias Krüger
f08ece38a8
Rollup merge of #120833 - nnethercote:more-internal-emit_diagnostics-cleanups, r=oli-obk
More internal emit diagnostics cleanups

Miscellaneous improvements.

r? ``@oli-obk``
2024-02-12 18:04:07 +01:00
Matthias Krüger
57a2e91ae8
Rollup merge of #120765 - nnethercote:reorder-diag-API, r=compiler-errors
Reorder diagnostics API

The totally random ordering of diagnostic methods in `DiagCtxt` has been low-key driving me crazy for a while now.

r? ``@compiler-errors``
2024-02-12 18:04:07 +01:00
Nadrieril
faaf81bbbc Start blocks eagerly 2024-02-12 17:37:05 +01:00
Oli Scherer
0dac617a75 support adding const generic params to intrinsics
but right now all of them have zero const generic params
2024-02-12 15:22:42 +00:00
Oli Scherer
09fd556962 Make check_intrinsic_type not require ForeignItems anymore 2024-02-12 15:22:36 +00:00
bors
bdc15928c8 Auto merge of #115367 - frank-king:feature/unnamed-fields-hir, r=davidtwco
Lowering unnamed fields and anonymous adt

This implements #49804.

Goals:
- [x] lowering anonymous ADTs from AST to HIR
- [x] generating definitions of anonymous ADTs
- [x] uniqueness check of the unnamed fields
- [x] field projection of anonymous ADTs
- [x] `#[repr(C)]` check of the anonymous ADTs

Non-Goals (will be in the next PRs)
- capturing generic params for the anonymous ADTs from the parent ADT
- pattern matching of anonymous ADTs
- structural expressions of anonymous ADTs
- rustdoc support of anonymous ADTs
2024-02-12 14:51:15 +00:00
Hans Wennborg
718b304d82 llvm-wrapper: adapt for LLVM API change: Add support for EXPORTAS name types
Adapt for llvm/llvm-project@8f23464.
2024-02-12 15:23:50 +01:00
Lukas Markeffsky
95c5b06000 fix ICE for deref coercions with type errors 2024-02-12 14:37:35 +01:00
Chris Denton
83a850f2a1
Add lahfsahf and prfchw target feature 2024-02-12 10:31:12 -03:00
bors
ed19532868 Auto merge of #120960 - RalfJung:static-promoted-cycle, r=oli-obk
fix cycle error when a static and a promoted are mutually recursive

This also now allows promoteds everywhere to point to 'extern static', because why not? We still check that constants cannot transitively reach 'extern static' through references. (We allow it through raw pointers.)

r? `@oli-obk`
Fixes https://github.com/rust-lang/rust/issues/120949
2024-02-12 12:09:20 +00:00
Oli Scherer
79daf6107c Make the signature of equate_intrinsic_type support items other than ForeignItem 2024-02-12 09:52:12 +00:00
Oli Scherer
74c9dffac3 Remove impl_polarity query 2024-02-12 09:44:45 +00:00
Oli Scherer
92281c7e81 Implement intrinsics with fallback bodies 2024-02-12 09:44:22 +00:00
Oli Scherer
b43fbe63e7 Stop calling impl_polarity when impl_trait_ref was also called 2024-02-12 09:44:09 +00:00