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

Extract into variables: overlapping ranges not permitted #16539

Closed
Veykril opened this issue Feb 12, 2024 · 5 comments · Fixed by #16569
Closed

Extract into variables: overlapping ranges not permitted #16539

Veykril opened this issue Feb 12, 2024 · 5 comments · Fixed by #16569
Assignees
Labels
A-assists C-bug Category: bug

Comments

@Veykril
Copy link
Member

Veykril commented Feb 12, 2024

fn expander_to_proc_macro(
    expander: proc_macro_api::ProcMacro,
    ignored_macros: &[Box<str>],
) -> ProcMacro {
    let name = From::from(expander.name());
    let kind = match expander.kind() {
        proc_macro_api::ProcMacroKind::CustomDerive => ProcMacroKind::CustomDerive,
        proc_macro_api::ProcMacroKind::FuncLike => ProcMacroKind::FuncLike,
        proc_macro_api::ProcMacroKind::Attr => ProcMacroKind::Attr,
    };
    ProcMacro {
        name,
        kind,
        expander: sync::Arc::new(Expander(expander)),
        disabled: $0ignored_macros.iter().any(|replace| **replace == name)$0,
    }
}

Invoking Extract into variables on that range here errors with overlapping ranges not permitted. I've been running into this quite frequently recently.

@Veykril Veykril added A-assists C-bug Category: bug labels Feb 12, 2024
@Veykril
Copy link
Member Author

Veykril commented Feb 12, 2024

@DropDemBits I think this might be due to 1e1761e, if you have the time to look into that that at some point would be nice :) (anyone else is welcome to as well of course)

@roife
Copy link
Member

roife commented Feb 13, 2024

It works fine with latest master branch on my machine.

@Veykril
Copy link
Member Author

Veykril commented Feb 13, 2024

This seems to be location sensitive 😖 if you place that concrete snippet over https://github.com/rust-lang/rust-analyzer/blame/47b4dd72730e1b3d475cee8361faf47b79b0f583/crates/load-cargo/src/lib.rs#L349-L361 it triggers the error, if you put that function somewhere else it doesn't necessarily happen

@DropDemBits
Copy link
Contributor

Hmm, that feels like it has like something to do with snippet rendering, so I should look into that.

@rustbot claim

@DropDemBits
Copy link
Contributor

I've managed to minimize it to this:

fn expander_to_proc_macro() -> ProcMacro {
    ProcMacro {
        disabled: $0false$0,
    }
}

struct ProcMacro {
    disabled: bool,
}

Which generates this SourceChange:

SourceChange {
    source_file_edits: {
        FileId(
            0,
        ): (
            TextEdit {
                indels: [
                    Indel {
                        insert: "let",
                        delete: 47..56,
                    },
                    Indel {
                        insert: "disabled = false;\n    ProcMacro {\n        disabled,\n    }",
                        delete: 57..89,
                    },
                ],
            },
            Some(
                SnippetEdit(
                    [
                        (
                            0,
                            51..51,
                        ),
                    ],
                ),
            ),
        ),
    },
    file_system_edits: [],
    is_snippet: true,
}

This is a problem for the current snippet rendering code since it doesn't account for differences between the final source range and the initial source range when determining the new range that an Indel covers, and therefore whether a snippet lands inside of an Indel or not.

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

Successfully merging a pull request may close this issue.

3 participants