Skip to content

Commit

Permalink
Catch attempts to project nonexistent associated items from a trait.
Browse files Browse the repository at this point in the history
  • Loading branch information
pnkfelix committed Feb 24, 2015
1 parent 0ef56da commit 3a60f2c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/libcore/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,7 @@ pub trait IteratorExt: Iterator + Sized {
#[unstable(feature = "core", reason = "recent addition")]
fn cloned(self) -> Cloned<Self> where
Self::Item: Deref,
<Self::Item as Deref>::Output: Clone,
<Self::Item as Deref>::Target: Clone,
{
Cloned { it: self }
}
Expand Down
12 changes: 10 additions & 2 deletions src/librustc_typeck/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,12 +244,20 @@ impl<'a, 'tcx> AstConv<'tcx> for CollectCtxt<'a, 'tcx> {
}

fn projected_ty(&self,
_span: Span,
span: Span,
trait_ref: Rc<ty::TraitRef<'tcx>>,
item_name: ast::Name)
-> Ty<'tcx>
{
ty::mk_projection(self.tcx(), trait_ref, item_name)
let trait_def = ty::lookup_trait_def(self.tcx, trait_ref.def_id);
if !trait_def.associated_type_names.contains(&item_name) {
span_err!(self.tcx.sess, span, E0320,
"cannot find binding for item `{}` within trait `{}`",
item_name.as_str(), trait_ref.user_string(self.tcx));
ty::mk_t(self.tcx(), ty::ty_err)
} else {
ty::mk_projection(self.tcx(), trait_ref, item_name)
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/librustc_typeck/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ register_diagnostics! {
E0249, // expected constant expr for array length
E0250, // expected constant expr for array length
E0318, // can't create default impls for traits outside their crates
E0319 // trait impls for defaulted traits allowed just for structs/enums
E0319, // trait impls for defaulted traits allowed just for structs/enums
E0320 // Trait does not provide binding for Type in `<T as Trait>::Type`
}

__build_diagnostic_array! { DIAGNOSTICS }
Expand Down
4 changes: 1 addition & 3 deletions src/test/compile-fail/issue-19883.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,11 @@ trait To {
// This is a typo, the return type should be `<Dst as From<Self>>::Output`
fn to<Dst: From<Self>>(
self
//~^ error: the trait `core::marker::Sized` is not implemented
) ->
<Dst as From<Self>>::Dst
//~^ error: the trait `core::marker::Sized` is not implemented
//~^ error: cannot find binding for item `Dst` within trait `From<Self>`
{
From::from(
//~^ error: the trait `core::marker::Sized` is not implemented
self
)
}
Expand Down

0 comments on commit 3a60f2c

Please sign in to comment.