Skip to content

Commit 5337633

Browse files
committed
---
yaml --- r: 185835 b: refs/heads/auto c: 326711e h: refs/heads/master i: 185833: 649e6f7 185831: 83dd0c8 v: v3
1 parent 498968f commit 5337633

File tree

5 files changed

+96
-85
lines changed

5 files changed

+96
-85
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1010
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1111
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1212
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
13-
refs/heads/auto: 9a69378e8b61473fbfa55f347286718ca4c5d399
13+
refs/heads/auto: 326711e9bdee2e8f467ad716109b5a270b61478d
1414
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1515
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1616
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336

branches/auto/src/librustc_resolve/lib.rs

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3563,8 +3563,24 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
35633563
match ty.node {
35643564
// Like path expressions, the interpretation of path types depends
35653565
// on whether the path has multiple elements in it or not.
3566+
TyPath(_) | TyQPath(_) => {
3567+
let mut path_from_qpath;
3568+
let path = match ty.node {
3569+
TyPath(ref path) => path,
3570+
TyQPath(ref qpath) => {
3571+
self.resolve_type(&*qpath.self_type);
3572+
3573+
// Just make sure the trait is valid, don't record a def.
3574+
self.resolve_trait_reference(ty.id, &qpath.trait_path, TraitQPath);
3575+
self.def_map.borrow_mut().remove(&ty.id);
3576+
3577+
path_from_qpath = qpath.trait_path.clone();
3578+
path_from_qpath.segments.push(qpath.item_path.clone());
3579+
&path_from_qpath
3580+
}
3581+
_ => unreachable!()
3582+
};
35663583

3567-
TyPath(ref path) => {
35683584
// This is a path in the type namespace. Walk through scopes
35693585
// looking for it.
35703586
let mut result_def = None;
@@ -3609,7 +3625,11 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
36093625
self.record_def(ty.id, def);
36103626
}
36113627
None => {
3612-
let msg = format!("use of undeclared type name `{}`",
3628+
let kind = match ty.node {
3629+
TyQPath(_) => "associated type",
3630+
_ => "type name"
3631+
};
3632+
let msg = format!("use of undeclared {} `{}`", kind,
36133633
self.path_names_to_string(path));
36143634
self.resolve_error(ty.span, &msg[..]);
36153635
}
@@ -3621,17 +3641,6 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
36213641
self.resolve_type_parameter_bounds(bound_vec, TraitBoundingTypeParameter);
36223642
}
36233643

3624-
TyQPath(ref qpath) => {
3625-
self.resolve_type(&*qpath.self_type);
3626-
self.resolve_trait_reference(ty.id, &qpath.trait_path, TraitQPath);
3627-
for ty in qpath.item_path.parameters.types() {
3628-
self.resolve_type(&**ty);
3629-
}
3630-
for binding in qpath.item_path.parameters.bindings() {
3631-
self.resolve_type(&*binding.ty);
3632-
}
3633-
}
3634-
36353644
TyPolyTraitRef(ref bounds) => {
36363645
self.resolve_type_parameter_bounds(bounds, TraitObject);
36373646
visit::walk_ty(self, ty);

branches/auto/src/librustc_typeck/astconv.rs

Lines changed: 63 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -606,9 +606,10 @@ pub fn instantiate_trait_ref<'tcx>(
606606
def::DefTrait(trait_def_id) => {
607607
let trait_ref = ast_path_to_trait_ref(this,
608608
rscope,
609+
path.span,
609610
trait_def_id,
610611
self_ty,
611-
path,
612+
path.segments.last().unwrap(),
612613
projections);
613614
if let Some(id) = impl_id {
614615
this.tcx().impl_trait_refs.borrow_mut().insert(id, trait_ref.clone());
@@ -637,9 +638,10 @@ fn object_path_to_poly_trait_ref<'a,'tcx>(
637638
let mut tmp = Vec::new();
638639
let trait_ref = ty::Binder(ast_path_to_trait_ref(this,
639640
&shifted_rscope,
641+
path.span,
640642
trait_def_id,
641643
None,
642-
path,
644+
path.segments.last().unwrap(),
643645
Some(&mut tmp)));
644646
projections.extend(tmp.into_iter().map(ty::Binder));
645647
trait_ref
@@ -648,24 +650,25 @@ fn object_path_to_poly_trait_ref<'a,'tcx>(
648650
fn ast_path_to_trait_ref<'a,'tcx>(
649651
this: &AstConv<'tcx>,
650652
rscope: &RegionScope,
653+
span: Span,
651654
trait_def_id: ast::DefId,
652655
self_ty: Option<Ty<'tcx>>,
653-
path: &ast::Path,
656+
trait_segment: &ast::PathSegment,
654657
mut projections: Option<&mut Vec<ty::ProjectionPredicate<'tcx>>>)
655658
-> Rc<ty::TraitRef<'tcx>>
656659
{
657-
debug!("ast_path_to_trait_ref {:?}", path);
660+
debug!("ast_path_to_trait_ref {:?}", trait_segment);
658661
let trait_def = this.get_trait_def(trait_def_id);
659662

660-
let (regions, types, assoc_bindings) = match path.segments.last().unwrap().parameters {
663+
let (regions, types, assoc_bindings) = match trait_segment.parameters {
661664
ast::AngleBracketedParameters(ref data) => {
662665
// For now, require that parenthetical notation be used
663666
// only with `Fn()` etc.
664667
if !this.tcx().sess.features.borrow().unboxed_closures && trait_def.paren_sugar {
665-
span_err!(this.tcx().sess, path.span, E0215,
668+
span_err!(this.tcx().sess, span, E0215,
666669
"angle-bracket notation is not stable when \
667670
used with the `Fn` family of traits, use parentheses");
668-
span_help!(this.tcx().sess, path.span,
671+
span_help!(this.tcx().sess, span,
669672
"add `#![feature(unboxed_closures)]` to \
670673
the crate attributes to enable");
671674
}
@@ -676,10 +679,10 @@ fn ast_path_to_trait_ref<'a,'tcx>(
676679
// For now, require that parenthetical notation be used
677680
// only with `Fn()` etc.
678681
if !this.tcx().sess.features.borrow().unboxed_closures && !trait_def.paren_sugar {
679-
span_err!(this.tcx().sess, path.span, E0216,
682+
span_err!(this.tcx().sess, span, E0216,
680683
"parenthetical notation is only stable when \
681684
used with the `Fn` family of traits");
682-
span_help!(this.tcx().sess, path.span,
685+
span_help!(this.tcx().sess, span,
683686
"add `#![feature(unboxed_closures)]` to \
684687
the crate attributes to enable");
685688
}
@@ -689,7 +692,7 @@ fn ast_path_to_trait_ref<'a,'tcx>(
689692
};
690693

691694
let substs = create_substs_for_ast_path(this,
692-
path.span,
695+
span,
693696
&trait_def.generics,
694697
self_ty,
695698
types,
@@ -1047,33 +1050,42 @@ fn trait_defines_associated_type_named(this: &AstConv,
10471050

10481051
fn qpath_to_ty<'tcx>(this: &AstConv<'tcx>,
10491052
rscope: &RegionScope,
1050-
ast_ty: &ast::Ty, // the TyQPath
1051-
qpath: &ast::QPath)
1053+
span: Span,
1054+
opt_self_ty: Option<&ast::Ty>,
1055+
trait_def_id: ast::DefId,
1056+
trait_segment: &ast::PathSegment,
1057+
item_segment: &ast::PathSegment)
10521058
-> Ty<'tcx>
10531059
{
1054-
debug!("qpath_to_ty(ast_ty={})",
1055-
ast_ty.repr(this.tcx()));
1060+
let tcx = this.tcx();
10561061

1057-
let self_type = ast_ty_to_ty(this, rscope, &*qpath.self_type);
1062+
let self_ty = if let Some(ty) = opt_self_ty {
1063+
ast_ty_to_ty(this, rscope, ty)
1064+
} else {
1065+
let path_str = ty::item_path_str(tcx, trait_def_id);
1066+
span_err!(tcx.sess, span, E0223,
1067+
"ambiguous associated type; specify the type using the syntax \
1068+
`<Type as {}>::{}`",
1069+
path_str, &token::get_ident(item_segment.identifier));
1070+
return tcx.types.err;
1071+
};
10581072

1059-
debug!("qpath_to_ty: self_type={}", self_type.repr(this.tcx()));
1073+
debug!("qpath_to_ty: self_type={}", self_ty.repr(tcx));
10601074

1061-
let trait_ref = instantiate_trait_ref(this,
1075+
let trait_ref = ast_path_to_trait_ref(this,
10621076
rscope,
1063-
&qpath.trait_path,
1064-
ast_ty.id,
1065-
None,
1066-
Some(self_type),
1077+
span,
1078+
trait_def_id,
1079+
Some(self_ty),
1080+
trait_segment,
10671081
None);
10681082

1069-
debug!("qpath_to_ty: trait_ref={}", trait_ref.repr(this.tcx()));
1083+
debug!("qpath_to_ty: trait_ref={}", trait_ref.repr(tcx));
10701084

10711085
// `<T as Trait>::U<V>` shouldn't parse right now.
1072-
assert!(qpath.item_path.parameters.is_empty());
1086+
assert!(item_segment.parameters.is_empty());
10731087

1074-
return this.projected_ty(ast_ty.span,
1075-
trait_ref,
1076-
qpath.item_path.identifier.name);
1088+
this.projected_ty(span, trait_ref, item_segment.identifier.name)
10771089
}
10781090

10791091
/// Convert a type supplied as value for a type argument from AST into our
@@ -1189,13 +1201,17 @@ pub fn ast_ty_to_ty<'tcx>(this: &AstConv<'tcx>,
11891201
ast::TyPolyTraitRef(ref bounds) => {
11901202
conv_ty_poly_trait_ref(this, rscope, ast_ty.span, &bounds[..])
11911203
}
1192-
ast::TyPath(ref path) => {
1204+
ast::TyPath(_) | ast::TyQPath(_) => {
1205+
let simple_path = |&:| match ast_ty.node {
1206+
ast::TyPath(ref path) => path,
1207+
_ => tcx.sess.span_bug(ast_ty.span, "expected non-qualified path")
1208+
};
11931209
let a_def = match tcx.def_map.borrow().get(&ast_ty.id) {
11941210
None => {
11951211
tcx.sess
11961212
.span_bug(ast_ty.span,
11971213
&format!("unbound path {}",
1198-
path.repr(tcx)))
1214+
ast_ty.repr(tcx)))
11991215
}
12001216
Some(&d) => d
12011217
};
@@ -1208,24 +1224,24 @@ pub fn ast_ty_to_ty<'tcx>(this: &AstConv<'tcx>,
12081224
let trait_ref = object_path_to_poly_trait_ref(this,
12091225
rscope,
12101226
trait_def_id,
1211-
path,
1227+
simple_path(),
12121228
&mut projection_bounds);
12131229

1214-
trait_ref_to_object_type(this, rscope, path.span,
1230+
trait_ref_to_object_type(this, rscope, ast_ty.span,
12151231
trait_ref, projection_bounds, &[])
12161232
}
12171233
def::DefTy(did, _) | def::DefStruct(did) => {
1218-
ast_path_to_ty(this, rscope, did, path).ty
1234+
ast_path_to_ty(this, rscope, did, simple_path()).ty
12191235
}
12201236
def::DefTyParam(space, index, _, name) => {
1221-
check_path_args(tcx, path, NO_TPS | NO_REGIONS);
1237+
check_path_args(tcx, simple_path(), NO_TPS | NO_REGIONS);
12221238
ty::mk_param(tcx, space, index, name)
12231239
}
12241240
def::DefSelfTy(_) => {
12251241
// n.b.: resolve guarantees that the this type only appears in a
12261242
// trait, which we rely upon in various places when creating
12271243
// substs
1228-
check_path_args(tcx, path, NO_TPS | NO_REGIONS);
1244+
check_path_args(tcx, simple_path(), NO_TPS | NO_REGIONS);
12291245
ty::mk_self_type(tcx)
12301246
}
12311247
def::DefMod(id) => {
@@ -1236,20 +1252,20 @@ pub fn ast_ty_to_ty<'tcx>(this: &AstConv<'tcx>,
12361252
def::DefPrimTy(_) => {
12371253
panic!("DefPrimTy arm missed in previous ast_ty_to_prim_ty call");
12381254
}
1239-
def::DefAssociatedTy(trait_id, _) => {
1240-
let path_str = ty::item_path_str(tcx, trait_id);
1241-
span_err!(tcx.sess, ast_ty.span, E0223,
1242-
"ambiguous associated \
1243-
type; specify the type \
1244-
using the syntax `<Type \
1245-
as {}>::{}`",
1246-
path_str,
1247-
&token::get_ident(
1248-
path.segments
1249-
.last()
1250-
.unwrap()
1251-
.identifier));
1252-
this.tcx().types.err
1255+
def::DefAssociatedTy(trait_did, _) => {
1256+
let (opt_self_ty, trait_segment, item_segment) = match ast_ty.node {
1257+
ast::TyQPath(ref qpath) => {
1258+
(Some(&*qpath.self_type), qpath.trait_path.segments.last().unwrap(),
1259+
&qpath.item_path)
1260+
}
1261+
ast::TyPath(ref path) => {
1262+
(None, &path.segments[path.segments.len()-2],
1263+
path.segments.last().unwrap())
1264+
}
1265+
_ => unreachable!()
1266+
};
1267+
qpath_to_ty(this, rscope, ast_ty.span, opt_self_ty,
1268+
trait_did, trait_segment, item_segment)
12531269
}
12541270
def::DefAssociatedPath(provenance, assoc_ident) => {
12551271
associated_path_def_to_ty(this, ast_ty, provenance, assoc_ident.name)
@@ -1262,9 +1278,6 @@ pub fn ast_ty_to_ty<'tcx>(this: &AstConv<'tcx>,
12621278
}
12631279
}
12641280
}
1265-
ast::TyQPath(ref qpath) => {
1266-
qpath_to_ty(this, rscope, ast_ty, &**qpath)
1267-
}
12681281
ast::TyFixedLengthVec(ref ty, ref e) => {
12691282
match const_eval::eval_const_expr_partial(tcx, &**e, Some(tcx.types.uint)) {
12701283
Ok(ref r) => {

branches/auto/src/librustdoc/clean/mod.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1499,6 +1499,13 @@ impl Clean<Type> for ast::Ty {
14991499
TyPath(ref p) => {
15001500
resolve_type(cx, p.clean(cx), self.id)
15011501
}
1502+
TyQPath(ref qp) => {
1503+
Type::QPath {
1504+
name: qp.item_path.identifier.clean(cx),
1505+
self_type: box qp.self_type.clean(cx),
1506+
trait_: box resolve_type(cx, qp.trait_path.clean(cx), self.id)
1507+
}
1508+
}
15021509
TyObjectSum(ref lhs, ref bounds) => {
15031510
let lhs_ty = lhs.clean(cx);
15041511
match lhs_ty {
@@ -1512,7 +1519,6 @@ impl Clean<Type> for ast::Ty {
15121519
}
15131520
TyBareFn(ref barefn) => BareFunction(box barefn.clean(cx)),
15141521
TyParen(ref ty) => ty.clean(cx),
1515-
TyQPath(ref qp) => qp.clean(cx),
15161522
TyPolyTraitRef(ref bounds) => {
15171523
PolyTraitRef(bounds.clean(cx))
15181524
},
@@ -1624,16 +1630,6 @@ impl<'tcx> Clean<Type> for ty::Ty<'tcx> {
16241630
}
16251631
}
16261632

1627-
impl Clean<Type> for ast::QPath {
1628-
fn clean(&self, cx: &DocContext) -> Type {
1629-
Type::QPath {
1630-
name: self.item_path.identifier.clean(cx),
1631-
self_type: box self.self_type.clean(cx),
1632-
trait_: box resolve_type(cx, self.trait_path.clean(cx), 0)
1633-
}
1634-
}
1635-
}
1636-
16371633
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
16381634
pub enum StructField {
16391635
HiddenStructField, // inserted later by strip passes

branches/auto/src/test/compile-fail/issue-19883.rs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,11 @@ trait From<Src> {
1515
}
1616

1717
trait To {
18-
// This is a typo, the return type should be `<Dst as From<Self>>::Output`
19-
fn to<Dst: From<Self>>(
20-
self
21-
//~^ error: the trait `core::marker::Sized` is not implemented
22-
) ->
18+
fn to<Dst: From<Self>>(self) ->
2319
<Dst as From<Self>>::Dst
24-
//~^ error: the trait `core::marker::Sized` is not implemented
20+
//~^ ERROR use of undeclared associated type `From::Dst`
2521
{
26-
From::from(
27-
//~^ error: the trait `core::marker::Sized` is not implemented
28-
self
29-
)
22+
From::from(self)
3023
}
3124
}
3225

0 commit comments

Comments
 (0)