Skip to content

Commit

Permalink
Fix error codes
Browse files Browse the repository at this point in the history
  • Loading branch information
flaper87 committed Feb 22, 2015
1 parent 40fffc9 commit 0be1e43
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/librustc_typeck/coherence/orphan.rs
Expand Up @@ -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.");
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_typeck/coherence/overlap.rs
Expand Up @@ -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");

Expand Down
4 changes: 2 additions & 2 deletions src/librustc_typeck/diagnostics.rs
Expand Up @@ -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 }
Expand Down
29 changes: 29 additions & 0 deletions 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 <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.

// 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<T:MyTrait>() { bar::<T>() }

fn bar<T:NotImplemented>() { }

fn main() {
foo::<i32>(); //~ ERROR XXX
bar::<i32>(); //~ ERROR XXX
}

0 comments on commit 0be1e43

Please sign in to comment.