Skip to content

Commit 00ed709

Browse files
authored
Rollup merge of rust-lang#64546 - weiznich:bugfix/rfc-2451-rerebalance-tests, r=nikomatsakis
Bugfix/rfc 2451 rerebalance tests r? @nikomatsakis Fixes rust-lang#64412 Depends/Contains on rust-lang#64414 cc rust-lang#55437 and rust-lang#63599
2 parents 1d4f769 + 31b3012 commit 00ed709

33 files changed

+529
-15
lines changed

src/librustc/traits/coherence.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,15 @@ fn orphan_check_trait_ref<'tcx>(
378378
// Let Ti be the first such type.
379379
// - No uncovered type parameters P1..=Pn may appear in T0..Ti (excluding Ti)
380380
//
381-
for input_ty in trait_ref.input_types() {
381+
fn uncover_fundamental_ty(ty: Ty<'_>) -> Vec<Ty<'_>> {
382+
if fundamental_ty(ty) {
383+
ty.walk_shallow().flat_map(|ty| uncover_fundamental_ty(ty)).collect()
384+
} else {
385+
vec![ty]
386+
}
387+
}
388+
389+
for input_ty in trait_ref.input_types().flat_map(uncover_fundamental_ty) {
382390
debug!("orphan_check_trait_ref: check ty `{:?}`", input_ty);
383391
if ty_is_local(tcx, input_ty, in_crate) {
384392
debug!("orphan_check_trait_ref: ty_is_local `{:?}`", input_ty);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#![feature(re_rebalance_coherence)]
2+
3+
// compile-flags:--crate-name=test
4+
// aux-build:coherence_lib.rs
5+
6+
extern crate coherence_lib as lib;
7+
use lib::*;
8+
use std::rc::Rc;
9+
10+
struct Local;
11+
12+
impl Remote1<u32> for f64 {
13+
//~^ ERROR only traits defined in the current crate
14+
// | can be implemented for arbitrary types [E0117]
15+
}
16+
17+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
2+
--> $DIR/impl-foreign[foreign]-for-foreign.rs:12:1
3+
|
4+
LL | impl Remote1<u32> for f64 {
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate
6+
|
7+
= note: the impl does not reference only types defined in this crate
8+
= note: define and implement a trait or new type instead
9+
10+
error: aborting due to previous error
11+
12+
For more information about this error, try `rustc --explain E0117`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#![feature(re_rebalance_coherence)]
2+
3+
// compile-flags:--crate-name=test
4+
// aux-build:coherence_lib.rs
5+
// check-pass
6+
7+
extern crate coherence_lib as lib;
8+
use lib::*;
9+
use std::rc::Rc;
10+
11+
struct Local;
12+
13+
impl Remote1<u32> for Local {
14+
}
15+
16+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#![feature(re_rebalance_coherence)]
2+
3+
// check-pass
4+
// compile-flags:--crate-name=test
5+
// aux-build:coherence_lib.rs
6+
7+
extern crate coherence_lib as lib;
8+
use lib::*;
9+
use std::rc::Rc;
10+
11+
struct Local;
12+
impl<T> Remote2<Rc<T>, Local> for usize { }
13+
14+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#![feature(re_rebalance_coherence)]
2+
3+
// compile-flags:--crate-name=test
4+
// aux-build:coherence_lib.rs
5+
6+
extern crate coherence_lib as lib;
7+
use lib::*;
8+
use std::rc::Rc;
9+
10+
struct Local;
11+
12+
impl<T> Remote1<u32> for Box<T> {
13+
//~^ ERROR type parameter `T` must be used as the type parameter for some local type
14+
}
15+
16+
impl<'a, T> Remote1<u32> for &'a T {
17+
//~^ ERROR type parameter `T` must be used as the type parameter for some local type
18+
}
19+
20+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct<T>`)
2+
--> $DIR/impl[t]-foreign[foreign]-for-fundamental[t].rs:12:1
3+
|
4+
LL | impl<T> Remote1<u32> for Box<T> {
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type parameter `T` must be used as the type parameter for some local type
6+
|
7+
= note: only traits defined in the current crate can be implemented for a type parameter
8+
9+
error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct<T>`)
10+
--> $DIR/impl[t]-foreign[foreign]-for-fundamental[t].rs:16:1
11+
|
12+
LL | impl<'a, T> Remote1<u32> for &'a T {
13+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type parameter `T` must be used as the type parameter for some local type
14+
|
15+
= note: only traits defined in the current crate can be implemented for a type parameter
16+
17+
error: aborting due to 2 previous errors
18+
19+
For more information about this error, try `rustc --explain E0210`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#![feature(re_rebalance_coherence)]
2+
3+
// compile-flags:--crate-name=test
4+
// aux-build:coherence_lib.rs
5+
6+
extern crate coherence_lib as lib;
7+
use lib::*;
8+
use std::rc::Rc;
9+
10+
struct Local;
11+
12+
impl<T> Remote1<u32> for T {
13+
//~^ ERROR type parameter `T` must be used as the type parameter for some local type
14+
}
15+
16+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct<T>`)
2+
--> $DIR/impl[t]-foreign[foreign]-for-t.rs:12:1
3+
|
4+
LL | impl<T> Remote1<u32> for T {
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ type parameter `T` must be used as the type parameter for some local type
6+
|
7+
= note: only traits defined in the current crate can be implemented for a type parameter
8+
9+
error: aborting due to previous error
10+
11+
For more information about this error, try `rustc --explain E0210`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#![feature(re_rebalance_coherence)]
2+
3+
// compile-flags:--crate-name=test
4+
// aux-build:coherence_lib.rs
5+
6+
extern crate coherence_lib as lib;
7+
use lib::*;
8+
use std::rc::Rc;
9+
10+
struct Local;
11+
12+
impl<T> Remote2<Box<T>, Local> for u32 {
13+
//~^ ERROR type parameter `T` must be used as the type parameter for some local type
14+
}
15+
16+
impl<'a, T> Remote2<&'a T, Local> for u32 {
17+
//~^ ERROR type parameter `T` must be used as the type parameter for some local type
18+
}
19+
20+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct<T>`)
2+
--> $DIR/impl[t]-foreign[fundamental[t],local]-for-foreign.rs:12:1
3+
|
4+
LL | impl<T> Remote2<Box<T>, Local> for u32 {
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type parameter `T` must be used as the type parameter for some local type
6+
|
7+
= note: only traits defined in the current crate can be implemented for a type parameter
8+
9+
error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct<T>`)
10+
--> $DIR/impl[t]-foreign[fundamental[t],local]-for-foreign.rs:16:1
11+
|
12+
LL | impl<'a, T> Remote2<&'a T, Local> for u32 {
13+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type parameter `T` must be used as the type parameter for some local type
14+
|
15+
= note: only traits defined in the current crate can be implemented for a type parameter
16+
17+
error: aborting due to 2 previous errors
18+
19+
For more information about this error, try `rustc --explain E0210`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#![feature(re_rebalance_coherence)]
2+
3+
// compile-flags:--crate-name=test
4+
// aux-build:coherence_lib.rs
5+
6+
extern crate coherence_lib as lib;
7+
use lib::*;
8+
use std::rc::Rc;
9+
10+
struct Local;
11+
12+
impl<T> Remote1<Box<T>> for u32 {
13+
//~^ ERROR type parameter `T` must be used as the type parameter for some local type
14+
}
15+
16+
impl<'a, T> Remote1<&'a T> for u32 {
17+
//~^ ERROR type parameter `T` must be used as the type parameter for some local type
18+
}
19+
20+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct<T>`)
2+
--> $DIR/impl[t]-foreign[fundamental[t]]-for-foreign.rs:12:1
3+
|
4+
LL | impl<T> Remote1<Box<T>> for u32 {
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type parameter `T` must be used as the type parameter for some local type
6+
|
7+
= note: only traits defined in the current crate can be implemented for a type parameter
8+
9+
error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct<T>`)
10+
--> $DIR/impl[t]-foreign[fundamental[t]]-for-foreign.rs:16:1
11+
|
12+
LL | impl<'a, T> Remote1<&'a T> for u32 {
13+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type parameter `T` must be used as the type parameter for some local type
14+
|
15+
= note: only traits defined in the current crate can be implemented for a type parameter
16+
17+
error: aborting due to 2 previous errors
18+
19+
For more information about this error, try `rustc --explain E0210`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#![feature(re_rebalance_coherence)]
2+
3+
// compile-flags:--crate-name=test
4+
// aux-build:coherence_lib.rs
5+
6+
extern crate coherence_lib as lib;
7+
use lib::*;
8+
use std::rc::Rc;
9+
10+
struct Local;
11+
12+
impl<'a, T> Remote1<Box<T>> for &'a T {
13+
//~^ ERROR type parameter `T` must be used as the type parameter for some local type
14+
}
15+
impl<'a, T> Remote1<&'a T> for Box<T> {
16+
//~^ ERROR type parameter `T` must be used as the type parameter for some local type
17+
}
18+
19+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct<T>`)
2+
--> $DIR/impl[t]-foreign[fundamental[t]]-for-fundamental[t].rs:12:1
3+
|
4+
LL | impl<'a, T> Remote1<Box<T>> for &'a T {
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type parameter `T` must be used as the type parameter for some local type
6+
|
7+
= note: only traits defined in the current crate can be implemented for a type parameter
8+
9+
error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct<T>`)
10+
--> $DIR/impl[t]-foreign[fundamental[t]]-for-fundamental[t].rs:15:1
11+
|
12+
LL | impl<'a, T> Remote1<&'a T> for Box<T> {
13+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type parameter `T` must be used as the type parameter for some local type
14+
|
15+
= note: only traits defined in the current crate can be implemented for a type parameter
16+
17+
error: aborting due to 2 previous errors
18+
19+
For more information about this error, try `rustc --explain E0210`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#![feature(re_rebalance_coherence)]
2+
3+
// compile-flags:--crate-name=test
4+
// aux-build:coherence_lib.rs
5+
// check-pass
6+
7+
extern crate coherence_lib as lib;
8+
use lib::*;
9+
use std::rc::Rc;
10+
11+
struct Local;
12+
13+
impl<T> Remote1<Box<T>> for Local {}
14+
15+
impl<'a, T> Remote1<&'a T> for Local {}
16+
17+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#![feature(re_rebalance_coherence)]
2+
3+
// compile-flags:--crate-name=test
4+
// aux-build:coherence_lib.rs
5+
6+
extern crate coherence_lib as lib;
7+
use lib::*;
8+
use std::rc::Rc;
9+
10+
struct Local;
11+
12+
impl<T> Remote1<Box<T>> for T {
13+
//~^ ERROR type parameter `T` must be used as the type parameter for some local type
14+
}
15+
impl<'a, T> Remote1<&'a T> for T {
16+
//~^ ERROR type parameter `T` must be used as the type parameter for some local type
17+
}
18+
19+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct<T>`)
2+
--> $DIR/impl[t]-foreign[fundamental[t]]-for-t.rs:12:1
3+
|
4+
LL | impl<T> Remote1<Box<T>> for T {
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type parameter `T` must be used as the type parameter for some local type
6+
|
7+
= note: only traits defined in the current crate can be implemented for a type parameter
8+
9+
error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct<T>`)
10+
--> $DIR/impl[t]-foreign[fundamental[t]]-for-t.rs:15:1
11+
|
12+
LL | impl<'a, T> Remote1<&'a T> for T {
13+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type parameter `T` must be used as the type parameter for some local type
14+
|
15+
= note: only traits defined in the current crate can be implemented for a type parameter
16+
17+
error: aborting due to 2 previous errors
18+
19+
For more information about this error, try `rustc --explain E0210`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#![feature(re_rebalance_coherence)]
2+
3+
// compile-flags:--crate-name=test
4+
// aux-build:coherence_lib.rs
5+
// check-pass
6+
7+
extern crate coherence_lib as lib;
8+
use lib::*;
9+
use std::rc::Rc;
10+
11+
struct Local;
12+
struct Local2<T>(Rc<T>);
13+
14+
impl<T> Remote2<Local, Box<T>> for u32 {}
15+
impl<'a, T> Remote2<Local, &'a T> for u32 {}
16+
impl<T> Remote2<Local2<T>, Box<T>> for u32 {}
17+
impl<'a, T> Remote2<Local2<T>, &'a T> for u32 {}
18+
19+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#![feature(re_rebalance_coherence)]
2+
3+
// compile-flags:--crate-name=test
4+
// aux-build:coherence_lib.rs
5+
// check-pass
6+
7+
extern crate coherence_lib as lib;
8+
use lib::*;
9+
use std::rc::Rc;
10+
11+
struct Local;
12+
13+
impl<T> Remote1<Local> for Rc<T> {}
14+
impl<T> Remote1<Local> for Vec<Box<T>> {}
15+
16+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#![feature(re_rebalance_coherence)]
2+
3+
// compile-flags:--crate-name=test
4+
// aux-build:coherence_lib.rs
5+
6+
extern crate coherence_lib as lib;
7+
use lib::*;
8+
use std::rc::Rc;
9+
10+
struct Local;
11+
12+
impl<T> Remote1<Local> for Box<T> {
13+
//~^ ERROR type parameter `T` must be used as the type parameter for some local type
14+
}
15+
16+
impl<T> Remote1<Local> for &T {
17+
//~^ ERROR type parameter `T` must be used as the type parameter for some local type
18+
}
19+
20+
fn main() {}

0 commit comments

Comments
 (0)