Skip to content

Commit 5618aba

Browse files
committed
Auto merge of #44857 - toidiu:ak-44493-empty-predicate, r=nikomatsakis
#44493 add structure for inferred_outlives_of #44493 - add placeholder for the final implementation of inferred_outlives_of - add some placeholder tests
2 parents 4e9527c + 98c6e0a commit 5618aba

File tree

9 files changed

+113
-1
lines changed

9 files changed

+113
-1
lines changed

src/librustc/dep_graph/dep_node.rs

+1
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,7 @@ define_dep_nodes!( <'tcx>
476476
[] TypeOfItem(DefId),
477477
[] GenericsOfItem(DefId),
478478
[] PredicatesOfItem(DefId),
479+
[] InferredOutlivesOf(DefId),
479480
[] SuperPredicatesOfItem(DefId),
480481
[] TraitDefOfItem(DefId),
481482
[] AdtDefOfItem(DefId),

src/librustc/ty/maps/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ define_maps! { <'tcx>
121121
/// (inferred) variance.
122122
[] fn variances_of: ItemVariances(DefId) -> Rc<Vec<ty::Variance>>,
123123

124+
/// Maps from def-id of a type to its (inferred) outlives.
125+
[] fn inferred_outlives_of: InferredOutlivesOf(DefId) -> Vec<ty::Predicate<'tcx>>,
126+
124127
/// Maps from an impl/trait def-id to a list of the def-ids of its items
125128
[] fn associated_item_def_ids: AssociatedItemDefIds(DefId) -> Rc<Vec<DefId>>,
126129

src/librustc/ty/maps/plumbing.rs

+1
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,7 @@ pub fn force_from_dep_node<'a, 'gcx, 'lcx>(tcx: TyCtxt<'a, 'gcx, 'lcx>,
736736
DepKind::TypeOfItem => { force!(type_of, def_id!()); }
737737
DepKind::GenericsOfItem => { force!(generics_of, def_id!()); }
738738
DepKind::PredicatesOfItem => { force!(predicates_of, def_id!()); }
739+
DepKind::InferredOutlivesOf => { force!(inferred_outlives_of, def_id!()); }
739740
DepKind::SuperPredicatesOfItem => { force!(super_predicates_of, def_id!()); }
740741
DepKind::TraitDefOfItem => { force!(trait_def, def_id!()); }
741742
DepKind::AdtDefOfItem => { force!(adt_def, def_id!()); }

src/librustc_typeck/collect.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -1332,7 +1332,11 @@ fn early_bound_lifetimes_from_generics<'a, 'tcx>(
13321332
fn predicates_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
13331333
def_id: DefId)
13341334
-> ty::GenericPredicates<'tcx> {
1335-
explicit_predicates_of(tcx, def_id)
1335+
let explicit = explicit_predicates_of(tcx, def_id);
1336+
ty::GenericPredicates {
1337+
parent: explicit.parent,
1338+
predicates: [&explicit.predicates[..], &tcx.inferred_outlives_of(def_id)[..]].concat()
1339+
}
13361340
}
13371341

13381342
fn explicit_predicates_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,

src/librustc_typeck/diagnostics.rs

+1
Original file line numberDiff line numberDiff line change
@@ -4676,6 +4676,7 @@ register_diagnostics! {
46764676
E0588, // packed struct cannot transitively contain a `[repr(align)]` struct
46774677
E0592, // duplicate definitions with name `{}`
46784678
// E0613, // Removed (merged with E0609)
4679+
E0640, // infer outlives
46794680
E0627, // yield statement outside of generator literal
46804681
E0632, // cannot provide explicit type parameters when `impl Trait` is used in
46814682
// argument position.

src/librustc_typeck/lib.rs

+9
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ independently:
5050
5151
- variance: variance inference
5252
53+
- outlives: outlives inference
54+
5355
- check: walks over function bodies and type checks them, inferring types for
5456
local variables, type parameters, etc as necessary.
5557
@@ -122,6 +124,7 @@ mod collect;
122124
mod constrained_type_params;
123125
mod impl_wf_check;
124126
mod coherence;
127+
mod outlives;
125128
mod variance;
126129
mod namespace;
127130

@@ -286,6 +289,7 @@ pub fn provide(providers: &mut Providers) {
286289
coherence::provide(providers);
287290
check::provide(providers);
288291
variance::provide(providers);
292+
outlives::provide(providers);
289293
}
290294

291295
pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>)
@@ -301,6 +305,11 @@ pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>)
301305

302306
})?;
303307

308+
tcx.sess.track_errors(|| {
309+
time(time_passes, "outlives testing", ||
310+
outlives::test::test_inferred_outlives(tcx));
311+
})?;
312+
304313
tcx.sess.track_errors(|| {
305314
time(time_passes, "impl wf inference", ||
306315
impl_wf_check::impl_wf_check(tcx));

src/librustc_typeck/outlives/mod.rs

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright 2013 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+
use rustc::hir::def_id::DefId;
12+
use rustc::ty::{self, TyCtxt};
13+
use rustc::ty::maps::Providers;
14+
15+
/// Code to write unit test for outlives.
16+
pub mod test;
17+
18+
pub fn provide(providers: &mut Providers) {
19+
*providers = Providers {
20+
inferred_outlives_of,
21+
..*providers
22+
};
23+
}
24+
25+
//todo
26+
fn inferred_outlives_of<'a, 'tcx>(_tcx: TyCtxt<'a, 'tcx, 'tcx>, _def_id: DefId)
27+
-> Vec<ty::Predicate<'tcx>> {
28+
Vec::new()
29+
}

src/librustc_typeck/outlives/test.rs

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright 2013 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+
use rustc::hir;
12+
use rustc::hir::itemlikevisit::ItemLikeVisitor;
13+
use rustc::ty::TyCtxt;
14+
15+
pub fn test_inferred_outlives<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
16+
tcx.hir.krate().visit_all_item_likes(&mut OutlivesTest { tcx });
17+
}
18+
19+
struct OutlivesTest<'a, 'tcx: 'a> {
20+
tcx: TyCtxt<'a, 'tcx, 'tcx>
21+
}
22+
23+
impl<'a, 'tcx> ItemLikeVisitor<'tcx> for OutlivesTest<'a, 'tcx> {
24+
fn visit_item(&mut self, item: &'tcx hir::Item) {
25+
let item_def_id = self.tcx.hir.local_def_id(item.id);
26+
27+
// For unit testing: check for a special "rustc_outlives"
28+
// attribute and report an error with various results if found.
29+
if self.tcx.has_attr(item_def_id, "rustc_outlives") {
30+
let inferred_outlives_of = self.tcx.inferred_outlives_of(item_def_id);
31+
span_err!(self.tcx.sess,
32+
item.span,
33+
E0640,
34+
"{:?}",
35+
inferred_outlives_of);
36+
}
37+
}
38+
39+
fn visit_trait_item(&mut self, _: &'tcx hir::TraitItem) { }
40+
fn visit_impl_item(&mut self, _: &'tcx hir::ImplItem) { }
41+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2015 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+
// Test that the outlives computation runs for now...
12+
13+
#![feature(rustc_attrs)]
14+
15+
//todo add all the test cases
16+
// https://github.com/rust-lang/rfcs/blob/master/text/2093-infer-outlives.md#example-1-a-reference
17+
18+
#[rustc_outlives]
19+
struct Direct<'a, T> { //~ ERROR 19:1: 21:2: [] [E0640]
20+
field: &'a T
21+
}
22+
23+
fn main() { }

0 commit comments

Comments
 (0)