Skip to content

Commit

Permalink
Rollup merge of rust-lang#64546 - weiznich:bugfix/rfc-2451-rerebalanc…
Browse files Browse the repository at this point in the history
…e-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
  • Loading branch information
tmandry authored Sep 20, 2019
2 parents 50df43d + 31b3012 commit 5edb619
Show file tree
Hide file tree
Showing 33 changed files with 529 additions and 15 deletions.
10 changes: 9 additions & 1 deletion src/librustc/traits/coherence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,15 @@ fn orphan_check_trait_ref<'tcx>(
// Let Ti be the first such type.
// - No uncovered type parameters P1..=Pn may appear in T0..Ti (excluding Ti)
//
for input_ty in trait_ref.input_types() {
fn uncover_fundamental_ty(ty: Ty<'_>) -> Vec<Ty<'_>> {
if fundamental_ty(ty) {
ty.walk_shallow().flat_map(|ty| uncover_fundamental_ty(ty)).collect()
} else {
vec![ty]
}
}

for input_ty in trait_ref.input_types().flat_map(uncover_fundamental_ty) {
debug!("orphan_check_trait_ref: check ty `{:?}`", input_ty);
if ty_is_local(tcx, input_ty, in_crate) {
debug!("orphan_check_trait_ref: ty_is_local `{:?}`", input_ty);
Expand Down
17 changes: 17 additions & 0 deletions src/test/ui/coherence/impl-foreign[foreign]-for-foreign.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#![feature(re_rebalance_coherence)]

// compile-flags:--crate-name=test
// aux-build:coherence_lib.rs

extern crate coherence_lib as lib;
use lib::*;
use std::rc::Rc;

struct Local;

impl Remote1<u32> for f64 {
//~^ ERROR only traits defined in the current crate
// | can be implemented for arbitrary types [E0117]
}

fn main() {}
12 changes: 12 additions & 0 deletions src/test/ui/coherence/impl-foreign[foreign]-for-foreign.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
--> $DIR/impl-foreign[foreign]-for-foreign.rs:12:1
|
LL | impl Remote1<u32> for f64 {
| ^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate
|
= note: the impl does not reference only types defined in this crate
= note: define and implement a trait or new type instead

error: aborting due to previous error

For more information about this error, try `rustc --explain E0117`.
16 changes: 16 additions & 0 deletions src/test/ui/coherence/impl-foreign[foreign]-for-local.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#![feature(re_rebalance_coherence)]

// compile-flags:--crate-name=test
// aux-build:coherence_lib.rs
// check-pass

extern crate coherence_lib as lib;
use lib::*;
use std::rc::Rc;

struct Local;

impl Remote1<u32> for Local {
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#![feature(re_rebalance_coherence)]

// check-pass
// compile-flags:--crate-name=test
// aux-build:coherence_lib.rs

extern crate coherence_lib as lib;
use lib::*;
use std::rc::Rc;

struct Local;
impl<T> Remote2<Rc<T>, Local> for usize { }

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#![feature(re_rebalance_coherence)]

// compile-flags:--crate-name=test
// aux-build:coherence_lib.rs

extern crate coherence_lib as lib;
use lib::*;
use std::rc::Rc;

struct Local;

impl<T> Remote1<u32> for Box<T> {
//~^ ERROR type parameter `T` must be used as the type parameter for some local type
}

impl<'a, T> Remote1<u32> for &'a T {
//~^ ERROR type parameter `T` must be used as the type parameter for some local type
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct<T>`)
--> $DIR/impl[t]-foreign[foreign]-for-fundamental[t].rs:12:1
|
LL | impl<T> Remote1<u32> for Box<T> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type parameter `T` must be used as the type parameter for some local type
|
= note: only traits defined in the current crate can be implemented for a type parameter

error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct<T>`)
--> $DIR/impl[t]-foreign[foreign]-for-fundamental[t].rs:16:1
|
LL | impl<'a, T> Remote1<u32> for &'a T {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type parameter `T` must be used as the type parameter for some local type
|
= note: only traits defined in the current crate can be implemented for a type parameter

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0210`.
16 changes: 16 additions & 0 deletions src/test/ui/coherence/impl[t]-foreign[foreign]-for-t.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#![feature(re_rebalance_coherence)]

// compile-flags:--crate-name=test
// aux-build:coherence_lib.rs

extern crate coherence_lib as lib;
use lib::*;
use std::rc::Rc;

struct Local;

impl<T> Remote1<u32> for T {
//~^ ERROR type parameter `T` must be used as the type parameter for some local type
}

fn main() {}
11 changes: 11 additions & 0 deletions src/test/ui/coherence/impl[t]-foreign[foreign]-for-t.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct<T>`)
--> $DIR/impl[t]-foreign[foreign]-for-t.rs:12:1
|
LL | impl<T> Remote1<u32> for T {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ type parameter `T` must be used as the type parameter for some local type
|
= note: only traits defined in the current crate can be implemented for a type parameter

error: aborting due to previous error

For more information about this error, try `rustc --explain E0210`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#![feature(re_rebalance_coherence)]

// compile-flags:--crate-name=test
// aux-build:coherence_lib.rs

extern crate coherence_lib as lib;
use lib::*;
use std::rc::Rc;

struct Local;

impl<T> Remote2<Box<T>, Local> for u32 {
//~^ ERROR type parameter `T` must be used as the type parameter for some local type
}

impl<'a, T> Remote2<&'a T, Local> for u32 {
//~^ ERROR type parameter `T` must be used as the type parameter for some local type
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct<T>`)
--> $DIR/impl[t]-foreign[fundamental[t],local]-for-foreign.rs:12:1
|
LL | impl<T> Remote2<Box<T>, Local> for u32 {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type parameter `T` must be used as the type parameter for some local type
|
= note: only traits defined in the current crate can be implemented for a type parameter

error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct<T>`)
--> $DIR/impl[t]-foreign[fundamental[t],local]-for-foreign.rs:16:1
|
LL | impl<'a, T> Remote2<&'a T, Local> for u32 {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type parameter `T` must be used as the type parameter for some local type
|
= note: only traits defined in the current crate can be implemented for a type parameter

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0210`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#![feature(re_rebalance_coherence)]

// compile-flags:--crate-name=test
// aux-build:coherence_lib.rs

extern crate coherence_lib as lib;
use lib::*;
use std::rc::Rc;

struct Local;

impl<T> Remote1<Box<T>> for u32 {
//~^ ERROR type parameter `T` must be used as the type parameter for some local type
}

impl<'a, T> Remote1<&'a T> for u32 {
//~^ ERROR type parameter `T` must be used as the type parameter for some local type
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct<T>`)
--> $DIR/impl[t]-foreign[fundamental[t]]-for-foreign.rs:12:1
|
LL | impl<T> Remote1<Box<T>> for u32 {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type parameter `T` must be used as the type parameter for some local type
|
= note: only traits defined in the current crate can be implemented for a type parameter

error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct<T>`)
--> $DIR/impl[t]-foreign[fundamental[t]]-for-foreign.rs:16:1
|
LL | impl<'a, T> Remote1<&'a T> for u32 {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type parameter `T` must be used as the type parameter for some local type
|
= note: only traits defined in the current crate can be implemented for a type parameter

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0210`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#![feature(re_rebalance_coherence)]

// compile-flags:--crate-name=test
// aux-build:coherence_lib.rs

extern crate coherence_lib as lib;
use lib::*;
use std::rc::Rc;

struct Local;

impl<'a, T> Remote1<Box<T>> for &'a T {
//~^ ERROR type parameter `T` must be used as the type parameter for some local type
}
impl<'a, T> Remote1<&'a T> for Box<T> {
//~^ ERROR type parameter `T` must be used as the type parameter for some local type
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct<T>`)
--> $DIR/impl[t]-foreign[fundamental[t]]-for-fundamental[t].rs:12:1
|
LL | impl<'a, T> Remote1<Box<T>> for &'a T {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type parameter `T` must be used as the type parameter for some local type
|
= note: only traits defined in the current crate can be implemented for a type parameter

error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct<T>`)
--> $DIR/impl[t]-foreign[fundamental[t]]-for-fundamental[t].rs:15:1
|
LL | impl<'a, T> Remote1<&'a T> for Box<T> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type parameter `T` must be used as the type parameter for some local type
|
= note: only traits defined in the current crate can be implemented for a type parameter

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0210`.
17 changes: 17 additions & 0 deletions src/test/ui/coherence/impl[t]-foreign[fundamental[t]]-for-local.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#![feature(re_rebalance_coherence)]

// compile-flags:--crate-name=test
// aux-build:coherence_lib.rs
// check-pass

extern crate coherence_lib as lib;
use lib::*;
use std::rc::Rc;

struct Local;

impl<T> Remote1<Box<T>> for Local {}

impl<'a, T> Remote1<&'a T> for Local {}

fn main() {}
19 changes: 19 additions & 0 deletions src/test/ui/coherence/impl[t]-foreign[fundamental[t]]-for-t.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#![feature(re_rebalance_coherence)]

// compile-flags:--crate-name=test
// aux-build:coherence_lib.rs

extern crate coherence_lib as lib;
use lib::*;
use std::rc::Rc;

struct Local;

impl<T> Remote1<Box<T>> for T {
//~^ ERROR type parameter `T` must be used as the type parameter for some local type
}
impl<'a, T> Remote1<&'a T> for T {
//~^ ERROR type parameter `T` must be used as the type parameter for some local type
}

fn main() {}
19 changes: 19 additions & 0 deletions src/test/ui/coherence/impl[t]-foreign[fundamental[t]]-for-t.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct<T>`)
--> $DIR/impl[t]-foreign[fundamental[t]]-for-t.rs:12:1
|
LL | impl<T> Remote1<Box<T>> for T {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type parameter `T` must be used as the type parameter for some local type
|
= note: only traits defined in the current crate can be implemented for a type parameter

error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct<T>`)
--> $DIR/impl[t]-foreign[fundamental[t]]-for-t.rs:15:1
|
LL | impl<'a, T> Remote1<&'a T> for T {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type parameter `T` must be used as the type parameter for some local type
|
= note: only traits defined in the current crate can be implemented for a type parameter

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0210`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#![feature(re_rebalance_coherence)]

// compile-flags:--crate-name=test
// aux-build:coherence_lib.rs
// check-pass

extern crate coherence_lib as lib;
use lib::*;
use std::rc::Rc;

struct Local;
struct Local2<T>(Rc<T>);

impl<T> Remote2<Local, Box<T>> for u32 {}
impl<'a, T> Remote2<Local, &'a T> for u32 {}
impl<T> Remote2<Local2<T>, Box<T>> for u32 {}
impl<'a, T> Remote2<Local2<T>, &'a T> for u32 {}

fn main() {}
16 changes: 16 additions & 0 deletions src/test/ui/coherence/impl[t]-foreign[local]-for-foreign.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#![feature(re_rebalance_coherence)]

// compile-flags:--crate-name=test
// aux-build:coherence_lib.rs
// check-pass

extern crate coherence_lib as lib;
use lib::*;
use std::rc::Rc;

struct Local;

impl<T> Remote1<Local> for Rc<T> {}
impl<T> Remote1<Local> for Vec<Box<T>> {}

fn main() {}
20 changes: 20 additions & 0 deletions src/test/ui/coherence/impl[t]-foreign[local]-for-fundamental[t].rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#![feature(re_rebalance_coherence)]

// compile-flags:--crate-name=test
// aux-build:coherence_lib.rs

extern crate coherence_lib as lib;
use lib::*;
use std::rc::Rc;

struct Local;

impl<T> Remote1<Local> for Box<T> {
//~^ ERROR type parameter `T` must be used as the type parameter for some local type
}

impl<T> Remote1<Local> for &T {
//~^ ERROR type parameter `T` must be used as the type parameter for some local type
}

fn main() {}
Loading

0 comments on commit 5edb619

Please sign in to comment.