-
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
Dyn compatibility error when using an associated type as a type parameter in the super-trait listing #40533
Comments
Current output:
It should at least point at |
Output in #68377:
|
Tweak obligation error output - Point at arguments or output when fn obligations come from them, or ident when they don't - Point at `Sized` bound (fix #47990) - When object unsafe trait uses itself in associated item suggest using `Self` (fix #66424, fix #33375, partially address #38376, cc #61525) - Point at reason in object unsafe trait with `Self` in supertraits or `where`-clause (cc #40533, cc #68377) - On implicit type parameter `Sized` obligations, suggest `?Sized` (fix #57744, fix #46683)
I believe that we should change the implementation here rust/compiler/rustc_trait_selection/src/traits/object_safety.rs Lines 287 to 293 in ed97493
to account for Further changes would also be needed here rust/compiler/rustc_hir_analysis/src/astconv/mod.rs Lines 1519 to 1542 in ed97493
@rust-lang/lang, would this require team sign-off, or is the current behavior "accidental"/"incidental" and a change of behavior requires no "new rationale"? I'm also intrigued on whether this test should have been rejected with a more targeted error, instead of E0038: https://github.com/rust-lang/rust/blob/eb4580a570069175e1290b294d91042a09f9fde3/src/test/ui/issues/issue-26056.rs |
Self can appear in projections, but only as part of an "identity" trait-ref. i.e., if you hvae I think such a PR does not require an FCP, but it's prob a good idea to nominate for @rust-lang/types approval or review. This feels to me like a 'nitty gritty' detail. I think in general @rust-lang/types is a good choice for that, and types team can escalate to lang if it seems like it requires a policy decision. |
This is a disparity between trait generic parameter and associated type. I very much doubt such disparity is intended in this scenario. Though not particularly damaging, it adds restrictions during high-level type designs. trait Super<T> {}
trait Foo<Bar>: Super<Bar> {} // Using a generic parameter does not break object safety
type BoxFoo = Box<Foo<u8>>; |
I quite strongly believe that a fix for this issue should require a types FCP. Changes to the stable behavior of the type system, especially if the changes are hanbdle some nitty gritty detail should go through a types FCP, see https://rust-lang.zulipchat.com/#narrow/stream/144729-t-types/topic/FCPs.20for.20type.20system.20hacks where we've previously discussed this question on zulip. Most unsound issues and weird backcompat hurdles tend to be caused by one (or the interaction of multiple) such nitty gritty detail(s). Even if the FCP only manages to force t-types members to look at the PR in more detail, this is still very clearly worth it to me. |
I tried this code:
The code should compile since
Self::Bar
is the type parameter, notSelf
.Instead, it will fail with the following message:
the trait Foo cannot be made into an object
the trait cannot use Self as a type parameter in the supertrait listing
FYI the discussion that sparked this issue:
Meta
rustc --version --verbose
: rustc 1.17.0-nightly (b1e31766d
2017-03-03)The text was updated successfully, but these errors were encountered: