Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Renaming a struct that has a function with the same name will break code: #18892

Open
Tracked by #18812
Veykril opened this issue Jan 9, 2025 · 1 comment · May be fixed by #19306
Open
Tracked by #18812

Renaming a struct that has a function with the same name will break code: #18892

Veykril opened this issue Jan 9, 2025 · 1 comment · May be fixed by #19306
Labels
A-ide general IDE features C-bug Category: bug

Comments

@Veykril
Copy link
Member

Veykril commented Jan 9, 2025

// 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);
}
@Veykril Veykril mentioned this issue Jan 9, 2025
5 tasks
@Veykril Veykril added C-bug Category: bug A-ide general IDE features labels Jan 9, 2025
@Hmikihiro
Copy link
Contributor

I think this issue has multiple expected behaviors when resolved.

Renaming both a struct and a function at the same time.

pub use aligned::Rename_Aligned;

mod aligned {
    pub struct Rename_Aligned {
        size: usize,
    }

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

#[test]
fn aligned_rename_failure() {
    Rename_Aligned(5);
}

Only renaming the struct name and adding an import.

pub use aligned::{Aligned, Rename_Aligned};

mod aligned {
    pub struct Rename_Aligned {
        size: usize,
    }

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

#[test]
fn aligned_rename_failure() {
    Aligned(5);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ide general IDE features C-bug Category: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants