From 6fb5b73cf4dcf69e72ae414e83c53fe5eb8f0ffe Mon Sep 17 00:00:00 2001 From: Clar Fon Date: Tue, 22 Jan 2019 17:51:33 -0500 Subject: [PATCH 01/36] dbg!() without parameters. --- src/libstd/macros.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/libstd/macros.rs b/src/libstd/macros.rs index b87257188df10..cfb8336e54005 100644 --- a/src/libstd/macros.rs +++ b/src/libstd/macros.rs @@ -305,10 +305,16 @@ macro_rules! eprintln { /// let _ = dbg!(a); // <-- `a` is moved again; error! /// ``` /// +/// You can also use `dbg!()` without a value to just print the +/// file and line whenever it's reached. +/// /// [stderr]: https://en.wikipedia.org/wiki/Standard_streams#Standard_error_(stderr) #[macro_export] #[stable(feature = "dbg_macro", since = "1.32.0")] macro_rules! dbg { + () => { + eprintln!("[{}:{}]", file!(), line!()); + }; ($val:expr) => { // Use of `match` here is intentional because it affects the lifetimes // of temporaries - https://stackoverflow.com/a/48732525/1063961 From ea9e2c4ef5cf2d1867b284bd4f84b5417d8df45b Mon Sep 17 00:00:00 2001 From: Clar Fon Date: Thu, 31 Jan 2019 00:43:49 -0500 Subject: [PATCH 02/36] Test behaviour --- .../dbg-macro-expected-behavior.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/test/ui/rfc-2361-dbg-macro/dbg-macro-expected-behavior.rs b/src/test/ui/rfc-2361-dbg-macro/dbg-macro-expected-behavior.rs index 3d24f49ad7509..67f7f80a9e2da 100644 --- a/src/test/ui/rfc-2361-dbg-macro/dbg-macro-expected-behavior.rs +++ b/src/test/ui/rfc-2361-dbg-macro/dbg-macro-expected-behavior.rs @@ -33,6 +33,9 @@ fn test() { // We can move `b` because it's Copy. drop(b); + // Without parameters works as expected. + let _: () = dbg!(); + // Test that we can borrow and that successive applications is still identity. let a = NoCopy(1337); let b: &NoCopy = dbg!(dbg!(&a)); @@ -69,17 +72,19 @@ fn validate_stderr(stderr: Vec) { " y: 24", "}", - ":38] &a = NoCopy(", + ":37]", + + ":41] &a = NoCopy(", " 1337", ")", - ":38] dbg!(& a) = NoCopy(", + ":41] dbg!(& a) = NoCopy(", " 1337", ")", - ":43] f(&42) = 42", + ":46] f(&42) = 42", "before", - ":48] { foo += 1; eprintln!(\"before\"); 7331 } = 7331", + ":51] { foo += 1; eprintln!(\"before\"); 7331 } = 7331", ]); } From c5fe4055a90d0dac5dc80178d58148c042c5de2b Mon Sep 17 00:00:00 2001 From: Jon Gjengset Date: Thu, 28 Feb 2019 10:23:13 -0500 Subject: [PATCH 03/36] Clarify distinction between floor() and trunc() --- src/libstd/f32.rs | 12 ++++++++---- src/libstd/f64.rs | 12 ++++++++---- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/libstd/f32.rs b/src/libstd/f32.rs index f6cd9e82abd40..1636208f46f90 100644 --- a/src/libstd/f32.rs +++ b/src/libstd/f32.rs @@ -32,11 +32,13 @@ impl f32 { /// # Examples /// /// ``` - /// let f = 3.99_f32; + /// let f = 3.7_f32; /// let g = 3.0_f32; + /// let h = -3.7_f32; /// /// assert_eq!(f.floor(), 3.0); /// assert_eq!(g.floor(), 3.0); + /// assert_eq!(h.floor(), -4.0); /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[inline] @@ -104,11 +106,13 @@ impl f32 { /// # Examples /// /// ``` - /// let f = 3.3_f32; - /// let g = -3.7_f32; + /// let f = 3.7_f32; + /// let g = 3.0_f32; + /// let h = -3.7_f32; /// /// assert_eq!(f.trunc(), 3.0); - /// assert_eq!(g.trunc(), -3.0); + /// assert_eq!(g.trunc(), 3.0); + /// assert_eq!(h.trunc(), -3.0); /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[inline] diff --git a/src/libstd/f64.rs b/src/libstd/f64.rs index 8ff97ab828a73..71605618cf66e 100644 --- a/src/libstd/f64.rs +++ b/src/libstd/f64.rs @@ -32,11 +32,13 @@ impl f64 { /// # Examples /// /// ``` - /// let f = 3.99_f64; + /// let f = 3.7_f64; /// let g = 3.0_f64; + /// let h = -3.7_f64; /// /// assert_eq!(f.floor(), 3.0); /// assert_eq!(g.floor(), 3.0); + /// assert_eq!(h.floor(), -4.0); /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[inline] @@ -84,11 +86,13 @@ impl f64 { /// # Examples /// /// ``` - /// let f = 3.3_f64; - /// let g = -3.7_f64; + /// let f = 3.7_f64; + /// let g = 3.0_f64; + /// let h = -3.7_f64; /// /// assert_eq!(f.trunc(), 3.0); - /// assert_eq!(g.trunc(), -3.0); + /// assert_eq!(g.trunc(), 3.0); + /// assert_eq!(h.trunc(), -3.0); /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[inline] From b91ab6287952e8ff4f6d6765ed5196825027c903 Mon Sep 17 00:00:00 2001 From: Taeguk Kwon Date: Tue, 5 Mar 2019 23:08:01 +0900 Subject: [PATCH 04/36] Fix a tiny error in documentation of std::pin. --- src/libcore/pin.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcore/pin.rs b/src/libcore/pin.rs index fb78f5e5a2384..8da24c0451051 100644 --- a/src/libcore/pin.rs +++ b/src/libcore/pin.rs @@ -109,7 +109,7 @@ //! assert_eq!(still_unmoved.slice, NonNull::from(&still_unmoved.data)); //! //! // Since our type doesn't implement Unpin, this will fail to compile: -//! // let new_unmoved = Unmovable::new("world".to_string()); +//! // let mut new_unmoved = Unmovable::new("world".to_string()); //! // std::mem::swap(&mut *still_unmoved, &mut *new_unmoved); //! ``` //! From 96e361f6f4319782159164ceac6e1d660e383fcb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Vicente=20Milack?= Date: Mon, 4 Mar 2019 10:37:15 -0300 Subject: [PATCH 05/36] Fix buffer invalidation for BufRead There are two moments when a BufRead object needs to empty it's internal buffer: - In a seek call; - In a read call when all data in the internal buffer had been already consumed and the output buffer has a greater or equal size than the internal buffer. In both cases, the buffer was not being properly emptied, but only marked as consumed (self.pos = self.cap). That should be no problem if the inner reader is only Read, but if it is Seek as well, then it's possible to access the data in the buffer by using the seek_relative method. In order to prevent this from happening, both self.pos and self.cap should be set to 0. Two test cases were added to detect that failure: - test_buffered_reader_invalidated_after_read - test_buffered_reader_invalidated_after_seek Both tests are very similar to each other. The inner reader contains the following data: [5, 6, 7, 0, 1, 2, 3, 4]. The buffer capacity is 3 bytes. - First, we call fill_buffer, which loads [5, 6, 7] into the internal buffer, and then consume those 3 bytes. - Then we either read the 5 remaining bytes in a single read call or we move to the end of the stream by calling seek. In both cases the buffer should be emptied to prevent the previous data [5, 6, 7] from being read. - We now call seek_relative(-2) and read two bytes, which should give us the last 2 bytes of the stream: [3, 4]. Before this commit, the the seek_relative method would consider that we're still in the range of the internal buffer, so instead of fetching data from the inner reader, it would return the two last bytes that were incorrectly still in the buffer: [6, 7]. Therefore, the test would fail. Now, when seek_relative is called the buffer is empty. So the expected data [3, 4] is fetched from the inner reader and the test passes. --- src/libstd/io/buffered.rs | 45 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/src/libstd/io/buffered.rs b/src/libstd/io/buffered.rs index 559a54d3c8aca..365b1e5974737 100644 --- a/src/libstd/io/buffered.rs +++ b/src/libstd/io/buffered.rs @@ -225,6 +225,9 @@ impl Read for BufReader { // (larger than our internal buffer), bypass our internal buffer // entirely. if self.pos == self.cap && buf.len() >= self.buf.len() { + // Empty the buffer + self.cap = 0; + self.pos = 0; return self.inner.read(buf); } let nread = { @@ -323,14 +326,18 @@ impl Seek for BufReader { } else { // seek backwards by our remainder, and then by the offset self.inner.seek(SeekFrom::Current(-remainder))?; - self.pos = self.cap; // empty the buffer + // Empty the buffer + self.cap = 0; + self.pos = 0; result = self.inner.seek(SeekFrom::Current(n))?; } } else { // Seeking with Start/End doesn't care about our buffer length. result = self.inner.seek(pos)?; } - self.pos = self.cap; // empty the buffer + // Empty the buffer + self.cap = 0; + self.pos = 0; Ok(result) } } @@ -1066,6 +1073,40 @@ mod tests { assert_eq!(reader.fill_buf().ok(), Some(&[2, 3][..])); } + #[test] + fn test_buffered_reader_invalidated_after_read() { + let inner: &[u8] = &[5, 6, 7, 0, 1, 2, 3, 4]; + let mut reader = BufReader::with_capacity(3, io::Cursor::new(inner)); + + assert_eq!(reader.fill_buf().ok(), Some(&[5, 6, 7][..])); + reader.consume(3); + + let mut buffer = [0, 0, 0, 0, 0]; + assert_eq!(reader.read(&mut buffer).ok(), Some(5)); + assert_eq!(buffer, [0, 1, 2, 3, 4]); + + assert!(reader.seek_relative(-2).is_ok()); + let mut buffer = [0, 0]; + assert_eq!(reader.read(&mut buffer).ok(), Some(2)); + assert_eq!(buffer, [3, 4]); + } + + #[test] + fn test_buffered_reader_invalidated_after_seek() { + let inner: &[u8] = &[5, 6, 7, 0, 1, 2, 3, 4]; + let mut reader = BufReader::with_capacity(3, io::Cursor::new(inner)); + + assert_eq!(reader.fill_buf().ok(), Some(&[5, 6, 7][..])); + reader.consume(3); + + assert!(reader.seek(SeekFrom::Current(5)).is_ok()); + + assert!(reader.seek_relative(-2).is_ok()); + let mut buffer = [0, 0]; + assert_eq!(reader.read(&mut buffer).ok(), Some(2)); + assert_eq!(buffer, [3, 4]); + } + #[test] fn test_buffered_reader_seek_underflow() { // gimmick reader that yields its position modulo 256 for each byte From c36d91c5cc446a4688186be1071e0e139ba9d38f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Vicente=20Milack?= Date: Wed, 6 Mar 2019 16:22:28 -0300 Subject: [PATCH 06/36] Fix buffer invalidation at BufReader.read_vectored --- src/libstd/io/buffered.rs | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/libstd/io/buffered.rs b/src/libstd/io/buffered.rs index 365b1e5974737..fd4b582d7f2da 100644 --- a/src/libstd/io/buffered.rs +++ b/src/libstd/io/buffered.rs @@ -191,6 +191,13 @@ impl BufReader { /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn into_inner(self) -> R { self.inner } + + /// Invalidates all data in the internal buffer. + #[inline] + fn discard_buffer(&mut self) { + self.pos = 0; + self.cap = 0; + } } impl BufReader { @@ -225,9 +232,7 @@ impl Read for BufReader { // (larger than our internal buffer), bypass our internal buffer // entirely. if self.pos == self.cap && buf.len() >= self.buf.len() { - // Empty the buffer - self.cap = 0; - self.pos = 0; + self.discard_buffer(); return self.inner.read(buf); } let nread = { @@ -241,6 +246,7 @@ impl Read for BufReader { fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { let total_len = bufs.iter().map(|b| b.len()).sum::(); if self.pos == self.cap && total_len >= self.buf.len() { + self.discard_buffer(); return self.inner.read_vectored(bufs); } let nread = { @@ -326,18 +332,14 @@ impl Seek for BufReader { } else { // seek backwards by our remainder, and then by the offset self.inner.seek(SeekFrom::Current(-remainder))?; - // Empty the buffer - self.cap = 0; - self.pos = 0; + self.discard_buffer(); result = self.inner.seek(SeekFrom::Current(n))?; } } else { // Seeking with Start/End doesn't care about our buffer length. result = self.inner.seek(pos)?; } - // Empty the buffer - self.cap = 0; - self.pos = 0; + self.discard_buffer(); Ok(result) } } From b9d12edd6ce7b364fb1a4de53f7541d536df0940 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Mon, 11 Mar 2019 15:07:07 -0700 Subject: [PATCH 07/36] Be more discerning on when to attempt suggesting a comma in a macro invocation --- src/libsyntax/tokenstream.rs | 8 +++++--- src/test/ui/macros/missing-comma.rs | 7 +++++++ src/test/ui/macros/missing-comma.stderr | 21 +++++++++++++++------ 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/src/libsyntax/tokenstream.rs b/src/libsyntax/tokenstream.rs index 4ce308d015c00..5caa59a53f92b 100644 --- a/src/libsyntax/tokenstream.rs +++ b/src/libsyntax/tokenstream.rs @@ -178,9 +178,11 @@ impl TokenStream { while let Some((pos, ts)) = iter.next() { if let Some((_, next)) = iter.peek() { let sp = match (&ts, &next) { - ((TokenTree::Token(_, token::Token::Comma), NonJoint), _) | - (_, (TokenTree::Token(_, token::Token::Comma), NonJoint)) => continue, - ((TokenTree::Token(sp, _), NonJoint), _) => *sp, + (_, (TokenTree::Token(_, token::Token::Comma), _)) => continue, + ((TokenTree::Token(sp, token_left), NonJoint), + (TokenTree::Token(_, token_right), _)) + if token_left.is_ident() || token_left.is_lit() && + token_right.is_ident() || token_right.is_lit() => *sp, ((TokenTree::Delimited(sp, ..), NonJoint), _) => sp.entire(), _ => continue, }; diff --git a/src/test/ui/macros/missing-comma.rs b/src/test/ui/macros/missing-comma.rs index 1e146875bcc76..2b411aba8a2ee 100644 --- a/src/test/ui/macros/missing-comma.rs +++ b/src/test/ui/macros/missing-comma.rs @@ -6,6 +6,11 @@ macro_rules! foo { ($a:ident, $b:ident, $c:ident, $d:ident, $e:ident) => (); } +macro_rules! bar { + ($lvl:expr, $($arg:tt)+) => {} +} + + fn main() { println!("{}" a); //~^ ERROR expected token: `,` @@ -17,4 +22,6 @@ fn main() { //~^ ERROR no rules expected the token `d` foo!(a, b, c d e); //~^ ERROR no rules expected the token `d` + bar!(Level::Error, ); + //~^ ERROR unexpected end of macro invocation } diff --git a/src/test/ui/macros/missing-comma.stderr b/src/test/ui/macros/missing-comma.stderr index 5881e0b7b68c6..424fefd00f873 100644 --- a/src/test/ui/macros/missing-comma.stderr +++ b/src/test/ui/macros/missing-comma.stderr @@ -1,11 +1,11 @@ error: expected token: `,` - --> $DIR/missing-comma.rs:10:19 + --> $DIR/missing-comma.rs:15:19 | LL | println!("{}" a); | ^ error: no rules expected the token `b` - --> $DIR/missing-comma.rs:12:12 + --> $DIR/missing-comma.rs:17:12 | LL | macro_rules! foo { | ---------------- when calling this macro @@ -16,7 +16,7 @@ LL | foo!(a b); | help: missing comma here error: no rules expected the token `e` - --> $DIR/missing-comma.rs:14:21 + --> $DIR/missing-comma.rs:19:21 | LL | macro_rules! foo { | ---------------- when calling this macro @@ -27,7 +27,7 @@ LL | foo!(a, b, c, d e); | help: missing comma here error: no rules expected the token `d` - --> $DIR/missing-comma.rs:16:18 + --> $DIR/missing-comma.rs:21:18 | LL | macro_rules! foo { | ---------------- when calling this macro @@ -38,7 +38,7 @@ LL | foo!(a, b, c d, e); | help: missing comma here error: no rules expected the token `d` - --> $DIR/missing-comma.rs:18:18 + --> $DIR/missing-comma.rs:23:18 | LL | macro_rules! foo { | ---------------- when calling this macro @@ -46,5 +46,14 @@ LL | macro_rules! foo { LL | foo!(a, b, c d e); | ^ no rules expected this token in macro call -error: aborting due to 5 previous errors +error: unexpected end of macro invocation + --> $DIR/missing-comma.rs:25:23 + | +LL | macro_rules! bar { + | ---------------- when calling this macro +... +LL | bar!(Level::Error, ); + | ^ missing tokens in macro arguments + +error: aborting due to 6 previous errors From 27abd52170b2d2769f5fbed665795bdb9a3facef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Wed, 13 Mar 2019 00:10:16 -0700 Subject: [PATCH 08/36] Fix operator precedence --- src/libsyntax/tokenstream.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libsyntax/tokenstream.rs b/src/libsyntax/tokenstream.rs index 5caa59a53f92b..80a7bde606afa 100644 --- a/src/libsyntax/tokenstream.rs +++ b/src/libsyntax/tokenstream.rs @@ -181,8 +181,8 @@ impl TokenStream { (_, (TokenTree::Token(_, token::Token::Comma), _)) => continue, ((TokenTree::Token(sp, token_left), NonJoint), (TokenTree::Token(_, token_right), _)) - if token_left.is_ident() || token_left.is_lit() && - token_right.is_ident() || token_right.is_lit() => *sp, + if (token_left.is_ident() || token_left.is_lit()) && + (token_right.is_ident() || token_right.is_lit()) => *sp, ((TokenTree::Delimited(sp, ..), NonJoint), _) => sp.entire(), _ => continue, }; From 4e5692d9858d298f27757579688c71ba494cb5c3 Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Fri, 18 Jan 2019 12:18:57 +0100 Subject: [PATCH 09/36] test that wildcard type `_` is not duplicated by `type Foo = (X, X);` and potentially instantiated at different types. (Updated to reflect changes in diagnostic output and compiletest infrastructure.) --- ...ssue-55748-pat-types-constrain-bindings.rs | 70 +++++++++++++++++++ ...-55748-pat-types-constrain-bindings.stderr | 29 ++++++++ 2 files changed, 99 insertions(+) create mode 100644 src/test/ui/nll/user-annotations/issue-55748-pat-types-constrain-bindings.rs create mode 100644 src/test/ui/nll/user-annotations/issue-55748-pat-types-constrain-bindings.stderr diff --git a/src/test/ui/nll/user-annotations/issue-55748-pat-types-constrain-bindings.rs b/src/test/ui/nll/user-annotations/issue-55748-pat-types-constrain-bindings.rs new file mode 100644 index 0000000000000..3d042d442d531 --- /dev/null +++ b/src/test/ui/nll/user-annotations/issue-55748-pat-types-constrain-bindings.rs @@ -0,0 +1,70 @@ +// This test is ensuring that type ascriptions on let bindings +// constrain both: +// +// 1. the input expression on the right-hand side (after any potential +// coercion, and allowing for covariance), *and* +// +// 2. the bindings (if any) nested within the pattern on the left-hand +// side (and here, the type-constraint is *invariant*). + +#![feature(nll)] + +#![allow(dead_code, unused_mut)] +type PairUncoupled<'a, 'b, T> = (&'a T, &'b T); +type PairCoupledRegions<'a, T> = (&'a T, &'a T); +type PairCoupledTypes = (T, T); + +fn uncoupled_lhs<'a>(_x: &'a u32, s: &'static u32) -> &'static u32 { + let ((mut y, mut _z),): (PairUncoupled,) = ((s, &_x),); // ok + // Above compiling does *not* imply below would compile. + // ::std::mem::swap(&mut y, &mut _z); + y +} + +fn swap_regions((mut y, mut _z): PairCoupledRegions) { + ::std::mem::swap(&mut y, &mut _z); +} + +fn coupled_regions_lhs<'a>(_x: &'a u32, s: &'static u32) -> &'static u32 { + let ((y, _z),): (PairCoupledRegions,) = ((s, &_x),); + // If above line compiled, so should line below ... + + // swap_regions((y, _z)); + + // ... but the ascribed type also invalidates this use of `y` + y //~ ERROR lifetime may not live long enough +} + +fn swap_types((mut y, mut _z): PairCoupledTypes<&u32>) { + ::std::mem::swap(&mut y, &mut _z); +} + +fn coupled_types_lhs<'a>(_x: &'a u32, s: &'static u32) -> &'static u32 { + let ((y, _z),): (PairCoupledTypes<&u32>,) = ((s, &_x),); + // If above line compiled, so should line below ... + + // swap_types((y, _z)); + + // ... but the ascribed type also invalidates this use of `y` + y //~ ERROR lifetime may not live long enough +} + +fn swap_wilds((mut y, mut _z): PairCoupledTypes<&u32>) { + ::std::mem::swap(&mut y, &mut _z); +} + +fn coupled_wilds_lhs<'a>(_x: &'a u32, s: &'static u32) -> &'static u32 { + let ((y, _z),): (PairCoupledTypes<_>,) = ((s, &_x),); + // If above line compiled, so should line below + // swap_wilds((y, _z)); + + // ... but the ascribed type also invalidates this use of `y` + y //~ ERROR lifetime may not live long enough +} + +fn main() { + uncoupled_lhs(&3, &4); + coupled_regions_lhs(&3, &4); + coupled_types_lhs(&3, &4); + coupled_wilds_lhs(&3, &4); +} diff --git a/src/test/ui/nll/user-annotations/issue-55748-pat-types-constrain-bindings.stderr b/src/test/ui/nll/user-annotations/issue-55748-pat-types-constrain-bindings.stderr new file mode 100644 index 0000000000000..5929707e41e10 --- /dev/null +++ b/src/test/ui/nll/user-annotations/issue-55748-pat-types-constrain-bindings.stderr @@ -0,0 +1,29 @@ +error: lifetime may not live long enough + --> $DIR/issue-55748-pat-types-constrain-bindings.rs:35:5 + | +LL | fn coupled_regions_lhs<'a>(_x: &'a u32, s: &'static u32) -> &'static u32 { + | -- lifetime `'a` defined here +... +LL | y + | ^ returning this value requires that `'a` must outlive `'static` + +error: lifetime may not live long enough + --> $DIR/issue-55748-pat-types-constrain-bindings.rs:49:5 + | +LL | fn coupled_types_lhs<'a>(_x: &'a u32, s: &'static u32) -> &'static u32 { + | -- lifetime `'a` defined here +... +LL | y + | ^ returning this value requires that `'a` must outlive `'static` + +error: lifetime may not live long enough + --> $DIR/issue-55748-pat-types-constrain-bindings.rs:62:5 + | +LL | fn coupled_wilds_lhs<'a>(_x: &'a u32, s: &'static u32) -> &'static u32 { + | -- lifetime `'a` defined here +... +LL | y + | ^ returning this value requires that `'a` must outlive `'static` + +error: aborting due to 3 previous errors + From 541ad45a83482e3132c75fbbc55fb2afc03a6031 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 5 Mar 2019 02:29:21 +0100 Subject: [PATCH 10/36] Add default keyword handling in rustdoc --- src/librustdoc/clean/mod.rs | 24 ++++++++++++++++++++---- src/librustdoc/html/format.rs | 11 +++++++++++ src/librustdoc/html/render.rs | 8 +++++--- src/test/rustdoc/default_trait_method.rs | 15 +++++++++++++++ 4 files changed, 51 insertions(+), 7 deletions(-) create mode 100644 src/test/rustdoc/default_trait_method.rs diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index f2bf7ead5619b..86958e06d5c5b 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -507,6 +507,18 @@ impl Item { .as_ref() .or_else(|| self.stability.as_ref().and_then(|s| s.deprecation.as_ref())) } + pub fn is_default(&self) -> bool { + match self.inner { + ItemEnum::MethodItem(ref meth) => { + if let Some(defaultness) = meth.defaultness { + defaultness.has_value() && !defaultness.is_final() + } else { + false + } + } + _ => false, + } + } } #[derive(Clone, RustcEncodable, RustcDecodable, Debug)] @@ -1699,9 +1711,11 @@ pub struct Method { pub generics: Generics, pub decl: FnDecl, pub header: hir::FnHeader, + pub defaultness: Option, } -impl<'a> Clean for (&'a hir::MethodSig, &'a hir::Generics, hir::BodyId) { +impl<'a> Clean for (&'a hir::MethodSig, &'a hir::Generics, hir::BodyId, + Option) { fn clean(&self, cx: &DocContext<'_>) -> Method { let (generics, decl) = enter_impl_trait(cx, || { (self.1.clean(cx), (&*self.0.decl, self.2).clean(cx)) @@ -1710,6 +1724,7 @@ impl<'a> Clean for (&'a hir::MethodSig, &'a hir::Generics, hir::BodyId) decl, generics, header: self.0.header, + defaultness: self.3, } } } @@ -2015,7 +2030,7 @@ impl Clean for hir::TraitItem { default.map(|e| print_const_expr(cx, e))) } hir::TraitItemKind::Method(ref sig, hir::TraitMethod::Provided(body)) => { - MethodItem((sig, &self.generics, body).clean(cx)) + MethodItem((sig, &self.generics, body, None).clean(cx)) } hir::TraitItemKind::Method(ref sig, hir::TraitMethod::Required(ref names)) => { let (generics, decl) = enter_impl_trait(cx, || { @@ -2053,7 +2068,7 @@ impl Clean for hir::ImplItem { Some(print_const_expr(cx, expr))) } hir::ImplItemKind::Method(ref sig, body) => { - MethodItem((sig, &self.generics, body).clean(cx)) + MethodItem((sig, &self.generics, body, Some(self.defaultness)).clean(cx)) } hir::ImplItemKind::Type(ref ty) => TypedefItem(Typedef { type_: ty.clean(cx), @@ -2136,7 +2151,8 @@ impl<'tcx> Clean for ty::AssociatedItem { abi: sig.abi(), constness, asyncness: hir::IsAsync::NotAsync, - } + }, + defaultness: Some(self.defaultness), }) } else { TyMethodItem(TyMethod { diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index d204a179ca62c..48baf27bae20a 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -45,6 +45,7 @@ pub struct GenericBounds<'a>(pub &'a [clean::GenericBound]); /// Wrapper struct for emitting a comma-separated list of items pub struct CommaSep<'a, T>(pub &'a [T]); pub struct AbiSpace(pub Abi); +pub struct DefaultSpace(pub bool); /// Wrapper struct for properly emitting a function or method declaration. pub struct Function<'a> { @@ -1057,3 +1058,13 @@ impl fmt::Display for AbiSpace { } } } + +impl fmt::Display for DefaultSpace { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + if self.0 { + write!(f, "default ") + } else { + Ok(()) + } + } +} diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index d711e4514a049..f02e4a01ec56c 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -61,7 +61,7 @@ use crate::doctree; use crate::fold::DocFolder; use crate::html::escape::Escape; use crate::html::format::{AsyncSpace, ConstnessSpace}; -use crate::html::format::{GenericBounds, WhereClause, href, AbiSpace}; +use crate::html::format::{GenericBounds, WhereClause, href, AbiSpace, DefaultSpace}; use crate::html::format::{VisSpace, Function, UnsafetySpace, MutableSpace}; use crate::html::format::fmt_impl_for_trait_page; use crate::html::item_type::ItemType; @@ -3434,11 +3434,12 @@ fn render_assoc_item(w: &mut fmt::Formatter<'_>, } }; let mut header_len = format!( - "{}{}{}{}{:#}fn {}{:#}", + "{}{}{}{}{}{:#}fn {}{:#}", VisSpace(&meth.visibility), ConstnessSpace(header.constness), UnsafetySpace(header.unsafety), AsyncSpace(header.asyncness), + DefaultSpace(meth.is_default()), AbiSpace(header.abi), name, *g @@ -3450,12 +3451,13 @@ fn render_assoc_item(w: &mut fmt::Formatter<'_>, (0, true) }; render_attributes(w, meth)?; - write!(w, "{}{}{}{}{}fn {name}\ + write!(w, "{}{}{}{}{}{}fn {name}\ {generics}{decl}{where_clause}", VisSpace(&meth.visibility), ConstnessSpace(header.constness), UnsafetySpace(header.unsafety), AsyncSpace(header.asyncness), + DefaultSpace(meth.is_default()), AbiSpace(header.abi), href = href, name = name, diff --git a/src/test/rustdoc/default_trait_method.rs b/src/test/rustdoc/default_trait_method.rs new file mode 100644 index 0000000000000..dfbd8f2210fa4 --- /dev/null +++ b/src/test/rustdoc/default_trait_method.rs @@ -0,0 +1,15 @@ +#![feature(specialization)] + +pub trait Item { + fn foo(); + fn bar(); +} + +// @has default_trait_method/trait.Item.html +// @has - '//*[@id="method.foo"]' 'default fn foo()' +// @has - '//*[@id="method.bar"]' 'fn bar()' +// @!has - '//*[@id="method.bar"]' 'default fn bar()' +impl Item for T { + default fn foo() {} + fn bar() {} +} From a7bd36c9e8cdfac6a6edd4124e0d1d99a41b99a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Linus=20Unneb=C3=A4ck?= Date: Mon, 11 Mar 2019 16:07:31 +0000 Subject: [PATCH 11/36] Add peer_addr function to UdpSocket --- src/libstd/net/udp.rs | 17 +++++++++++++++++ src/libstd/sys/cloudabi/shims/net.rs | 4 ++++ src/libstd/sys/redox/net/udp.rs | 5 +++++ src/libstd/sys/sgx/net.rs | 4 ++++ src/libstd/sys_common/net.rs | 6 ++++++ 5 files changed, 36 insertions(+) diff --git a/src/libstd/net/udp.rs b/src/libstd/net/udp.rs index edc9d665444a0..c7ccf45b953e7 100644 --- a/src/libstd/net/udp.rs +++ b/src/libstd/net/udp.rs @@ -180,6 +180,23 @@ impl UdpSocket { } } + /// Returns the socket address of the remote peer this socket was connected to. + /// + /// # Examples + /// + /// ```no_run + /// use std::net::{Ipv4Addr, SocketAddr, SocketAddrV4, UdpSocket}; + /// + /// let socket = UdpSocket::bind("127.0.0.1:34254").expect("couldn't bind to address"); + /// socket.connect("192.168.0.1:41203").expect("couldn't connect to address"); + /// assert_eq!(socket.peer_addr().unwrap(), + /// SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::new(192, 168, 0, 1), 41203))); + /// ``` + #[stable(feature = "rust1", since = "1.0.0")] + pub fn peer_addr(&self) -> io::Result { + self.0.peer_addr() + } + /// Returns the socket address that this socket was created from. /// /// # Examples diff --git a/src/libstd/sys/cloudabi/shims/net.rs b/src/libstd/sys/cloudabi/shims/net.rs index 6d2a4962ab444..4364a1365443a 100644 --- a/src/libstd/sys/cloudabi/shims/net.rs +++ b/src/libstd/sys/cloudabi/shims/net.rs @@ -159,6 +159,10 @@ impl UdpSocket { unsupported() } + pub fn peer_addr(&self) -> io::Result { + match self.0 {} + } + pub fn socket_addr(&self) -> io::Result { match self.0 {} } diff --git a/src/libstd/sys/redox/net/udp.rs b/src/libstd/sys/redox/net/udp.rs index b1a60b1457083..274123dce4b58 100644 --- a/src/libstd/sys/redox/net/udp.rs +++ b/src/libstd/sys/redox/net/udp.rs @@ -72,6 +72,11 @@ impl UdpSocket { Ok(None) } + pub fn peer_addr(&self) -> Result { + let path = self.0.path()?; + Ok(path_to_peer_addr(path.to_str().unwrap_or(""))) + } + pub fn socket_addr(&self) -> Result { let path = self.0.path()?; Ok(path_to_local_addr(path.to_str().unwrap_or(""))) diff --git a/src/libstd/sys/sgx/net.rs b/src/libstd/sys/sgx/net.rs index e5e42e3d0b048..e851bdfe6a831 100644 --- a/src/libstd/sys/sgx/net.rs +++ b/src/libstd/sys/sgx/net.rs @@ -257,6 +257,10 @@ impl UdpSocket { unsupported() } + pub fn peer_addr(&self) -> io::Result { + match self.0 {} + } + pub fn socket_addr(&self) -> io::Result { match self.0 {} } diff --git a/src/libstd/sys_common/net.rs b/src/libstd/sys_common/net.rs index b9505aaa69ba5..b77bcee4b9d04 100644 --- a/src/libstd/sys_common/net.rs +++ b/src/libstd/sys_common/net.rs @@ -472,6 +472,12 @@ impl UdpSocket { pub fn into_socket(self) -> Socket { self.inner } + pub fn peer_addr(&self) -> io::Result { + sockname(|buf, len| unsafe { + c::getpeername(*self.inner.as_inner(), buf, len) + }) + } + pub fn socket_addr(&self) -> io::Result { sockname(|buf, len| unsafe { c::getsockname(*self.inner.as_inner(), buf, len) From bf473e3c153dfa84056249864a9f696d72f4e9a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Linus=20Unneb=C3=A4ck?= Date: Tue, 12 Mar 2019 10:32:23 +0000 Subject: [PATCH 12/36] Mark UdpSocket peer_addr unstable w/ tracking issue --- src/libstd/net/udp.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libstd/net/udp.rs b/src/libstd/net/udp.rs index c7ccf45b953e7..164039b303230 100644 --- a/src/libstd/net/udp.rs +++ b/src/libstd/net/udp.rs @@ -185,6 +185,7 @@ impl UdpSocket { /// # Examples /// /// ```no_run + /// #![feature(udp_peer_addr)] /// use std::net::{Ipv4Addr, SocketAddr, SocketAddrV4, UdpSocket}; /// /// let socket = UdpSocket::bind("127.0.0.1:34254").expect("couldn't bind to address"); @@ -192,7 +193,7 @@ impl UdpSocket { /// assert_eq!(socket.peer_addr().unwrap(), /// SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::new(192, 168, 0, 1), 41203))); /// ``` - #[stable(feature = "rust1", since = "1.0.0")] + #[unstable(feature = "udp_peer_addr", issue = "59127")] pub fn peer_addr(&self) -> io::Result { self.0.peer_addr() } From 24e3fa079c150675e1911f1a9f958b690ecaa1bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Linus=20Unneb=C3=A4ck?= Date: Tue, 12 Mar 2019 11:19:33 +0000 Subject: [PATCH 13/36] Document UdpSocket peer_addr NotConnected error --- src/libstd/net/udp.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/libstd/net/udp.rs b/src/libstd/net/udp.rs index 164039b303230..79e5ae79e4c01 100644 --- a/src/libstd/net/udp.rs +++ b/src/libstd/net/udp.rs @@ -193,6 +193,19 @@ impl UdpSocket { /// assert_eq!(socket.peer_addr().unwrap(), /// SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::new(192, 168, 0, 1), 41203))); /// ``` + /// + /// If the socket isn't connected, it will return a [`NotConnected`] error. + /// + /// [`NotConnected`]: ../../std/io/enum.ErrorKind.html#variant.NotConnected + /// + /// ```no_run + /// #![feature(udp_peer_addr)] + /// use std::net::UdpSocket; + /// + /// let socket = UdpSocket::bind("127.0.0.1:34254").expect("couldn't bind to address"); + /// assert_eq!(socket.peer_addr().unwrap_err().kind(), + /// ::std::io::ErrorKind::NotConnected); + /// ``` #[unstable(feature = "udp_peer_addr", issue = "59127")] pub fn peer_addr(&self) -> io::Result { self.0.peer_addr() From 7f7cfaee6aafbaa2477cb00b273299ec4e7d18d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Linus=20Unneb=C3=A4ck?= Date: Tue, 12 Mar 2019 16:50:00 +0000 Subject: [PATCH 14/36] Add test for UdpSocket peer_addr --- src/libstd/net/udp.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/libstd/net/udp.rs b/src/libstd/net/udp.rs index 79e5ae79e4c01..f3f65034f4256 100644 --- a/src/libstd/net/udp.rs +++ b/src/libstd/net/udp.rs @@ -903,6 +903,16 @@ mod tests { }) } + #[test] + fn socket_peer_ip4() { + each_ip(&mut |addr1, addr2| { + let server = t!(UdpSocket::bind(&addr1)); + assert_eq!(server.peer_addr().unwrap_err().kind(), ErrorKind::NotConnected); + t!(server.connect(&addr2)); + assert_eq!(addr2, t!(server.peer_addr())); + }) + } + #[test] fn udp_clone_smoke() { each_ip(&mut |addr1, addr2| { From 7e73cd48c4d531d8c3048941b4436833ec8651e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Linus=20Unneb=C3=A4ck?= Date: Tue, 12 Mar 2019 17:18:07 +0000 Subject: [PATCH 15/36] Fix test names regarding ip version --- src/libstd/net/udp.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libstd/net/udp.rs b/src/libstd/net/udp.rs index f3f65034f4256..b42a812304269 100644 --- a/src/libstd/net/udp.rs +++ b/src/libstd/net/udp.rs @@ -896,7 +896,7 @@ mod tests { } #[test] - fn socket_name_ip4() { + fn socket_name() { each_ip(&mut |addr, _| { let server = t!(UdpSocket::bind(&addr)); assert_eq!(addr, t!(server.local_addr())); @@ -904,7 +904,7 @@ mod tests { } #[test] - fn socket_peer_ip4() { + fn socket_peer() { each_ip(&mut |addr1, addr2| { let server = t!(UdpSocket::bind(&addr1)); assert_eq!(server.peer_addr().unwrap_err().kind(), ErrorKind::NotConnected); From 214110bb4c7902e4787612efc265e4b2bdf0c1df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Linus=20Unneb=C3=A4ck?= Date: Sat, 16 Mar 2019 11:19:01 +0000 Subject: [PATCH 16/36] Add UdpSocket peer_addr implementation for L4Re --- src/libstd/sys/unix/l4re.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/libstd/sys/unix/l4re.rs b/src/libstd/sys/unix/l4re.rs index b9e725371a36e..b3dd1cf6aaac7 100644 --- a/src/libstd/sys/unix/l4re.rs +++ b/src/libstd/sys/unix/l4re.rs @@ -292,6 +292,10 @@ pub mod net { pub fn into_socket(self) -> Socket { self.inner } + pub fn peer_addr(&self) -> io::Result { + unimpl!(); + } + pub fn socket_addr(&self) -> io::Result { unimpl!(); } @@ -463,4 +467,3 @@ pub mod net { } } } - From 81d5fb5c6fc65e947ff97c02997bfff9a1f6ce16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Linus=20Unneb=C3=A4ck?= Date: Sat, 16 Mar 2019 11:20:02 +0000 Subject: [PATCH 17/36] Add UdpSocket peer_addr implementation for Wasm --- src/libstd/sys/wasm/net.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/libstd/sys/wasm/net.rs b/src/libstd/sys/wasm/net.rs index a2ea2dfbbc032..c85dd000afe6f 100644 --- a/src/libstd/sys/wasm/net.rs +++ b/src/libstd/sys/wasm/net.rs @@ -156,6 +156,10 @@ impl UdpSocket { unsupported() } + pub fn peer_addr(&self) -> io::Result { + match self.0 {} + } + pub fn socket_addr(&self) -> io::Result { match self.0 {} } From 6ea18889c0e337ca3f6c4f2e274db13c760f5b0d Mon Sep 17 00:00:00 2001 From: Fabian Drinck Date: Fri, 22 Feb 2019 15:07:18 +0100 Subject: [PATCH 18/36] Add lint for redundant imports Co-authored-by: Stephan Schauerte --- src/librustc/lint/builtin.rs | 6 ++ src/librustc_resolve/resolve_imports.rs | 93 ++++++++++++++++++++++++- src/test/ui/lint/use-redundant.rs | 17 +++++ src/test/ui/lint/use-redundant.stderr | 14 ++++ 4 files changed, 129 insertions(+), 1 deletion(-) create mode 100644 src/test/ui/lint/use-redundant.rs create mode 100644 src/test/ui/lint/use-redundant.stderr diff --git a/src/librustc/lint/builtin.rs b/src/librustc/lint/builtin.rs index ad0ed39185c1c..c48231cbbf1aa 100644 --- a/src/librustc/lint/builtin.rs +++ b/src/librustc/lint/builtin.rs @@ -392,6 +392,12 @@ declare_lint! { "nested occurrence of `impl Trait` type" } +declare_lint! { + pub REDUNDANT_IMPORT, + Warn, + "redundant import" +} + /// Does nothing as a lint pass, but registers some `Lint`s /// that are used by other parts of the compiler. #[derive(Copy, Clone)] diff --git a/src/librustc_resolve/resolve_imports.rs b/src/librustc_resolve/resolve_imports.rs index 9daffd522bf2c..ea65f1fc5f2da 100644 --- a/src/librustc_resolve/resolve_imports.rs +++ b/src/librustc_resolve/resolve_imports.rs @@ -7,6 +7,7 @@ use crate::{NameBinding, NameBindingKind, ToNameBinding, PathResult, PrivacyErro use crate::{Resolver, Segment}; use crate::{names_to_string, module_to_string}; use crate::{resolve_error, ResolutionError, Suggestion}; +use crate::ModuleKind; use crate::macros::ParentScope; use errors::Applicability; @@ -14,7 +15,11 @@ use errors::Applicability; use rustc_data_structures::ptr_key::PtrKey; use rustc::ty; use rustc::lint::builtin::BuiltinLintDiagnostics; -use rustc::lint::builtin::{DUPLICATE_MACRO_EXPORTS, PUB_USE_OF_PRIVATE_EXTERN_CRATE}; +use rustc::lint::builtin::{ + DUPLICATE_MACRO_EXPORTS, + PUB_USE_OF_PRIVATE_EXTERN_CRATE, + REDUNDANT_IMPORT, +}; use rustc::hir::def_id::{CrateNum, DefId}; use rustc::hir::def::*; use rustc::session::DiagnosticMessageId; @@ -1230,10 +1235,96 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> { import[ns] = Some(PathResolution::new(def)); }); + self.check_for_redundant_imports( + ident, + directive, + source_bindings, + target_bindings, + target, + ); + debug!("(resolving single import) successfully resolved import"); None } + fn check_for_redundant_imports( + &mut self, + ident: Ident, + directive: &'b ImportDirective<'b>, + source_bindings: &PerNS, Determinacy>>>, + target_bindings: &PerNS>>>, + target: Ident, + ) { + // Check if we are at the root of a macro expansion and skip if we are. + if directive.parent_scope.expansion != Mark::root() { + return; + } + + if let ModuleKind::Def(_, _) = directive.parent_scope.module.kind { + return; + } + + let mut is_redundant = PerNS { + value_ns: None, + type_ns: None, + macro_ns: None, + }; + + let mut redundant_span = PerNS { + value_ns: None, + type_ns: None, + macro_ns: None, + }; + + self.per_ns(|this, ns| if let Some(binding) = source_bindings[ns].get().ok() { + if binding.def() == Def::Err { + return; + } + + let orig_blacklisted_binding = mem::replace( + &mut this.blacklisted_binding, + target_bindings[ns].get() + ); + + match this.early_resolve_ident_in_lexical_scope( + target, + ScopeSet::Import(ns), + &directive.parent_scope, + false, + false, + directive.span, + ) { + Ok(other_binding) => { + is_redundant[ns] = Some(binding.def() == other_binding.def()); + redundant_span[ns] = Some(other_binding.span); + } + Err(_) => is_redundant[ns] = Some(false) + } + + this.blacklisted_binding = orig_blacklisted_binding; + }); + + if !is_redundant.is_empty() && + is_redundant.present_items().all(|is_redundant| is_redundant) + { + self.session.buffer_lint( + REDUNDANT_IMPORT, + directive.id, + directive.span, + &format!("the item `{}` is imported redundantly", ident), + ); + + for span in redundant_span.present_items() { + self.session.buffer_lint( + REDUNDANT_IMPORT, + directive.id, + span, + "another import" + ); + } + } + } + fn resolve_glob_import(&mut self, directive: &'b ImportDirective<'b>) { let module = match directive.imported_module.get().unwrap() { ModuleOrUniformRoot::Module(module) => module, diff --git a/src/test/ui/lint/use-redundant.rs b/src/test/ui/lint/use-redundant.rs new file mode 100644 index 0000000000000..50d4d30625a6a --- /dev/null +++ b/src/test/ui/lint/use-redundant.rs @@ -0,0 +1,17 @@ +// compile-pass + +use crate::foo::Bar; //~ WARNING first import + +mod foo { + pub type Bar = i32; +} + +fn baz() -> Bar { + 3 +} + +fn main() { + use crate::foo::Bar; //~ WARNING redundant import + let _a: Bar = 3; + baz(); +} diff --git a/src/test/ui/lint/use-redundant.stderr b/src/test/ui/lint/use-redundant.stderr new file mode 100644 index 0000000000000..6a6becc5e615b --- /dev/null +++ b/src/test/ui/lint/use-redundant.stderr @@ -0,0 +1,14 @@ +warning: the item `Bar` is imported redundantly + --> $DIR/use-redundant.rs:14:9 + | +LL | use crate::foo::Bar; //~ WARNING redundant import + | ^^^^^^^^^^^^^^^ + | + = note: #[warn(redundant_import)] on by default + +warning: another import + --> $DIR/use-redundant.rs:3:5 + | +LL | use crate::foo::Bar; //~ WARNING first import + | ^^^^^^^^^^^^^^^ + From 66710962fa90d2155705442431317dfce6b9fbcb Mon Sep 17 00:00:00 2001 From: Fabian Drinck Date: Sun, 10 Mar 2019 12:52:30 +0100 Subject: [PATCH 19/36] Remove redundant imports --- src/librustc/ty/query/on_disk_cache.rs | 1 - src/librustc_codegen_llvm/context.rs | 1 - src/librustc_codegen_ssa/mir/rvalue.rs | 1 - src/librustc_errors/lib.rs | 2 +- src/librustc_interface/profile/mod.rs | 1 - src/librustc_mir/hair/pattern/mod.rs | 1 - src/librustc_mir/interpret/operator.rs | 2 -- src/librustc_resolve/lib.rs | 1 - src/librustc_traits/lowering/environment.rs | 2 +- src/librustc_typeck/check/wfcheck.rs | 5 ----- 10 files changed, 2 insertions(+), 15 deletions(-) diff --git a/src/librustc/ty/query/on_disk_cache.rs b/src/librustc/ty/query/on_disk_cache.rs index c16f861dedb50..7259ef0cc6cf6 100644 --- a/src/librustc/ty/query/on_disk_cache.rs +++ b/src/librustc/ty/query/on_disk_cache.rs @@ -778,7 +778,6 @@ impl<'enc, 'a, 'tcx, E> CacheEncoder<'enc, 'a, 'tcx, E> value: &V) -> Result<(), E::Error> { - use crate::ty::codec::TyEncoder; let start_pos = self.position(); tag.encode(self)?; diff --git a/src/librustc_codegen_llvm/context.rs b/src/librustc_codegen_llvm/context.rs index 23e3a8425d370..c0adee8284292 100644 --- a/src/librustc_codegen_llvm/context.rs +++ b/src/librustc_codegen_llvm/context.rs @@ -377,7 +377,6 @@ impl MiscMethods<'tcx> for CodegenCx<'ll, 'tcx> { // Returns a Value of the "eh_unwind_resume" lang item if one is defined, // otherwise declares it as an external function. fn eh_unwind_resume(&self) -> &'ll Value { - use crate::attributes; let unwresume = &self.eh_unwind_resume; if let Some(llfn) = unwresume.get() { return llfn; diff --git a/src/librustc_codegen_ssa/mir/rvalue.rs b/src/librustc_codegen_ssa/mir/rvalue.rs index b8131671320e1..0ef664dac02d8 100644 --- a/src/librustc_codegen_ssa/mir/rvalue.rs +++ b/src/librustc_codegen_ssa/mir/rvalue.rs @@ -750,7 +750,6 @@ fn cast_int_to_float<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>( // All inputs greater or equal to (f32::MAX + 0.5 ULP) are rounded to infinity, // and for everything else LLVM's uitofp works just fine. use rustc_apfloat::ieee::Single; - use rustc_apfloat::Float; const MAX_F32_PLUS_HALF_ULP: u128 = ((1 << (Single::PRECISION + 1)) - 1) << (Single::MAX_EXP - Single::PRECISION as i16); let max = bx.cx().const_uint_big(int_ty, MAX_F32_PLUS_HALF_ULP); diff --git a/src/librustc_errors/lib.rs b/src/librustc_errors/lib.rs index 7c7698ddd3d73..05eb9e00e3690 100644 --- a/src/librustc_errors/lib.rs +++ b/src/librustc_errors/lib.rs @@ -156,7 +156,7 @@ impl CodeSuggestion { /// Returns the assembled code suggestions and whether they should be shown with an underline. pub fn splice_lines(&self, cm: &SourceMapperDyn) -> Vec<(String, Vec)> { - use syntax_pos::{CharPos, Loc, Pos}; + use syntax_pos::{CharPos, Pos}; fn push_trailing(buf: &mut String, line_opt: Option<&Cow<'_, str>>, diff --git a/src/librustc_interface/profile/mod.rs b/src/librustc_interface/profile/mod.rs index eb13a5668f927..b6e30e87f0515 100644 --- a/src/librustc_interface/profile/mod.rs +++ b/src/librustc_interface/profile/mod.rs @@ -61,7 +61,6 @@ fn total_duration(traces: &[trace::Rec]) -> Duration { fn profile_queries_thread(r: Receiver) { use self::trace::*; use std::fs::File; - use std::time::{Instant}; let mut profq_msgs: Vec = vec![]; let mut frame: StackFrame = StackFrame { parse_st: ParseState::Clear, traces: vec![] }; diff --git a/src/librustc_mir/hair/pattern/mod.rs b/src/librustc_mir/hair/pattern/mod.rs index ad7b45d89453a..c7808c0bb0790 100644 --- a/src/librustc_mir/hair/pattern/mod.rs +++ b/src/librustc_mir/hair/pattern/mod.rs @@ -427,7 +427,6 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> { let mut kind = match (lo, hi) { (PatternKind::Constant { value: lo }, PatternKind::Constant { value: hi }) => { - use std::cmp::Ordering; let cmp = compare_const_vals( self.tcx, lo, diff --git a/src/librustc_mir/interpret/operator.rs b/src/librustc_mir/interpret/operator.rs index 944e393d296fc..b6227569f3b00 100644 --- a/src/librustc_mir/interpret/operator.rs +++ b/src/librustc_mir/interpret/operator.rs @@ -331,8 +331,6 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> val: ImmTy<'tcx, M::PointerTag>, ) -> EvalResult<'tcx, Scalar> { use rustc::mir::UnOp::*; - use rustc_apfloat::ieee::{Single, Double}; - use rustc_apfloat::Float; let layout = val.layout; let val = val.to_scalar()?; diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index ac149be4b2a89..622594a038096 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -1733,7 +1733,6 @@ impl<'a> Resolver<'a> { /// just that an error occurred. pub fn resolve_str_path_error(&mut self, span: Span, path_str: &str, is_value: bool) -> Result { - use std::iter; let mut errored = false; let path = if path_str.starts_with("::") { diff --git a/src/librustc_traits/lowering/environment.rs b/src/librustc_traits/lowering/environment.rs index c908c6993e19e..a6062fac61d61 100644 --- a/src/librustc_traits/lowering/environment.rs +++ b/src/librustc_traits/lowering/environment.rs @@ -190,7 +190,7 @@ crate fn environment<'a, 'tcx>( tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId ) -> Environment<'tcx> { - use super::{Lower, IntoFromEnvGoal}; + use super::IntoFromEnvGoal; use rustc::hir::{Node, TraitItemKind, ImplItemKind, ItemKind, ForeignItemKind}; debug!("environment(def_id = {:?})", def_id); diff --git a/src/librustc_typeck/check/wfcheck.rs b/src/librustc_typeck/check/wfcheck.rs index 1f7e05de18bcf..5289a3c621c67 100644 --- a/src/librustc_typeck/check/wfcheck.rs +++ b/src/librustc_typeck/check/wfcheck.rs @@ -420,9 +420,6 @@ fn check_where_clauses<'a, 'gcx, 'fcx, 'tcx>( def_id: DefId, return_ty: Option>, ) { - use ty::subst::Subst; - use rustc::ty::TypeFoldable; - let predicates = fcx.tcx.predicates_of(def_id); let generics = tcx.generics_of(def_id); @@ -1016,8 +1013,6 @@ fn check_false_global_bounds<'a, 'gcx, 'tcx>( span: Span, id: hir::HirId) { - use rustc::ty::TypeFoldable; - let empty_env = ty::ParamEnv::empty(); let def_id = fcx.tcx.hir().local_def_id_from_hir_id(id); From 1129a349b5414c9117f8bf5cd3adf9d65fa976c0 Mon Sep 17 00:00:00 2001 From: Fabian Drinck Date: Sat, 16 Mar 2019 16:49:13 +0100 Subject: [PATCH 20/36] Edit comments --- src/librustc_resolve/resolve_imports.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/librustc_resolve/resolve_imports.rs b/src/librustc_resolve/resolve_imports.rs index ea65f1fc5f2da..7e67f20554489 100644 --- a/src/librustc_resolve/resolve_imports.rs +++ b/src/librustc_resolve/resolve_imports.rs @@ -1255,11 +1255,13 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> { target_bindings: &PerNS>>>, target: Ident, ) { - // Check if we are at the root of a macro expansion and skip if we are. + // Skip if the import was produced by a macro. if directive.parent_scope.expansion != Mark::root() { return; } + // Skip if we are inside a named module (in contrast to an anonymous + // module defined by a block). if let ModuleKind::Def(_, _) = directive.parent_scope.module.kind { return; } From fef7e9d7fa34f8ba40c473ee475dbf389da87295 Mon Sep 17 00:00:00 2001 From: Fabian Drinck Date: Sat, 16 Mar 2019 17:38:12 +0100 Subject: [PATCH 21/36] Improve warning --- src/librustc/lint/builtin.rs | 9 +++++++++ src/librustc_resolve/resolve_imports.rs | 15 +++++---------- src/test/ui/lint/use-redundant.stderr | 11 ++++------- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/librustc/lint/builtin.rs b/src/librustc/lint/builtin.rs index c48231cbbf1aa..b833cbfdcb781 100644 --- a/src/librustc/lint/builtin.rs +++ b/src/librustc/lint/builtin.rs @@ -488,6 +488,7 @@ pub enum BuiltinLintDiagnostics { UnknownCrateTypes(Span, String, String), UnusedImports(String, Vec<(Span, String)>), NestedImplTrait { outer_impl_trait_span: Span, inner_impl_trait_span: Span }, + RedundantImport(Vec, ast::Ident), } impl BuiltinLintDiagnostics { @@ -584,6 +585,14 @@ impl BuiltinLintDiagnostics { db.span_label(outer_impl_trait_span, "outer `impl Trait`"); db.span_label(inner_impl_trait_span, "nested `impl Trait` here"); } + BuiltinLintDiagnostics::RedundantImport(spans, ident) => { + for span in spans { + db.span_label( + span, + format!("the item `{}` was already imported here", ident) + ); + } + } } } } diff --git a/src/librustc_resolve/resolve_imports.rs b/src/librustc_resolve/resolve_imports.rs index 7e67f20554489..da0ed4f91a896 100644 --- a/src/librustc_resolve/resolve_imports.rs +++ b/src/librustc_resolve/resolve_imports.rs @@ -1309,21 +1309,16 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> { if !is_redundant.is_empty() && is_redundant.present_items().all(|is_redundant| is_redundant) { - self.session.buffer_lint( + self.session.buffer_lint_with_diagnostic( REDUNDANT_IMPORT, directive.id, directive.span, &format!("the item `{}` is imported redundantly", ident), + BuiltinLintDiagnostics::RedundantImport( + redundant_span.present_items().collect(), + ident, + ), ); - - for span in redundant_span.present_items() { - self.session.buffer_lint( - REDUNDANT_IMPORT, - directive.id, - span, - "another import" - ); - } } } diff --git a/src/test/ui/lint/use-redundant.stderr b/src/test/ui/lint/use-redundant.stderr index 6a6becc5e615b..c843ed160df08 100644 --- a/src/test/ui/lint/use-redundant.stderr +++ b/src/test/ui/lint/use-redundant.stderr @@ -1,14 +1,11 @@ warning: the item `Bar` is imported redundantly --> $DIR/use-redundant.rs:14:9 | -LL | use crate::foo::Bar; //~ WARNING redundant import +LL | use crate::foo::Bar; + | --------------- the item `Bar` was already imported here +... +LL | use crate::foo::Bar; | ^^^^^^^^^^^^^^^ | = note: #[warn(redundant_import)] on by default -warning: another import - --> $DIR/use-redundant.rs:3:5 - | -LL | use crate::foo::Bar; //~ WARNING first import - | ^^^^^^^^^^^^^^^ - From 567649b94619d58cb33187b80d6d661bfe2ab8ea Mon Sep 17 00:00:00 2001 From: Fabian Drinck Date: Sat, 16 Mar 2019 18:08:51 +0100 Subject: [PATCH 22/36] Bless tests --- src/test/ui/lint/lint-unused-imports.stderr | 23 ++++++++++ .../rust-2018/future-proofing-locals.stderr | 46 +++++++++++++++++++ 2 files changed, 69 insertions(+) diff --git a/src/test/ui/lint/lint-unused-imports.stderr b/src/test/ui/lint/lint-unused-imports.stderr index f9a54f477f998..bf194696f6182 100644 --- a/src/test/ui/lint/lint-unused-imports.stderr +++ b/src/test/ui/lint/lint-unused-imports.stderr @@ -34,12 +34,35 @@ error: unused import: `foo::Square` LL | use foo::Square; | ^^^^^^^^^^^ +warning: the item `g` is imported redundantly + --> $DIR/lint-unused-imports.rs:68:9 + | +LL | / fn g() { +LL | | use self::g; + | | ^^^^^^^ +LL | | fn f() { +LL | | self::g(); +LL | | } +LL | | } + | |_- the item `g` was already imported here + | + = note: #[warn(redundant_import)] on by default + error: unused import: `self::g` --> $DIR/lint-unused-imports.rs:68:9 | LL | use self::g; | ^^^^^^^ +warning: the item `foo` is imported redundantly + --> $DIR/lint-unused-imports.rs:77:9 + | +LL | use test2::{foo, bar}; + | --- the item `foo` was already imported here +... +LL | use test2::foo; + | ^^^^^^^^^^ + error: unused import: `test2::foo` --> $DIR/lint-unused-imports.rs:77:9 | diff --git a/src/test/ui/rust-2018/future-proofing-locals.stderr b/src/test/ui/rust-2018/future-proofing-locals.stderr index 4d666d22afed1..fa8333b5d2112 100644 --- a/src/test/ui/rust-2018/future-proofing-locals.stderr +++ b/src/test/ui/rust-2018/future-proofing-locals.stderr @@ -52,5 +52,51 @@ error: imports cannot refer to local variables LL | use {T as _, x}; | ^ +warning: the item `T` is imported redundantly + --> $DIR/future-proofing-locals.rs:19:9 + | +LL | / mod T { +LL | | pub struct U; +LL | | } + | |_- the item `T` was already imported here +... +LL | use T; + | ^ + | + = note: #[warn(redundant_import)] on by default + +warning: the item `x` is imported redundantly + --> $DIR/future-proofing-locals.rs:31:9 + | +LL | / mod x { +LL | | pub struct y; +LL | | } + | |_- the item `x` was already imported here +... +LL | use x; + | ^ + +warning: the item `x` is imported redundantly + --> $DIR/future-proofing-locals.rs:37:17 + | +LL | / mod x { +LL | | pub struct y; +LL | | } + | |_- the item `x` was already imported here +... +LL | use x; + | ^ + +warning: the item `x` is imported redundantly + --> $DIR/future-proofing-locals.rs:45:18 + | +LL | / mod x { +LL | | pub struct y; +LL | | } + | |_- the item `x` was already imported here +... +LL | use {T as _, x}; + | ^ + error: aborting due to 9 previous errors From ceca4a146827fa13483423355b4a1f988d23b281 Mon Sep 17 00:00:00 2001 From: Fabian Drinck Date: Sat, 16 Mar 2019 19:06:22 +0100 Subject: [PATCH 23/36] Distinguish between imported and defined items --- src/librustc/lint/builtin.rs | 7 ++++--- src/librustc_resolve/resolve_imports.rs | 3 ++- src/test/ui/lint/use-redundant.stderr | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/librustc/lint/builtin.rs b/src/librustc/lint/builtin.rs index b833cbfdcb781..2fc250d1d338c 100644 --- a/src/librustc/lint/builtin.rs +++ b/src/librustc/lint/builtin.rs @@ -488,7 +488,7 @@ pub enum BuiltinLintDiagnostics { UnknownCrateTypes(Span, String, String), UnusedImports(String, Vec<(Span, String)>), NestedImplTrait { outer_impl_trait_span: Span, inner_impl_trait_span: Span }, - RedundantImport(Vec, ast::Ident), + RedundantImport(Vec<(Span, bool)>, ast::Ident), } impl BuiltinLintDiagnostics { @@ -586,10 +586,11 @@ impl BuiltinLintDiagnostics { db.span_label(inner_impl_trait_span, "nested `impl Trait` here"); } BuiltinLintDiagnostics::RedundantImport(spans, ident) => { - for span in spans { + for (span, is_imported) in spans { + let introduced = if is_imported { "imported" } else { "defined" }; db.span_label( span, - format!("the item `{}` was already imported here", ident) + format!("the item `{}` was {} here", ident, introduced) ); } } diff --git a/src/librustc_resolve/resolve_imports.rs b/src/librustc_resolve/resolve_imports.rs index da0ed4f91a896..36f1539f3eae9 100644 --- a/src/librustc_resolve/resolve_imports.rs +++ b/src/librustc_resolve/resolve_imports.rs @@ -1298,7 +1298,8 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> { ) { Ok(other_binding) => { is_redundant[ns] = Some(binding.def() == other_binding.def()); - redundant_span[ns] = Some(other_binding.span); + redundant_span[ns] = + Some((other_binding.span, other_binding.is_import())); } Err(_) => is_redundant[ns] = Some(false) } diff --git a/src/test/ui/lint/use-redundant.stderr b/src/test/ui/lint/use-redundant.stderr index c843ed160df08..b5000b22a1dad 100644 --- a/src/test/ui/lint/use-redundant.stderr +++ b/src/test/ui/lint/use-redundant.stderr @@ -2,7 +2,7 @@ warning: the item `Bar` is imported redundantly --> $DIR/use-redundant.rs:14:9 | LL | use crate::foo::Bar; - | --------------- the item `Bar` was already imported here + | --------------- the item `Bar` was imported here ... LL | use crate::foo::Bar; | ^^^^^^^^^^^^^^^ From 29a7732325460d3fd3a2c30a5c91a2f2db57bddb Mon Sep 17 00:00:00 2001 From: Fabian Drinck Date: Sat, 16 Mar 2019 19:19:40 +0100 Subject: [PATCH 24/36] Remove redundant import --- src/librustdoc/html/render.rs | 2 -- src/librustdoc/test.rs | 3 +-- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index d711e4514a049..aa10a55eb3c73 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -1062,8 +1062,6 @@ themePicker.onblur = handleThemeButtonsBlur; } if cx.shared.include_sources { - use std::path::Component; - let mut hierarchy = Hierarchy::new(OsString::new()); for source in cx.shared.local_sources.iter() .filter_map(|p| p.0.strip_prefix(&cx.shared.src_root) diff --git a/src/librustdoc/test.rs b/src/librustdoc/test.rs index f1d4d8470b2a5..0bbc7c5c4b223 100644 --- a/src/librustdoc/test.rs +++ b/src/librustdoc/test.rs @@ -371,8 +371,7 @@ pub fn make_test(s: &str, // Uses libsyntax to parse the doctest and find if there's a main fn and the extern // crate already is included. let (already_has_main, already_has_extern_crate, found_macro) = crate::syntax::with_globals(|| { - use crate::syntax::{ast, parse::{self, ParseSess}, source_map::FilePathMapping}; - use crate::syntax_pos::FileName; + use crate::syntax::{parse::{self, ParseSess}, source_map::FilePathMapping}; use errors::emitter::EmitterWriter; use errors::Handler; From 1062628daaa1bb1f533f499ee2369ac0c166b21d Mon Sep 17 00:00:00 2001 From: Fabian Drinck Date: Sat, 16 Mar 2019 19:21:03 +0100 Subject: [PATCH 25/36] Edit ui tests --- src/test/ui/lint/lint-unused-imports.rs | 1 + src/test/ui/rust-2018/future-proofing-locals.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/src/test/ui/lint/lint-unused-imports.rs b/src/test/ui/lint/lint-unused-imports.rs index 9c5b206203c1d..c7ffdc270c947 100644 --- a/src/test/ui/lint/lint-unused-imports.rs +++ b/src/test/ui/lint/lint-unused-imports.rs @@ -1,5 +1,6 @@ #![deny(unused_imports)] #![allow(dead_code)] +#![allow(redundant_import)] use bar::c::cc as cal; diff --git a/src/test/ui/rust-2018/future-proofing-locals.rs b/src/test/ui/rust-2018/future-proofing-locals.rs index 1e53c2d1daca4..df3badb94e5f0 100644 --- a/src/test/ui/rust-2018/future-proofing-locals.rs +++ b/src/test/ui/rust-2018/future-proofing-locals.rs @@ -1,6 +1,7 @@ // edition:2018 #![allow(non_camel_case_types)] +#![allow(redundant_import)] mod T { pub struct U; From bbbc446da33028f4e9fc8f8740680fa476481bf4 Mon Sep 17 00:00:00 2001 From: Fabian Drinck Date: Sun, 17 Mar 2019 09:49:31 +0100 Subject: [PATCH 26/36] Replace REDUNDANT_IMPORT with UNUSED_IMPORTS --- src/librustc/lint/builtin.rs | 8 +-- src/librustc_resolve/resolve_imports.rs | 4 +- src/test/ui/lint/lint-unused-imports.rs | 1 - src/test/ui/lint/lint-unused-imports.stderr | 10 ++- .../ui/rust-2018/future-proofing-locals.rs | 2 +- .../rust-2018/future-proofing-locals.stderr | 64 +++---------------- 6 files changed, 17 insertions(+), 72 deletions(-) diff --git a/src/librustc/lint/builtin.rs b/src/librustc/lint/builtin.rs index 2fc250d1d338c..bb6f65a84e08d 100644 --- a/src/librustc/lint/builtin.rs +++ b/src/librustc/lint/builtin.rs @@ -392,12 +392,6 @@ declare_lint! { "nested occurrence of `impl Trait` type" } -declare_lint! { - pub REDUNDANT_IMPORT, - Warn, - "redundant import" -} - /// Does nothing as a lint pass, but registers some `Lint`s /// that are used by other parts of the compiler. #[derive(Copy, Clone)] @@ -590,7 +584,7 @@ impl BuiltinLintDiagnostics { let introduced = if is_imported { "imported" } else { "defined" }; db.span_label( span, - format!("the item `{}` was {} here", ident, introduced) + format!("the item `{}` was already {} here", ident, introduced) ); } } diff --git a/src/librustc_resolve/resolve_imports.rs b/src/librustc_resolve/resolve_imports.rs index 36f1539f3eae9..21c146cd31e9b 100644 --- a/src/librustc_resolve/resolve_imports.rs +++ b/src/librustc_resolve/resolve_imports.rs @@ -18,7 +18,7 @@ use rustc::lint::builtin::BuiltinLintDiagnostics; use rustc::lint::builtin::{ DUPLICATE_MACRO_EXPORTS, PUB_USE_OF_PRIVATE_EXTERN_CRATE, - REDUNDANT_IMPORT, + UNUSED_IMPORTS, }; use rustc::hir::def_id::{CrateNum, DefId}; use rustc::hir::def::*; @@ -1311,7 +1311,7 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> { is_redundant.present_items().all(|is_redundant| is_redundant) { self.session.buffer_lint_with_diagnostic( - REDUNDANT_IMPORT, + UNUSED_IMPORTS, directive.id, directive.span, &format!("the item `{}` is imported redundantly", ident), diff --git a/src/test/ui/lint/lint-unused-imports.rs b/src/test/ui/lint/lint-unused-imports.rs index c7ffdc270c947..9c5b206203c1d 100644 --- a/src/test/ui/lint/lint-unused-imports.rs +++ b/src/test/ui/lint/lint-unused-imports.rs @@ -1,6 +1,5 @@ #![deny(unused_imports)] #![allow(dead_code)] -#![allow(redundant_import)] use bar::c::cc as cal; diff --git a/src/test/ui/lint/lint-unused-imports.stderr b/src/test/ui/lint/lint-unused-imports.stderr index bf194696f6182..62490972420a2 100644 --- a/src/test/ui/lint/lint-unused-imports.stderr +++ b/src/test/ui/lint/lint-unused-imports.stderr @@ -34,7 +34,7 @@ error: unused import: `foo::Square` LL | use foo::Square; | ^^^^^^^^^^^ -warning: the item `g` is imported redundantly +error: the item `g` is imported redundantly --> $DIR/lint-unused-imports.rs:68:9 | LL | / fn g() { @@ -44,9 +44,7 @@ LL | | fn f() { LL | | self::g(); LL | | } LL | | } - | |_- the item `g` was already imported here - | - = note: #[warn(redundant_import)] on by default + | |_- the item `g` was already defined here error: unused import: `self::g` --> $DIR/lint-unused-imports.rs:68:9 @@ -54,7 +52,7 @@ error: unused import: `self::g` LL | use self::g; | ^^^^^^^ -warning: the item `foo` is imported redundantly +error: the item `foo` is imported redundantly --> $DIR/lint-unused-imports.rs:77:9 | LL | use test2::{foo, bar}; @@ -75,5 +73,5 @@ error: unused import: `test::B2` LL | use test::B2; | ^^^^^^^^ -error: aborting due to 8 previous errors +error: aborting due to 10 previous errors diff --git a/src/test/ui/rust-2018/future-proofing-locals.rs b/src/test/ui/rust-2018/future-proofing-locals.rs index df3badb94e5f0..2c388cf3713b0 100644 --- a/src/test/ui/rust-2018/future-proofing-locals.rs +++ b/src/test/ui/rust-2018/future-proofing-locals.rs @@ -1,7 +1,7 @@ // edition:2018 #![allow(non_camel_case_types)] -#![allow(redundant_import)] +#![allow(unused_imports)] mod T { pub struct U; diff --git a/src/test/ui/rust-2018/future-proofing-locals.stderr b/src/test/ui/rust-2018/future-proofing-locals.stderr index fa8333b5d2112..7021489a6ddcf 100644 --- a/src/test/ui/rust-2018/future-proofing-locals.stderr +++ b/src/test/ui/rust-2018/future-proofing-locals.stderr @@ -1,102 +1,56 @@ error: imports cannot refer to type parameters - --> $DIR/future-proofing-locals.rs:13:9 + --> $DIR/future-proofing-locals.rs:14:9 | LL | use T as _; | ^ error: imports cannot refer to type parameters - --> $DIR/future-proofing-locals.rs:14:9 + --> $DIR/future-proofing-locals.rs:15:9 | LL | use T::U; | ^ error: imports cannot refer to type parameters - --> $DIR/future-proofing-locals.rs:15:9 + --> $DIR/future-proofing-locals.rs:16:9 | LL | use T::*; | ^ error: imports cannot refer to type parameters - --> $DIR/future-proofing-locals.rs:19:9 + --> $DIR/future-proofing-locals.rs:20:9 | LL | use T; | ^ error: imports cannot refer to local variables - --> $DIR/future-proofing-locals.rs:25:9 + --> $DIR/future-proofing-locals.rs:26:9 | LL | use x as _; | ^ error: imports cannot refer to local variables - --> $DIR/future-proofing-locals.rs:31:9 + --> $DIR/future-proofing-locals.rs:32:9 | LL | use x; | ^ error: imports cannot refer to local variables - --> $DIR/future-proofing-locals.rs:37:17 + --> $DIR/future-proofing-locals.rs:38:17 | LL | use x; | ^ error: imports cannot refer to type parameters - --> $DIR/future-proofing-locals.rs:45:10 + --> $DIR/future-proofing-locals.rs:46:10 | LL | use {T as _, x}; | ^ error: imports cannot refer to local variables - --> $DIR/future-proofing-locals.rs:45:18 + --> $DIR/future-proofing-locals.rs:46:18 | LL | use {T as _, x}; | ^ -warning: the item `T` is imported redundantly - --> $DIR/future-proofing-locals.rs:19:9 - | -LL | / mod T { -LL | | pub struct U; -LL | | } - | |_- the item `T` was already imported here -... -LL | use T; - | ^ - | - = note: #[warn(redundant_import)] on by default - -warning: the item `x` is imported redundantly - --> $DIR/future-proofing-locals.rs:31:9 - | -LL | / mod x { -LL | | pub struct y; -LL | | } - | |_- the item `x` was already imported here -... -LL | use x; - | ^ - -warning: the item `x` is imported redundantly - --> $DIR/future-proofing-locals.rs:37:17 - | -LL | / mod x { -LL | | pub struct y; -LL | | } - | |_- the item `x` was already imported here -... -LL | use x; - | ^ - -warning: the item `x` is imported redundantly - --> $DIR/future-proofing-locals.rs:45:18 - | -LL | / mod x { -LL | | pub struct y; -LL | | } - | |_- the item `x` was already imported here -... -LL | use {T as _, x}; - | ^ - error: aborting due to 9 previous errors From aac729542ca216da8d2a2529d085b4784b247c68 Mon Sep 17 00:00:00 2001 From: Fabian Drinck Date: Sun, 17 Mar 2019 11:38:38 +0100 Subject: [PATCH 27/36] Fix tests --- src/test/ui/lint/lint-unused-imports.rs | 2 ++ src/test/ui/lint/lint-unused-imports.stderr | 5 +++-- src/test/ui/lint/use-redundant.rs | 1 + src/test/ui/lint/use-redundant.stderr | 10 +++++++--- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/test/ui/lint/lint-unused-imports.rs b/src/test/ui/lint/lint-unused-imports.rs index 9c5b206203c1d..4754d8880763a 100644 --- a/src/test/ui/lint/lint-unused-imports.rs +++ b/src/test/ui/lint/lint-unused-imports.rs @@ -66,6 +66,7 @@ mod bar { fn g() { use self::g; //~ ERROR unused import: `self::g` + //~^ ERROR the item `g` is imported redundantly fn f() { self::g(); } @@ -75,6 +76,7 @@ fn g() { #[allow(unused_variables)] fn h() { use test2::foo; //~ ERROR unused import: `test2::foo` + //~^ ERROR the item `foo` is imported redundantly let foo = 0; } diff --git a/src/test/ui/lint/lint-unused-imports.stderr b/src/test/ui/lint/lint-unused-imports.stderr index 62490972420a2..b37f25ec01741 100644 --- a/src/test/ui/lint/lint-unused-imports.stderr +++ b/src/test/ui/lint/lint-unused-imports.stderr @@ -40,6 +40,7 @@ error: the item `g` is imported redundantly LL | / fn g() { LL | | use self::g; | | ^^^^^^^ +LL | | LL | | fn f() { LL | | self::g(); LL | | } @@ -53,7 +54,7 @@ LL | use self::g; | ^^^^^^^ error: the item `foo` is imported redundantly - --> $DIR/lint-unused-imports.rs:77:9 + --> $DIR/lint-unused-imports.rs:78:9 | LL | use test2::{foo, bar}; | --- the item `foo` was already imported here @@ -62,7 +63,7 @@ LL | use test2::foo; | ^^^^^^^^^^ error: unused import: `test2::foo` - --> $DIR/lint-unused-imports.rs:77:9 + --> $DIR/lint-unused-imports.rs:78:9 | LL | use test2::foo; | ^^^^^^^^^^ diff --git a/src/test/ui/lint/use-redundant.rs b/src/test/ui/lint/use-redundant.rs index 50d4d30625a6a..7abf5e498b538 100644 --- a/src/test/ui/lint/use-redundant.rs +++ b/src/test/ui/lint/use-redundant.rs @@ -1,4 +1,5 @@ // compile-pass +#![warn(unused_imports)] use crate::foo::Bar; //~ WARNING first import diff --git a/src/test/ui/lint/use-redundant.stderr b/src/test/ui/lint/use-redundant.stderr index b5000b22a1dad..b25ffc6073f46 100644 --- a/src/test/ui/lint/use-redundant.stderr +++ b/src/test/ui/lint/use-redundant.stderr @@ -1,11 +1,15 @@ warning: the item `Bar` is imported redundantly - --> $DIR/use-redundant.rs:14:9 + --> $DIR/use-redundant.rs:15:9 | LL | use crate::foo::Bar; - | --------------- the item `Bar` was imported here + | --------------- the item `Bar` was already imported here ... LL | use crate::foo::Bar; | ^^^^^^^^^^^^^^^ | - = note: #[warn(redundant_import)] on by default +note: lint level defined here + --> $DIR/use-redundant.rs:2:9 + | +LL | #![warn(unused_imports)] + | ^^^^^^^^^^^^^^ From 0ddd6b9da1399a4eaa8c5459e65efb75b832110a Mon Sep 17 00:00:00 2001 From: Fabian Drinck Date: Sun, 17 Mar 2019 11:55:32 +0100 Subject: [PATCH 28/36] Add glob import to redundancy test --- src/test/ui/lint/use-redundant.rs | 9 ++++++++ src/test/ui/lint/use-redundant.stderr | 33 ++++++++++++++++++++++----- 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/src/test/ui/lint/use-redundant.rs b/src/test/ui/lint/use-redundant.rs index 7abf5e498b538..328f8232bafa8 100644 --- a/src/test/ui/lint/use-redundant.rs +++ b/src/test/ui/lint/use-redundant.rs @@ -11,8 +11,17 @@ fn baz() -> Bar { 3 } +mod m1 { pub struct S {} } +mod m2 { pub struct S {} } + +use m1::*; +use m2::*; + fn main() { use crate::foo::Bar; //~ WARNING redundant import let _a: Bar = 3; baz(); + + use m1::S; //~ WARNING redundant import + let _s = S {}; } diff --git a/src/test/ui/lint/use-redundant.stderr b/src/test/ui/lint/use-redundant.stderr index b25ffc6073f46..82d2312779e6d 100644 --- a/src/test/ui/lint/use-redundant.stderr +++ b/src/test/ui/lint/use-redundant.stderr @@ -1,15 +1,36 @@ +warning: unused import: `m1::*` + --> $DIR/use-redundant.rs:17:5 + | +LL | use m1::*; + | ^^^^^ + | +note: lint level defined here + --> $DIR/use-redundant.rs:2:9 + | +LL | #![warn(unused_imports)] + | ^^^^^^^^^^^^^^ + +warning: unused import: `m2::*` + --> $DIR/use-redundant.rs:18:5 + | +LL | use m2::*; + | ^^^^^ + warning: the item `Bar` is imported redundantly - --> $DIR/use-redundant.rs:15:9 + --> $DIR/use-redundant.rs:21:9 | LL | use crate::foo::Bar; | --------------- the item `Bar` was already imported here ... LL | use crate::foo::Bar; | ^^^^^^^^^^^^^^^ + +warning: the item `S` is imported redundantly + --> $DIR/use-redundant.rs:25:9 | -note: lint level defined here - --> $DIR/use-redundant.rs:2:9 - | -LL | #![warn(unused_imports)] - | ^^^^^^^^^^^^^^ +LL | use m1::*; + | ----- the item `S` was already imported here +... +LL | use m1::S; + | ^^^^^ From 98b26728e0627ef417599497e2355e784a1e9f9c Mon Sep 17 00:00:00 2001 From: Bastian Kauschke Date: Sun, 17 Mar 2019 11:55:56 +0100 Subject: [PATCH 29/36] update mailmap for Bastian Kauschke --- .mailmap | 1 + 1 file changed, 1 insertion(+) diff --git a/.mailmap b/.mailmap index a928606b693e5..5f2f9c8995553 100644 --- a/.mailmap +++ b/.mailmap @@ -29,6 +29,7 @@ Ariel Ben-Yehuda Ariel Ben-Yehuda Ariel Ben-Yehuda arielb1 Austin Seipp Aydin Kim aydin.kim +Bastian Kauschke Barosl Lee Barosl LEE Ben Alpert Ben Sago Ben S From dad4a67f28201914ca5ae8f3fccf623a631485c6 Mon Sep 17 00:00:00 2001 From: Fabian Drinck Date: Sun, 17 Mar 2019 13:30:42 +0100 Subject: [PATCH 30/36] Fix more tests --- src/test/run-pass/binding/match-arm-statics.rs | 2 -- src/test/run-pass/ifmt.rs | 2 -- src/test/run-pass/invalid_const_promotion.rs | 1 - src/test/run-pass/issues/issue-38556.rs | 1 - src/test/run-pass/issues/issue-39367.rs | 1 - src/test/run-pass/out-of-stack.rs | 1 - src/test/run-pass/rfcs/rfc-2126-extern-absolute-paths/basic.rs | 1 - .../traits/traits-multidispatch-infer-convert-target.rs | 1 - 8 files changed, 10 deletions(-) diff --git a/src/test/run-pass/binding/match-arm-statics.rs b/src/test/run-pass/binding/match-arm-statics.rs index 359c39211588c..5f7e357eeb2a9 100644 --- a/src/test/run-pass/binding/match-arm-statics.rs +++ b/src/test/run-pass/binding/match-arm-statics.rs @@ -45,8 +45,6 @@ pub mod glfw { } fn issue_6533() { - use glfw; - fn action_to_str(state: glfw::InputState) -> &'static str { use glfw::{RELEASE, PRESS, REPEAT}; match state { diff --git a/src/test/run-pass/ifmt.rs b/src/test/run-pass/ifmt.rs index 56222fa46f7c9..8c17b01e2bd89 100644 --- a/src/test/run-pass/ifmt.rs +++ b/src/test/run-pass/ifmt.rs @@ -238,7 +238,6 @@ pub fn main() { // Basic test to make sure that we can invoke the `write!` macro with an // fmt::Write instance. fn test_write() { - use std::fmt::Write; let mut buf = String::new(); write!(&mut buf, "{}", 3); { @@ -267,7 +266,6 @@ fn test_print() { // Just make sure that the macros are defined, there's not really a lot that we // can do with them just yet (to test the output) fn test_format_args() { - use std::fmt::Write; let mut buf = String::new(); { let w = &mut buf; diff --git a/src/test/run-pass/invalid_const_promotion.rs b/src/test/run-pass/invalid_const_promotion.rs index 1524373895d9b..2775aac015615 100644 --- a/src/test/run-pass/invalid_const_promotion.rs +++ b/src/test/run-pass/invalid_const_promotion.rs @@ -25,7 +25,6 @@ fn foo() { #[cfg(unix)] fn check_status(status: std::process::ExitStatus) { - use libc; use std::os::unix::process::ExitStatusExt; assert!(status.signal() == Some(libc::SIGILL) diff --git a/src/test/run-pass/issues/issue-38556.rs b/src/test/run-pass/issues/issue-38556.rs index 0cc247f5b9ca5..63fd9db08ff2f 100644 --- a/src/test/run-pass/issues/issue-38556.rs +++ b/src/test/run-pass/issues/issue-38556.rs @@ -9,6 +9,5 @@ macro_rules! reexport { reexport!(); fn main() { - use Bar; fn f(_: Bar) {} } diff --git a/src/test/run-pass/issues/issue-39367.rs b/src/test/run-pass/issues/issue-39367.rs index bd92224bce161..484cd782a09df 100644 --- a/src/test/run-pass/issues/issue-39367.rs +++ b/src/test/run-pass/issues/issue-39367.rs @@ -15,7 +15,6 @@ fn arena() -> &'static ArenaSet> { fn require_sync(_: &T) { } unsafe fn __stability() -> &'static ArenaSet> { use std::mem::transmute; - use std::boxed::Box; static mut DATA: *const ArenaSet> = 0 as *const ArenaSet>; static mut ONCE: Once = ONCE_INIT; diff --git a/src/test/run-pass/out-of-stack.rs b/src/test/run-pass/out-of-stack.rs index 72d6d6806229e..9f868d6e5c3e4 100644 --- a/src/test/run-pass/out-of-stack.rs +++ b/src/test/run-pass/out-of-stack.rs @@ -36,7 +36,6 @@ fn loud_recurse() { #[cfg(unix)] fn check_status(status: std::process::ExitStatus) { - use libc; use std::os::unix::process::ExitStatusExt; assert!(!status.success()); diff --git a/src/test/run-pass/rfcs/rfc-2126-extern-absolute-paths/basic.rs b/src/test/run-pass/rfcs/rfc-2126-extern-absolute-paths/basic.rs index 15449a6b83e2e..f25d81f1c9a52 100644 --- a/src/test/run-pass/rfcs/rfc-2126-extern-absolute-paths/basic.rs +++ b/src/test/run-pass/rfcs/rfc-2126-extern-absolute-paths/basic.rs @@ -7,7 +7,6 @@ use xcrate::Z; fn f() { - use xcrate; use xcrate as ycrate; let s = xcrate::S; assert_eq!(format!("{:?}", s), "S"); diff --git a/src/test/run-pass/traits/traits-multidispatch-infer-convert-target.rs b/src/test/run-pass/traits/traits-multidispatch-infer-convert-target.rs index ca47d9736f63c..626e1ae71bc2f 100644 --- a/src/test/run-pass/traits/traits-multidispatch-infer-convert-target.rs +++ b/src/test/run-pass/traits/traits-multidispatch-infer-convert-target.rs @@ -28,7 +28,6 @@ where T : Convert } fn main() { - use std::default::Default; // T = i16, U = u32 test(22_i16, Default::default(), 2, 4); From 4b09e98472f151424a9ea0f454cd475465438699 Mon Sep 17 00:00:00 2001 From: Fabian Drinck Date: Sun, 17 Mar 2019 17:40:25 +0100 Subject: [PATCH 31/36] Fix doc tests --- src/liballoc/borrow.rs | 2 +- src/libcore/cell.rs | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/liballoc/borrow.rs b/src/liballoc/borrow.rs index 74c80a08b12ab..ee1799fad8e15 100644 --- a/src/liballoc/borrow.rs +++ b/src/liballoc/borrow.rs @@ -135,7 +135,7 @@ impl ToOwned for T /// Another example showing how to keep `Cow` in a struct: /// /// ``` -/// use std::borrow::{Cow, ToOwned}; +/// use std::borrow::Cow; /// /// struct Items<'a, X: 'a> where [X]: ToOwned> { /// values: Cow<'a, [X]>, diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs index 8383d305518ab..cbc1377e8be64 100644 --- a/src/libcore/cell.rs +++ b/src/libcore/cell.rs @@ -1423,7 +1423,6 @@ impl fmt::Display for RefMut<'_, T> { /// /// ``` /// use std::cell::UnsafeCell; -/// use std::marker::Sync; /// /// # #[allow(dead_code)] /// struct NotThreadSafe { From ab2522a10e64a25d4886e31540def37fb789f601 Mon Sep 17 00:00:00 2001 From: Fabian Drinck Date: Sun, 17 Mar 2019 21:07:57 +0100 Subject: [PATCH 32/36] Change message to present tense --- src/librustc/lint/builtin.rs | 2 +- src/test/ui/lint/lint-unused-imports.stderr | 4 ++-- src/test/ui/lint/use-redundant.stderr | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/librustc/lint/builtin.rs b/src/librustc/lint/builtin.rs index bb6f65a84e08d..f118abea2adea 100644 --- a/src/librustc/lint/builtin.rs +++ b/src/librustc/lint/builtin.rs @@ -584,7 +584,7 @@ impl BuiltinLintDiagnostics { let introduced = if is_imported { "imported" } else { "defined" }; db.span_label( span, - format!("the item `{}` was already {} here", ident, introduced) + format!("the item `{}` is already {} here", ident, introduced) ); } } diff --git a/src/test/ui/lint/lint-unused-imports.stderr b/src/test/ui/lint/lint-unused-imports.stderr index b37f25ec01741..96d71a228a5f2 100644 --- a/src/test/ui/lint/lint-unused-imports.stderr +++ b/src/test/ui/lint/lint-unused-imports.stderr @@ -45,7 +45,7 @@ LL | | fn f() { LL | | self::g(); LL | | } LL | | } - | |_- the item `g` was already defined here + | |_- the item `g` is already defined here error: unused import: `self::g` --> $DIR/lint-unused-imports.rs:68:9 @@ -57,7 +57,7 @@ error: the item `foo` is imported redundantly --> $DIR/lint-unused-imports.rs:78:9 | LL | use test2::{foo, bar}; - | --- the item `foo` was already imported here + | --- the item `foo` is already imported here ... LL | use test2::foo; | ^^^^^^^^^^ diff --git a/src/test/ui/lint/use-redundant.stderr b/src/test/ui/lint/use-redundant.stderr index 82d2312779e6d..3554443590abf 100644 --- a/src/test/ui/lint/use-redundant.stderr +++ b/src/test/ui/lint/use-redundant.stderr @@ -20,7 +20,7 @@ warning: the item `Bar` is imported redundantly --> $DIR/use-redundant.rs:21:9 | LL | use crate::foo::Bar; - | --------------- the item `Bar` was already imported here + | --------------- the item `Bar` is already imported here ... LL | use crate::foo::Bar; | ^^^^^^^^^^^^^^^ @@ -29,7 +29,7 @@ warning: the item `S` is imported redundantly --> $DIR/use-redundant.rs:25:9 | LL | use m1::*; - | ----- the item `S` was already imported here + | ----- the item `S` is already imported here ... LL | use m1::S; | ^^^^^ From 9d408d972f7cf16162ec3ab35e11c659ccee9566 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 29 Nov 2018 21:50:49 +0300 Subject: [PATCH 33/36] Add todo!() macro The use-case of `todo!()` macro is to be a much easier to type alternative to `unimplemented!()` macro. --- src/libcore/macros.rs | 59 +++++++++++++++++++++++++++++++++++++++++++ src/libstd/lib.rs | 3 ++- 2 files changed, 61 insertions(+), 1 deletion(-) diff --git a/src/libcore/macros.rs b/src/libcore/macros.rs index b052f59b0f5c2..d77936c7ddd91 100644 --- a/src/libcore/macros.rs +++ b/src/libcore/macros.rs @@ -559,6 +559,65 @@ macro_rules! unimplemented { ($($arg:tt)+) => (panic!("not yet implemented: {}", format_args!($($arg)*))); } +/// A standardized placeholder for marking unfinished code. +/// +/// This can be useful if you are prototyping and are just looking to have your +/// code typecheck. `todo!` works exactly like `unimplemented!`, there only +/// difference between the two macros is the name. +/// +/// # Panics +/// +/// This will always [panic!](macro.panic.html) +/// +/// # Examples +/// +/// Here's an example of some in-progress code. We have a trait `Foo`: +/// +/// ``` +/// trait Foo { +/// fn bar(&self); +/// fn baz(&self); +/// } +/// ``` +/// +/// We want to implement `Foo` on one of our types, but we also want to work on +/// just `bar()` first. In order for our code to compile, we need to implement +/// `baz()`, so we can use `todo!`: +/// +/// ``` +/// #![feature(todo_macro)] +/// +/// # trait Foo { +/// # fn bar(&self); +/// # fn baz(&self); +/// # } +/// struct MyStruct; +/// +/// impl Foo for MyStruct { +/// fn bar(&self) { +/// // implementation goes here +/// } +/// +/// fn baz(&self) { +/// // let's not worry about implementing baz() for now +/// todo!(); +/// } +/// } +/// +/// fn main() { +/// let s = MyStruct; +/// s.bar(); +/// +/// // we aren't even using baz() yet, so this is fine. +/// } +/// ``` +#[macro_export] +#[unstable(feature = "todo_macro", issue = "59277")] +macro_rules! todo { + () => (panic!("not yet implemented")); + ($($arg:tt)+) => (panic!("not yet implemented: {}", format_args!($($arg)*))); +} + /// A macro to create an array of [`MaybeUninit`] /// /// This macro constructs an uninitialized array of the type `[MaybeUninit; N]`. diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index fc8ac9a0b3e00..296c4c887274e 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -301,6 +301,7 @@ #![feature(stmt_expr_attributes)] #![feature(str_internals)] #![feature(thread_local)] +#![feature(todo_macro)] #![feature(toowned_clone_into)] #![feature(try_reserve)] #![feature(unboxed_closures)] @@ -323,7 +324,7 @@ use prelude::v1::*; #[stable(feature = "rust1", since = "1.0.0")] pub use core::{assert_eq, assert_ne, debug_assert, debug_assert_eq, debug_assert_ne}; #[stable(feature = "rust1", since = "1.0.0")] -pub use core::{unreachable, unimplemented, write, writeln, r#try}; +pub use core::{unreachable, unimplemented, write, writeln, r#try, todo}; #[allow(unused_imports)] // macros from `alloc` are not used on all platforms #[macro_use] From 87e727a678db09ab6a36e3ee1519e229a437cd99 Mon Sep 17 00:00:00 2001 From: Fabian Drinck Date: Mon, 18 Mar 2019 17:50:49 +0100 Subject: [PATCH 34/36] Handle glob import in redundancy check --- src/librustc_resolve/resolve_imports.rs | 5 ++++- src/test/ui/lint/use-redundant.stderr | 9 --------- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/src/librustc_resolve/resolve_imports.rs b/src/librustc_resolve/resolve_imports.rs index 21c146cd31e9b..529c3f51b6458 100644 --- a/src/librustc_resolve/resolve_imports.rs +++ b/src/librustc_resolve/resolve_imports.rs @@ -1297,7 +1297,10 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> { directive.span, ) { Ok(other_binding) => { - is_redundant[ns] = Some(binding.def() == other_binding.def()); + is_redundant[ns] = Some( + binding.def() == other_binding.def() + && !other_binding.is_ambiguity() + ); redundant_span[ns] = Some((other_binding.span, other_binding.is_import())); } diff --git a/src/test/ui/lint/use-redundant.stderr b/src/test/ui/lint/use-redundant.stderr index 3554443590abf..fbd9f81f18f8a 100644 --- a/src/test/ui/lint/use-redundant.stderr +++ b/src/test/ui/lint/use-redundant.stderr @@ -25,12 +25,3 @@ LL | use crate::foo::Bar; LL | use crate::foo::Bar; | ^^^^^^^^^^^^^^^ -warning: the item `S` is imported redundantly - --> $DIR/use-redundant.rs:25:9 - | -LL | use m1::*; - | ----- the item `S` is already imported here -... -LL | use m1::S; - | ^^^^^ - From caa37d854e42130f211580404e231a74b8a41fea Mon Sep 17 00:00:00 2001 From: Fabian Drinck Date: Mon, 18 Mar 2019 17:51:00 +0100 Subject: [PATCH 35/36] Restore test --- src/test/run-pass/rfcs/rfc-2126-extern-absolute-paths/basic.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/test/run-pass/rfcs/rfc-2126-extern-absolute-paths/basic.rs b/src/test/run-pass/rfcs/rfc-2126-extern-absolute-paths/basic.rs index f25d81f1c9a52..566b3581046d9 100644 --- a/src/test/run-pass/rfcs/rfc-2126-extern-absolute-paths/basic.rs +++ b/src/test/run-pass/rfcs/rfc-2126-extern-absolute-paths/basic.rs @@ -4,9 +4,12 @@ // compile-flags:--extern xcrate // edition:2018 +#![allow(unused_imports)] + use xcrate::Z; fn f() { + use xcrate; use xcrate as ycrate; let s = xcrate::S; assert_eq!(format!("{:?}", s), "S"); From de4be2cd85b5c8b707185d0e1f10b3373be0a3d5 Mon Sep 17 00:00:00 2001 From: Joshua Liebow-Feeser Date: Mon, 18 Mar 2019 12:01:16 -0700 Subject: [PATCH 36/36] Stabilize refcell_map_split feature - Closes #51476 --- src/libcore/cell.rs | 6 ++---- src/libcore/tests/lib.rs | 1 - 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs index 8383d305518ab..753f10e6a0ad0 100644 --- a/src/libcore/cell.rs +++ b/src/libcore/cell.rs @@ -1186,7 +1186,6 @@ impl<'b, T: ?Sized> Ref<'b, T> { /// # Examples /// /// ``` - /// #![feature(refcell_map_split)] /// use std::cell::{Ref, RefCell}; /// /// let cell = RefCell::new([1, 2, 3, 4]); @@ -1195,7 +1194,7 @@ impl<'b, T: ?Sized> Ref<'b, T> { /// assert_eq!(*begin, [1, 2]); /// assert_eq!(*end, [3, 4]); /// ``` - #[unstable(feature = "refcell_map_split", issue = "51476")] + #[stable(feature = "refcell_map_split", since = "1.35.0")] #[inline] pub fn map_split(orig: Ref<'b, T>, f: F) -> (Ref<'b, U>, Ref<'b, V>) where F: FnOnce(&T) -> (&U, &V) @@ -1268,7 +1267,6 @@ impl<'b, T: ?Sized> RefMut<'b, T> { /// # Examples /// /// ``` - /// #![feature(refcell_map_split)] /// use std::cell::{RefCell, RefMut}; /// /// let cell = RefCell::new([1, 2, 3, 4]); @@ -1279,7 +1277,7 @@ impl<'b, T: ?Sized> RefMut<'b, T> { /// begin.copy_from_slice(&[4, 3]); /// end.copy_from_slice(&[2, 1]); /// ``` - #[unstable(feature = "refcell_map_split", issue = "51476")] + #[stable(feature = "refcell_map_split", since = "1.35.0")] #[inline] pub fn map_split( orig: RefMut<'b, T>, f: F diff --git a/src/libcore/tests/lib.rs b/src/libcore/tests/lib.rs index a50310e195f0d..08dda4bcc3d24 100644 --- a/src/libcore/tests/lib.rs +++ b/src/libcore/tests/lib.rs @@ -16,7 +16,6 @@ #![feature(pattern)] #![feature(range_is_empty)] #![feature(raw)] -#![feature(refcell_map_split)] #![feature(refcell_replace_swap)] #![feature(slice_patterns)] #![feature(sort_internals)]