Skip to content

Commit d48fa83

Browse files
committed
Only enable unix socket stuff on unix with nightly
1 parent 9768c2e commit d48fa83

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

src/lib.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
#![doc(html_root_url="https://sfackler.github.io/rust-postgres/doc/v0.11.4")]
4242
#![warn(missing_docs)]
4343
#![allow(unknown_lints, needless_lifetimes)] // for clippy
44-
#![cfg_attr(feature = "nightly", feature(unix_socket))]
44+
#![cfg_attr(all(unix, feature = "nightly"), feature(unix_socket))]
4545

4646
extern crate bufstream;
4747
extern crate byteorder;
@@ -69,7 +69,7 @@ use std::mem;
6969
use std::result;
7070
use std::sync::Arc;
7171
use std::time::Duration;
72-
#[cfg(any(feature = "unix_socket", feature = "nightly"))]
72+
#[cfg(any(feature = "unix_socket", all(unix, feature = "nightly")))]
7373
use std::path::PathBuf;
7474

7575
// FIXME remove in 0.12
@@ -117,7 +117,7 @@ pub enum ConnectTarget {
117117
/// Connect via a Unix domain socket in the specified directory.
118118
///
119119
/// Requires the `unix_socket` or `nightly` feature.
120-
#[cfg(any(feature = "unix_socket", feature = "nightly"))]
120+
#[cfg(any(feature = "unix_socket", all(unix, feature = "nightly")))]
121121
Unix(PathBuf),
122122
}
123123

