Error fix suggestion request: replace `Self` with more lifetime lenient self type name
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
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.
由索引模型根据 Issue 内容生成。
描述
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
- 主要语言
- Rust
- 星标
- 123k
- 派生
- 16.6k
- 平均合并
- 2 天 17 小时
- 30 天内合并 PR
- 532
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
rust-lang/rust 的其他 Issue
-
C-bug needs-triage
难度 2/5 1-3 小时 新手友好度 88/100
rust-lang/rust#166722 · 1 个 reaction ·
维护者通常 1 天内回复
-
A-attributes relnotes relnotes-needs-review relnotes-tracking-issue T-compiler T-lang
难度 1/5 1 小时以内 新手友好度 78/100
维护者通常 1 天内回复
-
A-run-make C-bug T-bootstrap
难度 2/5 1-3 小时 新手友好度 65/100
维护者通常 1 天内回复
-
relnotes relnotes-tracking-issue T-libs
难度 1/5 1 小时以内 新手友好度 78/100
维护者通常 1 天内回复
-
A-str A-Unicode relnotes relnotes-tracking-issue T-libs
难度 1/5 1 小时以内 新手友好度 70/100
维护者通常 1 天内回复
相似的 Issue
-
Thai project names become 'project', 'project-2'… (slug keeps ASCII only)可能已有人在做 @mastel2 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 72/100
storytold/craft-anything#2538 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 70/100
compiler-explorer/compiler-explorer#9738 ·
维护者通常 2 天内回复
-
area: runtime enhancement good first issue help wanted
难度 2/5 1-3 小时 新手友好度 84/100
hffgzktbcc-blip/ounce-core#663 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 73/100
zellij-org/zellij#6026 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
tamatebako/tebako#1155 ·
维护者通常 1 天内回复