Skip to content

Make orphan check diagnostics clearer #22418

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 17, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions src/librustc_typeck/coherence/orphan.rs
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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() {}