Commit Graph

2988 Commits

Author SHA1 Message Date
León Orell Valerian Liehr
3c8950c30d
Rollup merge of #140792 - Urgau:minimum-maximum-intrinsics, r=scottmcm,traviscross,tgross35
Use intrinsics for `{f16,f32,f64,f128}::{minimum,maximum}` operations

This PR creates intrinsics for `{f16,f32,f64,f64}::{minimum,maximum}` operations.

This wasn't done when those operations were added as the LLVM support was too weak but now that LLVM has libcalls for unsupported platforms we can finally use them.

Cranelift and GCC[^1] support are partial, Cranelift doesn't support `f16` and `f128`, while GCC doesn't support `f16`.

r? `@tgross35`

try-job: aarch64-gnu
try-job: dist-various-1
try-job: dist-various-2

[^1]: https://www.gnu.org/software///gnulib/manual/html_node/Functions-in-_003cmath_002eh_003e.html
2025-05-11 02:44:36 +02:00
bors
b10555674f Auto merge of #140854 - oli-obk:merge-queries, r=nnethercote
Merge typeck loop with static/const item eval loop

r? `@ghost`

Let's try a small one first. Doing this in general has some bad cache coherence issues because the query caches are laid out in `Vec<QueryResult>` lists per query where each index refers to a `DefId` in the same order as we're iterating. Iterating two or more lists at the same time does have cache issues, so I want to poke a bit at it to see if we can't merge just a few of them at a time.
2025-05-10 14:20:43 +00:00
Oli Scherer
0b6e493515 Merge typeck loop with static/const item eval loop 2025-05-09 15:31:27 +00:00
Urgau
e7247df590 Use intrinsics for {f16,f32,f64,f128}::{minimum,maximum} operations 2025-05-09 17:11:23 +02:00
Matthias Krüger
a054be7434
Rollup merge of #140684 - compiler-errors:unnecessary-assoc, r=lcnr
Only include `dyn Trait<Assoc = ...>` associated type bounds for `Self: Sized` associated types if they are provided

Since #136458, we began filtering out associated types with `Self: Sized` bounds when constructing the list of associated type bounds to put into our `dyn Trait` types. For example, given:

```rust
trait Trait {
    type Assoc where Self: Sized;
}
```

After #136458, even if a user writes `dyn Trait<Assoc = ()>`, the lowered ty would have an empty projection list, and thus be equivalent to `dyn Trait`. However, this has the side effect of no longer constraining any types in the RHS of `Assoc = ...`, not implying any WF implied bounds, and not requiring that they hold when unsizing.

After this PR, we include these bounds, but (still) do not require that they are provided. If the are not provided, they are skipped from the projections list.

This results in `dyn Trait` types that have differing numbers of projection bounds. This will lead to re-introducing type mismatches e.g. between `dyn Trait` and `dyn Trait<Assoc = ()>`. However, this is expected and doesn't suffer from any of the deduplication unsoundness from before #136458.

We may want to begin to ignore thse bounds in the future by bumping `unused_associated_type_bounds` to an FCW. I don't want to tangle that up into the fix that was originally intended in #136458, so I'm doing a "fix-forward" in this PR and deferring thinking about this for the future.

Fixes #140645

r? lcnr
2025-05-08 20:22:16 +02:00
Matthias Krüger
34feb216e6
Rollup merge of #140769 - Zoxc:fix-140731, r=oli-obk
Add `DefPathData::OpaqueLifetime` to avoid conflicts for remapped opaque lifetimes

This adds `DefPathData::OpaqueLifetime` to ensure the def paths for remapped opaque lifetimes remain unique.

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

r? ``@oli-obk``
2025-05-08 08:14:20 +02:00
Matthias Krüger
a810f8ac89
Rollup merge of #140523 - compiler-errors:late-early-mismatch, r=jackh726
Better error message for late/early lifetime param mismatch

Rework the way we report early-/late-bound lifetime param mismatches to equate the trait and impl signatures using region variables, so that we can detect when a late-bound param is present in the signature in place of an early-bound param, or vice versa.

The diagnostic is a bit more technical, but it's more obviously clear to see what the problem is, even if it's not great at explaining how to fix it. I think this could be improved further, but I still think it's much better than what exists today.

Note to reviewer(s): I'd appreciate if we didn't bikeshed *too* much about this verbiage, b/c I hope it's clear that the old message sucked a lot. I'm happy to file bugs for interested new contributors to improve the messaging further.

Edit(fmease): Fixes https://github.com/rust-lang/rust/issues/33624.
2025-05-08 08:14:16 +02:00
John Kåre Alsaker
5913e55dfc Add DefPathData::OpaqueLifetime to avoid conflicts for remapped opaque lifetimes 2025-05-07 22:17:29 +02:00
Michael Goulet
f03d246db9 Better error message for late/early lifetime param mismatch 2025-05-07 18:12:54 +00:00
Michael Goulet
3799d8427a Review 2025-05-07 17:29:12 +00:00
Michael Goulet
b27d630f89 Point out region bound mismatches in check_region_bounds_on_impl_item 2025-05-07 17:13:39 +00:00
Michael Goulet
fd37906477 Only include associated type bounds for Self:Sized associated types if they are provided 2025-05-07 16:36:55 +00:00
Michael Goulet
df13f7c1fa Require T: TypeFoldable in Binder<T> visit 2025-05-07 16:00:21 +00:00
Guillaume Gomez
bdbf1c631a
Rollup merge of #140672 - compiler-errors:deeply-normalize, r=lcnr
Deeply normalize in the new solver in WF

We need to deeply normalize types we check for well-formedness, since we only collect implied bounds from normalized signature types.

Fixes https://github.com/rust-lang/trait-system-refactor-initiative/issues/194

r? lcnr
2025-05-05 21:32:35 +02:00
Guillaume Gomez
1e90557ae8
Rollup merge of #140374 - compiler-errors:global_asm-bug, r=lcnr
Resolve instance for SymFn in global/naked asm

`Instance::expect_resolve` ensures that we're actually going from trait item -> impl item.

Fixes #140373
2025-05-05 21:32:32 +02:00
Michael Goulet
12d3021ef0 Deeply normalize in the new solver in WF 2025-05-05 15:52:38 +00:00
Michael Goulet
833c212b81 Rename Instance::new to Instance::new_raw and add a note that it is raw 2025-05-05 13:17:35 +00:00
bors
243c5a35e1 Auto merge of #140453 - Zoxc:next-disambiguator, r=oli-obk
Remove global `next_disambiguator` state and handle it with a `DisambiguatorState` type

This removes `Definitions.next_disambiguator` as it doesn't guarantee deterministic def paths when `create_def` is called in parallel. Instead a new `DisambiguatorState` type is passed as a mutable reference to `create_def` to help create unique def paths. `create_def` calls with distinct  `DisambiguatorState` instances must ensure that that the def paths are unique without its help.

