Skip to content

Commit 9146a91

Browse files
committed
auto merge of #19391 : nick29581/rust/assoc-eq, r=nikomatsakis
r? @nikomatsakis cc @aturon (I think you were interested in this for some library stuff) closes #18432
2 parents a592124 + ce4318a commit 9146a91

37 files changed

+868
-262
lines changed

src/librustc/diagnostics.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -148,5 +148,9 @@ register_diagnostics!(
148148
E0169,
149149
E0170,
150150
E0171,
151-
E0172
151+
E0172,
152+
E0173,
153+
E0174,
154+
E0177,
155+
E0178
152156
)

src/librustc/metadata/decoder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ pub fn get_symbol(data: &[u8], id: ast::NodeId) -> String {
435435
}
436436

437437
// Something that a name can resolve to.
438-
#[deriving(Clone)]
438+
#[deriving(Clone,Show)]
439439
pub enum DefLike {
440440
DlDef(def::Def),
441441
DlImpl(ast::DefId),

src/librustc/middle/infer/error_reporting.rs

+14-2
Original file line numberDiff line numberDiff line change
@@ -1405,10 +1405,22 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> {
14051405
let new_types = data.types.map(|t| {
14061406
self.rebuild_arg_ty_or_output(&**t, lifetime, anon_nums, region_names)
14071407
});
1408+
let new_bindings = data.bindings.map(|b| {
1409+
P(ast::TypeBinding {
1410+
id: b.id,
1411+
ident: b.ident,
1412+
ty: self.rebuild_arg_ty_or_output(&*b.ty,
1413+
lifetime,
1414+
anon_nums,
1415+
region_names),
1416+
span: b.span
1417+
})
1418+
});
14081419
ast::AngleBracketedParameters(ast::AngleBracketedParameterData {
14091420
lifetimes: new_lts,
1410-
types: new_types
1411-
})
1421+
types: new_types,
1422+
bindings: new_bindings,
1423+
})
14121424
}
14131425
};
14141426
let new_seg = ast::PathSegment {

src/librustc/middle/privacy.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -1453,8 +1453,15 @@ impl<'a, 'tcx, 'v> Visitor<'v> for VisiblePrivateTypesVisitor<'a, 'tcx> {
14531453
}
14541454
}
14551455
for predicate in generics.where_clause.predicates.iter() {
1456-
for bound in predicate.bounds.iter() {
1457-
self.check_ty_param_bound(predicate.span, bound)
1456+
match predicate {
1457+
&ast::WherePredicate::BoundPredicate(ref bound_pred) => {
1458+
for bound in bound_pred.bounds.iter() {
1459+
self.check_ty_param_bound(bound_pred.span, bound)
1460+
}
1461+
}
1462+
&ast::WherePredicate::EqPredicate(ref eq_pred) => {
1463+
self.visit_ty(&*eq_pred.ty);
1464+
}
14581465
}
14591466
}
14601467
}

src/librustc/middle/resolve.rs

+80-56
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ pub type ExportMap2 = NodeMap<Vec<Export2>>;
108108

109109
pub struct Export2 {
110110
pub name: String, // The name of the target.
111-
pub def_id: DefId, // The definition of the target.
111+
pub def_id: DefId, // The definition of the target.
112112
}
113113

114114
// This set contains all exported definitions from external crates. The set does
@@ -314,7 +314,7 @@ impl<'a> Copy for TypeParameters<'a> {}
314314

315315
// The rib kind controls the translation of local
316316
// definitions (`DefLocal`) to upvars (`DefUpvar`).
317-
317+
#[deriving(Show)]
318318
enum RibKind {
319319
// No translation needs to be applied.
320320
NormalRibKind,
@@ -340,6 +340,7 @@ enum RibKind {
340340
impl Copy for RibKind {}
341341

342342
// Methods can be required or provided. RequiredMethod methods only occur in traits.
343+
#[deriving(Show)]
343344
enum MethodSort {
344345
RequiredMethod,
345346
ProvidedMethod(NodeId)
@@ -414,6 +415,7 @@ enum DuplicateCheckingMode {
414415
impl Copy for DuplicateCheckingMode {}
415416

416417
/// One local scope.
418+
#[deriving(Show)]
417419
struct Rib {
418420
bindings: HashMap<Name, DefLike>,
419421
kind: RibKind,
@@ -728,8 +730,11 @@ impl NameBindings {
728730
let type_def = self.type_def.borrow().clone();
729731
match type_def {
730732
None => {
731-
let module = Module::new(parent_link, def_id, kind,
732-
external, is_public);
733+
let module = Module::new(parent_link,
734+
def_id,
735+
kind,
736+
external,
737+
is_public);
733738
*self.type_def.borrow_mut() = Some(TypeNsDef {
734739
modifiers: modifiers,
735740
module_def: Some(Rc::new(module)),
@@ -774,9 +779,9 @@ impl NameBindings {
774779
}
775780
Some(type_def) => {
776781
*self.type_def.borrow_mut() = Some(TypeNsDef {
782+
module_def: type_def.module_def,
777783
type_def: Some(def),
778784
type_span: Some(sp),
779-
module_def: type_def.module_def,
780785
modifiers: modifiers,
781786
});
782787
}
@@ -1286,7 +1291,7 @@ impl<'a> Resolver<'a> {
12861291
}
12871292

12881293
fn get_parent_link(&mut self, parent: ReducedGraphParent, name: Name)
1289-
-> ParentLink {
1294+
-> ParentLink {
12901295
match parent {
12911296
ModuleReducedGraphParent(module_) => {
12921297
return ModuleParentLink(module_.downgrade(), name);
@@ -1578,14 +1583,14 @@ impl<'a> Resolver<'a> {
15781583

15791584
ItemImpl(_, Some(_), _, _) => parent,
15801585

1581-
ItemTrait(_, _, _, ref methods) => {
1586+
ItemTrait(_, _, _, ref items) => {
15821587
let name_bindings =
15831588
self.add_child(name,
15841589
parent.clone(),
15851590
ForbidDuplicateTypesAndModules,
15861591
sp);
15871592

1588-
// Add all the methods within to a new module.
1593+
// Add all the items within to a new module.
15891594
let parent_link = self.get_parent_link(parent.clone(), name);
15901595
name_bindings.define_module(parent_link,
15911596
Some(local_def(item.id)),
@@ -1598,13 +1603,12 @@ impl<'a> Resolver<'a> {
15981603

15991604
let def_id = local_def(item.id);
16001605

1601-
// Add the names of all the methods to the trait info.
1602-
for method in methods.iter() {
1603-
let (name, kind) = match *method {
1606+
// Add the names of all the items to the trait info.
1607+
for trait_item in items.iter() {
1608+
let (name, kind) = match *trait_item {
16041609
ast::RequiredMethod(_) |
16051610
ast::ProvidedMethod(_) => {
1606-
let ty_m =
1607-
ast_util::trait_item_to_ty_method(method);
1611+
let ty_m = ast_util::trait_item_to_ty_method(trait_item);
16081612

16091613
let name = ty_m.ident.name;
16101614

@@ -3353,7 +3357,7 @@ impl<'a> Resolver<'a> {
33533357
use_lexical_scope: UseLexicalScopeFlag,
33543358
span: Span,
33553359
name_search_type: NameSearchType)
3356-
-> ResolveResult<(Rc<Module>, LastPrivate)> {
3360+
-> ResolveResult<(Rc<Module>, LastPrivate)> {
33573361
let module_path_len = module_path.len();
33583362
assert!(module_path_len > 0);
33593363

@@ -3382,7 +3386,9 @@ impl<'a> Resolver<'a> {
33823386
mpath.slice_to(idx - 1));
33833387
return Failed(Some((span, msg)));
33843388
},
3385-
None => return Failed(None),
3389+
None => {
3390+
return Failed(None)
3391+
}
33863392
}
33873393
}
33883394
Failed(err) => return Failed(err),
@@ -3407,9 +3413,8 @@ impl<'a> Resolver<'a> {
34073413
// This is not a crate-relative path. We resolve the
34083414
// first component of the path in the current lexical
34093415
// scope and then proceed to resolve below that.
3410-
match self.resolve_module_in_lexical_scope(
3411-
module_,
3412-
module_path[0]) {
3416+
match self.resolve_module_in_lexical_scope(module_,
3417+
module_path[0]) {
34133418
Failed(err) => return Failed(err),
34143419
Indeterminate => {
34153420
debug!("(resolving module path for import) \
@@ -3576,8 +3581,7 @@ impl<'a> Resolver<'a> {
35763581
-> ResolveResult<Rc<Module>> {
35773582
// If this module is an anonymous module, resolve the item in the
35783583
// lexical scope. Otherwise, resolve the item from the crate root.
3579-
let resolve_result = self.resolve_item_in_lexical_scope(
3580-
module_, name, TypeNS);
3584+
let resolve_result = self.resolve_item_in_lexical_scope(module_, name, TypeNS);
35813585
match resolve_result {
35823586
Success((target, _)) => {
35833587
let bindings = &*target.bindings;
@@ -4590,25 +4594,42 @@ impl<'a> Resolver<'a> {
45904594

45914595
fn resolve_where_clause(&mut self, where_clause: &ast::WhereClause) {
45924596
for predicate in where_clause.predicates.iter() {
4593-
match self.resolve_identifier(predicate.ident,
4594-
TypeNS,
4595-
true,
4596-
predicate.span) {
4597-
Some((def @ DefTyParam(_, _, _), last_private)) => {
4598-
self.record_def(predicate.id, (def, last_private));
4599-
}
4600-
_ => {
4601-
self.resolve_error(
4602-
predicate.span,
4603-
format!("undeclared type parameter `{}`",
4604-
token::get_ident(
4605-
predicate.ident)).as_slice());
4597+
match predicate {
4598+
&ast::WherePredicate::BoundPredicate(ref bound_pred) => {
4599+
match self.resolve_identifier(bound_pred.ident,
4600+
TypeNS,
4601+
true,
4602+
bound_pred.span) {
4603+
Some((def @ DefTyParam(..), last_private)) => {
4604+
self.record_def(bound_pred.id, (def, last_private));
4605+
}
4606+
_ => {
4607+
self.resolve_error(
4608+
bound_pred.span,
4609+
format!("undeclared type parameter `{}`",
4610+
token::get_ident(
4611+
bound_pred.ident)).as_slice());
4612+
}
4613+
}
4614+
4615+
for bound in bound_pred.bounds.iter() {
4616+
self.resolve_type_parameter_bound(bound_pred.id, bound,
4617+
TraitBoundingTypeParameter);
4618+
}
46064619
}
4607-
}
4620+
&ast::WherePredicate::EqPredicate(ref eq_pred) => {
4621+
match self.resolve_path(eq_pred.id, &eq_pred.path, TypeNS, true) {
4622+
Some((def @ DefTyParam(..), last_private)) => {
4623+
self.record_def(eq_pred.id, (def, last_private));
4624+
}
4625+
_ => {
4626+
self.resolve_error(eq_pred.path.span,
4627+
"undeclared associated type");
4628+
}
4629+
}
46084630

4609-
for bound in predicate.bounds.iter() {
4610-
self.resolve_type_parameter_bound(predicate.id, bound,
4611-
TraitBoundingTypeParameter);
4631+
self.resolve_type(&*eq_pred.ty);
4632+
}
46124633
}
46134634
}
46144635
}
@@ -5269,15 +5290,19 @@ impl<'a> Resolver<'a> {
52695290
path: &Path,
52705291
namespace: Namespace,
52715292
check_ribs: bool) -> Option<(Def, LastPrivate)> {
5272-
// First, resolve the types.
5293+
// First, resolve the types and associated type bindings.
52735294
for ty in path.segments.iter().flat_map(|s| s.parameters.types().into_iter()) {
52745295
self.resolve_type(&**ty);
52755296
}
5297+
for binding in path.segments.iter().flat_map(|s| s.parameters.bindings().into_iter()) {
5298+
self.resolve_type(&*binding.ty);
5299+
}
52765300

52775301
if path.global {
52785302
return self.resolve_crate_relative_path(path, namespace);
52795303
}
52805304

5305+
// Try to find a path to an item in a module.
52815306
let unqualified_def =
52825307
self.resolve_identifier(path.segments
52835308
.last().unwrap()
@@ -5307,15 +5332,15 @@ impl<'a> Resolver<'a> {
53075332

53085333
// resolve a single identifier (used as a varref)
53095334
fn resolve_identifier(&mut self,
5310-
identifier: Ident,
5311-
namespace: Namespace,
5312-
check_ribs: bool,
5313-
span: Span)
5314-
-> Option<(Def, LastPrivate)> {
5335+
identifier: Ident,
5336+
namespace: Namespace,
5337+
check_ribs: bool,
5338+
span: Span)
5339+
-> Option<(Def, LastPrivate)> {
53155340
if check_ribs {
53165341
match self.resolve_identifier_in_local_ribs(identifier,
5317-
namespace,
5318-
span) {
5342+
namespace,
5343+
span) {
53195344
Some(def) => {
53205345
return Some((def, LastMod(AllPublic)));
53215346
}
@@ -5333,7 +5358,7 @@ impl<'a> Resolver<'a> {
53335358
containing_module: Rc<Module>,
53345359
name: Name,
53355360
namespace: Namespace)
5336-
-> NameDefinition {
5361+
-> NameDefinition {
53375362
// First, search children.
53385363
self.populate_module_if_necessary(&containing_module);
53395364

@@ -5403,9 +5428,9 @@ impl<'a> Resolver<'a> {
54035428

54045429
// resolve a "module-relative" path, e.g. a::b::c
54055430
fn resolve_module_relative_path(&mut self,
5406-
path: &Path,
5407-
namespace: Namespace)
5408-
-> Option<(Def, LastPrivate)> {
5431+
path: &Path,
5432+
namespace: Namespace)
5433+
-> Option<(Def, LastPrivate)> {
54095434
let module_path = path.segments.init().iter()
54105435
.map(|ps| ps.identifier.name)
54115436
.collect::<Vec<_>>();
@@ -5422,9 +5447,8 @@ impl<'a> Resolver<'a> {
54225447
let (span, msg) = match err {
54235448
Some((span, msg)) => (span, msg),
54245449
None => {
5425-
let msg = format!("Use of undeclared module `{}`",
5426-
self.names_to_string(
5427-
module_path.as_slice()));
5450+
let msg = format!("Use of undeclared type or module `{}`",
5451+
self.names_to_string(module_path.as_slice()));
54285452
(path.span, msg)
54295453
}
54305454
};
@@ -5518,10 +5542,10 @@ impl<'a> Resolver<'a> {
55185542
}
55195543

55205544
fn resolve_identifier_in_local_ribs(&mut self,
5521-
ident: Ident,
5522-
namespace: Namespace,
5523-
span: Span)
5524-
-> Option<Def> {
5545+
ident: Ident,
5546+
namespace: Namespace,
5547+
span: Span)
5548+
-> Option<Def> {
55255549
// Check the local set of ribs.
55265550
let search_result = match namespace {
55275551
ValueNS => {

src/librustc/middle/resolve_lifetime.rs

+22-3
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,22 @@ impl<'a, 'v> Visitor<'v> for LifetimeContext<'a> {
210210
}
211211
}
212212
for predicate in generics.where_clause.predicates.iter() {
213-
self.visit_ident(predicate.span, predicate.ident);
214-
visit::walk_ty_param_bounds_helper(self, &predicate.bounds);
213+
match predicate {
214+
&ast::WherePredicate::BoundPredicate(ast::WhereBoundPredicate{ ident,
215+
ref bounds,
216+
span,
217+
.. }) => {
218+
self.visit_ident(span, ident);
219+
visit::walk_ty_param_bounds_helper(self, bounds);
220+
}
221+
&ast::WherePredicate::EqPredicate(ast::WhereEqPredicate{ id,
222+
ref path,
223+
ref ty,
224+
.. }) => {
225+
self.visit_path(path, id);
226+
self.visit_ty(&**ty);
227+
}
228+
}
215229
}
216230
}
217231

@@ -486,7 +500,12 @@ fn early_bound_lifetime_names(generics: &ast::Generics) -> Vec<ast::Name> {
486500
visit::walk_ty_param_bounds_helper(&mut collector, &ty_param.bounds);
487501
}
488502
for predicate in generics.where_clause.predicates.iter() {
489-
visit::walk_ty_param_bounds_helper(&mut collector, &predicate.bounds);
503+
match predicate {
504+
&ast::WherePredicate::BoundPredicate(ast::WhereBoundPredicate{ref bounds, ..}) => {
505+
visit::walk_ty_param_bounds_helper(&mut collector, bounds);
506+
}
507+
&ast::WherePredicate::EqPredicate(_) => unimplemented!()
508+
}
490509
}
491510
}
492511

0 commit comments

Comments
 (0)