summary refs log tree commit diff
path: root/compiler/rustc_middle/src/ty
AgeCommit message (Collapse)AuthorLines
2023-11-08rustc: minor changes suggested by clippy perf lints.Nicholas Nethercote-1/+1
2023-11-06Auto merge of #117603 - HKalbasi:make-feature-additive, r=Nilstriebbors-1/+1
Make the randomize feature of rustc_abi additive The goal here is to make rust-analyzer able to build with the `rustc_private` versions of the rustc crates it depends on. See #116847
2023-11-05Make the randomize feature of rustc_abi additivehkalbasi-1/+1
2023-11-05Auto merge of #117589 - compiler-errors:global-vars-bug, r=jackh726bors-32/+12
Make sure that predicates with unmentioned bound vars are still considered global in the old solver In the old solver, we consider predicates with late-bound vars to not be "global": https://github.com/rust-lang/rust/blob/9c8a2694fadf3900c4d7880f6357cee60e9aa39b/compiler/rustc_trait_selection/src/traits/select/mod.rs#L1840-L1844 The implementation of `has_late_bound_vars` was modified in #115834 so that we'd properly anonymize binders that had late-bound vars but didn't reference them. This fixed an ICE. However, this also led to a behavioral change in https://github.com/rust-lang/rust/issues/117056#issuecomment-1775014545 for a couple of crates, which now consider `for<'a> GL33: Shader` (note the binder var that is *not* used in the predicate) to not be "global". This forces associated types to not be normalizable due to the old trait solver being dumb. This PR distinguishes types which *reference* late-bound vars and binders which *have* late-bound vars. The latter is represented with the new type flag `TypeFlags::HAS_BINDER_VARS`, which is used when we only care about knowing whether binders have vars in their bound var list (even if they're not used, like for binder anonymization). This should fix (after beta backport) the `luminance-gl` and `luminance-webgl` crates in #117056. r? types **(priority is kinda high on a review here given beta becomes stable on November 16.)**
2023-11-04Rollup merge of #117583 - compiler-errors:placeholderconst-lifetime, r=cjgillotMatthias Krüger-3/+3
Remove `'tcx` lifetime on `PlaceholderConst` The `'tcx` lifetime is not needed for anything, so this is a continuation of #117139.
2023-11-04Make sure that predicates with unmentioned bound vars are still considered ↵Michael Goulet-32/+12
global in the old solver
2023-11-04No lifetime on PlaceholderConstMichael Goulet-3/+3
2023-11-03Rollup merge of #117505 - estebank:issue-117501, r=TaKO8KiMatthias Krüger-0/+2
Fix incorrect trait bound restriction suggestion Suggest ``` error[E0308]: mismatched types --> $DIR/restrict-assoc-type-of-generic-bound.rs:9:12 | LL | pub fn foo<A: MyTrait, B>(a: A) -> B { | - - expected `B` because of return type | | | expected this type parameter LL | return a.bar(); | ^^^^^^^ expected type parameter `B`, found associated type | = note: expected type parameter `B` found associated type `<A as MyTrait>::T` help: consider further restricting this bound | LL | pub fn foo<A: MyTrait<T = B>, B>(a: A) -> B { | +++++++ ``` instead of ``` error[E0308]: mismatched types --> $DIR/restrict-assoc-type-of-generic-bound.rs:9:12 | LL | pub fn foo<A: MyTrait, B>(a: A) -> B { | - - expected `B` because of return type | | | expected this type parameter LL | return a.bar(); | ^^^^^^^ expected type parameter `B`, found associated type | = note: expected type parameter `B` found associated type `<A as MyTrait>::T` help: consider further restricting this bound | LL | pub fn foo<A: MyTrait + <T = B>, B>(a: A) -> B { | +++++++++ ``` Fix #117501.
2023-11-02Fix incorrect trait bound restriction suggestionEsteban Küber-0/+2
Suggest ``` error[E0308]: mismatched types --> $DIR/restrict-assoc-type-of-generic-bound.rs:9:12 | LL | pub fn foo<A: MyTrait, B>(a: A) -> B { | - - expected `B` because of return type | | | expected this type parameter LL | return a.bar(); | ^^^^^^^ expected type parameter `B`, found associated type | = note: expected type parameter `B` found associated type `<A as MyTrait>::T` help: consider further restricting this bound | LL | pub fn foo<A: MyTrait<T = B>, B>(a: A) -> B { | +++++++ ``` instead of ``` error[E0308]: mismatched types --> $DIR/restrict-assoc-type-of-generic-bound.rs:9:12 | LL | pub fn foo<A: MyTrait, B>(a: A) -> B { | - - expected `B` because of return type | | | expected this type parameter LL | return a.bar(); | ^^^^^^^ expected type parameter `B`, found associated type | = note: expected type parameter `B` found associated type `<A as MyTrait>::T` help: consider further restricting this bound | LL | pub fn foo<A: MyTrait + <T = B>, B>(a: A) -> B { | +++++++++ ``` Fix #117501.
2023-11-02only erase param env regions where neededlcnr-1/+1
2023-11-02dropck_outlives check generator witness needs_droplcnr-4/+6
2023-11-01Auto merge of #114208 - GKFX:offset_of_enum, r=wesleywiserbors-5/+32
Support enum variants in offset_of! This MR implements support for navigating through enum variants in `offset_of!`, placing the enum variant name in the second argument to `offset_of!`. The RFC placed it in the first argument, but I think it interacts better with nested field access in the second, as you can then write things like ```rust offset_of!(Type, field.Variant.field) ``` Alternatively, a syntactic distinction could be made between variants and fields (e.g. `field::Variant.field`) but I'm not convinced this would be helpful. [RFC 3308 # Enum Support](https://rust-lang.github.io/rfcs/3308-offset_of.html#enum-support-offset_ofsomeenumstructvariant-field_on_variant) Tracking Issue #106655.
2023-11-01Auto merge of #116692 - Nadrieril:half-open-ranges, r=cjgillotbors-35/+43
Match usize/isize exhaustively with half-open ranges The long-awaited finale to the saga of [exhaustiveness checking for integers](https://github.com/rust-lang/rust/pull/50912)! ```rust match 0usize { 0.. => {} // exhaustive! } match 0usize { 0..usize::MAX => {} // helpful error message! } ``` Features: - Half-open ranges behave as expected for `usize`/`isize`; - Trying to use `0..usize::MAX` will tell you that `usize::MAX..` is missing and explain why. No more unhelpful "`_` is missing"; - Everything else stays the same. This should unblock https://github.com/rust-lang/rust/issues/37854. Review-wise: - I recommend looking commit-by-commit; - This regresses perf because of the added complexity in `IntRange`; hopefully not too much; - I measured each `#[inline]`, they all help a bit with the perf regression (tho I don't get why); - I did not touch MIR building; I expect there's an easy PR there that would skip unnecessary comparisons when the range is half-open.
2023-10-31Enums in offset_of: update based on est31, scottmcm & llogiq reviewGeorge Bateman-14/+18
2023-10-31Support enum variants in offset_of!George Bateman-6/+29
2023-10-30Some more coroutine renamingsMichael Goulet-1/+1
2023-10-29Ignore RPIT duplicated lifetimes in opaque_types_defined_byMichael Goulet-1/+1
2023-10-29Auto merge of #117336 - workingjubilee:rollup-6negquv, r=workingjubileebors-49/+37
Rollup of 4 pull requests Successful merges: - #117170 (Add support for i586-unknown-netbsd as target.) - #117259 (Declare rustc_target's dependency on object/macho) - #117322 (change default output mode of `BootstrapCommand`) - #117325 (Small ty::print cleanups) r? `@ghost` `@rustbot` modify labels: rollup
2023-10-29Auto merge of #116447 - oli-obk:gen_fn, r=compiler-errorsbors-0/+13
Implement `gen` blocks in the 2024 edition Coroutines tracking issue https://github.com/rust-lang/rust/issues/43122 `gen` block tracking issue https://github.com/rust-lang/rust/issues/117078 This PR implements `gen` blocks that implement `Iterator`. Most of the logic with `async` blocks is shared, and thus I renamed various types that were referring to `async` specifically. An example usage of `gen` blocks is ```rust fn foo() -> impl Iterator<Item = i32> { gen { yield 42; for i in 5..18 { if i.is_even() { continue } yield i * 2; } } } ``` The limitations (to be resolved) of the implementation are listed in the tracking issue
2023-10-28Remove needless `allow`sNilstrieb-5/+0
2023-10-28Move macros to usageNilstrieb-40/+40
2023-10-28Remove needless print ctx defsNilstrieb-7/+0
2023-10-27Abstract over `PatRange` boundary valueNadrieril-35/+43
2023-10-27Rollup merge of #117246 - estebank:issue-117209, r=petrochenkovMatthias Krüger-0/+28
Fix ICE: Restrict param constraint suggestion When encountering an associated item with a type param that could be constrained, do not look at the parent item if the type param comes from the associated item. Fix #117209, fix #89868.
2023-10-27Account for type param from other item in `note_and_explain`Esteban Küber-0/+28
Fix #89868.
2023-10-27Make `gen` blocks implement the `Iterator` traitOli Scherer-0/+11
2023-10-26Replace type flag HAS_TY_GENERATOR with HAS_TY_COROUTINELeón Orell Valerian Liehr-2/+2
2023-10-26Auto merge of #112875 - compiler-errors:negative-coherence-rework, r=lcnrbors-0/+1
Rework negative coherence to properly consider impls that only partly overlap This PR implements a modified negative coherence that handles impls that only have partial overlap. It does this by: 1. taking both impl trait refs, instantiating them with infer vars 2. equating both trait refs 3. taking the equated trait ref (which represents the two impls' intersection), and resolving any vars 4. plugging all remaining infer vars with placeholder types these placeholder-plugged trait refs can then be used normally with the new trait solver, since we no longer have to worry about the issue with infer vars in param-envs. We use the **new trait solver** to reason correctly about unnormalized trait refs (due to deferred projection equality), since this avoid having to normalize anything under param-envs with infer vars in them. This PR then additionally: * removes the `FnPtr` knowable hack by implementing proper negative `FnPtr` trait bounds for rigid types. --- An example: Consider these two partially overlapping impls: ``` impl<T, U> PartialEq<&U> for &T where T: PartialEq<U> {} impl<F> PartialEq<F> for F where F: FnPtr {} ``` Under the old algorithm, we would take one of these impls and replace it with infer vars, then try unifying it with the other impl under identity substitutions. This is not possible in either direction, since it either sets `T = U`, or tries to equate `F = &?0`. Under the new algorithm, we try to unify `?0: PartialEq<?0>` with `&?1: PartialEq<&?2>`. This gives us `?0 = &?1 = &?2` and thus `?1 = ?2`. The intersection of these two trait refs therefore looks like: `&?1: PartialEq<&?1>`. After plugging this with placeholders, we get a trait ref that looks like `&!0: PartialEq<&!0>`, with the first impl having substs `?T = ?U = !0` and the second having substs `?F = &!0`[^1]. Then we can take the param-env from the first impl, and try to prove the negated where clause of the second. We know that `&!0: !FnPtr` never holds, since it's a rigid type that is also not a fn ptr, we successfully detect that these impls may never overlap. [^1]: For the purposes of this example, I just ignored lifetimes, since it doesn't really matter.
2023-10-26Add hir::GeneratorKind::GenOli Scherer-0/+2
2023-10-25Rollup merge of #117175 - oli-obk:gen_fn_split, r=compiler-errorsMatthias Krüger-2/+6
Rename AsyncCoroutineKind to CoroutineSource pulled out of https://github.com/rust-lang/rust/pull/116447 Also refactors the printing infra of `CoroutineSource` to be ready for easily extending it with a `Gen` variant for `gen` blocks
2023-10-25Rollup merge of #117008 - compiler-errors:canonical, r=lcnrMatthias Krüger-19/+23
Uplift `Canonical` to `rustc_type_ir` I plan on moving the new trait solver's canonicalizer into either `rustc_type_ir` or a child crate. One dependency on this is lifting `Canonical<V>` to `rustc_type_ir` so we can actually name the canonicalized values. I may also later lift `CanonicalVarInfo` into the new trait solver. I can't really tell what other changes need to be done, but I'm just putting this up sooner than later since I'm almost certain it'll need to be done regardless of other design choices. There are a couple of warts introduced by this PR, since we no longer can define inherent `Canonical` impls in `rustc_middle` -- see the changes to: * `compiler/rustc_trait_selection/src/traits/query/normalize.rs` * `compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs` r? lcnr
2023-10-25Refactor away the need for some `descr` methods.Oli Scherer-2/+6
Instead we use `Display` impls and their `alternate` render scheme to decide whether we want backticks or not.
2023-10-25Add a IsIdentity extension trait for CanonicalUserTypeMichael Goulet-5/+9
2023-10-25Uplift Canonical to rustc_type_irMichael Goulet-17/+17
2023-10-25Rollup merge of #117136 - compiler-errors:defid-list, r=oli-obkMatthias Krüger-0/+10
Intern `LocalDefId` list from `opaque_types_defined_by` query r? oli-obk
2023-10-25Auto merge of #116993 - compiler-errors:clause-kind, r=jackh726bors-183/+78
Uplift `ClauseKind` and `PredicateKind` into `rustc_type_ir` Uplift `ClauseKind` and `PredicateKind` into `rustc_type_ir`. Blocked on #116951 r? `@ghost`
2023-10-24Get rid of 'tcx on ConstVid, EffectVidMichael Goulet-52/+35
2023-10-24Intern LocalDefId list from opaque queryMichael Goulet-0/+10
2023-10-24Rollup merge of #117091 - compiler-errors:debug, r=lcnrMatthias Krüger-36/+36
`OptWithInfcx` naming nits, trait bound simplifications * Use an associated type `Interner` on `InferCtxtLike` to remove a redundant interner parameter (`I: Interner, Infcx: InferCtxtLike<I>` -> `Infcx: InferCtxtLike`). * Remove double-`Option` between `infcx: Option<Infcx>` and `fn universe_of_ty(&self, ty: ty::InferTy) -> Option<ty::UniverseIndex>`. We don't need the infcx to be optional if we can provide a "noop" (`NoInfcx`) implementation that just always returns `None` for universe index. * Also removes the `core::convert::Infallible` implementation which I found a bit weird... * Some naming nits with params. * I found `InferCtxt` + `InfCtx` and `Infcx` to be a lot of different ways to spell "inference context", so I got rid of the `InfCtx` type parameter name in favor of `Infcx` which is a more standard name. * I found `OptWithInfcx` to be a bit redundant -> `WithInfcx`. I'm making these changes because I intend to reuse the `InferCtxtLike` trait for uplifting the canonicalizer into a new trait -- conveniently, the information I need for uplifting the canonicalizer also is just the universe information of a type var, so it's super convenient 😸 r? `@BoxyUwU` or `@lcnr`
2023-10-23pre-cleanupsMichael Goulet-0/+1
2023-10-23Auto merge of #117103 - matthiaskrgr:rollup-96zuuom, r=matthiaskrgrbors-310/+323
Rollup of 6 pull requests Successful merges: - #107159 (rand use getrandom for freebsd (available since 12.x)) - #116859 (Make `ty::print::Printer` take `&mut self` instead of `self`) - #117046 (return unfixed len if pat has reported error) - #117070 (rustdoc: wrap Type with Box instead of Generics) - #117074 (Remove smir from triage and add me to stablemir) - #117086 (Update .mailmap to promote my livename) r? `@ghost` `@rustbot` modify labels: rollup
2023-10-23Remove redundant type parameterMichael Goulet-36/+36
2023-10-23Naming nitsMichael Goulet-26/+26
2023-10-22use visibility to check unused imports and delete some stmtsbohan-2/+0
2023-10-21Make `ty::print::Printer` take `&mut self` instead of `self`Nilstrieb-310/+323
This simplifies the code by removing all the `self` assignments and makes the flow of data clearer - always into the printer. Especially in v0 mangling, which already used `&mut self` in some places, it gets a lot more uniform.
2023-10-20Uplift ClauseKind and PredicateKindMichael Goulet-183/+78
2023-10-20Rename `CoroutineKind::Gen` to `::Coroutine`Oli Scherer-3/+3
2023-10-20s/generator/coroutine/Oli Scherer-106/+106
2023-10-20s/Generator/Coroutine/Oli Scherer-123/+123
2023-10-20Adjust importsMichael Goulet-4/+4