Skip to content

Add support for span context to derive(Diagnostic) and use it - #163414

Merged
rust-bors[bot] merged 5 commits into
rust-lang:mainfrom
estebank:derive-diagnostic-context
Sep 30, 2026
Merged

rust-bors[bot] merged 5 commits into
rust-lang:mainfrom
estebank:derive-diagnostic-context

Conversation

@estebank

@estebank estebank commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Allow writing

struct Diagnostic {
    #[primary_span]
    #[label("label text")]
    span: Span,
    #[context]
    context: Span,
}

So that the code pointed at by context is shown in the rendered diagnostic without an underline.

Point at enclosing item(s) on unexpected item type:

error: expected type, found constant
  --> $DIR/consts.rs:2:19
   |
LL | pub fn accept(
LL |     _: impl Trait<K: Copy>
   |                   ^------ bounds are not allowed on associated constants
   |                   |
   |                   unexpected constant
   |
note: the associated constant is defined here
  --> $DIR/consts.rs:7:5
   |
LL |     const K: i32;
   |     ^^^^^^^^^^

Show trait/impl for duplicate impl associated items

error[E0201]: duplicate definitions with name `Bar`:
  --> $DIR/associated-item-duplicate-names-3.rs:14:5
   |
LL | trait Foo {
LL |     type Bar;
   |     --------- item in trait
...
LL | impl Foo for Baz {
LL |     type Bar = i16;
   |     --------------- previous definition here
LL |     type Bar = u16;
   |     ^^^^^^^^^^^^^^^ duplicate definition

Point at trait/impl on associated item mismatch

error[E0324]: item `RESOLVED_WRONG` is an associated method, which doesn't match its trait `MyTrait`
  --> $DIR/unresolved-trait-impl-item.rs:12:5
   |
LL | trait MyTrait {
LL |     async fn resolved(&self);
LL |     const RESOLVED_WRONG: u8 = 0;
   |     ----------------------------- item in trait
...
LL | impl MyTrait for i32 {
...
LL |     async fn RESOLVED_WRONG() {}
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ does not match trait

On impl item signature mismatch, point at impl and trait

error: `impl` item signature doesn't match `trait` item signature
  --> $DIR/self-without-lifetime-constraint.rs:46:5
   |
LL | pub trait FromSql: Sized {
LL |     fn column_result(value: ValueRef<'_>) -> FromSqlResult<Self, &Self>;
   |     -------------------------------------------------------------------- expected `fn(ValueRef<'1>) -> Result<(&'2 str, &'1 &'2 str), _>`
...
LL | impl FromSql for &str {
LL |     fn column_result(value: ValueRef<'_>) -> FromSqlResult<&str, &&str> {
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ found `fn(ValueRef<'1>) -> Result<(&'1 str, &'1 &'1 str), _>`
   |
   = note: expected signature `fn(ValueRef<'1>) -> Result<(&'2 str, &'1 &'2 str), FromSqlError>`
              found signature `fn(ValueRef<'1>) -> Result<(&'1 str, &'1 &'1 str), FromSqlError>`
help: the lifetime requirements from the `impl` do not correspond to the requirements in the `trait`
  --> $DIR/self-without-lifetime-constraint.rs:42:60
   |
LL |     fn column_result(value: ValueRef<'_>) -> FromSqlResult<Self, &Self>;
   |                                                            ^^^^ consider borrowing this type parameter in the trait

@rustbot

rustbot commented Sep 27, 2026

Copy link
Copy Markdown
Collaborator

rustc_macros::diagnostics was changed

cc @TaKO8Ki, @JonathanBrouwer

@rustbot rustbot added A-translation Area: Translation infrastructure, and migrating existing diagnostics to SessionDiagnostic S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 27, 2026
@rustbot

rustbot commented Sep 27, 2026

Copy link
Copy Markdown
Collaborator

r? @petrochenkov

rustbot has assigned @petrochenkov.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 77 candidates
  • Random selection from 19 candidates

@rust-log-analyzer

This comment has been minimized.

@rustbot

rustbot commented Sep 27, 2026

Copy link
Copy Markdown
Collaborator

HIR ty lowering was modified

cc @fmease

@estebank estebank changed the title Add support for span context to derive(Diagnostic) Add support for span context to derive(Diagnostic) and use it Sep 27, 2026
@petrochenkov

Copy link
Copy Markdown
Contributor

It would be easier to understand what's going on here with a link to the previous work like #162874.

Comment thread tests/ui/associated-type-bounds/consts.rs Outdated
Comment thread tests/ui/associated-item/associated-item-duplicate-names.stderr
Comment thread compiler/rustc_resolve/src/late.rs
Comment thread compiler/rustc_hir_analysis/src/hir_ty_lowering/errors.rs Outdated
@petrochenkov petrochenkov added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 28, 2026
@estebank estebank added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Sep 28, 2026
@petrochenkov

Copy link
Copy Markdown
Contributor

r=me after squashing the review changes into the main changes.
@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 29, 2026
@rustbot

rustbot commented Sep 29, 2026

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

Allow writing

```rust
struct Diagnostic {
    #[primary_span]
    #[label("label text")]
    span: Span,
    #[context]
    context: Span,
}
```

So that the code pointed at by `context` is shown in the rendered diagnostic without an underline.
```
error[E0201]: duplicate definitions with name `Bar`:
  --> $DIR/associated-item-duplicate-names-3.rs:14:5
   |
LL | trait Foo {
LL |     type Bar;
   |     --------- item in trait
...
LL | impl Foo for Baz {
LL |     type Bar = i16;
   |     --------------- previous definition here
LL |     type Bar = u16;
   |     ^^^^^^^^^^^^^^^ duplicate definition
```
```
error[E0324]: item `RESOLVED_WRONG` is an associated method, which doesn't match its trait `MyTrait`
  --> $DIR/unresolved-trait-impl-item.rs:12:5
   |
LL | trait MyTrait {
LL |     async fn resolved(&self);
LL |     const RESOLVED_WRONG: u8 = 0;
   |     ----------------------------- item in trait
...
LL | impl MyTrait for i32 {
...
LL |     async fn RESOLVED_WRONG() {}
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ does not match trait
```
```
error: `impl` item signature doesn't match `trait` item signature
  --> $DIR/self-without-lifetime-constraint.rs:46:5
   |
LL | pub trait FromSql: Sized {
LL |     fn column_result(value: ValueRef<'_>) -> FromSqlResult<Self, &Self>;
   |     -------------------------------------------------------------------- expected `fn(ValueRef<'1>) -> Result<(&'2 str, &'1 &'2 str), _>`
...
LL | impl FromSql for &str {
LL |     fn column_result(value: ValueRef<'_>) -> FromSqlResult<&str, &&str> {
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ found `fn(ValueRef<'1>) -> Result<(&'1 str, &'1 &'1 str), _>`
   |
   = note: expected signature `fn(ValueRef<'1>) -> Result<(&'2 str, &'1 &'2 str), FromSqlError>`
              found signature `fn(ValueRef<'1>) -> Result<(&'1 str, &'1 &'1 str), FromSqlError>`
help: the lifetime requirements from the `impl` do not correspond to the requirements in the `trait`
  --> $DIR/self-without-lifetime-constraint.rs:42:60
   |
LL |     fn column_result(value: ValueRef<'_>) -> FromSqlResult<Self, &Self>;
   |                                                            ^^^^ consider borrowing this type parameter in the trait
```
@estebank
estebank force-pushed the derive-diagnostic-context branch from 577968c to 246eb14 Compare September 29, 2026 16:37
@estebank

Copy link
Copy Markdown
Contributor Author

@bors r=petrochenkov

@rust-bors

rust-bors Bot commented Sep 29, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 246eb14 has been approved by petrochenkov

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Sep 29, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Sep 29, 2026
…, r=petrochenkov

Add support for span context to `derive(Diagnostic)` and use it

Allow writing

```rust
struct Diagnostic {
    #[primary_span]
    #[label("label text")]
    span: Span,
    #[context]
    context: Span,
}
```

So that the code pointed at by `context` is shown in the rendered diagnostic without an underline.

Point at enclosing item(s) on unexpected item type:

```
error: expected type, found constant
  --> $DIR/consts.rs:2:19
   |
LL | pub fn accept(
LL |     _: impl Trait<K: Copy>
   |                   ^------ bounds are not allowed on associated constants
   |                   |
   |                   unexpected constant
   |
note: the associated constant is defined here
  --> $DIR/consts.rs:7:5
   |
LL |     const K: i32;
   |     ^^^^^^^^^^
```

Show trait/impl for duplicate impl associated items
```
error[E0201]: duplicate definitions with name `Bar`:
  --> $DIR/associated-item-duplicate-names-3.rs:14:5
   |
LL | trait Foo {
LL |     type Bar;
   |     --------- item in trait
...
LL | impl Foo for Baz {
LL |     type Bar = i16;
   |     --------------- previous definition here
LL |     type Bar = u16;
   |     ^^^^^^^^^^^^^^^ duplicate definition
```

Point at trait/impl on associated item mismatch
```
error[E0324]: item `RESOLVED_WRONG` is an associated method, which doesn't match its trait `MyTrait`
  --> $DIR/unresolved-trait-impl-item.rs:12:5
   |
LL | trait MyTrait {
LL |     async fn resolved(&self);
LL |     const RESOLVED_WRONG: u8 = 0;
   |     ----------------------------- item in trait
...
LL | impl MyTrait for i32 {
...
LL |     async fn RESOLVED_WRONG() {}
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ does not match trait
```
On `impl` item signature mismatch, point at impl and trait
```
error: `impl` item signature doesn't match `trait` item signature
  --> $DIR/self-without-lifetime-constraint.rs:46:5
   |
LL | pub trait FromSql: Sized {
LL |     fn column_result(value: ValueRef<'_>) -> FromSqlResult<Self, &Self>;
   |     -------------------------------------------------------------------- expected `fn(ValueRef<'1>) -> Result<(&'2 str, &'1 &'2 str), _>`
...
LL | impl FromSql for &str {
LL |     fn column_result(value: ValueRef<'_>) -> FromSqlResult<&str, &&str> {
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ found `fn(ValueRef<'1>) -> Result<(&'1 str, &'1 &'1 str), _>`
   |
   = note: expected signature `fn(ValueRef<'1>) -> Result<(&'2 str, &'1 &'2 str), FromSqlError>`
              found signature `fn(ValueRef<'1>) -> Result<(&'1 str, &'1 &'1 str), FromSqlError>`
help: the lifetime requirements from the `impl` do not correspond to the requirements in the `trait`
  --> $DIR/self-without-lifetime-constraint.rs:42:60
   |
LL |     fn column_result(value: ValueRef<'_>) -> FromSqlResult<Self, &Self>;
   |                                                            ^^^^ consider borrowing this type parameter in the trait
```
rust-bors Bot pushed a commit that referenced this pull request Sep 29, 2026
…uwer

Rollup of 5 pull requests

Successful merges:

 - #158102 (When compiling without a specified `--edition`, emit a message)
 - #158936 (Add `std::fs::{Home|Media}Dirs`)
 - #163414 (Add support for span context to `derive(Diagnostic)` and use it)
 - #163405 (Remove some #[linkage] options)
 - #163498 (Revert "Rollup merge of #120589 - devnexen:cpuaff_fbsd_upd, r=clarfonthey")
tgross35 added a commit to tgross35/rust that referenced this pull request Sep 29, 2026
…, r=petrochenkov

Add support for span context to `derive(Diagnostic)` and use it

Allow writing

```rust
struct Diagnostic {
    #[primary_span]
    #[label("label text")]
    span: Span,
    #[context]
    context: Span,
}
```

So that the code pointed at by `context` is shown in the rendered diagnostic without an underline.

Point at enclosing item(s) on unexpected item type:

```
error: expected type, found constant
  --> $DIR/consts.rs:2:19
   |
LL | pub fn accept(
LL |     _: impl Trait<K: Copy>
   |                   ^------ bounds are not allowed on associated constants
   |                   |
   |                   unexpected constant
   |
note: the associated constant is defined here
  --> $DIR/consts.rs:7:5
   |
LL |     const K: i32;
   |     ^^^^^^^^^^
```

Show trait/impl for duplicate impl associated items
```
error[E0201]: duplicate definitions with name `Bar`:
  --> $DIR/associated-item-duplicate-names-3.rs:14:5
   |
LL | trait Foo {
LL |     type Bar;
   |     --------- item in trait
...
LL | impl Foo for Baz {
LL |     type Bar = i16;
   |     --------------- previous definition here
LL |     type Bar = u16;
   |     ^^^^^^^^^^^^^^^ duplicate definition
```

Point at trait/impl on associated item mismatch
```
error[E0324]: item `RESOLVED_WRONG` is an associated method, which doesn't match its trait `MyTrait`
  --> $DIR/unresolved-trait-impl-item.rs:12:5
   |
LL | trait MyTrait {
LL |     async fn resolved(&self);
LL |     const RESOLVED_WRONG: u8 = 0;
   |     ----------------------------- item in trait
...
LL | impl MyTrait for i32 {
...
LL |     async fn RESOLVED_WRONG() {}
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ does not match trait
```
On `impl` item signature mismatch, point at impl and trait
```
error: `impl` item signature doesn't match `trait` item signature
  --> $DIR/self-without-lifetime-constraint.rs:46:5
   |
LL | pub trait FromSql: Sized {
LL |     fn column_result(value: ValueRef<'_>) -> FromSqlResult<Self, &Self>;
   |     -------------------------------------------------------------------- expected `fn(ValueRef<'1>) -> Result<(&'2 str, &'1 &'2 str), _>`
...
LL | impl FromSql for &str {
LL |     fn column_result(value: ValueRef<'_>) -> FromSqlResult<&str, &&str> {
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ found `fn(ValueRef<'1>) -> Result<(&'1 str, &'1 &'1 str), _>`
   |
   = note: expected signature `fn(ValueRef<'1>) -> Result<(&'2 str, &'1 &'2 str), FromSqlError>`
              found signature `fn(ValueRef<'1>) -> Result<(&'1 str, &'1 &'1 str), FromSqlError>`
help: the lifetime requirements from the `impl` do not correspond to the requirements in the `trait`
  --> $DIR/self-without-lifetime-constraint.rs:42:60
   |
LL |     fn column_result(value: ValueRef<'_>) -> FromSqlResult<Self, &Self>;
   |                                                            ^^^^ consider borrowing this type parameter in the trait
```
rust-bors Bot pushed a commit that referenced this pull request Sep 29, 2026
Rollup of 8 pull requests

Successful merges:

 - #158102 (When compiling without a specified `--edition`, emit a message)
 - #158936 (Add `std::fs::{Home|Media}Dirs`)
 - #163414 (Add support for span context to `derive(Diagnostic)` and use it)
 - #163481 (triagebot: use r-l/r zulip linkifier for r-l/r rustfmt backport nominations)
 - #163502 (arch::breakpoint: update docs)
 - #163505 (Sync cg_gcc subtree 2026-09-29)
 - #163405 (Remove some #[linkage] options)
 - #163498 (Revert "Rollup merge of #120589 - devnexen:cpuaff_fbsd_upd, r=clarfonthey")
rust-bors Bot pushed a commit that referenced this pull request Sep 29, 2026
Rollup of 8 pull requests

Successful merges:

 - #158102 (When compiling without a specified `--edition`, emit a message)
 - #158936 (Add `std::fs::{Home|Media}Dirs`)
 - #163414 (Add support for span context to `derive(Diagnostic)` and use it)
 - #163481 (triagebot: use r-l/r zulip linkifier for r-l/r rustfmt backport nominations)
 - #163502 (arch::breakpoint: update docs)
 - #163505 (Sync cg_gcc subtree 2026-09-29)
 - #163405 (Remove some #[linkage] options)
 - #163498 (Revert "Rollup merge of #120589 - devnexen:cpuaff_fbsd_upd, r=clarfonthey")
tgross35 added a commit to tgross35/rust that referenced this pull request Sep 30, 2026
…, r=petrochenkov

Add support for span context to `derive(Diagnostic)` and use it

Allow writing

```rust
struct Diagnostic {
    #[primary_span]
    #[label("label text")]
    span: Span,
    #[context]
    context: Span,
}
```

So that the code pointed at by `context` is shown in the rendered diagnostic without an underline.

Point at enclosing item(s) on unexpected item type:

```
error: expected type, found constant
  --> $DIR/consts.rs:2:19
   |
LL | pub fn accept(
LL |     _: impl Trait<K: Copy>
   |                   ^------ bounds are not allowed on associated constants
   |                   |
   |                   unexpected constant
   |
note: the associated constant is defined here
  --> $DIR/consts.rs:7:5
   |
LL |     const K: i32;
   |     ^^^^^^^^^^
```

Show trait/impl for duplicate impl associated items
```
error[E0201]: duplicate definitions with name `Bar`:
  --> $DIR/associated-item-duplicate-names-3.rs:14:5
   |
LL | trait Foo {
LL |     type Bar;
   |     --------- item in trait
...
LL | impl Foo for Baz {
LL |     type Bar = i16;
   |     --------------- previous definition here
LL |     type Bar = u16;
   |     ^^^^^^^^^^^^^^^ duplicate definition
```

Point at trait/impl on associated item mismatch
```
error[E0324]: item `RESOLVED_WRONG` is an associated method, which doesn't match its trait `MyTrait`
  --> $DIR/unresolved-trait-impl-item.rs:12:5
   |
LL | trait MyTrait {
LL |     async fn resolved(&self);
LL |     const RESOLVED_WRONG: u8 = 0;
   |     ----------------------------- item in trait
...
LL | impl MyTrait for i32 {
...
LL |     async fn RESOLVED_WRONG() {}
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ does not match trait
```
On `impl` item signature mismatch, point at impl and trait
```
error: `impl` item signature doesn't match `trait` item signature
  --> $DIR/self-without-lifetime-constraint.rs:46:5
   |
LL | pub trait FromSql: Sized {
LL |     fn column_result(value: ValueRef<'_>) -> FromSqlResult<Self, &Self>;
   |     -------------------------------------------------------------------- expected `fn(ValueRef<'1>) -> Result<(&'2 str, &'1 &'2 str), _>`
...
LL | impl FromSql for &str {
LL |     fn column_result(value: ValueRef<'_>) -> FromSqlResult<&str, &&str> {
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ found `fn(ValueRef<'1>) -> Result<(&'1 str, &'1 &'1 str), _>`
   |
   = note: expected signature `fn(ValueRef<'1>) -> Result<(&'2 str, &'1 &'2 str), FromSqlError>`
              found signature `fn(ValueRef<'1>) -> Result<(&'1 str, &'1 &'1 str), FromSqlError>`
help: the lifetime requirements from the `impl` do not correspond to the requirements in the `trait`
  --> $DIR/self-without-lifetime-constraint.rs:42:60
   |
LL |     fn column_result(value: ValueRef<'_>) -> FromSqlResult<Self, &Self>;
   |                                                            ^^^^ consider borrowing this type parameter in the trait
```
rust-bors Bot pushed a commit that referenced this pull request Sep 30, 2026
Rollup of 7 pull requests

Successful merges:

 - #158936 (Add `std::fs::{Home|Media}Dirs`)
 - #163414 (Add support for span context to `derive(Diagnostic)` and use it)
 - #163481 (triagebot: use r-l/r zulip linkifier for r-l/r rustfmt backport nominations)
 - #163502 (arch::breakpoint: update docs)
 - #163505 (Sync cg_gcc subtree 2026-09-29)
 - #163405 (Remove some #[linkage] options)
 - #163498 (Revert "Rollup merge of #120589 - devnexen:cpuaff_fbsd_upd, r=clarfonthey")
rust-bors Bot pushed a commit that referenced this pull request Sep 30, 2026
Rollup of 6 pull requests

Successful merges:

 - #158936 (Add `std::fs::{Home|Media}Dirs`)
 - #163414 (Add support for span context to `derive(Diagnostic)` and use it)
 - #163481 (triagebot: use r-l/r zulip linkifier for r-l/r rustfmt backport nominations)
 - #163502 (arch::breakpoint: update docs)
 - #163505 (Sync cg_gcc subtree 2026-09-29)
 - #163498 (Revert "Rollup merge of #120589 - devnexen:cpuaff_fbsd_upd, r=clarfonthey")
@rust-bors
rust-bors Bot merged commit c7a9fa3 into rust-lang:main Sep 30, 2026
13 checks passed
@rustbot rustbot added this to the 1.101.0 milestone Sep 30, 2026
rust-bors Bot pushed a commit that referenced this pull request Sep 30, 2026
Rollup merge of #163414 - estebank:derive-diagnostic-context, r=petrochenkov

Add support for span context to `derive(Diagnostic)` and use it

Allow writing

```rust
struct Diagnostic {
    #[primary_span]
    #[label("label text")]
    span: Span,
    #[context]
    context: Span,
}
```

So that the code pointed at by `context` is shown in the rendered diagnostic without an underline.

Point at enclosing item(s) on unexpected item type:

```
error: expected type, found constant
  --> $DIR/consts.rs:2:19
   |
LL | pub fn accept(
LL |     _: impl Trait<K: Copy>
   |                   ^------ bounds are not allowed on associated constants
   |                   |
   |                   unexpected constant
   |
note: the associated constant is defined here
  --> $DIR/consts.rs:7:5
   |
LL |     const K: i32;
   |     ^^^^^^^^^^
```

Show trait/impl for duplicate impl associated items
```
error[E0201]: duplicate definitions with name `Bar`:
  --> $DIR/associated-item-duplicate-names-3.rs:14:5
   |
LL | trait Foo {
LL |     type Bar;
   |     --------- item in trait
...
LL | impl Foo for Baz {
LL |     type Bar = i16;
   |     --------------- previous definition here
LL |     type Bar = u16;
   |     ^^^^^^^^^^^^^^^ duplicate definition
```

Point at trait/impl on associated item mismatch
```
error[E0324]: item `RESOLVED_WRONG` is an associated method, which doesn't match its trait `MyTrait`
  --> $DIR/unresolved-trait-impl-item.rs:12:5
   |
LL | trait MyTrait {
LL |     async fn resolved(&self);
LL |     const RESOLVED_WRONG: u8 = 0;
   |     ----------------------------- item in trait
...
LL | impl MyTrait for i32 {
...
LL |     async fn RESOLVED_WRONG() {}
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ does not match trait
```
On `impl` item signature mismatch, point at impl and trait
```
error: `impl` item signature doesn't match `trait` item signature
  --> $DIR/self-without-lifetime-constraint.rs:46:5
   |
LL | pub trait FromSql: Sized {
LL |     fn column_result(value: ValueRef<'_>) -> FromSqlResult<Self, &Self>;
   |     -------------------------------------------------------------------- expected `fn(ValueRef<'1>) -> Result<(&'2 str, &'1 &'2 str), _>`
...
LL | impl FromSql for &str {
LL |     fn column_result(value: ValueRef<'_>) -> FromSqlResult<&str, &&str> {
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ found `fn(ValueRef<'1>) -> Result<(&'1 str, &'1 &'1 str), _>`
   |
   = note: expected signature `fn(ValueRef<'1>) -> Result<(&'2 str, &'1 &'2 str), FromSqlError>`
              found signature `fn(ValueRef<'1>) -> Result<(&'1 str, &'1 &'1 str), FromSqlError>`
help: the lifetime requirements from the `impl` do not correspond to the requirements in the `trait`
  --> $DIR/self-without-lifetime-constraint.rs:42:60
   |
LL |     fn column_result(value: ValueRef<'_>) -> FromSqlResult<Self, &Self>;
   |                                                            ^^^^ consider borrowing this type parameter in the trait
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-translation Area: Translation infrastructure, and migrating existing diagnostics to SessionDiagnostic S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants