`mismatched_lifetime_syntaxes` suggests a machine-applicable edit that breaks shared macro invocations

Đang mở
#166,635 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
43/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
rust
Lĩnh vực
compilers

Hướng nghiên cứu

Start by reading the mismatched_lifetime_syntaxes lint implementation and its diagnostic tests; the issue does not name specific files. Reproduce the provided macro example and inspect how suggestions are emitted for multiple invocations. Done means the lint still warns but no longer marks an edit as machine-applicable when applying it breaks another invocation.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

A-lints A-macros A-suggestion-diagnostics C-bug D-invalid-suggestion L-mismatched_lifetime_syntaxes S-has-mcve T-compiler
Issue description

I found bug in Rust’s mismatched_lifetime_syntaxes lint. When 2 functions use the same macro in their return types, one with 'a and the other with 'b, the compiler suggests adding each lifetime at the same place in the macro definition and marks both edits MachineApplicable. Applying either automatic edit makes the other function fail with E0261 because the inserted lifetime name is out of scope there. I reproduced this on Rust 1.100.0 and Rust 1.102.0-nightly (6c709eb42), and cannot find a matching issue or PR yet.

Code
#![allow(dead_code)]

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

macro_rules! out {
    () => {
        Wrap
    };
}

fn first<'a>(x: &'a u8) -> out!() {
    Wrap(x)
}

fn second<'b>(x: &'b u8) -> out!() {
    Wrap(x)
}
Current output

Compiler output from Rust 1.102.0-nightly:

warning: hiding a lifetime that's named elsewhere is confusing
help: consistently use `'a`
 7 |         Wrap<'a>
   |             ++++

warning: hiding a lifetime that's named elsewhere is confusing
help: consistently use `'b`
 7 |         Wrap<'b>
   |             ++++

error[E0261]: use of undeclared lifetime name `'a`
 7 |         Wrap<'a>
   |              ^^ undeclared lifetime
...
15 | fn second<'b>(x: &'b u8) -> out!() {
   |                             ------ in this macro invocation

Test observation: Applying the 'a suggestion at line 7, column 13 (MachineApplicable) produces the E0261 error shown above.

Rust Version
rustc 1.102.0-nightly (6c709eb42 2026-11-25)
binary: rustc
commit-hash: 6c709eb428d472a3c3d93681c1ba37d44a1c27cf
commit-date: 2026-11-25
host: aarch64-apple-darwin
release: 1.102.0-nightly
LLVM version: 23.1.6
Desired output

The lint should continue warning about the inconsistent lifetime syntax, but avoid suggesting an automatic edit that breaks another macro invocation.

AI assistance

I used AI assistance to help discover and verify this bug. I independently reproduced it on the listed Rust versions before filing.

Ngôn ngữ chính
Rust
Star
123k
Fork
16.6k
Merge trung bình
2 ngày 17 giờ
Pull request đã merge (30 ngày)
532

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của rust-lang/rust

Tất cả issue của rust-lang/rust

Issue tương tự

Thêm issue về Rust

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.