Skip to content

Increase visibility assist doesn't play well with comments #21016

@pacak

Description

@pacak

rust-analyzer version:

% rust-analyzer --version
rust-analyzer 1.91.0 (f8297e3 2025-10-28)

rustc version: (eg. output of rustc -V)

 rustc -Vv
rustc 1.91.0 (f8297e351 2025-10-28)
binary: rustc
commit-hash: f8297e351a40c1439a467bbbb6879088047f50b3
commit-date: 2025-10-28
host: x86_64-unknown-linux-gnu
release: 1.91.0
LLVM version: 21.1.2

editor or extension: neovim 0.11, rustaceanvim

relevant settings: Nothing special

repository link (if public, optional): (eg. rust-analyzer)

code snippet to reproduce:

use crate::internal::Foo;

pub mod internal {
    pub struct Foo {
        /// plz
        bar: u32,
        // plz
        baz: u32,
    }
}

pub fn add() -> Foo {
    Foo { bar: 42, baz: 42 }
}

Running increasing visibility assist on bar/baz produces this:

use crate::internal::Foo;

pub mod internal {
    pub struct Foo {
        pub(crate) /// plz
        bar: u32,
        pub(crate) // plz
        baz: u32,
    }
}

pub fn add() -> Foo {
    Foo { bar: 42, baz: 42 }
}

Which is not valid code. I like the idea though.

I didn't check if it was fixed in the most recent version, but I tried looking though tickets/MRs and found no matches.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions