Skip to content

Commit

Permalink
Make orphan check diagnostics clearer
Browse files Browse the repository at this point in the history
closes #22388
  • Loading branch information
Jorge Aparicio committed Feb 16, 2015
1 parent c5db290 commit 9462a20
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 16 deletions.
11 changes: 3 additions & 8 deletions src/librustc_typeck/coherence/orphan.rs
Expand Up @@ -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"));
}
}
}
Expand Down
11 changes: 11 additions & 0 deletions src/test/auxiliary/orphan_check_diagnostics.rs
@@ -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 {}
2 changes: 1 addition & 1 deletion src/test/compile-fail/coherence-bigint-param.rs
Expand Up @@ -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() { }
2 changes: 1 addition & 1 deletion src/test/compile-fail/coherence-cow-no-cover.rs
Expand Up @@ -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() { }
2 changes: 1 addition & 1 deletion src/test/compile-fail/coherence-cross-crate-conflict.rs
Expand Up @@ -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
}

Expand Down
3 changes: 2 additions & 1 deletion src/test/compile-fail/coherence-lone-type-parameter.rs
Expand Up @@ -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() { }
2 changes: 1 addition & 1 deletion src/test/compile-fail/coherence-overlapping-pairs.rs
Expand Up @@ -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() { }
4 changes: 2 additions & 2 deletions src/test/compile-fail/coherence-pair-covered-uncovered-1.rs
Expand Up @@ -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() { }
2 changes: 1 addition & 1 deletion src/test/compile-fail/coherence-pair-covered-uncovered.rs
Expand Up @@ -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() { }
23 changes: 23 additions & 0 deletions src/test/compile-fail/orphan-check-diagnostics.rs
@@ -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() {}

0 comments on commit 9462a20

Please sign in to comment.