summary refs log tree commit diff
path: root/compiler/rustc_ty_utils/src
AgeCommit message (Collapse)AuthorLines
2023-05-20ensure !Unpin types do not get noaliasErik Desjardins-17/+19
2023-05-20improve code checking for drop_in_place lang itemErik Desjardins-4/+2
2023-05-20Apply `noalias`, `nonnull`, `dereferenceable`, and `align` attributes ↵Patrick Walton-17/+10
unconditionally. We've done measurements with Miri and have determined that `noalias` shouldn't break code. The requirements that allow us to add dereferenceable and align have been long documented in the standard library documentation.
2023-05-20[rustc_ty_utils] Add the LLVM `noalias` parameter attribute to ↵Patrick Walton-1/+35
`drop_in_place` in certain cases. LLVM can make use of the `noalias` parameter attribute on the parameter to `drop_in_place` in areas like argument promotion. Because the Rust compiler fully controls the code for `drop_in_place`, it can soundly deduce parameter attributes on it. In the case of a value that has a programmer-defined Drop implementation, we know that the first thing `drop_in_place` will do is pass a pointer to the object to `Drop::drop`. `Drop::drop` takes `&mut`, so it must be guaranteed that there are no pointers to the object upon entering that function. Therefore, it should be safe to mark `noalias` there. With this patch, we mark `noalias` only when the type is a value with a programmer-defined Drop implementation. This is possibly overly conservative, but I thought that proceeding cautiously was best in this instance.
2023-05-15Rollup merge of #111578 - Zoxc:query-macro-move, r=cjgillotMatthias Krüger-29/+33
Move expansion of query macros in rustc_middle to rustc_middle::query This moves the expansion of `define_callbacks!` and `define_feedable!` from `rustc_middle::ty::query` to `rustc_middle::query`. This means that types used in queries are both imported and used in `rustc_middle::query` instead of being split between these modules. It also decouples `rustc_middle::ty::query` further from `rustc_middle` which is helpful since we want to move `rustc_middle::ty::query` to the query system crates.
2023-05-15Move expansion of query macros in rustc_middle to rustc_middle::queryJohn Kåre Alsaker-29/+33
2023-05-15Auto merge of #111570 - compiler-errors:ct-err, r=BoxyUwUbors-3/+1
Rename const error methods for consistency renames `ty::Const`'s methods for creating a `ConstKind::Error` to be in the same naming style as `ty::Ty`'s equivalent methods. r? `@BoxyUwU`
2023-05-14Rename const error methods for consistencyMichael Goulet-3/+1
2023-05-12Use the opaque_types_defined_by query to cheaply check for whether a hidden ↵Oli Scherer-25/+164
type may be registered for an opaque type
2023-05-12add `query opaque_types_defined_by`lcnr-0/+82
2023-05-11Rollup merge of #106038 - aliemjay:opaque-implied, r=lcnrMichael Goulet-1/+12
use implied bounds when checking opaque types During opaque type inference, we check for the well-formedness of the hidden type in the opaque type's own environment, not the one of the defining site, which are different in the case of TAIT. However in the case of associated-type-impl-trait, we don't use implied bounds from the impl header. This caused us to reject the following: ```rust trait Service<Req> { type Output; fn call(req: Req) -> Self::Output; } impl<'a, Req> Service<&'a Req> for u8 { type Output= impl Sized; // we can't prove WF of hidden type `WF(&'a Req)` although it's implied by the impl //~^ ERROR type parameter Req doesn't live long enough fn call(req: &'a Req) -> Self::Output { req } } ``` although adding an explicit bound would make it pass: ```diff - impl<'a, Req> Service<&'a Req> for u8 { + impl<'a, Req> Service<&'a Req> for u8 where Req: 'a, { ``` I believe it should pass as we already allow the concrete type to be used: ```diff impl<'a, Req> Service<&'a Req> for u8 { - type Output= impl Sized; + type Output= &'a Req; ``` Fixes #95922 Builds on #105982 cc ``@lcnr`` (because implied bounds) r? ``@oli-obk``
2023-05-09add EarlyBinder to thir_abstract_const; remove tcx.bound_abstract_constKyle Matsuda-2/+2
2023-05-08Fix miscompilation when adding default method to `Future`Jonas Schievink-14/+11
2023-05-08Rollup merge of #111265 - spastorino:has_self-opaque_ty, r=compiler-errorsDylan DPC-1/+1
Make generics_of has_self on RPITITs delegate to the opaque r? `@compiler-errors` I couldn't come up with a test case and none of the ones in the `tests` folder is impacted by this change, but I still think is the right thing to do. Michael, let me know if you have ideas on how to add a test that's affected by this change.
2023-05-06make (try_)subst_and_normalize_erasing_regions take EarlyBinderKyle Matsuda-2/+1
2023-05-07use implied bounds when checking opaque typesAli MJ Al-Nasrawy-1/+12
2023-05-06Rollup merge of #111279 - compiler-errors:core-item-resolve, r=cjgillotMatthias Krüger-13/+71
More robust debug assertions for `Instance::resolve` on built-in traits with non-standard trait items In #111264, a user added a new item to the `Future` trait, but the code in [`resolve_associated_item`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_ty_utils/instance/fn.resolve_associated_item.html) implicitly assumes that the `Future` trait is defined with only one method (`Future::poll`) and treats the generator body as the implementation of that method. This PR adds some debug assertions to make sure that that new methods defined on `Future`/`Generator`/etc. don't accidentally resolve to the wrong item when they are added, and adds a helpful comment guiding a compiler dev (or curious `#![no_core]` user) to what must be done to support adding new associated items to these built-in implementations. I am open to discuss whether a test should be added, but I chose against it because I opted to make these `bug!()`s instead of, e.g., diagnostics or fatal errors. Arguably it doesn't need a test because it's not a bug that can be triggered by an end user, and internal-facing misuses of core kind of touch on rust-lang/compiler-team#620 -- however, I think the assertions I added in this PR are still a very useful way to make sure this bug doesn't waste debugging resources down the line. Fixes #111264
2023-05-06More robust debug assertions for `Instance::resolve` on built-in traits with ↵Michael Goulet-13/+71
custom items
2023-05-05Factor out checks in layout check and add helper inherent_size.Luqman Aden-54/+41
2023-05-05Make generics_of has_self on RPITITs delegate to the opaqueSantiago Pastorino-1/+1
2023-05-04Auto merge of #110806 - WaffleLapkin:unmkI, r=lcnrbors-3/+2
Replace `tcx.mk_trait_ref` with `TraitRef::new` First step in implementing https://github.com/rust-lang/compiler-team/issues/616 r? `@lcnr`
2023-05-03Restrict `From<S>` for `{D,Subd}iagnosticMessage`.Nicholas Nethercote-2/+2
Currently a `{D,Subd}iagnosticMessage` can be created from any type that impls `Into<String>`. That includes `&str`, `String`, and `Cow<'static, str>`, which are reasonable. It also includes `&String`, which is pretty weird, and results in many places making unnecessary allocations for patterns like this: ``` self.fatal(&format!(...)) ``` This creates a string with `format!`, takes a reference, passes the reference to `fatal`, which does an `into()`, which clones the reference, doing a second allocation. Two allocations for a single string, bleh. This commit changes the `From` impls so that you can only create a `{D,Subd}iagnosticMessage` from `&str`, `String`, or `Cow<'static, str>`. This requires changing all the places that currently create one from a `&String`. Most of these are of the `&format!(...)` form described above; each one removes an unnecessary static `&`, plus an allocation when executed. There are also a few places where the existing use of `&String` was more reasonable; these now just use `clone()` at the call site. As well as making the code nicer and more efficient, this is a step towards possibly using `Cow<'static, str>` in `{D,Subd}iagnosticMessage::{Str,Eager}`. That would require changing the `From<&'a str>` impls to `From<&'static str>`, which is doable, but I'm not yet sure if it's worthwhile.
2023-04-27rename `needs_infer` to `has_infer`Boxy-2/+2
2023-04-26Add new `ToPredicate` impls and `TraitRef` methods to remove some ↵Maybe Waffle-3/+2
`ty::Binber::dummy` calls
2023-04-25Replace `tcx.mk_trait_ref` with `ty::TraitRef::new`Maybe Waffle-1/+1
2023-04-24Split `{Idx, IndexVec, IndexSlice}` into their own modulesMaybe Waffle-1/+1
2023-04-22Auto merge of #106934 - DrMeepster:offset_of, r=WaffleLapkinbors-0/+2
Add offset_of! macro (RFC 3308) Implements https://github.com/rust-lang/rfcs/pull/3308 (tracking issue #106655) by adding the built in macro `core::mem::offset_of`. Two of the future possibilities are also implemented: * Nested field accesses (without array indexing) * DST support (for `Sized` fields) I wrote this a few months ago, before the RFC merged. Now that it's merged, I decided to rebase and finish it. cc `@thomcc` (RFC author)
2023-04-21offset_ofDrMeepster-0/+2
2023-04-20Remove WithOptconstParam.Camille GILLOT-76/+33
2023-04-20Feed type_of query instead of using WithOptconstParam.Camille GILLOT-6/+0
2023-04-19Auto merge of #110407 - Nilstrieb:fluent-macro, r=davidtwcobors-1/+1
Add `rustc_fluent_macro` to decouple fluent from `rustc_macros` Fluent, with all the icu4x it brings in, takes quite some time to compile. `fluent_messages!` is only needed in further downstream rustc crates, but is blocking more upstream crates like `rustc_index`. By splitting it out, we allow `rustc_macros` to be compiled earlier, which speeds up `x check compiler` by about 5 seconds (and even more after the needless dependency on `serde_json` is removed from `rustc_data_structures`).
2023-04-18Add `rustc_fluent_macro` to decouple fluent from `rustc_macros`Nilstrieb-1/+1
Fluent, with all the icu4x it brings in, takes quite some time to compile. `fluent_messages!` is only needed in further downstream rustc crates, but is blocking more upstream crates like `rustc_index`. By splitting it out, we allow `rustc_macros` to be compiled earlier, which speeds up `x check compiler` by about 5 seconds (and even more after the needless dependency on `serde_json` is removed from `rustc_data_structures`).
2023-04-17Spelling - compilerJosh Soref-2/+2
* account * achieved * advising * always * ambiguous * analysis * annotations * appropriate * build * candidates * cascading * category * character * clarification * compound * conceptually * constituent * consts * convenience * corresponds * debruijn * debug * debugable * debuggable * deterministic * discriminant * display * documentation * doesn't * ellipsis * erroneous * evaluability * evaluate * evaluation * explicitly * fallible * fulfill * getting * has * highlighting * illustrative * imported * incompatible * infringing * initialized * into * intrinsic * introduced * javascript * liveness * metadata * monomorphization * nonexistent * nontrivial * obligation * obligations * offset * opaque * opportunities * opt-in * outlive * overlapping * paragraph * parentheses * poisson * precisely * predecessors * predicates * preexisting * propagated * really * reentrant * referent * responsibility * rustonomicon * shortcircuit * simplifiable * simplifications * specify * stabilized * structurally * suggestibility * translatable * transmuting * two * unclosed * uninhabited * visibility * volatile * workaround Signed-off-by: Josh Soref <2119212+jsoref@users.noreply.github.com>
2023-04-16fix clippy::toplevel_ref_arg and ::manual_mapMatthias Krüger-8/+5
2023-04-10Fix typos in compilerDaniPopes-2/+2
2023-04-08Update compiler/rustc_ty_utils/src/layout.rs matthewjasper-1/+1
Fix formatting that rustfmt can't handle currently. Co-authored-by: Michael Goulet <michael@errs.io>
2023-04-08Move SIMD layout errors to `SessionDiagnostic`Matthew Jasper-20/+47
2023-04-07Move `FnPtrAddr` error to `SessionDiagnostic`Matthew Jasper-4/+12
2023-04-04Use `FieldIdx` in `FieldsShape`Scott McMurray-47/+41
Finally got to the main motivating example from the MCP :)
2023-03-31Auto merge of #109762 - scottmcm:variantdef-indexvec, r=WaffleLapkinbors-4/+5
Update `ty::VariantDef` to use `IndexVec<FieldIdx, FieldDef>` And while doing the updates for that, also uses `FieldIdx` in `ProjectionKind::Field` and `TypeckResults::field_indices`. There's more places that could use it (like `rustc_const_eval` and `LayoutS`), but I tried to keep this PR from exploding to *even more* places. Part 2/? of https://github.com/rust-lang/compiler-team/issues/606
2023-03-30Update `ty::VariantDef` to use `IndexVec<FieldIdx, FieldDef>`Scott McMurray-4/+5
And while doing the updates for that, also uses `FieldIdx` in `ProjectionKind::Field` and `TypeckResults::field_indices`. There's more places that could use it (like `rustc_const_eval` and `LayoutS`), but I tried to keep this PR from exploding to *even more* places. Part 2/? of https://github.com/rust-lang/compiler-team/issues/606
2023-03-30Auto merge of #109499 - spastorino:new-rpitit-19, r=compiler-errorsbors-16/+19
Give return-position impl traits in trait a (synthetic) name to avoid name collisions with new lowering strategy The only needed commit from this PR is the last one. r? `@compiler-errors` Needs #109455.
2023-03-29Walk return-position impl trait in trait deeply in associated_item_def_idsMichael Goulet-16/+19
2023-03-29Support TLS access into dylibs on WindowsJohn Kåre Alsaker-1/+11
2023-03-27Add a builtin `FnPtr` traitlcnr-1/+18
2023-03-25Refactor: `VariantIdx::from_u32(0)` -> `FIRST_VARIANT`Scott McMurray-7/+7
Since structs are always `VariantIdx(0)`, there's a bunch of files where the only reason they had `VariantIdx` or `vec::Idx` imported at all was to get the first variant. So this uses a constant for that, and adds some doc-comments to `VariantIdx` while I'm there, since it doesn't have any today.
2023-03-23Auto merge of #109503 - matthiaskrgr:rollup-cnp7kdd, r=matthiaskrgrbors-1/+1
Rollup of 9 pull requests Successful merges: - #108954 (rustdoc: handle generics better when matching notable traits) - #109203 (refactor/feat: refactor identifier parsing a bit) - #109213 (Eagerly intern and check CrateNum/StableCrateId collisions) - #109358 (rustc: Remove unused `Session` argument from some attribute functions) - #109359 (Update stdarch) - #109378 (Remove Ty::is_region_ptr) - #109423 (Use region-erased self type during IAT selection) - #109447 (new solver cleanup + implement coherence) - #109501 (make link clickable) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2023-03-22Rollup merge of #109378 - MU001999:master, r=scottmcmMatthias Krüger-1/+1
Remove Ty::is_region_ptr Fixes #109372
2023-03-22Auto merge of #109497 - matthiaskrgr:rollup-6txuxm0, r=matthiaskrgrbors-5/+3
Rollup of 10 pull requests Successful merges: - #109373 (Set LLVM `LLVM_UNREACHABLE_OPTIMIZE` to `OFF`) - #109392 (Custom MIR: Allow optional RET type annotation) - #109394 (adapt tests/codegen/vec-shrink-panik for LLVM 17) - #109412 (rustdoc: Add GUI test for "Auto-hide item contents for large items" setting) - #109452 (Ignore the vendor directory for tidy tests.) - #109457 (Remove comment about reusing rib allocations) - #109461 (rustdoc: remove redundant `.content` prefix from span/a colors) - #109477 (`HirId` to `LocalDefId` cleanup) - #109489 (More general captures) - #109494 (Do not feed param_env for RPITITs impl side) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2023-03-23Rollup merge of #109405 - compiler-errors:rpitit-as-opaques, r=spastorinoDylan DPC-11/+13
RPITITs are `DefKind::Opaque` with new lowering strategy r? `@spastorino` Kinda cherry-picked #109400