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
This commit is contained in:
commit
5618aba380
@ -476,6 +476,7 @@ define_dep_nodes!( <'tcx>
|
||||
[] TypeOfItem(DefId),
|
||||
[] GenericsOfItem(DefId),
|
||||
[] PredicatesOfItem(DefId),
|
||||
[] InferredOutlivesOf(DefId),
|
||||
[] SuperPredicatesOfItem(DefId),
|
||||
[] TraitDefOfItem(DefId),
|
||||
[] AdtDefOfItem(DefId),
|
||||
|
@ -121,6 +121,9 @@ define_maps! { <'tcx>
|
||||
/// (inferred) variance.
|
||||
[] fn variances_of: ItemVariances(DefId) -> Rc<Vec<ty::Variance>>,
|
||||
|
||||
/// Maps from def-id of a type to its (inferred) outlives.
|
||||
[] fn inferred_outlives_of: InferredOutlivesOf(DefId) -> Vec<ty::Predicate<'tcx>>,
|
||||
|
||||
/// Maps from an impl/trait def-id to a list of the def-ids of its items
|
||||
[] fn associated_item_def_ids: AssociatedItemDefIds(DefId) -> Rc<Vec<DefId>>,
|
||||
|
||||
|
@ -736,6 +736,7 @@ pub fn force_from_dep_node<'a, 'gcx, 'lcx>(tcx: TyCtxt<'a, 'gcx, 'lcx>,
|
||||
DepKind::TypeOfItem => { force!(type_of, def_id!()); }
|
||||
DepKind::GenericsOfItem => { force!(generics_of, def_id!()); }
|
||||
DepKind::PredicatesOfItem => { force!(predicates_of, def_id!()); }
|
||||
DepKind::InferredOutlivesOf => { force!(inferred_outlives_of, def_id!()); }
|
||||
DepKind::SuperPredicatesOfItem => { force!(super_predicates_of, def_id!()); }
|
||||
DepKind::TraitDefOfItem => { force!(trait_def, def_id!()); }
|
||||
DepKind::AdtDefOfItem => { force!(adt_def, def_id!()); }
|
||||
|
@ -1332,7 +1332,11 @@ fn early_bound_lifetimes_from_generics<'a, 'tcx>(
|
||||
fn predicates_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
def_id: DefId)
|
||||
-> ty::GenericPredicates<'tcx> {
|
||||
explicit_predicates_of(tcx, def_id)
|
||||
let explicit = explicit_predicates_of(tcx, def_id);
|
||||
ty::GenericPredicates {
|
||||
parent: explicit.parent,
|
||||
predicates: [&explicit.predicates[..], &tcx.inferred_outlives_of(def_id)[..]].concat()
|
||||
}
|
||||
}
|
||||
|
||||
fn explicit_predicates_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
|
@ -4676,6 +4676,7 @@ register_diagnostics! {
|
||||
E0588, // packed struct cannot transitively contain a `[repr(align)]` struct
|
||||
E0592, // duplicate definitions with name `{}`
|
||||
// E0613, // Removed (merged with E0609)
|
||||
E0640, // infer outlives
|
||||
E0627, // yield statement outside of generator literal
|
||||
E0632, // cannot provide explicit type parameters when `impl Trait` is used in
|
||||
// argument position.
|
||||
|
@ -50,6 +50,8 @@ independently:
|
||||
|
||||
- variance: variance inference
|
||||
|
||||
- outlives: outlives inference
|
||||
|
||||
- check: walks over function bodies and type checks them, inferring types for
|
||||
local variables, type parameters, etc as necessary.
|
||||
|
||||
@ -122,6 +124,7 @@ mod collect;
|
||||
mod constrained_type_params;
|
||||
mod impl_wf_check;
|
||||
mod coherence;
|
||||
mod outlives;
|
||||
mod variance;
|
||||
mod namespace;
|
||||
|
||||
@ -286,6 +289,7 @@ pub fn provide(providers: &mut Providers) {
|
||||
coherence::provide(providers);
|
||||
check::provide(providers);
|
||||
variance::provide(providers);
|
||||
outlives::provide(providers);
|
||||
}
|
||||
|
||||
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>)
|
||||
|
||||
})?;
|
||||
|
||||
tcx.sess.track_errors(|| {
|
||||
time(time_passes, "outlives testing", ||
|
||||
outlives::test::test_inferred_outlives(tcx));
|
||||
})?;
|
||||
|
||||
tcx.sess.track_errors(|| {
|
||||
time(time_passes, "impl wf inference", ||
|
||||
impl_wf_check::impl_wf_check(tcx));
|
||||
|
29
src/librustc_typeck/outlives/mod.rs
Normal file
29
src/librustc_typeck/outlives/mod.rs
Normal file
@ -0,0 +1,29 @@
|
||||
// Copyright 2013 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.
|
||||
|
||||
use rustc::hir::def_id::DefId;
|
||||
use rustc::ty::{self, TyCtxt};
|
||||
use rustc::ty::maps::Providers;
|
||||
|
||||
/// Code to write unit test for outlives.
|
||||
pub mod test;
|
||||
|
||||
pub fn provide(providers: &mut Providers) {
|
||||
*providers = Providers {
|
||||
inferred_outlives_of,
|
||||
..*providers
|
||||
};
|
||||
}
|
||||
|
||||
//todo
|
||||
fn inferred_outlives_of<'a, 'tcx>(_tcx: TyCtxt<'a, 'tcx, 'tcx>, _def_id: DefId)
|
||||
-> Vec<ty::Predicate<'tcx>> {
|
||||
Vec::new()
|
||||
}
|
41
src/librustc_typeck/outlives/test.rs
Normal file
41
src/librustc_typeck/outlives/test.rs
Normal file
@ -0,0 +1,41 @@
|
||||
// Copyright 2013 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.
|
||||
|
||||
use rustc::hir;
|
||||
use rustc::hir::itemlikevisit::ItemLikeVisitor;
|
||||
use rustc::ty::TyCtxt;
|
||||
|
||||
pub fn test_inferred_outlives<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
|
||||
tcx.hir.krate().visit_all_item_likes(&mut OutlivesTest { tcx });
|
||||
}
|
||||
|
||||
struct OutlivesTest<'a, 'tcx: 'a> {
|
||||
tcx: TyCtxt<'a, 'tcx, 'tcx>
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> ItemLikeVisitor<'tcx> for OutlivesTest<'a, 'tcx> {
|
||||
fn visit_item(&mut self, item: &'tcx hir::Item) {
|
||||
let item_def_id = self.tcx.hir.local_def_id(item.id);
|
||||
|
||||
// For unit testing: check for a special "rustc_outlives"
|
||||
// attribute and report an error with various results if found.
|
||||
if self.tcx.has_attr(item_def_id, "rustc_outlives") {
|
||||
let inferred_outlives_of = self.tcx.inferred_outlives_of(item_def_id);
|
||||
span_err!(self.tcx.sess,
|
||||
item.span,
|
||||
E0640,
|
||||
"{:?}",
|
||||
inferred_outlives_of);
|
||||
}
|
||||
}
|
||||
|
||||
fn visit_trait_item(&mut self, _: &'tcx hir::TraitItem) { }
|
||||
fn visit_impl_item(&mut self, _: &'tcx hir::ImplItem) { }
|
||||
}
|
23
src/test/compile-fail/outlives-associated-types.rs
Normal file
23
src/test/compile-fail/outlives-associated-types.rs
Normal file
@ -0,0 +1,23 @@
|
||||
// Copyright 2015 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.
|
||||
|
||||
// Test that the outlives computation runs for now...
|
||||
|
||||
#![feature(rustc_attrs)]
|
||||
|
||||
//todo add all the test cases
|
||||
// https://github.com/rust-lang/rfcs/blob/master/text/2093-infer-outlives.md#example-1-a-reference
|
||||
|
||||
#[rustc_outlives]
|
||||
struct Direct<'a, T> { //~ ERROR 19:1: 21:2: [] [E0640]
|
||||
field: &'a T
|
||||
}
|
||||
|
||||
fn main() { }
|
Loading…
x
Reference in New Issue
Block a user