Skip to content
This repository has been archived by the owner on Jan 3, 2024. It is now read-only.

edition error when running RustEmitIr or Rust EmitAsm #400

Open
salimp2009 opened this issue Jun 26, 2023 · 5 comments
Open

edition error when running RustEmitIr or Rust EmitAsm #400

salimp2009 opened this issue Jun 26, 2023 · 5 comments

Comments

@salimp2009
Copy link

salimp2009 commented Jun 26, 2023

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 salimp2009 changed the title edition error when running RustEmitIr or Rust EmitAst edition error when running RustEmitIr or Rust EmitAsm Jun 27, 2023
@salimp2009
Copy link
Author

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,
})

@roberte777
Copy link

Any progress on this?

@salimp2009
Copy link
Author

Any progress on this?

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

@roberte777
Copy link

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.

@salimp2009
Copy link
Author

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants