Skip to content

Some rename bugs #18812

Closed as not planned
Closed as not planned
@Bben01

Description

@Bben01

rust-analyzer version: 0.3.2237-standalone (59bc7b4 2024-12-29)
rustc 1.83.0 (90b35a623 2024-11-26)
VSCode version: 1.95.3 (macOS)

Hi,
I worked lately on a renaming tool using r-a, I ran into some edge cases.
I've opened a repo that list what I could minimally reproduce, with one bug per module.

You can find it here: https://github.com/Bben01/rust-analyser-rename-bugs

Here is a summary of the bugs:

  • Renaming an item that have a cfg-ed out counterpart won't get renamed
// here we have two items, one will be disabled and one enabled,
// if I rename the one that is enabled, the other one won't get renamed

#[cfg(miri)]
const CONST: usize = 6;

#[cfg(not(miri))]
const CONST: usize = 8;
pub struct Offset {
    // renaming inner here won't rename inner in the offset_of! macro
    inner: Inner,
}

pub struct Inner {
    // renaming `a` here won't rename `a` in the offset_of! macro
    a: u8,
}

#[test]
fn rename_offset_of() {
    // Trying to rename inner or `a` from here results in a "No reference found at position"
    std::mem::offset_of!(Offset, inner.a);
}
  • Renaming a function used in serde(with = "") won't get renamed
use std::fmt::Display;
use serde::{Serialize, Serializer};

#[derive(Serialize)]
pub struct SomeStruct {
    #[serde(serialize_with = "serialize_as_display")]
    field: usize,
}

// renaming this function won't rename the usage in `serialize_with`
pub fn serialize_as_display<T, S>(value: &T, serializer: S) -> Result<S::Ok, S::Error>
where
    T: Display,
    S: Serializer,
{
    serializer.serialize_str(&value.to_string())
}
// This currently export both the function and the struct
pub use aligned::Aligned;

mod aligned {
    // Renaming this struct will rename the `pub use` above, breaking the use in the test
    pub struct Aligned {
        size: usize,
    }

    #[allow(non_snake_case)]
    pub fn Aligned(size: usize) -> Aligned {
        Aligned {
            size
        }
    }
}

#[test]
fn aligned_rename_failure() {
    Aligned(5);
}
use std::io;
use thiserror::Error;

#[derive(Error, Debug)]
#[error("Rename failed at {}", .source)]
pub struct Error {
    // renaming this field won't rename the usage above
    source: io::Error,
}

I am also working on reproducing a crash I got with the semantic db, I will update this issue when I get an example.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-idegeneral IDE featuresC-bugCategory: bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions