-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Tweak E0599 and elaborate_predicates #106788
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
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
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,88 @@ | ||
// These are simplifications of the tower traits by the same name: | ||
|
||
pub trait Service<Request> { | ||
type Response; | ||
} | ||
|
||
pub trait Layer<C> { | ||
type Service; | ||
} | ||
|
||
// Any type will do here: | ||
|
||
pub struct Req; | ||
pub struct Res; | ||
|
||
// This is encoding a trait alias. | ||
|
||
pub trait ParticularService: | ||
Service<Req, Response = Res> { | ||
} | ||
|
||
impl<T> ParticularService for T | ||
where | ||
T: Service<Req, Response = Res>, | ||
{ | ||
} | ||
|
||
// This is also a trait alias. | ||
// The weird = <Self as ...> bound is there so that users of the trait do not | ||
// need to repeat the bounds. See https://github.com/rust-lang/rust/issues/20671 | ||
// for context, and in particular the workaround in: | ||
// https://github.com/rust-lang/rust/issues/20671#issuecomment-529752828 | ||
|
||
pub trait ParticularServiceLayer<C>: | ||
Layer<C, Service = <Self as ParticularServiceLayer<C>>::Service> | ||
{ | ||
type Service: ParticularService; | ||
} | ||
|
||
impl<T, C> ParticularServiceLayer<C> for T | ||
where | ||
T: Layer<C>, | ||
T::Service: ParticularService, | ||
{ | ||
type Service = T::Service; | ||
} | ||
|
||
// These are types that implement the traits that the trait aliases refer to. | ||
// They should also implement the alias traits due to the blanket impls. | ||
|
||
struct ALayer<C>(C); | ||
impl<C> Layer<C> for ALayer<C> { | ||
type Service = AService; | ||
} | ||
|
||
struct AService; | ||
impl Service<Req> for AService { | ||
// However, AService does _not_ meet the blanket implementation, | ||
// since its Response type is bool, not Res as it should be. | ||
type Response = bool; | ||
} | ||
|
||
// This is a wrapper type around ALayer that uses the trait alias | ||
// as a way to communicate the requirements of the provided types. | ||
struct Client<C>(C); | ||
|
||
// The method and the free-standing function below both have the same bounds. | ||
|
||
impl<C> Client<C> | ||
where | ||
ALayer<C>: ParticularServiceLayer<C>, | ||
{ | ||
fn check(&self) {} | ||
} | ||
|
||
fn check<C>(_: C) where ALayer<C>: ParticularServiceLayer<C> {} | ||
|
||
// But, they give very different error messages. | ||
|
||
fn main() { | ||
// This gives a very poor error message that does nothing to point the user | ||
// at the underlying cause of why the types involved do not meet the bounds. | ||
Client(()).check(); //~ ERROR E0599 | ||
|
||
// This gives a good(ish) error message that points the user at _why_ the | ||
// bound isn't met, and thus how they might fix it. | ||
check(()); //~ ERROR E0271 | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will never happen in practice, but it's better to deal with the
None == None
case when lang-items are not defined.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the
None == None
case you envision? Becausetrait_pred
might have beenNone
(so we don't get into this logic) andsized_trait()
might beNone
which might cause a build where the sized trait lang item isn't present to be too verbose (with extra labels), no other behavioral change.