@@ -174,14 +174,14 @@ impl<'a> IntoConnectParams for &'a str {
174174

175175
impl IntoConnectParams for Url {
176176
fn into_connect_params(self) -> result::Result<ConnectParams, Box<StdError + StdSync + Send>> {
177-
#[cfg(any(feature = "unix_socket", feature = "nightly"))]
177+
#[cfg(any(feature = "unix_socket", all(unix, feature = "nightly")))]
178178
fn make_unix(maybe_path: String)
179179
-> result::Result<ConnectTarget, Box<StdError + StdSync + Send>> {
180180
Ok(ConnectTarget::Unix(PathBuf::from(maybe_path)))
181181
}
182-
#[cfg(not(any(feature = "unix_socket", feature = "nightly")))]
182+
#[cfg(not(any(feature = "unix_socket", all(unix, feature = "nightly"))))]
183183
fn make_unix(_: String) -> result::Result<ConnectTarget, Box<StdError + StdSync + Send>> {
184-
Err("unix socket support requires the `unix_socket` feature".into())
184+
Err("unix socket support requires the `unix_socket` or `nightly` features".into())
185185
}
186186

187187
let Url { host, port, user, path: url::Path { mut path, query: options, .. }, .. } = self;

src/priv_io.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use std::time::Duration;
99
use bufstream::BufStream;
1010
#[cfg(feature = "unix_socket")]
1111
use unix_socket::UnixStream;
12-
#[cfg(all(not(feature = "unix_socket"), feature = "nightly"))]
12+
#[cfg(all(not(feature = "unix_socket"), all(unix, feature = "nightly")))]
1313
use std::os::unix::net::UnixStream;
1414
#[cfg(unix)]
1515
use std::os::unix::io::{AsRawFd, RawFd};
@@ -34,15 +34,15 @@ impl StreamOptions for BufStream<Box<StreamWrapper>> {
3434
fn set_read_timeout(&self, timeout: Option<Duration>) -> io::Result<()> {
3535
match self.get_ref().get_ref().0 {
3636
InternalStream::Tcp(ref s) => s.set_read_timeout(timeout),
37-
#[cfg(any(feature = "unix_socket", feature = "nightly"))]
37+
#[cfg(any(feature = "unix_socket", all(unix, feature = "nightly")))]
3838
InternalStream::Unix(ref s) => s.set_read_timeout(timeout),
3939
}
4040
}
4141

4242
fn set_nonblocking(&self, nonblock: bool) -> io::Result<()> {
4343
match self.get_ref().get_ref().0 {
4444
InternalStream::Tcp(ref s) => s.set_nonblocking(nonblock),
45-
#[cfg(any(feature = "unix_socket", feature = "nightly"))]
45+
#[cfg(any(feature = "unix_socket", all(unix, feature = "nightly")))]
4646
InternalStream::Unix(ref s) => s.set_nonblocking(nonblock),
4747
}
4848
}
@@ -58,7 +58,7 @@ impl fmt::Debug for Stream {
5858
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
5959
match self.0 {
6060
InternalStream::Tcp(ref s) => fmt::Debug::fmt(s, fmt),
61-
#[cfg(any(feature = "unix_socket", feature = "nightly"))]
61+
#[cfg(any(feature = "unix_socket", all(unix, feature = "nightly")))]
6262
InternalStream::Unix(ref s) => fmt::Debug::fmt(s, fmt),
6363
}
6464
}
@@ -95,7 +95,7 @@ impl AsRawFd for Stream {
9595
fn as_raw_fd(&self) -> RawFd {
9696
match self.0 {
9797
InternalStream::Tcp(ref s) => s.as_raw_fd(),
98-
#[cfg(any(feature = "unix_socket", feature = "nightly"))]
98+
#[cfg(any(feature = "unix_socket", all(unix, feature = "nightly")))]
9999
InternalStream::Unix(ref s) => s.as_raw_fd(),
100100
}
101101
}
@@ -113,15 +113,15 @@ impl AsRawSocket for Stream {
113113

114114
enum InternalStream {
115115
Tcp(TcpStream),
116-
#[cfg(any(feature = "unix_socket", feature = "nightly"))]
116+
#[cfg(any(feature = "unix_socket", all(unix, feature = "nightly")))]
117117
Unix(UnixStream),
118118
}
119119

120120
impl Read for InternalStream {
121121
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
122122
match *self {
123123
InternalStream::Tcp(ref mut s) => s.read(buf),
124-
#[cfg(any(feature = "unix_socket", feature = "nightly"))]
124+
#[cfg(any(feature = "unix_socket", all(unix, feature = "nightly")))]
125125
InternalStream::Unix(ref mut s) => s.read(buf),
126126
}
127127
}
@@ -131,15 +131,15 @@ impl Write for InternalStream {
131131
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
132132
match *self {
133133
InternalStream::Tcp(ref mut s) => s.write(buf),
134-
#[cfg(any(feature = "unix_socket", feature = "nightly"))]
134+
#[cfg(any(feature = "unix_socket", all(unix, feature = "nightly")))]
135135
InternalStream::Unix(ref mut s) => s.write(buf),
136136
}
137137
}
138138

139139
fn flush(&mut self) -> io::Result<()> {
140140
match *self {
141141
InternalStream::Tcp(ref mut s) => s.flush(),
142-
#[cfg(any(feature = "unix_socket", feature = "nightly"))]
142+
#[cfg(any(feature = "unix_socket", all(unix, feature = "nightly")))]
143143
InternalStream::Unix(ref mut s) => s.flush(),
144144
}
145145
}
@@ -151,7 +151,7 @@ fn open_socket(params: &ConnectParams) -> Result<InternalStream, ConnectError> {
151151
ConnectTarget::Tcp(ref host) => {
152152
Ok(try!(TcpStream::connect(&(&**host, port)).map(InternalStream::Tcp)))
153153
}
154-
#[cfg(any(feature = "unix_socket", feature = "nightly"))]
154+
#[cfg(any(feature = "unix_socket", all(unix, feature = "nightly")))]
155155
ConnectTarget::Unix(ref path) => {
156156
let path = path.join(&format!(".s.PGSQL.{}", port));
157157
Ok(try!(UnixStream::connect(&path).map(InternalStream::Unix)))
@@ -185,7 +185,7 @@ pub fn initialize_stream(params: &ConnectParams,
185185
// Postgres doesn't support SSL over unix sockets
186186
let host = match params.target {
187187
ConnectTarget::Tcp(ref host) => host,
188-
#[cfg(any(feature = "unix_socket", feature = "nightly"))]
188+
#[cfg(any(feature = "unix_socket", all(unix, feature = "nightly")))]
189189
ConnectTarget::Unix(_) => return Err(ConnectError::Io(::bad_response())),
190190
};
191191

tests/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ fn test_connection_finish() {
7575
}
7676

7777
#[test]
78-
#[cfg_attr(not(any(feature = "unix_socket", feature = "nightly")), ignore)]
78+
#[cfg_attr(not(any(feature = "unix_socket", all(unix, feature = "nightly"))), ignore)]
7979
fn test_unix_connection() {
8080
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", SslMode::None));
8181
let stmt = or_panic!(conn.prepare("SHOW unix_socket_directories"));

0 commit comments

Comments
 (0)