Skip to content

Commit

Permalink
Rollup merge of rust-lang#33572 - nagisa:assoc-const-types, r=eddyb
Browse files Browse the repository at this point in the history
Support references to outer type params for assoc consts

Fixes rust-lang#28809

r? @eddyb
  • Loading branch information
eddyb committed May 12, 2016
2 parents b4a9ebe + d3218fa commit 5f43767
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 24 deletions.
22 changes: 2 additions & 20 deletions src/librustc/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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) {
Expand All @@ -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);
Expand All @@ -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
Expand Down
4 changes: 1 addition & 3 deletions src/librustc_resolve/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/librustc_typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1151,7 +1151,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;
Expand Down
21 changes: 21 additions & 0 deletions src/test/run-pass/associated-const-outer-ty-refs.rs
Original file line number Diff line number Diff line change
@@ -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(){}

0 comments on commit 5f43767

Please sign in to comment.