Make orphan check diagnostics clearer

closes 
This commit is contained in:
Jorge Aparicio 2015-02-16 14:40:38 -05:00
parent c5db290bf6
commit 9462a207ff
10 changed files with 46 additions and 16 deletions

@ -88,15 +88,10 @@ impl<'cx, 'tcx,'v> visit::Visitor<'v> for OrphanChecker<'cx, 'tcx> {
Err(traits::OrphanCheckErr::UncoveredTy(param_ty)) => {
if !ty::has_attr(self.tcx, trait_def_id, "old_orphan_check") {
span_err!(self.tcx.sess, item.span, E0210,
"type parameter `{}` is not constrained by any local type; \
only traits defined in the current crate can be implemented \
for a type parameter",
"type parameter `{}` must be used as the type parameter for \
some local type (e.g. `MyStruct<T>`); only traits defined in \
the current crate can be implemented for a type parameter",
param_ty.user_string(self.tcx));
self.tcx.sess.span_note(
item.span,
&format!("for a limited time, you can add \
`#![feature(old_orphan_check)]` to your crate \
to disable this rule"));
}
}
}

@ -0,0 +1,11 @@
// 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.
pub trait RemoteTrait {}

@ -16,6 +16,6 @@ use lib::Remote1;
pub struct BigInt;
impl<T> Remote1<BigInt> for T { }
//~^ ERROR type parameter `T` is not constrained
//~^ ERROR type parameter `T` must be used as the type parameter for some local type
fn main() { }

@ -18,6 +18,6 @@ use lib::{Remote,Pair};
pub struct Cover<T>(T);
impl<T,U> Remote for Pair<Cover<T>,U> { }
//~^ ERROR type parameter `U` is not constrained by any local type
//~^ ERROR type parameter `U` must be used as the type parameter for some local type
fn main() { }

@ -16,7 +16,7 @@ extern crate trait_impl_conflict;
use trait_impl_conflict::Foo;
impl<A> Foo for A {
//~^ ERROR type parameter `A` is not constrained
//~^ ERROR type parameter `A` must be used as the type parameter for some local type
//~^^ ERROR E0119
}

@ -13,6 +13,7 @@
extern crate "coherence-lib" as lib;
use lib::Remote;
impl<T> Remote for T { } //~ ERROR type parameter `T` is not constrained
impl<T> Remote for T { }
//~^ ERROR type parameter `T` must be used as the type parameter for some local type
fn main() { }

@ -16,6 +16,6 @@ use lib::Remote;
struct Foo;
impl<T> Remote for lib::Pair<T,Foo> { }
//~^ ERROR type parameter `T` is not constrained
//~^ ERROR type parameter `T` must be used as the type parameter for some local type
fn main() { }

@ -18,7 +18,7 @@ use lib::{Remote1, Pair};
pub struct Local<T>(T);
impl<T,U> Remote1<Pair<T,Local<U>>> for i32 { }
//~^ ERROR type parameter `T` is not constrained
impl<T, U> Remote1<Pair<T, Local<U>>> for i32 { }
//~^ ERROR type parameter `T` must be used as the type parameter for some local type
fn main() { }

@ -16,6 +16,6 @@ use lib::{Remote, Pair};
struct Local<T>(T);
impl<T,U> Remote for Pair<T,Local<U>> { }
//~^ ERROR type parameter `T` is not constrained
//~^ ERROR type parameter `T` must be used as the type parameter for some local type
fn main() { }

@ -0,0 +1,23 @@
// 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.
// aux-build:orphan_check_diagnostics.rs
// see #22388
extern crate orphan_check_diagnostics;
use orphan_check_diagnostics::RemoteTrait;
trait LocalTrait {}
impl<T> RemoteTrait for T where T: LocalTrait {}
//~^ ERROR type parameter `T` must be used as the type parameter for some local type
fn main() {}