Anon associated types did rely on this global state for uniqueness and are changed to use (method they're defined in + their position in the method return type) as the `DefPathData` to ensure uniqueness. This also means that the method they're defined in appears in error messages, which is nicer.

`DefPathData::NestedStatic` is added to use for nested data inside statics instead of reusing `DefPathData::AnonConst` to avoid conflicts with those.

cc `@oli-obk`
2025-05-05 11:50:43 +00:00
John Kåre Alsaker
acb50d5136 Add comment on creation of lifetime inside opaque types 2025-05-04 20:05:59 +02:00
Vadim Petrochenkov
3eee3dad5c resolve: Support imports of associated types and glob imports from traits 2025-05-02 15:59:38 +03:00
Trevor Gross
a20fe8ff23
Rollup merge of #139909 - oli-obk:or-patterns, r=BoxyUwU
implement or-patterns for pattern types

These are necessary to represent `NonZeroI32`, as the range for that is `..0 | 1..`. The `rustc_scalar_layout_range_*` attributes avoided this by just implementing wraparound and having a single `1..=-1` range effectively. See https://rust-lang.zulipchat.com/#narrow/channel/481660-t-lang.2Fpattern-types/topic/.60or.20pattern.60.20representation.20in.20type.20system/with/504217694 for some background discussion

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

r? `@BoxyUwU`
2025-04-29 12:28:22 -04:00
John Kåre Alsaker
e561ec0e03 Remove global next_disambiguator state and handle it with a DisambiguatorState type 2025-04-29 13:22:38 +02:00
Chris Denton
3f5406f5be
Rollup merge of #140302 - compiler-errors:inline_asm-bug, r=lcnr
Move inline asm check to typeck, properly handle aliases

Pull `InlineAsmCtxt` down to `rustc_hir_typeck`, and instead of using things like `Ty::is_copy`, use the `InferCtxt`-aware methods. To fix https://github.com/rust-lang/trait-system-refactor-initiative/issues/189, we also add a `try_structurally_resolve_*` call to `expr_ty`.

r? lcnr
2025-04-28 23:29:16 +00:00
Guillaume Gomez
7843686ffe
Rollup merge of #140249 - BoxyUwU:remove_weak_alias_terminology, r=oli-obk
Remove `weak` alias terminology

I find the "weak" alias terminology to be quite confusing. It implies the existence of "strong" aliases (which do not exist) and I'm not really sure what about weak aliases is "weak". I much prefer "free alias" as the term. I think it's much more obvious what it means as "free function" is a well defined term that already exists in rust.

It's also a little confusing given "weak alias" is already a term in linker/codegen spaces which are part of the compiler too. Though I'm not particularly worried about that as it's usually very obvious if you're talking about the type system or not lol. I'm also currently trying to write documentation about aliases and it's somewhat awkward/confusing to be talking about *weak* aliases, when I'm not really sure what the basis for that as the term actually *is*.

I would also be happy to just find out there's a nice meaning behind calling them "weak" aliases :-)

r? `@oli-obk`

maybe we want a types MCP to decide on a specific naming here? or maybe we think its just too late to go back on this naming decision ^^'
2025-04-28 13:30:45 +02:00
Oli Scherer
b023856f29 Add or-patterns to pattern types 2025-04-28 07:50:18 +00:00
Oli Scherer
cb6d3715a5 Split out various pattern type matches into their own function 2025-04-28 07:46:50 +00:00
Oli Scherer
6008592fca Separate pattern lowering from pattern type lowering 2025-04-28 07:36:59 +00:00
Michael Goulet
3ab6051b95 Move inline_asm to typeck, properly handle aliases 2025-04-27 22:05:07 +00:00
bors
496145b9cc Auto merge of #139646 - lcnr:default-is-fully-concrete, r=BoxyUwU
check types of const param defaults

fixes #139643 by checking that the type of a const parameter default matches the type of the parameter as long as both types are fully concrete

r? `@BoxyUwU`
2025-04-27 01:59:43 +00:00
Matthias Krüger
3c322bc1cc
Rollup merge of #140320 - lcnr:wf-use-term, r=compiler-errors
replace `GenericArg` with `Term` where applicable

r? types
2025-04-26 16:12:33 +02:00
Matthias Krüger
fbf68324fc
Rollup merge of #140317 - mejrs:check_on_uni, r=compiler-errors
Remove redundant check

We still check for `rustc_on_unimplemented` on implementations, but this functionality was removed in https://github.com/rust-lang/rust/pull/139091, since then it always returns `Ok` when called with a non-trait defid.

b4c8b0c3f0/compiler/rustc_trait_selection/src/error_reporting/traits/on_unimplemented.rs (L557-L564)
2025-04-26 16:12:32 +02:00
lcnr
855035b038 convert some GenericArg to Term 2025-04-26 02:05:31 +00:00
mejrs
1ec3e626c2 Remove redundant check 2025-04-26 01:57:08 +02:00
Matthias Krüger
564e5ccb5c
Rollup merge of #140202 - est31:let_chains_feature_compiler, r=lcnr
Make #![feature(let_chains)] bootstrap conditional in compiler/

Let chains have been stabilized recently in #132833, so we can remove the gating from our uses in the compiler (as the compiler uses edition 2024).
2025-04-25 07:50:25 +02:00
lcnr
8cd12bf8fa check types of const param default 2025-04-24 13:28:59 +00:00
Boxy
bdfeb8f36b Remove weak alias terminology 2025-04-24 11:59:20 +01:00
est31
7493e1cdf6 Make #![feature(let_chains)] bootstrap conditional in compiler/ 2025-04-23 16:40:30 +02:00
Oli Scherer
5d2952100f Use is_lang_item and as_lang_item instead of handrolling their logic 2025-04-22 11:02:37 +00:00
Michael Goulet
6033e9df02 Don't compute name of associated item if it's an RPITIT 2025-04-20 16:08:39 +00:00
Matthias Krüger
c8a9095f0f
Rollup merge of #138528 - dianne:implicit-deref-patterns, r=Nadrieril
deref patterns: implement implicit deref patterns

This implements implicit deref patterns (per https://hackmd.io/4qDDMcvyQ-GDB089IPcHGg#Implicit-deref-patterns) and adds tests and an unstable book chapter.

Best reviewed commit-by-commit. Overall there's a lot of additions, but a lot of that is tests, documentation, and simple(?) refactoring.

Tracking issue: #87121

r? ``@Nadrieril``
2025-04-18 05:16:28 +02:00
dianne
977c9ab7a2 respect the tcx's recursion limit when peeling 2025-04-16 15:42:12 -07:00
Matthias Krüger
8e5df28a6a
Rollup merge of #139770 - nnethercote:rename-LifetimeName, r=BoxyUwU
Rename `LifetimeName` as `LifetimeKind`.

It's a much better name, more consistent with how we name such things.

Also rename `Lifetime::res` as `Lifetime::kind` to match. I suspect this field used to have the type `LifetimeRes` and then the type was changed but the field name remained the same.

r? ``@BoxyUwU``
2025-04-17 00:14:26 +02:00
Nicholas Nethercote
fe882bf330 Rename LifetimeName as LifetimeKind.
It's a much better name, more consistent with how we name such things.

Also rename `Lifetime::res` as `Lifetime::kind` to match. I suspect this
field used to have the type `LifetimeRes` and then the type was changed
but the field name remained the same.
2025-04-16 07:16:40 +10:00
Michael Goulet
11e5987d01 Don't compute name of associated item if it's an RPITIT 2025-04-15 18:46:26 +00:00
bors
f433fa46b0 Auto merge of #139845 - Zalathar:rollup-u5u5y1v, r=Zalathar
Rollup of 17 pull requests

Successful merges:

 - #138374 (Enable contracts for const functions)
 - #138380 (ci: add runners for vanilla LLVM 20)
 - #138393 (Allow const patterns of matches to contain pattern types)
 - #139517 (std: sys: process: uefi: Use NULL stdin by default)
 - #139554 (std: add Output::exit_ok)
 - #139660 (compiletest: Add an experimental new executor to replace libtest)
 - #139669 (Overhaul `AssocItem`)
 - #139671 (Proc macro span API redesign: Replace proc_macro::SourceFile by Span::{file, local_file})
 - #139750 (std/thread: Use default stack size from menuconfig for NuttX)
 - #139772 (Remove `hir::Map`)
 - #139785 (Let CStrings be either 1 or 2 byte aligned.)
 - #139789 (do not unnecessarily leak auto traits in item bounds)
 - #139791 (drop global where-bounds before merging candidates)
 - #139798 (normalize: prefer `ParamEnv` over `AliasBound` candidates)
 - #139822 (Fix: Map EOPNOTSUPP to ErrorKind::Unsupported on Unix)
 - #139833 (Fix some HIR pretty-printing problems)
 - #139836 (Basic tests of MPMC receiver cloning)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-04-15 08:02:23 +00:00
Stuart Cook
13cd5256ac
Rollup merge of #139669 - nnethercote:overhaul-AssocItem, r=oli-obk
Overhaul `AssocItem`

`AssocItem` has multiple fields that only make sense some of the time. E.g. the `name` can be empty if it's an RPITIT associated type. It's clearer and less error prone if these fields are moved to the relevant `kind` variants.

r? ``@fee1-dead``
2025-04-15 15:47:27 +10:00
Stuart Cook
380ad1b5d4
Rollup merge of #138374 - celinval:issue-136925-const-contract, r=compiler-errors,oli-obk,RalfJung
Enable contracts for const functions

Use `const_eval_select!()` macro to enable contract checking only at runtime. The existing contract logic relies on closures, which are not supported in constant functions.

This commit also removes one level of indirection for ensures clauses since we no longer build a closure around the ensures predicate.

Resolves #136925

**Call-out:** This is still a draft PR since CI is broken due to a new warning message for unreachable code when the bottom of the function is indeed unreachable. It's not clear to me why the warning wasn't triggered before.

r? ```@compiler-errors```
2025-04-15 15:47:24 +10:00
Nicholas Nethercote
78599d83e7 Move name field from AssocItem to AssocKind variants.
To accurately reflect that RPITIT assoc items don't have a name. This
avoids the use of `kw::Empty` to mean "no name", which is error prone.

Helps with #137978.
2025-04-15 08:07:15 +10:00
Nicholas Nethercote
89e93a51c8 Move two methods from AssocKind to AssocItem.
Because all the other similar methods are on `AssocItem`.
2025-04-15 08:07:15 +10:00
Nicholas Nethercote
b26f3d4347 Move opt_rpitit_info field to hir::AssocKind::Type.
From `hir::AssocItem`.
2025-04-15 08:06:59 +10:00