feat(hir-ty): add method references_only_ty_error to detect type errors#21497
feat(hir-ty): add method references_only_ty_error to detect type errors#21497ShoyuVanilla merged 1 commit intorust-lang:masterfrom
Conversation
ShoyuVanilla
left a comment
There was a problem hiding this comment.
Looks good overall, modulo a few nits:
crates/hir-ty/src/next_solver/ty.rs
Outdated
| fn visit_const(&mut self, c: Const<'db>) -> Self::Result { | ||
| if c.is_ct_error() { ControlFlow::Continue(()) } else { c.super_visit_with(self) } | ||
| } |
There was a problem hiding this comment.
I guess we don't have to implement this, as the default implementation of TypeVisitor::visit_const returns ControlFlow::Continue(()) for error consts?
There was a problem hiding this comment.
I confirmed it's indeed default. Removed.
| // The fix allows method resolution to proceed when only const errors exist, | ||
| // since const errors unify with any value in structurally_relate_consts. |
There was a problem hiding this comment.
This comment would be clearer if it were placed directly on the relevant line in method_resolution/probe.rs.
Also, the statement "since const errors unify with any value in structurally_relate_consts" is not quite correct. structurally_relate_consts returns Ok to avoid emitting redundant type mismatch errors once the typecheck is already tainted by error consts. Allowing method resolution to proceed in the presence of error consts is a workaround for our currently incomplete const evaluation, not a reflection of correct or intended behavior.
There was a problem hiding this comment.
Thanks for clarification, that was my premature speculation to make me why it's sound. I moved the comment and make it more concise to capture your wording. (also test is re-named to be consistent)
| r#" | ||
| struct Between<const M: usize, const N: usize, T>(T); | ||
|
|
||
| impl<const M: usize, T> Between<M, { usize::MAX }, T> { |
There was a problem hiding this comment.
I don’t think usize::MAX is suitable here. It is defined in Rust’s core library and is not available in our test suites. We have minicore.rs for a similar purpose, but it does not define usize::MAX.
If the intention is to create an error const by referring a non-existent associated constant, that approach is quite subtle and would benefit from being replaced with a more self-explanatory name. In any case, I think referring to an existing constant would be preferable, especially since we already having trouble resolving such associated constant inside a block.
I'd recommend defining a new ADT with an associated constant and using it instead of usize in this test.
There was a problem hiding this comment.
Added new Constant. I did not aware of such infra, and this had const error with different reason!
Add a new method `references_only_ty_error` to the `Ty` implementation to determine if a type contains only type errors, ignoring const and lifetime errors. Enhance test suite for const generic method resolution.
Add a new method
references_only_ty_errorto theTyimplementation to determine if a type contains only type errors, ignoring const and lifetime errors. Enhance test suite for const generic method resolution.Fixes: #21315
Before
After