Rollup merge of #33572 - nagisa:assoc-const-types, r=eddyb

Support references to outer type params for assoc consts

Fixes #28809

r? @eddyb
This commit is contained in:
Manish Goregaokar 2016-05-14 11:57:48 +02:00
commit 8845592514
4 changed files with 26 additions and 24 deletions

View file

@ -1260,7 +1260,7 @@ impl<'a, 'tcx> ParameterEnvironment<'tcx> {
match tcx.map.find(id) {
Some(ast_map::NodeImplItem(ref impl_item)) => {
match impl_item.node {
hir::ImplItemKind::Type(_) => {
hir::ImplItemKind::Type(_) | hir::ImplItemKind::Const(_, _) => {
// associated types don't have their own entry (for some reason),
// so for now just grab environment for the impl
let impl_id = tcx.map.get_parent(id);
@ -1272,15 +1272,6 @@ impl<'a, 'tcx> ParameterEnvironment<'tcx> {
&predicates,
tcx.region_maps.item_extent(id))
}
hir::ImplItemKind::Const(_, _) => {
let def_id = tcx.map.local_def_id(id);
let scheme = tcx.lookup_item_type(def_id);
let predicates = tcx.lookup_predicates(def_id);
tcx.construct_parameter_environment(impl_item.span,
&scheme.generics,
&predicates,
tcx.region_maps.item_extent(id))
}
hir::ImplItemKind::Method(_, ref body) => {
let method_def_id = tcx.map.local_def_id(id);
match tcx.impl_or_trait_item(method_def_id) {
@ -1303,7 +1294,7 @@ impl<'a, 'tcx> ParameterEnvironment<'tcx> {
}
Some(ast_map::NodeTraitItem(trait_item)) => {
match trait_item.node {
hir::TypeTraitItem(..) => {
hir::TypeTraitItem(..) | hir::ConstTraitItem(..) => {
// associated types don't have their own entry (for some reason),
// so for now just grab environment for the trait
let trait_id = tcx.map.get_parent(id);
@ -1315,15 +1306,6 @@ impl<'a, 'tcx> ParameterEnvironment<'tcx> {
&predicates,
tcx.region_maps.item_extent(id))
}
hir::ConstTraitItem(..) => {
let def_id = tcx.map.local_def_id(id);
let scheme = tcx.lookup_item_type(def_id);
let predicates = tcx.lookup_predicates(def_id);
tcx.construct_parameter_environment(trait_item.span,
&scheme.generics,
&predicates,
tcx.region_maps.item_extent(id))
}
hir::MethodTraitItem(_, ref body) => {
// Use call-site for extent (unless this is a
// trait method with no default; then fallback

View file

@ -1949,9 +1949,7 @@ impl<'a> Resolver<'a> {
this.check_trait_item(impl_item.ident.name,
impl_item.span,
|n, s| ResolutionError::ConstNotMemberOfTrait(n, s));
this.with_constant_rib(|this| {
visit::walk_impl_item(this, impl_item);
});
visit::walk_impl_item(this, impl_item);
}
ImplItemKind::Method(ref sig, _) => {
// If this is a trait impl, ensure the method

View file

@ -1153,7 +1153,8 @@ fn check_const<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>,
sp: Span,
e: &'tcx hir::Expr,
id: ast::NodeId) {
ccx.inherited(None).enter(|inh| {
let param_env = ParameterEnvironment::for_item(ccx.tcx, id);
ccx.inherited(Some(param_env)).enter(|inh| {
let rty = ccx.tcx.node_id_to_type(id);
let fcx = FnCtxt::new(&inh, ty::FnConverging(rty), e.id);
let declty = fcx.tcx.lookup_item_type(ccx.tcx.map.local_def_id(id)).ty;

View file

@ -0,0 +1,21 @@
// Copyright 2016 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.
#![feature(associated_consts)]
trait Lattice {
const BOTTOM: Self;
}
// FIXME(#33573): this should work without the 'static lifetime bound.
impl<T: 'static> Lattice for Option<T> {
const BOTTOM: Option<T> = None;
}
fn main(){}