Skip to content

Commit 5010496

Browse files
spastorinonikomatsakis
authored andcommitted
Check Aggregate predicates
1 parent c915926 commit 5010496

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

src/librustc_mir/transform/type_check.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,6 +1168,8 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
11681168
) {
11691169
let tcx = self.tcx();
11701170

1171+
self.prove_aggregate_predicates(aggregate_kind, location);
1172+
11711173
match aggregate_kind {
11721174
// tuple rvalue field type is always the type of the op. Nothing to check here.
11731175
AggregateKind::Tuple => return,
@@ -1235,6 +1237,31 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
12351237
}
12361238
}
12371239

1240+
fn prove_aggregate_predicates(
1241+
&mut self,
1242+
aggregate_kind: &AggregateKind<'tcx>,
1243+
location: Location,
1244+
) {
1245+
let tcx = self.tcx();
1246+
1247+
let instantiated_predicates = match aggregate_kind {
1248+
AggregateKind::Adt(def, _, substs, _) => {
1249+
tcx.predicates_of(def.did).instantiate(tcx, substs)
1250+
}
1251+
1252+
AggregateKind::Closure(def_id, substs) |
1253+
AggregateKind::Generator(def_id, substs, _) => {
1254+
tcx.predicates_of(*def_id).instantiate(tcx, substs.substs)
1255+
}
1256+
1257+
AggregateKind::Array(_) |
1258+
AggregateKind::Tuple => ty::InstantiatedPredicates::empty(),
1259+
};
1260+
1261+
let predicates = self.normalize(&instantiated_predicates.predicates, location);
1262+
self.prove_predicates(&predicates, location);
1263+
}
1264+
12381265
fn prove_trait_ref(&mut self, trait_ref: ty::TraitRef<'tcx>, location: Location) {
12391266
self.prove_predicates(
12401267
&[
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright 2017 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+
// compile-flags: -Z borrowck=mir -Z nll
12+
13+
#![allow(dead_code)]
14+
15+
use std::cell::Cell;
16+
17+
struct Foo<'a: 'b, 'b> {
18+
x: Cell<&'a u32>,
19+
y: Cell<&'b u32>,
20+
}
21+
22+
fn bar<'a, 'b>(x: Cell<&'a u32>, y: Cell<&'b u32>) {
23+
Foo { x, y };
24+
//~^ ERROR free region `'_#1r` does not outlive free region `'_#2r`
25+
//~| WARNING not reporting region error due to -Znll
26+
}
27+
28+
fn main() {}

0 commit comments

Comments
 (0)