about summary refs log tree commit diff
path: root/compiler/rustc_middle/src/ty/diagnostics.rs
AgeCommit message (Collapse)AuthorLines
2025-08-06Add support for shortening `Instance` and use itEsteban Küber-2/+11
Replace ad-hoc type path shortening logic for recursive mono instantiation errors to use `tcx.short_string()` instead.
2025-05-06Auto merge of #131160 - ↵bors-2/+2
ismailarilik:handle-potential-query-instability-lint-for-rustc-middle, r=oli-obk Handle `rustc_middle` cases of `rustc::potential_query_instability` lint This PR removes `#![allow(rustc::potential_query_instability)]` line from [`compiler/rustc_middle/src/lib.rs`](https://github.com/rust-lang/rust/blob/master/compiler/rustc_middle/src/lib.rs#L29) and converts `FxHash{Map,Set}` types into `FxIndex{Map,Set}` to suppress lint errors. A somewhat tracking issue: https://github.com/rust-lang/rust/issues/84447 r? `@compiler-errors`
2025-05-05Handle rustc_middle cases of rustc::potential_query_instability lintismailarilik-2/+2
2025-04-16Rename `LifetimeName` as `LifetimeKind`.Nicholas Nethercote-2/+2
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-14Remove unused `Map` field from `TraitObjectVisitor`.Nicholas Nethercote-1/+1
Also reduce visibility.
2025-04-14Remove unused `StaticLifetimeVisitor`.Nicholas Nethercote-12/+0
2025-03-17Auto merge of #138595 - jhpratt:rollup-09pvfzu, r=jhprattbors-24/+18
Rollup of 9 pull requests Successful merges: - #136355 (Add `*_value` methods to proc_macro lib) - #137621 (Add std support to cygwin target) - #137793 (Stablize anonymous pipe) - #138341 (std: Mention clone-on-write mutation in Arc<T>) - #138517 (Improve upvar analysis for deref of child capture) - #138584 (Update Rust Foundation links in Readme) - #138586 (Document `#![register_tool]`) - #138590 (Flatten and simplify some control flow 🫓) - #138592 (update change entry for #137147) r? `@ghost` `@rustbot` modify labels: rollup
2025-03-17Flatten and simplify some control flowYotam Ofek-24/+18
2025-03-17Use `strip_{prefix|suffix}` instead of `{starts|ends}_with`+indexingYotam Ofek-2/+2
2025-02-25Teach structured errors to display short `Ty`Esteban Küber-1/+9
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-31Make comma separated lists of anything easier to make for errorsEsteban Küber-10/+6
Provide a new function `listify`, meant to be used in cases similar to `pluralize!`. When you have a slice of arbitrary elements that need to be presented to the user, `listify` allows you to turn that into a list of comma separated strings. This reduces a lot of redundant logic that happens often in diagnostics.
2025-01-23Split hir `TyKind` and `ConstArgKind` in two and update `hir::Visitor`Boxy-4/+4
2025-01-23Make `hir::TyKind::TraitObject` use tagged ptrBoxy-7/+7
2025-01-19Manual cleanup of some `is_{or_none|some_and}` usagesYotam Ofek-1/+1
2025-01-03remove unused function paramsMatthias Krüger-2/+2
2024-12-16update uses of extract_if in the compilerThe 8472-1/+1
2024-12-07Tweak wordingEsteban Küber-5/+5
2024-12-07Do not talk about "trait `<Foo = Bar>`"Esteban Küber-2/+4
Pass in an appropriate `Option<DefId>` in more cases from hir ty lowering.
2024-12-07Account for `impl Trait` in "add bound" suggestion messageEsteban Küber-0/+6
2024-12-07Mention type parameter in more cases and don't suggest ~const bound already ↵Esteban Küber-16/+9
there
2024-12-07Use trait name instead of full constraint in suggestion messageEsteban Küber-23/+61
``` help: consider restricting type parameter `T` with traits `Copy` and `Trait` | LL | fn duplicate_custom<T: Copy + Trait>(t: S<T>) -> (S<T>, S<T>) { | ++++++++++++++ ``` ``` help: consider restricting type parameter `V` with trait `Copy` | LL | fn index<'a, K, V: std::marker::Copy>(map: &'a HashMap<K, V>, k: K) -> &'a V { | +++++++++++++++++++ ```
2024-12-07Add test for lack of suggestion in stableEsteban Küber-2/+2
This test will break when `Step` gets stabilized, but punt until then.
2024-12-07reword trait bound suggestion message to include the boundsEsteban Küber-14/+31
2024-12-07Don't suggest restricting bound with unstable traits on stableEsteban Küber-8/+24
On nightly, we mention the trait is unstable ``` error[E0277]: the trait bound `T: Unstable` is not satisfied --> $DIR/unstable-trait-suggestion.rs:13:9 | LL | foo(t) | --- ^ the trait `Unstable` is not implemented for `T` | | | required by a bound introduced by this call | note: required by a bound in `foo` --> $DIR/unstable-trait-suggestion.rs:9:11 | LL | fn foo<T: Unstable>(_: T) {} | ^^^^^^^^ required by this bound in `foo` help: consider restricting type parameter `T` but it is an `unstable` trait | LL | pub fn demo<T: Unstable>(t: T) { | ++++++++++ ``` On stable, we don't suggest the trait at all ``` error[E0277]: the trait bound `T: Unstable` is not satisfied --> $DIR/unstable-trait-suggestion.rs:13:9 | LL | foo(t) | --- ^ the trait `Unstable` is not implemented for `T` | | | required by a bound introduced by this call | note: required by a bound in `foo` --> $DIR/unstable-trait-suggestion.rs:9:11 | LL | fn foo<T: Unstable>(_: T) {} | ^^^^^^^^ required by this bound in `foo` ```
2024-11-25Refactor `where` predicates, and reserve for attributes supportFrank King-2/+2
2024-10-26Effects cleanupDeadbeef-1/+1
- removed extra bits from predicates queries that are no longer needed in the new system - removed the need for `non_erasable_generics` to take in tcx and DefId, removed unused arguments in callers
2024-10-24Remove associated type based effects logicMichael Goulet-3/+0
2024-10-22Represent TraitBoundModifiers as distinct parts in HIRMichael Goulet-1/+1
2024-10-14Move trait bound modifiers into hir::PolyTraitRefMichael Goulet-1/+2
2024-10-12remove a couple of redundant String to String conversionMatthias Krüger-1/+1
2024-10-04rm `ItemKind::OpaqueTy`Noah Lev-8/+2
This introduce an additional collection of opaques on HIR, as they can no longer be listed using the free item list.
2024-10-02Remove redundant in_trait from hir::TyKind::OpaqueDefMichael Goulet-1/+1
2024-09-22Reformat using the new identifier sorting from rustfmtMichael Goulet-1/+1
2024-08-13Use is_lang_item moreMichael Goulet-4/+4
2024-07-29Reformat `use` declarations.Nicholas Nethercote-6/+6
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-07-24Rollup merge of #127717 - gurry:127441-stray-impl-sugg, r=compiler-errorsMatthias Krüger-20/+49
Fix malformed suggestion for repeated maybe unsized bounds Fixes #127441 Now when we encounter something like `foo(a : impl ?Sized + ?Sized)`, instead of suggesting removal of both bounds and leaving `foo(a: impl )` behind, we suggest changing the first bound to `Sized` and removing the second bound, resulting in `foo(a: impl Sized)`. Although the issue was reported for impl trait types, it also occurred with regular param bounds. So if we encounter `foo<T: ?Sized + ?Sized>(a: T)` we now detect that all the bounds are `?Sized` and therefore emit the suggestion to remove the entire predicate `: ?Sized + ?Sized` resulting in `foo<T>(a: T)`. Lastly, if we encounter a situation where some of the bounds are something other than `?Sized`, then we emit separate removal suggestions for each `?Sized` bound. E.g. if we see `foo(a: impl ?Sized + Bar + ?Sized)` or `foo<T: ?Sized + Bar + ?Sized>(a: T)` we emit suggestions such that the user will be left with `foo(a : impl Bar)` or `foo<T: Bar>(a: T)` respectively.
2024-07-17Remove invalid further restricting for type boundyukang-0/+14
2024-07-14Fix malformed suggestion for repeated maybe unsized boundsGurinder Singh-20/+49
2024-06-21Rename a bunch of thingsMichael Goulet-1/+1
2024-04-23Wrap dyn type with parentheses in suggestionlong-long-float-17/+22
2024-04-09Add redundant_lifetime_args lintMichael Goulet-8/+7
2024-03-21Replace closures with `_` when suggesting fully qualified path for method callEsteban Küber-6/+22
``` error[E0283]: type annotations needed --> $DIR/into-inference-needs-type.rs:12:10 | LL | .into()?; | ^^^^ | = note: cannot satisfy `_: From<...>` = note: required for `FilterMap<...>` to implement `Into<_>` help: try using a fully qualified path to specify the expected types | LL ~ let list = <FilterMap<Map<std::slice::Iter<'_, &str>, _>, _> as Into<T>>::into(vec LL | .iter() LL | .map(|s| s.strip_prefix("t")) LL ~ .filter_map(Option::Some))?; | ``` Fix #122569.
2024-03-11Rename `IntoDiagnosticArg` as `IntoDiagArg`.Nicholas Nethercote-4/+4
Also rename `into_diagnostic_arg` as `into_diag_arg`, and `NotIntoDiagnosticArg` as `NotInotDiagArg`.
2024-03-05Convert `TypeVisitor` and `DefIdVisitor` to use `VisitorResult`Jason Newcomb-3/+3
2024-02-28Rename `DiagnosticArg{,Map,Name,Value}` as `DiagArg{,Map,Name,Value}`.Nicholas Nethercote-2/+2
2024-02-28Rename `DiagnosticBuilder` as `Diag`.Nicholas Nethercote-4/+4
Much better! Note that this involves renaming (and updating the value of) `DIAGNOSTIC_BUILDER` in clippy.
2024-02-19Prefer `DiagnosticBuilder` over `Diagnostic` in diagnostic modifiers.Nicholas Nethercote-4/+4
There are lots of functions that modify a diagnostic. This can be via a `&mut Diagnostic` or a `&mut DiagnosticBuilder`, because the latter type wraps the former and impls `DerefMut`. This commit converts all the `&mut Diagnostic` occurrences to `&mut DiagnosticBuilder`. This is a step towards greatly simplifying `Diagnostic`. Some of the relevant function are made generic, because they deal with both errors and warnings. No function bodies are changed, because all the modifier methods are available on both `Diagnostic` and `DiagnosticBuilder`.
2024-02-10Take empty `where` into account when suggesting predicatesGurinder Singh-1/+7
2024-02-04make effect infer variables suggestable in diagnosticsDeadbeef-0/+4
it works when a non-const context that does not enable effects calls into a const effects-enabled trait. We'd simply suggest the non-const trait bound in this case consistent to its fallback.
2024-01-30Remove the lifetime from `DiagnosticArgValue`.Nicholas Nethercote-1/+1
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.