about summary refs log tree commit diff
diff options
context:
space:
mode:
authorManish Goregaokar <manishsmail@gmail.com>2016-05-14 11:57:48 +0200
committerManish Goregaokar <manishsmail@gmail.com>2016-05-14 11:57:48 +0200
commit8845592514ea229a09dd152d2801363046749fb3 (patch)
tree2d23520cedafa4a24a5836c6b7cbf6c92fff73a9
parent25ca82aa17bb01927bb66a31ec817b0f39509c4d (diff)
parentd3218fae7b5a4a0ba9b02903dc12d36ff94a1388 (diff)
downloadrust-8845592514ea229a09dd152d2801363046749fb3.tar.gz
rust-8845592514ea229a09dd152d2801363046749fb3.zip
Rollup merge of #33572 - nagisa:assoc-const-types, r=eddyb
Support references to outer type params for assoc consts

Fixes #28809

r? @eddyb
-rw-r--r--src/librustc/ty/mod.rs22
-rw-r--r--src/librustc_resolve/lib.rs4
-rw-r--r--src/librustc_typeck/check/mod.rs3
-rw-r--r--src/test/run-pass/associated-const-outer-ty-refs.rs21
4 files changed, 26 insertions, 24 deletions
diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs
index 005d83da38d..114e81721ab 100644
--- a/src/librustc/ty/mod.rs
+++ b/src/librustc/ty/mod.rs
@@ -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
diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs
index 9cec3a51794..a1a966ea65a 100644
--- a/src/librustc_resolve/lib.rs
+++ b/src/librustc_resolve/lib.rs
@@ -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
diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs
index 6dfad749982..8f9e44c1365 100644
--- a/src/librustc_typeck/check/mod.rs
+++ b/src/librustc_typeck/check/mod.rs
@@ -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;
diff --git a/src/test/run-pass/associated-const-outer-ty-refs.rs b/src/test/run-pass/associated-const-outer-ty-refs.rs
new file mode 100644
index 00000000000..a603b225132
--- /dev/null
+++ b/src/test/run-pass/associated-const-outer-ty-refs.rs
@@ -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(){}