about summary refs log tree commit diff
path: root/compiler/rustc_middle/src/ty/error.rs
AgeCommit message (Collapse)AuthorLines
2025-09-08fixup limit handling codeJana Dönszelmann-1/+2
2025-08-06Add support for shortening `Instance` and use itEsteban Küber-11/+27
Replace ad-hoc type path shortening logic for recursive mono instantiation errors to use `tcx.short_string()` instead.
2025-08-03Rename `Printer` variables.Nicholas Nethercote-12/+12
Currently they are mostly named `cx`, which is a terrible name for a type that impls `Printer`/`PrettyPrinter`, and is easy to confuse with other types like `TyCtxt`. This commit changes them to `p`. A couple of existing `p` variables had to be renamed to make way.
2025-04-24Remove `weak` alias terminologyBoxy-1/+1
2025-04-07Simplify temp path creation a bitMichael Goulet-1/+1
2025-02-25Teach structured errors to display short `Ty`Esteban Küber-6/+4
Make it so that every structured error annotated with `#[derive(Diagnostic)]` that has a field of type `Ty<'_>`, the printing of that value into a `String` will look at the thread-local storage `TyCtxt` in order to shorten to a length appropriate with the terminal width. When this happen, the resulting error will have a note with the file where the full type name was written to. ``` error[E0618]: expected function, found `((..., ..., ..., ...), ..., ..., ...)`` --> long.rs:7:5 | 6 | fn foo(x: D) { //~ `x` has type `(... | - `x` has type `((..., ..., ..., ...), ..., ..., ...)` 7 | x(); //~ ERROR expected function, found `(... | ^-- | | | call expression requires function | = note: the full name for the type has been written to 'long.long-type-14182675702747116984.txt' = note: consider using `--verbose` to print the full type name to the console ```
2025-01-31Rework "long type names" printing logicEsteban Küber-11/+26
Make it so more type-system types can be printed in a shortened version (like `Predicate`s). Centralize printing the information about the "full type name path". Make the "long type path" for the file where long types are written part of `Diag`, so that it becomes easier to keep track of it, and ensure it will always will be printed out last in the diagnostic by making its addition to the output implicit. Tweak the shortening of types in "expected/found" labels. Remove dead file `note.rs`.
2025-01-10mir_transform: implement forced inliningDavid Wood-0/+3
Adds `#[rustc_force_inline]` which is similar to always inlining but reports an error if the inlining was not possible, and which always attempts to inline annotated items, regardless of optimisation levels. It can only be applied to free functions to guarantee that the MIR inliner will be able to resolve calls.
2024-12-22Begin to implement type system layer of unsafe bindersMichael Goulet-0/+1
2024-11-24Simplify array length mismatch error reportingMichael Goulet-6/+3
2024-11-02Fix type shortening writing to fileEsteban Küber-3/+18
Make sure that we append to the file for long ty paths. Do not write the same type more than once. Shorten the calculated width a bit.
2024-10-23remove `PredicatePolarity` and `BoundConstness` relate implslcnr-3/+0
Also removes `TypeError::ConstnessMismatch`. It is unused.
2024-09-22Reformat using the new identifier sorting from rustfmtMichael Goulet-1/+1
2024-08-09Shrink `TyKind::FnPtr`.Nicholas Nethercote-2/+2
By splitting the `FnSig` within `TyKind::FnPtr` into `FnSigTys` and `FnHeader`, which can be packed more efficiently. This reduces the size of the hot `TyKind` type from 32 bytes to 24 bytes on 64-bit platforms. This reduces peak memory usage by a few percent on some benchmarks. It also reduces cache misses and page faults similarly, though this doesn't translate to clear cycles or wall-time improvements on CI.
2024-07-29Reformat `use` declarations.Nicholas Nethercote-5/+5
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-06-06Uplift TypeErrorMichael Goulet-124/+39
2024-06-01Simplify IntVarValue/FloatVarValueMichael Goulet-21/+1
2024-05-17Rename Unsafe to SafetySantiago Pastorino-3/+3
2024-04-29Remove `extern crate rustc_macros` from `rustc_middle`.Nicholas Nethercote-0/+1
2024-04-08Actually create ranged int types in the type system.Oli Scherer-0/+1
2024-03-22Auto merge of #122900 - matthiaskrgr:rollup-nls90mb, r=matthiaskrgrbors-1/+1
Rollup of 8 pull requests Successful merges: - #114009 (compiler: allow transmute of ZST arrays with generics) - #122195 (Note that the caller chooses a type for type param) - #122651 (Suggest `_` for missing generic arguments in turbofish) - #122784 (Add `tag_for_variant` query) - #122839 (Split out `PredicatePolarity` from `ImplPolarity`) - #122873 (Merge my contributor emails into one using mailmap) - #122885 (Adjust better spastorino membership to triagebot's adhoc_groups) - #122888 (add a couple more tests) r? `@ghost` `@rustbot` modify labels: rollup
2024-03-22Further simplificationsMichael Goulet-1/+1
2024-03-22Programmatically convert some of the pat ctorsMichael Goulet-1/+1
2024-02-20Make --verbose imply -Z write-long-types-to-disk=noFernando Fernandez Mancera-1/+1
When shortening the type it is necessary to take into account the `--verbose` flag, if it is activated, we must always show the entire type and not write it in a file. Fixes: https://github.com/rust-lang/rust/issues/119130
2024-02-06Add CoroutineClosure to TyKind, AggregateKind, UpvarArgsMichael Goulet-1/+1
2023-12-13Tweak `short_ty_string` to reduce number of filesEsteban Küber-9/+11
When shortening types and writing them to disk, make `short_ty_string` capable of reusing the same file, instead of writing a file per shortened type.
2023-11-21Fix `clippy::needless_borrow` in the compilerNilstrieb-2/+2
`x clippy compiler -Aclippy::all -Wclippy::needless_borrow --fix`. Then I had to remove a few unnecessary parens and muts that were exposed now.
2023-11-02Add insta-stable std::hash::{DefaultHasher, RandomState} exportsltdk-2/+1
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-21Make `ty::print::Printer` take `&mut self` instead of `self`Nilstrieb-15/+14
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-20s/generator/coroutine/Oli Scherer-4/+4
2023-10-20s/Generator/Coroutine/Oli Scherer-4/+4
2023-10-13Format all the let chains in compilerMichael Goulet-1/+7
2023-09-23Remove GeneratorWitness and rename GeneratorWitnessMIR.Camille GILLOT-3/+2
2023-09-18Remove unused `Lift` derives.Nicholas Nethercote-2/+2
I found these by commenting out all `Lift` derives and then adding back the ones that were necessary to successfully compile.
2023-07-30inline format!() args up to and including rustc_middleMatthias Krüger-4/+4
2023-07-24new unstable option: -Zwrite-long-types-to-diskMahdi Dibaiee-2/+7
This option guards the logic of writing long type names in files and instead using short forms in error messages in rustc_middle/ty/error behind a flag. The main motivation for this change is to disable this behaviour when running ui tests. This logic can be triggered by running tests in a directory that has a long enough path, e.g. /my/very-long-path/where/rust-codebase/exists/ This means ui tests can fail depending on how long the path to their file is. Some ui tests actually rely on this behaviour for their assertions, so for those we enable the flag manually.
2023-06-16Add `AliasKind::Weak` for type aliases.Oli Scherer-0/+1
Only use it when the type alias contains an opaque type. Also does wf-checking on such type aliases.
2023-05-30leak_check: remove unused codepathlcnr-13/+0
2023-05-04IAT: Introduce AliasKind::InherentLeón Orell Valerian Liehr-2/+2
2023-04-26Remove unused `TypeFoldable`/`TypeVisitable` impls.Nicholas Nethercote-1/+1
2023-03-11remove duplicated calls to sort_stringklensy-6/+2
2023-02-13fix: improve the suggestion on future not awaitedVincenzo Palazzo-1/+1
Considering the following code ```rust fn foo() -> u8 { async fn async_fn() -> u8 { 22 } async_fn() } fn main() {} ``` the error generated before this commit from the compiler is ``` ➜ rust git:(macros/async_fn_suggestion) ✗ rustc test.rs --edition 2021 error[E0308]: mismatched types --> test.rs:4:5 | 1 | fn foo() -> u8 { | -- expected `u8` because of return type ... 4 | async_fn() | ^^^^^^^^^^ expected `u8`, found opaque type | = note: expected type `u8` found opaque type `impl Future<Output = u8>` help: consider `await`ing on the `Future` | 4 | async_fn().await | ++++++ error: aborting due to previous error ``` In this case the error is nor perfect, and can confuse the user that do not know that the opaque type is the future. So this commit will propose (and conclude the work start in https://github.com/rust-lang/rust/issues/80658) to change the string `opaque type` to `future` when applicable and also remove the Expected vs Received note by adding a more specific one regarding the async function that return a future type. So the new error emitted by the compiler is ``` error[E0308]: mismatched types --> test.rs:4:5 | 1 | fn foo() -> u8 { | -- expected `u8` because of return type ... 4 | async_fn() | ^^^^^^^^^^ expected `u8`, found future | note: calling an async function returns a future --> test.rs:4:5 | 4 | async_fn() | ^^^^^^^^^^ help: consider `await`ing on the `Future` | 4 | async_fn().await | ++++++ error: aborting due to previous error ``` Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
2023-01-30Fix unquoted projection types in labelEsteban Küber-1/+1
2023-01-30Mention fn coercion rules (needs to be expanded)Esteban Küber-1/+1
2023-01-30review commentsEsteban Küber-36/+43
2023-01-30Modify primary span label for E0308Esteban Küber-124/+67
The previous output was unintuitive to users.
2023-01-27Introduce GeneratorWitnessMIR.Camille GILLOT-2/+3
2023-01-25Move `note_and_explain_type_err` from `rustc_middle` to `rustc_infer`Nilstrieb-632/+5
This way we can properly deal with the types.
2023-01-11Be more specific about constructor `FnDef`s in type mismatchMichael Goulet-3/+11