diff --git a/contrib/examples/fix.hgrc b/contrib/examples/fix.hgrc --- a/contrib/examples/fix.hgrc +++ b/contrib/examples/fix.hgrc @@ -3,7 +3,7 @@ clang-format:pattern = set:(**.c or **.cc or **.h) and not "include:contrib/clang-format-ignorelist" rustfmt:command = rustfmt +nightly -rustfmt:pattern = set:**.rs +rustfmt:pattern = set:"**.rs" - "mercurial/thirdparty/**" black:command = black --config=black.toml - black:pattern = set:**.py - mercurial/thirdparty/** diff --git a/rust/chg/src/clientext.rs b/rust/chg/src/clientext.rs --- a/rust/chg/src/clientext.rs +++ b/rust/chg/src/clientext.rs @@ -43,11 +43,20 @@ stdout: &impl AsRawFd, stderr: &impl AsRawFd, ) -> io::Result<()> { - attachio::attach_io(self.client.borrow_protocol_mut(), stdin, stdout, stderr).await + attachio::attach_io( + self.client.borrow_protocol_mut(), + stdin, + stdout, + stderr, + ) + .await } /// Changes the working directory of the server. - pub async fn set_current_dir(&mut self, dir: impl AsRef) -> io::Result<()> { + pub async fn set_current_dir( + &mut self, + dir: impl AsRef, + ) -> io::Result<()> { let dir_bytes = dir.as_ref().as_os_str().as_bytes().to_owned(); self.client .borrow_protocol_mut() @@ -67,7 +76,10 @@ } /// Changes the process title of the server. - pub async fn set_process_name(&mut self, name: impl AsRef) -> io::Result<()> { + pub async fn set_process_name( + &mut self, + name: impl AsRef, + ) -> io::Result<()> { let name_bytes = name.as_ref().as_bytes().to_owned(); self.client .borrow_protocol_mut() diff --git a/rust/chg/src/locator.rs b/rust/chg/src/locator.rs --- a/rust/chg/src/locator.rs +++ b/rust/chg/src/locator.rs @@ -71,8 +71,12 @@ } /// Specifies the arguments to be passed to the server at start. - pub fn set_early_args(&mut self, args: impl IntoIterator>) { - self.hg_early_args = args.into_iter().map(|a| a.as_ref().to_owned()).collect(); + pub fn set_early_args( + &mut self, + args: impl IntoIterator>, + ) { + self.hg_early_args = + args.into_iter().map(|a| a.as_ref().to_owned()).collect(); } /// Connects to the server. @@ -104,7 +108,10 @@ /// Runs instructions received from the server. /// /// Returns true if the client should try connecting to the other server. - fn run_instructions(&mut self, instructions: &[Instruction]) -> io::Result { + fn run_instructions( + &mut self, + instructions: &[Instruction], + ) -> io::Result { let mut reconnect = false; for inst in instructions { debug!("instruction: {:?}", inst); @@ -123,7 +130,10 @@ "insecure redirect instruction from server: {}", path.display() ); - return Err(io::Error::new(io::ErrorKind::InvalidData, msg)); + return Err(io::Error::new( + io::ErrorKind::InvalidData, + msg, + )); } self.redirect_sock_path = Some(path.to_owned()); reconnect = true; @@ -134,7 +144,10 @@ "insecure unlink instruction from server: {}", path.display() ); - return Err(io::Error::new(io::ErrorKind::InvalidData, msg)); + return Err(io::Error::new( + io::ErrorKind::InvalidData, + msg, + )); } fs::remove_file(path).unwrap_or(()); // may race } @@ -319,7 +332,10 @@ P: AsRef, { let a = fs::symlink_metadata(path.as_ref())?; - if a.is_dir() && a.uid() == procutil::get_effective_uid() && (a.mode() & 0o777) == 0o700 { + if a.is_dir() + && a.uid() == procutil::get_effective_uid() + && (a.mode() & 0o777) == 0o700 + { Ok(path) } else { Err(io::Error::new(io::ErrorKind::Other, "insecure directory")) @@ -344,7 +360,9 @@ } /// Collects arguments which need to be passed to the server at start. -pub fn collect_early_args(args: impl IntoIterator>) -> Vec { +pub fn collect_early_args( + args: impl IntoIterator>, +) -> Vec { let mut args_iter = args.into_iter(); let mut early_args = Vec::new(); while let Some(arg) = args_iter.next() { diff --git a/rust/chg/src/message.rs b/rust/chg/src/message.rs --- a/rust/chg/src/message.rs +++ b/rust/chg/src/message.rs @@ -32,11 +32,16 @@ } /// Parses "S" channel request into command type and spec. -pub fn parse_command_spec(data: Bytes) -> io::Result<(CommandType, CommandSpec)> { +pub fn parse_command_spec( + data: Bytes, +) -> io::Result<(CommandType, CommandSpec)> { let mut split = data.split(|&c| c == b'\0'); - let ctype = parse_command_type(split.next().ok_or(new_parse_error("missing type"))?)?; + let ctype = parse_command_type( + split.next().ok_or(new_parse_error("missing type"))?, + )?; let command = split.next().ok_or(new_parse_error("missing command"))?; - let current_dir = split.next().ok_or(new_parse_error("missing current dir"))?; + let current_dir = + split.next().ok_or(new_parse_error("missing current dir"))?; let mut envs = Vec::new(); for l in split { @@ -89,14 +94,21 @@ (b"exit", Some(arg)) => decode_latin1(arg) .parse() .map(Instruction::Exit) - .map_err(|_| new_parse_error(format!("invalid exit code: {:?}", arg)))?, + .map_err(|_| { + new_parse_error(format!("invalid exit code: {:?}", arg)) + })?, (b"reconnect", None) => Instruction::Reconnect, (b"redirect", Some(arg)) => { Instruction::Redirect(OsStr::from_bytes(arg).to_owned().into()) } - (b"unlink", Some(arg)) => Instruction::Unlink(OsStr::from_bytes(arg).to_owned().into()), + (b"unlink", Some(arg)) => { + Instruction::Unlink(OsStr::from_bytes(arg).to_owned().into()) + } _ => { - return Err(new_parse_error(format!("unknown command: {:?}", l))); + return Err(new_parse_error(format!( + "unknown command: {:?}", + l + ))); } }; instructions.push(inst); @@ -118,7 +130,8 @@ ) -> Bytes { let mut vars_iter = vars.into_iter(); if let Some((k, v)) = vars_iter.next() { - let mut dst = BytesMut::with_capacity(INITIAL_PACKED_ENV_VARS_CAPACITY); + let mut dst = + BytesMut::with_capacity(INITIAL_PACKED_ENV_VARS_CAPACITY); pack_env_into(&mut dst, k.as_ref(), v.as_ref()); for (k, v) in vars_iter { dst.reserve(1); @@ -145,7 +158,9 @@ s.as_ref().iter().map(|&c| c as char).collect() } -fn new_parse_error(error: impl Into>) -> io::Error { +fn new_parse_error( + error: impl Into>, +) -> io::Error { io::Error::new(io::ErrorKind::InvalidData, error) } @@ -183,17 +198,24 @@ fn parse_command_spec_too_short() { assert!(parse_command_spec(Bytes::from_static(b"")).is_err()); assert!(parse_command_spec(Bytes::from_static(b"pager")).is_err()); - assert!(parse_command_spec(Bytes::from_static(b"pager\0less")).is_err()); + assert!( + parse_command_spec(Bytes::from_static(b"pager\0less")).is_err() + ); } #[test] fn parse_command_spec_malformed_env() { - assert!(parse_command_spec(Bytes::from_static(b"pager\0less\0/tmp\0HOME")).is_err()); + assert!(parse_command_spec(Bytes::from_static( + b"pager\0less\0/tmp\0HOME" + )) + .is_err()); } #[test] fn parse_command_spec_unknown_type() { - assert!(parse_command_spec(Bytes::from_static(b"paper\0less")).is_err()); + assert!( + parse_command_spec(Bytes::from_static(b"paper\0less")).is_err() + ); } #[test] diff --git a/rust/chg/src/procutil.rs b/rust/chg/src/procutil.rs --- a/rust/chg/src/procutil.rs +++ b/rust/chg/src/procutil.rs @@ -44,7 +44,8 @@ if flags < 0 { return Err(io::Error::last_os_error()); } - let r = unsafe { libc::fcntl(fd, libc::F_SETFL, flags & !libc::O_NONBLOCK) }; + let r = + unsafe { libc::fcntl(fd, libc::F_SETFL, flags & !libc::O_NONBLOCK) }; if r < 0 { return Err(io::Error::last_os_error()); } @@ -69,7 +70,10 @@ /// /// This touches global states, and thus synchronized as a one-time /// initialization function. -pub fn setup_signal_handler_once(pid: u32, pgid: Option) -> io::Result<()> { +pub fn setup_signal_handler_once( + pid: u32, + pgid: Option, +) -> io::Result<()> { let pid_signed = pid as i32; let pgid_signed = pgid.map(|n| n as i32).unwrap_or(0); let mut r = 0; diff --git a/rust/chg/src/runcommand.rs b/rust/chg/src/runcommand.rs --- a/rust/chg/src/runcommand.rs +++ b/rust/chg/src/runcommand.rs @@ -36,7 +36,8 @@ ChannelMessage::Data(..) => { // just ignores data sent to optional channel } - ChannelMessage::InputRequest(..) | ChannelMessage::LineRequest(..) => { + ChannelMessage::InputRequest(..) + | ChannelMessage::LineRequest(..) => { return Err(io::Error::new( io::ErrorKind::InvalidData, "unsupported request", @@ -49,7 +50,8 @@ // server spins new command loop while pager request is // in progress, which can be terminated by "" command. let pin = handler.spawn_pager(&cmd_spec).await?; - attachio::attach_io(proto, &io::stdin(), &pin, &pin).await?; + attachio::attach_io(proto, &io::stdin(), &pin, &pin) + .await?; proto.send_command("").await?; // terminator } CommandType::System => { diff --git a/rust/chg/src/uihandler.rs b/rust/chg/src/uihandler.rs --- a/rust/chg/src/uihandler.rs +++ b/rust/chg/src/uihandler.rs @@ -22,7 +22,10 @@ /// Handles pager command request. /// /// Returns the pipe to be attached to the server if the pager is spawned. - async fn spawn_pager(&mut self, spec: &CommandSpec) -> io::Result; + async fn spawn_pager( + &mut self, + spec: &CommandSpec, + ) -> io::Result; /// Handles system command request. /// @@ -53,8 +56,12 @@ impl SystemHandler for ChgUiHandler { type PagerStdin = ChildStdin; - async fn spawn_pager(&mut self, spec: &CommandSpec) -> io::Result { - let mut pager = new_shell_command(&spec).stdin(Stdio::piped()).spawn()?; + async fn spawn_pager( + &mut self, + spec: &CommandSpec, + ) -> io::Result { + let mut pager = + new_shell_command(&spec).stdin(Stdio::piped()).spawn()?; let pin = pager.stdin.take().unwrap(); procutil::set_blocking_fd(pin.as_raw_fd())?; // TODO: if pager exits, notify the server with SIGPIPE immediately. diff --git a/rust/hg-cpython/rustfmt.toml b/rust/hg-cpython/rustfmt.toml deleted file mode 100644 --- a/rust/hg-cpython/rustfmt.toml +++ /dev/null @@ -1,3 +0,0 @@ -max_width = 79 -wrap_comments = true -error_on_line_overflow = true diff --git a/rust/hgcli/build.rs b/rust/hgcli/build.rs --- a/rust/hgcli/build.rs +++ b/rust/hgcli/build.rs @@ -5,7 +5,9 @@ /*! Build script to integrate PyOxidizer. */ fn main() { - if let Ok(config_rs) = std::env::var("DEP_PYTHONXY_DEFAULT_PYTHON_CONFIG_RS") { + if let Ok(config_rs) = + std::env::var("DEP_PYTHONXY_DEFAULT_PYTHON_CONFIG_RS") + { println!( "cargo:rustc-env=PYOXIDIZER_DEFAULT_PYTHON_CONFIG_RS={}", config_rs diff --git a/rust/hgcli/src/main.rs b/rust/hgcli/src/main.rs --- a/rust/hgcli/src/main.rs +++ b/rust/hgcli/src/main.rs @@ -9,21 +9,22 @@ include!(env!("PYOXIDIZER_DEFAULT_PYTHON_CONFIG_RS")); fn main() { - // The following code is in a block so the MainPythonInterpreter is destroyed in an - // orderly manner, before process exit. + // The following code is in a block so the MainPythonInterpreter is + // destroyed in an orderly manner, before process exit. let code = { - // Load the default Python configuration as derived by the PyOxidizer config - // file used at build time. + // Load the default Python configuration as derived by the PyOxidizer + // config file used at build time. let config = default_python_config(); - // Construct a new Python interpreter using that config, handling any errors - // from construction. + // Construct a new Python interpreter using that config, handling any + // errors from construction. match MainPythonInterpreter::new(config) { Ok(mut interp) => { - // And run it using the default run configuration as specified by the - // configuration. If an uncaught Python exception is raised, handle it. - // This includes the special SystemExit, which is a request to terminate the - // process. + // And run it using the default run configuration as specified + // by the configuration. If an uncaught Python + // exception is raised, handle it. + // This includes the special SystemExit, which is a request to + // terminate the process. interp.run_as_main() } Err(msg) => { diff --git a/rust/rhg/rustfmt.toml b/rust/rhg/rustfmt.toml deleted file mode 100644 --- a/rust/rhg/rustfmt.toml +++ /dev/null @@ -1,3 +0,0 @@ -max_width = 79 -wrap_comments = true -error_on_line_overflow = true diff --git a/rust/hg-core/rustfmt.toml b/rustfmt.toml rename from rust/hg-core/rustfmt.toml rename to rustfmt.toml --- a/rust/hg-core/rustfmt.toml +++ b/rustfmt.toml @@ -1,3 +1,4 @@ +edition = "2018" max_width = 79 wrap_comments = true error_on_line_overflow = true diff --git a/tests/test-check-code.t b/tests/test-check-code.t --- a/tests/test-check-code.t +++ b/tests/test-check-code.t @@ -69,6 +69,7 @@ hg hgeditor hgweb.cgi + rustfmt.toml setup.py Prevent adding modules which could be shadowed by ancient .so/.dylib.