-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Add wrong_any_coerce
lint
#3376
Conversation
22ad055
to
ca7408b
Compare
src_ty: Ty<'tcx>, | ||
tgt_ty: Ty<'tcx>, | ||
) -> Option<LintData<'tcx>> { | ||
// redo the typechecking for this coercion to see if it required unsizing something to `dyn Any` |
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's the reason for this? Would it be possible to use https://doc.rust-lang.org/nightly/nightly-rustc/rustc/ty/struct.TyCtxt.html#method.struct_lockstep_tails to figure out whether the src_ty
already is Any
at the same level that tgt_ty
is?
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.
struct_lockstep_tails
doesn't go through references and Box<T>
ends up as PhantomData<T>
, so we'd have to do some additional work to use that. That also wouldn't work if the type is generic (i.e. T: Deref<Target=dyn Any>
).
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.
ugh, makes sense :/
Do you think we can share this function with rustc by refactoring the original rustc code to factor out this function and make it public?
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.
Something like resolve_obligations_for_unsize_coercion(.., obligation_callback: impl FnMut(&PredicateObligation) -> ()) -> ..
? Then typechecking could use the callback to check for unsizing to a tuple (which apparently is feature gated) and we could check for unsizing to dyn Any
?
babfbde
to
0fcd88d
Compare
Ping @HMPerson1. I'm going over old PRs, that were abandoned by us reviewers (sorry for that!) or by the authors. Are you still interested in completing this? |
151e966
to
8e9c8f6
Compare
return true; | ||
} | ||
} | ||
// TODO: check for `RefCell<dyn Any>`? |
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.
Do you want to do this in this PR? Otherwise you can put this in the Known Problems
section.
☔ The latest upstream changes (presumably #4259) made this pull request unmergeable. Please resolve the merge conflicts. |
Hi @HMPerson1, since this PR has been inactive for a while, I'm going to go ahead and close it. Please don't hesitate to re-open it/ask for help. (As far as I can tell, the last status was that there were some remaining |
This lints any coercion to
dyn Any
where the source type derefs todyn Any
(e.g.Box<dyn Any>
,Rc<dyn Any>
, etc.). We might also want to lintRefCell<dyn Any>
orMutex<dyn Any>
, but I don't know of a good way to check for things like that without just hardcoding a list of "container-ish things".Fixes #2988