Commit graph

44894 commits

Author SHA1 Message Date
Matthias Krüger
0c4415cdd6
Rollup merge of #138387 - RalfJung:intrinsic-arg-names, r=oli-obk
intrinsics: remove unnecessary leading underscore from argument names

This is unnecessary since https://github.com/rust-lang/rust/pull/135840.
2025-03-12 17:59:10 +01:00
Matthias Krüger
de7e5e96be
Rollup merge of #138345 - oli-obk:autodiff-cleanup, r=compiler-errors
Some autodiff cleanups

cc ````@ZuseZ4````

just some things I noticed
2025-03-12 17:59:09 +01:00
Matthias Krüger
d93ef397ce
Rollup merge of #138331 - nnethercote:use-RUSTC_LINT_FLAGS-more, r=onur-ozkan,jieyouxu
Use `RUSTC_LINT_FLAGS` more

An alternative to the failed #138084.

Fixes #138106.

r? ````@jieyouxu````
2025-03-12 17:59:08 +01:00
Matthias Krüger
4ffbc32f17
Rollup merge of #137701 - cuviper:sharded-hashtable, r=fmease
Convert `ShardedHashMap` to use `hashbrown::HashTable`

The `hash_raw_entry` feature (#56167) has finished fcp-close, so the compiler
should stop using it to allow its removal. Several `Sharded` maps were
using raw entries to avoid re-hashing between shard and map lookup, and
we can do that with `hashbrown::HashTable` instead.
2025-03-12 17:59:07 +01:00
Matthias Krüger
d55e2e4333
Rollup merge of #137314 - lcnr:cycles-with-unknown-kind, r=compiler-errors
change definitely unproductive cycles to error

builds on top of #136824 by adding a third variant to `PathKind` for paths which may change to be coinductive in the future but must not be so right now. Most notably, impl where-clauses of not yet coinductive traits.

With this, we can change cycles which are definitely unproductive to a proper error. This fixes https://github.com/rust-lang/trait-system-refactor-initiative/issues/114. This does not affect stable as we keep these cycles as ambiguous during coherence.

r? ````````@compiler-errors```````` ````````@nikomatsakis````````
2025-03-12 17:59:06 +01:00
Michael Goulet
42773bfcac Disentangle ForwardGenericParamBan and ConstParamTy ribs 2025-03-12 16:56:26 +00:00
bjorn3
1543256e6f Remove unused host_tlib_path field 2025-03-12 15:05:25 +00:00
bjorn3
f51d1d29f7 Rename user_provided_sysroot argument of fluent_bundle 2025-03-12 15:05:25 +00:00
bjorn3
7e8494f0a5 Don't return an error from get_or_default_sysroot
All callers unwrap the result.
2025-03-12 15:05:25 +00:00
bjorn3
0a679514d4 Avoid unnecessary argument mutation in fluent_bundle 2025-03-12 15:05:24 +00:00
bjorn3
b54398e4ea Make opts.maybe_sysroot non-optional
build_session_options always uses materialize_sysroot anyway.
2025-03-12 15:05:24 +00:00
bors
aaa2d47dae Auto merge of #138083 - nnethercote:rm-NtItem-NtStmt, r=petrochenkov
Remove `NtItem` and `NtStmt`

Another piece of #124141.

r? `@petrochenkov`
2025-03-12 14:18:36 +00:00
Bryanskiy
ccdba16f42 Delegation: reject C-variadics 2025-03-12 17:14:51 +03:00
Bryanskiy
7bfe2136e4 Delegation: one more ICE fix for MethodCall generation 2025-03-12 15:59:37 +03:00
lcnr
adbcb910f0 remove unnecessary variant 2025-03-12 10:12:53 +01:00
Scott McMurray
143f39362a Don't alloca just to look at a discriminant
Today we're making LLVM do a bunch of extra work for every enum you match on, even trivial stuff like `Option<bool>`.  Let's not.
2025-03-12 00:56:43 -07:00
Matthias Krüger
76f9cda260
Rollup merge of #138377 - nnethercote:rustc_hir_typeck, r=compiler-errors
Remove unnecessary lifetime from `PatInfo`.

r? ```@jackh726```
2025-03-12 08:06:51 +01:00
Matthias Krüger
4c6edb1df8
Rollup merge of #138376 - nnethercote:hir-ItemKind-ident-precursors, r=compiler-errors
Item-related cleanups

I have been looking at `hir::Item` closely and found a few minor cleanup opportunities.

r? ```@spastorino```
2025-03-12 08:06:51 +01:00
Matthias Krüger
2bdb10f164
Rollup merge of #138372 - Eclips4:issue-138196, r=scottmcm
Refactor `pick2_mut` & `pick3_mut` to use `get_disjoint_mut`

Closes #138196
2025-03-12 08:06:50 +01:00
Matthias Krüger
b849aa9f61
Rollup merge of #138360 - Urgau:fix-fp-expr_or_init, r=wesleywiser
Fix false-positive in `expr_or_init` and in the `invalid_from_utf8` lint

This PR fixes the logic for finding initializer in the `expr_or_init` and `expr_or_init_with_outside_body` functions.

If the binding were to be mutable (`let mut`), the logic wouldn't consider that the initializer expression could have been modified and would return the init expression even-trough multiple subsequent assignments could have been done.

Example:
```rust
let mut a = [99, 108, 130, 105, 112, 112]; // invalid, not UTF-8
loop {
    a = *b"clippy"; // valid
    break;
}
std::str::from_utf8_mut(&mut a); // currently warns, with this PR it doesn't
```

This PR modifies the logic to excludes mutable let bindings.

Found when using `expr_or_init` in https://github.com/rust-lang/rust/pull/119220.

r? compiler
2025-03-12 08:06:50 +01:00
Matthias Krüger
5833dfa78a
Rollup merge of #138347 - nnethercote:less-kw-Empty-2, r=compiler-errors
Reduce `kw::Empty` usage, part 2

A few small `kw::Empty` removals, or steps toward removals.

r? fmease
2025-03-12 08:06:49 +01:00
Matthias Krüger
143eb4f03e
Rollup merge of #138174 - compiler-errors:elaborate-unsize-self-pred, r=BoxyUwU
Elaborate trait assumption in `receiver_is_dispatchable`

Fixes #138172. See comment on the linked test.

Probably not a fix for the general problem, bc I think this may still be incomplete for other weird `where` clauses on the receiver. But 🤷, supertraits seems like an obvious one to fix.
2025-03-12 08:06:47 +01:00
Ralf Jung
cf318a79d6 intrinsics: remove unnecessary leading underscore from argument names 2025-03-12 08:04:09 +01:00
Nicholas Nethercote
c0cee43af5 Remove unnecessary lifetime from PatInfo. 2025-03-12 13:03:18 +11:00
bors
d2b52c5c48 Auto merge of #137795 - Jarcho:idx_opt, r=davidtwco
Allow bounds checks when enumerating `IndexSlice` to be elided

Without this hint, each loop iteration has to separately bounds check the index. See https://godbolt.org/z/zrfPY4Ten for an example.

This is technically a behaviour change, but only in cases where the compiler is going to crash anyways.
2025-03-12 00:30:16 +00:00
Nicholas Nethercote
ee9ef82795 Factor out some repeated code in parse_item_impl. 2025-03-12 09:55:29 +11:00
Nicholas Nethercote
ed10418363 Inline and remove State::print_item_type.
It has a single call site. The removal of the closure argument is a nice
touch.
2025-03-12 09:55:15 +11:00
Nicholas Nethercote
d7029d7e2d Remove unused OwnerNode::ident method. 2025-03-12 09:54:25 +11:00
Josh Stone
576bcfcd4e Update compiletest's has_asm_support to match rustc
The list of `ASM_SUPPORTED_ARCHS` was missing a few from the compiler's
actual stable list.
2025-03-11 15:42:33 -07:00
Kirill Podoprigora
7398b39a0b Make panic's more specific 2025-03-12 00:35:16 +02:00
Nicholas Nethercote
4eadaff184 Convert a kw::Empty occurrence to sym::dummy.
`adjust_ident_and_get_scope` returns the symbol it receives unchanged,
and the call site ignores the returned symbol, so this symbol is unused.
2025-03-12 09:35:13 +11:00
Nicholas Nethercote
0b2d7062c4 Introduce sym::dummy and Ident::dummy.
The idea is to identify cases of symbols/identifiers that are not
expected to be used. There isn't a perfectly sharp line between "dummy"
and "not dummy", but I think it's useful nonetheless.
2025-03-12 09:35:11 +11:00
Nicholas Nethercote
fe04460f6f Remove an unnecessary kw::Empty check.
Replace it with an assert for now, just in case it is reachable.
2025-03-12 09:34:21 +11:00
Nicholas Nethercote
763db5dcd9 Convert a delayed bug to a bug.
This is never hit in the test suite.

At some point the check should be removed entirely. There are a million
places in the compiler where an empty symbol doesn't make sense, so a
check of this nature has almost zero value. But I'll leave it in place
for now just in case it gets hit by fuzzing or in the wild.
2025-03-12 09:34:21 +11:00
Nicholas Nethercote
256c27e748 Move methods from Map to TyCtxt, part 4.
Continuing the work from #137350.

Removes the unused methods: `expect_variant`, `expect_field`,
`expect_foreign_item`.

Every method gains a `hir_` prefix.
2025-03-12 08:55:37 +11:00
Nicholas Nethercote
281af35cc3 Rename hir_attrs query as hir_attr_map.
To make room for the moving of `Map::attrs` to `TyCtxt::hir_attrs` in
the next commit. (It makes sense to rename the query, because it has
many fewer uses than the method.)
2025-03-12 08:55:35 +11:00
Nicholas Nethercote
d2642abed3 Adjust Map's to_string functionality.
`Map::node_to_string` just calls the free function `hir_id_to_string`.
This commit removes the former and changes the latter into a `TyCtxt`
method.
2025-03-12 08:30:03 +11:00
bors
c625102320 Auto merge of #138366 - matthiaskrgr:rollup-cn16m7q, r=matthiaskrgr
Rollup of 10 pull requests

Successful merges:

 - #137715 (Allow int literals for pattern types with int base types)
 - #138002 (Disable CFI for weakly linked syscalls)
 - #138051 (Add support for downloading GCC from CI)
 - #138231 (Prevent ICE in autodiff validation by emitting user-friendly errors)
 - #138245 (stabilize `ci_rustc_if_unchanged_logic` test for local environments)
 - #138256 (Do not feed anon const a type that references generics that it does not have)
 - #138284 (Do not write user type annotation for const param value path)
 - #138296 (Remove `AdtFlags::IS_ANONYMOUS` and `Copy`/`Clone` condition for anonymous ADT)
 - #138352 (miri native_calls: ensure we actually expose *mutable* provenance to the memory FFI can access)
 - #138354 (remove redundant `body`  arguments)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-03-11 21:17:18 +00:00
Kirill Podoprigora
64d143326f Refactor pick2_mut & pick3_mut to use get_disjoint_mut 2025-03-11 22:57:01 +02:00
Urgau
faa5b3f7de Fix false-positive in expr_or_init and in the invalid_from_utf8 lint 2025-03-11 21:56:53 +01:00
Matthias Krüger
4c1a1867c7
Rollup merge of #138354 - lcnr:goodbye-TypeVerifier, r=compiler-errors
remove redundant `body`  arguments

it's already stored in the `TypeChecker` itself
2025-03-11 19:35:35 +01:00
Matthias Krüger
4feb86684d
Rollup merge of #138352 - RalfJung:miri-native-calls-exposed, r=oli-obk
miri native_calls: ensure we actually expose *mutable* provenance to the memory FFI can access

In native call mode, the interpreter memory itself is accessed directly by external code via pointers created from integers and passed via libffi, so we have to ensure the provenance in Miri itself (on the meta level) is sufficiently exposed. So far we only exposed the provenance for read-only accesses. This may we enough as that may actually be the same provenance as for mutable accesses, but it's hard to be sure, and anyway there's no reason to do such a gambit -- we have this function, `prepare_for_native_call`, which iterates all memory the call can access. let's just also (re-)expose Miri's own allocations there. We expose the read-only provenance for all of them and the mutable provenance for the mutable allocations.

r? ``@oli-obk``
2025-03-11 19:35:34 +01:00
Matthias Krüger
954b88ed2a
Rollup merge of #138296 - compiler-errors:deanonymous, r=lcnr
Remove `AdtFlags::IS_ANONYMOUS` and `Copy`/`Clone` condition for anonymous ADT

cc #131045, which removed anonymous ADTs from the compiler

I forgot more stuff I guess.
2025-03-11 19:35:33 +01:00
Matthias Krüger
16ff824133
Rollup merge of #138284 - compiler-errors:const-param-ty-annotation, r=BoxyUwU
Do not write user type annotation for const param value path

As I noted in the code comment, `DefKind::ConstParam` isn't actually *generic* over its own args, we just use the identity args from the body when lowering the value path so we have something to plug into the `EarlyBinder` we get back from `type_of` for the const param. So skip over it in `write_user_type_annotation_from_args`.

Somewhat unrelated, but I left an explanation for a somewhat mysterious quirk in the THIR lowering of user type annotations for patterns having to do with ctors and their `type_of` not actually being the type of the pattern node it's ascribing.

Fixes #138048

r? ``@BoxyUwU``
2025-03-11 19:35:32 +01:00
Matthias Krüger
4ff58c9103
Rollup merge of #138256 - compiler-errors:anon-const-ty, r=BoxyUwU
Do not feed anon const a type that references generics that it does not have

Fixes #137865

See the comment I left in the code. We could alternatively give these anon consts the generics from the parent, but that would be moving in a GCE-esque direction that we may not want. Open to tweaks here.

r? BoxyUwU
2025-03-11 19:35:31 +01:00
Matthias Krüger
caa2d008f9
Rollup merge of #138231 - Sa4dUs:autodiff-ice, r=ZuseZ4
Prevent ICE in autodiff validation by emitting user-friendly errors

This PR moves `valid_ret_activity` and `valid_input_activity` checks to the macro expansion phase in compiler/rustc_builtin_macros/src/autodiff.rs, replacing the following internal compiler error (ICE):
```
error: internal compiler error:
compiler/rustc_codegen_ssa/src/codegen_attrs.rs:935:13:
Invalid input activity Dual for Reverse mode
```
with a more user-friendly message.

The issue specifically affected the test file `tests/ui/autodiff/autodiff_illegal.rs`, impacting the functions `f5` and `f6`.

The ICE can be reproduced by following [Enzyme's Rustbook](https://enzymead.github.io/rustbook/installation.html) installation guide.

Additionally, this PR adds tests for invalid return activity in `autodiff_illegal.rs`, which previously triggered an unnoticed ICE before these fixes.

r? ``@oli-obk``
2025-03-11 19:35:29 +01:00
Matthias Krüger
8a2e3acb45
Rollup merge of #137715 - oli-obk:pattern-type-literals, r=BoxyUwU
Allow int literals for pattern types with int base types

r? ``@BoxyUwU``

I also added an error at layout computation time for layouts that contain wrapping ranges (happens at monomorphization time). This is obviously hacky, but at least prevents such types from making it to codegen for now. It made writing the tests for int literals easier as I didn't have to think about that edge case

Basically this PR allows you to stop using transmutes for creating pattern types and instead just use literals:

```rust
let x: pattern_type!(u32 is 5..10) = 7;
```

works, and if the literal is out of range you get a type mismatch because it just stays at the base type and the base type can't be coerced to the pattern type.

cc ``@joshtriplett`` ``@scottmcm``
2025-03-11 19:35:27 +01:00
bors
6650252439 Auto merge of #128440 - oli-obk:defines, r=lcnr
Add `#[define_opaques]` attribute and require it for all type-alias-impl-trait sites that register a hidden type

Instead of relying on the signature of items to decide whether they are constraining an opaque type, the opaque types that the item constrains must be explicitly listed.

A previous version of this PR used an actual attribute, but had to keep the resolved `DefId`s in a side table.

Now we just lower to fields in the AST that have no surface syntax, instead a builtin attribute macro fills in those fields where applicable.

Note that for convenience referencing opaque types in associated types from associated methods on the same impl will not require an attribute. If that causes problems `#[defines()]` can be used to overwrite the default of searching for opaques in the signature.

One wart of this design is that closures and static items do not have generics. So since I stored the opaques in the generics of functions, consts and methods, I would need to add a custom field to closures and statics to track this information. During a T-types discussion we decided to just not do this for now.

fixes #131298
2025-03-11 18:13:31 +00:00
Michael Goulet
c170d0f12f Elaborate param-env built for checking DispatchFromDyn for dyn compat 2025-03-11 16:32:56 +00:00
lcnr
a5eb387d61 merge TypeChecker and TypeVerifier 2025-03-11 16:34:15 +01:00