diff --git a/src/librustc_typeck/coherence/orphan.rs b/src/librustc_typeck/coherence/orphan.rs index 08aa54b6f5f4b..d34a16a924f70 100644 --- a/src/librustc_typeck/coherence/orphan.rs +++ b/src/librustc_typeck/coherence/orphan.rs @@ -101,7 +101,7 @@ impl<'cx, 'tcx,'v> visit::Visitor<'v> for OrphanChecker<'cx, 'tcx> { debug!("coherence2::orphan check: default trait impl {}", item.repr(self.tcx)); let trait_ref = ty::node_id_to_trait_ref(self.tcx, ast_trait_ref.ref_id); if trait_ref.def_id.krate != ast::LOCAL_CRATE { - span_err!(self.tcx.sess, item.span, E0316, + span_err!(self.tcx.sess, item.span, E0318, "cannot create default implementations for traits outside the \ crate they're defined in; define a new trait instead."); } diff --git a/src/librustc_typeck/coherence/overlap.rs b/src/librustc_typeck/coherence/overlap.rs index 26624c051c911..9accfe7749e8e 100644 --- a/src/librustc_typeck/coherence/overlap.rs +++ b/src/librustc_typeck/coherence/overlap.rs @@ -141,7 +141,7 @@ impl<'cx, 'tcx,'v> visit::Visitor<'v> for OverlapChecker<'cx, 'tcx> { ty::ty_struct(..) | ty::ty_enum(..) => {}, _ => { let impl_def_id = ast_util::local_def(item.id); - span_err!(self.tcx.sess, self.span_of_impl(impl_def_id), E0317, + span_err!(self.tcx.sess, self.span_of_impl(impl_def_id), E0319, "implementations for traits providing default \ implementations are only allowed on structs and enums"); diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index 39ae233957af4..6f363faef6039 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -172,8 +172,8 @@ register_diagnostics! { E0248, // found value name used as a type E0249, // expected constant expr for array length E0250, // expected constant expr for array length - E0316, // can't create default impls for traits outside their crates - E0317 + E0318, // can't create default impls for traits outside their crates + E0319 // trait impls for defaulted traits allowed just for structs/enums } __build_diagnostic_array! { DIAGNOSTICS } diff --git a/src/test/compile-fail/typeck-default-trait-impl-supertrait.rs b/src/test/compile-fail/typeck-default-trait-impl-supertrait.rs new file mode 100644 index 0000000000000..cb3f50c8d8702 --- /dev/null +++ b/src/test/compile-fail/typeck-default-trait-impl-supertrait.rs @@ -0,0 +1,29 @@ +// Copyright 2015 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Test that when a `..` impl applies, we also check that any +// supertrait conditions are met. + +#![feature(optin_builtin_traits)] + +trait NotImplemented { } + +trait MyTrait : NotImplemented {} + +impl MyTrait for .. {} + +fn foo() { bar::() } + +fn bar() { } + +fn main() { + foo::(); //~ ERROR XXX + bar::(); //~ ERROR XXX +}