From 77de40192e6c5f39c511f846850fb60881e8ee9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauren=C8=9Biu=20Nicola?= Date: Sun, 26 Apr 2020 14:53:33 +0300 Subject: Use x86_64-unknown-linux-gnu for releases --- xtask/src/dist.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'xtask/src') diff --git a/xtask/src/dist.rs b/xtask/src/dist.rs index a56eeef8d..aef68089e 100644 --- a/xtask/src/dist.rs +++ b/xtask/src/dist.rs @@ -50,21 +50,19 @@ fn dist_server(nightly: bool) -> Result<()> { if cfg!(target_os = "linux") { std::env::set_var("CC", "clang"); run!( - "cargo build --manifest-path ./crates/rust-analyzer/Cargo.toml --bin rust-analyzer --release - --target x86_64-unknown-linux-musl - " + "cargo build --manifest-path ./crates/rust-analyzer/Cargo.toml --bin rust-analyzer --release" // We'd want to add, but that requires setting the right linker somehow // --features=jemalloc )?; if !nightly { - run!("strip ./target/x86_64-unknown-linux-musl/release/rust-analyzer")?; + run!("strip ./target/release/rust-analyzer")?; } } else { run!("cargo build --manifest-path ./crates/rust-analyzer/Cargo.toml --bin rust-analyzer --release")?; } let (src, dst) = if cfg!(target_os = "linux") { - ("./target/x86_64-unknown-linux-musl/release/rust-analyzer", "./dist/rust-analyzer-linux") + ("./target/release/rust-analyzer", "./dist/rust-analyzer-linux") } else if cfg!(target_os = "windows") { ("./target/release/rust-analyzer.exe", "./dist/rust-analyzer-windows.exe") } else if cfg!(target_os = "macos") { -- cgit v1.2.3 From 0af727da91e7ff3c8ed5518cb7e005e8d4f939b0 Mon Sep 17 00:00:00 2001 From: John Renner Date: Mon, 27 Apr 2020 10:02:47 -0700 Subject: Validate the location of `crate` in paths --- xtask/src/ast_src.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'xtask/src') diff --git a/xtask/src/ast_src.rs b/xtask/src/ast_src.rs index 9c02f7c6f..98c8644e4 100644 --- a/xtask/src/ast_src.rs +++ b/xtask/src/ast_src.rs @@ -595,7 +595,7 @@ pub(crate) const AST_SRC: AstSrc = AstSrc { qualifier: Path, } struct PathSegment { - T![::], T![<], NameRef, TypeArgList, ParamList, RetType, PathType, T![>] + T![::], T![crate], T![<], NameRef, TypeArgList, ParamList, RetType, PathType, T![>] } struct TypeArgList { T![::], -- cgit v1.2.3 From a1e84516e8c39a0dd65b1cbcb557de63c1d4b90a Mon Sep 17 00:00:00 2001 From: oxalica Date: Thu, 30 Apr 2020 17:42:34 +0800 Subject: Avoid `rustup` invocation for non-rustup rust installation --- xtask/src/lib.rs | 100 +++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 67 insertions(+), 33 deletions(-) (limited to 'xtask/src') diff --git a/xtask/src/lib.rs b/xtask/src/lib.rs index ec824a518..bf4d85dcb 100644 --- a/xtask/src/lib.rs +++ b/xtask/src/lib.rs @@ -10,7 +10,6 @@ pub mod pre_commit; pub mod codegen; mod ast_src; -use anyhow::Context; use std::{ env, io::Write, @@ -24,9 +23,9 @@ use crate::{ not_bash::{date_iso, fs2, pushd, rm_rf, run}, }; -pub use anyhow::Result; +pub use anyhow::{bail, Context as _, Result}; -const TOOLCHAIN: &str = "stable"; +const RUSTFMT_TOOLCHAIN: &str = "stable"; pub fn project_root() -> PathBuf { Path::new( @@ -57,15 +56,25 @@ pub fn run_rustfmt(mode: Mode) -> Result<()> { let _dir = pushd(project_root()); ensure_rustfmt()?; - let check = if mode == Mode::Verify { "--check" } else { "" }; - run!("rustup run {} -- cargo fmt -- {}", TOOLCHAIN, check)?; - Ok(()) + if Command::new("cargo") + .env("RUSTUP_TOOLCHAIN", RUSTFMT_TOOLCHAIN) + .args(&["fmt", "--"]) + .args(if mode == Mode::Verify { &["--check"][..] } else { &[] }) + .stderr(Stdio::inherit()) + .status()? + .success() + { + Ok(()) + } else { + bail!("Rustfmt failed"); + } } fn reformat(text: impl std::fmt::Display) -> Result { ensure_rustfmt()?; - let mut rustfmt = Command::new("rustup") - .args(&["run", TOOLCHAIN, "--", "rustfmt", "--config-path"]) + let mut rustfmt = Command::new("rustfmt") + .env("RUSTUP_TOOLCHAIN", RUSTFMT_TOOLCHAIN) + .args(&["--config-path"]) .arg(project_root().join("rustfmt.toml")) .args(&["--config", "fn_single_line=true"]) .stdin(Stdio::piped()) @@ -79,29 +88,42 @@ fn reformat(text: impl std::fmt::Display) -> Result { } fn ensure_rustfmt() -> Result<()> { - match Command::new("rustup") - .args(&["run", TOOLCHAIN, "--", "cargo", "fmt", "--version"]) + match Command::new("rustfmt") + .args(&["--version"]) + .env("RUSTUP_TOOLCHAIN", RUSTFMT_TOOLCHAIN) + .stdout(Stdio::piped()) .stderr(Stdio::null()) - .stdout(Stdio::null()) - .status() + .spawn() + .and_then(|child| child.wait_with_output()) { - Ok(status) if status.success() => return Ok(()), - _ => (), - }; - run!("rustup toolchain install {}", TOOLCHAIN)?; - run!("rustup component add rustfmt --toolchain {}", TOOLCHAIN)?; - Ok(()) + Ok(output) + if output.status.success() + && std::str::from_utf8(&output.stdout)?.contains(RUSTFMT_TOOLCHAIN) => + { + Ok(()) + } + _ => { + bail!( + "Failed to run rustfmt from toolchain '{0}'. \ + Please run `rustup component add rustfmt --toolchain {0}` to install it.", + RUSTFMT_TOOLCHAIN, + ); + } + } } pub fn run_clippy() -> Result<()> { - match Command::new("rustup") - .args(&["run", TOOLCHAIN, "--", "cargo", "clippy", "--version"]) + match Command::new("cargo") + .args(&["clippy", "--version"]) .stderr(Stdio::null()) .stdout(Stdio::null()) .status() { Ok(status) if status.success() => (), - _ => install_clippy().context("install clippy")?, + _ => bail!( + "Failed run cargo clippy. \ + Please run `rustup component add clippy` to install it.", + ), }; let allowed_lints = [ @@ -110,17 +132,7 @@ pub fn run_clippy() -> Result<()> { "clippy::nonminimal_bool", "clippy::redundant_pattern_matching", ]; - run!( - "rustup run {} -- cargo clippy --all-features --all-targets -- -A {}", - TOOLCHAIN, - allowed_lints.join(" -A ") - )?; - Ok(()) -} - -fn install_clippy() -> Result<()> { - run!("rustup toolchain install {}", TOOLCHAIN)?; - run!("rustup component add clippy --toolchain {}", TOOLCHAIN)?; + run!("cargo clippy --all-features --all-targets -- -A {}", allowed_lints.join(" -A "))?; Ok(()) } @@ -130,7 +142,29 @@ pub fn run_fuzzer() -> Result<()> { run!("cargo install cargo-fuzz")?; }; - run!("rustup run nightly -- cargo fuzz run parser")?; + // Expecting nightly rustc + match Command::new("rustc") + .args(&["--version"]) + .env("RUSTUP_TOOLCHAIN", "nightly") + .stdout(Stdio::piped()) + .stderr(Stdio::null()) + .spawn() + .and_then(|child| child.wait_with_output()) + { + Ok(output) + if output.status.success() + && std::str::from_utf8(&output.stdout)?.contains("nightly") => {} + _ => bail!("fuzz tests require nightly rustc"), + } + + let status = Command::new("cargo") + .env("RUSTUP_TOOLCHAIN", "nightly") + .args(&["fuzz", "run", "parser"]) + .stderr(Stdio::inherit()) + .status()?; + if !status.success() { + bail!("{}", status); + } Ok(()) } -- cgit v1.2.3 From 5f0008040e9a168e5eaec0bbd754a6f14d12896a Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Apr 2020 15:14:55 +0200 Subject: Allow to set env vars and pipe stdin via not_bash --- xtask/src/lib.rs | 111 ++++++++++++++------------------------------------ xtask/src/not_bash.rs | 60 ++++++++++++++++++++++----- 2 files changed, 79 insertions(+), 92 deletions(-) (limited to 'xtask/src') diff --git a/xtask/src/lib.rs b/xtask/src/lib.rs index bf4d85dcb..2b7a461e5 100644 --- a/xtask/src/lib.rs +++ b/xtask/src/lib.rs @@ -12,21 +12,18 @@ mod ast_src; use std::{ env, - io::Write, path::{Path, PathBuf}, - process::{Command, Stdio}, }; + use walkdir::{DirEntry, WalkDir}; use crate::{ codegen::Mode, - not_bash::{date_iso, fs2, pushd, rm_rf, run}, + not_bash::{date_iso, fs2, pushd, pushenv, rm_rf, run}, }; pub use anyhow::{bail, Context as _, Result}; -const RUSTFMT_TOOLCHAIN: &str = "stable"; - pub fn project_root() -> PathBuf { Path::new( &env::var("CARGO_MANIFEST_DIR").unwrap_or_else(|_| env!("CARGO_MANIFEST_DIR").to_owned()), @@ -54,77 +51,44 @@ pub fn rust_files(path: &Path) -> impl Iterator { pub fn run_rustfmt(mode: Mode) -> Result<()> { let _dir = pushd(project_root()); + let _e = pushenv("RUSTUP_TOOLCHAIN", "stable"); ensure_rustfmt()?; - - if Command::new("cargo") - .env("RUSTUP_TOOLCHAIN", RUSTFMT_TOOLCHAIN) - .args(&["fmt", "--"]) - .args(if mode == Mode::Verify { &["--check"][..] } else { &[] }) - .stderr(Stdio::inherit()) - .status()? - .success() - { - Ok(()) - } else { - bail!("Rustfmt failed"); - } + match mode { + Mode::Overwrite => run!("cargo fmt"), + Mode::Verify => run!("cargo fmt -- --check"), + }?; + Ok(()) } fn reformat(text: impl std::fmt::Display) -> Result { + let _e = pushenv("RUSTUP_TOOLCHAIN", "stable"); ensure_rustfmt()?; - let mut rustfmt = Command::new("rustfmt") - .env("RUSTUP_TOOLCHAIN", RUSTFMT_TOOLCHAIN) - .args(&["--config-path"]) - .arg(project_root().join("rustfmt.toml")) - .args(&["--config", "fn_single_line=true"]) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .spawn()?; - write!(rustfmt.stdin.take().unwrap(), "{}", text)?; - let output = rustfmt.wait_with_output()?; - let stdout = String::from_utf8(output.stdout)?; + let stdout = run!( + "rustfmt --config-path {} --config fn_single_line=true", project_root().join("rustfmt.toml").display(); + Result<()> { - match Command::new("rustfmt") - .args(&["--version"]) - .env("RUSTUP_TOOLCHAIN", RUSTFMT_TOOLCHAIN) - .stdout(Stdio::piped()) - .stderr(Stdio::null()) - .spawn() - .and_then(|child| child.wait_with_output()) - { - Ok(output) - if output.status.success() - && std::str::from_utf8(&output.stdout)?.contains(RUSTFMT_TOOLCHAIN) => - { - Ok(()) - } - _ => { - bail!( - "Failed to run rustfmt from toolchain '{0}'. \ - Please run `rustup component add rustfmt --toolchain {0}` to install it.", - RUSTFMT_TOOLCHAIN, - ); - } + let out = run!("rustfmt --version")?; + if !out.contains("stable") { + bail!( + "Failed to run rustfmt from toolchain 'stable'. \ + Please run `rustup component add rustfmt --toolchain stable` to install it.", + ) } + Ok(()) } pub fn run_clippy() -> Result<()> { - match Command::new("cargo") - .args(&["clippy", "--version"]) - .stderr(Stdio::null()) - .stdout(Stdio::null()) - .status() - { - Ok(status) if status.success() => (), - _ => bail!( + if run!("cargo clippy --version").is_err() { + bail!( "Failed run cargo clippy. \ Please run `rustup component add clippy` to install it.", - ), - }; + ) + } let allowed_lints = [ "clippy::collapsible_if", @@ -138,33 +102,18 @@ pub fn run_clippy() -> Result<()> { pub fn run_fuzzer() -> Result<()> { let _d = pushd("./crates/ra_syntax"); + let _e = pushenv("RUSTUP_TOOLCHAIN", "nightly"); if run!("cargo fuzz --help").is_err() { run!("cargo install cargo-fuzz")?; }; // Expecting nightly rustc - match Command::new("rustc") - .args(&["--version"]) - .env("RUSTUP_TOOLCHAIN", "nightly") - .stdout(Stdio::piped()) - .stderr(Stdio::null()) - .spawn() - .and_then(|child| child.wait_with_output()) - { - Ok(output) - if output.status.success() - && std::str::from_utf8(&output.stdout)?.contains("nightly") => {} - _ => bail!("fuzz tests require nightly rustc"), + let out = run!("rustc --version")?; + if !out.contains("nightly") { + bail!("fuzz tests require nightly rustc") } - let status = Command::new("cargo") - .env("RUSTUP_TOOLCHAIN", "nightly") - .args(&["fuzz", "run", "parser"]) - .stderr(Stdio::inherit()) - .status()?; - if !status.success() { - bail!("{}", status); - } + run!("cargo fuzz run parser")?; Ok(()) } diff --git a/xtask/src/not_bash.rs b/xtask/src/not_bash.rs index ef1699934..a6431e586 100644 --- a/xtask/src/not_bash.rs +++ b/xtask/src/not_bash.rs @@ -3,6 +3,8 @@ use std::{ cell::RefCell, env, + ffi::OsString, + io::Write, path::{Path, PathBuf}, process::{Command, Stdio}, }; @@ -57,7 +59,10 @@ macro_rules! _run { run!($($expr),*; echo = true) }; ($($expr:expr),* ; echo = $echo:expr) => { - $crate::not_bash::run_process(format!($($expr),*), $echo) + $crate::not_bash::run_process(format!($($expr),*), $echo, None) + }; + ($($expr:expr),* ; <$stdin:expr) => { + $crate::not_bash::run_process(format!($($expr),*), false, Some($stdin)) }; } pub(crate) use _run as run; @@ -77,6 +82,21 @@ impl Drop for Pushd { } } +pub struct Pushenv { + _p: (), +} + +pub fn pushenv(var: &str, value: &str) -> Pushenv { + Env::with(|env| env.pushenv(var.into(), value.into())); + Pushenv { _p: () } +} + +impl Drop for Pushenv { + fn drop(&mut self) { + Env::with(|env| env.popenv()) + } +} + pub fn rm_rf(path: impl AsRef) -> Result<()> { let path = path.as_ref(); if !path.exists() { @@ -90,15 +110,15 @@ pub fn rm_rf(path: impl AsRef) -> Result<()> { } #[doc(hidden)] -pub fn run_process(cmd: String, echo: bool) -> Result { - run_process_inner(&cmd, echo).with_context(|| format!("process `{}` failed", cmd)) +pub fn run_process(cmd: String, echo: bool, stdin: Option<&[u8]>) -> Result { + run_process_inner(&cmd, echo, stdin).with_context(|| format!("process `{}` failed", cmd)) } pub fn date_iso() -> Result { run!("date --iso --utc") } -fn run_process_inner(cmd: &str, echo: bool) -> Result { +fn run_process_inner(cmd: &str, echo: bool, stdin: Option<&[u8]>) -> Result { let mut args = shelx(cmd); let binary = args.remove(0); let current_dir = Env::with(|it| it.cwd().to_path_buf()); @@ -107,12 +127,17 @@ fn run_process_inner(cmd: &str, echo: bool) -> Result { println!("> {}", cmd) } - let output = Command::new(binary) - .args(args) - .current_dir(current_dir) - .stdin(Stdio::null()) - .stderr(Stdio::inherit()) - .output()?; + let mut command = Command::new(binary); + command.args(args).current_dir(current_dir).stderr(Stdio::inherit()); + let output = match stdin { + None => command.stdin(Stdio::null()).output(), + Some(stdin) => { + command.stdin(Stdio::piped()).stdout(Stdio::piped()); + let mut process = command.spawn()?; + process.stdin.take().unwrap().write_all(stdin)?; + process.wait_with_output() + } + }?; let stdout = String::from_utf8(output.stdout)?; if echo { @@ -133,13 +158,15 @@ fn shelx(cmd: &str) -> Vec { struct Env { pushd_stack: Vec, + pushenv_stack: Vec<(OsString, Option)>, } impl Env { fn with T, T>(f: F) -> T { thread_local! { static ENV: RefCell = RefCell::new(Env { - pushd_stack: vec![env::current_dir().unwrap()] + pushd_stack: vec![env::current_dir().unwrap()], + pushenv_stack: vec![], }); } ENV.with(|it| f(&mut *it.borrow_mut())) @@ -154,6 +181,17 @@ impl Env { self.pushd_stack.pop().unwrap(); env::set_current_dir(self.cwd()).unwrap(); } + fn pushenv(&mut self, var: OsString, value: OsString) { + self.pushenv_stack.push((var.clone(), env::var_os(&var))); + env::set_var(var, value) + } + fn popenv(&mut self) { + let (var, value) = self.pushenv_stack.pop().unwrap(); + match value { + None => env::remove_var(var), + Some(value) => env::set_var(var, value), + } + } fn cwd(&self) -> &Path { self.pushd_stack.last().unwrap() } -- cgit v1.2.3 From 15cfa9a808be820ceafc2e957ea8532e8ec68f00 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Apr 2020 21:36:31 +0200 Subject: Fix a bunch of false-positives in join-lines --- xtask/src/ast_src.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'xtask/src') diff --git a/xtask/src/ast_src.rs b/xtask/src/ast_src.rs index 98c8644e4..c14804aad 100644 --- a/xtask/src/ast_src.rs +++ b/xtask/src/ast_src.rs @@ -451,7 +451,7 @@ pub(crate) const AST_SRC: AstSrc = AstSrc { struct ContinueExpr: AttrsOwner { T![continue], T![lifetime] } struct BreakExpr: AttrsOwner { T![break], T![lifetime], Expr } struct Label { T![lifetime] } - struct BlockExpr: AttrsOwner { Label, T![unsafe], Block } + struct BlockExpr: AttrsOwner { Label, T![unsafe], T![async], Block } struct ReturnExpr: AttrsOwner { Expr } struct CallExpr: ArgListOwner { Expr } struct MethodCallExpr: AttrsOwner, ArgListOwner { -- cgit v1.2.3 From 292ba6a1f81fee4170c3081f74499fe8c3ddedd4 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Apr 2020 22:41:14 +0200 Subject: Remove dead code, which elaborately pretends to be alive --- xtask/src/ast_src.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'xtask/src') diff --git a/xtask/src/ast_src.rs b/xtask/src/ast_src.rs index c14804aad..bdd42cb76 100644 --- a/xtask/src/ast_src.rs +++ b/xtask/src/ast_src.rs @@ -162,7 +162,6 @@ pub(crate) const KINDS_SRC: KindsSrc = KindsSrc { "RECORD_LIT", "RECORD_FIELD_LIST", "RECORD_FIELD", - "TRY_BLOCK_EXPR", "BOX_EXPR", // postfix "CALL_EXPR", @@ -440,7 +439,6 @@ pub(crate) const AST_SRC: AstSrc = AstSrc { } struct IfExpr: AttrsOwner { T![if], Condition } struct LoopExpr: AttrsOwner, LoopBodyOwner { T![loop] } - struct TryBlockExpr: AttrsOwner { T![try], body: BlockExpr } struct ForExpr: AttrsOwner, LoopBodyOwner { T![for], Pat, @@ -451,7 +449,7 @@ pub(crate) const AST_SRC: AstSrc = AstSrc { struct ContinueExpr: AttrsOwner { T![continue], T![lifetime] } struct BreakExpr: AttrsOwner { T![break], T![lifetime], Expr } struct Label { T![lifetime] } - struct BlockExpr: AttrsOwner { Label, T![unsafe], T![async], Block } + struct BlockExpr: AttrsOwner { Label, T![unsafe], T![async], Block } struct ReturnExpr: AttrsOwner { Expr } struct CallExpr: ArgListOwner { Expr } struct MethodCallExpr: AttrsOwner, ArgListOwner { @@ -722,7 +720,6 @@ pub(crate) const AST_SRC: AstSrc = AstSrc { FieldExpr, AwaitExpr, TryExpr, - TryBlockExpr, CastExpr, RefExpr, PrefixExpr, -- cgit v1.2.3 From 3bb46042fb5b8ee421e350c54079cb68b4edc996 Mon Sep 17 00:00:00 2001 From: John Renner Date: Fri, 1 May 2020 08:59:24 -0700 Subject: Validate uses of self and super --- xtask/src/ast_src.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'xtask/src') diff --git a/xtask/src/ast_src.rs b/xtask/src/ast_src.rs index c14804aad..1abb62f6f 100644 --- a/xtask/src/ast_src.rs +++ b/xtask/src/ast_src.rs @@ -595,7 +595,7 @@ pub(crate) const AST_SRC: AstSrc = AstSrc { qualifier: Path, } struct PathSegment { - T![::], T![crate], T![<], NameRef, TypeArgList, ParamList, RetType, PathType, T![>] + T![::], T![crate], T![self], T![super], T![<], NameRef, TypeArgList, ParamList, RetType, PathType, T![>] } struct TypeArgList { T![::], -- cgit v1.2.3 From fd030f9450ed6910677e30f8fa65b06e71fcffa2 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 2 May 2020 01:12:37 +0200 Subject: Revert "Merge #4233" This reverts commit a5f2b16366f027ad60c58266a66eb7fbdcbda9f9, reversing changes made to c96b2180c1c4206a0a98c280b4d30897eb116336. --- xtask/src/ast_src.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'xtask/src') diff --git a/xtask/src/ast_src.rs b/xtask/src/ast_src.rs index 703fb9be9..1abb62f6f 100644 --- a/xtask/src/ast_src.rs +++ b/xtask/src/ast_src.rs @@ -162,6 +162,7 @@ pub(crate) const KINDS_SRC: KindsSrc = KindsSrc { "RECORD_LIT", "RECORD_FIELD_LIST", "RECORD_FIELD", + "TRY_BLOCK_EXPR", "BOX_EXPR", // postfix "CALL_EXPR", @@ -439,6 +440,7 @@ pub(crate) const AST_SRC: AstSrc = AstSrc { } struct IfExpr: AttrsOwner { T![if], Condition } struct LoopExpr: AttrsOwner, LoopBodyOwner { T![loop] } + struct TryBlockExpr: AttrsOwner { T![try], body: BlockExpr } struct ForExpr: AttrsOwner, LoopBodyOwner { T![for], Pat, @@ -449,7 +451,7 @@ pub(crate) const AST_SRC: AstSrc = AstSrc { struct ContinueExpr: AttrsOwner { T![continue], T![lifetime] } struct BreakExpr: AttrsOwner { T![break], T![lifetime], Expr } struct Label { T![lifetime] } - struct BlockExpr: AttrsOwner { Label, T![unsafe], T![async], Block } + struct BlockExpr: AttrsOwner { Label, T![unsafe], T![async], Block } struct ReturnExpr: AttrsOwner { Expr } struct CallExpr: ArgListOwner { Expr } struct MethodCallExpr: AttrsOwner, ArgListOwner { @@ -720,6 +722,7 @@ pub(crate) const AST_SRC: AstSrc = AstSrc { FieldExpr, AwaitExpr, TryExpr, + TryBlockExpr, CastExpr, RefExpr, PrefixExpr, -- cgit v1.2.3 From 4f2134cc33f07c09fe166cec42971828843bc0ef Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 2 May 2020 01:18:19 +0200 Subject: Introduce EffectExpr --- xtask/src/ast_src.rs | 19 +++++++------------ xtask/src/codegen/gen_syntax.rs | 1 + 2 files changed, 8 insertions(+), 12 deletions(-) (limited to 'xtask/src') diff --git a/xtask/src/ast_src.rs b/xtask/src/ast_src.rs index 1abb62f6f..028f7cbe1 100644 --- a/xtask/src/ast_src.rs +++ b/xtask/src/ast_src.rs @@ -162,7 +162,7 @@ pub(crate) const KINDS_SRC: KindsSrc = KindsSrc { "RECORD_LIT", "RECORD_FIELD_LIST", "RECORD_FIELD", - "TRY_BLOCK_EXPR", + "EFFECT_EXPR", "BOX_EXPR", // postfix "CALL_EXPR", @@ -177,7 +177,6 @@ pub(crate) const KINDS_SRC: KindsSrc = KindsSrc { "PREFIX_EXPR", "RANGE_EXPR", // just weird "BIN_EXPR", - "BLOCK", "EXTERN_BLOCK", "EXTERN_ITEM_LIST", "ENUM_VARIANT", @@ -440,7 +439,7 @@ pub(crate) const AST_SRC: AstSrc = AstSrc { } struct IfExpr: AttrsOwner { T![if], Condition } struct LoopExpr: AttrsOwner, LoopBodyOwner { T![loop] } - struct TryBlockExpr: AttrsOwner { T![try], body: BlockExpr } + struct EffectExpr: AttrsOwner { Label, T![try], T![unsafe], T![async], BlockExpr } struct ForExpr: AttrsOwner, LoopBodyOwner { T![for], Pat, @@ -451,7 +450,9 @@ pub(crate) const AST_SRC: AstSrc = AstSrc { struct ContinueExpr: AttrsOwner { T![continue], T![lifetime] } struct BreakExpr: AttrsOwner { T![break], T![lifetime], Expr } struct Label { T![lifetime] } - struct BlockExpr: AttrsOwner { Label, T![unsafe], T![async], Block } + struct BlockExpr: AttrsOwner, ModuleItemOwner { + T!['{'], statements: [Stmt], Expr, T!['}'], + } struct ReturnExpr: AttrsOwner { Expr } struct CallExpr: ArgListOwner { Expr } struct MethodCallExpr: AttrsOwner, ArgListOwner { @@ -460,7 +461,7 @@ pub(crate) const AST_SRC: AstSrc = AstSrc { struct IndexExpr: AttrsOwner { T!['['], T![']'] } struct FieldExpr: AttrsOwner { Expr, T![.], NameRef } struct AwaitExpr: AttrsOwner { Expr, T![.], T![await] } - struct TryExpr: AttrsOwner { T![try], Expr } + struct TryExpr: AttrsOwner { Expr, T![?] } struct CastExpr: AttrsOwner { Expr, T![as], TypeRef } struct RefExpr: AttrsOwner { T![&], T![raw], T![mut], Expr } struct PrefixExpr: AttrsOwner { /*PrefixOp,*/ Expr } @@ -556,12 +557,6 @@ pub(crate) const AST_SRC: AstSrc = AstSrc { T![;], } struct Condition { T![let], Pat, T![=], Expr } - struct Block: AttrsOwner, ModuleItemOwner { - T!['{'], - statements: [Stmt], - Expr, - T!['}'], - } struct ParamList { T!['('], SelfParam, @@ -722,7 +717,7 @@ pub(crate) const AST_SRC: AstSrc = AstSrc { FieldExpr, AwaitExpr, TryExpr, - TryBlockExpr, + EffectExpr, CastExpr, RefExpr, PrefixExpr, diff --git a/xtask/src/codegen/gen_syntax.rs b/xtask/src/codegen/gen_syntax.rs index e9dc09552..8028575c5 100644 --- a/xtask/src/codegen/gen_syntax.rs +++ b/xtask/src/codegen/gen_syntax.rs @@ -432,6 +432,7 @@ impl Field<'_> { ":" => "colon", "::" => "coloncolon", "#" => "pound", + "?" => "question_mark", _ => name, }; format_ident!("{}_token", name) -- cgit v1.2.3