Change:
Could this be fixed by "::unwrap" in the file (src/test/compile-fail/trait-or-new-type-) // error-pattern: found value name used as a type impl<TOption<T::unwrap { pub fn foo(&self) { } fn main() { } !
I don't understand your question, and that's not valid syntax. You can only create an impl for a type in the same module.
definitely I'm confused :-P. Im trying to determine how to fix this issue.Has been a while I didnt work with C like language(last 5 years have been working with C# and Java) ;-) If I create my own file (as you did writing the ) and implement the same code, I get the issue. Rust is a compiler, so Im assuming that a compiler file should be fixed in order to avoid the user implement namespace overlapping imports. Is my assumption correct about this problem?
Yes, your assumption is correct. The goal is to provide an error message that makes sense when a program tries to create an impl for a type that is not in scope (ie. does not exist).
The code I provided is a Rust compiler file (which i changed), not a new one. Im trying to understand where in the code can I implement this fix
Find the place that generates the error message, and follow the code backwards until it's clear where you could modify it to produce a better error message for this case.
Someone gave me a good tip on how to debug Rust I will try this. The terminal is quite archaic ;-P
I think point was essentially "grep for the error message, and look at the code there", using a full debugger to find out where it is is probably still quite hard at the moment. In any case, running turns up . So it looks like one could just expand the pattern to cover more cases.
I used Eclipse as explained by Michael and did a search and found that file. Now correct me if I'm wrong but the it seems that there is no "match a_def {" (startting at line 444) for the impl type. I'm going to attempt to add a case and test
in there is an enumeration, I dont see one for 'impl' (such as DefTrait for example) line 226. Isn't suppose to be one?
No, because the name we are creating an impl for is not itself an impl; the compiler seems to think that it is a module instead. Figuring out why this is the case would be a good start.
seems like astriranna solved the issue by adding: ast::DefMod(_) =
I just tested but this does not work for 'impl' (still get the same error message)
Yes, that is not a solution, just a slightly clearer (but still incorrect) error message.

Discussion:
match *name_bindings.type_def.borrow() { None => {} Some(ref ty) => { <del> let msg = format!("import `{}` conflicts with type in  this module", token::get_name(name).get()); self.session.span_err(import_span, msg.as_slice()); match ty.type_span { None => {} Some(span) => { self.session .span_note(span, "conflicting type here") </del> <ins> match ty.module_def { None => { let msg = format!("import `{}` conflicts with type in  this module", token::get_name(name).get()); self.session.span_err(import_span, msg.as_slice()); match ty.type_span { None => {} Some(span) => { self.session .span_note(span, "note conflicting type here") } } } Some(ref module_def) => { match module_def.kind.get() { ImplModuleKind => { match ty.type_span { None => { /* this can't ever happen */ } Some(span) => { let msg = format!("inherent implementations  are only allowed on types  defined in the current module"); self.session .span_err(span, msg.as_slice()); self.session .span_note(import_span, "import from other module here") } } } _ => { let msg = format!("import `{}` conflicts with existing  submodule", token::get_name(name).get()); self.session.span_err(import_span, msg.as_slice()); match ty.type_span { None => {} Some(span) => { self.session .span_note(span, "note conflicting module here") } } } } </ins> } } }

}); }); }); <ins> // Check that the current type is indeed a type, if we have an anonymous impl if opt_trait_reference.is_none() { match self_type.node { // TyPath is the only thing that we handled in `build_reduced_graph_for_item`, // where we created a module with the name of the type in order to implement // an anonymous trait. In the case that the path does not resolve to an actual // type, the result will be that the type name resolves to a module but not // a type (shadowing any imported modules or types with this name), leading // to weird user-visible bugs. So we ward this off here. See #15060. TyPath(ref path, _, path_id) => { match self.def_map.borrow().find(&path_id) { // FIXME: should we catch other options and give more precise errors? Some(&DefMod(_)) => { self.resolve_error(path.span, "inherent implementations are not  allowed for types not defined in  the current module."); } _ => {} } } _ => { } } } </ins> } fn check_trait_item(&self, ident: Ident, span: Span) {

<ins> // Copyright 2012 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your // option. This file may not be copied, modified, or distributed // except according to those terms. // ignore-tidy-linelength pub struct Foo; mod bar { use Foo; impl Foo { //~ERROR inherent implementations are only allowed on types defined in the current module fn baz(&self) {} } } fn main() {} </ins>

<ins> // Copyright 2012 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your // option. This file may not be copied, modified, or distributed // except according to those terms. // ignore-tidy-linelength struct Foo { x: int } impl Fo { //~ERROR inherent implementations are not allowed for types not defined in the current module. fn foo() {} } fn main() {} </ins>

<ins> // Copyright 2012 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your // option. This file may not be copied, modified, or distributed // except according to those terms. // ignore-tidy-linelength pub mod a { pub struct Foo { a: uint } } pub mod b { use a::Foo; impl Foo { //~ERROR inherent implementations are only allowed on types defined in the current module fn bar(&self) { } } } pub fn main() { } </ins>

<ins> // Copyright 2012 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your // option. This file may not be copied, modified, or distributed // except according to those terms. // ignore-tidy-linelength impl B { //~ERROR inherent implementations are not allowed for types not defined in the current module. } fn main() { } </ins>

// option. This file may not be copied, modified, or distributed // except according to those terms. <del> // FIXME(#8767) bad error message; Option is not a module impl<T> Option<T> { //~ERROR found module name used as a type </del> <ins> // ignore-tidy-linelength impl<T> Option<T> { //~ERROR inherent implementations are not allowed for types not defined in the current module. </ins> pub fn foo(&self) { } }