about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNiko Matsakis <niko@alum.mit.edu>2016-09-30 18:15:11 -0400
committerNiko Matsakis <niko@alum.mit.edu>2016-10-03 11:52:36 -0400
commit58b75f7aa3165d6b412610d3eae210df55182398 (patch)
treef0af04e9ff3551bae6108f4ac3f8a1e4be96406b
parent954873055a998a06841ac19b39b1fe18a6641731 (diff)
downloadrust-58b75f7aa3165d6b412610d3eae210df55182398.tar.gz
rust-58b75f7aa3165d6b412610d3eae210df55182398.zip
loosen assertion against proj in collector
The collector was asserting a total absence of projections, but some
projections are expected, even in trans: in particular, projections
containing higher-ranked regions, which we don't currently normalize.
-rw-r--r--src/librustc/ty/flags.rs5
-rw-r--r--src/librustc/ty/fold.rs2
-rw-r--r--src/librustc/ty/mod.rs4
-rw-r--r--src/librustc_trans/collector.rs4
-rw-r--r--src/test/run-pass/issue-36381.rs34
5 files changed, 47 insertions, 2 deletions
diff --git a/src/librustc/ty/flags.rs b/src/librustc/ty/flags.rs
index cddd59fa83c..1434b0e60e2 100644
--- a/src/librustc/ty/flags.rs
+++ b/src/librustc/ty/flags.rs
@@ -107,6 +107,11 @@ impl FlagComputation {
             }
 
             &ty::TyProjection(ref data) => {
+                // currently we can't normalize projections that
+                // include bound regions, so track those separately.
+                if !data.has_escaping_regions() {
+                    self.add_flags(TypeFlags::HAS_NORMALIZABLE_PROJECTION);
+                }
                 self.add_flags(TypeFlags::HAS_PROJECTION);
                 self.add_projection_ty(data);
             }
diff --git a/src/librustc/ty/fold.rs b/src/librustc/ty/fold.rs
index 2c18d1d5254..886ad8cd861 100644
--- a/src/librustc/ty/fold.rs
+++ b/src/librustc/ty/fold.rs
@@ -105,7 +105,7 @@ pub trait TypeFoldable<'tcx>: fmt::Debug + Clone {
                              TypeFlags::HAS_FREE_REGIONS |
                              TypeFlags::HAS_TY_INFER |
                              TypeFlags::HAS_PARAMS |
-                             TypeFlags::HAS_PROJECTION |
+                             TypeFlags::HAS_NORMALIZABLE_PROJECTION |
                              TypeFlags::HAS_TY_ERR |
                              TypeFlags::HAS_SELF)
     }
diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs
index 717b8923a16..723af1f0d90 100644
--- a/src/librustc/ty/mod.rs
+++ b/src/librustc/ty/mod.rs
@@ -462,6 +462,10 @@ bitflags! {
         // Only set for TyInfer other than Fresh.
         const KEEP_IN_LOCAL_TCX  = 1 << 11,
 
+        // Is there a projection that does not involve a bound region?
+        // Currently we can't normalize projections w/ bound regions.
+        const HAS_NORMALIZABLE_PROJECTION = 1 << 12,
+
         const NEEDS_SUBST        = TypeFlags::HAS_PARAMS.bits |
                                    TypeFlags::HAS_SELF.bits |
                                    TypeFlags::HAS_RE_EARLY_BOUND.bits,
diff --git a/src/librustc_trans/collector.rs b/src/librustc_trans/collector.rs
index 429bc7490fc..8112bb8e65c 100644
--- a/src/librustc_trans/collector.rs
+++ b/src/librustc_trans/collector.rs
@@ -1019,7 +1019,9 @@ fn create_fn_trans_item<'a, 'tcx>(scx: &SharedCrateContext<'a, 'tcx>,
     let concrete_substs = monomorphize::apply_param_substs(scx,
                                                            param_substs,
                                                            &fn_substs);
-    assert!(concrete_substs.is_normalized_for_trans());
+    assert!(concrete_substs.is_normalized_for_trans(),
+            "concrete_substs not normalized for trans: {:?}",
+            concrete_substs);
     TransItem::Fn(Instance::new(def_id, concrete_substs))
 }
 
diff --git a/src/test/run-pass/issue-36381.rs b/src/test/run-pass/issue-36381.rs
new file mode 100644
index 00000000000..6cd991bd942
--- /dev/null
+++ b/src/test/run-pass/issue-36381.rs
@@ -0,0 +1,34 @@
+// Copyright 2014 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.
+
+// Regression test for #36381. The trans collector was asserting that
+// there are no projection types, but the `<&str as
+// StreamOnce>::Position` projection contained a late-bound region,
+// and we don't currently normalize in that case until the function is
+// actually invoked.
+
+pub trait StreamOnce {
+    type Position;
+}
+
+impl<'a> StreamOnce for &'a str {
+    type Position = usize;
+}
+
+pub fn parser<F>(_: F) {
+}
+
+fn follow(_: &str) -> <&str as StreamOnce>::Position {
+    panic!()
+}
+
+fn main() {
+    parser(follow);
+}