From d3d88ad34554387a286edb00718bc9b640e16314 Mon Sep 17 00:00:00 2001 From: saying121 Date: Sun, 11 Feb 2024 13:12:06 +0800 Subject: [PATCH 1/3] refactor(Rustc): do not need a main function, and make it can use 2024 edition --- CHANGELOG.md | 4 ++-- lua/rustaceanvim/commands/rustc_unpretty.lua | 20 +++++++++++++------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 61305cd3..0b3f20aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -93,7 +93,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 Used by default in Neovim >= 0.10. - LSP: `:RustLsp testables` command, which is equivalent to `:RustLsp runnables`, but filters the runnables for tests only, - + > [!IMPORTANT] > > In Neovim < 0.10, `'background'` executor blocks the UI while running tests. @@ -107,7 +107,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 and achieve an experience similar to Rust Playground. (currently requires a nightly compiler). Thanks [saying121](https://github.com/saying121)! -- Config: `tools.rustc_unpretty` arguments for `rustc`. +- Config: `tools.rustc` arguments for `rustc`. ### Changed diff --git a/lua/rustaceanvim/commands/rustc_unpretty.lua b/lua/rustaceanvim/commands/rustc_unpretty.lua index c42d403e..9c797dea 100644 --- a/lua/rustaceanvim/commands/rustc_unpretty.lua +++ b/lua/rustaceanvim/commands/rustc_unpretty.lua @@ -110,7 +110,7 @@ function M.rustc_unpretty(level) local pos = { math.max(cursor[1] - 1, 0), cursor[2] } local cline = api.nvim_get_current_line() - if not string.find(cline, 'fn%s*') then + if not string.find(cline, 'fn%s+') then local temp = vim.fn.searchpos('fn ', 'bcn', vim.fn.line('w0')) pos = { math.max(temp[1] - 1, 0), temp[2] } end @@ -129,13 +129,19 @@ function M.rustc_unpretty(level) end text = table.concat(b, '\n') - -- rustc need a main function for `-Z unpretty` - if not string.find(text, 'fn%s*main') then - text = text .. 'fn main() {}' - end - compat.system( - { rustc, '--edition', config.tools.rustc.edition, '-Z', 'unpretty=' .. level, '-' }, + { + rustc, + '--crate-type', + 'lib', + '--edition', + config.tools.rustc.edition, + '-Z', + 'unstable-options', + '-Z', + 'unpretty=' .. level, + '-', + }, { stdin = text }, vim.schedule_wrap(handler) ) From 9c7d0bf9a924728c041c587a000496ae96f4510c Mon Sep 17 00:00:00 2001 From: saying121 Date: Sun, 11 Feb 2024 13:31:56 +0800 Subject: [PATCH 2/3] style(stylua): reformat docs(changelog): update --- CHANGELOG.md | 7 +++++ lua/rustaceanvim/commands/rustc_unpretty.lua | 28 +++++++++----------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0b3f20aa..a45af13e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,13 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [Unreleased] + +### Changed + +- Rustc: Do not need a main function, and make it can use 2024 edition + by unstable-options. + ## [4.6.0] - 2024-02-07 ### Added diff --git a/lua/rustaceanvim/commands/rustc_unpretty.lua b/lua/rustaceanvim/commands/rustc_unpretty.lua index 9c797dea..f81d516c 100644 --- a/lua/rustaceanvim/commands/rustc_unpretty.lua +++ b/lua/rustaceanvim/commands/rustc_unpretty.lua @@ -129,22 +129,18 @@ function M.rustc_unpretty(level) end text = table.concat(b, '\n') - compat.system( - { - rustc, - '--crate-type', - 'lib', - '--edition', - config.tools.rustc.edition, - '-Z', - 'unstable-options', - '-Z', - 'unpretty=' .. level, - '-', - }, - { stdin = text }, - vim.schedule_wrap(handler) - ) + compat.system({ + rustc, + '--crate-type', + 'lib', + '--edition', + config.tools.rustc.edition, + '-Z', + 'unstable-options', + '-Z', + 'unpretty=' .. level, + '-', + }, { stdin = text }, vim.schedule_wrap(handler)) end return M From a42b367cbabad6eaa7ae8a296aa8cdce5350062c Mon Sep 17 00:00:00 2001 From: Marc Jakobi Date: Sun, 11 Feb 2024 16:03:42 +0100 Subject: [PATCH 3/3] Update CHANGELOG.md --- CHANGELOG.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a45af13e..1bad5ba6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,10 +8,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] -### Changed +### Added -- Rustc: Do not need a main function, and make it can use 2024 edition - by unstable-options. +- Rustc: Do not require a main function, + and support the 2024 edition + via `unstable-options`. ## [4.6.0] - 2024-02-07