Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spans for elided lifetimes for references are suboptimal. #229

Closed
steffahn opened this issue Jan 19, 2023 · 2 comments · Fixed by #230
Closed

Spans for elided lifetimes for references are suboptimal. #229

steffahn opened this issue Jan 19, 2023 · 2 comments · Fixed by #230

Comments

@steffahn
Copy link

Given how hints like ----- lifetime `'life0` defined here below point to the async keyword, whereas the usage of '_ makes the span of the lifetime argument point to the '_ syntax itself, I believe it could be an improvement in UX if the span of lifetime arguments generated for & and &mut implicit (i.e. without “'_”) elided lifetimes could point to the & or the &mut instead.

#[async_trait::async_trait]
trait Foo {
    async fn bar(&self, x: &str, y: &'_ str) -> &'static str;
}
struct S(String);
#[async_trait::async_trait]
impl Foo for S {
    async fn bar(&self, x: &str, y: &'_ str) -> &'static str {
        if false {
            &self.0
        } else if false {
            x
        } else {
            y
        }
    }
}
   Compiling playground v0.0.1 (/playground)
error: lifetime may not live long enough
 --> src/lib.rs:8:49
  |
8 |     async fn bar(&self, x: &str, y: &'_ str) -> &'static str {
  |     ----- lifetime `'life0` defined here        ^^^^^^^^^^^^ type annotation requires that `'life0` must outlive `'static`

error: lifetime may not live long enough
 --> src/lib.rs:8:49
  |
8 |     async fn bar(&self, x: &str, y: &'_ str) -> &'static str {
  |     ----- lifetime `'life1` defined here        ^^^^^^^^^^^^ type annotation requires that `'life1` must outlive `'static`

error: lifetime may not live long enough
 --> src/lib.rs:8:49
  |
8 |     async fn bar(&self, x: &str, y: &'_ str) -> &'static str {
  |                                      --         ^^^^^^^^^^^^ type annotation requires that `'life2` must outlive `'static`
  |                                      |
  |                                      lifetime `'life2` defined here

help: the following changes may resolve your lifetime errors
  |
  = help: replace `'life0` with `'static`
  = help: replace `'life1` with `'static`
  = help: replace `'life2` with `'static`

error: could not compile `playground` due to 3 previous errors

the improvement should make it look more like:

   Compiling playground v0.0.1 (/playground)
error: lifetime may not live long enough
 --> src/lib.rs:8:49
  |
8 |     async fn bar(&self, x: &str, y: &'_ str) -> &'static str {
  |                  -                              ^^^^^^^^^^^^ type annotation requires that `'life2` must outlive `'static`
  |                  |
  |                  lifetime `'life0` defined here

error: lifetime may not live long enough
 --> src/lib.rs:8:49
  |
8 |     async fn bar(&self, x: &str, y: &'_ str) -> &'static str {
  |                            -                    ^^^^^^^^^^^^ type annotation requires that `'life2` must outlive `'static`
  |                            |
  |                            lifetime `'life1` defined here

error: lifetime may not live long enough
 --> src/lib.rs:8:49
  |
8 |     async fn bar(&self, x: &str, y: &'_ str) -> &'static str {
  |                                      --         ^^^^^^^^^^^^ type annotation requires that `'life2` must outlive `'static`
  |                                      |
  |                                      lifetime `'life2` defined here

help: the following changes may resolve your lifetime errors
  |
  = help: replace `'life0` with `'static`
  = help: replace `'life1` with `'static`
  = help: replace `'life2` with `'static`

error: could not compile `playground` due to 3 previous errors
@dtolnay
Copy link
Owner

dtolnay commented Jan 20, 2023

Good idea; thank you.

Fixed in async-trait 0.1.62.

@steffahn
Copy link
Author

This was done so quickly, thank you!

crapStone added a commit to Calciumdibromid/CaBr2 that referenced this issue Jan 23, 2023
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [async-trait](https://github.com/dtolnay/async-trait) | dependencies | patch | `0.1.61` -> `0.1.62` |

---

### Release Notes

<details>
<summary>dtolnay/async-trait</summary>

### [`v0.1.62`](https://github.com/dtolnay/async-trait/releases/tag/0.1.62)

[Compare Source](dtolnay/async-trait@0.1.61...0.1.62)

-   Improve error message involving elided lifetimes ([#&#8203;229](dtolnay/async-trait#229))

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNC4xMDYuMCIsInVwZGF0ZWRJblZlciI6IjM0LjEwNi4wIn0=-->

Co-authored-by: cabr2-bot <cabr2.help@gmail.com>
Co-authored-by: crapStone <crapstone01@gmail.com>
Reviewed-on: https://codeberg.org/Calciumdibromid/CaBr2/pulls/1746
Reviewed-by: crapStone <crapstone@noreply.codeberg.org>
Co-authored-by: Calciumdibromid Bot <cabr2_bot@noreply.codeberg.org>
Co-committed-by: Calciumdibromid Bot <cabr2_bot@noreply.codeberg.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants