Confusing message on inconsistent

オープン
#166,149 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
45/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
rust
領域
compilers

調査の方向性

Start by tracing how the mismatched_lifetime_syntaxes lint builds its spans and help text for elided input lifetimes and hidden output lifetimes. Reproduce the example with the stated Rust version, then inspect existing lint tests for similar cases. Done means the diagnostic explains this case accurately, with tests covering the chosen wording or behavior.

索引モデルが issue の本文から書いたものです。

説明

A-diagnostics T-compiler
Code
#![allow(dead_code)]

struct HintRef<'a>(&'a u8);

fn hint(value: &u8) -> HintRef {
    HintRef(value)
}

fn main() {}
Current output
warning: hiding a lifetime that's elided elsewhere is confusing
 --> src/main.rs:5:16
  |
5 | fn hint(value: &u8) -> HintRef {
  |                ^^^     ^^^^^^^ the same lifetime is hidden here
  |                |
  |                the lifetime is elided here
  |
  = help: the same lifetime is referred to in inconsistent ways, making the signature confusing
  = note: `#[warn(mismatched_lifetime_syntaxes)]` on by default
help: use `'_` for type paths
  |
5 | fn hint(value: &u8) -> HintRef<'_> {
  |                               ++++
Rationale and extra context

"the same lifetime is referred to in inconsistent ways" doesn't make sense in this context: neither the & nor the HintRef have any lifetime written, so arguably they are consistent?

I'm not sure what the cleanest option is here:

(1) Explicit mention of sugar:

5 | fn hint(value: &u8) -> HintRef {
  |                ^^^     ^^^^^^^ the same lifetime is hidden here
  |                |
  |                this lifetime is `_

(2) Just drop the warning in this case?

I'd also be tempted to change the span to only apply to the &, something like this:

5 | fn hint(value: &u8) -> HintRef {
  |                ^       ^^^^^^^ the same lifetime is hidden here
  |                |
  |                the lifetime is elided here
Rust Version
rustc 1.100.0 on the playground reproduces this.
主要言語
Rust
スター
122k
フォーク
16.7k
平均マージ
2日 16時間
マージ済み PR(30日)
515

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

rust-lang/rust のほかの issue

rust-lang/rust の issue をすべて見る

似ている issue

Rust の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。