Skip to content

Commit 961ee0a

Browse files
committed
Allow impls for traits as a concrete type
1 parent 2790505 commit 961ee0a

File tree

4 files changed

+14
-8
lines changed

4 files changed

+14
-8
lines changed

src/librustc/middle/resolve.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,10 @@ impl NameBindings {
627627
sp: Span) {
628628
// Merges the module with the existing type def or creates a new one.
629629
let modifiers = if is_public { PUBLIC } else { DefModifiers::empty() } | IMPORTABLE;
630-
let module_ = Rc::new(Module::new(parent_link, def_id, kind, external,
630+
let module_ = Rc::new(Module::new(parent_link,
631+
def_id,
632+
kind,
633+
external,
631634
is_public));
632635
let type_def = self.type_def.borrow().clone();
633636
match type_def {
@@ -1372,6 +1375,8 @@ impl<'a> Resolver<'a> {
13721375
// Create the module and add all methods.
13731376
match ty.node {
13741377
TyPath(ref path, _, _) if path.segments.len() == 1 => {
1378+
// FIXME(18446) we should distinguish between the name of
1379+
// a trait and the name of an impl of that trait.
13751380
let mod_name = path.segments.last().unwrap().identifier.name;
13761381

13771382
let parent_opt = parent.module().children.borrow()
@@ -1380,8 +1385,8 @@ impl<'a> Resolver<'a> {
13801385
// It already exists
13811386
Some(ref child) if child.get_module_if_available()
13821387
.is_some() &&
1383-
child.get_module().kind.get() ==
1384-
ImplModuleKind => {
1388+
(child.get_module().kind.get() == ImplModuleKind ||
1389+
child.get_module().kind.get() == TraitModuleKind) => {
13851390
ModuleReducedGraphParent(child.get_module())
13861391
}
13871392
Some(ref child) if child.get_module_if_available()

src/librustc/middle/traits/select.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
514514
// and `Rc<Baz>`. (Note that it is not a *coherence violation*
515515
// to have impls for both `Bar` and `Baz`, despite this
516516
// ambiguity). In this case, we report an error, listing all
517-
// the applicable impls. The use can explicitly "up-coerce"
517+
// the applicable impls. The user can explicitly "up-coerce"
518518
// to the type they want.
519519
//
520520
// Note that this coercion step only considers actual impls
@@ -1931,7 +1931,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
19311931

19321932
fn all_impls(&self, trait_def_id: ast::DefId) -> Vec<ast::DefId> {
19331933
/*!
1934-
* Returns se tof all impls for a given trait.
1934+
* Returns set of all impls for a given trait.
19351935
*/
19361936

19371937
ty::populate_implementations_for_trait_if_necessary(self.tcx(),

src/librustc/middle/typeck/coherence/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,8 @@ impl<'a, 'tcx> CoherenceChecker<'a, 'tcx> {
207207
let impl_items = self.create_impl_from_item(item);
208208

209209
for associated_trait in associated_traits.iter() {
210-
let trait_ref = ty::node_id_to_trait_ref(
211-
self.crate_context.tcx, associated_trait.ref_id);
210+
let trait_ref = ty::node_id_to_trait_ref(self.crate_context.tcx,
211+
associated_trait.ref_id);
212212
debug!("(checking implementation) adding impl for trait '{}', item '{}'",
213213
trait_ref.repr(self.crate_context.tcx),
214214
token::get_ident(item.ident));

src/librustc/middle/typeck/coherence/orphan.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ impl<'cx, 'tcx,'v> visit::Visitor<'v> for OrphanChecker<'cx, 'tcx> {
4141
let self_ty = ty::lookup_item_type(self.tcx, def_id).ty;
4242
match ty::get(self_ty).sty {
4343
ty::ty_enum(def_id, _) |
44-
ty::ty_struct(def_id, _) => {
44+
ty::ty_struct(def_id, _) |
45+
ty::ty_trait(box ty::TyTrait{ def_id, ..}) => {
4546
if def_id.krate != ast::LOCAL_CRATE {
4647
span_err!(self.tcx.sess, item.span, E0116,
4748
"cannot associate methods with a type outside the \

0 commit comments

Comments
 (0)