Skip to content

Code Action generate mut trait noeffect $0 #1320

@A4-Tacks

Description

@A4-Tacks

What's the output of :CocInfo

## versions

vim version: VIM - Vi IMproved 9.1 9011362
node version: v23.9.0
coc.nvim version: 0.0.82-cd4a6b6 2025-05-21 20:12:09 +0800
coc.nvim directory: /home/lrne/.vim/plugged/coc.nvim
term: dumb
platform: linux

## Log of coc.nvim

2025-07-25T22:46:17.118 INFO (pid:16828) [plugin] - coc.nvim initialized with node: v23.9.0 after 775
2025-07-25T22:46:17.123 INFO (pid:16828) [services] - LanguageClient Rust Analyzer Language Server state change: stopped => starting
2025-07-25T22:46:17.146 INFO (pid:16828) [language-client-index] - Language server "rust-analyzer" started with 16864
2025-07-25T22:46:17.530 INFO (pid:16828) [services] - LanguageClient Rust Analyzer Language Server state change: starting => running
2025-07-25T22:46:17.558 INFO (pid:16828) [services] - service rust-analyzer started
2025-07-25T22:46:42.931 INFO (pid:16828) [attach] - receive notification: codeAction [ 'cursor' ]
2025-07-25T22:46:45.151 INFO (pid:16828) [extension:coc-rust-analyzer] - {
  range: { start: { line: 1, character: 0 }, end: { line: 1, character: 0 } },
  newText: '$0impl std::ops::IndexMut<&str> for Foo {\n' +
    '    fn index_mut(&mut self, index: &str) -> &mut Self::Output {\n' +
    '        &mut ()\n' +
    '    }\n' +
    '}\n' +
    '\n'
}
2025-07-25T22:46:48.800 INFO (pid:16828) [attach] - receive notification: showInfo []

What's the output of :CocCommand rust-analyzer.serverVersion

rust-analyzer 1.90.0-nightly (9748d87 2025-07-21)

What's your coc-rust-analyzer version? You can get it from :CocList extensions

+ coc-rust-analyzer 0.83.0

src/main.rs

pub struct Foo;
impl std::ops::Index<&str> for Foo {
    type Output = ();
    fn index(&self, index: &str) -> &Self::Output {
        &()
    }
}

fn main() {}

On line2 ops click 3. Generate `IndexMut` impl from this `Index` trai

Output:

pub struct Foo;
$0impl std::ops::IndexMut<&str> for Foo {
    fn index_mut(&mut self, index: &str) -> &mut Self::Output {
        &mut ()
    }
}

impl std::ops::Index<&str> for Foo {
    type Output = ();
    fn index(&self, index: &str) -> &Self::Output {
        &()
    }
}

fn main() {}

mini-vimrc:

colorscheme habamax

set nu
set laststatus=2
set statusline=%<%f\ %h%m%r%=%-14.(%l,%c%V%)\ %P
set statusline^=%(%1*[%{coc#status()}%{get(b:,'coc_current_function','')}]%*\ %)

call plug#begin('~/.vim/plugged')
Plug 'neoclide/coc.nvim'
call plug#end()

inoremap <silent><expr> <cr> foldclosed('.') != -1
            \ ? execute("foldopen!")
            \ : coc#pum#visible() ? coc#pum#confirm()
            \ : "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"
nmap <F3> <Plug>(coc-codeaction-cursor)

coc-settings.json:

{
    "rust-analyzer.updates.checkOnStartup": false
}

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions