summary refs log tree commit diff
path: root/compiler/rustc_middle/src
AgeCommit message (Collapse)AuthorLines
2024-02-08[Beta 1.77] Fix bootstrapping from 1.76Eric Huss-1/+1
2024-01-31Rollup merge of #120495 - clubby789:remove-amdgpu-kernel, r=oli-obkNadrieril-1/+0
Remove the `abi_amdgpu_kernel` feature The tracking issue (#51575) has been closed for 3 years, with no activity for 5.
2024-01-31Auto merge of #120346 - petrochenkov:ownodes, r=oli-obkbors-55/+55
hir: Refactor getters for owner nodes
2024-01-30Rollup merge of #120293 - estebank:issue-102629, r=nnethercoteGuillaume Gomez-0/+2
Deduplicate more sized errors on call exprs Change the implicit `Sized` `Obligation` `Span` for call expressions to include the whole expression. This aids the existing deduplication machinery to reduce the number of errors caused by a single unsized expression.
2024-01-30Remove the `abi_amdgpu_kernel` featureclubby789-1/+0
2024-01-30hir: Remove `hir::Map::{owner,expect_owner}`Vadim Petrochenkov-10/+2
2024-01-30hir: Add non-optional `hir_owner_nodes` for real `OwnerId`sVadim Petrochenkov-40/+53
2024-01-30hir: Simplify `hir_owner_nodes` queryVadim Petrochenkov-13/+8
The query accept arbitrary DefIds, not just owner DefIds. The return can be an `Option` because if there are no nodes, then it doesn't matter whether it's due to NonOwner or Phantom. Also rename the query to `opt_hir_owner_nodes`.
2024-01-30Rollup merge of #120488 - nnethercote:diag-lifetimes, r=oli-obkGuillaume Gomez-27/+21
Diagnostic lifetimes cleanups Some diagnostic simplifications. r? `@oli-obk`
2024-01-30Rollup merge of #120425 - DaniPopes:query-default-return, r=NilstriebGuillaume Gomez-14/+14
Remove unnecessary unit returns in query declarations For consistency with normal functions.
2024-01-30Remove the lifetime from `DiagnosticArgValue`.Nicholas Nethercote-27/+21
Because it's almost always static. This makes `impl IntoDiagnosticArg for DiagnosticArgValue` trivial, which is nice. There are a few diagnostics constructed in `compiler/rustc_mir_build/src/check_unsafety.rs` and `compiler/rustc_mir_transform/src/errors.rs` that now need symbols converted to `String` with `to_string` instead of `&str` with `as_str`, but that' no big deal, and worth it for the simplifications elsewhere.
2024-01-29Stop using `String` for error codes.Nicholas Nethercote-3/+3
Error codes are integers, but `String` is used everywhere to represent them. Gross! This commit introduces `ErrCode`, an integral newtype for error codes, replacing `String`. It also introduces a constant for every error code, e.g. `E0123`, and removes the `error_code!` macro. The constants are imported wherever used with `use rustc_errors::codes::*`. With the old code, we have three different ways to specify an error code at a use point: ``` error_code!(E0123) // macro call struct_span_code_err!(dcx, span, E0123, "msg"); // bare ident arg to macro call \#[diag(name, code = "E0123")] // string struct Diag; ``` With the new code, they all use the `E0123` constant. ``` E0123 // constant struct_span_code_err!(dcx, span, E0123, "msg"); // constant \#[diag(name, code = E0123)] // constant struct Diag; ``` The commit also changes the structure of the error code definitions: - `rustc_error_codes` now just defines a higher-order macro listing the used error codes and nothing else. - Because that's now the only thing in the `rustc_error_codes` crate, I moved it into the `lib.rs` file and removed the `error_codes.rs` file. - `rustc_errors` uses that macro to define everything, e.g. the error code constants and the `DIAGNOSTIC_TABLES`. This is in its new `codes.rs` file.
2024-01-27Remove unnecessary unit returns in query declarationsDaniPopes-14/+14
For consistency with normal functions.
2024-01-27Rollup merge of #120386 - klensy:destruction_scopes, r=compiler-errorsMatthias Krüger-8/+0
ScopeTree: remove destruction_scopes as unused last usages removed by https://github.com/rust-lang/rust/pull/116170 Unused, but still presented in memory at `t-gmax` (in DHAT termonology)
2024-01-26ScopeTree: remove destruction_scopes as unusedklensy-8/+0
last usages removed by https://github.com/rust-lang/rust/pull/116170
2024-01-26interpret: project_downcast: do not ICE for uninhabited variantsRalf Jung-0/+2
2024-01-26Auto merge of #119968 - clubby789:unused-feature, r=compiler-errorsbors-6/+0
Remove unused/unnecessary features ~~The bulk of the actual code changes here is replacing try blocks with equivalent closures. I'm not entirely sure that's a good idea since it may have perf impact, happy to revert if that's the case/the change is unwanted.~~ I also removed a lot of `recursion_limit = "256"` since everything seems to build fine without that and most don't have any comment justifying it.
2024-01-26Auto merge of #116167 - RalfJung:structural-eq, r=lcnrbors-7/+6
remove StructuralEq trait The documentation given for the trait is outdated: *all* function pointers implement `PartialEq` and `Eq` these days. So the `StructuralEq` trait doesn't really seem to have any reason to exist any more. One side-effect of this PR is that we allow matching on some consts that do not implement `Eq`. However, we already allowed matching on floats and consts containing floats, so this is not new, it is just allowed in more cases now. IMO it makes no sense at all to allow float matching but also sometimes require an `Eq` instance. If we want to require `Eq` we should adjust https://github.com/rust-lang/rust/pull/115893 to check for `Eq`, and rule out float matching for good. Fixes https://github.com/rust-lang/rust/issues/115881
2024-01-25Rollup merge of #120330 - ↵Matthias Krüger-4/+15
compiler-errors:no-coroutine-info-in-coroutine-drop-body, r=nnethercote Remove coroutine info when building coroutine drop body Coroutine drop shims are not themselves coroutines, so erase the "`coroutine`" field from the body so that helper fns like `yield_ty` and `coroutine_kind` properly return `None` for the drop shim.
2024-01-25Remove unused featuresclubby789-6/+0
2024-01-25Auto merge of #120335 - matthiaskrgr:rollup-2a0y3rd, r=matthiaskrgrbors-3/+12
Rollup of 10 pull requests Successful merges: - #119305 (Add `AsyncFn` family of traits) - #119389 (Provide more context on recursive `impl` evaluation overflow) - #119895 (Remove `track_errors` entirely) - #120230 (Assert that a single scope is passed to `for_scope`) - #120278 (Remove --fatal-warnings on wasm targets) - #120292 (coverage: Dismantle `Instrumentor` and flatten span refinement) - #120315 (On E0308 involving `dyn Trait`, mention trait objects) - #120317 (pattern_analysis: Let `ctor_sub_tys` return any Iterator they want) - #120318 (pattern_analysis: Reuse most of the `DeconstructedPat` `Debug` impl) - #120325 (rustc_data_structures: use either instead of itertools) r? `@ghost` `@rustbot` modify labels: rollup
2024-01-25Rollup merge of #119895 - oli-obk:track_errors_3, r=matthewjasperMatthias Krüger-3/+12
Remove `track_errors` entirely follow up to https://github.com/rust-lang/rust/pull/119869 r? `@matthewjasper` There are some diagnostic changes adding new diagnostics or not emitting some anymore. We can improve upon that in follow-up work imo.
2024-01-25Auto merge of #119955 - kamalesh0406:master, r=WaffleLapkinbors-18/+56
Modify GenericArg and Term structs to use strict provenance rules This is the first PR to solve issue #119217 . In this PR, I have modified the GenericArg struct to use the `NonNull` struct as the pointer instead of `NonZeroUsize`. The change were tested by running `./x test compiler/rustc_middle`. Resolves https://github.com/rust-lang/rust/issues/119217 r? `@WaffleLapkin`
2024-01-25What even is CoroutineInfoMichael Goulet-4/+15
2024-01-25Auto merge of #119627 - oli-obk:const_prop_lint_n̵o̵n̵sense, r=cjgillotbors-2/+0
Remove all ConstPropNonsense We track all locals and projections on them ourselves within the const propagator and only use the InterpCx to actually do some low level operations or read from constants (via `OpTy` we get for said constants). This helps moving the const prop lint out from the normal pipeline and running it just based on borrowck information. This in turn allows us to make progress on https://github.com/rust-lang/rust/pull/108730#issuecomment-1875557745 there are various follow up cleanups that can be done after this PR (e.g. not matching on Rvalue twice and doing binop checks twice), but lets try landing this one first. r? `@RalfJung`
2024-01-24remove StructuralEq traitRalf Jung-7/+6
2024-01-24Deduplicate more sized errors on call exprsEsteban Küber-0/+2
Change the implicit `Sized` `Obligation` `Span` for call expressions to include the whole expression. This aids the existing deduplication machinery to reduce the number of errors caused by a single unsized expression.
2024-01-23Auto merge of #120283 - fmease:rollup-rk0f6r5, r=fmeasebors-10/+17
Rollup of 9 pull requests Successful merges: - #112806 (Small code improvements in `collect_intra_doc_links.rs`) - #119766 (Split tait and impl trait in assoc items logic) - #120139 (Do not normalize closure signature when building `FnOnce` shim) - #120160 (Manually implement derived `NonZero` traits.) - #120171 (Fix assume and assert in jump threading) - #120183 (Add `#[coverage(off)]` to closures introduced by `#[test]` and `#[bench]`) - #120195 (add several resolution test cases) - #120259 (Split Diagnostics for Uncommon Codepoints: Add List to Display Characters Involved) - #120261 (Provide structured suggestion to use trait objects in some cases of `if` arm type divergence) r? `@ghost` `@rustbot` modify labels: rollup
2024-01-23Rollup merge of #120139 - compiler-errors:fnonce-shim, r=BoxyUwULeón Orell Valerian Liehr-10/+8
Do not normalize closure signature when building `FnOnce` shim It is not necessary to normalize the closure signature when building an `FnOnce` shim for an `Fn`/`FnMut` closure. That closure shim is just calling `FnMut::call_mut(&mut self)` anyways. It's also somewhat sketchy that we were ever doing this to begin with, since we're normalizing with a `ParamEnv::reveal_all()` param-env, which is definitely not right with possibly polymorphic substs. This cuts out a tiny bit of unnecessary work in `Instance::resolve` and simplifies the signature because now we can unconditionally return an `Instance`.
2024-01-23Rollup merge of #119766 - oli-obk:split_tait_and_atpit, r=compiler-errorsLeón Orell Valerian Liehr-0/+9
Split tait and impl trait in assoc items logic And simplify the assoc item logic where applicable. This separation shows that it is easier to reason about impl trait in assoc items compared with TAITs. See https://rust-lang.zulipchat.com/#narrow/stream/315482-t-compiler.2Fetc.2Fopaque-types/topic/impl.20trait.20in.20associated.20type for some discussion. The current plan is to try to stabilize impl trait in associated items before TAIT, as they do not have any issues with their defining scopes (see https://github.com/rust-lang/rust/issues/107645 for why this is not a trivial or uncontroversial topic).
2024-01-23Rollup merge of #120270 - compiler-errors:randos, r=lcnrLeón Orell Valerian Liehr-50/+33
A bunch of random modifications r? oli-obk Kitchen sink of changes that I didn't know where to put elsewhere. Documentation tweaks mostly, but also removing some unreachable code and simplifying the pretty printing for closures/coroutines.
2024-01-23const prop nonsense eliminatedOli Scherer-2/+0
2024-01-23Remove track_errors entirelyOli Scherer-3/+12
2024-01-23Random type checker changesMichael Goulet-50/+33
2024-01-23Auto merge of #119044 - RalfJung:intern-without-types, r=oli-obkbors-2/+8
const-eval interning: get rid of type-driven traversal This entirely replaces our const-eval interner, i.e. the code that takes the final result of a constant evaluation from the local memory of the const-eval machine to the global `tcx` memory. The main goal of this change is to ensure that we can detect mutable references that sneak into this final value -- this is something we want to reject for `static` and `const`, and while const-checking performs some static analysis to ensure this, I would be much more comfortable stabilizing const_mut_refs if we had a dynamic check that sanitizes the final value. (This is generally the approach we have been using on const-eval: do a static check to give nice errors upfront, and then do a dynamic check to be really sure that the properties we need for soundness, actually hold.) We can do this now that https://github.com/rust-lang/rust/pull/118324 landed and each pointer comes with a bit (completely independent of its type) storing whether mutation is permitted through this pointer or not. The new interner is a lot simpler than the old one: previously we did a complete type-driven traversal to determine the mutability of all memory we see, and then a second pass to intern any leftover raw pointers. The new interner simply recursively traverses the allocation holding the final result, and all allocations reachable from it (which can be determined from the raw bytes of the result, without knowing anything about types), and ensures they all get interned. The initial allocation is interned as immutable for `const` and pomoted and non-interior-mutable `static`; all other allocations are interned as immutable for `static`, `const`, and promoted. The main subtlety is justifying that those inner allocations may indeed be interned immutably, i.e., that mutating them later would anyway already be UB: - for promoteds, we rely on the analysis that does promotion to ensure that this is sound. - for `const` and `static`, we check that all pointers in the final result that point to things that are new (i.e., part of this const evaluation) are immutable, i.e., were created via `&<expr>` at a non-interior-mutable type. Mutation through immutable pointers is UB so we are free to intern that memory as immutable. Interning raises an error if it encounters a dangling pointer or a mutable pointer that violates the above rules. I also extended our type-driven const validity checks to ensure that `&mut T` in the final value of a const points to mutable memory, at least if `T` is not zero-sized. This catches cases of people turning `&i32` into `&mut i32` (which would still be considered a read-only pointer). Similarly, when these checks encounter an `UnsafeCell`, they are checking that it lives in mutable memory. (Both of these only traverse the newly created values; if those point to other consts/promoteds, the check stops there. But that's okay, we don't have to catch all the UB.) I co-developed this with the stricter interner changes but I can split it out into a separate PR if you prefer. This PR does have the immediate effect of allowing some new code on stable, for instance: ```rust const CONST_RAW: *const Vec<i32> = &Vec::new() as *const _; ``` Previously that code got rejected since the type-based interner didn't know what to do with that pointer. It's a raw pointer, we cannot trust its type. The new interner does not care about types so it sees no issue with this code; there's an immutable pointer pointing to some read-only memory (storing a `Vec<i32>`), all is good. Accepting this code pretty much commits us to non-type-based interning, but I think that's the better strategy anyway. This PR also leads to slightly worse error messages when the final value of a const contains a dangling reference. Previously we would complete interning and then the type-based validation would detect this dangling reference and show a nice error saying where in the value (i.e., in which field) the dangling reference is located. However, the new interner cannot distinguish dangling references from dangling raw pointers, so it must throw an error when it encounters either of them. It doesn't have an understanding of the value structure so all it can say is "somewhere in this constant there's a dangling pointer". (Later parts of the compiler don't like dangling pointers/references so we have to reject them either during interning or during validation.) This could potentially be improved by doing validation before interning, but that's a larger change that I have not attempted yet. (It's also subtle since we do want validation to use the final mutability bits of all involved allocations, and currently it is interning that marks a bunch of allocations as immutable -- that would have to still happen before validation.) `@rust-lang/wg-const-eval` I hope you are okay with this plan. :) `@rust-lang/lang` paging you in since this accepts new code on stable as explained above. Please let me know if you think FCP is necessary.
2024-01-23Auto merge of #120017 - nnethercote:lint-api, r=oli-obkbors-22/+22
Fix naming in the lint API Methods for emit lints are named very inconsistently. This PR fixes that up. r? `@compiler-errors`
2024-01-22Rollup merge of #120233 - oli-obk:revert_trait_obj_upcast_stabilization, r=lcnrMatthias Krüger-0/+1
Revert stabilization of trait_upcasting feature Reverts #118133 This reverts commit 6d2b84b3ed7848fd91b8d6151d4451b3103ed816, reversing changes made to 73bc12199ea8c7651ed98b069c0dd6b0bb5fabcf. The feature has a soundness bug: * #120222 It is unclear to me whether we'll actually want to destabilize, but I thought it was still prudent to open the PR for easy destabilization once we get there.
2024-01-22Rollup merge of #120216 - nnethercote:fix-trimmed_def_paths-assertion, ↵Matthias Krüger-2/+0
r=compiler-errors Fix a `trimmed_def_paths` assertion failure. `RegionHighlightMode::force_print_trimmed_def_path` can call `trimmed_def_paths` even when `tcx.sess.opts.trimmed_def_paths` is false. Based on the `force` in the method name, it seems this is deliberate, so I have removed the assertion. Fixes #120035. r? `@compiler-errors`
2024-01-22Rollup merge of #120143 - ↵Matthias Krüger-0/+50
compiler-errors:consolidate-instance-resolve-for-coroutines, r=oli-obk Consolidate logic around resolving built-in coroutine trait impls Deduplicates a lot of code. Requires defining a new lang item for `Coroutine::resume` for consistency, but it seems not harmful at worst, and potentially later useful at best. r? oli-obk
2024-01-23Rename `struct_lint_level` as `lint_level`.Nicholas Nethercote-9/+9
2024-01-23Rename `TyCtxt::emit_spanned_lint` as `TyCtxt::emit_node_span_lint`.Nicholas Nethercote-2/+2
2024-01-23Rename `TyCtxt::emit_lint` as `TyCtxt::emit_node_lint`.Nicholas Nethercote-2/+2
2024-01-23Rename `TyCtxt::struct_span_lint_hir` as `TyCtxt::node_span_lint`.Nicholas Nethercote-5/+5
2024-01-23Rename `TyCtxt::struct_lint_node` as `TyCtxt::node_lint`.Nicholas Nethercote-3/+3
2024-01-23Rename `LintContext::lookup` as `LintContext::opt_span_lint`.Nicholas Nethercote-1/+1
2024-01-22Do not normalize closure signature when building FnOnce shimMichael Goulet-10/+8
2024-01-22Add a simpler and more targetted code path for impl trait in assoc itemsOli Scherer-0/+9
2024-01-22Revert "Auto merge of #118133 - Urgau:stabilize_trait_upcasting, r=WaffleLapkin"Oli Scherer-0/+1
This reverts commit 6d2b84b3ed7848fd91b8d6151d4451b3103ed816, reversing changes made to 73bc12199ea8c7651ed98b069c0dd6b0bb5fabcf.
2024-01-22Auto merge of #120080 - cuviper:128-align-packed, r=nikicbors-16/+13
Pack u128 in the compiler to mitigate new alignment This is based on #116672, adding a new `#[repr(packed(8))]` wrapper on `u128` to avoid changing any of the compiler's size assertions. This is needed in two places: * `SwitchTargets`, otherwise its `SmallVec<[u128; 1]>` gets padded up to 32 bytes. * `LitKind::Int`, so that entire `enum` can stay 24 bytes. * This change definitely has far-reaching effects though, since it's public.
2024-01-22Auto merge of #120226 - matthiaskrgr:rollup-9xwx0si, r=matthiaskrgrbors-2/+5
Rollup of 9 pull requests Successful merges: - #118714 ( Explanation that fields are being used when deriving `(Partial)Ord` on enums) - #119710 (Improve `let_underscore_lock`) - #119726 (Tweak Library Integer Division Docs) - #119746 (rustdoc: hide modals when resizing the sidebar) - #119986 (Fix error counting) - #120194 (Shorten `#[must_use]` Diagnostic Message for `Option::is_none`) - #120200 (Correct the anchor of an URL in an error message) - #120203 (Replace `#!/bin/bash` with `#!/usr/bin/env bash` in rust-installer tests) - #120212 (Give nnethercote more reviews) r? `@ghost` `@rustbot` modify labels: rollup