Skip to content

Commit 58b75f7

Browse files
committed
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.
1 parent 9548730 commit 58b75f7

File tree

5 files changed

+47
-2
lines changed

5 files changed

+47
-2
lines changed

src/librustc/ty/flags.rs

+5
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@ impl FlagComputation {
107107
}
108108

109109
&ty::TyProjection(ref data) => {
110+
// currently we can't normalize projections that
111+
// include bound regions, so track those separately.
112+
if !data.has_escaping_regions() {
113+
self.add_flags(TypeFlags::HAS_NORMALIZABLE_PROJECTION);
114+
}
110115
self.add_flags(TypeFlags::HAS_PROJECTION);
111116
self.add_projection_ty(data);
112117
}

src/librustc/ty/fold.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ pub trait TypeFoldable<'tcx>: fmt::Debug + Clone {
105105
TypeFlags::HAS_FREE_REGIONS |
106106
TypeFlags::HAS_TY_INFER |
107107
TypeFlags::HAS_PARAMS |
108-
TypeFlags::HAS_PROJECTION |
108+
TypeFlags::HAS_NORMALIZABLE_PROJECTION |
109109
TypeFlags::HAS_TY_ERR |
110110
TypeFlags::HAS_SELF)
111111
}

src/librustc/ty/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,10 @@ bitflags! {
462462
// Only set for TyInfer other than Fresh.
463463
const KEEP_IN_LOCAL_TCX = 1 << 11,
464464

465+
// Is there a projection that does not involve a bound region?
466+
// Currently we can't normalize projections w/ bound regions.
467+
const HAS_NORMALIZABLE_PROJECTION = 1 << 12,
468+
465469
const NEEDS_SUBST = TypeFlags::HAS_PARAMS.bits |
466470
TypeFlags::HAS_SELF.bits |
467471
TypeFlags::HAS_RE_EARLY_BOUND.bits,

src/librustc_trans/collector.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1019,7 +1019,9 @@ fn create_fn_trans_item<'a, 'tcx>(scx: &SharedCrateContext<'a, 'tcx>,
10191019
let concrete_substs = monomorphize::apply_param_substs(scx,
10201020
param_substs,
10211021
&fn_substs);
1022-
assert!(concrete_substs.is_normalized_for_trans());
1022+
assert!(concrete_substs.is_normalized_for_trans(),
1023+
"concrete_substs not normalized for trans: {:?}",
1024+
concrete_substs);
10231025
TransItem::Fn(Instance::new(def_id, concrete_substs))
10241026
}
10251027

src/test/run-pass/issue-36381.rs

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Regression test for #36381. The trans collector was asserting that
12+
// there are no projection types, but the `<&str as
13+
// StreamOnce>::Position` projection contained a late-bound region,
14+
// and we don't currently normalize in that case until the function is
15+
// actually invoked.
16+
17+
pub trait StreamOnce {
18+
type Position;
19+
}
20+
21+
impl<'a> StreamOnce for &'a str {
22+
type Position = usize;
23+
}
24+
25+
pub fn parser<F>(_: F) {
26+
}
27+
28+
fn follow(_: &str) -> <&str as StreamOnce>::Position {
29+
panic!()
30+
}
31+
32+
fn main() {
33+
parser(follow);
34+
}

0 commit comments

Comments
 (0)