diff --git a/src/lib.rs b/src/lib.rs index 0bb32d07..ffd268af 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -41,7 +41,7 @@ #![doc(html_root_url="https://sfackler.github.io/rust-postgres/doc/v0.11.4")] #![warn(missing_docs)] #![allow(unknown_lints, needless_lifetimes)] // for clippy -#![cfg_attr(feature = "nightly", feature(unix_socket))] +#![cfg_attr(all(unix, feature = "nightly"), feature(unix_socket))] extern crate bufstream; extern crate byteorder; @@ -69,7 +69,7 @@ use std::mem; use std::result; use std::sync::Arc; use std::time::Duration; -#[cfg(any(feature = "unix_socket", feature = "nightly"))] +#[cfg(any(feature = "unix_socket", all(unix, feature = "nightly")))] use std::path::PathBuf; // FIXME remove in 0.12 @@ -117,7 +117,7 @@ pub enum ConnectTarget { /// Connect via a Unix domain socket in the specified directory. /// /// Requires the `unix_socket` or `nightly` feature. - #[cfg(any(feature = "unix_socket", feature = "nightly"))] + #[cfg(any(feature = "unix_socket", all(unix, feature = "nightly")))] Unix(PathBuf), } @@ -174,14 +174,14 @@ impl<'a> IntoConnectParams for &'a str { impl IntoConnectParams for Url { fn into_connect_params(self) -> result::Result> { - #[cfg(any(feature = "unix_socket", feature = "nightly"))] + #[cfg(any(feature = "unix_socket", all(unix, feature = "nightly")))] fn make_unix(maybe_path: String) -> result::Result> { Ok(ConnectTarget::Unix(PathBuf::from(maybe_path))) } - #[cfg(not(any(feature = "unix_socket", feature = "nightly")))] + #[cfg(not(any(feature = "unix_socket", all(unix, feature = "nightly"))))] fn make_unix(_: String) -> result::Result> { - Err("unix socket support requires the `unix_socket` feature".into()) + Err("unix socket support requires the `unix_socket` or `nightly` features".into()) } let Url { host, port, user, path: url::Path { mut path, query: options, .. }, .. } = self; diff --git a/src/priv_io.rs b/src/priv_io.rs index 5cc77f90..154e3baf 100644 --- a/src/priv_io.rs +++ b/src/priv_io.rs @@ -9,7 +9,7 @@ use std::time::Duration; use bufstream::BufStream; #[cfg(feature = "unix_socket")] use unix_socket::UnixStream; -#[cfg(all(not(feature = "unix_socket"), feature = "nightly"))] +#[cfg(all(not(feature = "unix_socket"), all(unix, feature = "nightly")))] use std::os::unix::net::UnixStream; #[cfg(unix)] use std::os::unix::io::{AsRawFd, RawFd}; @@ -34,7 +34,7 @@ impl StreamOptions for BufStream> { fn set_read_timeout(&self, timeout: Option) -> io::Result<()> { match self.get_ref().get_ref().0 { InternalStream::Tcp(ref s) => s.set_read_timeout(timeout), - #[cfg(any(feature = "unix_socket", feature = "nightly"))] + #[cfg(any(feature = "unix_socket", all(unix, feature = "nightly")))] InternalStream::Unix(ref s) => s.set_read_timeout(timeout), } } @@ -42,7 +42,7 @@ impl StreamOptions for BufStream> { fn set_nonblocking(&self, nonblock: bool) -> io::Result<()> { match self.get_ref().get_ref().0 { InternalStream::Tcp(ref s) => s.set_nonblocking(nonblock), - #[cfg(any(feature = "unix_socket", feature = "nightly"))] + #[cfg(any(feature = "unix_socket", all(unix, feature = "nightly")))] InternalStream::Unix(ref s) => s.set_nonblocking(nonblock), } } @@ -58,7 +58,7 @@ impl fmt::Debug for Stream { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { match self.0 { InternalStream::Tcp(ref s) => fmt::Debug::fmt(s, fmt), - #[cfg(any(feature = "unix_socket", feature = "nightly"))] + #[cfg(any(feature = "unix_socket", all(unix, feature = "nightly")))] InternalStream::Unix(ref s) => fmt::Debug::fmt(s, fmt), } } @@ -95,7 +95,7 @@ impl AsRawFd for Stream { fn as_raw_fd(&self) -> RawFd { match self.0 { InternalStream::Tcp(ref s) => s.as_raw_fd(), - #[cfg(any(feature = "unix_socket", feature = "nightly"))] + #[cfg(any(feature = "unix_socket", all(unix, feature = "nightly")))] InternalStream::Unix(ref s) => s.as_raw_fd(), } } @@ -113,7 +113,7 @@ impl AsRawSocket for Stream { enum InternalStream { Tcp(TcpStream), - #[cfg(any(feature = "unix_socket", feature = "nightly"))] + #[cfg(any(feature = "unix_socket", all(unix, feature = "nightly")))] Unix(UnixStream), } @@ -121,7 +121,7 @@ impl Read for InternalStream { fn read(&mut self, buf: &mut [u8]) -> io::Result { match *self { InternalStream::Tcp(ref mut s) => s.read(buf), - #[cfg(any(feature = "unix_socket", feature = "nightly"))] + #[cfg(any(feature = "unix_socket", all(unix, feature = "nightly")))] InternalStream::Unix(ref mut s) => s.read(buf), } } @@ -131,7 +131,7 @@ impl Write for InternalStream { fn write(&mut self, buf: &[u8]) -> io::Result { match *self { InternalStream::Tcp(ref mut s) => s.write(buf), - #[cfg(any(feature = "unix_socket", feature = "nightly"))] + #[cfg(any(feature = "unix_socket", all(unix, feature = "nightly")))] InternalStream::Unix(ref mut s) => s.write(buf), } } @@ -139,7 +139,7 @@ impl Write for InternalStream { fn flush(&mut self) -> io::Result<()> { match *self { InternalStream::Tcp(ref mut s) => s.flush(), - #[cfg(any(feature = "unix_socket", feature = "nightly"))] + #[cfg(any(feature = "unix_socket", all(unix, feature = "nightly")))] InternalStream::Unix(ref mut s) => s.flush(), } } @@ -151,7 +151,7 @@ fn open_socket(params: &ConnectParams) -> Result { ConnectTarget::Tcp(ref host) => { Ok(try!(TcpStream::connect(&(&**host, port)).map(InternalStream::Tcp))) } - #[cfg(any(feature = "unix_socket", feature = "nightly"))] + #[cfg(any(feature = "unix_socket", all(unix, feature = "nightly")))] ConnectTarget::Unix(ref path) => { let path = path.join(&format!(".s.PGSQL.{}", port)); Ok(try!(UnixStream::connect(&path).map(InternalStream::Unix))) @@ -185,7 +185,7 @@ pub fn initialize_stream(params: &ConnectParams, // Postgres doesn't support SSL over unix sockets let host = match params.target { ConnectTarget::Tcp(ref host) => host, - #[cfg(any(feature = "unix_socket", feature = "nightly"))] + #[cfg(any(feature = "unix_socket", all(unix, feature = "nightly")))] ConnectTarget::Unix(_) => return Err(ConnectError::Io(::bad_response())), }; diff --git a/tests/test.rs b/tests/test.rs index 6442af6d..ede7438d 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -75,7 +75,7 @@ fn test_connection_finish() { } #[test] -#[cfg_attr(not(any(feature = "unix_socket", feature = "nightly")), ignore)] +#[cfg_attr(not(any(feature = "unix_socket", all(unix, feature = "nightly"))), ignore)] fn test_unix_connection() { let conn = or_panic!(Connection::connect("postgres://postgres@localhost", SslMode::None)); let stmt = or_panic!(conn.prepare("SHOW unix_socket_directories"));