rust-tools.nvim icon indicating copy to clipboard operation
rust-tools.nvim copied to clipboard

edition error when running RustEmitIr or Rust EmitAsm

Open salimp2009 opened this issue 2 years ago • 5 comments

Hi I have been using rust-tool for a while and it is awesome. However some of the commands (that use rustc; e.g RustEmitIr, RustEmitAsm) gives error due to edtion issue if there is an item that is not included in edtion 2015. Is it possible to read the edition from Cargo.toml file and pass that as an argument to rustc to avoid those errors. Cargo is currently uses edition 2021 as default ; image image

salimp2009 avatar Jun 26 '23 18:06 salimp2009

I believe checking edition can be done in a similar way to the example below for rustfmt as explained in null-ls wiki but use it for RustEmitIr or RustEmitAsm functions ( I believe edition can be passed as an argument to rustc )

null_ls.builtins.formatting.rustfmt.with({
    extra_args = function(params)
        local Path = require("plenary.path")
        local cargo_toml = Path:new(params.root .. "/" .. "Cargo.toml")

        if cargo_toml:exists() and cargo_toml:is_file() then
            for _, line in ipairs(cargo_toml:readlines()) do
                local edition = line:match([[^edition%s*=%s*%"(%d+)%"]])
                if edition then
                    return { "--edition=" .. edition }
                end
            end
        end
        -- default edition when we don't find `Cargo.toml` or the `edition` in it.
        return { "--edition=2021" }
    end,
})

salimp2009 avatar Jul 02 '23 11:07 salimp2009

Any progress on this?

roberte777 avatar Oct 14 '23 05:10 roberte777

Any progress on this?

not that I know off. No body even responded yet :(

salimp2009 avatar Oct 14 '23 09:10 salimp2009

Any progress on this?

not that I know off. No body even responded yet :(

I do know that you're right about setting the edition. I'm not even sure how to pass it to the rust tools commands, though. I tried to pass it directly in the language server command, still getting the edition errors.

roberte777 avatar Oct 14 '23 13:10 roberte777

Any progress on this?

not that I know off. No body even responded yet :(

I do know that you're right about setting the edition. I'm not even sure how to pass it to the rust tools commands, though. I tried to pass it directly in the language server command, still getting the edition errors.

I have not looked at how rust-tools implemented . it can be either hard coded or can be read from toml file as in the example how null-ls does.

salimp2009 avatar Oct 14 '23 13:10 salimp2009