-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
rustc: remove ty::MethodOrigin and replace its uses with equivalent logic. #26694
Conversation
r? @Aatch (rust_highfive has picked a reviewer for you, use r? to override) |
@arielb1 Right, by "lints" I meant |
|
r+ modulo not storing the vtable + passing tests. |
☔ The latest upstream changes (presumably #26677) made this pull request unmergeable. Please resolve the merge conflicts. |
I ended up making all the changes anyway. Original PR description was:
|
cc @huonw The commit named "rustc_lint: use traits::select for methods in unconditional_recursion." produces warnings for overloaded operators (and probably other things I haven't thought of): struct Foo;
impl std::ops::Deref for Foo {
type Target = Foo;
// warning: function cannot return without recurring
fn deref(&self) -> &Foo { &**self }
}
impl std::ops::Index<usize> for Foo {
type Output = Foo;
// warning: function cannot return without recurring
fn index(&self, x: usize) -> &Foo { &self[x] }
} We might want some tests for these. |
@bors r+ |
📌 Commit d877cfd has been approved by |
⌛ Testing commit d877cfd with merge 411a5bf... |
💔 Test failed - auto-linux-64-nopt-t |
@bors r=arielb1 |
📌 Commit d256eb1 has been approved by |
Since this fixes a memory safety bug, can we backport it? |
@bluss the refactoring parts are pretty huge, though maybe just the vtable upcasting logic could be... I'm not sure. |
⌛ Testing commit d256eb1 with merge a993275... |
💔 Test failed - auto-mac-64-opt |
@bors retry |
⌛ Testing commit d256eb1 with merge 42e545f... |
`MethodCallee` now has no information about the method, other than its `DefId`. The previous bits of information can be recovered as follows: ```rust let method_item = tcx.impl_or_trait_item(callee.def_id); let container = method_item.container(); ``` The method is inherent if `container` is a `ty::ImplContainer`: * the `impl` the method comes from is `container.id()` The method is a trait method if `container` is a `ty::TraitContainer: * the `trait` the method is part of is `container.id()` * a `ty::TraitRef` can be constructed by putting together: * `container.id()` as the `trait` ID * `callee.substs.clone().method_to_trait()` as the `trait` substs (including `Self`) * the above `trait_ref` is a valid `T: Trait<A, B, C>` predicate * selecting `trait_ref` could result in one of the following: * `traits::VtableImpl(data)`: static dispatch to `data.impl_def_id` * `traits::VtableObject(data)`: dynamic dispatch, with the vtable index: `traits::get_vtable_index_of_object_method(tcx, data, callee.def_id)` * other variants of `traits::Vtable`: various other `impl` sources
MethodCallee
now has no information about the method, other than itsDefId
.The previous bits of information can be recovered as follows:
The method is inherent if
container
is aty::ImplContainer
:impl
the method comes from iscontainer.id()
The method is a trait method if
container
is aty::TraitContainer
:trait
the method is part of iscontainer.id()
ty::TraitRef
can be constructed by putting together:container.id()
as thetrait
IDcallee.substs.clone().method_to_trait()
as thetrait
substs (includingSelf
)trait_ref
is a validT: Trait<A, B, C>
predicatetrait_ref
could result in one of the following:traits::VtableImpl(data)
: static dispatch todata.impl_def_id
traits::VtableObject(data)
: dynamic dispatch, with the vtable index:traits::get_vtable_index_of_object_method(tcx, data, callee.def_id)
traits::Vtable
: various otherimpl
sources