From 8f158bc62bbe05e99927f4e86c1c38182d187c1e Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Tue, 12 Nov 2019 22:07:39 +0100 Subject: [PATCH 01/16] Replace .unwrap() with ? in std::os::unix::net --- src/libstd/sys/unix/ext/mod.rs | 2 +- src/libstd/sys/unix/ext/net.rs | 384 ++++++++++++++++++++------------- 2 files changed, 237 insertions(+), 149 deletions(-) diff --git a/src/libstd/sys/unix/ext/mod.rs b/src/libstd/sys/unix/ext/mod.rs index ccbac1a3e4b59..8039dcd2208cb 100644 --- a/src/libstd/sys/unix/ext/mod.rs +++ b/src/libstd/sys/unix/ext/mod.rs @@ -16,7 +16,7 @@ //! use std::os::unix::prelude::*; //! //! fn main() { -//! let f = File::create("foo.txt").unwrap(); +//! let f = File::create("foo.txt")?; //! let fd = f.as_raw_fd(); //! //! // use fd with native unix bindings diff --git a/src/libstd/sys/unix/ext/net.rs b/src/libstd/sys/unix/ext/net.rs index 42edd5dbbea7c..cfa157c66d102 100644 --- a/src/libstd/sys/unix/ext/net.rs +++ b/src/libstd/sys/unix/ext/net.rs @@ -142,9 +142,11 @@ impl SocketAddr { /// ```no_run /// use std::os::unix::net::UnixListener; /// - /// let socket = UnixListener::bind("/tmp/sock").unwrap(); - /// let addr = socket.local_addr().expect("Couldn't get local address"); - /// assert_eq!(addr.is_unnamed(), false); + /// fn main() -> std::io::Result<()> { + /// let socket = UnixListener::bind("/tmp/sock")?; + /// let addr = socket.local_addr().expect("Couldn't get local address"); + /// assert_eq!(addr.is_unnamed(), false); + /// } /// ``` /// /// An unnamed address: @@ -152,9 +154,11 @@ impl SocketAddr { /// ``` /// use std::os::unix::net::UnixDatagram; /// - /// let socket = UnixDatagram::unbound().unwrap(); - /// let addr = socket.local_addr().expect("Couldn't get local address"); - /// assert_eq!(addr.is_unnamed(), true); + /// fn main() -> std::io::Result<()> { + /// let socket = UnixDatagram::unbound()?; + /// let addr = socket.local_addr().expect("Couldn't get local address"); + /// assert_eq!(addr.is_unnamed(), true); + /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] pub fn is_unnamed(&self) -> bool { @@ -175,9 +179,11 @@ impl SocketAddr { /// use std::os::unix::net::UnixListener; /// use std::path::Path; /// - /// let socket = UnixListener::bind("/tmp/sock").unwrap(); - /// let addr = socket.local_addr().expect("Couldn't get local address"); - /// assert_eq!(addr.as_pathname(), Some(Path::new("/tmp/sock"))); + /// fn main() -> std::io::Result<()> { + /// let socket = UnixListener::bind("/tmp/sock")?; + /// let addr = socket.local_addr().expect("Couldn't get local address"); + /// assert_eq!(addr.as_pathname(), Some(Path::new("/tmp/sock"))); + /// } /// ``` /// /// Without a pathname: @@ -185,9 +191,11 @@ impl SocketAddr { /// ``` /// use std::os::unix::net::UnixDatagram; /// - /// let socket = UnixDatagram::unbound().unwrap(); - /// let addr = socket.local_addr().expect("Couldn't get local address"); - /// assert_eq!(addr.as_pathname(), None); + /// fn main() -> std::io::Result<()> { + /// let socket = UnixDatagram::unbound()?; + /// let addr = socket.local_addr().expect("Couldn't get local address"); + /// assert_eq!(addr.as_pathname(), None); + /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] pub fn as_pathname(&self) -> Option<&Path> { @@ -247,11 +255,13 @@ impl<'a> fmt::Display for AsciiEscaped<'a> { /// use std::os::unix::net::UnixStream; /// use std::io::prelude::*; /// -/// let mut stream = UnixStream::connect("/path/to/my/socket").unwrap(); -/// stream.write_all(b"hello world").unwrap(); -/// let mut response = String::new(); -/// stream.read_to_string(&mut response).unwrap(); -/// println!("{}", response); +/// fn main() -> std::io::Result<()> { +/// let mut stream = UnixStream::connect("/path/to/my/socket")?; +/// stream.write_all(b"hello world")?; +/// let mut response = String::new(); +/// stream.read_to_string(&mut response)?; +/// println!("{}", response); +/// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] pub struct UnixStream(Socket); @@ -336,8 +346,10 @@ impl UnixStream { /// ```no_run /// use std::os::unix::net::UnixStream; /// - /// let socket = UnixStream::connect("/tmp/sock").unwrap(); - /// let sock_copy = socket.try_clone().expect("Couldn't clone socket"); + /// fn main() -> std::io::Result<()> { + /// let socket = UnixStream::connect("/tmp/sock")?; + /// let sock_copy = socket.try_clone().expect("Couldn't clone socket"); + /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] pub fn try_clone(&self) -> io::Result { @@ -351,8 +363,10 @@ impl UnixStream { /// ```no_run /// use std::os::unix::net::UnixStream; /// - /// let socket = UnixStream::connect("/tmp/sock").unwrap(); - /// let addr = socket.local_addr().expect("Couldn't get local address"); + /// fn main() -> std::io::Result<()> { + /// let socket = UnixStream::connect("/tmp/sock")?; + /// let addr = socket.local_addr().expect("Couldn't get local address"); + /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] pub fn local_addr(&self) -> io::Result { @@ -366,8 +380,10 @@ impl UnixStream { /// ```no_run /// use std::os::unix::net::UnixStream; /// - /// let socket = UnixStream::connect("/tmp/sock").unwrap(); - /// let addr = socket.peer_addr().expect("Couldn't get peer address"); + /// fn main() -> std::io::Result<()> { + /// let socket = UnixStream::connect("/tmp/sock")?; + /// let addr = socket.peer_addr().expect("Couldn't get peer address"); + /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] pub fn peer_addr(&self) -> io::Result { @@ -391,7 +407,7 @@ impl UnixStream { /// use std::os::unix::net::UnixStream; /// use std::time::Duration; /// - /// let socket = UnixStream::connect("/tmp/sock").unwrap(); + /// let socket = UnixStream::connect("/tmp/sock")?; /// socket.set_read_timeout(Some(Duration::new(1, 0))).expect("Couldn't set read timeout"); /// ``` /// @@ -403,10 +419,12 @@ impl UnixStream { /// use std::os::unix::net::UnixStream; /// use std::time::Duration; /// - /// let socket = UnixStream::connect("/tmp/sock").unwrap(); - /// let result = socket.set_read_timeout(Some(Duration::new(0, 0))); - /// let err = result.unwrap_err(); - /// assert_eq!(err.kind(), io::ErrorKind::InvalidInput) + /// fn main() -> std::io::Result<()> { + /// let socket = UnixStream::connect("/tmp/sock")?; + /// let result = socket.set_read_timeout(Some(Duration::new(0, 0))); + /// let err = result.unwrap_err(); + /// assert_eq!(err.kind(), io::ErrorKind::InvalidInput) + /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] pub fn set_read_timeout(&self, timeout: Option) -> io::Result<()> { @@ -430,8 +448,11 @@ impl UnixStream { /// use std::os::unix::net::UnixStream; /// use std::time::Duration; /// - /// let socket = UnixStream::connect("/tmp/sock").unwrap(); - /// socket.set_write_timeout(Some(Duration::new(1, 0))).expect("Couldn't set write timeout"); + /// fn main() -> std::io::Result<()> { + /// let socket = UnixStream::connect("/tmp/sock")?; + /// socket.set_write_timeout(Some(Duration::new(1, 0))) + /// .expect("Couldn't set write timeout"); + /// } /// ``` /// /// An [`Err`] is returned if the zero [`Duration`] is passed to this @@ -442,10 +463,12 @@ impl UnixStream { /// use std::net::UdpSocket; /// use std::time::Duration; /// - /// let socket = UdpSocket::bind("127.0.0.1:34254").unwrap(); - /// let result = socket.set_write_timeout(Some(Duration::new(0, 0))); - /// let err = result.unwrap_err(); - /// assert_eq!(err.kind(), io::ErrorKind::InvalidInput) + /// fn main() -> std::io::Result<()> { + /// let socket = UdpSocket::bind("127.0.0.1:34254")?; + /// let result = socket.set_write_timeout(Some(Duration::new(0, 0))); + /// let err = result.unwrap_err(); + /// assert_eq!(err.kind(), io::ErrorKind::InvalidInput) + /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] pub fn set_write_timeout(&self, timeout: Option) -> io::Result<()> { @@ -460,9 +483,11 @@ impl UnixStream { /// use std::os::unix::net::UnixStream; /// use std::time::Duration; /// - /// let socket = UnixStream::connect("/tmp/sock").unwrap(); - /// socket.set_read_timeout(Some(Duration::new(1, 0))).expect("Couldn't set read timeout"); - /// assert_eq!(socket.read_timeout().unwrap(), Some(Duration::new(1, 0))); + /// fn main() -> std::io::Result<()> { + /// let socket = UnixStream::connect("/tmp/sock")?; + /// socket.set_read_timeout(Some(Duration::new(1, 0))).expect("Couldn't set read timeout"); + /// assert_eq!(socket.read_timeout()?, Some(Duration::new(1, 0))); + /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] pub fn read_timeout(&self) -> io::Result> { @@ -477,9 +502,12 @@ impl UnixStream { /// use std::os::unix::net::UnixStream; /// use std::time::Duration; /// - /// let socket = UnixStream::connect("/tmp/sock").unwrap(); - /// socket.set_write_timeout(Some(Duration::new(1, 0))).expect("Couldn't set write timeout"); - /// assert_eq!(socket.write_timeout().unwrap(), Some(Duration::new(1, 0))); + /// fn main() -> std::io::Result<()> { + /// let socket = UnixStream::connect("/tmp/sock")?; + /// socket.set_write_timeout(Some(Duration::new(1, 0))) + /// .expect("Couldn't set write timeout"); + /// assert_eq!(socket.write_timeout()?, Some(Duration::new(1, 0))); + /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] pub fn write_timeout(&self) -> io::Result> { @@ -493,8 +521,10 @@ impl UnixStream { /// ```no_run /// use std::os::unix::net::UnixStream; /// - /// let socket = UnixStream::connect("/tmp/sock").unwrap(); - /// socket.set_nonblocking(true).expect("Couldn't set nonblocking"); + /// fn main() -> std::io::Result<()> { + /// let socket = UnixStream::connect("/tmp/sock")?; + /// socket.set_nonblocking(true).expect("Couldn't set nonblocking"); + /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] pub fn set_nonblocking(&self, nonblocking: bool) -> io::Result<()> { @@ -508,9 +538,11 @@ impl UnixStream { /// ```no_run /// use std::os::unix::net::UnixStream; /// - /// let socket = UnixStream::connect("/tmp/sock").unwrap(); - /// if let Ok(Some(err)) = socket.take_error() { - /// println!("Got error: {:?}", err); + /// fn main() -> std::io::Result<()> { + /// let socket = UnixStream::connect("/tmp/sock")?; + /// if let Ok(Some(err)) = socket.take_error() { + /// println!("Got error: {:?}", err); + /// } /// } /// ``` /// @@ -535,8 +567,10 @@ impl UnixStream { /// use std::os::unix::net::UnixStream; /// use std::net::Shutdown; /// - /// let socket = UnixStream::connect("/tmp/sock").unwrap(); - /// socket.shutdown(Shutdown::Both).expect("shutdown function failed"); + /// fn main() -> std::io::Result<()> { + /// let socket = UnixStream::connect("/tmp/sock"); + /// socket.shutdown(Shutdown::Both).expect("shutdown function failed"); + /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] pub fn shutdown(&self, how: Shutdown) -> io::Result<()> { @@ -697,18 +731,20 @@ impl IntoRawFd for net::UdpSocket { /// // ... /// } /// -/// let listener = UnixListener::bind("/path/to/the/socket").unwrap(); +/// fn main() -> std::io::Result<()> { +/// let listener = UnixListener::bind("/path/to/the/socket")?; /// -/// // accept connections and process them, spawning a new thread for each one -/// for stream in listener.incoming() { -/// match stream { -/// Ok(stream) => { -/// /* connection succeeded */ -/// thread::spawn(|| handle_client(stream)); -/// } -/// Err(err) => { -/// /* connection failed */ -/// break; +/// // accept connections and process them, spawning a new thread for each one +/// for stream in listener.incoming() { +/// match stream { +/// Ok(stream) => { +/// /* connection succeeded */ +/// thread::spawn(|| handle_client(stream)); +/// } +/// Err(err) => { +/// /* connection failed */ +/// break; +/// } /// } /// } /// } @@ -773,11 +809,13 @@ impl UnixListener { /// ```no_run /// use std::os::unix::net::UnixListener; /// - /// let listener = UnixListener::bind("/path/to/the/socket").unwrap(); + /// fn main() -> std::io::Result<()> { + /// let listener = UnixListener::bind("/path/to/the/socket")?; /// - /// match listener.accept() { - /// Ok((socket, addr)) => println!("Got a client: {:?}", addr), - /// Err(e) => println!("accept function failed: {:?}", e), + /// match listener.accept() { + /// Ok((socket, addr)) => println!("Got a client: {:?}", addr), + /// Err(e) => println!("accept function failed: {:?}", e), + /// } /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] @@ -800,9 +838,11 @@ impl UnixListener { /// ```no_run /// use std::os::unix::net::UnixListener; /// - /// let listener = UnixListener::bind("/path/to/the/socket").unwrap(); + /// fn main() -> std::io::Result<()> { + /// let listener = UnixListener::bind("/path/to/the/socket")?; /// - /// let listener_copy = listener.try_clone().expect("try_clone failed"); + /// let listener_copy = listener.try_clone().expect("try_clone failed"); + /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] pub fn try_clone(&self) -> io::Result { @@ -816,9 +856,11 @@ impl UnixListener { /// ```no_run /// use std::os::unix::net::UnixListener; /// - /// let listener = UnixListener::bind("/path/to/the/socket").unwrap(); + /// fn main() -> std::io::Result<()> { + /// let listener = UnixListener::bind("/path/to/the/socket")?; /// - /// let addr = listener.local_addr().expect("Couldn't get local address"); + /// let addr = listener.local_addr().expect("Couldn't get local address"); + /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] pub fn local_addr(&self) -> io::Result { @@ -832,9 +874,11 @@ impl UnixListener { /// ```no_run /// use std::os::unix::net::UnixListener; /// - /// let listener = UnixListener::bind("/path/to/the/socket").unwrap(); + /// fn main() -> std::io::Result<()> { + /// let listener = UnixListener::bind("/path/to/the/socket")?; /// - /// listener.set_nonblocking(true).expect("Couldn't set non blocking"); + /// listener.set_nonblocking(true).expect("Couldn't set non blocking"); + /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] pub fn set_nonblocking(&self, nonblocking: bool) -> io::Result<()> { @@ -848,10 +892,12 @@ impl UnixListener { /// ```no_run /// use std::os::unix::net::UnixListener; /// - /// let listener = UnixListener::bind("/tmp/sock").unwrap(); + /// fn main() -> std::io::Result<()> { + /// let listener = UnixListener::bind("/tmp/sock")?; /// - /// if let Ok(Some(err)) = listener.take_error() { - /// println!("Got error: {:?}", err); + /// if let Ok(Some(err)) = listener.take_error() { + /// println!("Got error: {:?}", err); + /// } /// } /// ``` /// @@ -880,15 +926,17 @@ impl UnixListener { /// // ... /// } /// - /// let listener = UnixListener::bind("/path/to/the/socket").unwrap(); - /// - /// for stream in listener.incoming() { - /// match stream { - /// Ok(stream) => { - /// thread::spawn(|| handle_client(stream)); - /// } - /// Err(err) => { - /// break; + /// fn main() -> std::io::Result<()> { + /// let listener = UnixListener::bind("/path/to/the/socket")?; + /// + /// for stream in listener.incoming() { + /// match stream { + /// Ok(stream) => { + /// thread::spawn(|| handle_client(stream)); + /// } + /// Err(err) => { + /// break; + /// } /// } /// } /// } @@ -947,15 +995,17 @@ impl<'a> IntoIterator for &'a UnixListener { /// // ... /// } /// -/// let listener = UnixListener::bind("/path/to/the/socket").unwrap(); +/// fn main() -> std::io::Result<()> { +/// let listener = UnixListener::bind("/path/to/the/socket")?; /// -/// for stream in listener.incoming() { -/// match stream { -/// Ok(stream) => { -/// thread::spawn(|| handle_client(stream)); -/// } -/// Err(err) => { -/// break; +/// for stream in listener.incoming() { +/// match stream { +/// Ok(stream) => { +/// thread::spawn(|| handle_client(stream)); +/// } +/// Err(err) => { +/// break; +/// } /// } /// } /// } @@ -986,11 +1036,13 @@ impl<'a> Iterator for Incoming<'a> { /// ```no_run /// use std::os::unix::net::UnixDatagram; /// -/// let socket = UnixDatagram::bind("/path/to/my/socket").unwrap(); -/// socket.send_to(b"hello world", "/path/to/other/socket").unwrap(); -/// let mut buf = [0; 100]; -/// let (count, address) = socket.recv_from(&mut buf).unwrap(); -/// println!("socket {:?} sent {:?}", address, &buf[..count]); +/// fn main() -> std::io::Result<()> { +/// let socket = UnixDatagram::bind("/path/to/my/socket")?; +/// socket.send_to(b"hello world", "/path/to/other/socket")?; +/// let mut buf = [0; 100]; +/// let (count, address) = socket.recv_from(&mut buf)?; +/// println!("socket {:?} sent {:?}", address, &buf[..count]); +/// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] pub struct UnixDatagram(Socket); @@ -1099,14 +1151,16 @@ impl UnixDatagram { /// ```no_run /// use std::os::unix::net::UnixDatagram; /// - /// let sock = UnixDatagram::unbound().unwrap(); - /// match sock.connect("/path/to/the/socket") { - /// Ok(sock) => sock, - /// Err(e) => { - /// println!("Couldn't connect: {:?}", e); - /// return - /// } - /// }; + /// fn main() -> std::io::Result<()> { + /// let sock = UnixDatagram::unbound()?; + /// match sock.connect("/path/to/the/socket") { + /// Ok(sock) => sock, + /// Err(e) => { + /// println!("Couldn't connect: {:?}", e); + /// return + /// } + /// }; + /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] pub fn connect>(&self, path: P) -> io::Result<()> { @@ -1133,9 +1187,11 @@ impl UnixDatagram { /// ```no_run /// use std::os::unix::net::UnixDatagram; /// - /// let sock = UnixDatagram::bind("/path/to/the/socket").unwrap(); + /// fn main() -> std::io::Result<()> { + /// let sock = UnixDatagram::bind("/path/to/the/socket")?; /// - /// let sock_copy = sock.try_clone().expect("try_clone failed"); + /// let sock_copy = sock.try_clone().expect("try_clone failed"); + /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] pub fn try_clone(&self) -> io::Result { @@ -1149,9 +1205,11 @@ impl UnixDatagram { /// ```no_run /// use std::os::unix::net::UnixDatagram; /// - /// let sock = UnixDatagram::bind("/path/to/the/socket").unwrap(); + /// fn main() -> std::io::Result<()> { + /// let sock = UnixDatagram::bind("/path/to/the/socket")?; /// - /// let addr = sock.local_addr().expect("Couldn't get local address"); + /// let addr = sock.local_addr().expect("Couldn't get local address"); + /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] pub fn local_addr(&self) -> io::Result { @@ -1169,10 +1227,12 @@ impl UnixDatagram { /// ```no_run /// use std::os::unix::net::UnixDatagram; /// - /// let sock = UnixDatagram::unbound().unwrap(); - /// sock.connect("/path/to/the/socket").unwrap(); + /// fn main() -> std::io::Result<()> { + /// let sock = UnixDatagram::unbound()?; + /// sock.connect("/path/to/the/socket")?; /// - /// let addr = sock.peer_addr().expect("Couldn't get peer address"); + /// let addr = sock.peer_addr().expect("Couldn't get peer address"); + /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] pub fn peer_addr(&self) -> io::Result { @@ -1189,11 +1249,13 @@ impl UnixDatagram { /// ```no_run /// use std::os::unix::net::UnixDatagram; /// - /// let sock = UnixDatagram::unbound().unwrap(); - /// let mut buf = vec![0; 10]; - /// match sock.recv_from(buf.as_mut_slice()) { - /// Ok((size, sender)) => println!("received {} bytes from {:?}", size, sender), - /// Err(e) => println!("recv_from function failed: {:?}", e), + /// fn main() -> std::io::Result<()> { + /// let sock = UnixDatagram::unbound()?; + /// let mut buf = vec![0; 10]; + /// match sock.recv_from(buf.as_mut_slice()) { + /// Ok((size, sender)) => println!("received {} bytes from {:?}", size, sender), + /// Err(e) => println!("recv_from function failed: {:?}", e), + /// } /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] @@ -1229,9 +1291,11 @@ impl UnixDatagram { /// ```no_run /// use std::os::unix::net::UnixDatagram; /// - /// let sock = UnixDatagram::bind("/path/to/the/socket").unwrap(); - /// let mut buf = vec![0; 10]; - /// sock.recv(buf.as_mut_slice()).expect("recv function failed"); + /// fn main() -> std::io::Result<()> { + /// let sock = UnixDatagram::bind("/path/to/the/socket")?; + /// let mut buf = vec![0; 10]; + /// sock.recv(buf.as_mut_slice()).expect("recv function failed"); + /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] pub fn recv(&self, buf: &mut [u8]) -> io::Result { @@ -1247,8 +1311,10 @@ impl UnixDatagram { /// ```no_run /// use std::os::unix::net::UnixDatagram; /// - /// let sock = UnixDatagram::unbound().unwrap(); - /// sock.send_to(b"omelette au fromage", "/some/sock").expect("send_to function failed"); + /// fn main() -> std::io::Result<()> { + /// let sock = UnixDatagram::unbound()?; + /// sock.send_to(b"omelette au fromage", "/some/sock").expect("send_to function failed"); + /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] pub fn send_to>(&self, buf: &[u8], path: P) -> io::Result { @@ -1280,9 +1346,11 @@ impl UnixDatagram { /// ```no_run /// use std::os::unix::net::UnixDatagram; /// - /// let sock = UnixDatagram::unbound().unwrap(); - /// sock.connect("/some/sock").expect("Couldn't connect"); - /// sock.send(b"omelette au fromage").expect("send_to function failed"); + /// fn main() -> std::io::Result<()> { + /// let sock = UnixDatagram::unbound()?; + /// sock.connect("/some/sock").expect("Couldn't connect"); + /// sock.send(b"omelette au fromage").expect("send_to function failed"); + /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] pub fn send(&self, buf: &[u8]) -> io::Result { @@ -1307,8 +1375,11 @@ impl UnixDatagram { /// use std::os::unix::net::UnixDatagram; /// use std::time::Duration; /// - /// let sock = UnixDatagram::unbound().unwrap(); - /// sock.set_read_timeout(Some(Duration::new(1, 0))).expect("set_read_timeout function failed"); + /// fn main() -> std::io::Result<()> { + /// let sock = UnixDatagram::unbound()?; + /// sock.set_read_timeout(Some(Duration::new(1, 0))) + /// .expect("set_read_timeout function failed"); + /// } /// ``` /// /// An [`Err`] is returned if the zero [`Duration`] is passed to this @@ -1319,10 +1390,12 @@ impl UnixDatagram { /// use std::os::unix::net::UnixDatagram; /// use std::time::Duration; /// - /// let socket = UnixDatagram::unbound().unwrap(); - /// let result = socket.set_read_timeout(Some(Duration::new(0, 0))); - /// let err = result.unwrap_err(); - /// assert_eq!(err.kind(), io::ErrorKind::InvalidInput) + /// fn main() -> std::io::Result<()> { + /// let socket = UnixDatagram::unbound()?; + /// let result = socket.set_read_timeout(Some(Duration::new(0, 0))); + /// let err = result.unwrap_err(); + /// assert_eq!(err.kind(), io::ErrorKind::InvalidInput) + /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] pub fn set_read_timeout(&self, timeout: Option) -> io::Result<()> { @@ -1346,9 +1419,11 @@ impl UnixDatagram { /// use std::os::unix::net::UnixDatagram; /// use std::time::Duration; /// - /// let sock = UnixDatagram::unbound().unwrap(); - /// sock.set_write_timeout(Some(Duration::new(1, 0))) - /// .expect("set_write_timeout function failed"); + /// fn main() -> std::io::Result<()> { + /// let sock = UnixDatagram::unbound()?; + /// sock.set_write_timeout(Some(Duration::new(1, 0))) + /// .expect("set_write_timeout function failed"); + /// } /// ``` /// /// An [`Err`] is returned if the zero [`Duration`] is passed to this @@ -1359,10 +1434,12 @@ impl UnixDatagram { /// use std::os::unix::net::UnixDatagram; /// use std::time::Duration; /// - /// let socket = UnixDatagram::unbound().unwrap(); - /// let result = socket.set_write_timeout(Some(Duration::new(0, 0))); - /// let err = result.unwrap_err(); - /// assert_eq!(err.kind(), io::ErrorKind::InvalidInput) + /// fn main() -> std::io::Result<()> { + /// let socket = UnixDatagram::unbound()?; + /// let result = socket.set_write_timeout(Some(Duration::new(0, 0))); + /// let err = result.unwrap_err(); + /// assert_eq!(err.kind(), io::ErrorKind::InvalidInput) + /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] pub fn set_write_timeout(&self, timeout: Option) -> io::Result<()> { @@ -1377,9 +1454,12 @@ impl UnixDatagram { /// use std::os::unix::net::UnixDatagram; /// use std::time::Duration; /// - /// let sock = UnixDatagram::unbound().unwrap(); - /// sock.set_read_timeout(Some(Duration::new(1, 0))).expect("set_read_timeout function failed"); - /// assert_eq!(sock.read_timeout().unwrap(), Some(Duration::new(1, 0))); + /// fn main() -> std::io::Result<()> { + /// let sock = UnixDatagram::unbound()?; + /// sock.set_read_timeout(Some(Duration::new(1, 0))) + /// .expect("set_read_timeout function failed"); + /// assert_eq!(sock.read_timeout()?, Some(Duration::new(1, 0))); + /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] pub fn read_timeout(&self) -> io::Result> { @@ -1394,10 +1474,12 @@ impl UnixDatagram { /// use std::os::unix::net::UnixDatagram; /// use std::time::Duration; /// - /// let sock = UnixDatagram::unbound().unwrap(); - /// sock.set_write_timeout(Some(Duration::new(1, 0))) - /// .expect("set_write_timeout function failed"); - /// assert_eq!(sock.write_timeout().unwrap(), Some(Duration::new(1, 0))); + /// fn main() -> std::io::Result<()> { + /// let sock = UnixDatagram::unbound()?; + /// sock.set_write_timeout(Some(Duration::new(1, 0))) + /// .expect("set_write_timeout function failed"); + /// assert_eq!(sock.write_timeout()?, Some(Duration::new(1, 0))); + /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] pub fn write_timeout(&self) -> io::Result> { @@ -1411,8 +1493,10 @@ impl UnixDatagram { /// ``` /// use std::os::unix::net::UnixDatagram; /// - /// let sock = UnixDatagram::unbound().unwrap(); - /// sock.set_nonblocking(true).expect("set_nonblocking function failed"); + /// fn main() -> std::io::Result<()> { + /// let sock = UnixDatagram::unbound()?; + /// sock.set_nonblocking(true).expect("set_nonblocking function failed"); + /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] pub fn set_nonblocking(&self, nonblocking: bool) -> io::Result<()> { @@ -1426,9 +1510,11 @@ impl UnixDatagram { /// ```no_run /// use std::os::unix::net::UnixDatagram; /// - /// let sock = UnixDatagram::unbound().unwrap(); - /// if let Ok(Some(err)) = sock.take_error() { - /// println!("Got error: {:?}", err); + /// fn main() -> std::io::Result<()> { + /// let sock = UnixDatagram::unbound()?; + /// if let Ok(Some(err)) = sock.take_error() { + /// println!("Got error: {:?}", err); + /// } /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] @@ -1448,8 +1534,10 @@ impl UnixDatagram { /// use std::os::unix::net::UnixDatagram; /// use std::net::Shutdown; /// - /// let sock = UnixDatagram::unbound().unwrap(); - /// sock.shutdown(Shutdown::Both).expect("shutdown function failed"); + /// fn main() -> std::io::Result<()> { + /// let sock = UnixDatagram::unbound()?; + /// sock.shutdown(Shutdown::Both).expect("shutdown function failed"); + /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] pub fn shutdown(&self, how: Shutdown) -> io::Result<()> { From 3a2da7194cfe35efa2f4a5fa3415defd4335c523 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Wed, 13 Nov 2019 09:43:08 +0100 Subject: [PATCH 02/16] Return Ok(()) in docstrings in std::os::unix::net --- src/libstd/sys/unix/ext/net.rs | 55 +++++++++++++++++++++++++++------- 1 file changed, 45 insertions(+), 10 deletions(-) diff --git a/src/libstd/sys/unix/ext/net.rs b/src/libstd/sys/unix/ext/net.rs index cfa157c66d102..5aafdb8241a8e 100644 --- a/src/libstd/sys/unix/ext/net.rs +++ b/src/libstd/sys/unix/ext/net.rs @@ -146,6 +146,7 @@ impl SocketAddr { /// let socket = UnixListener::bind("/tmp/sock")?; /// let addr = socket.local_addr().expect("Couldn't get local address"); /// assert_eq!(addr.is_unnamed(), false); + /// Ok(()) /// } /// ``` /// @@ -158,6 +159,7 @@ impl SocketAddr { /// let socket = UnixDatagram::unbound()?; /// let addr = socket.local_addr().expect("Couldn't get local address"); /// assert_eq!(addr.is_unnamed(), true); + /// Ok(()) /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] @@ -183,6 +185,7 @@ impl SocketAddr { /// let socket = UnixListener::bind("/tmp/sock")?; /// let addr = socket.local_addr().expect("Couldn't get local address"); /// assert_eq!(addr.as_pathname(), Some(Path::new("/tmp/sock"))); + /// Ok(()) /// } /// ``` /// @@ -195,6 +198,7 @@ impl SocketAddr { /// let socket = UnixDatagram::unbound()?; /// let addr = socket.local_addr().expect("Couldn't get local address"); /// assert_eq!(addr.as_pathname(), None); + /// Ok(()) /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] @@ -261,6 +265,7 @@ impl<'a> fmt::Display for AsciiEscaped<'a> { /// let mut response = String::new(); /// stream.read_to_string(&mut response)?; /// println!("{}", response); +/// Ok(()) /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] @@ -349,6 +354,7 @@ impl UnixStream { /// fn main() -> std::io::Result<()> { /// let socket = UnixStream::connect("/tmp/sock")?; /// let sock_copy = socket.try_clone().expect("Couldn't clone socket"); + /// Ok(()) /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] @@ -366,6 +372,7 @@ impl UnixStream { /// fn main() -> std::io::Result<()> { /// let socket = UnixStream::connect("/tmp/sock")?; /// let addr = socket.local_addr().expect("Couldn't get local address"); + /// Ok(()) /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] @@ -383,6 +390,7 @@ impl UnixStream { /// fn main() -> std::io::Result<()> { /// let socket = UnixStream::connect("/tmp/sock")?; /// let addr = socket.peer_addr().expect("Couldn't get peer address"); + /// Ok(()) /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] @@ -424,6 +432,7 @@ impl UnixStream { /// let result = socket.set_read_timeout(Some(Duration::new(0, 0))); /// let err = result.unwrap_err(); /// assert_eq!(err.kind(), io::ErrorKind::InvalidInput) + /// Ok(()) /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] @@ -452,6 +461,7 @@ impl UnixStream { /// let socket = UnixStream::connect("/tmp/sock")?; /// socket.set_write_timeout(Some(Duration::new(1, 0))) /// .expect("Couldn't set write timeout"); + /// Ok(()) /// } /// ``` /// @@ -468,6 +478,7 @@ impl UnixStream { /// let result = socket.set_write_timeout(Some(Duration::new(0, 0))); /// let err = result.unwrap_err(); /// assert_eq!(err.kind(), io::ErrorKind::InvalidInput) + /// Ok(()) /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] @@ -487,6 +498,7 @@ impl UnixStream { /// let socket = UnixStream::connect("/tmp/sock")?; /// socket.set_read_timeout(Some(Duration::new(1, 0))).expect("Couldn't set read timeout"); /// assert_eq!(socket.read_timeout()?, Some(Duration::new(1, 0))); + /// Ok(()) /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] @@ -507,6 +519,7 @@ impl UnixStream { /// socket.set_write_timeout(Some(Duration::new(1, 0))) /// .expect("Couldn't set write timeout"); /// assert_eq!(socket.write_timeout()?, Some(Duration::new(1, 0))); + /// Ok(()) /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] @@ -524,6 +537,7 @@ impl UnixStream { /// fn main() -> std::io::Result<()> { /// let socket = UnixStream::connect("/tmp/sock")?; /// socket.set_nonblocking(true).expect("Couldn't set nonblocking"); + /// Ok(()) /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] @@ -543,6 +557,7 @@ impl UnixStream { /// if let Ok(Some(err)) = socket.take_error() { /// println!("Got error: {:?}", err); /// } + /// Ok(()) /// } /// ``` /// @@ -570,6 +585,7 @@ impl UnixStream { /// fn main() -> std::io::Result<()> { /// let socket = UnixStream::connect("/tmp/sock"); /// socket.shutdown(Shutdown::Both).expect("shutdown function failed"); + /// Ok(()) /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] @@ -747,6 +763,7 @@ impl IntoRawFd for net::UdpSocket { /// } /// } /// } +/// Ok(()) /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] @@ -816,6 +833,7 @@ impl UnixListener { /// Ok((socket, addr)) => println!("Got a client: {:?}", addr), /// Err(e) => println!("accept function failed: {:?}", e), /// } + /// Ok(()) /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] @@ -840,8 +858,8 @@ impl UnixListener { /// /// fn main() -> std::io::Result<()> { /// let listener = UnixListener::bind("/path/to/the/socket")?; - /// /// let listener_copy = listener.try_clone().expect("try_clone failed"); + /// Ok(()) /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] @@ -858,8 +876,8 @@ impl UnixListener { /// /// fn main() -> std::io::Result<()> { /// let listener = UnixListener::bind("/path/to/the/socket")?; - /// /// let addr = listener.local_addr().expect("Couldn't get local address"); + /// Ok(()) /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] @@ -876,8 +894,8 @@ impl UnixListener { /// /// fn main() -> std::io::Result<()> { /// let listener = UnixListener::bind("/path/to/the/socket")?; - /// /// listener.set_nonblocking(true).expect("Couldn't set non blocking"); + /// Ok(()) /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] @@ -898,6 +916,7 @@ impl UnixListener { /// if let Ok(Some(err)) = listener.take_error() { /// println!("Got error: {:?}", err); /// } + /// Ok(()) /// } /// ``` /// @@ -939,6 +958,7 @@ impl UnixListener { /// } /// } /// } + /// Ok(()) /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] @@ -1008,6 +1028,7 @@ impl<'a> IntoIterator for &'a UnixListener { /// } /// } /// } +/// Ok(()) /// } /// ``` #[derive(Debug)] @@ -1042,6 +1063,7 @@ impl<'a> Iterator for Incoming<'a> { /// let mut buf = [0; 100]; /// let (count, address) = socket.recv_from(&mut buf)?; /// println!("socket {:?} sent {:?}", address, &buf[..count]); +/// Ok(()) /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] @@ -1157,9 +1179,10 @@ impl UnixDatagram { /// Ok(sock) => sock, /// Err(e) => { /// println!("Couldn't connect: {:?}", e); - /// return + /// return Err(e) /// } /// }; + /// Ok(()) /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] @@ -1189,8 +1212,8 @@ impl UnixDatagram { /// /// fn main() -> std::io::Result<()> { /// let sock = UnixDatagram::bind("/path/to/the/socket")?; - /// /// let sock_copy = sock.try_clone().expect("try_clone failed"); + /// Ok(()) /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] @@ -1207,8 +1230,8 @@ impl UnixDatagram { /// /// fn main() -> std::io::Result<()> { /// let sock = UnixDatagram::bind("/path/to/the/socket")?; - /// /// let addr = sock.local_addr().expect("Couldn't get local address"); + /// Ok(()) /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] @@ -1232,6 +1255,7 @@ impl UnixDatagram { /// sock.connect("/path/to/the/socket")?; /// /// let addr = sock.peer_addr().expect("Couldn't get peer address"); + /// Ok(()) /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] @@ -1252,10 +1276,9 @@ impl UnixDatagram { /// fn main() -> std::io::Result<()> { /// let sock = UnixDatagram::unbound()?; /// let mut buf = vec![0; 10]; - /// match sock.recv_from(buf.as_mut_slice()) { - /// Ok((size, sender)) => println!("received {} bytes from {:?}", size, sender), - /// Err(e) => println!("recv_from function failed: {:?}", e), - /// } + /// let (size, sender) = sock.recv_from(buf.as_mut_slice())?; + /// println!("received {} bytes from {:?}", size, sender); + /// Ok(()) /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] @@ -1295,6 +1318,7 @@ impl UnixDatagram { /// let sock = UnixDatagram::bind("/path/to/the/socket")?; /// let mut buf = vec![0; 10]; /// sock.recv(buf.as_mut_slice()).expect("recv function failed"); + /// Ok(()) /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] @@ -1314,6 +1338,7 @@ impl UnixDatagram { /// fn main() -> std::io::Result<()> { /// let sock = UnixDatagram::unbound()?; /// sock.send_to(b"omelette au fromage", "/some/sock").expect("send_to function failed"); + /// Ok(()) /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] @@ -1350,6 +1375,7 @@ impl UnixDatagram { /// let sock = UnixDatagram::unbound()?; /// sock.connect("/some/sock").expect("Couldn't connect"); /// sock.send(b"omelette au fromage").expect("send_to function failed"); + /// Ok(()) /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] @@ -1379,6 +1405,7 @@ impl UnixDatagram { /// let sock = UnixDatagram::unbound()?; /// sock.set_read_timeout(Some(Duration::new(1, 0))) /// .expect("set_read_timeout function failed"); + /// Ok(()) /// } /// ``` /// @@ -1395,6 +1422,7 @@ impl UnixDatagram { /// let result = socket.set_read_timeout(Some(Duration::new(0, 0))); /// let err = result.unwrap_err(); /// assert_eq!(err.kind(), io::ErrorKind::InvalidInput) + /// Ok(()) /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] @@ -1423,6 +1451,7 @@ impl UnixDatagram { /// let sock = UnixDatagram::unbound()?; /// sock.set_write_timeout(Some(Duration::new(1, 0))) /// .expect("set_write_timeout function failed"); + /// Ok(()) /// } /// ``` /// @@ -1439,6 +1468,7 @@ impl UnixDatagram { /// let result = socket.set_write_timeout(Some(Duration::new(0, 0))); /// let err = result.unwrap_err(); /// assert_eq!(err.kind(), io::ErrorKind::InvalidInput) + /// Ok(()) /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] @@ -1459,6 +1489,7 @@ impl UnixDatagram { /// sock.set_read_timeout(Some(Duration::new(1, 0))) /// .expect("set_read_timeout function failed"); /// assert_eq!(sock.read_timeout()?, Some(Duration::new(1, 0))); + /// Ok(()) /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] @@ -1479,6 +1510,7 @@ impl UnixDatagram { /// sock.set_write_timeout(Some(Duration::new(1, 0))) /// .expect("set_write_timeout function failed"); /// assert_eq!(sock.write_timeout()?, Some(Duration::new(1, 0))); + /// Ok(()) /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] @@ -1496,6 +1528,7 @@ impl UnixDatagram { /// fn main() -> std::io::Result<()> { /// let sock = UnixDatagram::unbound()?; /// sock.set_nonblocking(true).expect("set_nonblocking function failed"); + /// Ok(()) /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] @@ -1515,6 +1548,7 @@ impl UnixDatagram { /// if let Ok(Some(err)) = sock.take_error() { /// println!("Got error: {:?}", err); /// } + /// Ok(()) /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] @@ -1537,6 +1571,7 @@ impl UnixDatagram { /// fn main() -> std::io::Result<()> { /// let sock = UnixDatagram::unbound()?; /// sock.shutdown(Shutdown::Both).expect("shutdown function failed"); + /// Ok(()) /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] From aff79422d8ad3c6c7a079ff393066e28298dcf3c Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Sun, 24 Nov 2019 13:56:37 +0100 Subject: [PATCH 03/16] Also fix the signature of main in std::sys::unix::ext --- src/libstd/sys/unix/ext/mod.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/libstd/sys/unix/ext/mod.rs b/src/libstd/sys/unix/ext/mod.rs index 8039dcd2208cb..78a3fd05c730a 100644 --- a/src/libstd/sys/unix/ext/mod.rs +++ b/src/libstd/sys/unix/ext/mod.rs @@ -15,11 +15,13 @@ //! use std::fs::File; //! use std::os::unix::prelude::*; //! -//! fn main() { +//! fn main() -> std::io::Result<()> { //! let f = File::create("foo.txt")?; //! let fd = f.as_raw_fd(); //! //! // use fd with native unix bindings +//! +//! Ok(()) //! } //! ``` From cdfb5cb4bfff382dda24bb9106b3d0d018adb844 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Sun, 24 Nov 2019 13:57:52 +0100 Subject: [PATCH 04/16] Add missing semicolons and question marks --- src/libstd/sys/unix/ext/net.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/libstd/sys/unix/ext/net.rs b/src/libstd/sys/unix/ext/net.rs index 5aafdb8241a8e..92b62014406a4 100644 --- a/src/libstd/sys/unix/ext/net.rs +++ b/src/libstd/sys/unix/ext/net.rs @@ -431,7 +431,7 @@ impl UnixStream { /// let socket = UnixStream::connect("/tmp/sock")?; /// let result = socket.set_read_timeout(Some(Duration::new(0, 0))); /// let err = result.unwrap_err(); - /// assert_eq!(err.kind(), io::ErrorKind::InvalidInput) + /// assert_eq!(err.kind(), io::ErrorKind::InvalidInput); /// Ok(()) /// } /// ``` @@ -477,7 +477,7 @@ impl UnixStream { /// let socket = UdpSocket::bind("127.0.0.1:34254")?; /// let result = socket.set_write_timeout(Some(Duration::new(0, 0))); /// let err = result.unwrap_err(); - /// assert_eq!(err.kind(), io::ErrorKind::InvalidInput) + /// assert_eq!(err.kind(), io::ErrorKind::InvalidInput); /// Ok(()) /// } /// ``` @@ -583,7 +583,7 @@ impl UnixStream { /// use std::net::Shutdown; /// /// fn main() -> std::io::Result<()> { - /// let socket = UnixStream::connect("/tmp/sock"); + /// let socket = UnixStream::connect("/tmp/sock")?; /// socket.shutdown(Shutdown::Both).expect("shutdown function failed"); /// Ok(()) /// } @@ -1421,7 +1421,7 @@ impl UnixDatagram { /// let socket = UnixDatagram::unbound()?; /// let result = socket.set_read_timeout(Some(Duration::new(0, 0))); /// let err = result.unwrap_err(); - /// assert_eq!(err.kind(), io::ErrorKind::InvalidInput) + /// assert_eq!(err.kind(), io::ErrorKind::InvalidInput); /// Ok(()) /// } /// ``` @@ -1467,7 +1467,7 @@ impl UnixDatagram { /// let socket = UnixDatagram::unbound()?; /// let result = socket.set_write_timeout(Some(Duration::new(0, 0))); /// let err = result.unwrap_err(); - /// assert_eq!(err.kind(), io::ErrorKind::InvalidInput) + /// assert_eq!(err.kind(), io::ErrorKind::InvalidInput); /// Ok(()) /// } /// ``` From be18a227655b52cd49feeb61cbfe28de8f31a854 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Sun, 24 Nov 2019 15:31:28 +0100 Subject: [PATCH 05/16] Add missing main() and return value --- src/libstd/sys/unix/ext/net.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/libstd/sys/unix/ext/net.rs b/src/libstd/sys/unix/ext/net.rs index 92b62014406a4..5177cce628c96 100644 --- a/src/libstd/sys/unix/ext/net.rs +++ b/src/libstd/sys/unix/ext/net.rs @@ -415,8 +415,11 @@ impl UnixStream { /// use std::os::unix::net::UnixStream; /// use std::time::Duration; /// - /// let socket = UnixStream::connect("/tmp/sock")?; - /// socket.set_read_timeout(Some(Duration::new(1, 0))).expect("Couldn't set read timeout"); + /// fn main() -> std::io::Result<()> { + /// let socket = UnixStream::connect("/tmp/sock")?; + /// socket.set_read_timeout(Some(Duration::new(1, 0))).expect("Couldn't set read timeout"); + /// Ok(()) + /// } /// ``` /// /// An [`Err`] is returned if the zero [`Duration`] is passed to this From 3e7a5a4e0bdf13f504922c9e9b5c539cd57b576f Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Wed, 27 Nov 2019 23:19:03 +0100 Subject: [PATCH 06/16] handle diverging functions forwarding their return place --- src/librustc_mir/interpret/place.rs | 31 +++++++++++++++-------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/src/librustc_mir/interpret/place.rs b/src/librustc_mir/interpret/place.rs index 5b263f7680131..c03d1da677758 100644 --- a/src/librustc_mir/interpret/place.rs +++ b/src/librustc_mir/interpret/place.rs @@ -651,20 +651,21 @@ where use rustc::mir::PlaceBase; let mut place_ty = match &place.base { - PlaceBase::Local(mir::RETURN_PLACE) => match self.frame().return_place { - Some(return_place) => { - // We use our layout to verify our assumption; caller will validate - // their layout on return. - PlaceTy { - place: *return_place, - layout: self.layout_of( - self.subst_from_frame_and_normalize_erasing_regions( - self.frame().body.return_ty() - ) - )?, - } + PlaceBase::Local(mir::RETURN_PLACE) => { + // `return_place` has the *caller* layout, but we want to use our + // `layout to verify our assumption. The caller will validate + // their layout on return. + PlaceTy { + place: match self.frame().return_place { + Some(p) => *p, + None => Place::null(&*self), + }, + layout: self.layout_of( + self.subst_from_frame_and_normalize_erasing_regions( + self.frame().body.return_ty() + ) + )?, } - None => throw_unsup!(InvalidNullPointerUsage), }, PlaceBase::Local(local) => PlaceTy { // This works even for dead/uninitialized locals; we check further when writing @@ -791,8 +792,8 @@ where // to handle padding properly, which is only correct if we never look at this data with the // wrong type. - let ptr = match self.check_mplace_access(dest, None) - .expect("places should be checked on creation") + // Invalid places are a thing: the return place of a diverging function + let ptr = match self.check_mplace_access(dest, None)? { Some(ptr) => ptr, None => return Ok(()), // zero-sized access From 2869abacfa12ce3946234e5554d160fc932d933d Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Wed, 27 Nov 2019 23:36:39 +0100 Subject: [PATCH 07/16] comment --- src/librustc_mir/interpret/place.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/librustc_mir/interpret/place.rs b/src/librustc_mir/interpret/place.rs index c03d1da677758..70d9836b6ff0f 100644 --- a/src/librustc_mir/interpret/place.rs +++ b/src/librustc_mir/interpret/place.rs @@ -658,6 +658,13 @@ where PlaceTy { place: match self.frame().return_place { Some(p) => *p, + // Even if we don't have a return place, we sometimes need to + // create this place, but any attempt to read from / write to it + // (even a ZST read/write) needs to error, so let us make this + // a NULL place. + // + // FIXME: Ideally we'd make sure that the place projections also + // bail out. None => Place::null(&*self), }, layout: self.layout_of( From f2bee66d6c30599b9cb5c13349588e856466faae Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 28 Nov 2019 00:02:37 +0100 Subject: [PATCH 08/16] Add missing check --- src/librustdoc/html/static/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index cc0f470b34920..49a9cb093da2a 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -1221,7 +1221,7 @@ function getSearchElement() { // then an exact path match path.indexOf(keys[i]) > -1 || // next if there is a parent, check for exact parent match - (parent !== undefined && + (parent !== undefined && parent.name !== undefined && parent.name.toLowerCase().indexOf(keys[i]) > -1) || // lastly check to see if the name was a levenshtein match levenshtein(name, keys[i]) <= MAX_LEV_DISTANCE)) { From 27f4d6b5231b137c60a17c012386ed69f324ee56 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 28 Nov 2019 00:02:51 +0100 Subject: [PATCH 09/16] Remove minification on search-index.js file --- src/librustdoc/html/render.rs | 94 ++++------------------------------- 1 file changed, 9 insertions(+), 85 deletions(-) diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index ba94cb82c00d2..2d7fef56731a2 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -715,19 +715,13 @@ themePicker.onblur = handleThemeButtonsBlur; path: &Path, krate: &str, key: &str, - for_search_index: bool, - ) -> io::Result<(Vec, Vec, Vec)> { + ) -> io::Result<(Vec, Vec)> { let mut ret = Vec::new(); let mut krates = Vec::new(); - let mut variables = Vec::new(); if path.exists() { for line in BufReader::new(File::open(path)?).lines() { let line = line?; - if for_search_index && line.starts_with("var R") { - variables.push(line.clone()); - continue; - } if !line.starts_with(key) { continue; } @@ -741,7 +735,7 @@ themePicker.onblur = handleThemeButtonsBlur; .unwrap_or_else(|| String::new())); } } - Ok((ret, krates, variables)) + Ok((ret, krates)) } fn show_item(item: &IndexItem, krate: &str) -> String { @@ -756,7 +750,7 @@ themePicker.onblur = handleThemeButtonsBlur; let dst = cx.dst.join(&format!("aliases{}.js", cx.shared.resource_suffix)); { - let (mut all_aliases, _, _) = try_err!(collect(&dst, &krate.name, "ALIASES", false), &dst); + let (mut all_aliases, _) = try_err!(collect(&dst, &krate.name, "ALIASES"), &dst); let mut output = String::with_capacity(100); for (alias, items) in &cx.cache.aliases { if items.is_empty() { @@ -853,9 +847,7 @@ themePicker.onblur = handleThemeButtonsBlur; } let dst = cx.dst.join(&format!("source-files{}.js", cx.shared.resource_suffix)); - let (mut all_sources, _krates, _) = try_err!(collect(&dst, &krate.name, "sourcesIndex", - false), - &dst); + let (mut all_sources, _krates) = try_err!(collect(&dst, &krate.name, "sourcesIndex"), &dst); all_sources.push(format!("sourcesIndex[\"{}\"] = {};", &krate.name, hierarchy.to_json_string())); @@ -867,20 +859,15 @@ themePicker.onblur = handleThemeButtonsBlur; // Update the search index let dst = cx.dst.join(&format!("search-index{}.js", cx.shared.resource_suffix)); - let (mut all_indexes, mut krates, variables) = try_err!(collect(&dst, - &krate.name, - "searchIndex", - true), &dst); + let (mut all_indexes, mut krates) = try_err!(collect(&dst, &krate.name, "searchIndex"), &dst); all_indexes.push(search_index); // Sort the indexes by crate so the file will be generated identically even // with rustdoc running in parallel. all_indexes.sort(); { - let mut v = String::from("var N=null,E=\"\",T=\"t\",U=\"u\",searchIndex={};\n"); - v.push_str(&minify_replacer( - &format!("{}\n{}", variables.join(""), all_indexes.join("\n")), - options.enable_minification)); + let mut v = String::from("var searchIndex={};\n"); + v.push_str(&all_indexes.join("\n")); // "addSearchOptions" has to be called first so the crate filtering can be set before the // search might start (if it's set into the URL for example). v.push_str("addSearchOptions(searchIndex);initSearch(searchIndex);"); @@ -981,9 +968,8 @@ themePicker.onblur = handleThemeButtonsBlur; remote_item_type, remote_path[remote_path.len() - 1])); - let (mut all_implementors, _, _) = try_err!(collect(&mydst, &krate.name, "implementors", - false), - &mydst); + let (mut all_implementors, _) = try_err!(collect(&mydst, &krate.name, "implementors"), + &mydst); all_implementors.push(implementors); // Sort the implementors by crate so the file will be generated // identically even with rustdoc running in parallel. @@ -1020,68 +1006,6 @@ fn write_minify(fs:&DocFS, dst: PathBuf, contents: &str, enable_minification: bo } } -fn minify_replacer( - contents: &str, - enable_minification: bool, -) -> String { - use minifier::js::{simple_minify, Keyword, ReservedChar, Token, Tokens}; - - if enable_minification { - let tokens: Tokens<'_> = simple_minify(contents) - .into_iter() - .filter(|(f, next)| { - // We keep backlines. - minifier::js::clean_token_except(f, next, &|c: &Token<'_>| { - c.get_char() != Some(ReservedChar::Backline) - }) - }) - .map(|(f, _)| { - minifier::js::replace_token_with(f, &|t: &Token<'_>| { - match *t { - Token::Keyword(Keyword::Null) => Some(Token::Other("N")), - Token::String(s) => { - let s = &s[1..s.len() -1]; // The quotes are included - if s.is_empty() { - Some(Token::Other("E")) - } else if s == "t" { - Some(Token::Other("T")) - } else if s == "u" { - Some(Token::Other("U")) - } else { - None - } - } - _ => None, - } - }) - }) - .collect::>() - .into(); - let o = tokens.apply(|f| { - // We add a backline after the newly created variables. - minifier::js::aggregate_strings_into_array_with_separation_filter( - f, - "R", - Token::Char(ReservedChar::Backline), - // This closure prevents crates' names from being aggregated. - // - // The point here is to check if the string is preceded by '[' and - // "searchIndex". If so, it means this is a crate name and that it - // shouldn't be aggregated. - |tokens, pos| { - pos < 2 || - !tokens[pos - 1].eq_char(ReservedChar::OpenBracket) || - tokens[pos - 2].get_other() != Some("searchIndex") - } - ) - }) - .to_string(); - format!("{}\n", o) - } else { - format!("{}\n", contents) - } -} - #[derive(Debug, Eq, PartialEq, Hash)] struct ItemEntry { url: String, From baeea4ed67ab1183ffb24cad1a40511356a279a4 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 28 Nov 2019 00:26:59 +0100 Subject: [PATCH 10/16] minify theme.js as well --- src/librustdoc/html/render.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 2d7fef56731a2..49471a8e938a9 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -644,10 +644,9 @@ themePicker.onblur = handleThemeButtonsBlur; themes.appendChild(but); }});"#, as_json(&themes)); - write(cx.dst.join(&format!("theme{}.js", cx.shared.resource_suffix)), - theme_js.as_bytes() - )?; - + write_minify(&cx.shared.fs, cx.path("theme.js"), + &theme_js, + options.enable_minification)?; write_minify(&cx.shared.fs, cx.path("main.js"), static_files::MAIN_JS, options.enable_minification)?; From 71710608f009066b5a2dd65ea88ec5c0a79422e4 Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Thu, 28 Nov 2019 22:32:43 +0200 Subject: [PATCH 11/16] rustc: hide HirId's fmt::Debug output from -Z span_free_formats. --- src/librustc/mir/mod.rs | 8 ++++++-- src/librustc/ty/print/pretty.rs | 2 +- src/test/mir-opt/inline-closure-borrows-arg.rs | 6 +++--- src/test/mir-opt/inline-closure-captures.rs | 6 +++--- src/test/mir-opt/inline-closure.rs | 6 +++--- src/test/mir-opt/retag.rs | 2 +- 6 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/librustc/mir/mod.rs b/src/librustc/mir/mod.rs index c745dd9444cd6..bcb245d862b6b 100644 --- a/src/librustc/mir/mod.rs +++ b/src/librustc/mir/mod.rs @@ -2302,10 +2302,14 @@ impl<'tcx> Debug for Rvalue<'tcx> { } } - AggregateKind::Closure(def_id, _) => ty::tls::with(|tcx| { + AggregateKind::Closure(def_id, substs) => ty::tls::with(|tcx| { if let Some(hir_id) = tcx.hir().as_local_hir_id(def_id) { let name = if tcx.sess.opts.debugging_opts.span_free_formats { - format!("[closure@{:?}]", hir_id) + let substs = tcx.lift(&substs).unwrap(); + format!( + "[closure@{}]", + tcx.def_path_str_with_substs(def_id, substs), + ) } else { format!("[closure@{:?}]", tcx.hir().span(hir_id)) }; diff --git a/src/librustc/ty/print/pretty.rs b/src/librustc/ty/print/pretty.rs index 2a311ea962424..8d2f5600bac29 100644 --- a/src/librustc/ty/print/pretty.rs +++ b/src/librustc/ty/print/pretty.rs @@ -682,7 +682,7 @@ pub trait PrettyPrinter<'tcx>: // FIXME(eddyb) should use `def_span`. if let Some(hir_id) = self.tcx().hir().as_local_hir_id(did) { if self.tcx().sess.opts.debugging_opts.span_free_formats { - p!(write("@{:?}", hir_id)); + p!(write("@"), print_def_path(did, substs)); } else { p!(write("@{:?}", self.tcx().hir().span(hir_id))); } diff --git a/src/test/mir-opt/inline-closure-borrows-arg.rs b/src/test/mir-opt/inline-closure-borrows-arg.rs index b5bfeef5e9c56..768f495322809 100644 --- a/src/test/mir-opt/inline-closure-borrows-arg.rs +++ b/src/test/mir-opt/inline-closure-borrows-arg.rs @@ -21,8 +21,8 @@ fn foo(_t: T, q: &i32) -> i32 { // debug _t => _1; // debug q => _2; // let mut _0: i32; -// let _3: [closure@HirId { owner: DefIndex(4), local_id: 31 }]; -// let mut _4: &[closure@HirId { owner: DefIndex(4), local_id: 31 }]; +// let _3: [closure@foo::{{closure}}#0]; +// let mut _4: &[closure@foo::{{closure}}#0]; // let mut _5: (&i32, &i32); // let mut _6: &i32; // let mut _7: &i32; @@ -40,7 +40,7 @@ fn foo(_t: T, q: &i32) -> i32 { // } // bb0: { // ... -// _3 = [closure@HirId { owner: DefIndex(4), local_id: 31 }]; +// _3 = [closure@foo::::{{closure}}#0]; // ... // _4 = &_3; // ... diff --git a/src/test/mir-opt/inline-closure-captures.rs b/src/test/mir-opt/inline-closure-captures.rs index e73dbe48bd143..e000a418d90c7 100644 --- a/src/test/mir-opt/inline-closure-captures.rs +++ b/src/test/mir-opt/inline-closure-captures.rs @@ -17,10 +17,10 @@ fn foo(t: T, q: i32) -> (i32, T) { // debug t => _1; // debug q => _2; // let mut _0: (i32, T); -// let _3: [closure@HirId { owner: DefIndex(4), local_id: 15 } q:&i32, t:&T]; +// let _3: [closure@foo::{{closure}}#0 q:&i32, t:&T]; // let mut _4: &i32; // let mut _5: &T; -// let mut _6: &[closure@HirId { owner: DefIndex(4), local_id: 15 } q:&i32, t:&T]; +// let mut _6: &[closure@foo::{{closure}}#0 q:&i32, t:&T]; // let mut _7: (i32,); // let mut _8: i32; // let mut _11: i32; @@ -39,7 +39,7 @@ fn foo(t: T, q: i32) -> (i32, T) { // _4 = &_2; // ... // _5 = &_1; -// _3 = [closure@HirId { owner: DefIndex(4), local_id: 15 }] { q: move _4, t: move _5 }; +// _3 = [closure@foo::::{{closure}}#0] { q: move _4, t: move _5 }; // ... // _6 = &_3; // ... diff --git a/src/test/mir-opt/inline-closure.rs b/src/test/mir-opt/inline-closure.rs index ddf027f4be38a..bd36e77818edc 100644 --- a/src/test/mir-opt/inline-closure.rs +++ b/src/test/mir-opt/inline-closure.rs @@ -17,8 +17,8 @@ fn foo(_t: T, q: i32) -> i32 { // debug _t => _1; // debug q => _2; // let mut _0: i32; -// let _3: [closure@HirId { owner: DefIndex(4), local_id: 15 }]; -// let mut _4: &[closure@HirId { owner: DefIndex(4), local_id: 15 }]; +// let _3: [closure@foo::{{closure}}#0]; +// let mut _4: &[closure@foo::{{closure}}#0]; // let mut _5: (i32, i32); // let mut _6: i32; // let mut _7: i32; @@ -33,7 +33,7 @@ fn foo(_t: T, q: i32) -> i32 { // } // bb0: { // ... -// _3 = [closure@HirId { owner: DefIndex(4), local_id: 15 }]; +// _3 = [closure@foo::::{{closure}}#0]; // ... // _4 = &_3; // ... diff --git a/src/test/mir-opt/retag.rs b/src/test/mir-opt/retag.rs index 96b848eb1d41c..32995448a21e9 100644 --- a/src/test/mir-opt/retag.rs +++ b/src/test/mir-opt/retag.rs @@ -100,7 +100,7 @@ fn main() { // } // END rustc.main.EraseRegions.after.mir // START rustc.main-{{closure}}.EraseRegions.after.mir -// fn main::{{closure}}#0(_1: &[closure@HirId { owner: DefIndex(13), local_id: 72 }], _2: &i32) -> &i32 { +// fn main::{{closure}}#0(_1: &[closure@main::{{closure}}#0], _2: &i32) -> &i32 { // ... // bb0: { // Retag([fn entry] _1); From 30a9978c6c8eb257a17e562f23690291ba1fc979 Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Tue, 26 Nov 2019 19:55:03 +0200 Subject: [PATCH 12/16] rustc: move MIR source_scope_local_data's ClearCrossCrate to be around elements. --- src/librustc/mir/mod.rs | 11 +++- src/librustc_mir/borrow_check/mod.rs | 67 ++++++++++---------- src/librustc_mir/build/mod.rs | 9 ++- src/librustc_mir/build/scope.rs | 11 ++-- src/librustc_mir/interpret/eval_context.rs | 4 +- src/librustc_mir/shim.rs | 21 ++---- src/librustc_mir/transform/check_unsafety.rs | 31 +++------ src/librustc_mir/transform/const_prop.rs | 49 +++++--------- 8 files changed, 88 insertions(+), 115 deletions(-) diff --git a/src/librustc/mir/mod.rs b/src/librustc/mir/mod.rs index 8c1690a177bde..5f820f5b788ae 100644 --- a/src/librustc/mir/mod.rs +++ b/src/librustc/mir/mod.rs @@ -106,7 +106,7 @@ pub struct Body<'tcx> { /// Crate-local information for each source scope, that can't (and /// needn't) be tracked across crates. - pub source_scope_local_data: ClearCrossCrate>, + pub source_scope_local_data: IndexVec>, /// The yield type of the function, if it is a generator. pub yield_ty: Option>, @@ -167,7 +167,7 @@ impl<'tcx> Body<'tcx> { pub fn new( basic_blocks: IndexVec>, source_scopes: IndexVec, - source_scope_local_data: ClearCrossCrate>, + source_scope_local_data: IndexVec>, local_decls: LocalDecls<'tcx>, user_type_annotations: CanonicalUserTypeAnnotations<'tcx>, arg_count: usize, @@ -435,6 +435,13 @@ pub enum ClearCrossCrate { } impl ClearCrossCrate { + pub fn as_ref(&'a self) -> ClearCrossCrate<&'a T> { + match self { + ClearCrossCrate::Clear => ClearCrossCrate::Clear, + ClearCrossCrate::Set(v) => ClearCrossCrate::Set(v), + } + } + pub fn assert_crate_local(self) -> T { match self { ClearCrossCrate::Clear => bug!("unwrapping cross-crate data"), diff --git a/src/librustc_mir/borrow_check/mod.rs b/src/librustc_mir/borrow_check/mod.rs index 649aeac12de94..c5236407d135f 100644 --- a/src/librustc_mir/borrow_check/mod.rs +++ b/src/librustc_mir/borrow_check/mod.rs @@ -300,11 +300,10 @@ fn do_mir_borrowck<'a, 'tcx>( let mut initial_diag = mbcx.report_conflicting_borrow(location, (&place, span), bk, &borrow); - let lint_root = if let ClearCrossCrate::Set(ref vsi) = mbcx.body.source_scope_local_data { - let scope = mbcx.body.source_info(location).scope; - vsi[scope].lint_root - } else { - id + let scope = mbcx.body.source_info(location).scope; + let lint_root = match &mbcx.body.source_scope_local_data[scope] { + ClearCrossCrate::Set(data) => data.lint_root, + _ => id, }; // Span and message don't matter; we overwrite them below anyway @@ -338,38 +337,40 @@ fn do_mir_borrowck<'a, 'tcx>( debug!("mbcx.used_mut: {:?}", mbcx.used_mut); let used_mut = mbcx.used_mut; for local in mbcx.body.mut_vars_and_args_iter().filter(|local| !used_mut.contains(local)) { - if let ClearCrossCrate::Set(ref vsi) = mbcx.body.source_scope_local_data { - let local_decl = &mbcx.body.local_decls[local]; - - // Skip over locals that begin with an underscore or have no name - match mbcx.local_names[local] { - Some(name) => if name.as_str().starts_with("_") { - continue; - }, - None => continue, - } + let local_decl = &mbcx.body.local_decls[local]; + let lint_root = match &mbcx.body.source_scope_local_data[local_decl.source_info.scope] { + ClearCrossCrate::Set(data) => data.lint_root, + _ => continue, + }; - let span = local_decl.source_info.span; - if span.desugaring_kind().is_some() { - // If the `mut` arises as part of a desugaring, we should ignore it. + // Skip over locals that begin with an underscore or have no name + match mbcx.local_names[local] { + Some(name) => if name.as_str().starts_with("_") { continue; - } + }, + None => continue, + } - let mut_span = tcx.sess.source_map().span_until_non_whitespace(span); - tcx.struct_span_lint_hir( - UNUSED_MUT, - vsi[local_decl.source_info.scope].lint_root, - span, - "variable does not need to be mutable", - ) - .span_suggestion_short( - mut_span, - "remove this `mut`", - String::new(), - Applicability::MachineApplicable, - ) - .emit(); + let span = local_decl.source_info.span; + if span.desugaring_kind().is_some() { + // If the `mut` arises as part of a desugaring, we should ignore it. + continue; } + + let mut_span = tcx.sess.source_map().span_until_non_whitespace(span); + tcx.struct_span_lint_hir( + UNUSED_MUT, + lint_root, + span, + "variable does not need to be mutable", + ) + .span_suggestion_short( + mut_span, + "remove this `mut`", + String::new(), + Applicability::MachineApplicable, + ) + .emit(); } // Buffer any move errors that we collected and de-duplicated. diff --git a/src/librustc_mir/build/mod.rs b/src/librustc_mir/build/mod.rs index 91ddd5a5623c0..716e57dc4fba0 100644 --- a/src/librustc_mir/build/mod.rs +++ b/src/librustc_mir/build/mod.rs @@ -309,7 +309,7 @@ struct Builder<'a, 'tcx> { /// The vector of all scopes that we have created thus far; /// we track this for debuginfo later. source_scopes: IndexVec, - source_scope_local_data: IndexVec, + source_scope_local_data: IndexVec>, source_scope: SourceScope, /// The guard-context: each time we build the guard expression for @@ -741,7 +741,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { Body::new( self.cfg.basic_blocks, self.source_scopes, - ClearCrossCrate::Set(self.source_scope_local_data), + self.source_scope_local_data, self.local_decls, self.canonical_user_type_annotations, self.arg_count, @@ -942,7 +942,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { self.hir.root_lint_level ); let parent_root = tcx.maybe_lint_level_root_bounded( - self.source_scope_local_data[original_source_scope].lint_root, + self.source_scope_local_data[original_source_scope] + .as_ref() + .assert_crate_local() + .lint_root, self.hir.root_lint_level, ); if current_root != parent_root { diff --git a/src/librustc_mir/build/scope.rs b/src/librustc_mir/build/scope.rs index bb25b28526960..d756a22a0002c 100644 --- a/src/librustc_mir/build/scope.rs +++ b/src/librustc_mir/build/scope.rs @@ -436,7 +436,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { // We estimate the true lint roots here to avoid creating a lot of source scopes. let parent_root = tcx.maybe_lint_level_root_bounded( - self.source_scope_local_data[source_scope].lint_root, + self.source_scope_local_data[source_scope] + .as_ref() + .assert_crate_local() + .lint_root, self.hir.root_lint_level, ); let current_root = tcx.maybe_lint_level_root_bounded( @@ -663,13 +666,13 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { lint_root: if let LintLevel::Explicit(lint_root) = lint_level { lint_root } else { - self.source_scope_local_data[parent].lint_root + self.source_scope_local_data[parent].as_ref().assert_crate_local().lint_root }, safety: safety.unwrap_or_else(|| { - self.source_scope_local_data[parent].safety + self.source_scope_local_data[parent].as_ref().assert_crate_local().safety }) }; - self.source_scope_local_data.push(scope_local_data); + self.source_scope_local_data.push(ClearCrossCrate::Set(scope_local_data)); scope } diff --git a/src/librustc_mir/interpret/eval_context.rs b/src/librustc_mir/interpret/eval_context.rs index 626e81fa91186..4b07f217ab3f5 100644 --- a/src/librustc_mir/interpret/eval_context.rs +++ b/src/librustc_mir/interpret/eval_context.rs @@ -849,8 +849,8 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { } else { block.terminator().source_info }; - match body.source_scope_local_data { - mir::ClearCrossCrate::Set(ref ivs) => Some(ivs[source_info.scope].lint_root), + match &body.source_scope_local_data[source_info.scope] { + mir::ClearCrossCrate::Set(data) => Some(data.lint_root), mir::ClearCrossCrate::Clear => None, } }); diff --git a/src/librustc_mir/shim.rs b/src/librustc_mir/shim.rs index 08af271ff46e0..e2466c6d07a43 100644 --- a/src/librustc_mir/shim.rs +++ b/src/librustc_mir/shim.rs @@ -198,9 +198,6 @@ fn build_drop_shim<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, ty: Option>) let mut body = new_body( blocks, - IndexVec::from_elem_n( - SourceScopeData { span, parent_scope: None }, 1 - ), local_decls_for_sig(&sig, span), sig.inputs().len(), span); @@ -244,15 +241,18 @@ fn build_drop_shim<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, ty: Option>) fn new_body<'tcx>( basic_blocks: IndexVec>, - source_scopes: IndexVec, local_decls: IndexVec>, arg_count: usize, span: Span, ) -> Body<'tcx> { Body::new( basic_blocks, - source_scopes, - ClearCrossCrate::Clear, + IndexVec::from_elem_n( + SourceScopeData { span, parent_scope: None }, 1 + ), + IndexVec::from_elem_n( + ClearCrossCrate::Clear, 1 + ), local_decls, IndexVec::new(), arg_count, @@ -380,9 +380,6 @@ impl CloneShimBuilder<'tcx> { fn into_mir(self) -> Body<'tcx> { new_body( self.blocks, - IndexVec::from_elem_n( - SourceScopeData { span: self.span, parent_scope: None }, 1 - ), self.local_decls, self.sig.inputs().len(), self.span, @@ -836,9 +833,6 @@ fn build_call_shim<'tcx>( let mut body = new_body( blocks, - IndexVec::from_elem_n( - SourceScopeData { span, parent_scope: None }, 1 - ), local_decls, sig.inputs().len(), span, @@ -919,9 +913,6 @@ pub fn build_adt_ctor(tcx: TyCtxt<'_>, ctor_id: DefId) -> &Body<'_> { let body = new_body( IndexVec::from_elem_n(start_block, 1), - IndexVec::from_elem_n( - SourceScopeData { span, parent_scope: None }, 1 - ), local_decls, sig.inputs().len(), span, diff --git a/src/librustc_mir/transform/check_unsafety.rs b/src/librustc_mir/transform/check_unsafety.rs index b7cc4e9fcf66c..b1c4101dbc759 100644 --- a/src/librustc_mir/transform/check_unsafety.rs +++ b/src/librustc_mir/transform/check_unsafety.rs @@ -1,6 +1,4 @@ use rustc_data_structures::fx::FxHashSet; -use rustc_index::vec::IndexVec; -use rustc_data_structures::sync::Lrc; use rustc::ty::query::Providers; use rustc::ty::{self, TyCtxt}; @@ -24,7 +22,6 @@ pub struct UnsafetyChecker<'a, 'tcx> { body: &'a Body<'tcx>, const_context: bool, min_const_fn: bool, - source_scope_local_data: &'a IndexVec, violations: Vec, source_info: SourceInfo, tcx: TyCtxt<'tcx>, @@ -39,7 +36,6 @@ impl<'a, 'tcx> UnsafetyChecker<'a, 'tcx> { const_context: bool, min_const_fn: bool, body: &'a Body<'tcx>, - source_scope_local_data: &'a IndexVec, tcx: TyCtxt<'tcx>, param_env: ty::ParamEnv<'tcx>, ) -> Self { @@ -51,7 +47,6 @@ impl<'a, 'tcx> UnsafetyChecker<'a, 'tcx> { body, const_context, min_const_fn, - source_scope_local_data, violations: vec![], source_info: SourceInfo { span: body.span, @@ -219,8 +214,10 @@ impl<'a, 'tcx> Visitor<'tcx> for UnsafetyChecker<'a, 'tcx> { if context.is_borrow() { if util::is_disaligned(self.tcx, self.body, self.param_env, place) { let source_info = self.source_info; - let lint_root = - self.source_scope_local_data[source_info.scope].lint_root; + let lint_root = self.body.source_scope_local_data[source_info.scope] + .as_ref() + .assert_crate_local() + .lint_root; self.register_violations(&[UnsafetyViolation { source_info, description: Symbol::intern("borrow of packed field"), @@ -346,7 +343,10 @@ impl<'a, 'tcx> UnsafetyChecker<'a, 'tcx> { fn register_violations(&mut self, violations: &[UnsafetyViolation], unsafe_blocks: &[(hir::HirId, bool)]) { - let safety = self.source_scope_local_data[self.source_info.scope].safety; + let safety = self.body.source_scope_local_data[self.source_info.scope] + .as_ref() + .assert_crate_local() + .safety; let within_unsafe = match safety { // `unsafe` blocks are required in safe code Safety::Safe => { @@ -516,17 +516,6 @@ fn unsafety_check_result(tcx: TyCtxt<'_>, def_id: DefId) -> UnsafetyCheckResult // `mir_built` force this. let body = &tcx.mir_built(def_id).borrow(); - let source_scope_local_data = match body.source_scope_local_data { - ClearCrossCrate::Set(ref data) => data, - ClearCrossCrate::Clear => { - debug!("unsafety_violations: {:?} - remote, skipping", def_id); - return UnsafetyCheckResult { - violations: Lrc::new([]), - unsafe_blocks: Lrc::new([]) - } - } - }; - let param_env = tcx.param_env(def_id); let id = tcx.hir().as_local_hir_id(def_id).unwrap(); @@ -536,9 +525,7 @@ fn unsafety_check_result(tcx: TyCtxt<'_>, def_id: DefId) -> UnsafetyCheckResult hir::BodyOwnerKind::Const | hir::BodyOwnerKind::Static(_) => (true, false), }; - let mut checker = UnsafetyChecker::new( - const_context, min_const_fn, - body, source_scope_local_data, tcx, param_env); + let mut checker = UnsafetyChecker::new(const_context, min_const_fn, body, tcx, param_env); checker.visit_body(body); check_unused_unsafe(tcx, def_id, &checker.used_unsafe, &mut checker.inherited_blocks); diff --git a/src/librustc_mir/transform/const_prop.rs b/src/librustc_mir/transform/const_prop.rs index d2740cf3771a8..705006fabbe42 100644 --- a/src/librustc_mir/transform/const_prop.rs +++ b/src/librustc_mir/transform/const_prop.rs @@ -74,17 +74,11 @@ impl<'tcx> MirPass<'tcx> for ConstProp { trace!("ConstProp starting for {:?}", source.def_id()); - // Steal some data we need from `body`. - let source_scope_local_data = std::mem::replace( - &mut body.source_scope_local_data, - ClearCrossCrate::Clear - ); - let dummy_body = &Body::new( body.basic_blocks().clone(), Default::default(), - ClearCrossCrate::Clear, + body.source_scope_local_data.clone(), body.local_decls.clone(), Default::default(), body.arg_count, @@ -101,19 +95,11 @@ impl<'tcx> MirPass<'tcx> for ConstProp { let mut optimization_finder = ConstPropagator::new( body, dummy_body, - source_scope_local_data, tcx, source ); optimization_finder.visit_body(body); - // put back the data we stole from `mir` - let source_scope_local_data = optimization_finder.release_stolen_data(); - std::mem::replace( - &mut body.source_scope_local_data, - source_scope_local_data - ); - trace!("ConstProp done for {:?}", source.def_id()); } } @@ -266,7 +252,9 @@ struct ConstPropagator<'mir, 'tcx> { source: MirSource<'tcx>, can_const_prop: IndexVec, param_env: ParamEnv<'tcx>, - source_scope_local_data: ClearCrossCrate>, + // FIXME(eddyb) avoid cloning these two fields more than once, + // by accessing them through `ecx` instead. + source_scope_local_data: IndexVec>, local_decls: IndexVec>, ret: Option>, } @@ -298,7 +286,6 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { fn new( body: &Body<'tcx>, dummy_body: &'mir Body<'tcx>, - source_scope_local_data: ClearCrossCrate>, tcx: TyCtxt<'tcx>, source: MirSource<'tcx>, ) -> ConstPropagator<'mir, 'tcx> { @@ -336,17 +323,15 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { source, param_env, can_const_prop, - source_scope_local_data, + // FIXME(eddyb) avoid cloning these two fields more than once, + // by accessing them through `ecx` instead. + source_scope_local_data: body.source_scope_local_data.clone(), //FIXME(wesleywiser) we can't steal this because `Visitor::super_visit_body()` needs it local_decls: body.local_decls.clone(), ret: ret.map(Into::into), } } - fn release_stolen_data(self) -> ClearCrossCrate> { - self.source_scope_local_data - } - fn get_const(&self, local: Local) -> Option> { if local == RETURN_PLACE { // Try to read the return place as an immediate so that if it is representable as a @@ -376,14 +361,11 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { F: FnOnce(&mut Self) -> InterpResult<'tcx, T>, { self.ecx.tcx.span = source_info.span; - let lint_root = match self.source_scope_local_data { - ClearCrossCrate::Set(ref ivs) => { - //FIXME(#51314): remove this check - if source_info.scope.index() >= ivs.len() { - return None; - } - ivs[source_info.scope].lint_root - }, + // FIXME(eddyb) move this to the `Panic(_)` error case, so that + // `f(self)` is always called, and that the only difference when + // `source_scope_local_data` is missing, is that the lint isn't emitted. + let lint_root = match &self.source_scope_local_data[source_info.scope] { + ClearCrossCrate::Set(data) => data.lint_root, ClearCrossCrate::Clear => return None, }; let r = match f(self) { @@ -507,8 +489,8 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { let right_size = r.layout.size; let r_bits = r.to_scalar().and_then(|r| r.to_bits(right_size)); if r_bits.ok().map_or(false, |b| b >= left_bits as u128) { - let source_scope_local_data = match self.source_scope_local_data { - ClearCrossCrate::Set(ref data) => data, + let lint_root = match &self.source_scope_local_data[source_info.scope] { + ClearCrossCrate::Set(data) => data.lint_root, ClearCrossCrate::Clear => return None, }; let dir = if *op == BinOp::Shr { @@ -516,10 +498,9 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { } else { "left" }; - let hir_id = source_scope_local_data[source_info.scope].lint_root; self.tcx.lint_hir( ::rustc::lint::builtin::EXCEEDING_BITSHIFTS, - hir_id, + lint_root, span, &format!("attempt to shift {} with overflow", dir)); return None; From 78d85fcf52363f1237b877ea5b7b5583cd833894 Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Tue, 26 Nov 2019 19:55:32 +0200 Subject: [PATCH 13/16] rustc_mir: fix inliner to also copy over source_scope_local_data. --- src/librustc_mir/transform/inline.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/librustc_mir/transform/inline.rs b/src/librustc_mir/transform/inline.rs index 867673beb35cc..70a0fb2d1035c 100644 --- a/src/librustc_mir/transform/inline.rs +++ b/src/librustc_mir/transform/inline.rs @@ -388,16 +388,25 @@ impl Inliner<'tcx> { let mut local_map = IndexVec::with_capacity(callee_body.local_decls.len()); let mut scope_map = IndexVec::with_capacity(callee_body.source_scopes.len()); - for mut scope in callee_body.source_scopes.iter().cloned() { + for (callee_idx, scope) in callee_body.source_scopes.iter_enumerated() { + let mut scope = scope.clone(); if scope.parent_scope.is_none() { scope.parent_scope = Some(callsite.location.scope); + // FIXME(eddyb) is this really needed? + // (also note that it's always overwritten below) scope.span = callee_body.span; } + // FIXME(eddyb) this doesn't seem right at all. + // The inlined source scopes should probably be annotated as + // such, but also contain all of the original information. scope.span = callsite.location.span; let idx = caller_body.source_scopes.push(scope); scope_map.push(idx); + + let local_data = callee_body.source_scope_local_data[callee_idx].clone(); + assert_eq!(idx, caller_body.source_scope_local_data.push(local_data)); } for loc in callee_body.vars_and_temps_iter() { From a9976d89ed721184a95a24f109a65916f2905793 Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Tue, 26 Nov 2019 22:17:35 +0200 Subject: [PATCH 14/16] rustc: move mir::SourceScopeLocalData to a field of SourceScopeData. --- src/librustc/mir/mod.rs | 10 ++++------ src/librustc/mir/visit.rs | 1 + src/librustc_mir/borrow_check/mod.rs | 4 ++-- src/librustc_mir/build/mod.rs | 6 ++---- src/librustc_mir/build/scope.rs | 20 ++++++++++---------- src/librustc_mir/interpret/eval_context.rs | 2 +- src/librustc_mir/shim.rs | 6 ++---- src/librustc_mir/transform/check_unsafety.rs | 6 ++++-- src/librustc_mir/transform/const_prop.rs | 17 ++++++++--------- src/librustc_mir/transform/inline.rs | 6 +----- src/librustc_mir/transform/promote_consts.rs | 1 - 11 files changed, 35 insertions(+), 44 deletions(-) diff --git a/src/librustc/mir/mod.rs b/src/librustc/mir/mod.rs index 5f820f5b788ae..da0cadd5cf242 100644 --- a/src/librustc/mir/mod.rs +++ b/src/librustc/mir/mod.rs @@ -104,10 +104,6 @@ pub struct Body<'tcx> { /// and used for debuginfo. Indexed by a `SourceScope`. pub source_scopes: IndexVec, - /// Crate-local information for each source scope, that can't (and - /// needn't) be tracked across crates. - pub source_scope_local_data: IndexVec>, - /// The yield type of the function, if it is a generator. pub yield_ty: Option>, @@ -167,7 +163,6 @@ impl<'tcx> Body<'tcx> { pub fn new( basic_blocks: IndexVec>, source_scopes: IndexVec, - source_scope_local_data: IndexVec>, local_decls: LocalDecls<'tcx>, user_type_annotations: CanonicalUserTypeAnnotations<'tcx>, arg_count: usize, @@ -188,7 +183,6 @@ impl<'tcx> Body<'tcx> { phase: MirPhase::Build, basic_blocks, source_scopes, - source_scope_local_data, yield_ty: None, generator_drop: None, generator_layout: None, @@ -2034,6 +2028,10 @@ rustc_index::newtype_index! { pub struct SourceScopeData { pub span: Span, pub parent_scope: Option, + + /// Crate-local information for this source scope, that can't (and + /// needn't) be tracked across crates. + pub local_data: ClearCrossCrate, } #[derive(Clone, Debug, RustcEncodable, RustcDecodable, HashStable)] diff --git a/src/librustc/mir/visit.rs b/src/librustc/mir/visit.rs index 58c12ef250155..145593f1c4d4a 100644 --- a/src/librustc/mir/visit.rs +++ b/src/librustc/mir/visit.rs @@ -317,6 +317,7 @@ macro_rules! make_mir_visitor { let SourceScopeData { span, parent_scope, + local_data: _, } = scope_data; self.visit_span(span); diff --git a/src/librustc_mir/borrow_check/mod.rs b/src/librustc_mir/borrow_check/mod.rs index c5236407d135f..3a783f674e9ae 100644 --- a/src/librustc_mir/borrow_check/mod.rs +++ b/src/librustc_mir/borrow_check/mod.rs @@ -301,7 +301,7 @@ fn do_mir_borrowck<'a, 'tcx>( mbcx.report_conflicting_borrow(location, (&place, span), bk, &borrow); let scope = mbcx.body.source_info(location).scope; - let lint_root = match &mbcx.body.source_scope_local_data[scope] { + let lint_root = match &mbcx.body.source_scopes[scope].local_data { ClearCrossCrate::Set(data) => data.lint_root, _ => id, }; @@ -338,7 +338,7 @@ fn do_mir_borrowck<'a, 'tcx>( let used_mut = mbcx.used_mut; for local in mbcx.body.mut_vars_and_args_iter().filter(|local| !used_mut.contains(local)) { let local_decl = &mbcx.body.local_decls[local]; - let lint_root = match &mbcx.body.source_scope_local_data[local_decl.source_info.scope] { + let lint_root = match &mbcx.body.source_scopes[local_decl.source_info.scope].local_data { ClearCrossCrate::Set(data) => data.lint_root, _ => continue, }; diff --git a/src/librustc_mir/build/mod.rs b/src/librustc_mir/build/mod.rs index 716e57dc4fba0..eb9b401f27208 100644 --- a/src/librustc_mir/build/mod.rs +++ b/src/librustc_mir/build/mod.rs @@ -309,7 +309,6 @@ struct Builder<'a, 'tcx> { /// The vector of all scopes that we have created thus far; /// we track this for debuginfo later. source_scopes: IndexVec, - source_scope_local_data: IndexVec>, source_scope: SourceScope, /// The guard-context: each time we build the guard expression for @@ -704,7 +703,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { block_context: BlockContext::new(), source_scopes: IndexVec::new(), source_scope: OUTERMOST_SOURCE_SCOPE, - source_scope_local_data: IndexVec::new(), guard_context: vec![], push_unsafe_count: 0, unpushed_unsafe: safety, @@ -741,7 +739,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { Body::new( self.cfg.basic_blocks, self.source_scopes, - self.source_scope_local_data, self.local_decls, self.canonical_user_type_annotations, self.arg_count, @@ -942,7 +939,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { self.hir.root_lint_level ); let parent_root = tcx.maybe_lint_level_root_bounded( - self.source_scope_local_data[original_source_scope] + self.source_scopes[original_source_scope] + .local_data .as_ref() .assert_crate_local() .lint_root, diff --git a/src/librustc_mir/build/scope.rs b/src/librustc_mir/build/scope.rs index d756a22a0002c..00a30af806a89 100644 --- a/src/librustc_mir/build/scope.rs +++ b/src/librustc_mir/build/scope.rs @@ -436,7 +436,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { // We estimate the true lint roots here to avoid creating a lot of source scopes. let parent_root = tcx.maybe_lint_level_root_bounded( - self.source_scope_local_data[source_scope] + self.source_scopes[source_scope] + .local_data .as_ref() .assert_crate_local() .lint_root, @@ -657,23 +658,22 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { let parent = self.source_scope; debug!("new_source_scope({:?}, {:?}, {:?}) - parent({:?})={:?}", span, lint_level, safety, - parent, self.source_scope_local_data.get(parent)); - let scope = self.source_scopes.push(SourceScopeData { - span, - parent_scope: Some(parent), - }); + parent, self.source_scopes.get(parent)); let scope_local_data = SourceScopeLocalData { lint_root: if let LintLevel::Explicit(lint_root) = lint_level { lint_root } else { - self.source_scope_local_data[parent].as_ref().assert_crate_local().lint_root + self.source_scopes[parent].local_data.as_ref().assert_crate_local().lint_root }, safety: safety.unwrap_or_else(|| { - self.source_scope_local_data[parent].as_ref().assert_crate_local().safety + self.source_scopes[parent].local_data.as_ref().assert_crate_local().safety }) }; - self.source_scope_local_data.push(ClearCrossCrate::Set(scope_local_data)); - scope + self.source_scopes.push(SourceScopeData { + span, + parent_scope: Some(parent), + local_data: ClearCrossCrate::Set(scope_local_data), + }) } /// Given a span and the current source scope, make a SourceInfo. diff --git a/src/librustc_mir/interpret/eval_context.rs b/src/librustc_mir/interpret/eval_context.rs index 4b07f217ab3f5..dc62cbefe3442 100644 --- a/src/librustc_mir/interpret/eval_context.rs +++ b/src/librustc_mir/interpret/eval_context.rs @@ -849,7 +849,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { } else { block.terminator().source_info }; - match &body.source_scope_local_data[source_info.scope] { + match &body.source_scopes[source_info.scope].local_data { mir::ClearCrossCrate::Set(data) => Some(data.lint_root), mir::ClearCrossCrate::Clear => None, } diff --git a/src/librustc_mir/shim.rs b/src/librustc_mir/shim.rs index e2466c6d07a43..708686fdcf9f1 100644 --- a/src/librustc_mir/shim.rs +++ b/src/librustc_mir/shim.rs @@ -248,10 +248,8 @@ fn new_body<'tcx>( Body::new( basic_blocks, IndexVec::from_elem_n( - SourceScopeData { span, parent_scope: None }, 1 - ), - IndexVec::from_elem_n( - ClearCrossCrate::Clear, 1 + SourceScopeData { span, parent_scope: None, local_data: ClearCrossCrate::Clear }, + 1, ), local_decls, IndexVec::new(), diff --git a/src/librustc_mir/transform/check_unsafety.rs b/src/librustc_mir/transform/check_unsafety.rs index b1c4101dbc759..d12d21aee6abe 100644 --- a/src/librustc_mir/transform/check_unsafety.rs +++ b/src/librustc_mir/transform/check_unsafety.rs @@ -214,7 +214,8 @@ impl<'a, 'tcx> Visitor<'tcx> for UnsafetyChecker<'a, 'tcx> { if context.is_borrow() { if util::is_disaligned(self.tcx, self.body, self.param_env, place) { let source_info = self.source_info; - let lint_root = self.body.source_scope_local_data[source_info.scope] + let lint_root = self.body.source_scopes[source_info.scope] + .local_data .as_ref() .assert_crate_local() .lint_root; @@ -343,7 +344,8 @@ impl<'a, 'tcx> UnsafetyChecker<'a, 'tcx> { fn register_violations(&mut self, violations: &[UnsafetyViolation], unsafe_blocks: &[(hir::HirId, bool)]) { - let safety = self.body.source_scope_local_data[self.source_info.scope] + let safety = self.body.source_scopes[self.source_info.scope] + .local_data .as_ref() .assert_crate_local() .safety; diff --git a/src/librustc_mir/transform/const_prop.rs b/src/librustc_mir/transform/const_prop.rs index 705006fabbe42..f9a012d400c47 100644 --- a/src/librustc_mir/transform/const_prop.rs +++ b/src/librustc_mir/transform/const_prop.rs @@ -9,7 +9,7 @@ use rustc::hir::def_id::DefId; use rustc::mir::{ AggregateKind, Constant, Location, Place, PlaceBase, Body, Operand, Rvalue, Local, UnOp, StatementKind, Statement, LocalKind, TerminatorKind, Terminator, ClearCrossCrate, SourceInfo, - BinOp, SourceScope, SourceScopeLocalData, LocalDecl, BasicBlock, RETURN_PLACE, + BinOp, SourceScope, SourceScopeData, LocalDecl, BasicBlock, RETURN_PLACE, }; use rustc::mir::visit::{ Visitor, PlaceContext, MutatingUseContext, MutVisitor, NonMutatingUseContext, @@ -77,8 +77,7 @@ impl<'tcx> MirPass<'tcx> for ConstProp { let dummy_body = &Body::new( body.basic_blocks().clone(), - Default::default(), - body.source_scope_local_data.clone(), + body.source_scopes.clone(), body.local_decls.clone(), Default::default(), body.arg_count, @@ -254,7 +253,7 @@ struct ConstPropagator<'mir, 'tcx> { param_env: ParamEnv<'tcx>, // FIXME(eddyb) avoid cloning these two fields more than once, // by accessing them through `ecx` instead. - source_scope_local_data: IndexVec>, + source_scopes: IndexVec, local_decls: IndexVec>, ret: Option>, } @@ -325,7 +324,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { can_const_prop, // FIXME(eddyb) avoid cloning these two fields more than once, // by accessing them through `ecx` instead. - source_scope_local_data: body.source_scope_local_data.clone(), + source_scopes: body.source_scopes.clone(), //FIXME(wesleywiser) we can't steal this because `Visitor::super_visit_body()` needs it local_decls: body.local_decls.clone(), ret: ret.map(Into::into), @@ -362,9 +361,9 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { { self.ecx.tcx.span = source_info.span; // FIXME(eddyb) move this to the `Panic(_)` error case, so that - // `f(self)` is always called, and that the only difference when - // `source_scope_local_data` is missing, is that the lint isn't emitted. - let lint_root = match &self.source_scope_local_data[source_info.scope] { + // `f(self)` is always called, and that the only difference when the + // scope's `local_data` is missing, is that the lint isn't emitted. + let lint_root = match &self.source_scopes[source_info.scope].local_data { ClearCrossCrate::Set(data) => data.lint_root, ClearCrossCrate::Clear => return None, }; @@ -489,7 +488,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { let right_size = r.layout.size; let r_bits = r.to_scalar().and_then(|r| r.to_bits(right_size)); if r_bits.ok().map_or(false, |b| b >= left_bits as u128) { - let lint_root = match &self.source_scope_local_data[source_info.scope] { + let lint_root = match &self.source_scopes[source_info.scope].local_data { ClearCrossCrate::Set(data) => data.lint_root, ClearCrossCrate::Clear => return None, }; diff --git a/src/librustc_mir/transform/inline.rs b/src/librustc_mir/transform/inline.rs index 70a0fb2d1035c..ebfadd0cfd3ed 100644 --- a/src/librustc_mir/transform/inline.rs +++ b/src/librustc_mir/transform/inline.rs @@ -388,8 +388,7 @@ impl Inliner<'tcx> { let mut local_map = IndexVec::with_capacity(callee_body.local_decls.len()); let mut scope_map = IndexVec::with_capacity(callee_body.source_scopes.len()); - for (callee_idx, scope) in callee_body.source_scopes.iter_enumerated() { - let mut scope = scope.clone(); + for mut scope in callee_body.source_scopes.iter().cloned() { if scope.parent_scope.is_none() { scope.parent_scope = Some(callsite.location.scope); // FIXME(eddyb) is this really needed? @@ -404,9 +403,6 @@ impl Inliner<'tcx> { let idx = caller_body.source_scopes.push(scope); scope_map.push(idx); - - let local_data = callee_body.source_scope_local_data[callee_idx].clone(); - assert_eq!(idx, caller_body.source_scope_local_data.push(local_data)); } for loc in callee_body.vars_and_temps_iter() { diff --git a/src/librustc_mir/transform/promote_consts.rs b/src/librustc_mir/transform/promote_consts.rs index cc6108c7dc095..591f3ca44009d 100644 --- a/src/librustc_mir/transform/promote_consts.rs +++ b/src/librustc_mir/transform/promote_consts.rs @@ -1081,7 +1081,6 @@ pub fn promote_candidates<'tcx>( // FIXME: maybe try to filter this to avoid blowing up // memory usage? body.source_scopes.clone(), - body.source_scope_local_data.clone(), initial_locals, IndexVec::new(), 0, From 02b66a19010c76e41805e65179e951ad1d41e0c7 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Wed, 27 Nov 2019 20:39:53 +0100 Subject: [PATCH 15/16] libunwind_panic: adjust miri panic hack --- src/libcore/intrinsics.rs | 4 ++- src/libpanic_unwind/lib.rs | 16 ++++++---- src/libpanic_unwind/miri.rs | 42 --------------------------- src/librustc_codegen_ssa/mir/block.rs | 15 +++------- 4 files changed, 18 insertions(+), 59 deletions(-) delete mode 100644 src/libpanic_unwind/miri.rs diff --git a/src/libcore/intrinsics.rs b/src/libcore/intrinsics.rs index e3dc5630c94b4..d4952f53bf7fe 100644 --- a/src/libcore/intrinsics.rs +++ b/src/libcore/intrinsics.rs @@ -1348,9 +1348,11 @@ extern "rust-intrinsic" { pub fn ptr_offset_from(ptr: *const T, base: *const T) -> isize; /// Internal hook used by Miri to implement unwinding. + /// Compiles to a NOP during non-Miri codegen. + /// /// Perma-unstable: do not use #[cfg(not(bootstrap))] - pub fn miri_start_panic(data: *mut (dyn crate::any::Any + crate::marker::Send)) -> !; + pub fn miri_start_panic(data: *mut (dyn crate::any::Any + crate::marker::Send)) -> (); } // Some functions are defined here because they accidentally got made diff --git a/src/libpanic_unwind/lib.rs b/src/libpanic_unwind/lib.rs index 0c834e5c2a05c..3a14197c77bec 100644 --- a/src/libpanic_unwind/lib.rs +++ b/src/libpanic_unwind/lib.rs @@ -36,10 +36,7 @@ use core::raw; use core::panic::BoxMeUp; cfg_if::cfg_if! { - if #[cfg(miri)] { - #[path = "miri.rs"] - mod imp; - } else if #[cfg(target_os = "emscripten")] { + if #[cfg(target_os = "emscripten")] { #[path = "emcc.rs"] mod imp; } else if #[cfg(target_arch = "wasm32")] { @@ -94,5 +91,14 @@ pub unsafe extern "C" fn __rust_maybe_catch_panic(f: fn(*mut u8), #[unwind(allowed)] pub unsafe extern "C" fn __rust_start_panic(payload: usize) -> u32 { let payload = payload as *mut &mut dyn BoxMeUp; - imp::panic(Box::from_raw((*payload).take_box())) + let payload = (*payload).take_box(); + + // Miri panic support: cfg'd out of normal builds just to be sure. + // When going through normal codegen, `miri_start_panic` is a NOP, so the + // Miri-enabled sysroot still supports normal unwinding. But when executed in + // Miri, this line initiates unwinding. + #[cfg(miri)] + core::intrinsics::miri_start_panic(payload); + + imp::panic(Box::from_raw(payload)) } diff --git a/src/libpanic_unwind/miri.rs b/src/libpanic_unwind/miri.rs deleted file mode 100644 index f26c42fd4bcba..0000000000000 --- a/src/libpanic_unwind/miri.rs +++ /dev/null @@ -1,42 +0,0 @@ -#![allow(nonstandard_style)] - -use core::any::Any; -use alloc::boxed::Box; - -pub fn payload() -> *mut u8 { - core::ptr::null_mut() -} - -pub unsafe fn panic(data: Box) -> ! { - core::intrinsics::miri_start_panic(Box::into_raw(data)) -} - -pub unsafe fn cleanup(ptr: *mut u8) -> Box { - Box::from_raw(ptr) -} - -// This is required by the compiler to exist (e.g., it's a lang item), -// but is never used by Miri. Therefore, we just use a stub here -#[lang = "eh_personality"] -#[cfg(not(test))] -fn rust_eh_personality() { - unsafe { core::intrinsics::abort() } -} - -// The rest is required on *some* targets to exist (specifically, MSVC targets that use SEH). -// We just add it on all targets. Copied from `seh.rs`. -#[repr(C)] -pub struct _TypeDescriptor { - pub pVFTable: *const u8, - pub spare: *mut u8, - pub name: [u8; 11], -} - -const TYPE_NAME: [u8; 11] = *b"rust_panic\0"; - -#[cfg_attr(not(test), lang = "eh_catch_typeinfo")] -static mut TYPE_DESCRIPTOR: _TypeDescriptor = _TypeDescriptor { - pVFTable: core::ptr::null(), - spare: core::ptr::null_mut(), - name: TYPE_NAME, -}; diff --git a/src/librustc_codegen_ssa/mir/block.rs b/src/librustc_codegen_ssa/mir/block.rs index 14be0e80fb482..d76392f7570b4 100644 --- a/src/librustc_codegen_ssa/mir/block.rs +++ b/src/librustc_codegen_ssa/mir/block.rs @@ -528,18 +528,11 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { _ => FnAbi::new(&bx, sig, &extra_args) }; - // This should never be reachable at runtime: - // We should only emit a call to this intrinsic in #[cfg(miri)] mode, - // which means that we will never actually use the generate object files - // (we will just be interpreting the MIR) - // - // Note that we still need to be able to codegen *something* for this intrisnic: - // Miri currently uses Xargo to build a special libstd. As a side effect, - // we generate normal object files for libstd - while these are never used, - // we still need to be able to build them. + // For normal codegen, this Miri-specific intrinsic is just a NOP. if intrinsic == Some("miri_start_panic") { - bx.abort(); - bx.unreachable(); + let target = destination.as_ref().unwrap().1; + helper.maybe_sideeffect(self.mir, &mut bx, &[target]); + helper.funclet_br(self, &mut bx, target); return; } From 9034efe3f707b7e7aed83b049035c63f290a16fa Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Sat, 30 Nov 2019 17:29:56 +0200 Subject: [PATCH 16/16] rustc: don't just show raw DefIndex's in BrNamed's fmt::Debug impl. --- src/librustc/ty/structural_impls.rs | 8 ++++++-- .../closure-requirements/escape-argument-callee.stderr | 2 +- .../ui/nll/closure-requirements/escape-argument.stderr | 2 +- .../propagate-approximated-fail-no-postdom.stderr | 2 +- .../propagate-approximated-ref.stderr | 2 +- ...imated-shorter-to-static-comparing-against-free.stderr | 4 ++-- ...opagate-approximated-shorter-to-static-no-bound.stderr | 2 +- ...gate-approximated-shorter-to-static-wrong-bound.stderr | 2 +- .../propagate-approximated-val.stderr | 2 +- .../propagate-despite-same-free-region.stderr | 2 +- .../propagate-fail-to-approximate-longer-no-bounds.stderr | 2 +- ...opagate-fail-to-approximate-longer-wrong-bounds.stderr | 2 +- .../closure-requirements/return-wrong-bound-region.stderr | 2 +- .../nll/ty-outlives/projection-one-region-closure.stderr | 2 +- .../projection-two-region-trait-bound-closure.stderr | 2 +- .../ty-param-closure-approximate-lower-bound.stderr | 6 +++--- .../ty-param-closure-outlives-from-where-clause.stderr | 4 ++-- 17 files changed, 26 insertions(+), 22 deletions(-) diff --git a/src/librustc/ty/structural_impls.rs b/src/librustc/ty/structural_impls.rs index ffbf8813d309d..ce76a4c831b58 100644 --- a/src/librustc/ty/structural_impls.rs +++ b/src/librustc/ty/structural_impls.rs @@ -3,6 +3,7 @@ //! hand, though we've recently added some macros and proc-macros to help with the tedium. use crate::hir::def::Namespace; +use crate::hir::def_id::CRATE_DEF_INDEX; use crate::mir::ProjectionKind; use crate::mir::interpret; use crate::ty::{self, Lift, Ty, TyCtxt, InferConst}; @@ -95,8 +96,11 @@ impl fmt::Debug for ty::BoundRegion { match *self { ty::BrAnon(n) => write!(f, "BrAnon({:?})", n), ty::BrNamed(did, name) => { - write!(f, "BrNamed({:?}:{:?}, {})", - did.krate, did.index, name) + if did.index == CRATE_DEF_INDEX { + write!(f, "BrNamed({})", name) + } else { + write!(f, "BrNamed({:?}, {})", did, name) + } } ty::BrEnv => write!(f, "BrEnv"), } diff --git a/src/test/ui/nll/closure-requirements/escape-argument-callee.stderr b/src/test/ui/nll/closure-requirements/escape-argument-callee.stderr index 1f15ce5c212f4..abeffee4d3fc2 100644 --- a/src/test/ui/nll/closure-requirements/escape-argument-callee.stderr +++ b/src/test/ui/nll/closure-requirements/escape-argument-callee.stderr @@ -6,7 +6,7 @@ LL | let mut closure = expect_sig(|p, y| *p = y); | = note: defining type: DefId(0:4 ~ escape_argument_callee[317d]::test[0]::{{closure}}[0]) with closure substs [ i16, - for<'r, 's, 't0> extern "rust-call" fn((&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 'r)) mut &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 's)) i32, &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 't0)) i32)), + for<'r, 's, 't0> extern "rust-call" fn((&ReLateBound(DebruijnIndex(0), BrNamed('r)) mut &ReLateBound(DebruijnIndex(0), BrNamed('s)) i32, &ReLateBound(DebruijnIndex(0), BrNamed('t0)) i32)), ] error: lifetime may not live long enough diff --git a/src/test/ui/nll/closure-requirements/escape-argument.stderr b/src/test/ui/nll/closure-requirements/escape-argument.stderr index 610a4aed796c6..f750d15533bc4 100644 --- a/src/test/ui/nll/closure-requirements/escape-argument.stderr +++ b/src/test/ui/nll/closure-requirements/escape-argument.stderr @@ -6,7 +6,7 @@ LL | let mut closure = expect_sig(|p, y| *p = y); | = note: defining type: DefId(0:4 ~ escape_argument[317d]::test[0]::{{closure}}[0]) with closure substs [ i16, - for<'r, 's> extern "rust-call" fn((&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 'r)) mut &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 's)) i32, &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 's)) i32)), + for<'r, 's> extern "rust-call" fn((&ReLateBound(DebruijnIndex(0), BrNamed('r)) mut &ReLateBound(DebruijnIndex(0), BrNamed('s)) i32, &ReLateBound(DebruijnIndex(0), BrNamed('s)) i32)), ] note: No external requirements diff --git a/src/test/ui/nll/closure-requirements/propagate-approximated-fail-no-postdom.stderr b/src/test/ui/nll/closure-requirements/propagate-approximated-fail-no-postdom.stderr index 43406c05a2500..92f30d400f26e 100644 --- a/src/test/ui/nll/closure-requirements/propagate-approximated-fail-no-postdom.stderr +++ b/src/test/ui/nll/closure-requirements/propagate-approximated-fail-no-postdom.stderr @@ -10,7 +10,7 @@ LL | | }, | = note: defining type: DefId(0:18 ~ propagate_approximated_fail_no_postdom[317d]::supply[0]::{{closure}}[0]) with closure substs [ i16, - for<'r, 's> extern "rust-call" fn((std::cell::Cell<&'_#1r &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 'r)) u32>, std::cell::Cell<&'_#2r &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 'r)) u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 's)) &'_#3r u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 'r)) u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 's)) u32>)), + for<'r, 's> extern "rust-call" fn((std::cell::Cell<&'_#1r &ReLateBound(DebruijnIndex(0), BrNamed('r)) u32>, std::cell::Cell<&'_#2r &ReLateBound(DebruijnIndex(0), BrNamed('r)) u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed('s)) &'_#3r u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed('r)) u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed('s)) u32>)), ] = note: late-bound region is '_#4r = note: late-bound region is '_#5r diff --git a/src/test/ui/nll/closure-requirements/propagate-approximated-ref.stderr b/src/test/ui/nll/closure-requirements/propagate-approximated-ref.stderr index 6f5b813e85e35..00bb66afbe538 100644 --- a/src/test/ui/nll/closure-requirements/propagate-approximated-ref.stderr +++ b/src/test/ui/nll/closure-requirements/propagate-approximated-ref.stderr @@ -11,7 +11,7 @@ LL | | }); | = note: defining type: DefId(0:16 ~ propagate_approximated_ref[317d]::supply[0]::{{closure}}[0]) with closure substs [ i16, - for<'r, 's, 't0, 't1, 't2, 't3> extern "rust-call" fn((&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 'r)) std::cell::Cell<&'_#1r &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 's)) u32>, &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 't0)) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 't1)) &'_#2r u32>, &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 't2)) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 's)) u32>, &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 't3)) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 't1)) u32>)), + for<'r, 's, 't0, 't1, 't2, 't3> extern "rust-call" fn((&ReLateBound(DebruijnIndex(0), BrNamed('r)) std::cell::Cell<&'_#1r &ReLateBound(DebruijnIndex(0), BrNamed('s)) u32>, &ReLateBound(DebruijnIndex(0), BrNamed('t0)) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed('t1)) &'_#2r u32>, &ReLateBound(DebruijnIndex(0), BrNamed('t2)) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed('s)) u32>, &ReLateBound(DebruijnIndex(0), BrNamed('t3)) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed('t1)) u32>)), ] = note: late-bound region is '_#3r = note: late-bound region is '_#4r diff --git a/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-comparing-against-free.stderr b/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-comparing-against-free.stderr index 5ebc22da0365f..2b05503b58dbe 100644 --- a/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-comparing-against-free.stderr +++ b/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-comparing-against-free.stderr @@ -10,7 +10,7 @@ LL | | }) | = note: defining type: DefId(0:9 ~ propagate_approximated_shorter_to_static_comparing_against_free[317d]::case1[0]::{{closure}}[0]) with closure substs [ i32, - for<'r> extern "rust-call" fn((std::cell::Cell<&'_#1r u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 'r)) u32>)), + for<'r> extern "rust-call" fn((std::cell::Cell<&'_#1r u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed('r)) u32>)), ] error[E0521]: borrowed data escapes outside of closure @@ -48,7 +48,7 @@ LL | | }) | = note: defining type: DefId(0:11 ~ propagate_approximated_shorter_to_static_comparing_against_free[317d]::case2[0]::{{closure}}[0]) with closure substs [ i32, - for<'r> extern "rust-call" fn((std::cell::Cell<&'_#1r u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 'r)) u32>)), + for<'r> extern "rust-call" fn((std::cell::Cell<&'_#1r u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed('r)) u32>)), ] = note: number of external vids: 2 = note: where '_#1r: '_#0r diff --git a/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-no-bound.stderr b/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-no-bound.stderr index 5ebf8e248b368..ee0f0b7e65dd8 100644 --- a/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-no-bound.stderr +++ b/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-no-bound.stderr @@ -12,7 +12,7 @@ LL | | }); | = note: defining type: DefId(0:16 ~ propagate_approximated_shorter_to_static_no_bound[317d]::supply[0]::{{closure}}[0]) with closure substs [ i16, - for<'r, 's, 't0, 't1, 't2> extern "rust-call" fn((&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 'r)) std::cell::Cell<&'_#1r &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 's)) u32>, &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 't0)) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 's)) u32>, &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 't1)) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 't2)) u32>)), + for<'r, 's, 't0, 't1, 't2> extern "rust-call" fn((&ReLateBound(DebruijnIndex(0), BrNamed('r)) std::cell::Cell<&'_#1r &ReLateBound(DebruijnIndex(0), BrNamed('s)) u32>, &ReLateBound(DebruijnIndex(0), BrNamed('t0)) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed('s)) u32>, &ReLateBound(DebruijnIndex(0), BrNamed('t1)) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed('t2)) u32>)), ] = note: late-bound region is '_#2r = note: late-bound region is '_#3r diff --git a/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-wrong-bound.stderr b/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-wrong-bound.stderr index 91caa42c9bf7b..611a129e00c83 100644 --- a/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-wrong-bound.stderr +++ b/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-wrong-bound.stderr @@ -12,7 +12,7 @@ LL | | }); | = note: defining type: DefId(0:16 ~ propagate_approximated_shorter_to_static_wrong_bound[317d]::supply[0]::{{closure}}[0]) with closure substs [ i16, - for<'r, 's, 't0, 't1, 't2, 't3> extern "rust-call" fn((&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 'r)) std::cell::Cell<&'_#1r &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 's)) u32>, &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 't0)) std::cell::Cell<&'_#2r &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 't1)) u32>, &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 't2)) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 's)) u32>, &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 't3)) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 't1)) u32>)), + for<'r, 's, 't0, 't1, 't2, 't3> extern "rust-call" fn((&ReLateBound(DebruijnIndex(0), BrNamed('r)) std::cell::Cell<&'_#1r &ReLateBound(DebruijnIndex(0), BrNamed('s)) u32>, &ReLateBound(DebruijnIndex(0), BrNamed('t0)) std::cell::Cell<&'_#2r &ReLateBound(DebruijnIndex(0), BrNamed('t1)) u32>, &ReLateBound(DebruijnIndex(0), BrNamed('t2)) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed('s)) u32>, &ReLateBound(DebruijnIndex(0), BrNamed('t3)) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed('t1)) u32>)), ] = note: late-bound region is '_#3r = note: late-bound region is '_#4r diff --git a/src/test/ui/nll/closure-requirements/propagate-approximated-val.stderr b/src/test/ui/nll/closure-requirements/propagate-approximated-val.stderr index 243c8b12ecb4b..9328d05518c67 100644 --- a/src/test/ui/nll/closure-requirements/propagate-approximated-val.stderr +++ b/src/test/ui/nll/closure-requirements/propagate-approximated-val.stderr @@ -11,7 +11,7 @@ LL | | }); | = note: defining type: DefId(0:16 ~ propagate_approximated_val[317d]::test[0]::{{closure}}[0]) with closure substs [ i16, - for<'r, 's> extern "rust-call" fn((std::cell::Cell<&'_#1r &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 'r)) u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 's)) &'_#2r u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 'r)) u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 's)) u32>)), + for<'r, 's> extern "rust-call" fn((std::cell::Cell<&'_#1r &ReLateBound(DebruijnIndex(0), BrNamed('r)) u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed('s)) &'_#2r u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed('r)) u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed('s)) u32>)), ] = note: late-bound region is '_#3r = note: late-bound region is '_#4r diff --git a/src/test/ui/nll/closure-requirements/propagate-despite-same-free-region.stderr b/src/test/ui/nll/closure-requirements/propagate-despite-same-free-region.stderr index c5468e73cfa08..afac5267c4866 100644 --- a/src/test/ui/nll/closure-requirements/propagate-despite-same-free-region.stderr +++ b/src/test/ui/nll/closure-requirements/propagate-despite-same-free-region.stderr @@ -10,7 +10,7 @@ LL | | }, | = note: defining type: DefId(0:14 ~ propagate_despite_same_free_region[317d]::supply[0]::{{closure}}[0]) with closure substs [ i16, - for<'r, 's> extern "rust-call" fn((std::cell::Cell<&'_#1r &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 'r)) u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 's)) &'_#2r u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 'r)) u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 's)) u32>)), + for<'r, 's> extern "rust-call" fn((std::cell::Cell<&'_#1r &ReLateBound(DebruijnIndex(0), BrNamed('r)) u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed('s)) &'_#2r u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed('r)) u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed('s)) u32>)), ] = note: late-bound region is '_#3r = note: number of external vids: 4 diff --git a/src/test/ui/nll/closure-requirements/propagate-fail-to-approximate-longer-no-bounds.stderr b/src/test/ui/nll/closure-requirements/propagate-fail-to-approximate-longer-no-bounds.stderr index bf43c89386547..9699e8fbdf8e5 100644 --- a/src/test/ui/nll/closure-requirements/propagate-fail-to-approximate-longer-no-bounds.stderr +++ b/src/test/ui/nll/closure-requirements/propagate-fail-to-approximate-longer-no-bounds.stderr @@ -11,7 +11,7 @@ LL | | }); | = note: defining type: DefId(0:16 ~ propagate_fail_to_approximate_longer_no_bounds[317d]::supply[0]::{{closure}}[0]) with closure substs [ i16, - for<'r, 's, 't0, 't1, 't2> extern "rust-call" fn((&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 'r)) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 's)) &'_#1r u32>, &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 't0)) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 't1)) u32>, &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 't2)) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 's)) u32>)), + for<'r, 's, 't0, 't1, 't2> extern "rust-call" fn((&ReLateBound(DebruijnIndex(0), BrNamed('r)) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed('s)) &'_#1r u32>, &ReLateBound(DebruijnIndex(0), BrNamed('t0)) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed('t1)) u32>, &ReLateBound(DebruijnIndex(0), BrNamed('t2)) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed('s)) u32>)), ] = note: late-bound region is '_#2r = note: late-bound region is '_#3r diff --git a/src/test/ui/nll/closure-requirements/propagate-fail-to-approximate-longer-wrong-bounds.stderr b/src/test/ui/nll/closure-requirements/propagate-fail-to-approximate-longer-wrong-bounds.stderr index 569bae999dd27..2a18079cdc3a3 100644 --- a/src/test/ui/nll/closure-requirements/propagate-fail-to-approximate-longer-wrong-bounds.stderr +++ b/src/test/ui/nll/closure-requirements/propagate-fail-to-approximate-longer-wrong-bounds.stderr @@ -11,7 +11,7 @@ LL | | }); | = note: defining type: DefId(0:16 ~ propagate_fail_to_approximate_longer_wrong_bounds[317d]::supply[0]::{{closure}}[0]) with closure substs [ i16, - for<'r, 's, 't0, 't1, 't2, 't3> extern "rust-call" fn((&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 'r)) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 's)) &'_#1r u32>, &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 't0)) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 't1)) &'_#2r u32>, &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 't2)) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 's)) u32>, &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 't3)) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 't1)) u32>)), + for<'r, 's, 't0, 't1, 't2, 't3> extern "rust-call" fn((&ReLateBound(DebruijnIndex(0), BrNamed('r)) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed('s)) &'_#1r u32>, &ReLateBound(DebruijnIndex(0), BrNamed('t0)) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed('t1)) &'_#2r u32>, &ReLateBound(DebruijnIndex(0), BrNamed('t2)) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed('s)) u32>, &ReLateBound(DebruijnIndex(0), BrNamed('t3)) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed('t1)) u32>)), ] = note: late-bound region is '_#3r = note: late-bound region is '_#4r diff --git a/src/test/ui/nll/closure-requirements/return-wrong-bound-region.stderr b/src/test/ui/nll/closure-requirements/return-wrong-bound-region.stderr index 00c56a796d1b6..8ce0b7758b05b 100644 --- a/src/test/ui/nll/closure-requirements/return-wrong-bound-region.stderr +++ b/src/test/ui/nll/closure-requirements/return-wrong-bound-region.stderr @@ -6,7 +6,7 @@ LL | expect_sig(|a, b| b); // ought to return `a` | = note: defining type: DefId(0:4 ~ return_wrong_bound_region[317d]::test[0]::{{closure}}[0]) with closure substs [ i16, - for<'r, 's> extern "rust-call" fn((&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 'r)) i32, &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 's)) i32)) -> &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 'r)) i32, + for<'r, 's> extern "rust-call" fn((&ReLateBound(DebruijnIndex(0), BrNamed('r)) i32, &ReLateBound(DebruijnIndex(0), BrNamed('s)) i32)) -> &ReLateBound(DebruijnIndex(0), BrNamed('r)) i32, ] error: lifetime may not live long enough diff --git a/src/test/ui/nll/ty-outlives/projection-one-region-closure.stderr b/src/test/ui/nll/ty-outlives/projection-one-region-closure.stderr index d33f672229860..d9cbc71f95456 100644 --- a/src/test/ui/nll/ty-outlives/projection-one-region-closure.stderr +++ b/src/test/ui/nll/ty-outlives/projection-one-region-closure.stderr @@ -38,7 +38,7 @@ error[E0309]: the parameter type `T` may not live long enough LL | with_signature(cell, t, |cell, t| require(cell, t)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = help: consider adding an explicit lifetime bound `T: ReFree(DefId(0:15 ~ projection_one_region_closure[317d]::no_relationships_late[0]), BrNamed(crate0:DefIndex(16), 'a))`... + = help: consider adding an explicit lifetime bound `T: ReFree(DefId(0:15 ~ projection_one_region_closure[317d]::no_relationships_late[0]), BrNamed(DefId(0:16 ~ projection_one_region_closure[317d]::no_relationships_late[0]::'a[0]), 'a))`... error: lifetime may not live long enough --> $DIR/projection-one-region-closure.rs:45:39 diff --git a/src/test/ui/nll/ty-outlives/projection-two-region-trait-bound-closure.stderr b/src/test/ui/nll/ty-outlives/projection-two-region-trait-bound-closure.stderr index ed548a3b4e210..ed53ce9113393 100644 --- a/src/test/ui/nll/ty-outlives/projection-two-region-trait-bound-closure.stderr +++ b/src/test/ui/nll/ty-outlives/projection-two-region-trait-bound-closure.stderr @@ -39,7 +39,7 @@ error[E0309]: the associated type `>::AssocType` may LL | with_signature(cell, t, |cell, t| require(cell, t)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = help: consider adding an explicit lifetime bound `>::AssocType: ReFree(DefId(0:17 ~ projection_two_region_trait_bound_closure[317d]::no_relationships_late[0]), BrNamed(crate0:DefIndex(18), 'a))`... + = help: consider adding an explicit lifetime bound `>::AssocType: ReFree(DefId(0:17 ~ projection_two_region_trait_bound_closure[317d]::no_relationships_late[0]), BrNamed(DefId(0:18 ~ projection_two_region_trait_bound_closure[317d]::no_relationships_late[0]::'a[0]), 'a))`... note: External requirements --> $DIR/projection-two-region-trait-bound-closure.rs:48:29 diff --git a/src/test/ui/nll/ty-outlives/ty-param-closure-approximate-lower-bound.stderr b/src/test/ui/nll/ty-outlives/ty-param-closure-approximate-lower-bound.stderr index fd8d8917c1878..e2a9bd7e3cd08 100644 --- a/src/test/ui/nll/ty-outlives/ty-param-closure-approximate-lower-bound.stderr +++ b/src/test/ui/nll/ty-outlives/ty-param-closure-approximate-lower-bound.stderr @@ -7,7 +7,7 @@ LL | twice(cell, value, |a, b| invoke(a, b)); = note: defining type: DefId(0:11 ~ ty_param_closure_approximate_lower_bound[317d]::generic[0]::{{closure}}[0]) with closure substs [ T, i16, - for<'r, 's> extern "rust-call" fn((std::option::Option>, &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 's)) T)), + for<'r, 's> extern "rust-call" fn((std::option::Option>, &ReLateBound(DebruijnIndex(0), BrNamed('s)) T)), ] = note: number of external vids: 2 = note: where T: '_#1r @@ -34,7 +34,7 @@ LL | twice(cell, value, |a, b| invoke(a, b)); = note: defining type: DefId(0:15 ~ ty_param_closure_approximate_lower_bound[317d]::generic_fail[0]::{{closure}}[0]) with closure substs [ T, i16, - for<'r, 's> extern "rust-call" fn((std::option::Option>, &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 's)) T)), + for<'r, 's> extern "rust-call" fn((std::option::Option>, &ReLateBound(DebruijnIndex(0), BrNamed('s)) T)), ] = note: late-bound region is '_#2r = note: number of external vids: 3 @@ -59,7 +59,7 @@ error[E0309]: the parameter type `T` may not live long enough LL | twice(cell, value, |a, b| invoke(a, b)); | ^^^^^^^^^^^^^^^^^^^ | - = help: consider adding an explicit lifetime bound `T: ReFree(DefId(0:12 ~ ty_param_closure_approximate_lower_bound[317d]::generic_fail[0]), BrNamed(crate0:DefIndex(13), 'a))`... + = help: consider adding an explicit lifetime bound `T: ReFree(DefId(0:12 ~ ty_param_closure_approximate_lower_bound[317d]::generic_fail[0]), BrNamed(DefId(0:13 ~ ty_param_closure_approximate_lower_bound[317d]::generic_fail[0]::'a[0]), 'a))`... error: aborting due to previous error diff --git a/src/test/ui/nll/ty-outlives/ty-param-closure-outlives-from-where-clause.stderr b/src/test/ui/nll/ty-outlives/ty-param-closure-outlives-from-where-clause.stderr index 97b84d1bdf801..ffd936b58be37 100644 --- a/src/test/ui/nll/ty-outlives/ty-param-closure-outlives-from-where-clause.stderr +++ b/src/test/ui/nll/ty-outlives/ty-param-closure-outlives-from-where-clause.stderr @@ -49,7 +49,7 @@ LL | | require(&x, &y) LL | | }) | |_____^ | - = help: consider adding an explicit lifetime bound `T: ReFree(DefId(0:11 ~ ty_param_closure_outlives_from_where_clause[317d]::no_region[0]), BrNamed(crate0:DefIndex(12), 'a))`... + = help: consider adding an explicit lifetime bound `T: ReFree(DefId(0:11 ~ ty_param_closure_outlives_from_where_clause[317d]::no_region[0]), BrNamed(DefId(0:12 ~ ty_param_closure_outlives_from_where_clause[317d]::no_region[0]::'a[0]), 'a))`... note: External requirements --> $DIR/ty-param-closure-outlives-from-where-clause.rs:43:26 @@ -139,7 +139,7 @@ LL | | require(&x, &y) LL | | }) | |_____^ | - = help: consider adding an explicit lifetime bound `T: ReFree(DefId(0:19 ~ ty_param_closure_outlives_from_where_clause[317d]::wrong_region[0]), BrNamed(crate0:DefIndex(20), 'a))`... + = help: consider adding an explicit lifetime bound `T: ReFree(DefId(0:19 ~ ty_param_closure_outlives_from_where_clause[317d]::wrong_region[0]), BrNamed(DefId(0:20 ~ ty_param_closure_outlives_from_where_clause[317d]::wrong_region[0]::'a[0]), 'a))`... note: External requirements --> $DIR/ty-param-closure-outlives-from-where-clause.rs:77:26