diff --git a/src/doc/rust.css b/src/doc/rust.css index 664bc0fdab00..5f216169efe2 100644 --- a/src/doc/rust.css +++ b/src/doc/rust.css @@ -11,181 +11,181 @@ * except according to those terms. */ @font-face { - font-family: 'Fira Sans'; - font-style: normal; - font-weight: 400; - src: local('Fira Sans'), url("FiraSans-Regular.woff") format('woff'); + font-family: 'Fira Sans'; + font-style: normal; + font-weight: 400; + src: local('Fira Sans'), url("FiraSans-Regular.woff") format('woff'); } @font-face { - font-family: 'Fira Sans'; - font-style: normal; - font-weight: 500; - src: local('Fira Sans Medium'), url("FiraSans-Medium.woff") format('woff'); + font-family: 'Fira Sans'; + font-style: normal; + font-weight: 500; + src: local('Fira Sans Medium'), url("FiraSans-Medium.woff") format('woff'); } @font-face { - font-family: 'Source Serif Pro'; - font-style: normal; - font-weight: 400; - src: local('Source Serif Pro'), url("SourceSerifPro-Regular.woff") format('woff'); + font-family: 'Source Serif Pro'; + font-style: normal; + font-weight: 400; + src: local('Source Serif Pro'), url("SourceSerifPro-Regular.woff") format('woff'); } @font-face { - font-family: 'Source Serif Pro'; - font-style: italic; - font-weight: 400; - src: url("Heuristica-Italic.woff") format('woff'); + font-family: 'Source Serif Pro'; + font-style: italic; + font-weight: 400; + src: url("Heuristica-Italic.woff") format('woff'); } @font-face { - font-family: 'Source Serif Pro'; - font-style: normal; - font-weight: 700; - src: local('Source Serif Pro Bold'), url("SourceSerifPro-Bold.woff") format('woff'); + font-family: 'Source Serif Pro'; + font-style: normal; + font-weight: 700; + src: local('Source Serif Pro Bold'), url("SourceSerifPro-Bold.woff") format('woff'); } @font-face { - font-family: 'Source Code Pro'; - font-style: normal; - font-weight: 400; - /* Avoid using locally installed font because bad versions are in circulation: - * see https://github.com/rust-lang/rust/issues/24355 */ - src: url("SourceCodePro-Regular.woff") format('woff'); + font-family: 'Source Code Pro'; + font-style: normal; + font-weight: 400; + /* Avoid using locally installed font because bad versions are in circulation: + * see https://github.com/rust-lang/rust/issues/24355 */ + src: url("SourceCodePro-Regular.woff") format('woff'); } *:not(body) { -webkit-box-sizing: border-box; - -moz-box-sizing: border-box; - box-sizing: border-box; + -moz-box-sizing: border-box; + box-sizing: border-box; } /* General structure */ body { - background-color: white; - margin: 0 auto; - padding: 0 15px; - font-family: "Source Serif Pro", Georgia, Times, "Times New Roman", serif; - font-size: 18px; - color: #333; - line-height: 1.428571429; - - -webkit-font-feature-settings: "kern", "liga"; - -moz-font-feature-settings: "kern", "liga"; - font-feature-settings: "kern", "liga"; + background-color: white; + margin: 0 auto; + padding: 0 15px; + font-family: "Source Serif Pro", Georgia, Times, "Times New Roman", serif; + font-size: 18px; + color: #333; + line-height: 1.428571429; + + -webkit-font-feature-settings: "kern", "liga"; + -moz-font-feature-settings: "kern", "liga"; + font-feature-settings: "kern", "liga"; } @media (min-width: 768px) { - body { - max-width: 750px; - } + body { + max-width: 750px; + } } h1, h2, h3, h4, h5, h6, nav, #versioninfo { - font-family: "Fira Sans", "Helvetica Neue", Helvetica, Arial, sans-serif; + font-family: "Fira Sans", "Helvetica Neue", Helvetica, Arial, sans-serif; } h1, h2, h3, h4, h5, h6 { - color: black; - font-weight: 400; - line-height: 1.1; + color: black; + font-weight: 400; + line-height: 1.1; } h1, h2, h3 { - margin-top: 20px; - margin-bottom: 15px; + margin-top: 20px; + margin-bottom: 15px; } h1 { - margin-bottom: 20px; + margin-bottom: 20px; } h4, h5, h6 { - margin-top: 12px; - margin-bottom: 10px; - padding: 5px 10px; + margin-top: 12px; + margin-bottom: 10px; + padding: 5px 10px; } h5, h6 { - text-decoration: underline; + text-decoration: underline; } h1 { - font-size: 28px; - font-weight: 500; - padding: .1em .4em; - border-bottom: 2px solid #ddd; + font-size: 28px; + font-weight: 500; + padding: .1em .4em; + border-bottom: 2px solid #ddd; } h1.title { - line-height: 1.5em; + line-height: 1.5em; } h2 { - font-size: 26px; - padding: .2em .5em; - border-bottom: 1px solid #ddd; + font-size: 26px; + padding: .2em .5em; + border-bottom: 1px solid #ddd; } h3 { - font-size: 24px; - padding: .2em .7em; - border-bottom: 1px solid #DDE8FC; + font-size: 24px; + padding: .2em .7em; + border-bottom: 1px solid #DDE8FC; } h4 { - font-size: 22px; + font-size: 22px; } h5 { - font-size: 20px; + font-size: 20px; } h6 { - font-size: 18px; + font-size: 18px; } @media (min-width: 992px) { - h1 { - font-size: 36px; - } - h2 { - font-size: 30px; - } - h3 { - font-size: 26px; - } + h1 { + font-size: 36px; + } + h2 { + font-size: 30px; + } + h3 { + font-size: 26px; + } } nav { - column-count: 2; - -moz-column-count: 2; - -webkit-column-count: 2; - font-size: 15px; - margin: 0 0 1em 0; + column-count: 2; + -moz-column-count: 2; + -webkit-column-count: 2; + font-size: 15px; + margin: 0 0 1em 0; } p { - margin: 0 0 1em 0; + margin: 0 0 1em 0; } strong { - font-weight: bold; + font-weight: bold; } em { - font-style: italic; + font-style: italic; } footer { - border-top: 1px solid #ddd; - font-size: 14px; - font-style: italic; - padding-top: 5px; - margin-top: 3em; - margin-bottom: 1em; + border-top: 1px solid #ddd; + font-size: 14px; + font-style: italic; + padding-top: 5px; + margin-top: 3em; + margin-bottom: 1em; } /* Links layout */ a { - text-decoration: none; - color: #428BCA; - background: transparent; + text-decoration: none; + color: #428BCA; + background: transparent; } a:hover, a:focus { - color: #2A6496; - text-decoration: underline; + color: #2A6496; + text-decoration: underline; } a:focus { - outline: thin dotted #333; - outline: 5px auto -webkit-focus-ring-color; - outline-offset: -2px; + outline: thin dotted #333; + outline: 5px auto -webkit-focus-ring-color; + outline-offset: -2px; } a:hover, a:active { - outline: 0; + outline: 0; } h1 a:link, h1 a:visited, h2 a:link, h2 a:visited, @@ -197,34 +197,34 @@ h5 a:hover {text-decoration: none;} /* Code */ pre, code { - font-family: "Source Code Pro", Menlo, Monaco, Consolas, "DejaVu Sans Mono", monospace; - word-wrap: break-word; + font-family: "Source Code Pro", Menlo, Monaco, Consolas, "DejaVu Sans Mono", monospace; + word-wrap: break-word; } pre { - border-left: 2px solid #eee; - white-space: pre-wrap; - padding: 14px; - padding-right: 0; - margin: 20px 0; - font-size: 13px; - word-break: break-all; + border-left: 2px solid #eee; + white-space: pre-wrap; + padding: 14px; + padding-right: 0; + margin: 20px 0; + font-size: 15px; + word-break: break-all; } code { - padding: 0 2px; - color: #8D1A38; + padding: 0 2px; + color: #8D1A38; } pre code { - padding: 0; - font-size: inherit; - color: inherit; + padding: 0; + font-size: inherit; + color: inherit; } a > code { - color: #428BCA; + color: #428BCA; } .section-header > a > code { - color: #8D1A38; + color: #8D1A38; } /* Code highlighting */ @@ -241,178 +241,221 @@ pre.rust .lifetime { color: #B76514; } /* The rest */ #versioninfo { - text-align: center; - margin: 0.5em; - font-size: 1.1em; + text-align: center; + margin: 0.5em; + font-size: 1.1em; } @media (min-width: 992px) { - #versioninfo { - font-size: 0.8em; - position: fixed; - bottom: 0px; - right: 0px; - } - .white-sticker { - background-color: #fff; - margin: 2px; - padding: 0 2px; - border-radius: .2em; - } + #versioninfo { + font-size: 0.8em; + position: fixed; + bottom: 0px; + right: 0px; + } + .white-sticker { + background-color: #fff; + margin: 2px; + padding: 0 2px; + border-radius: .2em; + } } #versioninfo a.hash { - color: gray; - font-size: 80%; + color: gray; + font-size: 80%; } blockquote { - color: #000; - margin: 20px 0; - padding: 15px 20px; - background-color: #f2f7f9; - border-top: .1em solid #e5eef2; - border-bottom: .1em solid #e5eef2; + color: #000; + margin: 20px 0; + padding: 15px 20px; + background-color: #f2f7f9; + border-top: .1em solid #e5eef2; + border-bottom: .1em solid #e5eef2; } blockquote p { - font-size: 17px; - font-weight: 300; - line-height: 1.4; + font-size: 17px; + font-weight: 300; + line-height: 1.4; } blockquote p:last-child { - margin-bottom: 0; + margin-bottom: 0; } ul, ol { - padding-left: 25px; + padding-left: 25px; } ul ul, ol ul, ul ol, ol ol { - margin-bottom: 0; + margin-bottom: 0; } dl { - margin-bottom: 20px; + margin-bottom: 20px; } dd { - margin-left: 0; + margin-left: 0; } nav ul { - list-style-type: none; - margin: 0; - padding-left: 0px; + list-style-type: none; + margin: 0; + padding-left: 0px; } /* Only display one level of hierarchy in the TOC */ nav ul ul { - display: none; + display: none; } sub, sup { - font-size: 75%; - line-height: 0; - position: relative; + font-size: 75%; + line-height: 0; + position: relative; } hr { - margin-top: 20px; - margin-bottom: 20px; - border: 0; - border-top: 1px solid #eeeeee; + margin-top: 20px; + margin-bottom: 20px; + border: 0; + border-top: 1px solid #eeeeee; } table { - border-collapse: collapse; - border-spacing: 0; - overflow-x: auto; - display: block; + border-collapse: collapse; + border-spacing: 0; + overflow-x: auto; + display: block; } table tr.odd { - background: #eee; + background: #eee; } table td, table th { - border: 1px solid #ddd; - padding: 5px; + border: 1px solid #ddd; + padding: 5px; } /* Code snippets */ pre.rust { position: relative; } a.test-arrow { - background-color: rgba(78, 139, 202, 0.2); - display: inline-block; - position: absolute; - color: #f5f5f5; - padding: 5px 10px 5px 10px; - border-radius: 5px; - font-size: 130%; - top: 5px; - right: 5px; + background-color: rgba(78, 139, 202, 0.2); + display: inline-block; + position: absolute; + color: #f5f5f5; + padding: 5px 10px 5px 10px; + border-radius: 5px; + font-size: 130%; + top: 5px; + right: 5px; } a.test-arrow:hover{ - background-color: #4e8bca; - text-decoration: none; + background-color: #4e8bca; + text-decoration: none; } .unstable-feature { - border: 2px solid red; - padding: 5px; + border: 2px solid red; + padding: 5px; } @media (min-width: 1170px) { - pre { - font-size: 15px; - } + pre { + font-size: 15px; + } } @media print { - * { - text-shadow: none !important; - color: #000 !important; - background: transparent !important; - box-shadow: none !important; - } - a, a:visited { - text-decoration: underline; - } - p a[href]:after { - content: " (" attr(href) ")"; - } - footer a[href]:after { - content: ""; - } - a[href^="javascript:"]:after, a[href^="#"]:after { - content: ""; - } - pre, blockquote { - border: 1px solid #999; - page-break-inside: avoid; - } - @page { - margin: 2cm .5cm; - } - h1:not(.title), h2, h3 { - border-bottom: 0px none; - } - p, h2, h3 { - orphans: 3; - widows: 3; - } - h2, h3 { - page-break-after: avoid; - } - table { - border-collapse: collapse !important; - } - table td, table th { - background-color: #fff !important; - } + * { + text-shadow: none !important; + color: #000 !important; + background: transparent !important; + box-shadow: none !important; + } + a, a:visited { + text-decoration: underline; + } + p a[href]:after { + content: " (" attr(href) ")"; + } + footer a[href]:after { + content: ""; + } + a[href^="javascript:"]:after, a[href^="#"]:after { + content: ""; + } + pre, blockquote { + border: 1px solid #999; + page-break-inside: avoid; + } + @page { + margin: 2cm .5cm; + } + h1:not(.title), h2, h3 { + border-bottom: 0px none; + } + p, h2, h3 { + orphans: 3; + widows: 3; + } + h2, h3 { + page-break-after: avoid; + } + table { + border-collapse: collapse !important; + } + table td, table th { + background-color: #fff !important; + } } #keyword-table-marker + table thead { display: none; } #keyword-table-marker + table td { border: none; } #keyword-table-marker + table { - margin-left: 2em; - margin-bottom: 1em; + margin-left: 2em; + margin-bottom: 1em; +} + +.error-described { + position: relative; +} + +.information { + position: absolute; + left: -25px; + margin-top: 7px; + z-index: 1; +} + +.tooltip { + position: relative; + display: inline-block; + cursor: pointer; +} + +.tooltip .tooltiptext { + width: 120px; + display: none; + text-align: center; + padding: 5px 3px; + border-radius: 6px; + margin-left: 5px; + top: -5px; + left: 105%; + z-index: 1; +} + +.tooltip:hover .tooltiptext { + display: inline; +} + +.tooltip .tooltiptext::after { + content: " "; + position: absolute; + top: 50%; + left: 13px; + margin-top: -5px; + border-width: 5px; + border-style: solid; } diff --git a/src/liballoc/benches/slice.rs b/src/liballoc/benches/slice.rs index 17538d885f8f..ee5182a1d466 100644 --- a/src/liballoc/benches/slice.rs +++ b/src/liballoc/benches/slice.rs @@ -343,7 +343,7 @@ macro_rules! rotate { fn $name(b: &mut Bencher) { let size = mem::size_of_val(&$gen(1)[0]); let mut v = $gen($len * 8 / size); - b.iter(|| black_box(&mut v).rotate(($mid*8+size-1)/size)); + b.iter(|| black_box(&mut v).rotate_left(($mid*8+size-1)/size)); b.bytes = (v.len() * size) as u64; } } diff --git a/src/liballoc/slice.rs b/src/liballoc/slice.rs index fa73197885be..28caccbc87fd 100644 --- a/src/liballoc/slice.rs +++ b/src/liballoc/slice.rs @@ -1360,24 +1360,61 @@ impl [T] { core_slice::SliceExt::sort_unstable_by_key(self, f); } - /// Permutes the slice in-place such that `self[mid..]` moves to the - /// beginning of the slice while `self[..mid]` moves to the end of the - /// slice. Equivalently, rotates the slice `mid` places to the left - /// or `k = self.len() - mid` places to the right. + /// Rotates the slice in-place such that the first `mid` elements of the + /// slice move to the end while the last `self.len() - mid` elements move to + /// the front. After calling `rotate_left`, the element previously at index + /// `mid` will become the first element in the slice. /// - /// This is a "k-rotation", a permutation in which item `i` moves to - /// position `i + k`, modulo the length of the slice. See _Elements - /// of Programming_ [ยง10.4][eop]. + /// # Panics + /// + /// This function will panic if `mid` is greater than the length of the + /// slice. Note that `mid == self.len()` does _not_ panic and is a no-op + /// rotation. + /// + /// # Complexity + /// + /// Takes linear (in `self.len()`) time. + /// + /// # Examples /// - /// Rotation by `mid` and rotation by `k` are inverse operations. + /// ``` + /// #![feature(slice_rotate)] /// - /// [eop]: https://books.google.com/books?id=CO9ULZGINlsC&pg=PA178&q=k-rotation + /// let mut a = ['a', 'b', 'c', 'd', 'e', 'f']; + /// a.rotate_left(2); + /// assert_eq!(a, ['c', 'd', 'e', 'f', 'a', 'b']); + /// ``` + /// + /// Rotating a subslice: + /// + /// ``` + /// #![feature(slice_rotate)] + /// + /// let mut a = ['a', 'b', 'c', 'd', 'e', 'f']; + /// a[1..5].rotate_left(1); + /// assert_eq!(a, ['a', 'c', 'd', 'e', 'b', 'f']); + /// ``` + #[unstable(feature = "slice_rotate", issue = "41891")] + pub fn rotate_left(&mut self, mid: usize) { + core_slice::SliceExt::rotate_left(self, mid); + } + + #[unstable(feature = "slice_rotate", issue = "41891")] + #[rustc_deprecated(since = "", reason = "renamed to `rotate_left`")] + pub fn rotate(&mut self, mid: usize) { + core_slice::SliceExt::rotate_left(self, mid); + } + + /// Rotates the slice in-place such that the first `self.len() - k` + /// elements of the slice move to the end while the last `k` elements move + /// to the front. After calling `rotate_right`, the element previously at + /// index `self.len() - k` will become the first element in the slice. /// /// # Panics /// - /// This function will panic if `mid` is greater than the length of the - /// slice. (Note that `mid == self.len()` does _not_ panic; it's a nop - /// rotation with `k == 0`, the inverse of a rotation with `mid == 0`.) + /// This function will panic if `k` is greater than the length of the + /// slice. Note that `k == self.len()` does _not_ panic and is a no-op + /// rotation. /// /// # Complexity /// @@ -1388,31 +1425,23 @@ impl [T] { /// ``` /// #![feature(slice_rotate)] /// - /// let mut a = [1, 2, 3, 4, 5, 6, 7]; - /// let mid = 2; - /// a.rotate(mid); - /// assert_eq!(&a, &[3, 4, 5, 6, 7, 1, 2]); - /// let k = a.len() - mid; - /// a.rotate(k); - /// assert_eq!(&a, &[1, 2, 3, 4, 5, 6, 7]); - /// - /// use std::ops::Range; - /// fn slide(slice: &mut [T], range: Range, to: usize) { - /// if to < range.start { - /// slice[to..range.end].rotate(range.start-to); - /// } else if to > range.end { - /// slice[range.start..to].rotate(range.end-range.start); - /// } - /// } - /// let mut v: Vec<_> = (0..10).collect(); - /// slide(&mut v, 1..4, 7); - /// assert_eq!(&v, &[0, 4, 5, 6, 1, 2, 3, 7, 8, 9]); - /// slide(&mut v, 6..8, 1); - /// assert_eq!(&v, &[0, 3, 7, 4, 5, 6, 1, 2, 8, 9]); + /// let mut a = ['a', 'b', 'c', 'd', 'e', 'f']; + /// a.rotate_right(2); + /// assert_eq!(a, ['e', 'f', 'a', 'b', 'c', 'd']); + /// ``` + /// + /// Rotate a subslice: + /// + /// ``` + /// #![feature(slice_rotate)] + /// + /// let mut a = ['a', 'b', 'c', 'd', 'e', 'f']; + /// a[1..5].rotate_right(1); + /// assert_eq!(a, ['a', 'e', 'b', 'c', 'd', 'f']); /// ``` #[unstable(feature = "slice_rotate", issue = "41891")] - pub fn rotate(&mut self, mid: usize) { - core_slice::SliceExt::rotate(self, mid); + pub fn rotate_right(&mut self, k: usize) { + core_slice::SliceExt::rotate_right(self, k); } /// Copies the elements from `src` into `self`. diff --git a/src/liballoc/tests/slice.rs b/src/liballoc/tests/slice.rs index 85d5ce304b88..49bdc9e1b90d 100644 --- a/src/liballoc/tests/slice.rs +++ b/src/liballoc/tests/slice.rs @@ -494,37 +494,72 @@ fn test_sort_stability() { } #[test] -fn test_rotate() { +fn test_rotate_left() { let expected: Vec<_> = (0..13).collect(); let mut v = Vec::new(); // no-ops v.clone_from(&expected); - v.rotate(0); + v.rotate_left(0); assert_eq!(v, expected); - v.rotate(expected.len()); + v.rotate_left(expected.len()); assert_eq!(v, expected); let mut zst_array = [(), (), ()]; - zst_array.rotate(2); + zst_array.rotate_left(2); // happy path v = (5..13).chain(0..5).collect(); - v.rotate(8); + v.rotate_left(8); assert_eq!(v, expected); let expected: Vec<_> = (0..1000).collect(); // small rotations in large slice, uses ptr::copy v = (2..1000).chain(0..2).collect(); - v.rotate(998); + v.rotate_left(998); assert_eq!(v, expected); v = (998..1000).chain(0..998).collect(); - v.rotate(2); + v.rotate_left(2); assert_eq!(v, expected); // non-small prime rotation, has a few rounds of swapping v = (389..1000).chain(0..389).collect(); - v.rotate(1000-389); + v.rotate_left(1000-389); + assert_eq!(v, expected); +} + +#[test] +fn test_rotate_right() { + let expected: Vec<_> = (0..13).collect(); + let mut v = Vec::new(); + + // no-ops + v.clone_from(&expected); + v.rotate_right(0); + assert_eq!(v, expected); + v.rotate_right(expected.len()); + assert_eq!(v, expected); + let mut zst_array = [(), (), ()]; + zst_array.rotate_right(2); + + // happy path + v = (5..13).chain(0..5).collect(); + v.rotate_right(5); + assert_eq!(v, expected); + + let expected: Vec<_> = (0..1000).collect(); + + // small rotations in large slice, uses ptr::copy + v = (2..1000).chain(0..2).collect(); + v.rotate_right(2); + assert_eq!(v, expected); + v = (998..1000).chain(0..998).collect(); + v.rotate_right(998); + assert_eq!(v, expected); + + // non-small prime rotation, has a few rounds of swapping + v = (389..1000).chain(0..389).collect(); + v.rotate_right(389); assert_eq!(v, expected); } diff --git a/src/libcore/slice/mod.rs b/src/libcore/slice/mod.rs index 72036d6d3a24..e6b79314aa96 100644 --- a/src/libcore/slice/mod.rs +++ b/src/libcore/slice/mod.rs @@ -206,7 +206,10 @@ pub trait SliceExt { fn ends_with(&self, needle: &[Self::Item]) -> bool where Self::Item: PartialEq; #[unstable(feature = "slice_rotate", issue = "41891")] - fn rotate(&mut self, mid: usize); + fn rotate_left(&mut self, mid: usize); + + #[unstable(feature = "slice_rotate", issue = "41891")] + fn rotate_right(&mut self, k: usize); #[stable(feature = "clone_from_slice", since = "1.7.0")] fn clone_from_slice(&mut self, src: &[Self::Item]) where Self::Item: Clone; @@ -645,7 +648,7 @@ impl SliceExt for [T] { self.binary_search_by(|p| p.cmp(x)) } - fn rotate(&mut self, mid: usize) { + fn rotate_left(&mut self, mid: usize) { assert!(mid <= self.len()); let k = self.len() - mid; @@ -655,6 +658,16 @@ impl SliceExt for [T] { } } + fn rotate_right(&mut self, k: usize) { + assert!(k <= self.len()); + let mid = self.len() - k; + + unsafe { + let p = self.as_mut_ptr(); + rotate::ptr_rotate(mid, p.offset(mid as isize), k); + } + } + #[inline] fn clone_from_slice(&mut self, src: &[T]) where T: Clone { assert!(self.len() == src.len(), diff --git a/src/libcore/tests/slice.rs b/src/libcore/tests/slice.rs index d6230e93f998..40e5fe5758ac 100644 --- a/src/libcore/tests/slice.rs +++ b/src/libcore/tests/slice.rs @@ -329,17 +329,32 @@ fn test_iter_folds() { } #[test] -fn test_rotate() { +fn test_rotate_left() { const N: usize = 600; let a: &mut [_] = &mut [0; N]; for i in 0..N { a[i] = i; } - a.rotate(42); + a.rotate_left(42); let k = N - 42; for i in 0..N { - assert_eq!(a[(i+k)%N], i); + assert_eq!(a[(i + k) % N], i); + } +} + +#[test] +fn test_rotate_right() { + const N: usize = 600; + let a: &mut [_] = &mut [0; N]; + for i in 0..N { + a[i] = i; + } + + a.rotate_right(42); + + for i in 0..N { + assert_eq!(a[(i + 42) % N], i); } } diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index a2a6a0da68ff..ffb844632e46 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -1214,8 +1214,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InvalidNoMangleItems { // don't have anything to attach a symbol to let msg = "const items should never be #[no_mangle]"; let mut err = cx.struct_span_lint(NO_MANGLE_CONST_ITEMS, it.span, msg); + + // account for "pub const" (#45562) + let start = cx.tcx.sess.codemap().span_to_snippet(it.span) + .map(|snippet| snippet.find("const").unwrap_or(0)) + .unwrap_or(0) as u32; // `const` is 5 chars - let const_span = it.span.with_hi(BytePos(it.span.lo().0 + 5)); + let const_span = it.span.with_hi(BytePos(it.span.lo().0 + start + 5)); err.span_suggestion(const_span, "try a static value", "pub static".to_owned()); diff --git a/src/libstd/macros.rs b/src/libstd/macros.rs index 9f3f0ea27421..f058b1caef50 100644 --- a/src/libstd/macros.rs +++ b/src/libstd/macros.rs @@ -283,7 +283,7 @@ pub mod builtin { /// Unconditionally causes compilation to fail with the given error message when encountered. /// /// This macro should be used when a crate uses a conditional compilation strategy to provide - /// better error messages for errornous conditions. + /// better error messages for erroneous conditions. /// /// # Examples /// diff --git a/src/libstd/panicking.rs b/src/libstd/panicking.rs index 80ce15944a5c..f91eaf433d76 100644 --- a/src/libstd/panicking.rs +++ b/src/libstd/panicking.rs @@ -316,7 +316,6 @@ impl<'a> Location<'a> { /// # Examples /// /// ```should_panic - /// #![feature(panic_col)] /// use std::panic; /// /// panic::set_hook(Box::new(|panic_info| { @@ -329,7 +328,7 @@ impl<'a> Location<'a> { /// /// panic!("Normal panic"); /// ``` - #[unstable(feature = "panic_col", reason = "recently added", issue = "42939")] + #[stable(feature = "panic_col", since = "1.25")] pub fn column(&self) -> u32 { self.col } diff --git a/src/test/ui/suggestions/issue-45562.rs b/src/test/ui/suggestions/issue-45562.rs new file mode 100644 index 000000000000..f493df56f949 --- /dev/null +++ b/src/test/ui/suggestions/issue-45562.rs @@ -0,0 +1,14 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#[no_mangle] pub const RAH: usize = 5; +//~^ ERROR const items should never be #[no_mangle] + +fn main() {} diff --git a/src/test/ui/suggestions/issue-45562.stderr b/src/test/ui/suggestions/issue-45562.stderr new file mode 100644 index 000000000000..2f8c4cd3f2e7 --- /dev/null +++ b/src/test/ui/suggestions/issue-45562.stderr @@ -0,0 +1,12 @@ +error: const items should never be #[no_mangle] + --> $DIR/issue-45562.rs:11:14 + | +11 | #[no_mangle] pub const RAH: usize = 5; + | ---------^^^^^^^^^^^^^^^^ + | | + | help: try a static value: `pub static` + | + = note: #[deny(no_mangle_const_items)] on by default + +error: aborting due to previous error + diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index 774733e7068f..d1643c0aa4b6 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -2867,7 +2867,7 @@ fn read2_abbreviated(mut child: Child) -> io::Result { *skipped += data.len(); if data.len() <= TAIL_LEN { tail[..data.len()].copy_from_slice(data); - tail.rotate(data.len()); + tail.rotate_left(data.len()); } else { tail.copy_from_slice(&data[(data.len() - TAIL_LEN)..]); } diff --git a/src/tools/error_index_generator/main.rs b/src/tools/error_index_generator/main.rs index ca383b5add01..aedae366c411 100644 --- a/src/tools/error_index_generator/main.rs +++ b/src/tools/error_index_generator/main.rs @@ -109,7 +109,65 @@ impl Formatter for HTMLFormatter { } fn footer(&self, output: &mut Write) -> Result<(), Box> { - write!(output, "\n")?; + write!(output, r##" + +"##)?; Ok(()) } }