-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Do not resolve associated const when there is no provided value #99449
Do not resolve associated const when there is no provided value #99449
Conversation
Some changes occurred in const_evaluatable.rs cc @lcnr |
@@ -185,14 +185,20 @@ pub fn is_const_evaluatable<'cx, 'tcx>( | |||
} | |||
let concrete = infcx.const_eval_resolve(param_env, uv.expand(), Some(span)); | |||
match concrete { | |||
Err(ErrorHandled::TooGeneric) => Err(if !uv.has_infer_types_or_consts() { | |||
Err(ErrorHandled::TooGeneric) => Err(if uv.has_infer_types_or_consts() { |
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.
TooGeneric
here is a bit of a misnomer, since it really should be "not concrete" or something.
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.
🤔 it's weird that we have to actually deal with TooGeneric
here 🤔
this should already be guarded against by the uniify_failure_kind
. Do any tests change if you always use
let guar = infcx.tcx.sess.delay_span_bug(
span,
format!("Missing value for constant, but no error reported?"),
);
NotConstEvaluatable::Error(guar)
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.
I changed this to always delay a bug, and not specially deal with TooGeneric
in the case of infer/param types:
match concrete {
Err(ErrorHandled::TooGeneric) => Err({
let guar = infcx.tcx.sess.delay_span_bug(
span,
format!("Missing value for constant, but no error reported?"),
);
NotConstEvaluatable::Error(guar)
}),
and I get two ICEs, see this gist: https://gist.github.com/compiler-errors/146cd973d15ddc7fcfee6ff28a9ac5e0
Was that what you were asking me to try, @lcnr?
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.
yeah, so InferCtxt::const_eval_resolve
is not not doing what we need for this
rust/compiler/rustc_infer/src/infer/mod.rs
Lines 1664 to 1671 in 03d488b
if substs.has_infer_types_or_consts() { | |
let ac = AbstractConst::new(self.tcx, unevaluated.shrink()); | |
if let Ok(None) = ac { | |
substs = InternalSubsts::identity_for_item(self.tcx, unevaluated.def.did); | |
} else { | |
return Err(ErrorHandled::TooGeneric); | |
} | |
} |
I guess what we should do is:
match on AbstractConst::new(self.tcx, unevaluated.shrink());
Ok(None)
is already correct.
Err(emitted)
-> NotConstEvaluatable::Error(emitted)
Ok(Some(x))
-> the inference vars aren't used in the anon const, replace them with placeholders
feel free to do that in this PR, otherwise r=me
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.
@lcnr: I'm gonna do it in a follow-up PR, since this solution doesn't really rely on that change, does it?
r=me after dealing with the first comment |
r? @lcnr |
@bors r=lcnr |
…-item, r=lcnr Do not resolve associated const when there is no provided value Fixes rust-lang#98629, since now we just delay a bug when we're not able to evaluate a const item due to the value not actually being provided by anything. This means compilation proceeds forward to where the "missing item in impl" error is emitted. ---- The root issue here is that when we're looking for the defining `LeafDef` in `resolve_associated_item`, we end up getting the trait's AssocItem instead of the impl's AssocItem (which does not exist). This resolution "succeeds" even if the trait's item has no default value, and then since this item has no value to evaluate, it turns into a const eval error. This root issue becomes problematic (as in rust-lang#98629) when this const eval error happens in wfcheck (for example, due to normalizing the param-env of something that references this const). Since this happens sooner than the check that an impl actually provides all of the items that a trait requires (which happens during later typecheck), we end up aborting compilation early with only this un-informative message. I'm not exactly sure _why_ this bug arises due to rust-lang#96591 -- perhaps valtrees are evaluated more eagerly than in the old system? r? `@oli-obk` or `@lcnr` since y'all are familiar with const eval and reviewed rust-lang#96591, though feel free to reassign. This is a regression from stable to beta, so I would be open to considering this for beta backport. It seems correct to me, especially given the improvements in the other UI tests this PR touches, but may have some side-effects that I'm unaware of...?
…-item, r=lcnr Do not resolve associated const when there is no provided value Fixes rust-lang#98629, since now we just delay a bug when we're not able to evaluate a const item due to the value not actually being provided by anything. This means compilation proceeds forward to where the "missing item in impl" error is emitted. ---- The root issue here is that when we're looking for the defining `LeafDef` in `resolve_associated_item`, we end up getting the trait's AssocItem instead of the impl's AssocItem (which does not exist). This resolution "succeeds" even if the trait's item has no default value, and then since this item has no value to evaluate, it turns into a const eval error. This root issue becomes problematic (as in rust-lang#98629) when this const eval error happens in wfcheck (for example, due to normalizing the param-env of something that references this const). Since this happens sooner than the check that an impl actually provides all of the items that a trait requires (which happens during later typecheck), we end up aborting compilation early with only this un-informative message. I'm not exactly sure _why_ this bug arises due to rust-lang#96591 -- perhaps valtrees are evaluated more eagerly than in the old system? r? ``@oli-obk`` or ``@lcnr`` since y'all are familiar with const eval and reviewed rust-lang#96591, though feel free to reassign. This is a regression from stable to beta, so I would be open to considering this for beta backport. It seems correct to me, especially given the improvements in the other UI tests this PR touches, but may have some side-effects that I'm unaware of...?
…-item, r=lcnr Do not resolve associated const when there is no provided value Fixes rust-lang#98629, since now we just delay a bug when we're not able to evaluate a const item due to the value not actually being provided by anything. This means compilation proceeds forward to where the "missing item in impl" error is emitted. ---- The root issue here is that when we're looking for the defining `LeafDef` in `resolve_associated_item`, we end up getting the trait's AssocItem instead of the impl's AssocItem (which does not exist). This resolution "succeeds" even if the trait's item has no default value, and then since this item has no value to evaluate, it turns into a const eval error. This root issue becomes problematic (as in rust-lang#98629) when this const eval error happens in wfcheck (for example, due to normalizing the param-env of something that references this const). Since this happens sooner than the check that an impl actually provides all of the items that a trait requires (which happens during later typecheck), we end up aborting compilation early with only this un-informative message. I'm not exactly sure _why_ this bug arises due to rust-lang#96591 -- perhaps valtrees are evaluated more eagerly than in the old system? r? ```@oli-obk``` or ```@lcnr``` since y'all are familiar with const eval and reviewed rust-lang#96591, though feel free to reassign. This is a regression from stable to beta, so I would be open to considering this for beta backport. It seems correct to me, especially given the improvements in the other UI tests this PR touches, but may have some side-effects that I'm unaware of...?
…-item, r=lcnr Do not resolve associated const when there is no provided value Fixes rust-lang#98629, since now we just delay a bug when we're not able to evaluate a const item due to the value not actually being provided by anything. This means compilation proceeds forward to where the "missing item in impl" error is emitted. ---- The root issue here is that when we're looking for the defining `LeafDef` in `resolve_associated_item`, we end up getting the trait's AssocItem instead of the impl's AssocItem (which does not exist). This resolution "succeeds" even if the trait's item has no default value, and then since this item has no value to evaluate, it turns into a const eval error. This root issue becomes problematic (as in rust-lang#98629) when this const eval error happens in wfcheck (for example, due to normalizing the param-env of something that references this const). Since this happens sooner than the check that an impl actually provides all of the items that a trait requires (which happens during later typecheck), we end up aborting compilation early with only this un-informative message. I'm not exactly sure _why_ this bug arises due to rust-lang#96591 -- perhaps valtrees are evaluated more eagerly than in the old system? r? ````@oli-obk```` or ````@lcnr```` since y'all are familiar with const eval and reviewed rust-lang#96591, though feel free to reassign. This is a regression from stable to beta, so I would be open to considering this for beta backport. It seems correct to me, especially given the improvements in the other UI tests this PR touches, but may have some side-effects that I'm unaware of...?
Discussed in T-compiler meeting. Declining to backport, though if someone wants to make a strong argument for it, you can renominate. (The heart of the discussion is that I was/am nervous about the change, while @oli-obk 's opinion is that "the fix is fairly simple and the problem is annoying to debug when hit". I'm mainly curious to know how @lcnr feels, since they had suggestions on follow-up changes that should be made to this code as well.) @rustbot label: -beta-nominated |
…-item, r=lcnr Do not resolve associated const when there is no provided value Fixes rust-lang#98629, since now we just delay a bug when we're not able to evaluate a const item due to the value not actually being provided by anything. This means compilation proceeds forward to where the "missing item in impl" error is emitted. ---- The root issue here is that when we're looking for the defining `LeafDef` in `resolve_associated_item`, we end up getting the trait's AssocItem instead of the impl's AssocItem (which does not exist). This resolution "succeeds" even if the trait's item has no default value, and then since this item has no value to evaluate, it turns into a const eval error. This root issue becomes problematic (as in rust-lang#98629) when this const eval error happens in wfcheck (for example, due to normalizing the param-env of something that references this const). Since this happens sooner than the check that an impl actually provides all of the items that a trait requires (which happens during later typecheck), we end up aborting compilation early with only this un-informative message. I'm not exactly sure _why_ this bug arises due to rust-lang#96591 -- perhaps valtrees are evaluated more eagerly than in the old system? r? `@oli-obk` or `@lcnr` since y'all are familiar with const eval and reviewed rust-lang#96591, though feel free to reassign. This is a regression from stable to beta, so I would be open to considering this for beta backport. It seems correct to me, especially given the improvements in the other UI tests this PR touches, but may have some side-effects that I'm unaware of...?
c8165c5
to
22b2aae
Compare
Some changes occurred in src/tools/clippy cc @rust-lang/clippy |
@bors r=lcnr |
…-item, r=lcnr Do not resolve associated const when there is no provided value Fixes rust-lang#98629, since now we just delay a bug when we're not able to evaluate a const item due to the value not actually being provided by anything. This means compilation proceeds forward to where the "missing item in impl" error is emitted. ---- The root issue here is that when we're looking for the defining `LeafDef` in `resolve_associated_item`, we end up getting the trait's AssocItem instead of the impl's AssocItem (which does not exist). This resolution "succeeds" even if the trait's item has no default value, and then since this item has no value to evaluate, it turns into a const eval error. This root issue becomes problematic (as in rust-lang#98629) when this const eval error happens in wfcheck (for example, due to normalizing the param-env of something that references this const). Since this happens sooner than the check that an impl actually provides all of the items that a trait requires (which happens during later typecheck), we end up aborting compilation early with only this un-informative message. I'm not exactly sure _why_ this bug arises due to rust-lang#96591 -- perhaps valtrees are evaluated more eagerly than in the old system? r? `@oli-obk` or `@lcnr` since y'all are familiar with const eval and reviewed rust-lang#96591, though feel free to reassign. This is a regression from stable to beta, so I would be open to considering this for beta backport. It seems correct to me, especially given the improvements in the other UI tests this PR touches, but may have some side-effects that I'm unaware of...?
…laumeGomez Rollup of 6 pull requests Successful merges: - rust-lang#99298 (Make `ui-fulldeps/gated-plugins` and `ui-fulldeps/multiple-plugins` tests stage 2 only) - rust-lang#99396 (Add some additional double-adjustment regression tests) - rust-lang#99449 (Do not resolve associated const when there is no provided value) - rust-lang#99595 (Mark atomics as unsupported on thumbv6m) - rust-lang#99627 (Lock stdout once when listing tests) - rust-lang#99638 (Remove Clean trait implementation for hir::Ty and middle::Ty) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
handle consts with param/infer in `const_eval_resolve` better This PR addresses [this thread here](rust-lang#99449 (comment)). Was this the change you were looking for `@lcnr?` Interestingly, one test has begun to pass. Was that expected? r? `@lcnr`
handle consts with param/infer in `const_eval_resolve` better This PR addresses [this thread here](rust-lang#99449 (comment)). Was this the change you were looking for ``@lcnr?`` Interestingly, one test has begun to pass. Was that expected? r? ``@lcnr``
Fixes #98629, since now we just delay a bug when we're not able to evaluate a const item due to the value not actually being provided by anything. This means compilation proceeds forward to where the "missing item in impl" error is emitted.
The root issue here is that when we're looking for the defining
LeafDef
inresolve_associated_item
, we end up getting the trait's AssocItem instead of the impl's AssocItem (which does not exist). This resolution "succeeds" even if the trait's item has no default value, and then since this item has no value to evaluate, it turns into a const eval error.This root issue becomes problematic (as in #98629) when this const eval error happens in wfcheck (for example, due to normalizing the param-env of something that references this const). Since this happens sooner than the check that an impl actually provides all of the items that a trait requires (which happens during later typecheck), we end up aborting compilation early with only this un-informative message.
I'm not exactly sure why this bug arises due to #96591 -- perhaps valtrees are evaluated more eagerly than in the old system?
r? @oli-obk or @lcnr since y'all are familiar with const eval and reviewed #96591, though feel free to reassign.
This is a regression from stable to beta, so I would be open to considering this for beta backport. It seems correct to me, especially given the improvements in the other UI tests this PR touches, but may have some side-effects that I'm unaware of...?