]> git.lizzy.rs Git - rust.git/commitdiff
Take out an insurance policy in case `iter.size_hint()`
authorMazdak Farrokhzad <twingoow@gmail.com>
Thu, 24 Oct 2019 01:21:23 +0000 (03:21 +0200)
committerMazdak Farrokhzad <twingoow@gmail.com>
Fri, 25 Oct 2019 15:43:53 +0000 (17:43 +0200)
lies, underreporting the number of elements.

src/librustc/ty/context.rs

index f958a7e357b398736682d5de5a904e98ef826797..0f7d5d9a25e617d8b750e9b59bd16f980139f25b 100644 (file)
@@ -2930,14 +2930,18 @@ fn intern_with<I: Iterator<Item=Self>, F: FnOnce(&[T]) -> R>(mut iter: I, f: F)
         // lower bounds from `size_hint` agree they are correct.
         Ok(match iter.size_hint() {
             (1, Some(1)) => {
-                f(&[iter.next().unwrap()?])
+                let t0 = iter.next().unwrap()?;
+                assert!(iter.next().is_none());
+                f(&[t0])
             }
             (2, Some(2)) => {
                 let t0 = iter.next().unwrap()?;
                 let t1 = iter.next().unwrap()?;
+                assert!(iter.next().is_none());
                 f(&[t0, t1])
             }
             (0, Some(0)) => {
+                assert!(iter.next().is_none());
                 f(&[])
             }
             _ => {