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

Abierto
#166,635 1 comentario 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
43/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
rust
Área
compilers

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
Rust
Estrellas
123k
Forks
16.6k
Merge medio
2 d 17 h
PR fusionados (30 d)
532

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de rust-lang/rust

Todos los issues de rust-lang/rust

Issues similares

Más issues de Rust

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.