Skip to content

Commit 9462a20

Browse files
author
Jorge Aparicio
committed
Make orphan check diagnostics clearer
closes #22388
1 parent c5db290 commit 9462a20

10 files changed

+46
-16
lines changed

src/librustc_typeck/coherence/orphan.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,10 @@ impl<'cx, 'tcx,'v> visit::Visitor<'v> for OrphanChecker<'cx, 'tcx> {
8888
Err(traits::OrphanCheckErr::UncoveredTy(param_ty)) => {
8989
if !ty::has_attr(self.tcx, trait_def_id, "old_orphan_check") {
9090
span_err!(self.tcx.sess, item.span, E0210,
91-
"type parameter `{}` is not constrained by any local type; \
92-
only traits defined in the current crate can be implemented \
93-
for a type parameter",
91+
"type parameter `{}` must be used as the type parameter for \
92+
some local type (e.g. `MyStruct<T>`); only traits defined in \
93+
the current crate can be implemented for a type parameter",
9494
param_ty.user_string(self.tcx));
95-
self.tcx.sess.span_note(
96-
item.span,
97-
&format!("for a limited time, you can add \
98-
`#![feature(old_orphan_check)]` to your crate \
99-
to disable this rule"));
10095
}
10196
}
10297
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
pub trait RemoteTrait {}

src/test/compile-fail/coherence-bigint-param.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ use lib::Remote1;
1616
pub struct BigInt;
1717

1818
impl<T> Remote1<BigInt> for T { }
19-
//~^ ERROR type parameter `T` is not constrained
19+
//~^ ERROR type parameter `T` must be used as the type parameter for some local type
2020

2121
fn main() { }

src/test/compile-fail/coherence-cow-no-cover.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ use lib::{Remote,Pair};
1818
pub struct Cover<T>(T);
1919

2020
impl<T,U> Remote for Pair<Cover<T>,U> { }
21-
//~^ ERROR type parameter `U` is not constrained by any local type
21+
//~^ ERROR type parameter `U` must be used as the type parameter for some local type
2222

2323
fn main() { }

src/test/compile-fail/coherence-cross-crate-conflict.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ extern crate trait_impl_conflict;
1616
use trait_impl_conflict::Foo;
1717

1818
impl<A> Foo for A {
19-
//~^ ERROR type parameter `A` is not constrained
19+
//~^ ERROR type parameter `A` must be used as the type parameter for some local type
2020
//~^^ ERROR E0119
2121
}
2222

src/test/compile-fail/coherence-lone-type-parameter.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
extern crate "coherence-lib" as lib;
1414
use lib::Remote;
1515

16-
impl<T> Remote for T { } //~ ERROR type parameter `T` is not constrained
16+
impl<T> Remote for T { }
17+
//~^ ERROR type parameter `T` must be used as the type parameter for some local type
1718

1819
fn main() { }

src/test/compile-fail/coherence-overlapping-pairs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ use lib::Remote;
1616
struct Foo;
1717

1818
impl<T> Remote for lib::Pair<T,Foo> { }
19-
//~^ ERROR type parameter `T` is not constrained
19+
//~^ ERROR type parameter `T` must be used as the type parameter for some local type
2020

2121
fn main() { }

src/test/compile-fail/coherence-pair-covered-uncovered-1.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use lib::{Remote1, Pair};
1818

1919
pub struct Local<T>(T);
2020

21-
impl<T,U> Remote1<Pair<T,Local<U>>> for i32 { }
22-
//~^ ERROR type parameter `T` is not constrained
21+
impl<T, U> Remote1<Pair<T, Local<U>>> for i32 { }
22+
//~^ ERROR type parameter `T` must be used as the type parameter for some local type
2323

2424
fn main() { }

src/test/compile-fail/coherence-pair-covered-uncovered.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ use lib::{Remote, Pair};
1616
struct Local<T>(T);
1717

1818
impl<T,U> Remote for Pair<T,Local<U>> { }
19-
//~^ ERROR type parameter `T` is not constrained
19+
//~^ ERROR type parameter `T` must be used as the type parameter for some local type
2020

2121
fn main() { }
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// aux-build:orphan_check_diagnostics.rs
12+
// see #22388
13+
14+
extern crate orphan_check_diagnostics;
15+
16+
use orphan_check_diagnostics::RemoteTrait;
17+
18+
trait LocalTrait {}
19+
20+
impl<T> RemoteTrait for T where T: LocalTrait {}
21+
//~^ ERROR type parameter `T` must be used as the type parameter for some local type
22+
23+
fn main() {}

0 commit comments

Comments
 (0)