-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #135866 - BoxyUwU:dont_pick_fnptr_nested_goals, r=lcnr
Don't pick `T: FnPtr` nested goals as the leaf goal in diagnostics for new solver r? `@lcnr` See `tests/ui/traits/next-solver/diagnostics/dont-pick-fnptr-bound-as-leaf.rs` for a minimized example of what code this affects the diagnostics off. The output of running nightly `-Znext-solver` on that test is the following: ``` error[E0277]: the trait bound `Foo: Trait` is not satisfied --> src/lib.rs:14:20 | 14 | requires_trait(Foo); | -------------- ^^^ the trait `FnPtr` is not implemented for `Foo` | | | required by a bound introduced by this call | note: required for `Foo` to implement `Trait` --> src/lib.rs:7:16 | 7 | impl<T: FnPtr> Trait for T {} | ----- ^^^^^ ^ | | | unsatisfied trait bound introduced here note: required by a bound in `requires_trait` --> src/lib.rs:11:22 | 11 | fn requires_trait<T: Trait>(_: T) {} | ^^^^^ required by this bound in `requires_trait` ``` Part of rust-lang/trait-system-refactor-initiative#148
- Loading branch information
Showing
26 changed files
with
388 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
tests/ui/traits/next-solver/diagnostics/dont-pick-fnptr-bound-as-leaf.current.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
error[E0277]: the trait bound `Foo: Trait` is not satisfied | ||
--> $DIR/dont-pick-fnptr-bound-as-leaf.rs:24:20 | ||
| | ||
LL | requires_trait(Foo); | ||
| -------------- ^^^ the trait `Trait` is not implemented for `Foo` | ||
| | | ||
| required by a bound introduced by this call | ||
| | ||
note: required by a bound in `requires_trait` | ||
--> $DIR/dont-pick-fnptr-bound-as-leaf.rs:19:22 | ||
| | ||
LL | fn requires_trait<T: Trait>(_: T) {} | ||
| ^^^^^ required by this bound in `requires_trait` | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0277`. |
17 changes: 17 additions & 0 deletions
17
tests/ui/traits/next-solver/diagnostics/dont-pick-fnptr-bound-as-leaf.next.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
error[E0277]: the trait bound `Foo: Trait` is not satisfied | ||
--> $DIR/dont-pick-fnptr-bound-as-leaf.rs:24:20 | ||
| | ||
LL | requires_trait(Foo); | ||
| -------------- ^^^ the trait `Trait` is not implemented for `Foo` | ||
| | | ||
| required by a bound introduced by this call | ||
| | ||
note: required by a bound in `requires_trait` | ||
--> $DIR/dont-pick-fnptr-bound-as-leaf.rs:19:22 | ||
| | ||
LL | fn requires_trait<T: Trait>(_: T) {} | ||
| ^^^^^ required by this bound in `requires_trait` | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0277`. |
28 changes: 28 additions & 0 deletions
28
tests/ui/traits/next-solver/diagnostics/dont-pick-fnptr-bound-as-leaf.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
//@ revisions: current next | ||
//@[next] compile-flags: -Znext-solver | ||
//@ ignore-compare-mode-next-solver (explicit revisions) | ||
|
||
// When emitting an error for `Foo: Trait` not holding we attempt to find a nested goal | ||
// to give as the reason why the bound does not hold. This test checks that we do not | ||
// try to tell the user that `Foo: FnPtr` is unimplemented as that would be confusing. | ||
|
||
#![feature(fn_ptr_trait)] | ||
|
||
use std::marker::FnPtr; | ||
|
||
trait Trait {} | ||
|
||
impl<T: FnPtr> Trait for T {} | ||
|
||
struct Foo; | ||
|
||
fn requires_trait<T: Trait>(_: T) {} | ||
//~^ NOTE: required by a bound in `requires_trait` | ||
//~| NOTE: required by this bound in `requires_trait` | ||
|
||
fn main() { | ||
requires_trait(Foo); | ||
//~^ ERROR: the trait bound `Foo: Trait` is not satisfied | ||
//~| NOTE: the trait `Trait` is not implemented for `Foo` | ||
//~| NOTE: required by a bound introduced by this call | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
error[E0277]: the trait bound `K: Hash` is not satisfied | ||
--> $DIR/bad-index-due-to-nested.rs:24:5 | ||
| | ||
LL | map[k] | ||
| ^^^ the trait `Hash` is not implemented for `K` | ||
| | ||
note: required for `HashMap<K, V>` to implement `Index<&K>` | ||
--> $DIR/bad-index-due-to-nested.rs:11:12 | ||
| | ||
LL | impl<K, V> Index<&K> for HashMap<K, V> | ||
| ^^^^^^^^^ ^^^^^^^^^^^^^ | ||
LL | where | ||
LL | K: Hash, | ||
| ---- unsatisfied trait bound introduced here | ||
help: consider restricting type parameter `K` with trait `Hash` | ||
| | ||
LL | fn index<'a, K: std::hash::Hash, V>(map: &'a HashMap<K, V>, k: K) -> &'a V { | ||
| +++++++++++++++++ | ||
|
||
error[E0277]: the trait bound `V: Copy` is not satisfied | ||
--> $DIR/bad-index-due-to-nested.rs:24:5 | ||
| | ||
LL | map[k] | ||
| ^^^ the trait `Copy` is not implemented for `V` | ||
| | ||
note: required for `HashMap<K, V>` to implement `Index<&K>` | ||
--> $DIR/bad-index-due-to-nested.rs:11:12 | ||
| | ||
LL | impl<K, V> Index<&K> for HashMap<K, V> | ||
| ^^^^^^^^^ ^^^^^^^^^^^^^ | ||
... | ||
LL | V: Copy, | ||
| ---- unsatisfied trait bound introduced here | ||
help: consider restricting type parameter `V` with trait `Copy` | ||
| | ||
LL | fn index<'a, K, V: std::marker::Copy>(map: &'a HashMap<K, V>, k: K) -> &'a V { | ||
| +++++++++++++++++++ | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/bad-index-due-to-nested.rs:24:9 | ||
| | ||
LL | fn index<'a, K, V>(map: &'a HashMap<K, V>, k: K) -> &'a V { | ||
| - found this type parameter | ||
LL | map[k] | ||
| ^ expected `&K`, found type parameter `K` | ||
| | ||
= note: expected reference `&_` | ||
found type parameter `_` | ||
help: consider borrowing here | ||
| | ||
LL | map[&k] | ||
| + | ||
|
||
error[E0277]: the trait bound `K: Hash` is not satisfied | ||
--> $DIR/bad-index-due-to-nested.rs:24:5 | ||
| | ||
LL | map[k] | ||
| ^^^^^^ the trait `Hash` is not implemented for `K` | ||
| | ||
note: required for `HashMap<K, V>` to implement `Index<&K>` | ||
--> $DIR/bad-index-due-to-nested.rs:11:12 | ||
| | ||
LL | impl<K, V> Index<&K> for HashMap<K, V> | ||
| ^^^^^^^^^ ^^^^^^^^^^^^^ | ||
LL | where | ||
LL | K: Hash, | ||
| ---- unsatisfied trait bound introduced here | ||
help: consider restricting type parameter `K` with trait `Hash` | ||
| | ||
LL | fn index<'a, K: std::hash::Hash, V>(map: &'a HashMap<K, V>, k: K) -> &'a V { | ||
| +++++++++++++++++ | ||
|
||
error: aborting due to 4 previous errors | ||
|
||
Some errors have detailed explanations: E0277, E0308. | ||
For more information about an error, try `rustc --explain E0277`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
tests/ui/union/union-derive-eq.stderr → ...s/ui/union/union-derive-eq.current.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
error[E0277]: the trait bound `PartialEqNotEq: Eq` is not satisfied | ||
--> $DIR/union-derive-eq.rs:21:5 | ||
| | ||
LL | #[derive(Eq)] | ||
| -- in this derive macro expansion | ||
LL | union U2 { | ||
LL | a: PartialEqNotEq, | ||
| ^^^^^^^^^^^^^^^^^ the trait `Eq` is not implemented for `PartialEqNotEq` | ||
| | ||
= note: this error originates in the derive macro `Eq` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
help: consider annotating `PartialEqNotEq` with `#[derive(Eq)]` | ||
| | ||
LL + #[derive(Eq)] | ||
LL | struct PartialEqNotEq; | ||
| | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0277`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 4 additions & 4 deletions
8
tests/ui/wf/wf-trait-fn-arg.stderr → tests/ui/wf/wf-trait-fn-arg.current.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
error[E0277]: the trait bound `Self: Eq` is not satisfied | ||
--> $DIR/wf-trait-fn-arg.rs:16:23 | ||
| | ||
LL | fn bar(&self, x: &Bar<Self>); | ||
| ^^^^^^^^^ the trait `Eq` is not implemented for `Self` | ||
| | ||
help: consider further restricting `Self` | ||
| | ||
LL | fn bar(&self, x: &Bar<Self>) where Self: Eq; | ||
| ++++++++++++++ | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0277`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,22 @@ | ||
//@ revisions: current next | ||
//@[next] compile-flags: -Znext-solver | ||
//@ ignore-compare-mode-next-solver (explicit revisions) | ||
|
||
// Check that we test WF conditions for fn arguments in a trait definition. | ||
|
||
#![feature(rustc_attrs)] | ||
#![allow(dead_code)] | ||
#![allow(unused_variables)] | ||
|
||
struct Bar<T:Eq+?Sized> { value: Box<T> } | ||
struct Bar<T: Eq + ?Sized> { | ||
value: Box<T>, | ||
} | ||
|
||
trait Foo { | ||
fn bar(&self, x: &Bar<Self>); | ||
//~^ ERROR E0277 | ||
// | ||
// Here, Eq ought to be implemented. | ||
//~^ ERROR E0277 | ||
// | ||
// Here, Eq ought to be implemented. | ||
} | ||
|
||
fn main() { } | ||
fn main() {} |
8 changes: 4 additions & 4 deletions
8
tests/ui/wf/wf-trait-fn-ret.stderr → tests/ui/wf/wf-trait-fn-ret.current.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
error[E0277]: the trait bound `Self: Eq` is not satisfied | ||
--> $DIR/wf-trait-fn-ret.rs:15:23 | ||
| | ||
LL | fn bar(&self) -> &Bar<Self>; | ||
| ^^^^^^^^^ the trait `Eq` is not implemented for `Self` | ||
| | ||
help: consider further restricting `Self` | ||
| | ||
LL | fn bar(&self) -> &Bar<Self> where Self: Eq; | ||
| ++++++++++++++ | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0277`. |
Oops, something went wrong.