]> git.lizzy.rs Git - rust.git/commitdiff
Rollup merge of #50421 - kennytm:fix-50415-ice-when-returning-range-inclusive-from...
authorkennytm <kennytm@gmail.com>
Thu, 3 May 2018 15:42:36 +0000 (23:42 +0800)
committerkennytm <kennytm@gmail.com>
Thu, 3 May 2018 18:12:55 +0000 (02:12 +0800)
Fix ICE when using a..=b in a closure.

Fix #50415.

14 files changed:
src/librustc/lint/mod.rs
src/librustc/middle/region.rs
src/librustc_mir/hair/pattern/mod.rs
src/librustc_mir/interpret/eval_context.rs
src/librustdoc/html/static/main.js
src/libstd/path.rs
src/libsyntax_pos/lib.rs
src/test/rustdoc-js/alias.js
src/test/rustdoc-js/basic.js
src/test/ui/const-eval/ice-packed.rs [new file with mode: 0644]
src/test/ui/inference_unstable.rs
src/test/ui/inference_unstable.stderr
src/tools/cargo
src/tools/rustdoc-js/tester.js

index 0d4fd99995f7ed2d57d4fefe61d16cb20ab4b28f..d6c6f9dc0f61a0b1e5c72fee9af09b4b2634d6e3 100644 (file)
@@ -507,7 +507,7 @@ pub fn struct_lint_level<'a>(sess: &'a Session,
 
         let explanation = if lint_id == LintId::of(::lint::builtin::UNSTABLE_NAME_COLLISION) {
             "once this method is added to the standard library, \
-             there will be ambiguity here, which will cause a hard error!"
+             the ambiguity may cause an error or change in behavior!"
                 .to_owned()
         } else if let Some(edition) = future_incompatible.edition {
             format!("{} in the {} edition!", STANDARD_MESSAGE, edition)
index 5f4efbeeaa8762da80ffc0cf8119189a29e418d7..bfc9ff6660de9890254f9d37eb06660d413da73d 100644 (file)
@@ -690,21 +690,22 @@ pub fn nearest_common_ancestor(&self,
         // the start. So this algorithm is faster.
         let mut ma = Some(scope_a);
         let mut mb = Some(scope_b);
-        let mut seen: SmallVec<[Scope; 32]> = SmallVec::new();
+        let mut seen_a: SmallVec<[Scope; 32]> = SmallVec::new();
+        let mut seen_b: SmallVec<[Scope; 32]> = SmallVec::new();
         loop {
             if let Some(a) = ma {
-                if seen.iter().position(|s| *s == a).is_some() {
+                if seen_b.iter().position(|s| *s == a).is_some() {
                     return a;
                 }
-                seen.push(a);
+                seen_a.push(a);
                 ma = self.parent_map.get(&a).map(|s| *s);
             }
 
             if let Some(b) = mb {
-                if seen.iter().position(|s| *s == b).is_some() {
+                if seen_a.iter().position(|s| *s == b).is_some() {
                     return b;
                 }
-                seen.push(b);
+                seen_b.push(b);
                 mb = self.parent_map.get(&b).map(|s| *s);
             }
 
index 619b4596b42277c0649439b94ed9eef25f90be9e..623e0de478bcaf6979361d138b70674651fbdd36 100644 (file)
@@ -792,7 +792,7 @@ fn const_to_pat(
                 ConstVal::Value(miri) => const_val_field(
                     self.tcx, self.param_env, instance,
                     variant_opt, field, miri, cv.ty,
-                ).unwrap(),
+                ).expect("field access failed"),
                 _ => bug!("{:#?} is not a valid adt", cv),
             };
             self.const_to_pat(instance, val, id, span)
index e1b358a5eb7799ed19bd784d465480dbb4694a66..bea29b6926aa63c1b48b1c6a5266a75b809885d7 100644 (file)
@@ -1340,9 +1340,7 @@ pub fn try_read_value(&self, ptr: Pointer, ptr_align: Align, ty: Ty<'tcx>) -> Ev
         use syntax::ast::FloatTy;
 
         let layout = self.layout_of(ty)?;
-        // do the strongest layout check of the two
-        let align = layout.align.max(ptr_align);
-        self.memory.check_align(ptr, align)?;
+        self.memory.check_align(ptr, ptr_align)?;
 
         if layout.size.bytes() == 0 {
             return Ok(Some(Value::ByVal(PrimVal::Undef)));
index bcad2eb19f57496aa401e6e81044d7fb0a4b4330..6d80145b29c7c271a70a5b42166fd6231890de3b 100644 (file)
         if (e.parentNode.id === "main") {
             var otherMessage;
             if (hasClass(e, "type-decl")) {
-                otherMessage = '&nbsp;Show&nbsp;type&nbsp;declaration';
+                otherMessage = '&nbsp;Show&nbsp;declaration';
             }
             e.parentNode.insertBefore(createToggle(otherMessage), e);
             if (otherMessage && getCurrentValue('rustdoc-item-declarations') !== "false") {
index 955a6af1ae67eaac5a78975499cf329658003667..696711a70d4f6408cc773abf87d04ed932e64b02 100644 (file)
@@ -87,7 +87,6 @@
 use iter::{self, FusedIterator};
 use ops::{self, Deref};
 use rc::Rc;
-use str::FromStr;
 use sync::Arc;
 
 use ffi::{OsStr, OsString};
@@ -1441,32 +1440,6 @@ fn from(s: String) -> PathBuf {
     }
 }
 
-/// Error returned from [`PathBuf::from_str`][`from_str`].
-///
-/// Note that parsing a path will never fail. This error is just a placeholder
-/// for implementing `FromStr` for `PathBuf`.
-///
-/// [`from_str`]: struct.PathBuf.html#method.from_str
-#[derive(Debug, Clone, PartialEq, Eq)]
-#[stable(feature = "path_from_str", since = "1.26.0")]
-pub enum ParsePathError {}
-
-#[stable(feature = "path_from_str", since = "1.26.0")]
-impl fmt::Display for ParsePathError {
-    fn fmt(&self, _: &mut fmt::Formatter) -> fmt::Result {
-        match *self {}
-    }
-}
-
-#[stable(feature = "path_from_str", since = "1.26.0")]
-impl FromStr for PathBuf {
-    type Err = ParsePathError;
-
-    fn from_str(s: &str) -> Result<Self, Self::Err> {
-        Ok(PathBuf::from(s))
-    }
-}
-
 #[stable(feature = "rust1", since = "1.0.0")]
 impl<P: AsRef<Path>> iter::FromIterator<P> for PathBuf {
     fn from_iter<I: IntoIterator<Item = P>>(iter: I) -> PathBuf {
index 8d37b4aa3968f5c84deaa5cd3383eb13ba21e4d2..8b4a3ea26a1ef7dca52f5a179e2f0110c7ea5f3f 100644 (file)
@@ -1150,13 +1150,17 @@ pub trait Pos {
 // have been unsuccessful
 
 impl Pos for BytePos {
+    #[inline(always)]
     fn from_usize(n: usize) -> BytePos { BytePos(n as u32) }
+
+    #[inline(always)]
     fn to_usize(&self) -> usize { let BytePos(n) = *self; n as usize }
 }
 
 impl Add for BytePos {
     type Output = BytePos;
 
+    #[inline(always)]
     fn add(self, rhs: BytePos) -> BytePos {
         BytePos((self.to_usize() + rhs.to_usize()) as u32)
     }
@@ -1165,6 +1169,7 @@ fn add(self, rhs: BytePos) -> BytePos {
 impl Sub for BytePos {
     type Output = BytePos;
 
+    #[inline(always)]
     fn sub(self, rhs: BytePos) -> BytePos {
         BytePos((self.to_usize() - rhs.to_usize()) as u32)
     }
@@ -1183,13 +1188,17 @@ fn decode<D: Decoder>(d: &mut D) -> Result<BytePos, D::Error> {
 }
 
 impl Pos for CharPos {
+    #[inline(always)]
     fn from_usize(n: usize) -> CharPos { CharPos(n) }
+
+    #[inline(always)]
     fn to_usize(&self) -> usize { let CharPos(n) = *self; n }
 }
 
 impl Add for CharPos {
     type Output = CharPos;
 
+    #[inline(always)]
     fn add(self, rhs: CharPos) -> CharPos {
         CharPos(self.to_usize() + rhs.to_usize())
     }
@@ -1198,6 +1207,7 @@ fn add(self, rhs: CharPos) -> CharPos {
 impl Sub for CharPos {
     type Output = CharPos;
 
+    #[inline(always)]
     fn sub(self, rhs: CharPos) -> CharPos {
         CharPos(self.to_usize() - rhs.to_usize())
     }
index a0500f24c17ee61454872cd88649595be78403b8..93a04e31985bac705acb4cb8713c71d92dba1f69 100644 (file)
@@ -8,6 +8,8 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+// ignore-order
+
 const QUERY = '[';
 
 const EXPECTED = {
index 863437cac91d46340f4b40a2acff9c4d804803be..d7ba1253eabe0ddb377353944d65e89f949ae058 100644 (file)
@@ -13,8 +13,8 @@ const QUERY = 'String';
 const EXPECTED = {
     'others': [
         { 'path': 'std::string', 'name': 'String' },
-        { 'path': 'std::ffi', 'name': 'OsString' },
         { 'path': 'std::ffi', 'name': 'CString' },
+        { 'path': 'std::ffi', 'name': 'OsString' },
     ],
     'in_args': [
         { 'path': 'std::str', 'name': 'eq' },
diff --git a/src/test/ui/const-eval/ice-packed.rs b/src/test/ui/const-eval/ice-packed.rs
new file mode 100644 (file)
index 0000000..1db12a0
--- /dev/null
@@ -0,0 +1,28 @@
+// 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// compile-pass
+#[derive(Copy, Clone, PartialEq, Eq)]
+#[repr(packed)]
+pub struct Num(u64);
+
+impl Num {
+    pub const ZERO: Self = Num(0);
+}
+
+pub fn decrement(a: Num) -> Num {
+    match a {
+        Num::ZERO => Num::ZERO,
+        a => Num(a.0 - 1)
+    }
+}
+
+fn main() {
+}
index 816c443a06c21c6c38fb9600fde1173b0c082636..5a70dffd4c8c2f91b14e0da642c20f99b62d12d2 100644 (file)
@@ -25,5 +25,5 @@
 fn main() {
     assert_eq!('x'.ipu_flatten(), 1);
     //~^ WARN a method with this name may be added to the standard library in the future
-    //~^^ WARN once this method is added to the standard library, there will be ambiguity here
+    //~^^ WARN once this method is added to the standard library, the ambiguity may cause an error
 }
index 9c614d659d36f79319f9ec78b011ddb4bc33fe9c..a217bc57b367028cae9be7e8e5d30aba7e79d83a 100644 (file)
@@ -5,7 +5,7 @@ LL |     assert_eq!('x'.ipu_flatten(), 1);
    |                    ^^^^^^^^^^^
    |
    = note: #[warn(unstable_name_collision)] on by default
-   = warning: once this method is added to the standard library, there will be ambiguity here, which will cause a hard error!
+   = warning: once this method is added to the standard library, the ambiguity may cause an error or change in behavior!
    = note: for more information, see issue #48919 <https://github.com/rust-lang/rust/issues/48919>
    = help: call with fully qualified syntax `inference_unstable_itertools::IpuItertools::ipu_flatten(...)` to keep using the current method
    = note: add #![feature(ipu_flatten)] to the crate attributes to enable `inference_unstable_iterator::IpuIterator::ipu_flatten`
index 122fd5be5201913d42e219e132d6569493583bca..66b0ffa81c560be1b79511b51f49cbb23bc78651 160000 (submodule)
@@ -1 +1 @@
-Subproject commit 122fd5be5201913d42e219e132d6569493583bca
+Subproject commit 66b0ffa81c560be1b79511b51f49cbb23bc78651
index 6992f2ba123378d481baa367a5947e30f8f32d6d..1c79443dedf35551319ea138ec6580470e3162af 100644 (file)
@@ -87,6 +87,7 @@ function loadContent(content) {
     var Module = module.constructor;
     var m = new Module();
     m._compile(content, "tmp.js");
+    m.exports.ignore_order = content.indexOf("\n// ignore-order\n") !== -1;
     return m.exports;
 }
 
@@ -130,10 +131,10 @@ function lookForEntry(entry, data) {
             }
         }
         if (allGood === true) {
-            return true;
+            return i;
         }
     }
-    return false;
+    return null;
 }
 
 function main(argv) {
@@ -177,6 +178,7 @@ function main(argv) {
                                'exports.QUERY = QUERY;exports.EXPECTED = EXPECTED;');
         const expected = loadedFile.EXPECTED;
         const query = loadedFile.QUERY;
+        const ignore_order = loadedFile.ignore_order;
         var results = loaded.execSearch(loaded.getQuery(query), index);
         process.stdout.write('Checking "' + file + '" ... ');
         var error_text = [];
@@ -189,13 +191,17 @@ function main(argv) {
                 break;
             }
             var entry = expected[key];
-            var found = false;
+            var prev_pos = 0;
             for (var i = 0; i < entry.length; ++i) {
-                if (lookForEntry(entry[i], results[key]) === true) {
-                    found = true;
-                } else {
+                var entry_pos = lookForEntry(entry[i], results[key]);
+                if (entry_pos === null) {
                     error_text.push("==> Result not found in '" + key + "': '" +
                                     JSON.stringify(entry[i]) + "'");
+                } else if (entry_pos < prev_pos && ignore_order === false) {
+                    error_text.push("==> '" + JSON.stringify(entry[i]) + "' was supposed to be " +
+                                    " before '" + JSON.stringify(results[key][entry_pos]) + "'");
+                } else {
+                    prev_pos = entry_pos;
                 }
             }
         }