From 56ebfb185b2e144d5404eda1fc40b0070a3122f3 Mon Sep 17 00:00:00 2001 From: Tim Vermeulen Date: Sun, 2 Jun 2019 13:31:49 +0200 Subject: [PATCH 01/32] Implement DoubleEndedIterator for iter::{StepBy, Peekable, Take} --- src/libcore/iter/adapters/mod.rs | 117 +++++++++++++++++++ src/libcore/tests/iter.rs | 192 ++++++++++++++++++++++++++++--- 2 files changed, 296 insertions(+), 13 deletions(-) diff --git a/src/libcore/iter/adapters/mod.rs b/src/libcore/iter/adapters/mod.rs index 518442efe7417..00053d9da84e0 100644 --- a/src/libcore/iter/adapters/mod.rs +++ b/src/libcore/iter/adapters/mod.rs @@ -485,6 +485,39 @@ impl Iterator for StepBy where I: Iterator { } } +impl StepBy where I: ExactSizeIterator { + // The zero-based index starting from the end of the iterator of the + // last element. Used in the `DoubleEndedIterator` implementation. + fn next_back_index(&self) -> usize { + let rem = self.iter.len() % (self.step + 1); + if self.first_take { + if rem == 0 { self.step } else { rem - 1 } + } else { + rem + } + } +} + +#[stable(feature = "double_ended_step_by_iterator", since = "1.38.0")] +impl DoubleEndedIterator for StepBy where I: DoubleEndedIterator + ExactSizeIterator { + #[inline] + fn next_back(&mut self) -> Option { + self.iter.nth_back(self.next_back_index()) + } + + #[inline] + fn nth_back(&mut self, n: usize) -> Option { + // `self.iter.nth_back(usize::MAX)` does the right thing here when `n` + // is out of bounds because the length of `self.iter` does not exceed + // `usize::MAX` (because `I: ExactSizeIterator`) and `nth_back` is + // zero-indexed + let n = n + .saturating_mul(self.step + 1) + .saturating_add(self.next_back_index()); + self.iter.nth_back(n) + } +} + // StepBy can only make the iterator shorter, so the len will still fit. #[stable(feature = "iterator_step_by", since = "1.28.0")] impl ExactSizeIterator for StepBy where I: ExactSizeIterator {} @@ -1158,6 +1191,45 @@ impl Iterator for Peekable { } } +#[stable(feature = "double_ended_peek_iterator", since = "1.38.0")] +impl DoubleEndedIterator for Peekable where I: DoubleEndedIterator { + #[inline] + fn next_back(&mut self) -> Option { + self.iter.next_back().or_else(|| self.peeked.take().and_then(|x| x)) + } + + #[inline] + fn try_rfold(&mut self, init: B, mut f: F) -> R where + Self: Sized, F: FnMut(B, Self::Item) -> R, R: Try + { + match self.peeked.take() { + Some(None) => return Try::from_ok(init), + Some(Some(v)) => match self.iter.try_rfold(init, &mut f).into_result() { + Ok(acc) => f(acc, v), + Err(e) => { + self.peeked = Some(Some(v)); + Try::from_error(e) + } + }, + None => self.iter.try_rfold(init, f), + } + } + + #[inline] + fn rfold(self, init: Acc, mut fold: Fold) -> Acc + where Fold: FnMut(Acc, Self::Item) -> Acc, + { + match self.peeked { + Some(None) => return init, + Some(Some(v)) => { + let acc = self.iter.rfold(init, &mut fold); + fold(acc, v) + } + None => self.iter.rfold(init, fold), + } + } +} + #[stable(feature = "rust1", since = "1.0.0")] impl ExactSizeIterator for Peekable {} @@ -1613,6 +1685,51 @@ impl Iterator for Take where I: Iterator{ } } +#[stable(feature = "double_ended_take_iterator", since = "1.38.0")] +impl DoubleEndedIterator for Take where I: DoubleEndedIterator + ExactSizeIterator { + #[inline] + fn next_back(&mut self) -> Option { + if self.n == 0 { + None + } else { + let n = self.n; + self.n -= 1; + self.iter.nth_back(self.iter.len().saturating_sub(n)) + } + } + + #[inline] + fn nth_back(&mut self, n: usize) -> Option { + let len = self.iter.len(); + if self.n > n { + let m = len.saturating_sub(self.n) + n; + self.n -= n + 1; + self.iter.nth_back(m) + } else { + if len > 0 { + self.iter.nth_back(len - 1); + } + None + } + } + + #[inline] + fn try_rfold(&mut self, init: Acc, fold: Fold) -> R where + Self: Sized, Fold: FnMut(Acc, Self::Item) -> R, R: Try + { + if self.n == 0 { + Try::from_ok(init) + } else { + let len = self.iter.len(); + if len > self.n && self.iter.nth_back(len - self.n - 1).is_none() { + Try::from_ok(init) + } else { + self.iter.try_rfold(init, fold) + } + } + } +} + #[stable(feature = "rust1", since = "1.0.0")] impl ExactSizeIterator for Take where I: ExactSizeIterator {} diff --git a/src/libcore/tests/iter.rs b/src/libcore/tests/iter.rs index bedb9e756129c..60efeda3a40ec 100644 --- a/src/libcore/tests/iter.rs +++ b/src/libcore/tests/iter.rs @@ -188,6 +188,19 @@ fn test_iterator_step_by() { assert_eq!(it.next(), Some(6)); assert_eq!(it.next(), Some(9)); assert_eq!(it.next(), None); + + let mut it = (0..3).step_by(1); + assert_eq!(it.next_back(), Some(2)); + assert_eq!(it.next_back(), Some(1)); + assert_eq!(it.next_back(), Some(0)); + assert_eq!(it.next_back(), None); + + let mut it = (0..11).step_by(3); + assert_eq!(it.next_back(), Some(9)); + assert_eq!(it.next_back(), Some(6)); + assert_eq!(it.next_back(), Some(3)); + assert_eq!(it.next_back(), Some(0)); + assert_eq!(it.next_back(), None); } #[test] @@ -252,6 +265,31 @@ fn test_iterator_step_by_nth_overflow() { assert_eq!(it.0, (usize::MAX as Bigger) * 1); } +#[test] +fn test_iterator_step_by_nth_back() { + let mut it = (0..16).step_by(5); + assert_eq!(it.nth_back(0), Some(15)); + assert_eq!(it.nth_back(0), Some(10)); + assert_eq!(it.nth_back(0), Some(5)); + assert_eq!(it.nth_back(0), Some(0)); + assert_eq!(it.nth_back(0), None); + + let mut it = (0..16).step_by(5); + assert_eq!(it.next(), Some(0)); // to set `first_take` to `false` + assert_eq!(it.nth_back(0), Some(15)); + assert_eq!(it.nth_back(0), Some(10)); + assert_eq!(it.nth_back(0), Some(5)); + assert_eq!(it.nth_back(0), None); + + let it = || (0..18).step_by(5); + assert_eq!(it().nth_back(0), Some(15)); + assert_eq!(it().nth_back(1), Some(10)); + assert_eq!(it().nth_back(2), Some(5)); + assert_eq!(it().nth_back(3), Some(0)); + assert_eq!(it().nth_back(4), None); + assert_eq!(it().nth_back(42), None); +} + #[test] #[should_panic] fn test_iterator_step_by_zero() { @@ -465,8 +503,8 @@ fn test_iterator_filter_fold() { #[test] fn test_iterator_peekable() { let xs = vec![0, 1, 2, 3, 4, 5]; - let mut it = xs.iter().cloned().peekable(); + let mut it = xs.iter().cloned().peekable(); assert_eq!(it.len(), 6); assert_eq!(it.peek().unwrap(), &0); assert_eq!(it.len(), 6); @@ -492,6 +530,33 @@ fn test_iterator_peekable() { assert_eq!(it.len(), 0); assert!(it.next().is_none()); assert_eq!(it.len(), 0); + + let mut it = xs.iter().cloned().peekable(); + assert_eq!(it.len(), 6); + assert_eq!(it.peek().unwrap(), &0); + assert_eq!(it.len(), 6); + assert_eq!(it.next_back().unwrap(), 5); + assert_eq!(it.len(), 5); + assert_eq!(it.next_back().unwrap(), 4); + assert_eq!(it.len(), 4); + assert_eq!(it.next_back().unwrap(), 3); + assert_eq!(it.len(), 3); + assert_eq!(it.peek().unwrap(), &0); + assert_eq!(it.len(), 3); + assert_eq!(it.peek().unwrap(), &0); + assert_eq!(it.len(), 3); + assert_eq!(it.next_back().unwrap(), 2); + assert_eq!(it.len(), 2); + assert_eq!(it.next_back().unwrap(), 1); + assert_eq!(it.len(), 1); + assert_eq!(it.peek().unwrap(), &0); + assert_eq!(it.len(), 1); + assert_eq!(it.next_back().unwrap(), 0); + assert_eq!(it.len(), 0); + assert!(it.peek().is_none()); + assert_eq!(it.len(), 0); + assert!(it.next_back().is_none()); + assert_eq!(it.len(), 0); } #[test] @@ -564,6 +629,18 @@ fn test_iterator_peekable_fold() { assert_eq!(i, xs.len()); } +#[test] +fn test_iterator_peekable_rfold() { + let xs = [0, 1, 2, 3, 4, 5]; + let mut it = xs.iter().peekable(); + assert_eq!(it.peek(), Some(&&0)); + let i = it.rfold(0, |i, &x| { + assert_eq!(x, xs[xs.len() - 1 - i]); + i + 1 + }); + assert_eq!(i, xs.len()); +} + /// This is an iterator that follows the Iterator contract, /// but it is not fused. After having returned None once, it will start /// producing elements if .next() is called again. @@ -812,13 +889,25 @@ fn test_iterator_skip_fold() { fn test_iterator_take() { let xs = [0, 1, 2, 3, 5, 13, 15, 16, 17, 19]; let ys = [0, 1, 2, 3, 5]; - let mut it = xs.iter().take(5); + + let mut it = xs.iter().take(ys.len()); let mut i = 0; - assert_eq!(it.len(), 5); + assert_eq!(it.len(), ys.len()); while let Some(&x) = it.next() { assert_eq!(x, ys[i]); i += 1; - assert_eq!(it.len(), 5-i); + assert_eq!(it.len(), ys.len() - i); + } + assert_eq!(i, ys.len()); + assert_eq!(it.len(), 0); + + let mut it = xs.iter().take(ys.len()); + let mut i = 0; + assert_eq!(it.len(), ys.len()); + while let Some(&x) = it.next_back() { + i += 1; + assert_eq!(x, ys[ys.len() - i]); + assert_eq!(it.len(), ys.len() - i); } assert_eq!(i, ys.len()); assert_eq!(it.len(), 0); @@ -848,19 +937,51 @@ fn test_iterator_take_nth() { } } +#[test] +fn test_iterator_take_nth_back() { + let xs = [0, 1, 2, 4, 5]; + let mut it = xs.iter(); + { + let mut take = it.by_ref().take(3); + let mut i = 0; + while let Some(&x) = take.nth_back(0) { + i += 1; + assert_eq!(x, 3 - i); + } + } + assert_eq!(it.nth_back(0), None); + + let xs = [0, 1, 2, 3, 4]; + let mut it = xs.iter().take(7); + assert_eq!(it.nth_back(1), Some(&3)); + assert_eq!(it.nth_back(1), Some(&1)); + assert_eq!(it.nth_back(1), None); +} + #[test] fn test_iterator_take_short() { let xs = [0, 1, 2, 3]; - let ys = [0, 1, 2, 3]; + let mut it = xs.iter().take(5); let mut i = 0; - assert_eq!(it.len(), 4); + assert_eq!(it.len(), xs.len()); while let Some(&x) = it.next() { - assert_eq!(x, ys[i]); + assert_eq!(x, xs[i]); i += 1; - assert_eq!(it.len(), 4-i); + assert_eq!(it.len(), xs.len() - i); } - assert_eq!(i, ys.len()); + assert_eq!(i, xs.len()); + assert_eq!(it.len(), 0); + + let mut it = xs.iter().take(5); + let mut i = 0; + assert_eq!(it.len(), xs.len()); + while let Some(&x) = it.next_back() { + i += 1; + assert_eq!(x, xs[xs.len() - i]); + assert_eq!(it.len(), xs.len() - i); + } + assert_eq!(i, xs.len()); assert_eq!(it.len(), 0); } @@ -2241,17 +2362,50 @@ fn test_enumerate_try_folds() { } #[test] -fn test_peek_try_fold() { +fn test_peek_try_folds() { let f = &|acc, x| i32::checked_add(2*acc, x); + assert_eq!((1..20).peekable().try_fold(7, f), (1..20).try_fold(7, f)); + assert_eq!((1..20).peekable().try_rfold(7, f), (1..20).try_rfold(7, f)); + let mut iter = (1..20).peekable(); assert_eq!(iter.peek(), Some(&1)); assert_eq!(iter.try_fold(7, f), (1..20).try_fold(7, f)); + let mut iter = (1..20).peekable(); + assert_eq!(iter.peek(), Some(&1)); + assert_eq!(iter.try_rfold(7, f), (1..20).try_rfold(7, f)); + let mut iter = [100, 20, 30, 40, 50, 60, 70].iter().cloned().peekable(); assert_eq!(iter.peek(), Some(&100)); assert_eq!(iter.try_fold(0, i8::checked_add), None); assert_eq!(iter.peek(), Some(&40)); + + let mut iter = [100, 20, 30, 40, 50, 60, 70].iter().cloned().peekable(); + assert_eq!(iter.peek(), Some(&100)); + assert_eq!(iter.try_rfold(0, i8::checked_add), None); + assert_eq!(iter.peek(), Some(&100)); + assert_eq!(iter.next_back(), Some(50)); + + let mut iter = (2..5).peekable(); + assert_eq!(iter.peek(), Some(&2)); + assert_eq!(iter.try_for_each(Err), Err(2)); + assert_eq!(iter.peek(), Some(&3)); + assert_eq!(iter.try_for_each(Err), Err(3)); + assert_eq!(iter.peek(), Some(&4)); + assert_eq!(iter.try_for_each(Err), Err(4)); + assert_eq!(iter.peek(), None); + assert_eq!(iter.try_for_each(Err), Ok(())); + + let mut iter = (2..5).peekable(); + assert_eq!(iter.peek(), Some(&2)); + assert_eq!(iter.try_rfold((), |(), x| Err(x)), Err(4)); + assert_eq!(iter.peek(), Some(&2)); + assert_eq!(iter.try_rfold((), |(), x| Err(x)), Err(3)); + assert_eq!(iter.peek(), Some(&2)); + assert_eq!(iter.try_rfold((), |(), x| Err(x)), Err(2)); + assert_eq!(iter.peek(), None); + assert_eq!(iter.try_rfold((), |(), x| Err(x)), Ok(())); } #[test] @@ -2300,13 +2454,25 @@ fn test_skip_try_folds() { fn test_take_try_folds() { let f = &|acc, x| i32::checked_add(2*acc, x); assert_eq!((10..30).take(10).try_fold(7, f), (10..20).try_fold(7, f)); - //assert_eq!((10..30).take(10).try_rfold(7, f), (10..20).try_rfold(7, f)); + assert_eq!((10..30).take(10).try_rfold(7, f), (10..20).try_rfold(7, f)); let mut iter = (10..30).take(20); assert_eq!(iter.try_fold(0, i8::checked_add), None); assert_eq!(iter.next(), Some(20)); - //assert_eq!(iter.try_rfold(0, i8::checked_add), None); - //assert_eq!(iter.next_back(), Some(24)); + assert_eq!(iter.try_rfold(0, i8::checked_add), None); + assert_eq!(iter.next_back(), Some(24)); + + let mut iter = (2..20).take(3); + assert_eq!(iter.try_for_each(Err), Err(2)); + assert_eq!(iter.try_for_each(Err), Err(3)); + assert_eq!(iter.try_for_each(Err), Err(4)); + assert_eq!(iter.try_for_each(Err), Ok(())); + + let mut iter = (2..20).take(3).rev(); + assert_eq!(iter.try_for_each(Err), Err(4)); + assert_eq!(iter.try_for_each(Err), Err(3)); + assert_eq!(iter.try_for_each(Err), Err(2)); + assert_eq!(iter.try_for_each(Err), Ok(())); } #[test] From 3b15b1664e2856a2a7cf430676355c82f2aac65b Mon Sep 17 00:00:00 2001 From: Jason Shin Date: Thu, 1 Aug 2019 12:42:52 +1000 Subject: [PATCH 02/32] Explaining the reason why validation is performed in to_str of path.rs --- src/libstd/path.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/libstd/path.rs b/src/libstd/path.rs index 126bc3754dabc..21c4968bfbe8b 100644 --- a/src/libstd/path.rs +++ b/src/libstd/path.rs @@ -1819,6 +1819,8 @@ impl Path { /// Yields a [`&str`] slice if the `Path` is valid unicode. /// /// This conversion may entail doing a check for UTF-8 validity. + /// Also it it worthwhile noting that validation is performed because Non-UTF-8 strings are + /// perfectly valid for some OS. /// /// [`&str`]: ../primitive.str.html /// From 1aa4a578276b2a3f7c47dcea7ad75786982550d4 Mon Sep 17 00:00:00 2001 From: Jason Shin Date: Thu, 1 Aug 2019 13:55:01 +1000 Subject: [PATCH 03/32] Update src/libstd/path.rs to shorten the explanation for .to_str validation step Co-Authored-By: Mazdak Farrokhzad --- src/libstd/path.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libstd/path.rs b/src/libstd/path.rs index 21c4968bfbe8b..56fde77daac58 100644 --- a/src/libstd/path.rs +++ b/src/libstd/path.rs @@ -1819,7 +1819,7 @@ impl Path { /// Yields a [`&str`] slice if the `Path` is valid unicode. /// /// This conversion may entail doing a check for UTF-8 validity. - /// Also it it worthwhile noting that validation is performed because Non-UTF-8 strings are + /// Note that validation is performed because non-UTF-8 strings are /// perfectly valid for some OS. /// /// [`&str`]: ../primitive.str.html From 83b5eb961528972acaa13992a9bbbe9574458550 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Tue, 30 Jul 2019 17:46:46 -0700 Subject: [PATCH 04/32] Always error on `SizeOverflow` during mir evaluation --- src/librustc/mir/interpret/error.rs | 1 - src/test/ui/consts/issue-55878.rs | 4 ++++ src/test/ui/consts/issue-55878.stderr | 15 +++++++++++++++ src/test/ui/issues/issue-56762.rs | 2 ++ src/test/ui/issues/issue-56762.stderr | 15 +++++++++++++-- 5 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 src/test/ui/consts/issue-55878.rs create mode 100644 src/test/ui/consts/issue-55878.stderr diff --git a/src/librustc/mir/interpret/error.rs b/src/librustc/mir/interpret/error.rs index 8d41b019c221a..7c1941196390a 100644 --- a/src/librustc/mir/interpret/error.rs +++ b/src/librustc/mir/interpret/error.rs @@ -141,7 +141,6 @@ impl<'tcx> ConstEvalErr<'tcx> { err_inval!(Layout(LayoutError::Unknown(_))) | err_inval!(TooGeneric) => return Err(ErrorHandled::TooGeneric), - err_inval!(Layout(LayoutError::SizeOverflow(_))) | err_inval!(TypeckError) => return Err(ErrorHandled::Reported), _ => {}, diff --git a/src/test/ui/consts/issue-55878.rs b/src/test/ui/consts/issue-55878.rs new file mode 100644 index 0000000000000..ce6c25742870e --- /dev/null +++ b/src/test/ui/consts/issue-55878.rs @@ -0,0 +1,4 @@ +// error-pattern: reaching this expression at runtime will panic or abort +fn main() { + println!("Size: {}", std::mem::size_of::<[u8; std::u64::MAX as usize]>()); +} diff --git a/src/test/ui/consts/issue-55878.stderr b/src/test/ui/consts/issue-55878.stderr new file mode 100644 index 0000000000000..03537ff20bf5e --- /dev/null +++ b/src/test/ui/consts/issue-55878.stderr @@ -0,0 +1,15 @@ +error: reaching this expression at runtime will panic or abort + --> $SRC_DIR/libcore/mem/mod.rs:LL:COL + | +LL | intrinsics::size_of::() + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ rustc layout computation failed: SizeOverflow([u8; 18446744073709551615]) + | + ::: $DIR/issue-55878.rs:3:26 + | +LL | println!("Size: {}", std::mem::size_of::<[u8; std::u64::MAX as usize]>()); + | --------------------------------------------------- + | + = note: `#[deny(const_err)]` on by default + +error: aborting due to previous error + diff --git a/src/test/ui/issues/issue-56762.rs b/src/test/ui/issues/issue-56762.rs index 8bb81b907c9a4..f12d0121a8f1a 100644 --- a/src/test/ui/issues/issue-56762.rs +++ b/src/test/ui/issues/issue-56762.rs @@ -17,6 +17,8 @@ impl TooBigArray { } static MY_TOO_BIG_ARRAY_1: TooBigArray = TooBigArray::new(); +//~^ ERROR could not evaluate static initializer static MY_TOO_BIG_ARRAY_2: [u8; HUGE_SIZE] = [0x00; HUGE_SIZE]; +//~^ ERROR could not evaluate static initializer fn main() { } diff --git a/src/test/ui/issues/issue-56762.stderr b/src/test/ui/issues/issue-56762.stderr index 83d5dc62e6161..fa7b9c71eb4a2 100644 --- a/src/test/ui/issues/issue-56762.stderr +++ b/src/test/ui/issues/issue-56762.stderr @@ -1,4 +1,15 @@ -error: the type `[u8; 2305843009213693951]` is too big for the current architecture +error[E0080]: could not evaluate static initializer + --> $DIR/issue-56762.rs:19:1 + | +LL | static MY_TOO_BIG_ARRAY_1: TooBigArray = TooBigArray::new(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ rustc layout computation failed: SizeOverflow([u8; 2305843009213693951]) -error: aborting due to previous error +error[E0080]: could not evaluate static initializer + --> $DIR/issue-56762.rs:21:1 + | +LL | static MY_TOO_BIG_ARRAY_2: [u8; HUGE_SIZE] = [0x00; HUGE_SIZE]; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ rustc layout computation failed: SizeOverflow([u8; 2305843009213693951]) +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0080`. From 58bd8786e891f69fcb7982938a635d4f8b16496b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Wed, 31 Jul 2019 14:10:33 -0700 Subject: [PATCH 05/32] Do not lint on SizeOverflow, always error --- src/librustc/mir/interpret/error.rs | 4 +++- src/test/ui/consts/issue-55878.stderr | 5 ++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/librustc/mir/interpret/error.rs b/src/librustc/mir/interpret/error.rs index 7c1941196390a..acdabd1e53d63 100644 --- a/src/librustc/mir/interpret/error.rs +++ b/src/librustc/mir/interpret/error.rs @@ -137,16 +137,18 @@ impl<'tcx> ConstEvalErr<'tcx> { message: &str, lint_root: Option, ) -> Result, ErrorHandled> { + let mut must_error = false; match self.error { err_inval!(Layout(LayoutError::Unknown(_))) | err_inval!(TooGeneric) => return Err(ErrorHandled::TooGeneric), err_inval!(TypeckError) => return Err(ErrorHandled::Reported), + err_inval!(LayoutError::SizeOverflow(_)) => must_error = true, _ => {}, } trace!("reporting const eval failure at {:?}", self.span); - let mut err = if let Some(lint_root) = lint_root { + let mut err = if let (Some(lint_root), false) = (lint_root, must_error) { let hir_id = self.stacktrace .iter() .rev() diff --git a/src/test/ui/consts/issue-55878.stderr b/src/test/ui/consts/issue-55878.stderr index 03537ff20bf5e..7ca7024912fbb 100644 --- a/src/test/ui/consts/issue-55878.stderr +++ b/src/test/ui/consts/issue-55878.stderr @@ -1,4 +1,4 @@ -error: reaching this expression at runtime will panic or abort +error[E0080]: reaching this expression at runtime will panic or abort --> $SRC_DIR/libcore/mem/mod.rs:LL:COL | LL | intrinsics::size_of::() @@ -8,8 +8,7 @@ LL | intrinsics::size_of::() | LL | println!("Size: {}", std::mem::size_of::<[u8; std::u64::MAX as usize]>()); | --------------------------------------------------- - | - = note: `#[deny(const_err)]` on by default error: aborting due to previous error +For more information about this error, try `rustc --explain E0080`. From d3da411a080fb19c9cba2b812a48fb0a57c03013 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Wed, 31 Jul 2019 16:22:34 -0700 Subject: [PATCH 06/32] Nicer labels for type layout errors --- src/librustc/mir/interpret/error.rs | 4 ++-- src/test/ui/consts/issue-55878.stderr | 2 +- src/test/ui/issues/issue-56762.stderr | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/librustc/mir/interpret/error.rs b/src/librustc/mir/interpret/error.rs index acdabd1e53d63..05978ae3c6f7a 100644 --- a/src/librustc/mir/interpret/error.rs +++ b/src/librustc/mir/interpret/error.rs @@ -144,7 +144,7 @@ impl<'tcx> ConstEvalErr<'tcx> { return Err(ErrorHandled::TooGeneric), err_inval!(TypeckError) => return Err(ErrorHandled::Reported), - err_inval!(LayoutError::SizeOverflow(_)) => must_error = true, + err_inval!(Layout(LayoutError::SizeOverflow(_))) => must_error = true, _ => {}, } trace!("reporting const eval failure at {:?}", self.span); @@ -336,7 +336,7 @@ impl fmt::Debug for InvalidProgramInfo<'tcx> { TypeckError => write!(f, "encountered constants with type errors, stopping evaluation"), Layout(ref err) => - write!(f, "rustc layout computation failed: {:?}", err), + write!(f, "{}", err), } } } diff --git a/src/test/ui/consts/issue-55878.stderr b/src/test/ui/consts/issue-55878.stderr index 7ca7024912fbb..adb272f4bed9c 100644 --- a/src/test/ui/consts/issue-55878.stderr +++ b/src/test/ui/consts/issue-55878.stderr @@ -2,7 +2,7 @@ error[E0080]: reaching this expression at runtime will panic or abort --> $SRC_DIR/libcore/mem/mod.rs:LL:COL | LL | intrinsics::size_of::() - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ rustc layout computation failed: SizeOverflow([u8; 18446744073709551615]) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ the type `[u8; 18446744073709551615]` is too big for the current architecture | ::: $DIR/issue-55878.rs:3:26 | diff --git a/src/test/ui/issues/issue-56762.stderr b/src/test/ui/issues/issue-56762.stderr index fa7b9c71eb4a2..bce95087c5ce4 100644 --- a/src/test/ui/issues/issue-56762.stderr +++ b/src/test/ui/issues/issue-56762.stderr @@ -2,13 +2,13 @@ error[E0080]: could not evaluate static initializer --> $DIR/issue-56762.rs:19:1 | LL | static MY_TOO_BIG_ARRAY_1: TooBigArray = TooBigArray::new(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ rustc layout computation failed: SizeOverflow([u8; 2305843009213693951]) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the type `[u8; 2305843009213693951]` is too big for the current architecture error[E0080]: could not evaluate static initializer --> $DIR/issue-56762.rs:21:1 | LL | static MY_TOO_BIG_ARRAY_2: [u8; HUGE_SIZE] = [0x00; HUGE_SIZE]; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ rustc layout computation failed: SizeOverflow([u8; 2305843009213693951]) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the type `[u8; 2305843009213693951]` is too big for the current architecture error: aborting due to 2 previous errors From dad56c39474377c7d47e261b380d0be3aed104cc Mon Sep 17 00:00:00 2001 From: Thomas de Zeeuw Date: Thu, 25 Jul 2019 22:30:52 +0200 Subject: [PATCH 07/32] Add {IoSlice, IoSliceMut}::advance --- src/libstd/io/mod.rs | 200 +++++++++++++++++++++++++++++++++- src/libstd/sys/cloudabi/io.rs | 14 +++ src/libstd/sys/redox/io.rs | 14 +++ src/libstd/sys/sgx/io.rs | 14 +++ src/libstd/sys/unix/io.rs | 24 ++++ src/libstd/sys/vxworks/io.rs | 24 ++++ src/libstd/sys/wasi/io.rs | 24 ++++ src/libstd/sys/wasm/io.rs | 14 +++ src/libstd/sys/windows/io.rs | 24 ++++ 9 files changed, 351 insertions(+), 1 deletion(-) diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index f89a714443715..f2b6ce6feb295 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -942,6 +942,62 @@ impl<'a> IoSliceMut<'a> { pub fn new(buf: &'a mut [u8]) -> IoSliceMut<'a> { IoSliceMut(sys::io::IoSliceMut::new(buf)) } + + /// Advance the internal cursor of the slice. + /// + /// # Notes + /// + /// Elements in the slice may be modified if the cursor is not advanced to + /// the end of the slice. For example if we have a slice of buffers with 2 + /// `IoSliceMut`s, both of length 8, and we advance the cursor by 10 bytes + /// the first `IoSliceMut` will be untouched however the second will be + /// modified to remove the first 2 bytes (10 - 8). + /// + /// # Examples + /// + /// ``` + /// #![feature(io_slice_advance)] + /// + /// use std::io::IoSliceMut; + /// use std::mem; + /// use std::ops::Deref; + /// + /// let mut buf1 = [1; 8]; + /// let mut buf2 = [2; 16]; + /// let mut buf3 = [3; 8]; + /// let mut bufs = &mut [ + /// IoSliceMut::new(&mut buf1), + /// IoSliceMut::new(&mut buf2), + /// IoSliceMut::new(&mut buf3), + /// ][..]; + /// + /// // Mark 10 bytes as read. + /// bufs = IoSliceMut::advance(mem::replace(&mut bufs, &mut []), 10); + /// assert_eq!(bufs[0].deref(), [2; 14].as_ref()); + /// assert_eq!(bufs[1].deref(), [3; 8].as_ref()); + /// ``` + #[unstable(feature = "io_slice_advance", issue = "62726")] + #[inline] + pub fn advance<'b>(bufs: &'b mut [IoSliceMut<'a>], n: usize) -> &'b mut [IoSliceMut<'a>] { + // Number of buffers to remove. + let mut remove = 0; + // Total length of all the to be removed buffers. + let mut accumulated_len = 0; + for buf in bufs.iter() { + if accumulated_len + buf.len() > n { + break; + } else { + accumulated_len += buf.len(); + remove += 1; + } + } + + let bufs = &mut bufs[remove..]; + if !bufs.is_empty() { + bufs[0].0.advance(n - accumulated_len) + } + bufs + } } #[stable(feature = "iovec", since = "1.36.0")] @@ -989,6 +1045,61 @@ impl<'a> IoSlice<'a> { pub fn new(buf: &'a [u8]) -> IoSlice<'a> { IoSlice(sys::io::IoSlice::new(buf)) } + + /// Advance the internal cursor of the slice. + /// + /// # Notes + /// + /// Elements in the slice may be modified if the cursor is not advanced to + /// the end of the slice. For example if we have a slice of buffers with 2 + /// `IoSlice`s, both of length 8, and we advance the cursor by 10 bytes the + /// first `IoSlice` will be untouched however the second will be modified to + /// remove the first 2 bytes (10 - 8). + /// + /// # Examples + /// + /// ``` + /// #![feature(io_slice_advance)] + /// + /// use std::io::IoSlice; + /// use std::mem; + /// use std::ops::Deref; + /// + /// let mut buf1 = [1; 8]; + /// let mut buf2 = [2; 16]; + /// let mut buf3 = [3; 8]; + /// let mut bufs = &mut [ + /// IoSlice::new(&mut buf1), + /// IoSlice::new(&mut buf2), + /// IoSlice::new(&mut buf3), + /// ][..]; + /// + /// // Mark 10 bytes as written. + /// bufs = IoSlice::advance(mem::replace(&mut bufs, &mut []), 10); + /// assert_eq!(bufs[0].deref(), [2; 14].as_ref()); + /// assert_eq!(bufs[1].deref(), [3; 8].as_ref()); + #[unstable(feature = "io_slice_advance", issue = "62726")] + #[inline] + pub fn advance<'b>(bufs: &'b mut [IoSlice<'a>], n: usize) -> &'b mut [IoSlice<'a>] { + // Number of buffers to remove. + let mut remove = 0; + // Total length of all the to be removed buffers. + let mut accumulated_len = 0; + for buf in bufs.iter() { + if accumulated_len + buf.len() > n { + break; + } else { + accumulated_len += buf.len(); + remove += 1; + } + } + + let bufs = &mut bufs[remove..]; + if !bufs.is_empty() { + bufs[0].0.advance(n - accumulated_len) + } + bufs + } } #[stable(feature = "iovec", since = "1.36.0")] @@ -2268,8 +2379,10 @@ impl Iterator for Lines { #[cfg(test)] mod tests { use crate::io::prelude::*; - use crate::io; use super::{Cursor, SeekFrom, repeat}; + use crate::io::{self, IoSlice, IoSliceMut}; + use crate::mem; + use crate::ops::Deref; #[test] #[cfg_attr(target_os = "emscripten", ignore)] @@ -2537,4 +2650,89 @@ mod tests { Ok(()) } + + #[test] + fn io_slice_mut_advance() { + let mut buf1 = [1; 8]; + let mut buf2 = [2; 16]; + let mut buf3 = [3; 8]; + let mut bufs = &mut [ + IoSliceMut::new(&mut buf1), + IoSliceMut::new(&mut buf2), + IoSliceMut::new(&mut buf3), + ][..]; + + // Only in a single buffer.. + bufs = IoSliceMut::advance(mem::replace(&mut bufs, &mut []), 1); + assert_eq!(bufs[0].deref(), [1; 7].as_ref()); + assert_eq!(bufs[1].deref(), [2; 16].as_ref()); + assert_eq!(bufs[2].deref(), [3; 8].as_ref()); + + // Removing a buffer, leaving others as is. + bufs = IoSliceMut::advance(mem::replace(&mut bufs, &mut []), 7); + assert_eq!(bufs[0].deref(), [2; 16].as_ref()); + assert_eq!(bufs[1].deref(), [3; 8].as_ref()); + + // Removing a buffer and removing from the next buffer. + bufs = IoSliceMut::advance(mem::replace(&mut bufs, &mut []), 18); + assert_eq!(bufs[0].deref(), [3; 6].as_ref()); + } + + #[test] + fn io_slice_mut_advance_empty_slice() { + let mut empty_bufs = &mut [][..]; + // Shouldn't panic. + IoSliceMut::advance(&mut empty_bufs, 1); + } + + #[test] + fn io_slice_mut_advance_beyond_total_length() { + let mut buf1 = [1; 8]; + let mut bufs = &mut [IoSliceMut::new(&mut buf1)][..]; + + // Going beyond the total length should be ok. + bufs = IoSliceMut::advance(mem::replace(&mut bufs, &mut []), 9); + assert!(bufs.is_empty()); + } + + #[test] + fn io_slice_advance() { + let mut buf1 = [1; 8]; + let mut buf2 = [2; 16]; + let mut buf3 = [3; 8]; + let mut bufs = + &mut [IoSlice::new(&mut buf1), IoSlice::new(&mut buf2), IoSlice::new(&mut buf3)][..]; + + // Only in a single buffer.. + bufs = IoSlice::advance(mem::replace(&mut bufs, &mut []), 1); + assert_eq!(bufs[0].deref(), [1; 7].as_ref()); + assert_eq!(bufs[1].deref(), [2; 16].as_ref()); + assert_eq!(bufs[2].deref(), [3; 8].as_ref()); + + // Removing a buffer, leaving others as is. + bufs = IoSlice::advance(mem::replace(&mut bufs, &mut []), 7); + assert_eq!(bufs[0].deref(), [2; 16].as_ref()); + assert_eq!(bufs[1].deref(), [3; 8].as_ref()); + + // Removing a buffer and removing from the next buffer. + bufs = IoSlice::advance(mem::replace(&mut bufs, &mut []), 18); + assert_eq!(bufs[0].deref(), [3; 6].as_ref()); + } + + #[test] + fn io_slice_advance_empty_slice() { + let mut empty_bufs = &mut [][..]; + // Shouldn't panic. + IoSlice::advance(&mut empty_bufs, 1); + } + + #[test] + fn io_slice_advance_beyond_total_length() { + let mut buf1 = [1; 8]; + let mut bufs = &mut [IoSlice::new(&mut buf1)][..]; + + // Going beyond the total length should be ok. + bufs = IoSlice::advance(mem::replace(&mut bufs, &mut []), 9); + assert!(bufs.is_empty()); + } } diff --git a/src/libstd/sys/cloudabi/io.rs b/src/libstd/sys/cloudabi/io.rs index 4b423a5cbc11a..976e122463d1b 100644 --- a/src/libstd/sys/cloudabi/io.rs +++ b/src/libstd/sys/cloudabi/io.rs @@ -1,3 +1,5 @@ +use crate::mem; + pub struct IoSlice<'a>(&'a [u8]); impl<'a> IoSlice<'a> { @@ -6,6 +8,11 @@ impl<'a> IoSlice<'a> { IoSlice(buf) } + #[inline] + pub fn advance(&mut self, n: usize) { + self.0 = &self.0[n..] + } + #[inline] pub fn as_slice(&self) -> &[u8] { self.0 @@ -20,6 +27,13 @@ impl<'a> IoSliceMut<'a> { IoSliceMut(buf) } + #[inline] + pub fn advance(&mut self, n: usize) { + let slice = mem::replace(&mut self.0, &mut []); + let (_, remaining) = slice.split_at_mut(n); + self.0 = remaining; + } + #[inline] pub fn as_slice(&self) -> &[u8] { self.0 diff --git a/src/libstd/sys/redox/io.rs b/src/libstd/sys/redox/io.rs index 4b423a5cbc11a..976e122463d1b 100644 --- a/src/libstd/sys/redox/io.rs +++ b/src/libstd/sys/redox/io.rs @@ -1,3 +1,5 @@ +use crate::mem; + pub struct IoSlice<'a>(&'a [u8]); impl<'a> IoSlice<'a> { @@ -6,6 +8,11 @@ impl<'a> IoSlice<'a> { IoSlice(buf) } + #[inline] + pub fn advance(&mut self, n: usize) { + self.0 = &self.0[n..] + } + #[inline] pub fn as_slice(&self) -> &[u8] { self.0 @@ -20,6 +27,13 @@ impl<'a> IoSliceMut<'a> { IoSliceMut(buf) } + #[inline] + pub fn advance(&mut self, n: usize) { + let slice = mem::replace(&mut self.0, &mut []); + let (_, remaining) = slice.split_at_mut(n); + self.0 = remaining; + } + #[inline] pub fn as_slice(&self) -> &[u8] { self.0 diff --git a/src/libstd/sys/sgx/io.rs b/src/libstd/sys/sgx/io.rs index 4b423a5cbc11a..976e122463d1b 100644 --- a/src/libstd/sys/sgx/io.rs +++ b/src/libstd/sys/sgx/io.rs @@ -1,3 +1,5 @@ +use crate::mem; + pub struct IoSlice<'a>(&'a [u8]); impl<'a> IoSlice<'a> { @@ -6,6 +8,11 @@ impl<'a> IoSlice<'a> { IoSlice(buf) } + #[inline] + pub fn advance(&mut self, n: usize) { + self.0 = &self.0[n..] + } + #[inline] pub fn as_slice(&self) -> &[u8] { self.0 @@ -20,6 +27,13 @@ impl<'a> IoSliceMut<'a> { IoSliceMut(buf) } + #[inline] + pub fn advance(&mut self, n: usize) { + let slice = mem::replace(&mut self.0, &mut []); + let (_, remaining) = slice.split_at_mut(n); + self.0 = remaining; + } + #[inline] pub fn as_slice(&self) -> &[u8] { self.0 diff --git a/src/libstd/sys/unix/io.rs b/src/libstd/sys/unix/io.rs index bc854e772e16f..a3a7291917697 100644 --- a/src/libstd/sys/unix/io.rs +++ b/src/libstd/sys/unix/io.rs @@ -21,6 +21,18 @@ impl<'a> IoSlice<'a> { } } + #[inline] + pub fn advance(&mut self, n: usize) { + if self.vec.iov_len < n { + panic!("advancing IoSlice beyond its length"); + } + + unsafe { + self.vec.iov_len -= n; + self.vec.iov_base = self.vec.iov_base.add(n); + } + } + #[inline] pub fn as_slice(&self) -> &[u8] { unsafe { @@ -47,6 +59,18 @@ impl<'a> IoSliceMut<'a> { } } + #[inline] + pub fn advance(&mut self, n: usize) { + if self.vec.iov_len < n { + panic!("advancing IoSliceMut beyond its length"); + } + + unsafe { + self.vec.iov_len -= n; + self.vec.iov_base = self.vec.iov_base.add(n); + } + } + #[inline] pub fn as_slice(&self) -> &[u8] { unsafe { diff --git a/src/libstd/sys/vxworks/io.rs b/src/libstd/sys/vxworks/io.rs index 72954ff20ef95..8cd11cbf5df4e 100644 --- a/src/libstd/sys/vxworks/io.rs +++ b/src/libstd/sys/vxworks/io.rs @@ -21,6 +21,18 @@ impl<'a> IoSlice<'a> { } } + #[inline] + pub fn advance(&mut self, n: usize) { + if self.vec.iov_len < n { + panic!("advancing IoSlice beyond its length"); + } + + unsafe { + self.vec.iov_len -= n; + self.vec.iov_base = self.vec.iov_base.add(n); + } + } + #[inline] pub fn as_slice(&self) -> &[u8] { unsafe { @@ -46,6 +58,18 @@ impl<'a> IoSliceMut<'a> { } } + #[inline] + pub fn advance(&mut self, n: usize) { + if self.vec.iov_len < n { + panic!("advancing IoSliceMut beyond its length"); + } + + unsafe { + self.vec.iov_len -= n; + self.vec.iov_base = self.vec.iov_base.add(n); + } + } + #[inline] pub fn as_slice(&self) -> &[u8] { unsafe { diff --git a/src/libstd/sys/wasi/io.rs b/src/libstd/sys/wasi/io.rs index a5bddad708b19..ffecca5d1b6ff 100644 --- a/src/libstd/sys/wasi/io.rs +++ b/src/libstd/sys/wasi/io.rs @@ -21,6 +21,18 @@ impl<'a> IoSlice<'a> { } } + #[inline] + pub fn advance(&mut self, n: usize) { + if self.vec.buf_len < n { + panic!("advancing IoSlice beyond its length"); + } + + unsafe { + self.vec.buf_len -= n; + self.vec.buf = self.vec.buf.add(n); + } + } + #[inline] pub fn as_slice(&self) -> &[u8] { unsafe { @@ -47,6 +59,18 @@ impl<'a> IoSliceMut<'a> { } } + #[inline] + pub fn advance(&mut self, n: usize) { + if self.vec.buf_len < n { + panic!("advancing IoSlice beyond its length"); + } + + unsafe { + self.vec.buf_len -= n; + self.vec.buf = self.vec.buf.add(n); + } + } + #[inline] pub fn as_slice(&self) -> &[u8] { unsafe { diff --git a/src/libstd/sys/wasm/io.rs b/src/libstd/sys/wasm/io.rs index 4b423a5cbc11a..976e122463d1b 100644 --- a/src/libstd/sys/wasm/io.rs +++ b/src/libstd/sys/wasm/io.rs @@ -1,3 +1,5 @@ +use crate::mem; + pub struct IoSlice<'a>(&'a [u8]); impl<'a> IoSlice<'a> { @@ -6,6 +8,11 @@ impl<'a> IoSlice<'a> { IoSlice(buf) } + #[inline] + pub fn advance(&mut self, n: usize) { + self.0 = &self.0[n..] + } + #[inline] pub fn as_slice(&self) -> &[u8] { self.0 @@ -20,6 +27,13 @@ impl<'a> IoSliceMut<'a> { IoSliceMut(buf) } + #[inline] + pub fn advance(&mut self, n: usize) { + let slice = mem::replace(&mut self.0, &mut []); + let (_, remaining) = slice.split_at_mut(n); + self.0 = remaining; + } + #[inline] pub fn as_slice(&self) -> &[u8] { self.0 diff --git a/src/libstd/sys/windows/io.rs b/src/libstd/sys/windows/io.rs index f0da2323f4f57..e44dcbe164daf 100644 --- a/src/libstd/sys/windows/io.rs +++ b/src/libstd/sys/windows/io.rs @@ -21,6 +21,18 @@ impl<'a> IoSlice<'a> { } } + #[inline] + pub fn advance(&mut self, n: usize) { + if (self.vec.len as usize) < n { + panic!("advancing IoSlice beyond its length"); + } + + unsafe { + self.vec.len -= n as c::ULONG; + self.vec.buf = self.vec.buf.add(n); + } + } + #[inline] pub fn as_slice(&self) -> &[u8] { unsafe { @@ -48,6 +60,18 @@ impl<'a> IoSliceMut<'a> { } } + #[inline] + pub fn advance(&mut self, n: usize) { + if (self.vec.len as usize) < n { + panic!("advancing IoSliceMut beyond its length"); + } + + unsafe { + self.vec.len -= n as c::ULONG; + self.vec.buf = self.vec.buf.add(n); + } + } + #[inline] pub fn as_slice(&self) -> &[u8] { unsafe { From 2c5684208c6f951b2cbe90df26a6691a95099e93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Sat, 3 Aug 2019 13:37:44 -0700 Subject: [PATCH 08/32] avoid mutable state and override main message --- src/librustc/mir/interpret/error.rs | 11 ++++++----- src/test/ui/consts/issue-55878.rs | 2 +- src/test/ui/consts/issue-55878.stderr | 2 +- src/test/ui/issues/issue-56762.rs | 4 ++-- src/test/ui/issues/issue-56762.stderr | 4 ++-- 5 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/librustc/mir/interpret/error.rs b/src/librustc/mir/interpret/error.rs index 05978ae3c6f7a..fb6f74397fc4c 100644 --- a/src/librustc/mir/interpret/error.rs +++ b/src/librustc/mir/interpret/error.rs @@ -137,16 +137,15 @@ impl<'tcx> ConstEvalErr<'tcx> { message: &str, lint_root: Option, ) -> Result, ErrorHandled> { - let mut must_error = false; - match self.error { + let must_error = match self.error { err_inval!(Layout(LayoutError::Unknown(_))) | err_inval!(TooGeneric) => return Err(ErrorHandled::TooGeneric), err_inval!(TypeckError) => return Err(ErrorHandled::Reported), - err_inval!(Layout(LayoutError::SizeOverflow(_))) => must_error = true, - _ => {}, - } + err_inval!(Layout(LayoutError::SizeOverflow(_))) => true, + _ => false, + }; trace!("reporting const eval failure at {:?}", self.span); let mut err = if let (Some(lint_root), false) = (lint_root, must_error) { let hir_id = self.stacktrace @@ -161,6 +160,8 @@ impl<'tcx> ConstEvalErr<'tcx> { tcx.span, message, ) + } else if must_error { + struct_error(tcx, &self.error.to_string()) } else { struct_error(tcx, message) }; diff --git a/src/test/ui/consts/issue-55878.rs b/src/test/ui/consts/issue-55878.rs index ce6c25742870e..6d8159e2fcdde 100644 --- a/src/test/ui/consts/issue-55878.rs +++ b/src/test/ui/consts/issue-55878.rs @@ -1,4 +1,4 @@ -// error-pattern: reaching this expression at runtime will panic or abort +// error-pattern: the type `[u8; 18446744073709551615]` is too big for the current architecture fn main() { println!("Size: {}", std::mem::size_of::<[u8; std::u64::MAX as usize]>()); } diff --git a/src/test/ui/consts/issue-55878.stderr b/src/test/ui/consts/issue-55878.stderr index adb272f4bed9c..184c6d0e29293 100644 --- a/src/test/ui/consts/issue-55878.stderr +++ b/src/test/ui/consts/issue-55878.stderr @@ -1,4 +1,4 @@ -error[E0080]: reaching this expression at runtime will panic or abort +error[E0080]: the type `[u8; 18446744073709551615]` is too big for the current architecture --> $SRC_DIR/libcore/mem/mod.rs:LL:COL | LL | intrinsics::size_of::() diff --git a/src/test/ui/issues/issue-56762.rs b/src/test/ui/issues/issue-56762.rs index f12d0121a8f1a..5ba5b9847d085 100644 --- a/src/test/ui/issues/issue-56762.rs +++ b/src/test/ui/issues/issue-56762.rs @@ -17,8 +17,8 @@ impl TooBigArray { } static MY_TOO_BIG_ARRAY_1: TooBigArray = TooBigArray::new(); -//~^ ERROR could not evaluate static initializer +//~^ ERROR the type `[u8; 2305843009213693951]` is too big for the current architecture static MY_TOO_BIG_ARRAY_2: [u8; HUGE_SIZE] = [0x00; HUGE_SIZE]; -//~^ ERROR could not evaluate static initializer +//~^ ERROR the type `[u8; 2305843009213693951]` is too big for the current architecture fn main() { } diff --git a/src/test/ui/issues/issue-56762.stderr b/src/test/ui/issues/issue-56762.stderr index bce95087c5ce4..e74904f1f6818 100644 --- a/src/test/ui/issues/issue-56762.stderr +++ b/src/test/ui/issues/issue-56762.stderr @@ -1,10 +1,10 @@ -error[E0080]: could not evaluate static initializer +error[E0080]: the type `[u8; 2305843009213693951]` is too big for the current architecture --> $DIR/issue-56762.rs:19:1 | LL | static MY_TOO_BIG_ARRAY_1: TooBigArray = TooBigArray::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the type `[u8; 2305843009213693951]` is too big for the current architecture -error[E0080]: could not evaluate static initializer +error[E0080]: the type `[u8; 2305843009213693951]` is too big for the current architecture --> $DIR/issue-56762.rs:21:1 | LL | static MY_TOO_BIG_ARRAY_2: [u8; HUGE_SIZE] = [0x00; HUGE_SIZE]; From 50b258b072d972267d7a4b6a4e4a3f51c12c3959 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sun, 4 Aug 2019 02:07:35 +0300 Subject: [PATCH 09/32] diagnostics: Describe crate root modules in `DefKind::Mod` as "crate" --- src/librustc/hir/def.rs | 8 +++-- src/librustc_privacy/lib.rs | 2 +- src/librustc_resolve/diagnostics.rs | 5 ++- src/librustc_resolve/lib.rs | 36 +++++++------------ src/librustc_typeck/astconv.rs | 4 +-- src/librustc_typeck/check/method/suggest.rs | 6 ++-- src/test/ui/extern/extern-crate-visibility.rs | 4 +-- .../ui/extern/extern-crate-visibility.stderr | 4 +-- ...e-extern-crate-restricted-shadowing.stderr | 2 +- .../ui/imports/glob-conflict-cross-crate.rs | 2 +- .../imports/glob-conflict-cross-crate.stderr | 2 +- src/test/ui/imports/issue-56125.stderr | 12 +++---- src/test/ui/imports/issue-57539.stderr | 4 +-- .../macro-path-prelude-shadowing.stderr | 2 +- src/test/ui/no-link.rs | 2 +- src/test/ui/no-link.stderr | 2 +- src/test/ui/recursion/recursive-reexports.rs | 2 +- .../ui/recursion/recursive-reexports.stderr | 2 +- .../ui/resolve/enums-are-namespaced-xc.stderr | 6 ++-- .../single-segment.rs | 2 +- .../single-segment.stderr | 2 +- .../ambiguity-macros-nested.stderr | 4 +-- .../uniform-paths/ambiguity-macros.stderr | 4 +-- .../uniform-paths/ambiguity-nested.stderr | 4 +-- .../rust-2018/uniform-paths/ambiguity.stderr | 4 +-- .../uniform-paths/issue-56596.stderr | 4 +-- .../type-ascription-instead-of-path.rs | 2 +- .../type-ascription-instead-of-path.stderr | 2 +- 28 files changed, 62 insertions(+), 73 deletions(-) diff --git a/src/librustc/hir/def.rs b/src/librustc/hir/def.rs index 40992e927444b..f83fbcdc263b0 100644 --- a/src/librustc/hir/def.rs +++ b/src/librustc/hir/def.rs @@ -1,4 +1,4 @@ -use crate::hir::def_id::DefId; +use crate::hir::def_id::{DefId, CRATE_DEF_INDEX, LOCAL_CRATE}; use crate::util::nodemap::DefIdMap; use syntax::ast; use syntax::ext::base::MacroKind; @@ -81,9 +81,11 @@ pub enum DefKind { } impl DefKind { - pub fn descr(self) -> &'static str { + pub fn descr(self, def_id: DefId) -> &'static str { match self { DefKind::Fn => "function", + DefKind::Mod if def_id.index == CRATE_DEF_INDEX && def_id.krate != LOCAL_CRATE => + "crate", DefKind::Mod => "module", DefKind::Static => "static", DefKind::Enum => "enum", @@ -366,7 +368,7 @@ impl Res { /// A human readable name for the res kind ("function", "module", etc.). pub fn descr(&self) -> &'static str { match *self { - Res::Def(kind, _) => kind.descr(), + Res::Def(kind, def_id) => kind.descr(def_id), Res::SelfCtor(..) => "self constructor", Res::PrimTy(..) => "builtin type", Res::Local(..) => "local variable", diff --git a/src/librustc_privacy/lib.rs b/src/librustc_privacy/lib.rs index ac18f0e440b78..ceb5bf10f6923 100644 --- a/src/librustc_privacy/lib.rs +++ b/src/librustc_privacy/lib.rs @@ -1127,7 +1127,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypePrivacyVisitor<'a, 'tcx> { hir::QPath::Resolved(_, ref path) => path.to_string(), hir::QPath::TypeRelative(_, ref segment) => segment.ident.to_string(), }; - let msg = format!("{} `{}` is private", kind.descr(), name); + let msg = format!("{} `{}` is private", kind.descr(def_id), name); self.tcx.sess.span_err(span, &msg); return; } diff --git a/src/librustc_resolve/diagnostics.rs b/src/librustc_resolve/diagnostics.rs index aeb6f23da5aa6..ae18b2014e728 100644 --- a/src/librustc_resolve/diagnostics.rs +++ b/src/librustc_resolve/diagnostics.rs @@ -115,10 +115,9 @@ impl<'a> Resolver<'a> { let mod_prefix = match self.resolve_path_without_parent_scope( mod_path, Some(TypeNS), false, span, CrateLint::No ) { - PathResult::Module(ModuleOrUniformRoot::Module(module)) => - module.def_kind(), + PathResult::Module(ModuleOrUniformRoot::Module(module)) => module.res(), _ => None, - }.map_or(String::new(), |kind| format!("{} ", kind.descr())); + }.map_or(String::new(), |res| format!("{} ", res.descr())); (mod_prefix, format!("`{}`", Segment::names_to_string(mod_path))) }; (format!("cannot find {} `{}` in {}{}", expected, item_str, mod_prefix, mod_str), diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index a49be7c27c94a..cdf8d031ca90a 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -444,11 +444,12 @@ fn resolve_struct_error<'sess, 'a>(resolver: &'sess Resolver<'_>, err } ResolutionError::BindingShadowsSomethingUnacceptable(what_binding, name, binding) => { - let shadows_what = binding.descr(); + let res = binding.res(); + let shadows_what = res.descr(); let mut err = struct_span_err!(resolver.session, span, E0530, "{}s cannot shadow {}s", what_binding, shadows_what); err.span_label(span, format!("cannot be named the same as {} {}", - binding.article(), shadows_what)); + res.article(), shadows_what)); let participle = if binding.is_import() { "imported" } else { "defined" }; let msg = format!("the {} `{}` is {} here", shadows_what, name, participle); err.span_label(binding.span, msg); @@ -1243,13 +1244,6 @@ impl<'a> ModuleData<'a> { } } - fn def_kind(&self) -> Option { - match self.kind { - ModuleKind::Def(kind, ..) => Some(kind), - _ => None, - } - } - fn def_id(&self) -> Option { match self.kind { ModuleKind::Def(_, def_id, _) => Some(def_id), @@ -1494,14 +1488,6 @@ impl<'a> NameBinding<'a> { self.res().macro_kind() } - fn descr(&self) -> &'static str { - if self.is_extern_crate() { "extern crate" } else { self.res().descr() } - } - - fn article(&self) -> &'static str { - if self.is_extern_crate() { "an" } else { self.res().article() } - } - // Suppose that we resolved macro invocation with `invoc_parent_expansion` to binding `binding` // at some expansion round `max(invoc, binding)` when they both emerged from macros. // Then this function returns `true` if `self` may emerge from a macro *after* that @@ -4675,6 +4661,7 @@ impl<'a> Resolver<'a> { } fn binding_description(&self, b: &NameBinding<'_>, ident: Ident, from_prelude: bool) -> String { + let res = b.res(); if b.span.is_dummy() { let add_built_in = match b.res() { // These already contain the "built-in" prefix or look bad with it. @@ -4692,13 +4679,13 @@ impl<'a> Resolver<'a> { ("", "") }; - let article = if built_in.is_empty() { b.article() } else { "a" }; + let article = if built_in.is_empty() { res.article() } else { "a" }; format!("{a}{built_in} {thing}{from}", - a = article, thing = b.descr(), built_in = built_in, from = from) + a = article, thing = res.descr(), built_in = built_in, from = from) } else { let introduced = if b.is_import() { "imported" } else { "defined" }; format!("the {thing} {introduced} here", - thing = b.descr(), introduced = introduced) + thing = res.descr(), introduced = introduced) } } @@ -4721,6 +4708,7 @@ impl<'a> Resolver<'a> { let note_msg = format!("`{ident}` could{also} refer to {what}", ident = ident, also = also, what = what); + let thing = b.res().descr(); let mut help_msgs = Vec::new(); if b.is_glob_import() && (kind == AmbiguityKind::GlobVsGlob || kind == AmbiguityKind::GlobVsExpanded || @@ -4732,18 +4720,18 @@ impl<'a> Resolver<'a> { if b.is_extern_crate() && ident.span.rust_2018() { help_msgs.push(format!( "use `::{ident}` to refer to this {thing} unambiguously", - ident = ident, thing = b.descr(), + ident = ident, thing = thing, )) } if misc == AmbiguityErrorMisc::SuggestCrate { help_msgs.push(format!( "use `crate::{ident}` to refer to this {thing} unambiguously", - ident = ident, thing = b.descr(), + ident = ident, thing = thing, )) } else if misc == AmbiguityErrorMisc::SuggestSelf { help_msgs.push(format!( "use `self::{ident}` to refer to this {thing} unambiguously", - ident = ident, thing = b.descr(), + ident = ident, thing = thing, )) } @@ -4781,7 +4769,7 @@ impl<'a> Resolver<'a> { for &PrivacyError(dedup_span, ident, binding) in &self.privacy_errors { if reported_spans.insert(dedup_span) { span_err!(self.session, ident.span, E0603, "{} `{}` is private", - binding.descr(), ident.name); + binding.res().descr(), ident.name); } } } diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index e8e0dd8425bab..fbecf4c120877 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -1688,7 +1688,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { let kind = DefKind::AssocTy; if !item.vis.is_accessible_from(def_scope, tcx) { - let msg = format!("{} `{}` is private", kind.descr(), assoc_ident); + let msg = format!("{} `{}` is private", kind.descr(item.def_id), assoc_ident); tcx.sess.span_err(span, &msg); } tcx.check_stability(item.def_id, Some(hir_ref_id), span); @@ -1703,7 +1703,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { let mut could_refer_to = |kind: DefKind, def_id, also| { let note_msg = format!("`{}` could{} refer to {} defined here", - assoc_ident, also, kind.descr()); + assoc_ident, also, kind.descr(def_id)); err.span_note(tcx.def_span(def_id), ¬e_msg); }; could_refer_to(DefKind::Variant, variant_def_id, ""); diff --git a/src/librustc_typeck/check/method/suggest.rs b/src/librustc_typeck/check/method/suggest.rs index 408c267555c9e..4a5eba1df8836 100644 --- a/src/librustc_typeck/check/method/suggest.rs +++ b/src/librustc_typeck/check/method/suggest.rs @@ -522,7 +522,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { &format!( "there is {} {} with a similar name", def_kind.article(), - def_kind.descr(), + def_kind.descr(lev_candidate.def_id), ), lev_candidate.ident.to_string(), Applicability::MaybeIncorrect, @@ -543,9 +543,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { err.emit(); } - MethodError::PrivateMatch(kind, _, out_of_scope_traits) => { + MethodError::PrivateMatch(kind, def_id, out_of_scope_traits) => { let mut err = struct_span_err!(self.tcx.sess, span, E0624, - "{} `{}` is private", kind.descr(), item_name); + "{} `{}` is private", kind.descr(def_id), item_name); self.suggest_valid_traits(&mut err, out_of_scope_traits); err.emit(); } diff --git a/src/test/ui/extern/extern-crate-visibility.rs b/src/test/ui/extern/extern-crate-visibility.rs index b51e44390313b..e0a5cd5e98f4b 100644 --- a/src/test/ui/extern/extern-crate-visibility.rs +++ b/src/test/ui/extern/extern-crate-visibility.rs @@ -3,10 +3,10 @@ mod foo { } // Check that private crates can be used from outside their modules, albeit with warnings -use foo::core::cell; //~ ERROR extern crate `core` is private +use foo::core::cell; //~ ERROR crate `core` is private fn f() { - foo::core::cell::Cell::new(0); //~ ERROR extern crate `core` is private + foo::core::cell::Cell::new(0); //~ ERROR crate `core` is private use foo::*; mod core {} // Check that private crates are not glob imported diff --git a/src/test/ui/extern/extern-crate-visibility.stderr b/src/test/ui/extern/extern-crate-visibility.stderr index 8bc9f9a67e7ef..38c791ab83237 100644 --- a/src/test/ui/extern/extern-crate-visibility.stderr +++ b/src/test/ui/extern/extern-crate-visibility.stderr @@ -1,10 +1,10 @@ -error[E0603]: extern crate `core` is private +error[E0603]: crate `core` is private --> $DIR/extern-crate-visibility.rs:6:10 | LL | use foo::core::cell; | ^^^^ -error[E0603]: extern crate `core` is private +error[E0603]: crate `core` is private --> $DIR/extern-crate-visibility.rs:9:10 | LL | foo::core::cell::Cell::new(0); diff --git a/src/test/ui/imports/extern-prelude-extern-crate-restricted-shadowing.stderr b/src/test/ui/imports/extern-prelude-extern-crate-restricted-shadowing.stderr index 24b1b582d1ea3..e8dfd43b6767c 100644 --- a/src/test/ui/imports/extern-prelude-extern-crate-restricted-shadowing.stderr +++ b/src/test/ui/imports/extern-prelude-extern-crate-restricted-shadowing.stderr @@ -14,7 +14,7 @@ LL | Vec::panic!(); | ^^^ ambiguous name | = note: `Vec` could refer to a struct from prelude -note: `Vec` could also refer to the extern crate imported here +note: `Vec` could also refer to the crate imported here --> $DIR/extern-prelude-extern-crate-restricted-shadowing.rs:5:9 | LL | extern crate std as Vec; diff --git a/src/test/ui/imports/glob-conflict-cross-crate.rs b/src/test/ui/imports/glob-conflict-cross-crate.rs index c8b18525d8059..d84c243f2139c 100644 --- a/src/test/ui/imports/glob-conflict-cross-crate.rs +++ b/src/test/ui/imports/glob-conflict-cross-crate.rs @@ -3,6 +3,6 @@ extern crate glob_conflict; fn main() { - glob_conflict::f(); //~ ERROR cannot find function `f` in module `glob_conflict` + glob_conflict::f(); //~ ERROR cannot find function `f` in crate `glob_conflict` glob_conflict::glob::f(); //~ ERROR cannot find function `f` in module `glob_conflict::glob` } diff --git a/src/test/ui/imports/glob-conflict-cross-crate.stderr b/src/test/ui/imports/glob-conflict-cross-crate.stderr index ad70b7d5b91b0..0e3b4222fe44f 100644 --- a/src/test/ui/imports/glob-conflict-cross-crate.stderr +++ b/src/test/ui/imports/glob-conflict-cross-crate.stderr @@ -1,4 +1,4 @@ -error[E0425]: cannot find function `f` in module `glob_conflict` +error[E0425]: cannot find function `f` in crate `glob_conflict` --> $DIR/glob-conflict-cross-crate.rs:6:20 | LL | glob_conflict::f(); diff --git a/src/test/ui/imports/issue-56125.stderr b/src/test/ui/imports/issue-56125.stderr index 0ecedd50e03ec..d78cc5230367d 100644 --- a/src/test/ui/imports/issue-56125.stderr +++ b/src/test/ui/imports/issue-56125.stderr @@ -10,8 +10,8 @@ error[E0659]: `issue_56125` is ambiguous (name vs any other name during import r LL | use issue_56125::last_segment::*; | ^^^^^^^^^^^ ambiguous name | - = note: `issue_56125` could refer to an extern crate passed with `--extern` - = help: use `::issue_56125` to refer to this extern crate unambiguously + = note: `issue_56125` could refer to a crate passed with `--extern` + = help: use `::issue_56125` to refer to this crate unambiguously note: `issue_56125` could also refer to the module imported here --> $DIR/issue-56125.rs:6:9 | @@ -25,8 +25,8 @@ error[E0659]: `issue_56125` is ambiguous (name vs any other name during import r LL | use issue_56125::non_last_segment::non_last_segment::*; | ^^^^^^^^^^^ ambiguous name | - = note: `issue_56125` could refer to an extern crate passed with `--extern` - = help: use `::issue_56125` to refer to this extern crate unambiguously + = note: `issue_56125` could refer to a crate passed with `--extern` + = help: use `::issue_56125` to refer to this crate unambiguously note: `issue_56125` could also refer to the module imported here --> $DIR/issue-56125.rs:11:9 | @@ -40,8 +40,8 @@ error[E0659]: `issue_56125` is ambiguous (name vs any other name during import r LL | use issue_56125::*; | ^^^^^^^^^^^ ambiguous name | - = note: `issue_56125` could refer to an extern crate passed with `--extern` - = help: use `::issue_56125` to refer to this extern crate unambiguously + = note: `issue_56125` could refer to a crate passed with `--extern` + = help: use `::issue_56125` to refer to this crate unambiguously note: `issue_56125` could also refer to the module imported here --> $DIR/issue-56125.rs:18:9 | diff --git a/src/test/ui/imports/issue-57539.stderr b/src/test/ui/imports/issue-57539.stderr index ebf27ca54bc41..174088e8f6c11 100644 --- a/src/test/ui/imports/issue-57539.stderr +++ b/src/test/ui/imports/issue-57539.stderr @@ -4,8 +4,8 @@ error[E0659]: `core` is ambiguous (name vs any other name during import resoluti LL | use core; | ^^^^ ambiguous name | - = note: `core` could refer to a built-in extern crate - = help: use `::core` to refer to this extern crate unambiguously + = note: `core` could refer to a built-in crate + = help: use `::core` to refer to this crate unambiguously note: `core` could also refer to the module imported here --> $DIR/issue-57539.rs:5:9 | diff --git a/src/test/ui/macros/macro-path-prelude-shadowing.stderr b/src/test/ui/macros/macro-path-prelude-shadowing.stderr index e7b381daf9346..7bbb8eddb7137 100644 --- a/src/test/ui/macros/macro-path-prelude-shadowing.stderr +++ b/src/test/ui/macros/macro-path-prelude-shadowing.stderr @@ -4,7 +4,7 @@ error[E0659]: `std` is ambiguous (glob import vs any other name from outer scope LL | std::panic!(); | ^^^ ambiguous name | - = note: `std` could refer to a built-in extern crate + = note: `std` could refer to a built-in crate note: `std` could also refer to the module imported here --> $DIR/macro-path-prelude-shadowing.rs:27:9 | diff --git a/src/test/ui/no-link.rs b/src/test/ui/no-link.rs index f97c1074df4e1..939271832e3df 100644 --- a/src/test/ui/no-link.rs +++ b/src/test/ui/no-link.rs @@ -4,5 +4,5 @@ extern crate empty_struct; fn main() { - empty_struct::XEmpty1; //~ ERROR cannot find value `XEmpty1` in module `empty_struct` + empty_struct::XEmpty1; //~ ERROR cannot find value `XEmpty1` in crate `empty_struct` } diff --git a/src/test/ui/no-link.stderr b/src/test/ui/no-link.stderr index c9c8468eba432..66a74ff65601b 100644 --- a/src/test/ui/no-link.stderr +++ b/src/test/ui/no-link.stderr @@ -1,4 +1,4 @@ -error[E0425]: cannot find value `XEmpty1` in module `empty_struct` +error[E0425]: cannot find value `XEmpty1` in crate `empty_struct` --> $DIR/no-link.rs:7:19 | LL | empty_struct::XEmpty1; diff --git a/src/test/ui/recursion/recursive-reexports.rs b/src/test/ui/recursion/recursive-reexports.rs index 3d9fda35c68ac..0e17f22511818 100644 --- a/src/test/ui/recursion/recursive-reexports.rs +++ b/src/test/ui/recursion/recursive-reexports.rs @@ -2,6 +2,6 @@ extern crate recursive_reexports; -fn f() -> recursive_reexports::S {} //~ ERROR cannot find type `S` in module `recursive_reexports` +fn f() -> recursive_reexports::S {} //~ ERROR cannot find type `S` in crate `recursive_reexports` fn main() {} diff --git a/src/test/ui/recursion/recursive-reexports.stderr b/src/test/ui/recursion/recursive-reexports.stderr index 01afc1458afb9..f39d0a0d5e6f3 100644 --- a/src/test/ui/recursion/recursive-reexports.stderr +++ b/src/test/ui/recursion/recursive-reexports.stderr @@ -1,4 +1,4 @@ -error[E0412]: cannot find type `S` in module `recursive_reexports` +error[E0412]: cannot find type `S` in crate `recursive_reexports` --> $DIR/recursive-reexports.rs:5:32 | LL | fn f() -> recursive_reexports::S {} diff --git a/src/test/ui/resolve/enums-are-namespaced-xc.stderr b/src/test/ui/resolve/enums-are-namespaced-xc.stderr index 3e812c2694d03..d2209236a42e7 100644 --- a/src/test/ui/resolve/enums-are-namespaced-xc.stderr +++ b/src/test/ui/resolve/enums-are-namespaced-xc.stderr @@ -1,4 +1,4 @@ -error[E0425]: cannot find value `A` in module `namespaced_enums` +error[E0425]: cannot find value `A` in crate `namespaced_enums` --> $DIR/enums-are-namespaced-xc.rs:5:31 | LL | let _ = namespaced_enums::A; @@ -8,7 +8,7 @@ help: possible candidate is found in another module, you can import it into scop LL | use namespaced_enums::Foo::A; | -error[E0425]: cannot find function `B` in module `namespaced_enums` +error[E0425]: cannot find function `B` in crate `namespaced_enums` --> $DIR/enums-are-namespaced-xc.rs:7:31 | LL | let _ = namespaced_enums::B(10); @@ -18,7 +18,7 @@ help: possible candidate is found in another module, you can import it into scop LL | use namespaced_enums::Foo::B; | -error[E0422]: cannot find struct, variant or union type `C` in module `namespaced_enums` +error[E0422]: cannot find struct, variant or union type `C` in crate `namespaced_enums` --> $DIR/enums-are-namespaced-xc.rs:9:31 | LL | let _ = namespaced_enums::C { a: 10 }; diff --git a/src/test/ui/rfc-2126-extern-absolute-paths/single-segment.rs b/src/test/ui/rfc-2126-extern-absolute-paths/single-segment.rs index c16f46451bb60..72e50d78bc252 100644 --- a/src/test/ui/rfc-2126-extern-absolute-paths/single-segment.rs +++ b/src/test/ui/rfc-2126-extern-absolute-paths/single-segment.rs @@ -6,6 +6,6 @@ use crate; //~ ERROR crate root imports need to be explicitly named: `use crate use *; //~ ERROR cannot glob-import all possible crates fn main() { - let s = ::xcrate; //~ ERROR expected value, found module `xcrate` + let s = ::xcrate; //~ ERROR expected value, found crate `xcrate` //~^ NOTE not a value } diff --git a/src/test/ui/rfc-2126-extern-absolute-paths/single-segment.stderr b/src/test/ui/rfc-2126-extern-absolute-paths/single-segment.stderr index 396a798c8204f..253cc1bc57a5f 100644 --- a/src/test/ui/rfc-2126-extern-absolute-paths/single-segment.stderr +++ b/src/test/ui/rfc-2126-extern-absolute-paths/single-segment.stderr @@ -10,7 +10,7 @@ error: cannot glob-import all possible crates LL | use *; | ^ -error[E0423]: expected value, found module `xcrate` +error[E0423]: expected value, found crate `xcrate` --> $DIR/single-segment.rs:9:13 | LL | let s = ::xcrate; diff --git a/src/test/ui/rust-2018/uniform-paths/ambiguity-macros-nested.stderr b/src/test/ui/rust-2018/uniform-paths/ambiguity-macros-nested.stderr index 04144909095e8..27b8d0e216e05 100644 --- a/src/test/ui/rust-2018/uniform-paths/ambiguity-macros-nested.stderr +++ b/src/test/ui/rust-2018/uniform-paths/ambiguity-macros-nested.stderr @@ -4,8 +4,8 @@ error[E0659]: `std` is ambiguous (name vs any other name during import resolutio LL | pub use std::io; | ^^^ ambiguous name | - = note: `std` could refer to a built-in extern crate - = help: use `::std` to refer to this extern crate unambiguously + = note: `std` could refer to a built-in crate + = help: use `::std` to refer to this crate unambiguously note: `std` could also refer to the module defined here --> $DIR/ambiguity-macros-nested.rs:13:13 | diff --git a/src/test/ui/rust-2018/uniform-paths/ambiguity-macros.stderr b/src/test/ui/rust-2018/uniform-paths/ambiguity-macros.stderr index 71726371b74a4..44b34d2682d8a 100644 --- a/src/test/ui/rust-2018/uniform-paths/ambiguity-macros.stderr +++ b/src/test/ui/rust-2018/uniform-paths/ambiguity-macros.stderr @@ -4,8 +4,8 @@ error[E0659]: `std` is ambiguous (name vs any other name during import resolutio LL | use std::io; | ^^^ ambiguous name | - = note: `std` could refer to a built-in extern crate - = help: use `::std` to refer to this extern crate unambiguously + = note: `std` could refer to a built-in crate + = help: use `::std` to refer to this crate unambiguously note: `std` could also refer to the module defined here --> $DIR/ambiguity-macros.rs:12:9 | diff --git a/src/test/ui/rust-2018/uniform-paths/ambiguity-nested.stderr b/src/test/ui/rust-2018/uniform-paths/ambiguity-nested.stderr index 1d22a39c3a1d7..4129930bdb0fd 100644 --- a/src/test/ui/rust-2018/uniform-paths/ambiguity-nested.stderr +++ b/src/test/ui/rust-2018/uniform-paths/ambiguity-nested.stderr @@ -4,8 +4,8 @@ error[E0659]: `std` is ambiguous (name vs any other name during import resolutio LL | pub use std::io; | ^^^ ambiguous name | - = note: `std` could refer to a built-in extern crate - = help: use `::std` to refer to this extern crate unambiguously + = note: `std` could refer to a built-in crate + = help: use `::std` to refer to this crate unambiguously note: `std` could also refer to the module defined here --> $DIR/ambiguity-nested.rs:11:5 | diff --git a/src/test/ui/rust-2018/uniform-paths/ambiguity.stderr b/src/test/ui/rust-2018/uniform-paths/ambiguity.stderr index 45751c9f648c3..e123b323e7c57 100644 --- a/src/test/ui/rust-2018/uniform-paths/ambiguity.stderr +++ b/src/test/ui/rust-2018/uniform-paths/ambiguity.stderr @@ -4,8 +4,8 @@ error[E0659]: `std` is ambiguous (name vs any other name during import resolutio LL | use std::io; | ^^^ ambiguous name | - = note: `std` could refer to a built-in extern crate - = help: use `::std` to refer to this extern crate unambiguously + = note: `std` could refer to a built-in crate + = help: use `::std` to refer to this crate unambiguously note: `std` could also refer to the module defined here --> $DIR/ambiguity.rs:8:1 | diff --git a/src/test/ui/rust-2018/uniform-paths/issue-56596.stderr b/src/test/ui/rust-2018/uniform-paths/issue-56596.stderr index b1c0b461db4ad..e39840d34d9f7 100644 --- a/src/test/ui/rust-2018/uniform-paths/issue-56596.stderr +++ b/src/test/ui/rust-2018/uniform-paths/issue-56596.stderr @@ -4,8 +4,8 @@ error[E0659]: `issue_56596` is ambiguous (name vs any other name during import r LL | use issue_56596; | ^^^^^^^^^^^ ambiguous name | - = note: `issue_56596` could refer to an extern crate passed with `--extern` - = help: use `::issue_56596` to refer to this extern crate unambiguously + = note: `issue_56596` could refer to a crate passed with `--extern` + = help: use `::issue_56596` to refer to this crate unambiguously note: `issue_56596` could also refer to the module imported here --> $DIR/issue-56596.rs:11:5 | diff --git a/src/test/ui/suggestions/type-ascription-instead-of-path.rs b/src/test/ui/suggestions/type-ascription-instead-of-path.rs index 4c0fe6d8b5b4e..e92087e2947de 100644 --- a/src/test/ui/suggestions/type-ascription-instead-of-path.rs +++ b/src/test/ui/suggestions/type-ascription-instead-of-path.rs @@ -1,5 +1,5 @@ fn main() { std:io::stdin(); //~^ ERROR failed to resolve: use of undeclared type or module `io` - //~| ERROR expected value, found module + //~| ERROR expected value, found crate } diff --git a/src/test/ui/suggestions/type-ascription-instead-of-path.stderr b/src/test/ui/suggestions/type-ascription-instead-of-path.stderr index 0f9b31fb52b4f..fd2fedc76407c 100644 --- a/src/test/ui/suggestions/type-ascription-instead-of-path.stderr +++ b/src/test/ui/suggestions/type-ascription-instead-of-path.stderr @@ -4,7 +4,7 @@ error[E0433]: failed to resolve: use of undeclared type or module `io` LL | std:io::stdin(); | ^^ use of undeclared type or module `io` -error[E0423]: expected value, found module `std` +error[E0423]: expected value, found crate `std` --> $DIR/type-ascription-instead-of-path.rs:2:5 | LL | std:io::stdin(); From db099fb491fa2e713047af4f22d4139a71a21dbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Sat, 3 Aug 2019 15:59:25 -0700 Subject: [PATCH 10/32] Point to local place span on "type too big" error --- src/librustc/lint/context.rs | 3 +++ src/librustc/ty/layout.rs | 8 +++++++- src/librustc_codegen_llvm/builder.rs | 4 ++++ src/librustc_codegen_llvm/context.rs | 10 +++++++++- src/librustc_codegen_ssa/mir/analyze.rs | 8 +++++++- src/librustc_codegen_ssa/mir/rvalue.rs | 14 ++++++++++---- src/librustc_mir/interpret/eval_context.rs | 3 +++ src/librustc_mir/transform/const_prop.rs | 3 +++ src/librustc_passes/layout_test.rs | 4 ++++ src/librustc_target/abi/mod.rs | 2 ++ src/test/ui/huge-array-simple.stderr | 4 ++++ src/test/ui/huge-array.rs | 3 +-- src/test/ui/huge-array.stderr | 4 ++++ src/test/ui/issues/issue-15919.stderr | 4 ++++ 14 files changed, 65 insertions(+), 9 deletions(-) diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs index de812410e8bd8..7d9653a9a55b1 100644 --- a/src/librustc/lint/context.rs +++ b/src/librustc/lint/context.rs @@ -901,6 +901,9 @@ impl<'a, 'tcx> LayoutOf for LateContext<'a, 'tcx> { fn layout_of(&self, ty: Ty<'tcx>) -> Self::TyLayout { self.tcx.layout_of(self.param_env.and(ty)) } + fn spanned_layout_of(&self, ty: Ty<'tcx>, _: Option) -> Self::TyLayout { + self.layout_of(ty) + } } impl<'a, 'tcx, T: LateLintPass<'a, 'tcx>> LateContextAndPass<'a, 'tcx, T> { diff --git a/src/librustc/ty/layout.rs b/src/librustc/ty/layout.rs index 3b4b814c92a90..14d35fd4ce891 100644 --- a/src/librustc/ty/layout.rs +++ b/src/librustc/ty/layout.rs @@ -3,7 +3,7 @@ use crate::ty::{self, Ty, TyCtxt, TypeFoldable, ReprOptions}; use syntax::ast::{self, Ident, IntTy, UintTy}; use syntax::attr; -use syntax_pos::DUMMY_SP; +use syntax_pos::{DUMMY_SP, Span}; use std::cmp; use std::fmt; @@ -1943,6 +1943,9 @@ impl<'tcx> LayoutOf for LayoutCx<'tcx, TyCtxt<'tcx>> { Ok(layout) } + fn spanned_layout_of(&self, ty: Ty<'tcx>, _: Option) -> Self::TyLayout { + self.layout_of(ty) + } } impl LayoutOf for LayoutCx<'tcx, ty::query::TyCtxtAt<'tcx>> { @@ -1974,6 +1977,9 @@ impl LayoutOf for LayoutCx<'tcx, ty::query::TyCtxtAt<'tcx>> { Ok(layout) } + fn spanned_layout_of(&self, ty: Ty<'tcx>, _: Option) -> Self::TyLayout { + self.layout_of(ty) + } } // Helper (inherent) `layout_of` methods to avoid pushing `LayoutCx` to users. diff --git a/src/librustc_codegen_llvm/builder.rs b/src/librustc_codegen_llvm/builder.rs index 894e5c2fd3d93..c01ba728034ce 100644 --- a/src/librustc_codegen_llvm/builder.rs +++ b/src/librustc_codegen_llvm/builder.rs @@ -6,6 +6,7 @@ use crate::type_::Type; use crate::type_of::LayoutLlvmExt; use crate::value::Value; use syntax::symbol::LocalInternedString; +use syntax::source_map::Span; use rustc_codegen_ssa::common::{IntPredicate, TypeKind, RealPredicate}; use rustc_codegen_ssa::MemFlags; use libc::{c_uint, c_char}; @@ -90,6 +91,9 @@ impl ty::layout::LayoutOf for Builder<'_, '_, 'tcx> { fn layout_of(&self, ty: Ty<'tcx>) -> Self::TyLayout { self.cx.layout_of(ty) } + fn spanned_layout_of(&self, ty: Ty<'tcx>, _: Option) -> Self::TyLayout { + self.cx.layout_of(ty) + } } impl Deref for Builder<'_, 'll, 'tcx> { diff --git a/src/librustc_codegen_llvm/context.rs b/src/librustc_codegen_llvm/context.rs index 2b68eb53a4ab9..18d82c27d8cc9 100644 --- a/src/librustc_codegen_llvm/context.rs +++ b/src/librustc_codegen_llvm/context.rs @@ -30,6 +30,7 @@ use std::iter; use std::str; use std::sync::Arc; use syntax::symbol::LocalInternedString; +use syntax::source_map::Span; use crate::abi::Abi; /// There is one `CodegenCx` per compilation unit. Each one has its own LLVM @@ -860,9 +861,16 @@ impl LayoutOf for CodegenCx<'ll, 'tcx> { type TyLayout = TyLayout<'tcx>; fn layout_of(&self, ty: Ty<'tcx>) -> Self::TyLayout { + self.spanned_layout_of(ty, None) + } + + fn spanned_layout_of(&self, ty: Ty<'tcx>, span: Option) -> Self::TyLayout { self.tcx.layout_of(ty::ParamEnv::reveal_all().and(ty)) .unwrap_or_else(|e| if let LayoutError::SizeOverflow(_) = e { - self.sess().fatal(&e.to_string()) + match span { + Some(span) => self.sess().span_fatal(span, &e.to_string()), + None => self.sess().fatal(&e.to_string()), + } } else { bug!("failed to get layout for `{}`: {}", ty, e) }) diff --git a/src/librustc_codegen_ssa/mir/analyze.rs b/src/librustc_codegen_ssa/mir/analyze.rs index 907689541f978..1ce3dbc4fe3b6 100644 --- a/src/librustc_codegen_ssa/mir/analyze.rs +++ b/src/librustc_codegen_ssa/mir/analyze.rs @@ -182,13 +182,19 @@ impl<'mir, 'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> Visitor<'tcx> rvalue: &mir::Rvalue<'tcx>, location: Location) { debug!("visit_assign(place={:?}, rvalue={:?})", place, rvalue); + let mut decl_span = None; + if let mir::PlaceBase::Local(local) = &place.base { + if let Some(decl) = self.fx.mir.local_decls.get(*local) { + decl_span = Some(decl.source_info.span); + } + } if let mir::Place { base: mir::PlaceBase::Local(index), projection: None, } = *place { self.assign(index, location); - if !self.fx.rvalue_creates_operand(rvalue) { + if !self.fx.rvalue_creates_operand(rvalue, decl_span) { self.not_ssa(index); } } else { diff --git a/src/librustc_codegen_ssa/mir/rvalue.rs b/src/librustc_codegen_ssa/mir/rvalue.rs index 202cf147f1fcb..56c76cdc026f7 100644 --- a/src/librustc_codegen_ssa/mir/rvalue.rs +++ b/src/librustc_codegen_ssa/mir/rvalue.rs @@ -6,6 +6,7 @@ use rustc::middle::lang_items::ExchangeMallocFnLangItem; use rustc_apfloat::{ieee, Float, Status, Round}; use std::{u128, i128}; use syntax::symbol::sym; +use syntax::source_map::Span; use crate::base; use crate::MemFlags; @@ -136,7 +137,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { } _ => { - assert!(self.rvalue_creates_operand(rvalue)); + assert!(self.rvalue_creates_operand(rvalue, None)); let (mut bx, temp) = self.codegen_rvalue_operand(bx, rvalue); temp.val.store(&mut bx, dest); bx @@ -169,7 +170,11 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { mut bx: Bx, rvalue: &mir::Rvalue<'tcx> ) -> (Bx, OperandRef<'tcx, Bx::Value>) { - assert!(self.rvalue_creates_operand(rvalue), "cannot codegen {:?} to operand", rvalue); + assert!( + self.rvalue_creates_operand(rvalue, None), + "cannot codegen {:?} to operand", + rvalue, + ); match *rvalue { mir::Rvalue::Cast(ref kind, ref source, mir_cast_ty) => { @@ -691,7 +696,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { } impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { - pub fn rvalue_creates_operand(&self, rvalue: &mir::Rvalue<'tcx>) -> bool { + pub fn rvalue_creates_operand(&self, rvalue: &mir::Rvalue<'tcx>, span: Option) -> bool { match *rvalue { mir::Rvalue::Ref(..) | mir::Rvalue::Len(..) | @@ -707,7 +712,8 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { mir::Rvalue::Aggregate(..) => { let ty = rvalue.ty(self.mir, self.cx.tcx()); let ty = self.monomorphize(&ty); - self.cx.layout_of(ty).is_zst() + self.cx.spanned_layout_of(ty, span).is_zst() + // self.cx.layout_of(ty).is_zst() } } diff --git a/src/librustc_mir/interpret/eval_context.rs b/src/librustc_mir/interpret/eval_context.rs index f10d7fb965116..605afa7b36810 100644 --- a/src/librustc_mir/interpret/eval_context.rs +++ b/src/librustc_mir/interpret/eval_context.rs @@ -193,6 +193,9 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> LayoutOf for InterpCx<'mir, 'tcx, M> { .layout_of(self.param_env.and(ty)) .map_err(|layout| err_inval!(Layout(layout)).into()) } + fn spanned_layout_of(&self, ty: Ty<'tcx>, _: Option) -> Self::TyLayout { + self.layout_of(ty) + } } impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { diff --git a/src/librustc_mir/transform/const_prop.rs b/src/librustc_mir/transform/const_prop.rs index a450ec32e1a47..18b6f408fe12c 100644 --- a/src/librustc_mir/transform/const_prop.rs +++ b/src/librustc_mir/transform/const_prop.rs @@ -134,6 +134,9 @@ impl<'mir, 'tcx> LayoutOf for ConstPropagator<'mir, 'tcx> { fn layout_of(&self, ty: Ty<'tcx>) -> Self::TyLayout { self.tcx.layout_of(self.param_env.and(ty)) } + fn spanned_layout_of(&self, ty: Ty<'tcx>, _: Option) -> Self::TyLayout { + self.layout_of(ty) + } } impl<'mir, 'tcx> HasDataLayout for ConstPropagator<'mir, 'tcx> { diff --git a/src/librustc_passes/layout_test.rs b/src/librustc_passes/layout_test.rs index 95cb8de70675d..8c4635f3566ca 100644 --- a/src/librustc_passes/layout_test.rs +++ b/src/librustc_passes/layout_test.rs @@ -13,6 +13,7 @@ use rustc::ty::Ty; use rustc::ty::TyCtxt; use syntax::ast::Attribute; use syntax::symbol::sym; +use syntax::source_map::Span; pub fn test_layout(tcx: TyCtxt<'_>) { if tcx.features().rustc_attrs { @@ -116,6 +117,9 @@ impl LayoutOf for UnwrapLayoutCx<'tcx> { fn layout_of(&self, ty: Ty<'tcx>) -> Self::TyLayout { self.tcx.layout_of(self.param_env.and(ty)).unwrap() } + fn spanned_layout_of(&self, ty: Ty<'tcx>, _: Option) -> Self::TyLayout { + self.layout_of(ty) + } } impl HasTyCtxt<'tcx> for UnwrapLayoutCx<'tcx> { diff --git a/src/librustc_target/abi/mod.rs b/src/librustc_target/abi/mod.rs index 80fcb45d0b9bc..c4f38f4a7f4c3 100644 --- a/src/librustc_target/abi/mod.rs +++ b/src/librustc_target/abi/mod.rs @@ -9,6 +9,7 @@ use std::ops::{Add, Deref, Sub, Mul, AddAssign, Range, RangeInclusive}; use rustc_data_structures::newtype_index; use rustc_data_structures::indexed_vec::{Idx, IndexVec}; use syntax_pos::symbol::{sym, Symbol}; +use syntax_pos::Span; pub mod call; @@ -1012,6 +1013,7 @@ pub trait LayoutOf { type TyLayout; fn layout_of(&self, ty: Self::Ty) -> Self::TyLayout; + fn spanned_layout_of(&self, ty: Self::Ty, span: Option) -> Self::TyLayout; } #[derive(Copy, Clone, PartialEq, Eq)] diff --git a/src/test/ui/huge-array-simple.stderr b/src/test/ui/huge-array-simple.stderr index 3e9c86296cec2..71d3f62bbe53b 100644 --- a/src/test/ui/huge-array-simple.stderr +++ b/src/test/ui/huge-array-simple.stderr @@ -1,4 +1,8 @@ error: the type `[u8; N]` is too big for the current architecture + --> $DIR/huge-array-simple.rs:12:9 + | +LL | let _fat : [u8; (1<<61)+(1<<31)] = + | ^^^^ error: aborting due to previous error diff --git a/src/test/ui/huge-array.rs b/src/test/ui/huge-array.rs index f58dcd5806761..1ecf012e04be4 100644 --- a/src/test/ui/huge-array.rs +++ b/src/test/ui/huge-array.rs @@ -1,11 +1,10 @@ -// error-pattern:; 1518600000 - // FIXME https://github.com/rust-lang/rust/issues/59774 // normalize-stderr-test "thread.*panicked.*Metadata module not compiled.*\n" -> "" // normalize-stderr-test "note:.*RUST_BACKTRACE=1.*\n" -> "" fn generic(t: T) { let s: [T; 1518600000] = [t; 1518600000]; + //~^ ERROR the type `[[u8; 1518599999]; 1518600000]` is too big for the current architecture } fn main() { diff --git a/src/test/ui/huge-array.stderr b/src/test/ui/huge-array.stderr index 38d9effcfb527..823d974f4290e 100644 --- a/src/test/ui/huge-array.stderr +++ b/src/test/ui/huge-array.stderr @@ -1,4 +1,8 @@ error: the type `[[u8; 1518599999]; 1518600000]` is too big for the current architecture + --> $DIR/huge-array.rs:6:9 + | +LL | let s: [T; 1518600000] = [t; 1518600000]; + | ^ error: aborting due to previous error diff --git a/src/test/ui/issues/issue-15919.stderr b/src/test/ui/issues/issue-15919.stderr index e4e88cc47cfe7..66c768537843c 100644 --- a/src/test/ui/issues/issue-15919.stderr +++ b/src/test/ui/issues/issue-15919.stderr @@ -1,4 +1,8 @@ error: the type `[usize; N]` is too big for the current architecture + --> $DIR/issue-15919.rs:15:9 + | +LL | let x = [0usize; 0xffff_ffff_ffff_ffff]; + | ^ error: aborting due to previous error From 23400677d7efb82c396d37e01afc9d10698b3d3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Sat, 3 Aug 2019 22:04:39 -0700 Subject: [PATCH 11/32] Simplify change to layout_of --- src/librustc/lint/context.rs | 3 --- src/librustc/ty/layout.rs | 8 +------- src/librustc_codegen_llvm/builder.rs | 4 ---- src/librustc_codegen_ssa/mir/rvalue.rs | 1 - src/librustc_mir/interpret/eval_context.rs | 5 +---- src/librustc_mir/transform/const_prop.rs | 3 --- src/librustc_passes/layout_test.rs | 4 ---- src/librustc_target/abi/mod.rs | 4 +++- 8 files changed, 5 insertions(+), 27 deletions(-) diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs index 7d9653a9a55b1..de812410e8bd8 100644 --- a/src/librustc/lint/context.rs +++ b/src/librustc/lint/context.rs @@ -901,9 +901,6 @@ impl<'a, 'tcx> LayoutOf for LateContext<'a, 'tcx> { fn layout_of(&self, ty: Ty<'tcx>) -> Self::TyLayout { self.tcx.layout_of(self.param_env.and(ty)) } - fn spanned_layout_of(&self, ty: Ty<'tcx>, _: Option) -> Self::TyLayout { - self.layout_of(ty) - } } impl<'a, 'tcx, T: LateLintPass<'a, 'tcx>> LateContextAndPass<'a, 'tcx, T> { diff --git a/src/librustc/ty/layout.rs b/src/librustc/ty/layout.rs index 14d35fd4ce891..3b4b814c92a90 100644 --- a/src/librustc/ty/layout.rs +++ b/src/librustc/ty/layout.rs @@ -3,7 +3,7 @@ use crate::ty::{self, Ty, TyCtxt, TypeFoldable, ReprOptions}; use syntax::ast::{self, Ident, IntTy, UintTy}; use syntax::attr; -use syntax_pos::{DUMMY_SP, Span}; +use syntax_pos::DUMMY_SP; use std::cmp; use std::fmt; @@ -1943,9 +1943,6 @@ impl<'tcx> LayoutOf for LayoutCx<'tcx, TyCtxt<'tcx>> { Ok(layout) } - fn spanned_layout_of(&self, ty: Ty<'tcx>, _: Option) -> Self::TyLayout { - self.layout_of(ty) - } } impl LayoutOf for LayoutCx<'tcx, ty::query::TyCtxtAt<'tcx>> { @@ -1977,9 +1974,6 @@ impl LayoutOf for LayoutCx<'tcx, ty::query::TyCtxtAt<'tcx>> { Ok(layout) } - fn spanned_layout_of(&self, ty: Ty<'tcx>, _: Option) -> Self::TyLayout { - self.layout_of(ty) - } } // Helper (inherent) `layout_of` methods to avoid pushing `LayoutCx` to users. diff --git a/src/librustc_codegen_llvm/builder.rs b/src/librustc_codegen_llvm/builder.rs index c01ba728034ce..894e5c2fd3d93 100644 --- a/src/librustc_codegen_llvm/builder.rs +++ b/src/librustc_codegen_llvm/builder.rs @@ -6,7 +6,6 @@ use crate::type_::Type; use crate::type_of::LayoutLlvmExt; use crate::value::Value; use syntax::symbol::LocalInternedString; -use syntax::source_map::Span; use rustc_codegen_ssa::common::{IntPredicate, TypeKind, RealPredicate}; use rustc_codegen_ssa::MemFlags; use libc::{c_uint, c_char}; @@ -91,9 +90,6 @@ impl ty::layout::LayoutOf for Builder<'_, '_, 'tcx> { fn layout_of(&self, ty: Ty<'tcx>) -> Self::TyLayout { self.cx.layout_of(ty) } - fn spanned_layout_of(&self, ty: Ty<'tcx>, _: Option) -> Self::TyLayout { - self.cx.layout_of(ty) - } } impl Deref for Builder<'_, 'll, 'tcx> { diff --git a/src/librustc_codegen_ssa/mir/rvalue.rs b/src/librustc_codegen_ssa/mir/rvalue.rs index 56c76cdc026f7..4df45d1586086 100644 --- a/src/librustc_codegen_ssa/mir/rvalue.rs +++ b/src/librustc_codegen_ssa/mir/rvalue.rs @@ -713,7 +713,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { let ty = rvalue.ty(self.mir, self.cx.tcx()); let ty = self.monomorphize(&ty); self.cx.spanned_layout_of(ty, span).is_zst() - // self.cx.layout_of(ty).is_zst() } } diff --git a/src/librustc_mir/interpret/eval_context.rs b/src/librustc_mir/interpret/eval_context.rs index 605afa7b36810..1f23d8c017ccd 100644 --- a/src/librustc_mir/interpret/eval_context.rs +++ b/src/librustc_mir/interpret/eval_context.rs @@ -193,9 +193,6 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> LayoutOf for InterpCx<'mir, 'tcx, M> { .layout_of(self.param_env.and(ty)) .map_err(|layout| err_inval!(Layout(layout)).into()) } - fn spanned_layout_of(&self, ty: Ty<'tcx>, _: Option) -> Self::TyLayout { - self.layout_of(ty) - } } impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { @@ -509,7 +506,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { pub fn push_stack_frame( &mut self, instance: ty::Instance<'tcx>, - span: source_map::Span, + span: Span, body: &'mir mir::Body<'tcx>, return_place: Option>, return_to_block: StackPopCleanup, diff --git a/src/librustc_mir/transform/const_prop.rs b/src/librustc_mir/transform/const_prop.rs index 18b6f408fe12c..a450ec32e1a47 100644 --- a/src/librustc_mir/transform/const_prop.rs +++ b/src/librustc_mir/transform/const_prop.rs @@ -134,9 +134,6 @@ impl<'mir, 'tcx> LayoutOf for ConstPropagator<'mir, 'tcx> { fn layout_of(&self, ty: Ty<'tcx>) -> Self::TyLayout { self.tcx.layout_of(self.param_env.and(ty)) } - fn spanned_layout_of(&self, ty: Ty<'tcx>, _: Option) -> Self::TyLayout { - self.layout_of(ty) - } } impl<'mir, 'tcx> HasDataLayout for ConstPropagator<'mir, 'tcx> { diff --git a/src/librustc_passes/layout_test.rs b/src/librustc_passes/layout_test.rs index 8c4635f3566ca..95cb8de70675d 100644 --- a/src/librustc_passes/layout_test.rs +++ b/src/librustc_passes/layout_test.rs @@ -13,7 +13,6 @@ use rustc::ty::Ty; use rustc::ty::TyCtxt; use syntax::ast::Attribute; use syntax::symbol::sym; -use syntax::source_map::Span; pub fn test_layout(tcx: TyCtxt<'_>) { if tcx.features().rustc_attrs { @@ -117,9 +116,6 @@ impl LayoutOf for UnwrapLayoutCx<'tcx> { fn layout_of(&self, ty: Ty<'tcx>) -> Self::TyLayout { self.tcx.layout_of(self.param_env.and(ty)).unwrap() } - fn spanned_layout_of(&self, ty: Ty<'tcx>, _: Option) -> Self::TyLayout { - self.layout_of(ty) - } } impl HasTyCtxt<'tcx> for UnwrapLayoutCx<'tcx> { diff --git a/src/librustc_target/abi/mod.rs b/src/librustc_target/abi/mod.rs index c4f38f4a7f4c3..4f53c7795c2be 100644 --- a/src/librustc_target/abi/mod.rs +++ b/src/librustc_target/abi/mod.rs @@ -1013,7 +1013,9 @@ pub trait LayoutOf { type TyLayout; fn layout_of(&self, ty: Self::Ty) -> Self::TyLayout; - fn spanned_layout_of(&self, ty: Self::Ty, span: Option) -> Self::TyLayout; + fn spanned_layout_of(&self, ty: Self::Ty, _span: Option) -> Self::TyLayout { + self.layout_of(ty) + } } #[derive(Copy, Clone, PartialEq, Eq)] From 416caa10ed055e8f059bb2fe3d3dd67c063dfe6c Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Sun, 4 Aug 2019 20:20:12 +0900 Subject: [PATCH 12/32] Add test for issue-29265 --- src/test/ui/issues/auxiliary/issue-29265.rs | 9 +++++++++ src/test/ui/issues/issue-29265.rs | 10 ++++++++++ 2 files changed, 19 insertions(+) create mode 100644 src/test/ui/issues/auxiliary/issue-29265.rs create mode 100644 src/test/ui/issues/issue-29265.rs diff --git a/src/test/ui/issues/auxiliary/issue-29265.rs b/src/test/ui/issues/auxiliary/issue-29265.rs new file mode 100644 index 0000000000000..6d26002a2e707 --- /dev/null +++ b/src/test/ui/issues/auxiliary/issue-29265.rs @@ -0,0 +1,9 @@ +#![crate_type = "lib"] + +pub struct SomeType { + pub some_member: usize, +} + +pub static SOME_VALUE: SomeType = SomeType { + some_member: 1, +}; diff --git a/src/test/ui/issues/issue-29265.rs b/src/test/ui/issues/issue-29265.rs new file mode 100644 index 0000000000000..f554c4d16c7d1 --- /dev/null +++ b/src/test/ui/issues/issue-29265.rs @@ -0,0 +1,10 @@ +// aux-build:issue-29265.rs +// check-pass + +extern crate issue_29265 as lib; + +static _UNUSED: &'static lib::SomeType = &lib::SOME_VALUE; + +fn main() { + vec![0u8; lib::SOME_VALUE.some_member]; +} From 620567d87ed578587cbbc6bad851576507283544 Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Sun, 4 Aug 2019 20:20:40 +0900 Subject: [PATCH 13/32] Add test for issue-49544 --- src/test/ui/issues/auxiliary/issue-49544.rs | 7 +++++++ src/test/ui/issues/issue-49544.rs | 9 +++++++++ 2 files changed, 16 insertions(+) create mode 100644 src/test/ui/issues/auxiliary/issue-49544.rs create mode 100644 src/test/ui/issues/issue-49544.rs diff --git a/src/test/ui/issues/auxiliary/issue-49544.rs b/src/test/ui/issues/auxiliary/issue-49544.rs new file mode 100644 index 0000000000000..f8b3a3fba1e4a --- /dev/null +++ b/src/test/ui/issues/auxiliary/issue-49544.rs @@ -0,0 +1,7 @@ +#![crate_type = "lib"] + +pub fn foo() -> Vec { + std::env::args() + .skip(1) + .collect() +} diff --git a/src/test/ui/issues/issue-49544.rs b/src/test/ui/issues/issue-49544.rs new file mode 100644 index 0000000000000..ed356275fc135 --- /dev/null +++ b/src/test/ui/issues/issue-49544.rs @@ -0,0 +1,9 @@ +// aux-build:issue-49544.rs +// check-pass + +extern crate issue_49544; +use issue_49544::foo; + +fn main() { + let _ = foo(); +} From 92e4e8e7836e5a505dc466039135b75252e5b1f6 Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Sun, 4 Aug 2019 21:22:42 +0900 Subject: [PATCH 14/32] Add test for issue-37433 --- src/test/ui/issues/issue-37433.rs | 8 ++++++++ src/test/ui/issues/issue-37433.stderr | 8 ++++++++ 2 files changed, 16 insertions(+) create mode 100644 src/test/ui/issues/issue-37433.rs create mode 100644 src/test/ui/issues/issue-37433.stderr diff --git a/src/test/ui/issues/issue-37433.rs b/src/test/ui/issues/issue-37433.rs new file mode 100644 index 0000000000000..784e6ccdac089 --- /dev/null +++ b/src/test/ui/issues/issue-37433.rs @@ -0,0 +1,8 @@ +#![feature(asm)] + +fn main() { + unsafe { + asm!("" :: "r"("")); + //~^ ERROR: invalid value for constraint in inline assembly + } +} diff --git a/src/test/ui/issues/issue-37433.stderr b/src/test/ui/issues/issue-37433.stderr new file mode 100644 index 0000000000000..af64193330198 --- /dev/null +++ b/src/test/ui/issues/issue-37433.stderr @@ -0,0 +1,8 @@ +error[E0669]: invalid value for constraint in inline assembly + --> $DIR/issue-37433.rs:5:24 + | +LL | asm!("" :: "r"("")); + | ^^ + +error: aborting due to previous error + From 0d1584507ba540becb6fc78dfc2d1f8d1fc60cc1 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sun, 4 Aug 2019 14:12:11 +0200 Subject: [PATCH 15/32] fix UB in a test --- src/libcore/tests/ptr.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/libcore/tests/ptr.rs b/src/libcore/tests/ptr.rs index 569b3197d09bd..df5f4faa60e67 100644 --- a/src/libcore/tests/ptr.rs +++ b/src/libcore/tests/ptr.rs @@ -145,7 +145,6 @@ fn test_as_ref() { } #[test] -#[cfg(not(miri))] // This test is UB according to Stacked Borrows fn test_as_mut() { unsafe { let p: *mut isize = null_mut(); @@ -164,7 +163,7 @@ fn test_as_mut() { // Pointers to unsized types -- slices let s: &mut [u8] = &mut [1, 2, 3]; let ms: *mut [u8] = s; - assert_eq!(ms.as_mut(), Some(s)); + assert_eq!(ms.as_mut().unwrap() as *mut _, s as *mut _); let mz: *mut [u8] = &mut []; assert_eq!(mz.as_mut(), Some(&mut [][..])); From 95f29aa81bb0839f7cdedf267ac2a711d3301aae Mon Sep 17 00:00:00 2001 From: Ariel Ben-Yehuda Date: Sun, 4 Aug 2019 19:52:43 +0300 Subject: [PATCH 16/32] Revert "Rollup merge of #62696 - chocol4te:fix_#62194, r=estebank" This reverts commit df21a6f040a7011d509769a61ac7af9502636b33, reversing changes made to cc16d0486933e02237190366de2eb43df2215c11. --- src/librustc/traits/specialize/mod.rs | 9 ++------- .../ui/coherence/coherence-overlap-upstream.old.stderr | 2 ++ .../ui/coherence/coherence-overlap-upstream.re.stderr | 2 ++ ...nce_copy_like_err_fundamental_struct_tuple.old.stderr | 2 ++ ...ence_copy_like_err_fundamental_struct_tuple.re.stderr | 2 ++ .../coherence/coherence_copy_like_err_struct.old.stderr | 2 ++ .../coherence/coherence_copy_like_err_struct.re.stderr | 2 ++ .../coherence/coherence_copy_like_err_tuple.old.stderr | 2 ++ .../ui/coherence/coherence_copy_like_err_tuple.re.stderr | 2 ++ src/test/ui/issues/issue-48728.stderr | 2 ++ src/test/ui/specialization/issue-52050.stderr | 2 ++ 11 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/librustc/traits/specialize/mod.rs b/src/librustc/traits/specialize/mod.rs index 8a84fca143809..f0389bb037ac5 100644 --- a/src/librustc/traits/specialize/mod.rs +++ b/src/librustc/traits/specialize/mod.rs @@ -366,13 +366,8 @@ pub(super) fn specialization_graph_provider( } } - let access_levels = tcx.privacy_access_levels(impl_def_id.krate); - if let Some(id) = tcx.hir().as_local_hir_id(impl_def_id) { - if access_levels.is_exported(id) || access_levels.is_public(id) { - for cause in &overlap.intercrate_ambiguity_causes { - cause.add_intercrate_ambiguity_hint(&mut err); - } - } + for cause in &overlap.intercrate_ambiguity_causes { + cause.add_intercrate_ambiguity_hint(&mut err); } if overlap.involves_placeholder { diff --git a/src/test/ui/coherence/coherence-overlap-upstream.old.stderr b/src/test/ui/coherence/coherence-overlap-upstream.old.stderr index dea948ff8abbb..6c3484c2d8c4d 100644 --- a/src/test/ui/coherence/coherence-overlap-upstream.old.stderr +++ b/src/test/ui/coherence/coherence-overlap-upstream.old.stderr @@ -5,6 +5,8 @@ LL | impl Foo for T where T: Remote {} | --------------------------------- first implementation here LL | impl Foo for i16 {} | ^^^^^^^^^^^^^^^^ conflicting implementation for `i16` + | + = note: upstream crates may add new impl of trait `coherence_lib::Remote` for type `i16` in future versions error: aborting due to previous error diff --git a/src/test/ui/coherence/coherence-overlap-upstream.re.stderr b/src/test/ui/coherence/coherence-overlap-upstream.re.stderr index dea948ff8abbb..6c3484c2d8c4d 100644 --- a/src/test/ui/coherence/coherence-overlap-upstream.re.stderr +++ b/src/test/ui/coherence/coherence-overlap-upstream.re.stderr @@ -5,6 +5,8 @@ LL | impl Foo for T where T: Remote {} | --------------------------------- first implementation here LL | impl Foo for i16 {} | ^^^^^^^^^^^^^^^^ conflicting implementation for `i16` + | + = note: upstream crates may add new impl of trait `coherence_lib::Remote` for type `i16` in future versions error: aborting due to previous error diff --git a/src/test/ui/coherence/coherence_copy_like_err_fundamental_struct_tuple.old.stderr b/src/test/ui/coherence/coherence_copy_like_err_fundamental_struct_tuple.old.stderr index 0ec4f0bb8e74d..12c7a1f977c3f 100644 --- a/src/test/ui/coherence/coherence_copy_like_err_fundamental_struct_tuple.old.stderr +++ b/src/test/ui/coherence/coherence_copy_like_err_fundamental_struct_tuple.old.stderr @@ -6,6 +6,8 @@ LL | impl MyTrait for T { } ... LL | impl MyTrait for lib::MyFundamentalStruct<(MyType,)> { } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `lib::MyFundamentalStruct<(MyType,)>` + | + = note: upstream crates may add new impl of trait `lib::MyCopy` for type `lib::MyFundamentalStruct<(MyType,)>` in future versions error: aborting due to previous error diff --git a/src/test/ui/coherence/coherence_copy_like_err_fundamental_struct_tuple.re.stderr b/src/test/ui/coherence/coherence_copy_like_err_fundamental_struct_tuple.re.stderr index 0ec4f0bb8e74d..12c7a1f977c3f 100644 --- a/src/test/ui/coherence/coherence_copy_like_err_fundamental_struct_tuple.re.stderr +++ b/src/test/ui/coherence/coherence_copy_like_err_fundamental_struct_tuple.re.stderr @@ -6,6 +6,8 @@ LL | impl MyTrait for T { } ... LL | impl MyTrait for lib::MyFundamentalStruct<(MyType,)> { } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `lib::MyFundamentalStruct<(MyType,)>` + | + = note: upstream crates may add new impl of trait `lib::MyCopy` for type `lib::MyFundamentalStruct<(MyType,)>` in future versions error: aborting due to previous error diff --git a/src/test/ui/coherence/coherence_copy_like_err_struct.old.stderr b/src/test/ui/coherence/coherence_copy_like_err_struct.old.stderr index e5862fdda7c58..1b6c62e9bf3a8 100644 --- a/src/test/ui/coherence/coherence_copy_like_err_struct.old.stderr +++ b/src/test/ui/coherence/coherence_copy_like_err_struct.old.stderr @@ -6,6 +6,8 @@ LL | impl MyTrait for T { } ... LL | impl MyTrait for lib::MyStruct { } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `lib::MyStruct` + | + = note: upstream crates may add new impl of trait `lib::MyCopy` for type `lib::MyStruct` in future versions error: aborting due to previous error diff --git a/src/test/ui/coherence/coherence_copy_like_err_struct.re.stderr b/src/test/ui/coherence/coherence_copy_like_err_struct.re.stderr index e5862fdda7c58..1b6c62e9bf3a8 100644 --- a/src/test/ui/coherence/coherence_copy_like_err_struct.re.stderr +++ b/src/test/ui/coherence/coherence_copy_like_err_struct.re.stderr @@ -6,6 +6,8 @@ LL | impl MyTrait for T { } ... LL | impl MyTrait for lib::MyStruct { } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `lib::MyStruct` + | + = note: upstream crates may add new impl of trait `lib::MyCopy` for type `lib::MyStruct` in future versions error: aborting due to previous error diff --git a/src/test/ui/coherence/coherence_copy_like_err_tuple.old.stderr b/src/test/ui/coherence/coherence_copy_like_err_tuple.old.stderr index a3c4ef8e105a2..11bd788c76153 100644 --- a/src/test/ui/coherence/coherence_copy_like_err_tuple.old.stderr +++ b/src/test/ui/coherence/coherence_copy_like_err_tuple.old.stderr @@ -6,6 +6,8 @@ LL | impl MyTrait for T { } ... LL | impl MyTrait for (MyType,) { } | ^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `(MyType,)` + | + = note: upstream crates may add new impl of trait `lib::MyCopy` for type `(MyType,)` in future versions error: aborting due to previous error diff --git a/src/test/ui/coherence/coherence_copy_like_err_tuple.re.stderr b/src/test/ui/coherence/coherence_copy_like_err_tuple.re.stderr index a3c4ef8e105a2..11bd788c76153 100644 --- a/src/test/ui/coherence/coherence_copy_like_err_tuple.re.stderr +++ b/src/test/ui/coherence/coherence_copy_like_err_tuple.re.stderr @@ -6,6 +6,8 @@ LL | impl MyTrait for T { } ... LL | impl MyTrait for (MyType,) { } | ^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `(MyType,)` + | + = note: upstream crates may add new impl of trait `lib::MyCopy` for type `(MyType,)` in future versions error: aborting due to previous error diff --git a/src/test/ui/issues/issue-48728.stderr b/src/test/ui/issues/issue-48728.stderr index 777e1fc9c27ea..99a9bf9903e25 100644 --- a/src/test/ui/issues/issue-48728.stderr +++ b/src/test/ui/issues/issue-48728.stderr @@ -6,6 +6,8 @@ LL | #[derive(Clone)] ... LL | impl Clone for Node<[T]> { | ------------------------------------------- first implementation here + | + = note: upstream crates may add new impl of trait `std::clone::Clone` for type `[_]` in future versions error: aborting due to previous error diff --git a/src/test/ui/specialization/issue-52050.stderr b/src/test/ui/specialization/issue-52050.stderr index 583c580d341ba..dcb34f3ad4836 100644 --- a/src/test/ui/specialization/issue-52050.stderr +++ b/src/test/ui/specialization/issue-52050.stderr @@ -10,6 +10,8 @@ LL | | } LL | LL | impl IntoPyDictPointer for () | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `()` + | + = note: upstream crates may add new impl of trait `std::iter::Iterator` for type `()` in future versions error: aborting due to previous error From 387dcff796406eb55624c61e9f14a3b5c27ad5ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Sun, 4 Aug 2019 09:44:06 -0700 Subject: [PATCH 17/32] review comments: clean up --- src/librustc_codegen_llvm/context.rs | 6 +++--- src/librustc_codegen_ssa/mir/analyze.rs | 7 +------ src/librustc_codegen_ssa/mir/rvalue.rs | 8 ++++---- src/librustc_target/abi/mod.rs | 2 +- 4 files changed, 9 insertions(+), 14 deletions(-) diff --git a/src/librustc_codegen_llvm/context.rs b/src/librustc_codegen_llvm/context.rs index 18d82c27d8cc9..ee8f1843c1a82 100644 --- a/src/librustc_codegen_llvm/context.rs +++ b/src/librustc_codegen_llvm/context.rs @@ -30,7 +30,7 @@ use std::iter; use std::str; use std::sync::Arc; use syntax::symbol::LocalInternedString; -use syntax::source_map::Span; +use syntax::source_map::{DUMMY_SP, Span}; use crate::abi::Abi; /// There is one `CodegenCx` per compilation unit. Each one has its own LLVM @@ -861,10 +861,10 @@ impl LayoutOf for CodegenCx<'ll, 'tcx> { type TyLayout = TyLayout<'tcx>; fn layout_of(&self, ty: Ty<'tcx>) -> Self::TyLayout { - self.spanned_layout_of(ty, None) + self.spanned_layout_of(ty, DUMMY_SP) } - fn spanned_layout_of(&self, ty: Ty<'tcx>, span: Option) -> Self::TyLayout { + fn spanned_layout_of(&self, ty: Ty<'tcx>, span: Span) -> Self::TyLayout { self.tcx.layout_of(ty::ParamEnv::reveal_all().and(ty)) .unwrap_or_else(|e| if let LayoutError::SizeOverflow(_) = e { match span { diff --git a/src/librustc_codegen_ssa/mir/analyze.rs b/src/librustc_codegen_ssa/mir/analyze.rs index 1ce3dbc4fe3b6..5dc050cbb3672 100644 --- a/src/librustc_codegen_ssa/mir/analyze.rs +++ b/src/librustc_codegen_ssa/mir/analyze.rs @@ -182,18 +182,13 @@ impl<'mir, 'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> Visitor<'tcx> rvalue: &mir::Rvalue<'tcx>, location: Location) { debug!("visit_assign(place={:?}, rvalue={:?})", place, rvalue); - let mut decl_span = None; - if let mir::PlaceBase::Local(local) = &place.base { - if let Some(decl) = self.fx.mir.local_decls.get(*local) { - decl_span = Some(decl.source_info.span); - } - } if let mir::Place { base: mir::PlaceBase::Local(index), projection: None, } = *place { self.assign(index, location); + let decl_span = self.fx.mir.local_decls[index].source_info.span; if !self.fx.rvalue_creates_operand(rvalue, decl_span) { self.not_ssa(index); } diff --git a/src/librustc_codegen_ssa/mir/rvalue.rs b/src/librustc_codegen_ssa/mir/rvalue.rs index 4df45d1586086..29a97894bdca9 100644 --- a/src/librustc_codegen_ssa/mir/rvalue.rs +++ b/src/librustc_codegen_ssa/mir/rvalue.rs @@ -6,7 +6,7 @@ use rustc::middle::lang_items::ExchangeMallocFnLangItem; use rustc_apfloat::{ieee, Float, Status, Round}; use std::{u128, i128}; use syntax::symbol::sym; -use syntax::source_map::Span; +use syntax::source_map::{DUMMY_SP, Span}; use crate::base; use crate::MemFlags; @@ -137,7 +137,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { } _ => { - assert!(self.rvalue_creates_operand(rvalue, None)); + assert!(self.rvalue_creates_operand(rvalue, DUMMY_SP)); let (mut bx, temp) = self.codegen_rvalue_operand(bx, rvalue); temp.val.store(&mut bx, dest); bx @@ -171,7 +171,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { rvalue: &mir::Rvalue<'tcx> ) -> (Bx, OperandRef<'tcx, Bx::Value>) { assert!( - self.rvalue_creates_operand(rvalue, None), + self.rvalue_creates_operand(rvalue, DUMMY_SP), "cannot codegen {:?} to operand", rvalue, ); @@ -696,7 +696,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { } impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { - pub fn rvalue_creates_operand(&self, rvalue: &mir::Rvalue<'tcx>, span: Option) -> bool { + pub fn rvalue_creates_operand(&self, rvalue: &mir::Rvalue<'tcx>, span: Span) -> bool { match *rvalue { mir::Rvalue::Ref(..) | mir::Rvalue::Len(..) | diff --git a/src/librustc_target/abi/mod.rs b/src/librustc_target/abi/mod.rs index 4f53c7795c2be..dd7ae742a63c6 100644 --- a/src/librustc_target/abi/mod.rs +++ b/src/librustc_target/abi/mod.rs @@ -1013,7 +1013,7 @@ pub trait LayoutOf { type TyLayout; fn layout_of(&self, ty: Self::Ty) -> Self::TyLayout; - fn spanned_layout_of(&self, ty: Self::Ty, _span: Option) -> Self::TyLayout { + fn spanned_layout_of(&self, ty: Self::Ty, _span: Span) -> Self::TyLayout { self.layout_of(ty) } } From bdd79b849e9db3024c8b5a0426e6a08af20edd2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Sun, 4 Aug 2019 12:23:05 -0700 Subject: [PATCH 18/32] tweak output and tests --- src/librustc/mir/interpret/error.rs | 4 +++- src/librustc_codegen_llvm/context.rs | 5 +---- src/librustc_codegen_ssa/mir/analyze.rs | 27 +++++++++++++++++-------- src/test/ui/consts/issue-55878.stderr | 2 +- src/test/ui/huge-enum.rs | 12 +++++------ src/test/ui/huge-enum.stderr | 6 +++++- src/test/ui/huge-struct.rs | 2 ++ src/test/ui/huge-struct.stderr | 4 ++++ src/test/ui/issues/issue-56762.stderr | 4 ++-- 9 files changed, 42 insertions(+), 24 deletions(-) diff --git a/src/librustc/mir/interpret/error.rs b/src/librustc/mir/interpret/error.rs index fb6f74397fc4c..b875977658794 100644 --- a/src/librustc/mir/interpret/error.rs +++ b/src/librustc/mir/interpret/error.rs @@ -165,7 +165,9 @@ impl<'tcx> ConstEvalErr<'tcx> { } else { struct_error(tcx, message) }; - err.span_label(self.span, self.error.to_string()); + if !must_error { + err.span_label(self.span, self.error.to_string()); + } // Skip the last, which is just the environment of the constant. The stacktrace // is sometimes empty because we create "fake" eval contexts in CTFE to do work // on constant values. diff --git a/src/librustc_codegen_llvm/context.rs b/src/librustc_codegen_llvm/context.rs index ee8f1843c1a82..a2aaaddf0931c 100644 --- a/src/librustc_codegen_llvm/context.rs +++ b/src/librustc_codegen_llvm/context.rs @@ -867,10 +867,7 @@ impl LayoutOf for CodegenCx<'ll, 'tcx> { fn spanned_layout_of(&self, ty: Ty<'tcx>, span: Span) -> Self::TyLayout { self.tcx.layout_of(ty::ParamEnv::reveal_all().and(ty)) .unwrap_or_else(|e| if let LayoutError::SizeOverflow(_) = e { - match span { - Some(span) => self.sess().span_fatal(span, &e.to_string()), - None => self.sess().fatal(&e.to_string()), - } + self.sess().span_fatal(span, &e.to_string()) } else { bug!("failed to get layout for `{}`: {}", ty, e) }) diff --git a/src/librustc_codegen_ssa/mir/analyze.rs b/src/librustc_codegen_ssa/mir/analyze.rs index 5dc050cbb3672..cc0c733c22410 100644 --- a/src/librustc_codegen_ssa/mir/analyze.rs +++ b/src/librustc_codegen_ssa/mir/analyze.rs @@ -9,6 +9,7 @@ use rustc::mir::visit::{Visitor, PlaceContext, MutatingUseContext, NonMutatingUs use rustc::mir::traversal; use rustc::ty; use rustc::ty::layout::{LayoutOf, HasTyCtxt}; +use syntax_pos::DUMMY_SP; use super::FunctionCx; use crate::traits::*; @@ -20,10 +21,13 @@ pub fn non_ssa_locals<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( analyzer.visit_body(mir); - for (index, ty) in mir.local_decls.iter().map(|l| l.ty).enumerate() { + for (index, (ty, span)) in mir.local_decls.iter() + .map(|l| (l.ty, l.source_info.span)) + .enumerate() + { let ty = fx.monomorphize(&ty); debug!("local {} has type {:?}", index, ty); - let layout = fx.cx.layout_of(ty); + let layout = fx.cx.spanned_layout_of(ty, span); if fx.cx.is_backend_immediate(layout) { // These sorts of types are immediates that we can store // in an Value without an alloca. @@ -93,10 +97,12 @@ impl> LocalAnalyzer<'mir, 'a, 'tcx, Bx> { } } - fn process_place(&mut self, - place_ref: &mir::PlaceRef<'_, 'tcx>, - context: PlaceContext, - location: Location) { + fn process_place( + &mut self, + place_ref: &mir::PlaceRef<'_, 'tcx>, + context: PlaceContext, + location: Location, + ) { let cx = self.fx.cx; if let Some(proj) = place_ref.projection { @@ -116,12 +122,17 @@ impl> LocalAnalyzer<'mir, 'a, 'tcx, Bx> { .projection_ty(cx.tcx(), &proj.elem) .ty; let elem_ty = self.fx.monomorphize(&elem_ty); - if cx.layout_of(elem_ty).is_zst() { + let span = if let mir::PlaceBase::Local(index) = place_ref.base { + self.fx.mir.local_decls[*index].source_info.span + } else { + DUMMY_SP + }; + if cx.spanned_layout_of(elem_ty, span).is_zst() { return; } if let mir::ProjectionElem::Field(..) = proj.elem { - let layout = cx.layout_of(base_ty.ty); + let layout = cx.spanned_layout_of(base_ty.ty, span); if cx.is_backend_immediate(layout) || cx.is_backend_scalar_pair(layout) { // Recurse with the same context, instead of `Projection`, // potentially stopping at non-operand projections, diff --git a/src/test/ui/consts/issue-55878.stderr b/src/test/ui/consts/issue-55878.stderr index 184c6d0e29293..aa4dfb719f905 100644 --- a/src/test/ui/consts/issue-55878.stderr +++ b/src/test/ui/consts/issue-55878.stderr @@ -2,7 +2,7 @@ error[E0080]: the type `[u8; 18446744073709551615]` is too big for the current a --> $SRC_DIR/libcore/mem/mod.rs:LL:COL | LL | intrinsics::size_of::() - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ the type `[u8; 18446744073709551615]` is too big for the current architecture + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | ::: $DIR/issue-55878.rs:3:26 | diff --git a/src/test/ui/huge-enum.rs b/src/test/ui/huge-enum.rs index 2492afbdc8f81..8ac15f3156bfd 100644 --- a/src/test/ui/huge-enum.rs +++ b/src/test/ui/huge-enum.rs @@ -1,16 +1,14 @@ -// normalize-stderr-test "std::option::Option<\[u32; \d+\]>" -> "TYPE" -// normalize-stderr-test "\[u32; \d+\]" -> "TYPE" - // FIXME https://github.com/rust-lang/rust/issues/59774 // normalize-stderr-test "thread.*panicked.*Metadata module not compiled.*\n" -> "" // normalize-stderr-test "note:.*RUST_BACKTRACE=1.*\n" -> "" #[cfg(target_pointer_width = "32")] -fn main() { - let big: Option<[u32; (1<<29)-1]> = None; -} +type BIG = Option<[u32; (1<<29)-1]>; #[cfg(target_pointer_width = "64")] +type BIG = Option<[u32; (1<<45)-1]>; + fn main() { - let big: Option<[u32; (1<<45)-1]> = None; + let big: BIG = None; + //~^ ERROR is too big for the current architecture } diff --git a/src/test/ui/huge-enum.stderr b/src/test/ui/huge-enum.stderr index 67cae3d52ed2d..94349f475e9be 100644 --- a/src/test/ui/huge-enum.stderr +++ b/src/test/ui/huge-enum.stderr @@ -1,4 +1,8 @@ -error: the type `TYPE` is too big for the current architecture +error: the type `std::option::Option<[u32; 35184372088831]>` is too big for the current architecture + --> $DIR/huge-enum.rs:12:9 + | +LL | let big: BIG = None; + | ^^^ error: aborting due to previous error diff --git a/src/test/ui/huge-struct.rs b/src/test/ui/huge-struct.rs index dc7d75a6f028e..e120cae7fdd14 100644 --- a/src/test/ui/huge-struct.rs +++ b/src/test/ui/huge-struct.rs @@ -47,4 +47,6 @@ struct S1M { val: S1k> } fn main() { let fat: Option>>> = None; + //~^ ERROR the type `S32>>` is too big for the current architecture + } diff --git a/src/test/ui/huge-struct.stderr b/src/test/ui/huge-struct.stderr index 06b084bdc3a39..5c2140df48126 100644 --- a/src/test/ui/huge-struct.stderr +++ b/src/test/ui/huge-struct.stderr @@ -1,4 +1,8 @@ error: the type `SXX>>` is too big for the current architecture + --> $DIR/huge-struct.rs:49:9 + | +LL | let fat: Option>>> = None; + | ^^^ error: aborting due to previous error diff --git a/src/test/ui/issues/issue-56762.stderr b/src/test/ui/issues/issue-56762.stderr index e74904f1f6818..69626d4bc7a9e 100644 --- a/src/test/ui/issues/issue-56762.stderr +++ b/src/test/ui/issues/issue-56762.stderr @@ -2,13 +2,13 @@ error[E0080]: the type `[u8; 2305843009213693951]` is too big for the current ar --> $DIR/issue-56762.rs:19:1 | LL | static MY_TOO_BIG_ARRAY_1: TooBigArray = TooBigArray::new(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the type `[u8; 2305843009213693951]` is too big for the current architecture + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0080]: the type `[u8; 2305843009213693951]` is too big for the current architecture --> $DIR/issue-56762.rs:21:1 | LL | static MY_TOO_BIG_ARRAY_2: [u8; HUGE_SIZE] = [0x00; HUGE_SIZE]; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the type `[u8; 2305843009213693951]` is too big for the current architecture + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 2 previous errors From f621f890a6e427b6074f0a8561fe1c95feff743d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Sun, 4 Aug 2019 13:14:53 -0700 Subject: [PATCH 19/32] revert change to single test --- src/test/ui/huge-enum.rs | 3 +++ src/test/ui/huge-enum.stderr | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/test/ui/huge-enum.rs b/src/test/ui/huge-enum.rs index 8ac15f3156bfd..98d0ba6e15c09 100644 --- a/src/test/ui/huge-enum.rs +++ b/src/test/ui/huge-enum.rs @@ -1,3 +1,6 @@ +// normalize-stderr-test "std::option::Option<\[u32; \d+\]>" -> "TYPE" +// normalize-stderr-test "\[u32; \d+\]" -> "TYPE" + // FIXME https://github.com/rust-lang/rust/issues/59774 // normalize-stderr-test "thread.*panicked.*Metadata module not compiled.*\n" -> "" // normalize-stderr-test "note:.*RUST_BACKTRACE=1.*\n" -> "" diff --git a/src/test/ui/huge-enum.stderr b/src/test/ui/huge-enum.stderr index 94349f475e9be..1f16c81a8f45e 100644 --- a/src/test/ui/huge-enum.stderr +++ b/src/test/ui/huge-enum.stderr @@ -1,5 +1,5 @@ -error: the type `std::option::Option<[u32; 35184372088831]>` is too big for the current architecture - --> $DIR/huge-enum.rs:12:9 +error: the type `TYPE` is too big for the current architecture + --> $DIR/huge-enum.rs:15:9 | LL | let big: BIG = None; | ^^^ From a0685a9f2e6bada37ba39d83ab43f16cd90c52ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Sun, 4 Aug 2019 21:18:05 -0700 Subject: [PATCH 20/32] fix tests --- src/test/ui/consts/issue-55878.rs | 5 ++++- src/test/ui/consts/issue-55878.stderr | 4 ++-- src/test/ui/huge-array-simple-32.rs | 11 +++++++++++ src/test/ui/huge-array-simple-32.stderr | 8 ++++++++ src/test/ui/huge-array-simple-64.rs | 11 +++++++++++ src/test/ui/huge-array-simple-64.stderr | 8 ++++++++ src/test/ui/huge-array-simple.rs | 20 -------------------- src/test/ui/huge-array-simple.stderr | 8 -------- src/test/ui/issues/issue-15919-32.rs | 9 +++++++++ src/test/ui/issues/issue-15919-32.stderr | 8 ++++++++ src/test/ui/issues/issue-15919-64.rs | 9 +++++++++ src/test/ui/issues/issue-15919-64.stderr | 8 ++++++++ src/test/ui/issues/issue-15919.rs | 16 ---------------- src/test/ui/issues/issue-15919.stderr | 8 -------- 14 files changed, 78 insertions(+), 55 deletions(-) create mode 100644 src/test/ui/huge-array-simple-32.rs create mode 100644 src/test/ui/huge-array-simple-32.stderr create mode 100644 src/test/ui/huge-array-simple-64.rs create mode 100644 src/test/ui/huge-array-simple-64.stderr delete mode 100644 src/test/ui/huge-array-simple.rs delete mode 100644 src/test/ui/huge-array-simple.stderr create mode 100644 src/test/ui/issues/issue-15919-32.rs create mode 100644 src/test/ui/issues/issue-15919-32.stderr create mode 100644 src/test/ui/issues/issue-15919-64.rs create mode 100644 src/test/ui/issues/issue-15919-64.stderr delete mode 100644 src/test/ui/issues/issue-15919.rs delete mode 100644 src/test/ui/issues/issue-15919.stderr diff --git a/src/test/ui/consts/issue-55878.rs b/src/test/ui/consts/issue-55878.rs index 6d8159e2fcdde..aa1dd58d2463d 100644 --- a/src/test/ui/consts/issue-55878.rs +++ b/src/test/ui/consts/issue-55878.rs @@ -1,4 +1,7 @@ -// error-pattern: the type `[u8; 18446744073709551615]` is too big for the current architecture +// normalize-stderr-64bit "18446744073709551615" -> "SIZE" +// normalize-stderr-32bit "4294967295" -> "SIZE" + +// error-pattern: is too big for the current architecture fn main() { println!("Size: {}", std::mem::size_of::<[u8; std::u64::MAX as usize]>()); } diff --git a/src/test/ui/consts/issue-55878.stderr b/src/test/ui/consts/issue-55878.stderr index aa4dfb719f905..4332c7f19dc11 100644 --- a/src/test/ui/consts/issue-55878.stderr +++ b/src/test/ui/consts/issue-55878.stderr @@ -1,10 +1,10 @@ -error[E0080]: the type `[u8; 18446744073709551615]` is too big for the current architecture +error[E0080]: the type `[u8; SIZE]` is too big for the current architecture --> $SRC_DIR/libcore/mem/mod.rs:LL:COL | LL | intrinsics::size_of::() | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | - ::: $DIR/issue-55878.rs:3:26 + ::: $DIR/issue-55878.rs:6:26 | LL | println!("Size: {}", std::mem::size_of::<[u8; std::u64::MAX as usize]>()); | --------------------------------------------------- diff --git a/src/test/ui/huge-array-simple-32.rs b/src/test/ui/huge-array-simple-32.rs new file mode 100644 index 0000000000000..f72d69ee747b8 --- /dev/null +++ b/src/test/ui/huge-array-simple-32.rs @@ -0,0 +1,11 @@ +// ignore-32bit + +// FIXME https://github.com/rust-lang/rust/issues/59774 +// normalize-stderr-test "thread.*panicked.*Metadata module not compiled.*\n" -> "" +// normalize-stderr-test "note:.*RUST_BACKTRACE=1.*\n" -> "" +#![allow(exceeding_bitshifts)] + +fn main() { + let _fat: [u8; (1<<61)+(1<<31)] = //~ ERROR too big for the current architecture + [0; (1u64<<61) as usize +(1u64<<31) as usize]; +} diff --git a/src/test/ui/huge-array-simple-32.stderr b/src/test/ui/huge-array-simple-32.stderr new file mode 100644 index 0000000000000..70d9194ea55c5 --- /dev/null +++ b/src/test/ui/huge-array-simple-32.stderr @@ -0,0 +1,8 @@ +error: the type `[u8; 2305843011361177600]` is too big for the current architecture + --> $DIR/huge-array-simple-32.rs:9:9 + | +LL | let _fat: [u8; (1<<61)+(1<<31)] = + | ^^^^ + +error: aborting due to previous error + diff --git a/src/test/ui/huge-array-simple-64.rs b/src/test/ui/huge-array-simple-64.rs new file mode 100644 index 0000000000000..9f98f4d753190 --- /dev/null +++ b/src/test/ui/huge-array-simple-64.rs @@ -0,0 +1,11 @@ +// ignore-64bit + +// FIXME https://github.com/rust-lang/rust/issues/59774 +// normalize-stderr-test "thread.*panicked.*Metadata module not compiled.*\n" -> "" +// normalize-stderr-test "note:.*RUST_BACKTRACE=1.*\n" -> "" +#![allow(exceeding_bitshifts)] + +fn main() { + let _fat: [u8; (1<<31)+(1<<15)] = //~ ERROR too big for the current architecture + [0; (1u32<<31) as usize +(1u32<<15) as usize]; +} diff --git a/src/test/ui/huge-array-simple-64.stderr b/src/test/ui/huge-array-simple-64.stderr new file mode 100644 index 0000000000000..16372b02750ae --- /dev/null +++ b/src/test/ui/huge-array-simple-64.stderr @@ -0,0 +1,8 @@ +error: the type `[u8; 2147516416]` is too big for the current architecture + --> $DIR/huge-array-simple-32.rs:9:9 + | +LL | let _fat: [u8; (1<<31)+(1<<15)] = + | ^^^^ + +error: aborting due to previous error + diff --git a/src/test/ui/huge-array-simple.rs b/src/test/ui/huge-array-simple.rs deleted file mode 100644 index 0ff27168a7d86..0000000000000 --- a/src/test/ui/huge-array-simple.rs +++ /dev/null @@ -1,20 +0,0 @@ -// error-pattern: too big for the current architecture - -// normalize-stderr-test "; \d+]" -> "; N]" - -// FIXME https://github.com/rust-lang/rust/issues/59774 -// normalize-stderr-test "thread.*panicked.*Metadata module not compiled.*\n" -> "" -// normalize-stderr-test "note:.*RUST_BACKTRACE=1.*\n" -> "" -#![allow(exceeding_bitshifts)] - -#[cfg(target_pointer_width = "64")] -fn main() { - let _fat : [u8; (1<<61)+(1<<31)] = - [0; (1u64<<61) as usize +(1u64<<31) as usize]; -} - -#[cfg(target_pointer_width = "32")] -fn main() { - let _fat : [u8; (1<<31)+(1<<15)] = - [0; (1u32<<31) as usize +(1u32<<15) as usize]; -} diff --git a/src/test/ui/huge-array-simple.stderr b/src/test/ui/huge-array-simple.stderr deleted file mode 100644 index 71d3f62bbe53b..0000000000000 --- a/src/test/ui/huge-array-simple.stderr +++ /dev/null @@ -1,8 +0,0 @@ -error: the type `[u8; N]` is too big for the current architecture - --> $DIR/huge-array-simple.rs:12:9 - | -LL | let _fat : [u8; (1<<61)+(1<<31)] = - | ^^^^ - -error: aborting due to previous error - diff --git a/src/test/ui/issues/issue-15919-32.rs b/src/test/ui/issues/issue-15919-32.rs new file mode 100644 index 0000000000000..92394a4e54e9e --- /dev/null +++ b/src/test/ui/issues/issue-15919-32.rs @@ -0,0 +1,9 @@ +// ignore-64bit + +// FIXME https://github.com/rust-lang/rust/issues/59774 +// normalize-stderr-test "thread.*panicked.*Metadata module not compiled.*\n" -> "" +// normalize-stderr-test "note:.*RUST_BACKTRACE=1.*\n" -> "" + +fn main() { + let x = [0usize; 0xffff_ffff]; //~ ERROR too big +} diff --git a/src/test/ui/issues/issue-15919-32.stderr b/src/test/ui/issues/issue-15919-32.stderr new file mode 100644 index 0000000000000..fc53f43edbc87 --- /dev/null +++ b/src/test/ui/issues/issue-15919-32.stderr @@ -0,0 +1,8 @@ +error: the type `[usize; 4294967295]` is too big for the current architecture + --> $DIR/issue-15919-64.rs:8:9 + | +LL | let x = [0usize; 0xffff_ffff]; + | ^ + +error: aborting due to previous error + diff --git a/src/test/ui/issues/issue-15919-64.rs b/src/test/ui/issues/issue-15919-64.rs new file mode 100644 index 0000000000000..938ee92e2f256 --- /dev/null +++ b/src/test/ui/issues/issue-15919-64.rs @@ -0,0 +1,9 @@ +// ignore-32bit + +// FIXME https://github.com/rust-lang/rust/issues/59774 +// normalize-stderr-test "thread.*panicked.*Metadata module not compiled.*\n" -> "" +// normalize-stderr-test "note:.*RUST_BACKTRACE=1.*\n" -> "" + +fn main() { + let x = [0usize; 0xffff_ffff_ffff_ffff]; //~ ERROR too big +} diff --git a/src/test/ui/issues/issue-15919-64.stderr b/src/test/ui/issues/issue-15919-64.stderr new file mode 100644 index 0000000000000..571b87d9961c0 --- /dev/null +++ b/src/test/ui/issues/issue-15919-64.stderr @@ -0,0 +1,8 @@ +error: the type `[usize; 18446744073709551615]` is too big for the current architecture + --> $DIR/issue-15919-64.rs:8:9 + | +LL | let x = [0usize; 0xffff_ffff_ffff_ffff]; + | ^ + +error: aborting due to previous error + diff --git a/src/test/ui/issues/issue-15919.rs b/src/test/ui/issues/issue-15919.rs deleted file mode 100644 index a7ac4802a12d5..0000000000000 --- a/src/test/ui/issues/issue-15919.rs +++ /dev/null @@ -1,16 +0,0 @@ -// error-pattern: too big for the current architecture -// normalize-stderr-test "\[usize; \d+\]" -> "[usize; N]" - -// FIXME https://github.com/rust-lang/rust/issues/59774 -// normalize-stderr-test "thread.*panicked.*Metadata module not compiled.*\n" -> "" -// normalize-stderr-test "note:.*RUST_BACKTRACE=1.*\n" -> "" - -#[cfg(target_pointer_width = "32")] -fn main() { - let x = [0usize; 0xffff_ffff]; -} - -#[cfg(target_pointer_width = "64")] -fn main() { - let x = [0usize; 0xffff_ffff_ffff_ffff]; -} diff --git a/src/test/ui/issues/issue-15919.stderr b/src/test/ui/issues/issue-15919.stderr deleted file mode 100644 index 66c768537843c..0000000000000 --- a/src/test/ui/issues/issue-15919.stderr +++ /dev/null @@ -1,8 +0,0 @@ -error: the type `[usize; N]` is too big for the current architecture - --> $DIR/issue-15919.rs:15:9 - | -LL | let x = [0usize; 0xffff_ffff_ffff_ffff]; - | ^ - -error: aborting due to previous error - From 4e51ef7ccd9729b1f9074a44ef49778a3c53c3d4 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Mon, 5 Aug 2019 11:21:15 +0200 Subject: [PATCH 21/32] Test content, not value Co-Authored-By: Aleksey Kladov --- src/libcore/tests/ptr.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcore/tests/ptr.rs b/src/libcore/tests/ptr.rs index df5f4faa60e67..d5a079da989e2 100644 --- a/src/libcore/tests/ptr.rs +++ b/src/libcore/tests/ptr.rs @@ -163,7 +163,7 @@ fn test_as_mut() { // Pointers to unsized types -- slices let s: &mut [u8] = &mut [1, 2, 3]; let ms: *mut [u8] = s; - assert_eq!(ms.as_mut().unwrap() as *mut _, s as *mut _); + assert_eq!(ms.as_mut(), Some(&mut [1, 2, 3])); let mz: *mut [u8] = &mut []; assert_eq!(mz.as_mut(), Some(&mut [][..])); From b5e35b128efeed4bfdb4b1ee9d0697389ec9f164 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 30 Jul 2019 12:33:32 +0300 Subject: [PATCH 22/32] remove special code path for unknown tokens --- src/libsyntax/parse/lexer/mod.rs | 73 ++++--------------- src/test/ui/parser/lex-bad-token.rs | 2 + src/test/ui/parser/lex-stray-backslash.rs | 2 + src/test/ui/parser/unicode-quote-chars.rs | 3 + src/test/ui/parser/unicode-quote-chars.stderr | 18 ++++- 5 files changed, 37 insertions(+), 61 deletions(-) diff --git a/src/libsyntax/parse/lexer/mod.rs b/src/libsyntax/parse/lexer/mod.rs index 950b1b2ff5340..c209ae1cb9f1f 100644 --- a/src/libsyntax/parse/lexer/mod.rs +++ b/src/libsyntax/parse/lexer/mod.rs @@ -3,7 +3,7 @@ use crate::parse::token::{self, Token, TokenKind}; use crate::symbol::{sym, Symbol}; use crate::parse::unescape_error_reporting::{emit_unescape_error, push_escaped_char}; -use errors::{FatalError, Diagnostic, DiagnosticBuilder}; +use errors::{FatalError, DiagnosticBuilder}; use syntax_pos::{BytePos, Pos, Span, NO_EXPANSION}; use rustc_lexer::Base; use rustc_lexer::unescape; @@ -39,7 +39,6 @@ pub struct StringReader<'a> { pos: BytePos, /// Stop reading src at this index. end_src_index: usize, - fatal_errs: Vec>, /// Source text to tokenize. src: Lrc, override_span: Option, @@ -62,7 +61,6 @@ impl<'a> StringReader<'a> { pos: source_file.start_pos, end_src_index: src.len(), src, - fatal_errs: Vec::new(), override_span, } } @@ -89,29 +87,17 @@ impl<'a> StringReader<'a> { self.override_span.unwrap_or_else(|| Span::new(lo, hi, NO_EXPANSION)) } - fn unwrap_or_abort(&mut self, res: Result) -> Token { - match res { - Ok(tok) => tok, - Err(_) => { - self.emit_fatal_errors(); - FatalError.raise(); - } - } - } - /// Returns the next token, including trivia like whitespace or comments. /// /// `Err(())` means that some errors were encountered, which can be /// retrieved using `buffer_fatal_errors`. - pub fn try_next_token(&mut self) -> Result { - assert!(self.fatal_errs.is_empty()); - + pub fn next_token(&mut self) -> Token { let start_src_index = self.src_index(self.pos); let text: &str = &self.src[start_src_index..self.end_src_index]; if text.is_empty() { let span = self.mk_sp(self.pos, self.pos); - return Ok(Token::new(token::Eof, span)); + return Token::new(token::Eof, span); } { @@ -125,7 +111,7 @@ impl<'a> StringReader<'a> { let kind = token::Shebang(sym); let span = self.mk_sp(start, self.pos); - return Ok(Token::new(kind, span)); + return Token::new(kind, span); } } } @@ -139,39 +125,10 @@ impl<'a> StringReader<'a> { // This could use `?`, but that makes code significantly (10-20%) slower. // https://github.com/rust-lang/rust/issues/37939 - let kind = match self.cook_lexer_token(token.kind, start) { - Ok(it) => it, - Err(err) => return Err(self.fatal_errs.push(err)), - }; + let kind = self.cook_lexer_token(token.kind, start); let span = self.mk_sp(start, self.pos); - Ok(Token::new(kind, span)) - } - - /// Returns the next token, including trivia like whitespace or comments. - /// - /// Aborts in case of an error. - pub fn next_token(&mut self) -> Token { - let res = self.try_next_token(); - self.unwrap_or_abort(res) - } - - fn emit_fatal_errors(&mut self) { - for err in &mut self.fatal_errs { - err.emit(); - } - - self.fatal_errs.clear(); - } - - pub fn buffer_fatal_errors(&mut self) -> Vec { - let mut buffer = Vec::new(); - - for err in self.fatal_errs.drain(..) { - err.buffer(&mut buffer); - } - - buffer + Token::new(kind, span) } /// Report a fatal lexical error with a given span. @@ -218,8 +175,8 @@ impl<'a> StringReader<'a> { &self, token: rustc_lexer::TokenKind, start: BytePos, - ) -> Result> { - let kind = match token { + ) -> TokenKind { + match token { rustc_lexer::TokenKind::LineComment => { let string = self.str_from(start); // comments with only more "/"s are not doc comments @@ -396,16 +353,12 @@ impl<'a> StringReader<'a> { // this should be inside `rustc_lexer`. However, we should first remove compound // tokens like `<<` from `rustc_lexer`, and then add fancier error recovery to it, // as there will be less overall work to do this way. - return match unicode_chars::check_for_substitution(self, start, c, &mut err) { - Some(token) => { - err.emit(); - Ok(token) - } - None => Err(err), - } + let token = unicode_chars::check_for_substitution(self, start, c, &mut err) + .unwrap_or(token::Whitespace); + err.emit(); + token } - }; - Ok(kind) + } } fn cook_lexer_literal( diff --git a/src/test/ui/parser/lex-bad-token.rs b/src/test/ui/parser/lex-bad-token.rs index feb670c3d3dd0..9e4824611128d 100644 --- a/src/test/ui/parser/lex-bad-token.rs +++ b/src/test/ui/parser/lex-bad-token.rs @@ -1 +1,3 @@ ● //~ ERROR: unknown start of token + +fn main() {} diff --git a/src/test/ui/parser/lex-stray-backslash.rs b/src/test/ui/parser/lex-stray-backslash.rs index 90d359231a6e7..bb27f44c279f7 100644 --- a/src/test/ui/parser/lex-stray-backslash.rs +++ b/src/test/ui/parser/lex-stray-backslash.rs @@ -1 +1,3 @@ \ //~ ERROR: unknown start of token: \ + +fn main() {} diff --git a/src/test/ui/parser/unicode-quote-chars.rs b/src/test/ui/parser/unicode-quote-chars.rs index 69644211b8a11..1812dad81afc3 100644 --- a/src/test/ui/parser/unicode-quote-chars.rs +++ b/src/test/ui/parser/unicode-quote-chars.rs @@ -4,4 +4,7 @@ fn main() { println!(“hello world”); //~^ ERROR unknown start of token: \u{201c} //~^^ HELP Unicode characters '“' (Left Double Quotation Mark) and '”' (Right Double Quotation Mark) look like '"' (Quotation Mark), but are not + //~^^^ ERROR unknown start of token: \u{201d} + //~^^^^ HELP Unicode character '”' (Right Double Quotation Mark) looks like '"' (Quotation Mark), but it is not + //~^^^^^ ERROR expected token: `,` } diff --git a/src/test/ui/parser/unicode-quote-chars.stderr b/src/test/ui/parser/unicode-quote-chars.stderr index 4a09ed75605e4..84e45ecd873a4 100644 --- a/src/test/ui/parser/unicode-quote-chars.stderr +++ b/src/test/ui/parser/unicode-quote-chars.stderr @@ -8,5 +8,21 @@ help: Unicode characters '“' (Left Double Quotation Mark) and '”' (Right Dou LL | println!("hello world"); | ^^^^^^^^^^^^^ -error: aborting due to previous error +error: unknown start of token: \u{201d} + --> $DIR/unicode-quote-chars.rs:4:26 + | +LL | println!(“hello world”); + | ^ +help: Unicode character '”' (Right Double Quotation Mark) looks like '"' (Quotation Mark), but it is not + | +LL | println!(“hello world"); + | ^ + +error: expected token: `,` + --> $DIR/unicode-quote-chars.rs:4:21 + | +LL | println!(“hello world”); + | ^^^^^ expected `,` + +error: aborting due to 3 previous errors From 58ac81a60fe11868b0748a406d8e0b97efa4e8c5 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 30 Jul 2019 12:31:41 +0300 Subject: [PATCH 23/32] add unknown token --- src/librustc/ich/impls_syntax.rs | 3 ++- src/librustdoc/html/highlight.rs | 2 +- src/libsyntax/ext/proc_macro_server.rs | 2 +- src/libsyntax/parse/lexer/mod.rs | 2 +- src/libsyntax/parse/lexer/tokentrees.rs | 2 +- src/libsyntax/parse/token.rs | 4 +++- src/libsyntax/print/pprust.rs | 1 + 7 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/librustc/ich/impls_syntax.rs b/src/librustc/ich/impls_syntax.rs index 0c9c9adcf9da6..5cc8324b31606 100644 --- a/src/librustc/ich/impls_syntax.rs +++ b/src/librustc/ich/impls_syntax.rs @@ -363,7 +363,8 @@ impl<'a> HashStable> for token::TokenKind { } token::DocComment(val) | - token::Shebang(val) => val.hash_stable(hcx, hasher), + token::Shebang(val) | + token::Unknown(val) => val.hash_stable(hcx, hasher), } } } diff --git a/src/librustdoc/html/highlight.rs b/src/librustdoc/html/highlight.rs index 8132074d6e0e7..92d85ef9cacc5 100644 --- a/src/librustdoc/html/highlight.rs +++ b/src/librustdoc/html/highlight.rs @@ -237,7 +237,7 @@ impl<'a> Classifier<'a> { return Ok(()); }, - token::Whitespace => Class::None, + token::Whitespace | token::Unknown(..) => Class::None, token::Comment => Class::Comment, token::DocComment(..) => Class::DocComment, diff --git a/src/libsyntax/ext/proc_macro_server.rs b/src/libsyntax/ext/proc_macro_server.rs index 8d0023c9ab1eb..36621ce777510 100644 --- a/src/libsyntax/ext/proc_macro_server.rs +++ b/src/libsyntax/ext/proc_macro_server.rs @@ -184,7 +184,7 @@ impl FromInternal<(TreeAndJoint, &'_ ParseSess, &'_ mut Vec)> } OpenDelim(..) | CloseDelim(..) => unreachable!(), - Whitespace | Comment | Shebang(..) | Eof => unreachable!(), + Whitespace | Comment | Shebang(..) | Unknown(..) | Eof => unreachable!(), } } } diff --git a/src/libsyntax/parse/lexer/mod.rs b/src/libsyntax/parse/lexer/mod.rs index c209ae1cb9f1f..e86d4c7fde683 100644 --- a/src/libsyntax/parse/lexer/mod.rs +++ b/src/libsyntax/parse/lexer/mod.rs @@ -354,7 +354,7 @@ impl<'a> StringReader<'a> { // tokens like `<<` from `rustc_lexer`, and then add fancier error recovery to it, // as there will be less overall work to do this way. let token = unicode_chars::check_for_substitution(self, start, c, &mut err) - .unwrap_or(token::Whitespace); + .unwrap_or_else(|| token::Unknown(self.symbol_from(start))); err.emit(); token } diff --git a/src/libsyntax/parse/lexer/tokentrees.rs b/src/libsyntax/parse/lexer/tokentrees.rs index 830fbec58ded9..37e67a2729e6d 100644 --- a/src/libsyntax/parse/lexer/tokentrees.rs +++ b/src/libsyntax/parse/lexer/tokentrees.rs @@ -217,7 +217,7 @@ impl<'a> TokenTreesReader<'a> { loop { let token = self.string_reader.next_token(); match token.kind { - token::Whitespace | token::Comment | token::Shebang(_) => { + token::Whitespace | token::Comment | token::Shebang(_) | token::Unknown(_) => { self.joint_to_prev = NonJoint; } _ => { diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index 73adb5c947c0b..be800b4de66af 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -255,6 +255,8 @@ pub enum TokenKind { /// A comment. Comment, Shebang(ast::Name), + /// A completely invalid token which should be skipped. + Unknown(ast::Name), Eof, } @@ -603,7 +605,7 @@ impl Token { DotDotEq | Comma | Semi | ModSep | RArrow | LArrow | FatArrow | Pound | Dollar | Question | OpenDelim(..) | CloseDelim(..) | Literal(..) | Ident(..) | Lifetime(..) | Interpolated(..) | DocComment(..) | - Whitespace | Comment | Shebang(..) | Eof => return None, + Whitespace | Comment | Shebang(..) | Unknown(..) | Eof => return None, }; Some(Token::new(kind, self.span.to(joint.span))) diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 2ef8a919b9c56..378ba1e4107a4 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -288,6 +288,7 @@ fn token_kind_to_string_ext(tok: &TokenKind, convert_dollar_crate: Option) token::Whitespace => " ".to_string(), token::Comment => "/* */".to_string(), token::Shebang(s) => format!("/* shebang: {}*/", s), + token::Unknown(s) => s.to_string(), token::Interpolated(ref nt) => nonterminal_to_string(nt), } From b3e8c8bbe27e21a2e67039d9fb9ea41cb83b1499 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 30 Jul 2019 13:45:08 +0300 Subject: [PATCH 24/32] adapt rustdoc to infailable lexer --- src/librustdoc/html/highlight.rs | 27 +-- .../passes/check_code_block_syntax.rs | 32 +--- src/test/rustdoc-ui/invalid-syntax.stderr | 168 ++++++++++++++++-- 3 files changed, 177 insertions(+), 50 deletions(-) diff --git a/src/librustdoc/html/highlight.rs b/src/librustdoc/html/highlight.rs index 92d85ef9cacc5..5d86ee9721b75 100644 --- a/src/librustdoc/html/highlight.rs +++ b/src/librustdoc/html/highlight.rs @@ -44,7 +44,7 @@ pub fn render_with_highlighting( let mut highlighted_source = vec![]; if classifier.write_source(&mut highlighted_source).is_err() { - Err(classifier.lexer.buffer_fatal_errors()) + Err(()) } else { Ok(String::from_utf8_lossy(&highlighted_source).into_owned()) } @@ -59,14 +59,9 @@ pub fn render_with_highlighting( } write_footer(&mut out).unwrap(); } - Err(errors) => { - // If errors are encountered while trying to highlight, cancel the errors and just emit - // the unhighlighted source. The errors will have already been reported in the - // `check-code-block-syntax` pass. - for mut error in errors { - error.cancel(); - } - + Err(()) => { + // If errors are encountered while trying to highlight, just emit + // the unhighlighted source. write!(out, "
{}
", src).unwrap(); } } @@ -192,14 +187,20 @@ impl<'a> Classifier<'a> { if let Some(token) = self.peek_token.take() { return Ok(token); } - self.lexer.try_next_token().map_err(|()| HighlightError::LexError) + let token = self.lexer.next_token(); + if let token::Unknown(..) = &token.kind { + return Err(HighlightError::LexError); + } + Ok(token) } fn peek(&mut self) -> Result<&Token, HighlightError> { if self.peek_token.is_none() { - self.peek_token = Some( - self.lexer.try_next_token().map_err(|()| HighlightError::LexError)? - ); + let token = self.lexer.next_token(); + if let token::Unknown(..) = &token.kind { + return Err(HighlightError::LexError); + } + self.peek_token = Some(token); } Ok(self.peek_token.as_ref().unwrap()) } diff --git a/src/librustdoc/passes/check_code_block_syntax.rs b/src/librustdoc/passes/check_code_block_syntax.rs index 0488153e7cb73..357e17d2d1bc4 100644 --- a/src/librustdoc/passes/check_code_block_syntax.rs +++ b/src/librustdoc/passes/check_code_block_syntax.rs @@ -32,24 +32,20 @@ impl<'a, 'tcx> SyntaxChecker<'a, 'tcx> { dox[code_block.code].to_owned(), ); - let errors = { + let has_errors = { + let mut has_errors = false; let mut lexer = Lexer::new(&sess, source_file, None); - while let Ok(token::Token { kind, .. }) = lexer.try_next_token() { - if kind == token::Eof { - break; + loop { + match lexer.next_token().kind { + token::Eof => break, + token::Unknown(..) => has_errors = true, + _ => (), } } - - let errors = lexer.buffer_fatal_errors(); - - if !errors.is_empty() { - Err(errors) - } else { - Ok(()) - } + has_errors }; - if let Err(errors) = errors { + if has_errors { let mut diag = if let Some(sp) = super::source_span_for_markdown_range(self.cx, &dox, &code_block.range, &item.attrs) { @@ -58,11 +54,6 @@ impl<'a, 'tcx> SyntaxChecker<'a, 'tcx> { .sess() .struct_span_warn(sp, "could not parse code block as Rust code"); - for mut err in errors { - diag.note(&format!("error from rustc: {}", err.message())); - err.cancel(); - } - if code_block.syntax.is_none() && code_block.is_fenced { let sp = sp.from_inner(InnerSpan::new(0, 3)); diag.span_suggestion( @@ -82,11 +73,6 @@ impl<'a, 'tcx> SyntaxChecker<'a, 'tcx> { "doc comment contains an invalid Rust code block", ); - for mut err in errors { - // Don't bother reporting the error, because we can't show where it happened. - err.cancel(); - } - if code_block.syntax.is_none() && code_block.is_fenced { diag.help("mark blocks that do not contain Rust code as text: ```text"); } diff --git a/src/test/rustdoc-ui/invalid-syntax.stderr b/src/test/rustdoc-ui/invalid-syntax.stderr index b4ed747b44c81..3bebbecb9dfcf 100644 --- a/src/test/rustdoc-ui/invalid-syntax.stderr +++ b/src/test/rustdoc-ui/invalid-syntax.stderr @@ -1,3 +1,21 @@ +error: unknown start of token: \ + --> :1:1 + | +1 | \__________pkt->size___________/ \_result->size_/ \__pkt->size__/ + | ^ + +error: unknown start of token: \ + --> :1:43 + | +1 | \__________pkt->size___________/ \_result->size_/ \__pkt->size__/ + | ^ + +error: unknown start of token: \ + --> :1:60 + | +1 | \__________pkt->size___________/ \_result->size_/ \__pkt->size__/ + | ^ + warning: could not parse code block as Rust code --> $DIR/invalid-syntax.rs:3:5 | @@ -6,13 +24,31 @@ LL | /// ``` LL | | /// \__________pkt->size___________/ \_result->size_/ \__pkt->size__/ LL | | /// ``` | |_______^ - | - = note: error from rustc: unknown start of token: \ help: mark blocks that do not contain Rust code as text | LL | /// ```text | ^^^^^^^ +error: unknown start of token: ` + --> :3:30 + | +3 | | ^^^^^^ did you mean `baz::foobar`? + | ^ +help: Unicode character '`' (Grave Accent) looks like ''' (Single Quote), but it is not + | +3 | | ^^^^^^ did you mean 'baz::foobar`? + | ^ + +error: unknown start of token: ` + --> :3:42 + | +3 | | ^^^^^^ did you mean `baz::foobar`? + | ^ +help: Unicode character '`' (Grave Accent) looks like ''' (Single Quote), but it is not + | +3 | | ^^^^^^ did you mean `baz::foobar'? + | ^ + warning: could not parse code block as Rust code --> $DIR/invalid-syntax.rs:8:5 | @@ -23,13 +59,17 @@ LL | | /// LL | use foobar::Baz; LL | | /// | ^^^^^^ did you mean `baz::foobar`? LL | | /// ``` | |_______^ - | - = note: error from rustc: unknown start of token: ` help: mark blocks that do not contain Rust code as text | LL | /// ```text | ^^^^^^^ +error: unknown start of token: \ + --> :1:1 + | +1 | \_ + | ^ + warning: could not parse code block as Rust code --> $DIR/invalid-syntax.rs:19:5 | @@ -38,13 +78,17 @@ LL | /// ``` LL | | /// \_ LL | | /// ``` | |_______^ - | - = note: error from rustc: unknown start of token: \ help: mark blocks that do not contain Rust code as text | LL | /// ```text | ^^^^^^^ +error: unknown start of token: \ + --> :1:1 + | +1 | \_ + | ^ + warning: could not parse code block as Rust code --> $DIR/invalid-syntax.rs:32:5 | @@ -53,8 +97,12 @@ LL | /// ```rust LL | | /// \_ LL | | /// ``` | |_______^ - | - = note: error from rustc: unknown start of token: \ + +error: unknown start of token: \ + --> :2:5 + | +2 | \_ + | ^ warning: could not parse code block as Rust code --> $DIR/invalid-syntax.rs:41:9 @@ -63,16 +111,48 @@ LL | /// code with bad syntax | _________^ LL | | /// \_ | |__________^ - | - = note: error from rustc: unknown start of token: \ + +error: unknown start of token: ` + --> :1:1 + | +1 | ``` + | ^ +help: Unicode character '`' (Grave Accent) looks like ''' (Single Quote), but it is not + | +1 | '`` + | ^ + +error: unknown start of token: ` + --> :1:2 + | +1 | ``` + | ^ +help: Unicode character '`' (Grave Accent) looks like ''' (Single Quote), but it is not + | +1 | `'` + | ^ + +error: unknown start of token: ` + --> :1:3 + | +1 | ``` + | ^ +help: Unicode character '`' (Grave Accent) looks like ''' (Single Quote), but it is not + | +1 | ``' + | ^ warning: could not parse code block as Rust code --> $DIR/invalid-syntax.rs:55:9 | LL | /// ``` | ^^^ - | - = note: error from rustc: unknown start of token: ` + +error: unknown start of token: \ + --> :1:1 + | +1 | \_ + | ^ warning: could not parse code block as Rust code --> $DIR/invalid-syntax.rs:58:5 @@ -82,8 +162,12 @@ LL | /// ```edition2018 LL | | /// \_ LL | | /// ``` | |_______^ - | - = note: error from rustc: unknown start of token: \ + +error: unknown start of token: \ + --> :1:1 + | +1 | \_ + | ^ warning: doc comment contains an invalid Rust code block --> $DIR/invalid-syntax.rs:63:1 @@ -95,3 +179,59 @@ LL | | #[doc = "```"] | = help: mark blocks that do not contain Rust code as text: ```text +error: unknown start of token: \ + --> :1:1 + | +1 | \_ + | ^ + +error: unknown start of token: \ + --> :1:1 + | +1 | \_ + | ^ + +error: unknown start of token: ` + --> :1:1 + | +1 | ``` + | ^ +help: Unicode character '`' (Grave Accent) looks like ''' (Single Quote), but it is not + | +1 | '`` + | ^ + +error: unknown start of token: \ + --> :2:1 + | +2 | \_ + | ^ + +error: unknown start of token: \ + --> :1:1 + | +1 | \_ + | ^ + +error: unknown start of token: \ + --> :1:1 + | +1 | \_ + | ^ + +error: unknown start of token: ` + --> :3:30 + | +3 | | ^^^^^^ did you mean `baz::foobar`? + | ^ +help: Unicode character '`' (Grave Accent) looks like ''' (Single Quote), but it is not + | +3 | | ^^^^^^ did you mean 'baz::foobar`? + | ^ + +error: unknown start of token: \ + --> :1:1 + | +1 | \__________pkt->size___________/ \_result->size_/ \__pkt->size__/ + | ^ + From ab3fb1e775ff20f80096953080dfc650950041b0 Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Sun, 4 Aug 2019 17:59:06 -0400 Subject: [PATCH 25/32] Drop span argument from mk_list_item --- src/librustc/hir/lowering.rs | 7 +++---- src/libsyntax/attr/mod.rs | 4 ++-- src/libsyntax/ext/build.rs | 2 +- src/libsyntax/ext/expand.rs | 4 ++-- src/libsyntax/print/pprust.rs | 5 ++--- src/libsyntax_ext/test_harness.rs | 3 +-- 6 files changed, 11 insertions(+), 14 deletions(-) diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index 5031e6dbd87d2..493083c680aad 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -5176,11 +5176,10 @@ impl<'a> LoweringContext<'a> { let attr = { // `allow(unreachable_code)` let allow = { - let allow_ident = Ident::with_empty_ctxt(sym::allow).with_span_pos(e.span); - let uc_ident = Ident::with_empty_ctxt(sym::unreachable_code) - .with_span_pos(e.span); + let allow_ident = Ident::new(sym::allow, e.span); + let uc_ident = Ident::new(sym::unreachable_code, e.span); let uc_nested = attr::mk_nested_word_item(uc_ident); - attr::mk_list_item(e.span, allow_ident, vec![uc_nested]) + attr::mk_list_item(allow_ident, vec![uc_nested]) }; attr::mk_attr_outer(allow) }; diff --git a/src/libsyntax/attr/mod.rs b/src/libsyntax/attr/mod.rs index 3e56136b17108..7eea1aad8eadf 100644 --- a/src/libsyntax/attr/mod.rs +++ b/src/libsyntax/attr/mod.rs @@ -355,8 +355,8 @@ pub fn mk_name_value_item(span: Span, ident: Ident, lit_kind: LitKind, lit_span: MetaItem { path: Path::from_ident(ident), span, node: MetaItemKind::NameValue(lit) } } -pub fn mk_list_item(span: Span, ident: Ident, items: Vec) -> MetaItem { - MetaItem { path: Path::from_ident(ident), span, node: MetaItemKind::List(items) } +pub fn mk_list_item(ident: Ident, items: Vec) -> MetaItem { + MetaItem { path: Path::from_ident(ident), span: ident.span, node: MetaItemKind::List(items) } } pub fn mk_word_item(ident: Ident) -> MetaItem { diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index 59e13fdc8f163..83d9521685096 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -879,7 +879,7 @@ impl<'a> ExtCtxt<'a> { pub fn meta_list(&self, sp: Span, name: ast::Name, mis: Vec) -> ast::MetaItem { - attr::mk_list_item(sp, Ident::new(name, sp), mis) + attr::mk_list_item(Ident::new(name, sp), mis) } pub fn meta_name_value(&self, span: Span, name: ast::Name, lit_kind: ast::LitKind) diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index d2807e4a4b5fa..964c81dd46641 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -1272,7 +1272,7 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> { ]; let include_ident = Ident::with_empty_ctxt(sym::include); - let item = attr::mk_list_item(DUMMY_SP, include_ident, include_info); + let item = attr::mk_list_item(include_ident, include_info); items.push(ast::NestedMetaItem::MetaItem(item)); } Err(e) => { @@ -1333,7 +1333,7 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> { } } - let meta = attr::mk_list_item(DUMMY_SP, Ident::with_empty_ctxt(sym::doc), items); + let meta = attr::mk_list_item(Ident::with_empty_ctxt(sym::doc), items); *at = attr::Attribute { span: at.span, id: at.id, diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 2ef8a919b9c56..803426877335e 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -15,7 +15,7 @@ use crate::tokenstream::{self, TokenStream, TokenTree}; use rustc_target::spec::abi::{self, Abi}; use syntax_pos::{self, BytePos}; -use syntax_pos::{DUMMY_SP, FileName, Span}; +use syntax_pos::{FileName, Span}; use std::borrow::Cow; @@ -124,8 +124,7 @@ pub fn print_crate<'a>(cm: &'a SourceMap, // #![feature(prelude_import)] let pi_nested = attr::mk_nested_word_item(ast::Ident::with_empty_ctxt(sym::prelude_import)); - let list = attr::mk_list_item( - DUMMY_SP, ast::Ident::with_empty_ctxt(sym::feature), vec![pi_nested]); + let list = attr::mk_list_item(ast::Ident::with_empty_ctxt(sym::feature), vec![pi_nested]); let fake_attr = attr::mk_attr_inner(list); s.print_attribute(&fake_attr); diff --git a/src/libsyntax_ext/test_harness.rs b/src/libsyntax_ext/test_harness.rs index 4b3903c7ad7d3..eec8a3f802343 100644 --- a/src/libsyntax_ext/test_harness.rs +++ b/src/libsyntax_ext/test_harness.rs @@ -157,8 +157,7 @@ impl MutVisitor for EntryPointCleaner { item.map(|ast::Item {id, ident, attrs, node, vis, span, tokens}| { let allow_ident = Ident::with_empty_ctxt(sym::allow); let dc_nested = attr::mk_nested_word_item(Ident::from_str("dead_code")); - let allow_dead_code_item = attr::mk_list_item(DUMMY_SP, allow_ident, - vec![dc_nested]); + let allow_dead_code_item = attr::mk_list_item(allow_ident, vec![dc_nested]); let allow_dead_code = attr::mk_attr_outer(allow_dead_code_item); ast::Item { From 24a491f40c891e06dce930081d5e5228232f7a18 Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Sun, 4 Aug 2019 18:03:34 -0400 Subject: [PATCH 26/32] Drop explicit span argument from mk_name_value_item --- src/librustdoc/clean/cfg/tests.rs | 1 - src/libsyntax/attr/mod.rs | 5 +++-- src/libsyntax/ext/build.rs | 3 +-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/librustdoc/clean/cfg/tests.rs b/src/librustdoc/clean/cfg/tests.rs index d0df9f8f7e410..405144b444f09 100644 --- a/src/librustdoc/clean/cfg/tests.rs +++ b/src/librustdoc/clean/cfg/tests.rs @@ -211,7 +211,6 @@ fn test_parse_ok() { fn test_parse_err() { with_default_globals(|| { let mi = attr::mk_name_value_item( - DUMMY_SP, Ident::from_str("foo"), LitKind::Bool(false), DUMMY_SP, diff --git a/src/libsyntax/attr/mod.rs b/src/libsyntax/attr/mod.rs index 7eea1aad8eadf..28391aa0dec80 100644 --- a/src/libsyntax/attr/mod.rs +++ b/src/libsyntax/attr/mod.rs @@ -347,11 +347,12 @@ impl Attribute { pub fn mk_name_value_item_str(ident: Ident, value: Spanned) -> MetaItem { let lit_kind = LitKind::Str(value.node, ast::StrStyle::Cooked); - mk_name_value_item(ident.span.to(value.span), ident, lit_kind, value.span) + mk_name_value_item(ident, lit_kind, value.span) } -pub fn mk_name_value_item(span: Span, ident: Ident, lit_kind: LitKind, lit_span: Span) -> MetaItem { +pub fn mk_name_value_item(ident: Ident, lit_kind: LitKind, lit_span: Span) -> MetaItem { let lit = Lit::from_lit_kind(lit_kind, lit_span); + let span = ident.span.to(lit_span); MetaItem { path: Path::from_ident(ident), span, node: MetaItemKind::NameValue(lit) } } diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index 83d9521685096..db562840e8d3b 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -884,8 +884,7 @@ impl<'a> ExtCtxt<'a> { pub fn meta_name_value(&self, span: Span, name: ast::Name, lit_kind: ast::LitKind) -> ast::MetaItem { - attr::mk_name_value_item(span, Ident::new(name, span), - lit_kind, span) + attr::mk_name_value_item(Ident::new(name, span), lit_kind, span) } pub fn item_use(&self, sp: Span, From 88491497456e485b0171d6791bd81f52170fbc09 Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Sun, 4 Aug 2019 19:35:29 -0400 Subject: [PATCH 27/32] Make mk_attr_id private to libsyntax --- src/libsyntax/attr/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libsyntax/attr/mod.rs b/src/libsyntax/attr/mod.rs index 28391aa0dec80..a9d3227b3a8f4 100644 --- a/src/libsyntax/attr/mod.rs +++ b/src/libsyntax/attr/mod.rs @@ -368,7 +368,7 @@ pub fn mk_nested_word_item(ident: Ident) -> NestedMetaItem { NestedMetaItem::MetaItem(mk_word_item(ident)) } -pub fn mk_attr_id() -> AttrId { +crate fn mk_attr_id() -> AttrId { use std::sync::atomic::AtomicUsize; use std::sync::atomic::Ordering; From fbf93d4931ac9878943cb644d9c1b993b1d20a80 Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Mon, 5 Aug 2019 09:14:51 -0400 Subject: [PATCH 28/32] Remove leftover AwaitOrigin This was missed in PR #62293. --- src/libsyntax/ast.rs | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 849e77c4f3112..052eb55b40811 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -1284,15 +1284,6 @@ pub enum Movability { Movable, } -/// Whether an `await` comes from `await!` or `.await` syntax. -/// FIXME: this should be removed when support for legacy `await!` is removed. -/// https://github.com/rust-lang/rust/issues/60610 -#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, Copy)] -pub enum AwaitOrigin { - FieldLike, - MacroLike, -} - pub type Mac = Spanned; /// Represents a macro invocation. The `Path` indicates which macro From 90b95cf53f68888812cd5683cf44161e070e7dbd Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Mon, 5 Aug 2019 15:30:08 +0200 Subject: [PATCH 29/32] fix slice comparison Co-Authored-By: Aleksey Kladov --- src/libcore/tests/ptr.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcore/tests/ptr.rs b/src/libcore/tests/ptr.rs index d5a079da989e2..1a6be3a9bbd03 100644 --- a/src/libcore/tests/ptr.rs +++ b/src/libcore/tests/ptr.rs @@ -163,7 +163,7 @@ fn test_as_mut() { // Pointers to unsized types -- slices let s: &mut [u8] = &mut [1, 2, 3]; let ms: *mut [u8] = s; - assert_eq!(ms.as_mut(), Some(&mut [1, 2, 3])); + assert_eq!(ms.as_mut(), Some(&mut [1, 2, 3][..])); let mz: *mut [u8] = &mut []; assert_eq!(mz.as_mut(), Some(&mut [][..])); From 288b4e90780d827b0bca2b63b25b4a3056986111 Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Mon, 5 Aug 2019 10:28:23 -0400 Subject: [PATCH 30/32] Don't store &Span This is just needless indirection. --- src/librustc_mir/interpret/snapshot.rs | 4 ++-- src/librustc_resolve/lib.rs | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/librustc_mir/interpret/snapshot.rs b/src/librustc_mir/interpret/snapshot.rs index 70a297c866280..fad9fafbb0803 100644 --- a/src/librustc_mir/interpret/snapshot.rs +++ b/src/librustc_mir/interpret/snapshot.rs @@ -305,7 +305,7 @@ impl_stable_hash_for!(enum crate::interpret::eval_context::StackPopCleanup { #[derive(Eq, PartialEq)] struct FrameSnapshot<'a, 'tcx> { instance: &'a ty::Instance<'tcx>, - span: &'a Span, + span: Span, return_to_block: &'a StackPopCleanup, return_place: Option>>, locals: IndexVec>>, @@ -345,7 +345,7 @@ impl<'a, 'mir, 'tcx, Ctx> Snapshot<'a, Ctx> for &'a Frame<'mir, 'tcx> FrameSnapshot { instance, - span, + span: *span, return_to_block, block, stmt: *stmt, diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 1a203e73f0a86..1908d85e4ff2a 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -171,7 +171,7 @@ enum ResolutionError<'a> { GenericParamsFromOuterFunction(Res), /// Error E0403: the name is already used for a type or const parameter in this generic /// parameter list. - NameAlreadyUsedInParameterList(Name, &'a Span), + NameAlreadyUsedInParameterList(Name, Span), /// Error E0407: method is not a member of trait. MethodNotMemberOfTrait(Name, &'a str), /// Error E0437: type is not a member of trait. @@ -297,7 +297,7 @@ fn resolve_struct_error<'sess, 'a>(resolver: &'sess Resolver<'_>, parameter in this list of generic parameters", name); err.span_label(span, "already used"); - err.span_label(first_use_span.clone(), format!("first use of `{}`", name)); + err.span_label(first_use_span, format!("first use of `{}`", name)); err } ResolutionError::MethodNotMemberOfTrait(method, trait_) => { @@ -2853,7 +2853,7 @@ impl<'a> Resolver<'a> { let span = seen_bindings.get(&ident).unwrap(); let err = ResolutionError::NameAlreadyUsedInParameterList( ident.name, - span, + *span, ); resolve_error(self, param.ident.span, err); } @@ -2875,7 +2875,7 @@ impl<'a> Resolver<'a> { let span = seen_bindings.get(&ident).unwrap(); let err = ResolutionError::NameAlreadyUsedInParameterList( ident.name, - span, + *span, ); resolve_error(self, param.ident.span, err); } From 1f018636e35018bbd3f83de8da68ec50669cd646 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Mon, 5 Aug 2019 18:38:10 +0200 Subject: [PATCH 31/32] improve align_offset docs --- src/libcore/ptr/mod.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/libcore/ptr/mod.rs b/src/libcore/ptr/mod.rs index 0ec4dd47b1ff0..fa55bbf9c1650 100644 --- a/src/libcore/ptr/mod.rs +++ b/src/libcore/ptr/mod.rs @@ -1606,10 +1606,12 @@ impl *const T { /// `align`. /// /// If it is not possible to align the pointer, the implementation returns - /// `usize::max_value()`. + /// `usize::max_value()`. It is permissible for the implementation to *always* + /// return `usize::max_value()`. Only your algorithm's performance can depend + /// on getting a usable offset here, not its correctness. /// /// The offset is expressed in number of `T` elements, and not bytes. The value returned can be - /// used with the `add` method. + /// used with the `wrapping_add` method. /// /// There are no guarantees whatsoever that offsetting the pointer will not overflow or go /// beyond the allocation that the pointer points into. It is up to the caller to ensure that @@ -2407,10 +2409,12 @@ impl *mut T { /// `align`. /// /// If it is not possible to align the pointer, the implementation returns - /// `usize::max_value()`. + /// `usize::max_value()`. It is permissible for the implementation to *always* + /// return `usize::max_value()`. Only your algorithm's performance can depend + /// on getting a usable offset here, not its correctness. /// /// The offset is expressed in number of `T` elements, and not bytes. The value returned can be - /// used with the `add` method. + /// used with the `wrapping_add` method. /// /// There are no guarantees whatsoever that offsetting the pointer will not overflow or go /// beyond the allocation that the pointer points into. It is up to the caller to ensure that From 30910eef367fb305615597885242045e6c9949ba Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Mon, 5 Aug 2019 20:58:07 +0200 Subject: [PATCH 32/32] Make qualify consts in_projection use PlaceRef --- src/librustc_mir/transform/qualify_consts.rs | 29 ++++++++++---------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/src/librustc_mir/transform/qualify_consts.rs b/src/librustc_mir/transform/qualify_consts.rs index ffeaf4e19c22a..15f27d4e0c514 100644 --- a/src/librustc_mir/transform/qualify_consts.rs +++ b/src/librustc_mir/transform/qualify_consts.rs @@ -182,16 +182,17 @@ trait Qualif { fn in_projection_structurally( cx: &ConstCx<'_, 'tcx>, - base: &PlaceBase<'tcx>, - proj: &Projection<'tcx>, + place: PlaceRef<'_, 'tcx>, ) -> bool { + let proj = place.projection.as_ref().unwrap(); + let base_qualif = Self::in_place(cx, PlaceRef { - base, + base: place.base, projection: &proj.base, }); let qualif = base_qualif && Self::mask_for_ty( cx, - Place::ty_from(&base, &proj.base, cx.body, cx.tcx) + Place::ty_from(place.base, &proj.base, cx.body, cx.tcx) .projection_ty(cx.tcx, &proj.elem) .ty, ); @@ -208,10 +209,9 @@ trait Qualif { fn in_projection( cx: &ConstCx<'_, 'tcx>, - base: &PlaceBase<'tcx>, - proj: &Projection<'tcx>, + place: PlaceRef<'_, 'tcx>, ) -> bool { - Self::in_projection_structurally(cx, base, proj) + Self::in_projection_structurally(cx, place) } fn in_place(cx: &ConstCx<'_, 'tcx>, place: PlaceRef<'_, 'tcx>) -> bool { @@ -234,9 +234,9 @@ trait Qualif { Self::in_static(cx, static_) }, PlaceRef { - base, - projection: Some(proj), - } => Self::in_projection(cx, base, proj), + base: _, + projection: Some(_), + } => Self::in_projection(cx, place), } } @@ -448,9 +448,10 @@ impl Qualif for IsNotPromotable { fn in_projection( cx: &ConstCx<'_, 'tcx>, - base: &PlaceBase<'tcx>, - proj: &Projection<'tcx>, + place: PlaceRef<'_, 'tcx>, ) -> bool { + let proj = place.projection.as_ref().unwrap(); + match proj.elem { ProjectionElem::Deref | ProjectionElem::Downcast(..) => return true, @@ -461,7 +462,7 @@ impl Qualif for IsNotPromotable { ProjectionElem::Field(..) => { if cx.mode == Mode::NonConstFn { - let base_ty = Place::ty_from(base, &proj.base, cx.body, cx.tcx).ty; + let base_ty = Place::ty_from(place.base, &proj.base, cx.body, cx.tcx).ty; if let Some(def) = base_ty.ty_adt_def() { // No promotion of union field accesses. if def.is_union() { @@ -472,7 +473,7 @@ impl Qualif for IsNotPromotable { } } - Self::in_projection_structurally(cx, base, proj) + Self::in_projection_structurally(cx, place) } fn in_rvalue(cx: &ConstCx<'_, 'tcx>, rvalue: &Rvalue<'tcx>) -> bool {