-
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
Give a better error message when a query isn't supported for a local / external crate #101666
Comments
Claiming this. If @jyn514 someone could bring some color on whether If |
@rustbot claim |
@hanar3 yes, all keys must implement Key or they can't be used as the argument to a query in the first place. |
Awesome, thanks for the reply! This is what I have in place so far. impl Default for Providers {
fn default() -> Self {
Providers {
$($name: |_, key| bug!(
"`tcx.{}({:?})` unsupported for {} crate; \
perhaps the `{}` query was never assigned a provider function. Queries can be either made to the local crate, or the external crate. This error means you tried to use it for one that's not supported.",
stringify!($name),
key,
if key.query_crate_is_local() { "local" } else { "external" } ,
stringify!($name),
),)*
}
}
} The compiler, however, is not happy with me calling 175 | / macro_rules! define_callbacks {
176 | | (
177 | | $($(#[$attr:meta])*
178 | | [$($modifiers:tt)*] fn $name:ident($($K:tt)*) -> $V:ty,)*) => {
... |
282 | | if key.query_crate_is_local() { "local" } else { "external" } ,
| | ^^^^^^^^^^^^^^^^^^^^ method not found in `(ty::Ty<'_>, Option<Binder<'_, ExistentialTraitRef<'_>>>)`
... |
321 | | };
322 | | }
| |__- in this expansion of `define_callbacks!` (#2) This is the macro definition, I noticed it uses rust/compiler/rustc_middle/src/ty/query.rs Line 178 in c97922d
Is it right to assume that the [$($modifiers:tt)*] fn $name:ident($($K:expr)*) -> $V:ty,)*) EDIT: If key is always a valid key at runtime, this wouldn't cause harm I believe? Thanks in advance! |
@hanar3 hmm, I think I was wrong before - the problem is that the key only needs to implement the
|
Hi @jyn514, if I understood correctly, the key is not guaranteed to implement the To your point on the new I got to a point where I tried a few solutions (I can share them here, if you want to reference), but still end up with very similar compiler issues for all of them. key.query_crate_is_local(),
| | ^^^^^^^^^^^^^^^^^^^^ method not found in `InstanceDef<'_>` and
This one made me think I might be going to the right direction...I see a This was my last take on get_default_provider. Again, I'm not very knowledgeable on this, so my solutions were heavily based off of macros that were already present and doing similar things, so I'm afraid this might not be the way to solve it. macro_rules! get_default_provider {
([][$name:ident]) => {
()
};
([(separate_provide_extern) $($rest:tt)*][$name:ident]) => {
|_, key| bug!(
"`tcx.{}({:?})` unsupported by {} crate;", // Removed a chunk of the message here just to make this more readable.
stringify!($name),
if key.query_crate_is_local() { "local" } else { "extern" },
stringify!($name),
)
};
([$other:tt $($modifiers:tt)*][$($args:tt)*]) => {
get_default_provider!([$($modifiers)*][$($args)*])
};
} If you could point me to the right direction here as it relates to this new macro, that would be super helpful!! Again, thanks for the great support on this one. Really having fun while trying to push my first contribution! :) |
Hi @jyn514, |
…e, r=oli-obk Improve error for when query is unsupported by crate This is an improvement to the error message mentioned on rust-lang#101666. It seems like a good idea to also add [this link to the rustc-dev-guide](https://rustc-dev-guide.rust-lang.org/query.html), if explaining the query system in detail is a concern here, but I'm unsure if there is any restrictions on adding links to error messages.
…e, r=oli-obk Improve error for when query is unsupported by crate This is an improvement to the error message mentioned on rust-lang#101666. It seems like a good idea to also add [this link to the rustc-dev-guide](https://rustc-dev-guide.rust-lang.org/query.html), if explaining the query system in detail is a concern here, but I'm unsure if there is any restrictions on adding links to error messages.
…e, r=oli-obk Improve error for when query is unsupported by crate This is an improvement to the error message mentioned on rust-lang#101666. It seems like a good idea to also add [this link to the rustc-dev-guide](https://rustc-dev-guide.rust-lang.org/query.html), if explaining the query system in detail is a concern here, but I'm unsure if there is any restrictions on adding links to error messages.
…e, r=oli-obk Improve error for when query is unsupported by crate This is an improvement to the error message mentioned on rust-lang#101666. It seems like a good idea to also add [this link to the rustc-dev-guide](https://rustc-dev-guide.rust-lang.org/query.html), if explaining the query system in detail is a concern here, but I'm unsure if there is any restrictions on adding links to error messages.
Hello @jyn514, I looked into this a little bit and to me it seems that all the keys do implement I am new to contributing to rust. I don't know how feasible this is but maybe we can move |
@rustbot claim |
@rustbot release-assignment |
Unsupported query error now specifies if its unsupported for local or external crate Fixes rust-lang#101666. I had to move `keys.rs` from `rustc_query_impl` to `rustc_middle`. I don't know if that is problematic. I couldn't think of any other way to get the needed information inside `rustc_middle`. r? ``@jyn514``
@richkadel made a great start on this in #83367, but it would be nice to explain the
local
/external
distinction in the panic message; "unsupported by crate" is unhelpful. This is an ICE targeted at compiler developers so IMO it can be pretty much as long as we want.Currently the error looks like this:
I wrote up this description while helping someone debug on discord, which may be a good start:
If possible, we should say "
tcx.module_children
unsupported by local crate" (or external as appropriate, selected at runtime), but if not, we should at least explain what's going wrong better. The link below has a lot of details about the code structure that may be helpful.Originally posted by @richkadel in #83122 (comment)
The text was updated successfully, but these errors were encountered: