From 19e7a9a4ac93edc8b3bb4b5e129a1d1bc724555f Mon Sep 17 00:00:00 2001 From: saying Date: Sun, 11 Feb 2024 23:39:58 +0800 Subject: [PATCH] feat(rustc): do not require a main function + support 2024 edition (#225) Co-authored-by: saying121 Co-authored-by: Marc Jakobi --- CHANGELOG.md | 12 ++++++++-- lua/rustaceanvim/commands/rustc_unpretty.lua | 24 +++++++++++--------- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 61305cd3..1bad5ba6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,14 @@ 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] + +### Added + +- Rustc: Do not require a main function, + and support the 2024 edition + via `unstable-options`. + ## [4.6.0] - 2024-02-07 ### Added @@ -93,7 +101,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 +115,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..f81d516c 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,16 +129,18 @@ 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, '-' }, - { 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