Error fix suggestion request: replace `Self` with more lifetime lenient self type name

Abierto
#166,483 2 comentarios 1 reacción 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
45/100
Tipo de issue
Nueva funcionalidad
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
rust
Área
compilers

Línea de trabajo

The payload gives a minimal SliceMut reproducer and the current and desired lifetime may not live long enough output. Start by finding where that borrowck message is emitted and where the existing Self suggestion logic lives in rustc. Done means the note replace Self with SliceMut appears for this case, with a UI test added under tests/ui that matches the desired output.

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

Descripción

A-borrow-checker A-diagnostics A-lifetimes D-lack-of-suggestion T-compiler
Code
pub struct SliceMut<'a, T>(&'a mut [T]);

impl<'a, T> SliceMut<'a, T> {
    pub fn subslice_ok(&mut self, start: usize, end: usize) -> SliceMut<'_, T> {
        SliceMut(&mut self.0[start .. end])
    }
    
    pub fn subslice_fail(&mut self, start: usize, end: usize) -> SliceMut<'_, T> {
        Self(&mut self.0[start .. end])
    }
}
Current output
error: lifetime may not live long enough
  --> src/lib.rs:10:14
   |
 4 | impl<'a, T> SliceMut<'a, T> {
   |      -- lifetime `'a` defined here
...
 9 |     pub fn subslice_fail(&mut self, start: usize, end: usize) -> SliceMut<'_, T> {
   |                          - let's call the lifetime of this reference `'1`
10 |         Self(&mut self.0[start .. end])
   |              ^^^^^^^^^^^^^^^^^^^^^^^^^ this usage requires that `'1` must outlive `'a`
Desired output
error: lifetime may not live long enough
  --> src/lib.rs:10:14
   |
 4 | impl<'a, T> SliceMut<'a, T> {
   |      -- lifetime `'a` defined here
...
 9 |     pub fn subslice_fail(&mut self, start: usize, end: usize) -> SliceMut<'_, T> {
   |                          - let's call the lifetime of this reference `'1`
10 |         Self(&mut self.0[start .. end])
   |              ^^^^^^^^^^^^^^^^^^^^^^^^^ this usage requires that `'1` must outlive `'a`
     note: replace `Self` with `SliceMut`
Rationale and extra context

rustc should suggest replacing concrete type Self with the not-lifetime-bound self type name when those lifetimes differ

Other cases

Rust Version
rustc 1.101.0-nightly (1a2c4797e 2026-10-21)
binary: rustc
commit-hash: 1a2c4797ef2570bd76ca5dee34449169bc7dc457
commit-date: 2026-10-21
host: x86_64-unknown-linux-gnu
release: 1.101.0-nightly
LLVM version: 23.1.4
Anything else?

No response

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.