Skip to content

Commit 5ac6aae

Browse files
committed
---
yaml --- r: 232363 b: refs/heads/try c: ad47bd8 h: refs/heads/master i: 232361: 2305bbf 232359: 0f038a1 v: v3
1 parent 326deee commit 5ac6aae

File tree

3 files changed

+68
-38
lines changed

3 files changed

+68
-38
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: edeb4f1c86cbf6af8ef9874d4b3af50f721ea1b8
33
refs/heads/snap-stage3: 1af31d4974e33027a68126fa5a5a3c2c6491824f
4-
refs/heads/try: b1963154a10fd22d16a5eddd751046cc897e909c
4+
refs/heads/try: ad47bd8a0f6f5284a8f937f5cd8a0a7e3df96991
55
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
66
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
77
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try/src/librustc/middle/ty.rs

Lines changed: 66 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2833,6 +2833,15 @@ pub struct ParameterEnvironment<'a, 'tcx:'a> {
28332833
/// Caches the results of trait selection. This cache is used
28342834
/// for things that have to do with the parameters in scope.
28352835
pub selection_cache: traits::SelectionCache<'tcx>,
2836+
2837+
/// Scope that is attached to free regions for this scope. This
2838+
/// is usually the id of the fn body, but for more abstract scopes
2839+
/// like structs we often use the node-id of the struct.
2840+
///
2841+
/// FIXME(#3696). It would be nice to refactor so that free
2842+
/// regions don't have this implicit scope and instead introduce
2843+
/// relationships in the environment.
2844+
pub free_id: ast::NodeId,
28362845
}
28372846

28382847
impl<'a, 'tcx> ParameterEnvironment<'a, 'tcx> {
@@ -2846,13 +2855,26 @@ impl<'a, 'tcx> ParameterEnvironment<'a, 'tcx> {
28462855
implicit_region_bound: self.implicit_region_bound,
28472856
caller_bounds: caller_bounds,
28482857
selection_cache: traits::SelectionCache::new(),
2858+
free_id: self.free_id,
28492859
}
28502860
}
28512861

28522862
pub fn for_item(cx: &'a ctxt<'tcx>, id: NodeId) -> ParameterEnvironment<'a, 'tcx> {
28532863
match cx.map.find(id) {
28542864
Some(ast_map::NodeImplItem(ref impl_item)) => {
28552865
match impl_item.node {
2866+
ast::TypeImplItem(_) => {
2867+
// associated types don't have their own entry (for some reason),
2868+
// so for now just grab environment for the impl
2869+
let impl_id = cx.map.get_parent(id);
2870+
let impl_def_id = ast_util::local_def(impl_id);
2871+
let scheme = cx.lookup_item_type(impl_def_id);
2872+
let predicates = cx.lookup_predicates(impl_def_id);
2873+
cx.construct_parameter_environment(impl_item.span,
2874+
&scheme.generics,
2875+
&predicates,
2876+
id)
2877+
}
28562878
ast::ConstImplItem(_, _) => {
28572879
let def_id = ast_util::local_def(id);
28582880
let scheme = cx.lookup_item_type(def_id);
@@ -2881,42 +2903,37 @@ impl<'a, 'tcx> ParameterEnvironment<'a, 'tcx> {
28812903
}
28822904
}
28832905
}
2884-
ast::TypeImplItem(_) => {
2885-
cx.sess.bug("ParameterEnvironment::for_item(): \
2886-
can't create a parameter environment \
2887-
for type impl items")
2888-
}
28892906
ast::MacImplItem(_) => cx.sess.bug("unexpanded macro")
28902907
}
28912908
}
28922909
Some(ast_map::NodeTraitItem(trait_item)) => {
28932910
match trait_item.node {
2894-
ast::ConstTraitItem(_, ref default) => {
2895-
match *default {
2896-
Some(_) => {
2897-
let def_id = ast_util::local_def(id);
2898-
let scheme = cx.lookup_item_type(def_id);
2899-
let predicates = cx.lookup_predicates(def_id);
2900-
cx.construct_parameter_environment(trait_item.span,
2901-
&scheme.generics,
2902-
&predicates,
2903-
id)
2904-
}
2905-
None => {
2906-
cx.sess.bug("ParameterEnvironment::from_item(): \
2907-
can't create a parameter environment \
2908-
for const trait items without defaults")
2909-
}
2910-
}
2911+
ast::TypeTraitItem(..) => {
2912+
// associated types don't have their own entry (for some reason),
2913+
// so for now just grab environment for the trait
2914+
let trait_id = cx.map.get_parent(id);
2915+
let trait_def_id = ast_util::local_def(trait_id);
2916+
let trait_def = cx.lookup_trait_def(trait_def_id);
2917+
let predicates = cx.lookup_predicates(trait_def_id);
2918+
cx.construct_parameter_environment(trait_item.span,
2919+
&trait_def.generics,
2920+
&predicates,
2921+
id)
29112922
}
2912-
ast::MethodTraitItem(_, None) => {
2913-
cx.sess.span_bug(trait_item.span,
2914-
"ParameterEnvironment::for_item():
2915-
can't create a parameter \
2916-
environment for required trait \
2917-
methods")
2923+
ast::ConstTraitItem(..) => {
2924+
let def_id = ast_util::local_def(id);
2925+
let scheme = cx.lookup_item_type(def_id);
2926+
let predicates = cx.lookup_predicates(def_id);
2927+
cx.construct_parameter_environment(trait_item.span,
2928+
&scheme.generics,
2929+
&predicates,
2930+
id)
29182931
}
2919-
ast::MethodTraitItem(_, Some(ref body)) => {
2932+
ast::MethodTraitItem(_, ref body) => {
2933+
// for the body-id, use the id of the body
2934+
// block, unless this is a trait method with
2935+
// no default, then fallback to the method id.
2936+
let body_id = body.as_ref().map(|b| b.id).unwrap_or(id);
29202937
let method_def_id = ast_util::local_def(id);
29212938
match cx.impl_or_trait_item(method_def_id) {
29222939
MethodTraitItem(ref method_ty) => {
@@ -2926,7 +2943,7 @@ impl<'a, 'tcx> ParameterEnvironment<'a, 'tcx> {
29262943
trait_item.span,
29272944
method_generics,
29282945
method_bounds,
2929-
body.id)
2946+
body_id)
29302947
}
29312948
_ => {
29322949
cx.sess
@@ -2936,11 +2953,6 @@ impl<'a, 'tcx> ParameterEnvironment<'a, 'tcx> {
29362953
}
29372954
}
29382955
}
2939-
ast::TypeTraitItem(..) => {
2940-
cx.sess.bug("ParameterEnvironment::from_item(): \
2941-
can't create a parameter environment \
2942-
for type trait items")
2943-
}
29442956
}
29452957
}
29462958
Some(ast_map::NodeItem(item)) => {
@@ -2969,6 +2981,15 @@ impl<'a, 'tcx> ParameterEnvironment<'a, 'tcx> {
29692981
&predicates,
29702982
id)
29712983
}
2984+
ast::ItemTrait(..) => {
2985+
let def_id = ast_util::local_def(id);
2986+
let trait_def = cx.lookup_trait_def(def_id);
2987+
let predicates = cx.lookup_predicates(def_id);
2988+
cx.construct_parameter_environment(item.span,
2989+
&trait_def.generics,
2990+
&predicates,
2991+
id)
2992+
}
29722993
_ => {
29732994
cx.sess.span_bug(item.span,
29742995
"ParameterEnvironment::from_item():
@@ -6587,12 +6608,19 @@ impl<'tcx> ctxt<'tcx> {
65876608

65886609
/// Construct a parameter environment suitable for static contexts or other contexts where there
65896610
/// are no free type/lifetime parameters in scope.
6590-
pub fn empty_parameter_environment<'a>(&'a self) -> ParameterEnvironment<'a,'tcx> {
6611+
pub fn empty_parameter_environment<'a>(&'a self)
6612+
-> ParameterEnvironment<'a,'tcx> {
65916613
ty::ParameterEnvironment { tcx: self,
65926614
free_substs: Substs::empty(),
65936615
caller_bounds: Vec::new(),
65946616
implicit_region_bound: ty::ReEmpty,
6595-
selection_cache: traits::SelectionCache::new(), }
6617+
selection_cache: traits::SelectionCache::new(),
6618+
6619+
// for an empty parameter
6620+
// environment, there ARE no free
6621+
// regions, so it shouldn't matter
6622+
// what we use for the free id
6623+
free_id: ast::DUMMY_NODE_ID }
65966624
}
65976625

65986626
/// Constructs and returns a substitution that can be applied to move from
@@ -6676,6 +6704,7 @@ impl<'tcx> ctxt<'tcx> {
66766704
implicit_region_bound: ty::ReScope(free_id_outlive.to_code_extent()),
66776705
caller_bounds: predicates,
66786706
selection_cache: traits::SelectionCache::new(),
6707+
free_id: free_id,
66796708
};
66806709

66816710
let cause = traits::ObligationCause::misc(span, free_id);

branches/try/src/librustc/middle/ty_fold.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,7 @@ impl<'a, 'tcx> TypeFoldable<'tcx> for ty::ParameterEnvironment<'a, 'tcx> where '
547547
implicit_region_bound: self.implicit_region_bound.fold_with(folder),
548548
caller_bounds: self.caller_bounds.fold_with(folder),
549549
selection_cache: traits::SelectionCache::new(),
550+
free_id: self.free_id,
550551
}
551552
}
552553
}

0 commit comments

Comments
 (0)