Skip to content

consistently elide/don't elide types in diagnostics #118731

Open
@jyn514

Description

@jyn514

right now, the decision of whether to fully elide the type as _ is inconsistent - it never happens for functions, fn pointers, tuples, refs where the pointee types are equal, or adts, but it does happen for primitives and ADTs behind a raw pointer. that is probably not intended? might be worth moving the t1 == t2 comparison up above the big match for consistency.

if t1 == t2 && !self.tcx.sess.verbose() {
// The two types are the same, elide and don't highlight.
(DiagnosticStyledString::normal("_"), DiagnosticStyledString::normal("_"))

here is an example of it being inconsistent:

LL | fn say(self: &Pair<&str, isize>) {
| ^^^^^^^^^^^^^^^^^^ lifetime mismatch
|
= note: expected struct `Pair<&str, _>`

isize is elided but str is not.

i originally changed this to almost always elide the type, but @estebank is worried that will be confusing:
image
he suggested instead eliding if the type has either type params or projection types ("looks complicated", basically).

Originally posted by @jyn514 in #118730 (comment)

@rustbot label +A-diagnostics +E-medium

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsE-mediumCall for participation: Medium difficulty. Experience needed to fix: Intermediate.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions