-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
Tracking issue for future-incompatibility lint tyvar_behind_raw_pointer #46906
Copy link
Copy link
Open
Labels
A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.C-future-incompatibilityCategory: Future-incompatibility lintsCategory: Future-incompatibility lintsC-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language teamRelevant to the language team
Metadata
Metadata
Assignees
Labels
A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.C-future-incompatibilityCategory: Future-incompatibility lintsCategory: Future-incompatibility lintsC-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language teamRelevant to the language team
Type
Fields
Give feedbackNo fields configured for issues without a type.
Projects
Status
Idea
This is the summary issue for the
tyvar_behind_raw_pointerfuture-compatibility warning and other related errors. The goal of this page is describe why this change was made and how you can fix code that is affected by it. It also provides a place to ask questions or register a complaint if you feel the change should not be made. For more information on the policy around future-compatibility warnings, see our breaking change policy guidelines.What is the warning for?
This warning occurs when you call a method on a value whose type is a raw pointer to an unknown type (aka
*const _or*mut _), or a type that dereferences to one of these.The most common case for this is casts, for example:
This can be fixed by giving a type annotation to the cast:
The reason that this is going to become an error is because we are working on enabling arbitrary self types. Using that, you should be able to write functions such as:
While that case is obviously silly, we can't prevent a sibling crate from implementing it, and such a function would make a call to
s.is_null()when the type ofsis an*mut _ambiguous. Therefore, to avoid that potential breakage, you have to annotate the type of your raw pointer before the point of the method call.After you fix these warnings, if you are working with raw pointers on nightly, you might want to check out
#![feature(arbitrary_self_types)]yourself! It even works with trait objects:While I'm at it,
arbitrary_self_typesalso works for smart pointers, such asRc<T>orArc<T>(however, unfortunately we still have not figured out the best way to make it work with smart pointers to trait objects, so you can't yet createdyn Bartrait objects. We are planning on making it eventually work, so stay tuned!).When will this warning become a hard error?
At the beginning of each 6-week release cycle, the Rust compiler team will review the set of outstanding future compatibility warnings and nominate some of them for Final Comment Period. Toward the end of the cycle, we will review any comments and make a final determination whether to convert the warning into a hard error or remove it entirely.