Skip to content
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

Implement the Re-rebalance coherence RFC #56145

Merged
merged 13 commits into from
Jan 5, 2019

Conversation

weiznich
Copy link
Contributor

This is the first time I touch anything in the compiler so just tell me if I got something wrong.

Big thanks to @sgrif for the pointers where to look for those things.
cc #55437

@rust-highfive
Copy link
Collaborator

r? @varkor

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 21, 2018
@rust-highfive

This comment has been minimized.

Copy link
Member

@varkor varkor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't checked over the tests yet, but the code looks good. I'll try to look at the tests soon.

impls are allowed in crates.
The following rule is used:

Given `impl<P1..=Pn> Trait<T1..=Tn> for T0`, an impl is valid only if at
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this "if and only if"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's directly copied from the RFC. I think it should be "if and only if" but's not written there. (cc @sgrif who has written that thing)

src/librustc/traits/coherence.rs Outdated Show resolved Hide resolved
@weiznich
Copy link
Contributor Author

@varkor I've addressed your review comments.

@bors

This comment has been minimized.

@varkor
Copy link
Member

varkor commented Dec 1, 2018

Sorry about the delay @weiznich. I'll get to this soon.

@weiznich
Copy link
Contributor Author

weiznich commented Dec 3, 2018

@varkor I've rebased the PR.

@@ -393,6 +393,9 @@ declare_features! (
// `extern` in paths
(active, extern_in_paths, "1.23.0", Some(55600), None),

// Use `?` as the Kleene "at most one" operator
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You seem to have accidentally pulled in some extra changes with the rebase.

@varkor
Copy link
Member

varkor commented Dec 5, 2018

At the moment, the fact that all the coherence tests have been duplicated under the new feature flag seems a little excessive. I'm not quite sure what the correct approach here is though: we do want to make sure we don't break anything. I wonder if it would be appropriate to run the tests in two modes, a bit like NLL does at the moment. Alternatively, we could have a few tests that cover a representative sample of existing cases, under the assumption that the algorithm is mostly the same anyway and when stabilised, the existing tests are going to come into effect anyway.

Could you point out which tests are new (and demonstrate the new behaviour), so I can check those in particular?

I think @nikomatsakis will have better ideas about the right solution re. tests, so I'm going to reassign. The actual change looks good to me, though (once the rebase issues are fixed).

r? @nikomatsakis

@rust-highfive rust-highfive assigned nikomatsakis and unassigned varkor Dec 5, 2018
@weiznich
Copy link
Contributor Author

weiznich commented Dec 6, 2018

Could you point out which tests are new (and demonstrate the new behaviour), so I can check those in particular?

This one and this one is new. All other tests are just a copied version of the old coherence tests with the re_rebalance feature enabled.

At the moment, the fact that all the coherence tests have been duplicated under the new feature flag seems a little excessive. I'm not quite sure what the correct approach here is though: we do want to make sure we don't break anything. I wonder if it would be appropriate to run the tests in two modes, a bit like NLL does at the moment. Alternatively, we could have a few tests that cover a representative sample of existing cases, under the assumption that the algorithm is mostly the same anyway and when stabilised, the existing tests are going to come into effect anyway.

I'm not sure what would be a representative sample of the existing test cases here, nor I'm knowing what needs to be changed to run the existing tests using two modes. Would be great to get some more input here.

@weiznich weiznich force-pushed the re_rebalance_coherence branch 2 times, most recently from 06c2a37 to 8a97a74 Compare December 6, 2018 11:36
@rust-highfive

This comment has been minimized.

@bors

This comment has been minimized.

@weiznich
Copy link
Contributor Author

weiznich commented Dec 6, 2018

I'm not sure why those 2 tests fail. The corresponding .stderr files containing exactly those error messages...

@rust-highfive

This comment has been minimized.

@weiznich
Copy link
Contributor Author

@varkor @nikomatsakis Any news here?

Copy link
Contributor

@nikomatsakis nikomatsakis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems great! I would like before r+'ing though to spend a bit more time checking over the tests.

struct Oracle;
impl Backend for Oracle {}
impl<'a, T:'a, Tab> QueryFragment<Oracle> for BatchInsert<'a, T, Tab> {}
// ~^ ERROR E0210
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment needs to be //~^ -- no space

@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-5.0 of your PR failed on Travis (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
travis_time:end:0e6e87c0:start=1544786423331187056,finish=1544786477558750623,duration=54227563567
$ git checkout -qf FETCH_HEAD
travis_fold:end:git.checkout

Encrypted environment variables have been removed for security reasons.
See https://docs.travis-ci.com/user/pull-requests/#Pull-Requests-and-Security-Restrictions
$ export SCCACHE_BUCKET=rust-lang-ci-sccache2
$ export SCCACHE_REGION=us-west-1
Setting environment variables from .travis.yml
$ export IMAGE=x86_64-gnu-llvm-5.0
---
472 ./src/libstd/sys/unix
468 ./src/test/ui/resolve
460 ./src/test/ui/rust-2018
448 ./src/test/ui/traits
448 ./src/test/ui/re_rebalance_coherence
444 ./src/test/ui/privacy
436 ./src/librustc_resolve
420 ./src/doc/unstable-book
416 ./src/test/ui/associated-types
---
[00:43:45] .................................................................................................... 1100/5225
[00:43:47] .................................................................................................... 1200/5225
[00:43:49] .................................................................................................... 1300/5225
[00:43:52] .................................................................................................... 1400/5225
[00:43:54] ................................................................................F................... 1500/5225
[00:43:57] ............................i....................................................................i.. 1600/5225
[00:44:03] .................................................................................................... 1800/5225
[00:44:06] .................................................................................................... 1900/5225
[00:44:09] ........................................i........................................................... 2000/5225
[00:44:13] .................................................................................................... 2100/5225
---
[00:45:06] ...................................................i................................................ 3700/5225
[00:45:07] .................................................................................................... 3800/5225
[00:45:09] ........i........................................................................................... 3900/5225
[00:45:13] .................................................................................................... 4000/5225
[00:45:21] .......................................................................................FF........F.. 4100/5225
[00:45:25] ..........F......................................................................................... 4200/5225
[00:45:31] ..............................................................................................i..... 4400/5225
[00:45:36] .................................................................................................... 4500/5225
[00:45:40] .................................................................................................... 4600/5225
[00:45:43] .................................................................................................... 4700/5225
[00:45:43] .................................................................................................... 4700/5225
[00:45:47] ................................................................................i................... 4800/5225
[00:45:50] .................................................................................................... 4900/5225
[00:45:53] .................................................................................................... 5000/5225
[00:45:56] .................................................................................................... 5100/5225
[00:45:58] ................................................................i................................... 5200/5225
86_64-unknown-linux-gnu" "--error-format" "json" "-Zui-testing" "-C" "prefer-dynamic" "-o" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/feature-gates/feature-gate-re-rebalance-coherence/a" "-Crpath" "-O" "-Zunstable-options" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/feature-gates/feature-gate-re-rebalance-coherence/auxiliary" "-A" "unused"
[00:45:59] ------------------------------------------
[00:45:59] 
[00:45:59] ------------------------------------------
[00:45:59] stderr:
[00:45:59] stderr:
[00:45:59] ------------------------------------------
[00:45:59] {"message":"type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct<T>`)","code":{"code":"E0210","explanation":"\nThis error indicates a violation of one of Rust's orphan rules for trait\nimplementations. The rule concerns the use of type parameters in an\nimplementation of a foreign trait (a trait defined in another crate), and\nstates that type parameters must be \"covered\" by a local type. To understand\nwhat this means, it is perhaps easiest to consider a few examples.\n\nIf `ForeignTrait` is a trait defined in some external crate `foo`, then the\nfollowing trait `impl` is an error:\n\n```compile_fail,E0210\n# #[cfg(for_demonstration_only)]\nextern crate foo;\n# #[cfg(for_demonstration_only)]\nuse foo::ForeignTrait;\n# use std::panic::UnwindSafe as ForeignTrait;\n\nimpl<T> ForeignTrait for T { } // error\n# fn main() {}\n```\n\nTo work around this, it can be covered with a local type, `MyType`:\n\n```\n# use std::panic::on the design of the orphan rules, see [RFC 1023].\n\n[RFC 1023]: https://github.com/rust-lang/rfcs/blob/master/text/1023-rebalancing-coherence.md\n"},"level":"error","spans":[{"file_name":"/checkout/src/test/ui/feature-gates/feature-gate-re-rebalance-coherence.rs","byte_start":226,"byte_end":295,"line_start":10,"line_end":10,"column_start":1,"column_end":70,"is_primary":true,"text":[{"text":"impl<'a, T:'a, Tab> QueryFragment<Oracle> for BatchInsert<'a, T, Tab> {}","highlight_start":1,"highlight_end":70}],"label":"type parameter `T` must be used as the type parameter for some local type","suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[{"message":"only traits defined in the current crate can be implemented for a type parameter","code":null,"level":"note","spans":[],"children":[],"rendered":null}],"rendered":"error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct<T>`)\n  --> /checkout/src/test/ui/feature-gates/feature-gate-re-rebalance-coherence.rs:10:1\n   |\nLL | impl<'a, T:'a, Tab> QueryFragment<Oracle> for BatchInsert<'a, T, Tab> {}\n   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type parameter `T` must be used as the type parameter for some local type\n   |\n   = note: only traits defined in the current crate can be implemented for a type parameter\n\n"}
[00:45:59] {"message":"aborting due to previous error","code":null,"level":"error","spans":[],"children":[],"rendered":"error: aborting due to previous error\n\n"}
[00:45:59] {"message":"For more information about this error, try `rustc --explain E0210`.","code":null,"level":"","spans":[],"children":[],"rendered":"For more information about this error, try `rustc --explain E0210`.\n"}
[00:45:59] ------------------------------------------
[00:45:59] 
[00:45:59] 
[00:45:59] thread '[ui] ui/feature-gates/feature-gate-re-rebalance-coherence.rs' panicked at 'explicit panic', src/tools/compiletest/src/runtest.rs:3252:9
[00:45:59] 
[00:45:59] 
[00:45:59] ---- [ui] ui/re_rebalance_coherence/coherence-all-remote.rs stdout ----
[00:45:59] 
[00:45:59] 
[00:45:59] - error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g. `MyStruct<T>`)
[00:45:59] + error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct<T>`)
[00:45:59] 2   --> $DIR/coherence-all-remote.rs:18:1
[00:45:59] 3    |
[00:45:59] 4 LL | impl<T> Remote1<T> for isize { }
[00:45:59] 
[00:45:59] The actual stderr differed from the expected stderr.
[00:45:59] The actual stderr differed from the expected stderr.
[00:45:59] Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/re_rebalance_coherence/coherence-all-remote/coherence-all-remote.stderr
[00:45:59] To update references, rerun the tests and pass the `--bless` flag
[00:45:59] To only update this specific test, also pass `--test-args re_rebalance_coherence/coherence-all-remote.rs`
[00:45:59] error: 1 errors occurred comparing output.
[00:45:59] status: exit code: 1
[00:45:59] status: exit code: 1
[00:45:59] command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/ui/re_rebalance_coherence/coherence-all-remote.rs" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "-Zui-testing" "-C" "prefer-dynamic" "-o" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/re_rebalance_coherence/coherence-all-remote/a" "-Crpath" "-O" "-Zunstable-options" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/re_rebalance_coherence/coherence-all-remote/auxiliary" "-A" "unused"
[00:45:59] ------------------------------------------
[00:45:59] 
[00:45:59] ------------------------------------------
[00:45:59] stderr:
[00:45:59] stderr:
[00:45:59] ------------------------------------------
[00:45:59] {"message":"type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct<T>`)","code":{"code":"E0210","explanation":"\nThis error indicates a violation of one of Rust's orphan rules for trait\nimplementations. The rule concerns the use of type parameters in an\nimplementation of a foreign trait (a trait defined in another crate), and\nstates that type parameters must be \"covered\" by a local type. To understand\nwhat this means, it is perhaps easiest to consider a few examples.\n\nIf `ForeignTrait` is a trait defined in some external crate `foo`, then the\nfollowing trait `impl` is an error:\n\n```compile_fail,E0210\n# #[cfg(for_demonstration_only)]\nextern crate foo;\n# #[cfg(for_demonstration_only)]\nuse foo::ForeignTrait;\n# use std::panic::UnwindSafe as ForeignTrait;\n\nimpl<T> ForeignTrait for T { } // error\n# fn main() {}\n```\n\nTo work around this, it can be covered with a local type, `MyType`:\n\n```\n# use std::panic::UnwindSafe as ForeignTrait;\nstruct MyType<T>(T);\nimpl<T> ForeignTrait for MyType<T> { } // Ok\n```\n\nPlease note that a type alias is not sufficient.\n\nFor another example of an error, suppose there's another trait defined in `foo`\nnamed `ForeignTrait2` that takes two type parameters. Then this `impl` results\nin the same rule violation:\n\n```ignore (cannot-doctest-multicrate-project)\nstruct MyType2;\nimpl<T> ForeignTrait2<T, MyType<T>> for MyType2 { } // error\n```\n\nThe reason for this is that there are two appearances of type parameter `T` in\nthe `impl` header, both as parameters for `ForeignTrait2`. The first appearance\nis uncovered, and so runs afoul of the orphan rule.\n\nConsider one more example:\n\n```ignore (cannot-doctest-multicrate-project)\nimpl<T> ForeignTrait2<MyType<T>, T> for MyType2 { } // Ok\n```\n\nThis only differs from the previous `impl` in that the parameters `T` and\n`MyType<T>` for `ForeignTrait2` have been swapped. This example does *not*\nviolate the orphan rule; it is permitted.\n\nTo see why that last example was allowed, you need to understand the general\nrule. Unfortunately this rule is a bit tricky to state. Consider an `impl`:\n\n```ignore (only-for-syntax-highlight)\nimpl<P1, ..., Pm> ForeignTrait<T1, ..., Tn> for T0 { ... }\n```\n\nwhere `P1, ..., Pm` are the type parameters of the `impl` and `T0, ..., Tn`\nare types. One of the types `T0, ..., Tn` must be a local type (this is another\norphan rule, see the explanation for E0117). Let `i` be the smallest integer\nsuch that `Ti` is a local type. Then no type parameter can appear in any of the\n`Tj` for `j < i`.\n\nFor information on the design of the orphan rules, see [RFC 1023].\n\n[RFC 1023]: https://github.com/rust-lang/rfcs/blob/master/text/1023-rebalancing-coherence.md\n"},"level":"error","spans":[{"file_name":"/checkout/src/test/ui/re_rebalance_coherence/coherence-all-remote.rs","byte_start":589,"byte_end":617,"line_start":18,"line_end":18,"column_start":1,"column_end":29,"is_primary":true,"text":[{"text":"impl<T> Remote1<T> for isize { }","highlight_start":1,"highlight_end":29}],"label":"type parameter `T` must be used as the type parameter for some local type","suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[{"message":"only traits defined in the current crate can be implemented for a type parameter","code":null,"level":"note","spans":[],"children":[],"rendered":null}],"rendered":"error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct<T>`)\n  --> /checkout/src/test/ui/re_rebalance_coherence/coherence-all-remote.rs:18:1\n   |\nLL | impl<T> Remote1<T> for isize { }\n   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type parameter `T` must be used as the type parameter for some local type\n   |\n   = note: only traits defined in the current crate can be implemented for a type parameter\n\n"}
[00:45:59] {"message":"aborting due to previous error","code":null,"level":"error","spans":[],"children":[],"rendered":"error: aborting due to previous error\n\n"}
[00:45:59] {"message":"For more information about this error, try `rustc --explain E0210`.","code":null,"level":"","spans":[],"children":[],"rendered":"For more information about this error, try `rustc --explain E0210`.\n"}t-param/a" "-Crpath" "-O" "-Zunstable-options" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/re_rebalance_coherence/coherence-bigint-param/auxiliary" "-A" "unused"
[00:45:59] ------------------------------------------
[00:45:59] 
[00:45:59] ------------------------------------------
[00:45:59] stderr:
[00:45:59] stderr:
[00:45:59] ------------------------------------------
[00:45:59] {"message":"type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct<T>`)","code":{"code":"E0210","explanation":"\nThis error indicates a violation of one of Rust's orphan rules for trait\nimplementations. The rule concerns the use of type parameters in an\nimplementation of a foreign trait (a trait defined in another crate), and\nstates that type parameters must be \"covered\" by a local type. To understand\nwhat this means, it is perhaps easiest to consider a few examples.\n\nIf `ForeignTrait` is a trait defined in some external crate `foo`, then the\nfollowing trait `impl` is an error:\n\n```compile_fail,E0210\n# #[cfg(for_demonstration_only)]\nextern crate foo;\n# #[cfg(for_demonstration_only)]\nuse foo::ForeignTrait;\n# use std::panic::UnwindSafe as ForeignTrait;\n\nimpl<T> ForeignTrait for T { } // error\n# fn main() {}\n```\n\nTo work around this, it can be covered with a local type, `MyType`:\n\n```\n# use std::panic::UnwindSafe as ForeignTrait;\nstruct MyType<T>(T);\nimpl<T> ForeignTrait for MyType<T> { } // Ok\n```\n\nPlease note that a type alias is not sufficient.\n\nFor another example of an error, suppose there's another trait defined in `foo`\nnamed `ForeignTrait2` that takes two type parameters. Then this `impl` results\nin the same rule violation:\n\n```ignore (cannot-doctest-multicrate-project)\nstruct MyType2;\nimpl<T> ForeignTrait2<T, MyType<T>> for MyType2 { } // error\n```\n\nThe reason for this is that there are two appearances of type parameter `T` in\nthe `impl` header, both as parameters for `ForeignTrait2`. The first appearance\nis uncovered, and so runs afoul of the orphan rule.\n\nConsider one more example:\n\n```ignore (cannot-doctest-multicrate-project)\nimpl<T> ForeignTrait2<MyType<T>, T> for MyType2 { } // Ok\n```\n\nThis only differs from the previous `impl` in that the parameters `T` and\n`MyType<T>` for `ForeignTrait2` have been swapped. This example does *not*\nviolate the orphan rule; it is permitted.\n\nTo see why that last example was allowed, you need to understand the general\nrule. Unfortunately this rule is a bit tricky to state. Consider an `impl`:\n\n```ignore (only-for-syntax-highlight)\nimpl<P1, ..., Pm> ForeignTrait<T1, ..., Tn> for T0 { ... }\n```\n\nwhere `P1, ..., Pm` are the type parameters of the `impl` and `T0, ..., Tn`\nare types. One of the types `T0, ..., Tn` must be a local type (this is another\norphan rule, see the explanation for E0117). Let `i` be the smallest integer\nsuch that `Ti` is a local type. Then no type parameter can appear in any of the\n`Tj` for `j < i`.\n\nFor information on the design of the orphan rules, see [RFC 1023].\n\n[RFC 1023]: https://github.com/rust-lang/rfcs/blob/master/text/1023-rebalancing-coherence.md\n"},"level":"error","spans":[{"file_name":"/checkout/src/test/ui/re_rebalance_coherence/coherence-bigint-param.rs","byte_start":609,"byte_end":638,"line_start":20,"line_end":20,"column_start":1,"column_end":30,"is_primary":true,"text":[{"text":"impl<T> Remote1<BigInt> for T { }","highlight_start":1,"highlight_end":30}],"label":"type parameter `T` must be used as the type parameter for some local type","suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[{"message":"only traits defined in the current crate can be implemented for a type parameter","code":null,"level":"note","spans":[],"children":[],"rendered":null}],"rendered":"error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct<T>`)\n  --> /checkout/src/test/ui/re_rebalance_coherence/coherence-bigint-param.rs:20:1\n   |\nLL | impl<T> Remote1<BigInt> for T { }\n   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type parameter `T` must be used as the type parameter for some local type\n   |\n   = note: only traits defined in the current crate can be implemented for a type parameter\n\n"}
[00:45:59] {"message":"aborting due to previous error","code":null,"level":"error","spans":[],"children":[],"rendered":"error: aborting due to previous error\n\n"}
[00:45:59] {"message":"For more information about this error, try `rustc --explain E0210`.","code":null,"level":"","spans":[],"children":[],"rendered":"For more information about this error, try `rustc --explain E0210`.\n"}
[00:45:59] ------------------------------------------
[00:45:59] 
[00:45:59] 
[00:45:59] thread '[ui] ui/re_rebalance_coherence/coherence-bigint-param.rs' panicked at 'explicite:\n\n```\ntrait MyTrait {\n    fn get(&self) -> usize;\n}\n\nimpl<T> MyTrait for T {\n    fn get(&self) -> usize { 0 }\n}\n\nstruct Foo;\n\nfn main() {\n    let f = Foo;\n\n    f.get(); // the trait is implemented so we can use it\n}\n```\n"},"level":"error","spans":[{"file_name":"/checkout/src/test/ui/re_rebalance_coherence/coherence-cross-crate-conflict.rs","byte_start":703,"byte_end":720,"line_start":20,"line_end":20,"column_start":1,"column_end":18,"is_primary":true,"text":[{"text":"impl<A> Foo for A {","highlight_start":1,"highlight_end":18}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[{"message":"conflicting implementation in crate `trait_impl_conflict`:\n- impl trait_impl_conflict::Foo for isize;","code":null,"level":"note","spans":[],"children":[],"rendered":null}],"rendered":"error[E0119]: conflicting implementations of trait `trait_impl_conflict::Foo` for type `isize`:\n  --> /checkout/src/test/ui/re_rebalance_coherence/coherence-cross-crate-conflict.rs:20:1\n   |\nLL | impl<A> Foo for A {\n   | ^^^^^^^^^^^^^^^^^\n   |\n   = note: conflicting implementation in crate `trait_impl_conflict`:\n           - impl trait_impl_conflict::Foo for isize;\n\n"}
[00:45:59] {"message":"type parameter `A` must be used as the type parameter for some local type (e.g., `MyStruct<A>`)","code":{"code":"E0210","explanation":"\nThis error indicates a violation of one of Rust's orphan rules for trait\nimplementations. The rule concerns the use of type parameters in an\nimplementation of a foreign trait (a trait defined in another crate), and\nstates that type parameters must be need to understand the general\nrule. Unfortunately this rule is a bit tricky to state. Consider an `impl`:\n\n```ignore (only-for-syntax-highlight)\nimpl<P1, ..., Pm> ForeignTrait<T1, ..., Tn> for T0 { ... }\n```\n\nwhere `P1, ..., Pm` are the type parameters of the `impl` and `T0, ..., Tn`\nare types. One of the types `T0, ..., Tn` must be a local type (this is another\norphan rule, see the explanation for E0117). Let `i` be the smallest integer\nsuch that `Ti` is a local type. Then no type parameter can appear in any of the\n`Tj` for `j < i`.\n\nFor information on the design of the orphan rules, see [RFC 1023].\n\n[RFC 1023]: https://github.com/rust-lang/rfcs/blob/master/text/1023-rebalancing-coherence.md\n"},"level":"error","spans":[{"file_name":"/checkout/src/test/ui/re_rebalance_coherence/coherence-cross-crate-conflict.rs","byte_start":703,"byte_end":720,"line_start":20,"line_end":20,"column_start":1,"column_end":18,"is_primary":true,"text":[{"text":"impl<A> Foo for A {","highlight_start":1,"highlight_end":18}],"label":"type parameter `A` must be used as the type parameter for some local type","suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[{"message":"only traits defined in the current crate can be implemented for a type parameter","code":null,"level":"note","spans":[],"children":[],"rendered":null}],"rendered":"error[E0210]: type parameter `A` must be used as the type parameter for some local type (e.g., `MyStruct<A>`)\n  --> /checkout/src/test/ui/re_rebalance_coherence/coherence-cross-crate-conflict.rs:20:1\n   |\nLL | impl<A> Foo for A {\n   | ^^^^^^^^^^^^^^^^^ type parameter `A` must be used as the type parameter for some local type\n   |\n   = note: only traits defined in the current crate can be implemented for a type parameter\n\n"}
[00:45:59] {"message":"aborting due to 2 previous errors","code":null,"level":"error","spans":[],"children":[],"rendered":"error: aborting due to 2 previous errors\n\n"}
[00:45:59] {"message":"Some errors occurred: E0119, E0210.","code":null,"level":"","spans":[],"children":[],"rendered":"Some errors occurred: E0119, E0210.\n"}
[00:45:59] {"message":"For more information about an error, try `rustc --explain E0119`.","code":null,"level":"","spans":[],"children":[],"rendered":"For more information about an error, try `rustc --explain E0119`.\n"}
[00:45:59] ------------------------------------------
[00:45:59] 
[00:45:59] 
[00:45:59] thread '[ui] ui/re_rebalance_coherence/coherence-cross-crate-conflict.rs' panicked at 'explicit panic', src/tools/compiletest/src/runtest.rs:3252:9
[00:45:59] 
[00:45:59] ---- [ui] ui/re_rebalance_coherence/coherence-lone-type-parameter.rs stdout ----
[00:45:59] 
[00:45:59] 
[00:45:59] - error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g. `MyStruct<T>`)
[00:45:59] + error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct<T>`)
[00:45:59] 2   --> $DIR/coherence-lone-type-parameter.rs:18:1
[00:45:59] 3    |
[00:45:59] 4 LL | impl<T> Remote for T { }
[00:45:59] 
[00:45:59] The actual stderr differed from the expected stderr.
[00:45:59] The actual stderr differed from the expected stderr.
[00:45:59] Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/re_rebalance_coherence/coherence-lone-type-parameter/coherence-lone-type-parameter.stderr
[00:45:59] To update references, rerun the tests and pass the `--bless` flag
[00:45:59] To only update this specific test, also pass `--test-args re_rebalance_coherence/coherence-lone-type-parameter.rs`
[00:45:59] error: 1 errors occurred comparing output.
[00:45:59] status: exit code: 1
[00:45:59] status: exit code: 1
[00:45:59] command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/ui/re_rebalance_coherence/coherence-lone-type-parameter.rs" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "-Zui-testing" "-C" "prefer-dynamic" "-o" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/re_rebalance_coherence/coherence-lone-type-parameter/a" "-Crpath" "-O" "-Zunstable-options" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/re_rebalance_coherence/coherence-lone-type-parameter/auxiliary" "-A" "unused"
[00:45:59] ------------------------------------------
[00:45:59] 
[00:45:59] ------------------------------------------
[00:45:59] stderr:
[00:45:59] stderr:
[00:45:59] ------------------------------------------
[00:45:59] {"message":"type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct<T>`)","code":{"code":"E0210","explanation":"\nThis error indicates a violation of one of Rust's orphan rules for trait\nimplementations. The rule concerns the use of type parameters in an\nimplementation of a foreign trait (a trait defined in another crate), and\nstates that type parameters must be \"covered\" by a local type. To understand\nwhat this means, it is perhaps easiest to consider a few examples.\n\nIf `ForeignTrait` is a trait defined in some external crate `foo`, then the\nfollowing trait `impl` is an error:\n\n```compile_fail,E0210\n# #[cfg(for_demonstration_only)]\nextern crate foo;\n# #[cfg(for_demonstration_only)]\nuse foo::ForeignTrait;\n# use std::panic::UnwindSafe as ForeignTrait;\n\nimpl<T> ForeignTrait for T { } // error\n# fn main() {}\n```\n\nTo work around this, it can be covered with a local type, `MyType`:\n\n```\n# use std::panic::UnwindSafe as ForeignTrait;\nstruct MyType<T>(T);\nimpl<T> ForeignTrait for MyType<T> { } // Ok\n```\n\nPlease note that a type alias is not sufficient.\n\nFor another example of an error, suppose there's another trait defined in `foo`\nnamed `ForeignTrait2` that takes two type parameters. Then this `impl` results\nin the same rule violation:\n\n```ignore (cannot-doctest-multicrate-project)\nstruct MyType2;\nimpl<T> ForeignTrait2<T, MyType<T>> for MyType2 { } // error\n```\n\nThe reason for this is that there are two appearances of type parameter `T` in\nthe `impl` header, both as parameters for `ForeignTrait2`. The first appearance\nis uncovered, and so runs afoul of the orphan rule.\n\nConsider one more example:\n\n```ignore (cannot-doctest-multicrate-project)\nimpl<T> ForeignTrait2<MyType<T>, T> for MyType2 { } // Ok\n```\n\nThis only differs from the previous `impl` in that the parameters `T` and\n`MyType<T>` for `ForeignTrait2` have been swapped. This example does *not*\nviolate the orphan rule; it is permitted.\n\nTo see why that last example was allowed, you need to understand the general\nrule. Unfortunately this rule is a bit tricky to state. Consider an `impl`:\n\n```ignore (only-for-syntax-highlight)\nimpl<P1, ..., Pm> ForeignTrait<T1, ..., Tn> for T0 { ... }\n```\n\nwhere `P1, ..., Pm` are the type parameters of the `impl` and `T0, ..., Tn`\nare types. One of the types `T0, ..., Tn` must be a local type (this is another\norphan rule, see the explanation for E0117). Let `i` be the smallest integer\nsuch that `Ti` is a local type. Then no type parameter can appear in any of the\n`Tj` for `j < i`.\n\nFor information on the design of the orphan rules, see [RFC 1023].\n\n[RFC 1023]: https://github.com/rust-lang/rfcs/blob/master/text/1023-rebalancing-coherence.md\n"},"level":"error","spans":[{"file_name":"/checkout/src/test/ui/re_rebalance_coherence/coherence-lone-type-parameter.rs","byte_start":588,"byte_end":608,"line_start":18,"line_end":18,"column_start":1,"column_end":21,"is_primary":true,"text":[{"text":"impl<T> Remote for T { }","highlight_start":1,"highlight_end":21}],"label":"type parameter `T` must be used as the type parameter for some local type","suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[{"message":"only traits defined in the current crate can be implemented for a type parameter","code":null,"level":"note","spans":[],"children":[],"rendered":null}],"rendered":"error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct<T>`)\n  --> /checkout/src/test/ui/re_rebalance_coherence/coherence-lone-type-parameter.rs:18:1\n   |\nLL | impl<T> Remote for T { }\n   | ^^^^^-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib" "--run-lib-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/x86_64-unknown-linux-gnu/lib" "--rustc-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "--src-base" "/checkout/src/test/ui" "--build-base" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui" "--stage-id" "stage2-x86_64-unknown-linux-gnu" "--mode" "ui" "--target" "x86_64-unknown-linux-gnu" "--host" "x86_64-unknown-linux-gnu" "--llvm-filecheck" "/usr/lib/llvm-5.0/bin/FileCheck" "--host-rustcflags" "-Crpath -O -Zunstable-options  -Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--target-rustcflags" "-Crpath -O -Zunstable-options  -Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--docck-python" "/usr/bin/python2.7" "--lldb-python" "/usr/bin/python2.7" "--gdb" "/usr/bin/gdb" "--quiet" "--llvm-version" "5.0.0\n" "--system-llvm" "--cc" "" "--cxx" "" "--cflags" "" "--llvm-components" "" "--llvm-cxxflags" "" "--adb-path" "adb" "--adb-test-dir" "/data/tmp/work" "--android-cross-path" "" "--color" "always"
[00:45:59] 
[00:45:59] 
[00:45:59] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test
[00:45:59] Build completed unsuccessfully in 0:03:47
[00:45:59] Build completed unsuccessfully in 0:03:47
[00:45:59] Makefile:58: recipe for target 'check' failed
[00:45:59] make: *** [check] Error 1
The command "stamp sh -x -c "$RUN_SCRIPT"" exited with 2.
travis_time:start:00dcfdc5
$ date && (curl -fs --head https://google.com | grep ^Date: | sed 's/Date: //g' || true)
Fri Dec 14 12:07:25 UTC 2018

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@weiznich
Copy link
Contributor Author

@nikomatsakis Tests are fixed.

@nikomatsakis
Copy link
Contributor

I forgot about this question that @varkor raised:

At the moment, the fact that all the coherence tests have been duplicated under the new feature flag seems a little excessive.

One option here is to rewrite the duplicated tests using revisions. The idea is to include a comment like:

// revisions: old new

This will cause the same test to be built twice, once with #[cfg(old)] and once with #[cfg(new)] in scope.

You can then do things like:

#![cfg_attr(new, feature(new_algorithm))]

@weiznich -- do you want to take a shot at collapsing the tests this way?

@weiznich
Copy link
Contributor Author

@nikomatsakis I will try that. What's the right strategy here? In that case there are already revisions.


#![feature(re_rebalance_coherence)]

// revisions: a b c
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, in this case you would have to add another set of three revisions, I suppose. e.g., a, re_a, b, re_b, c, re_c

@bors
Copy link
Contributor

bors commented Jan 3, 2019

☔ The latest upstream changes (presumably #55517) made this pull request unmergeable. Please resolve the merge conflicts.

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jan 3, 2019
@cramertj
Copy link
Member

cramertj commented Jan 4, 2019

@bors r=nikomatsakis

@bors
Copy link
Contributor

bors commented Jan 4, 2019

📌 Commit d758e4d has been approved by nikomatsakis

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jan 4, 2019
@bors
Copy link
Contributor

bors commented Jan 5, 2019

⌛ Testing commit d758e4d with merge 244b05d...

bors added a commit that referenced this pull request Jan 5, 2019
Implement the Re-rebalance coherence RFC

This is the first time I touch anything in the compiler so just tell me if I got something wrong.

Big thanks to @sgrif for the pointers where to look for those things.
cc #55437
@bors
Copy link
Contributor

bors commented Jan 5, 2019

☀️ Test successful - status-appveyor, status-travis
Approved by: nikomatsakis
Pushing 244b05d to master...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants