Improve suggestions for NonZeroT <- T coercion error#99438
Improve suggestions for NonZeroT <- T coercion error#99438bors merged 5 commits intorust-lang:masterfrom
NonZeroT <- T coercion error#99438Conversation
|
Hey! It looks like you've submitted a new PR for the library teams! If this PR contains changes to any Examples of
|
compiler-errors
left a comment
There was a problem hiding this comment.
Thanks @WaffleLapkin for an interesting and useful diagnostics improvement as always. This looks good as is, but I had an idea of generalizing both parts of the PR. Let me know your thoughts.
| if !sole_field.did.is_local() | ||
| && !sole_field.vis.is_accessible_from( | ||
| self.tcx.parent_module(expr.hir_id).to_def_id(), | ||
| self.tcx, | ||
| ) |
There was a problem hiding this comment.
| if !sole_field.did.is_local() | |
| && !sole_field.vis.is_accessible_from( | |
| self.tcx.parent_module(expr.hir_id).to_def_id(), | |
| self.tcx, | |
| ) | |
| if !sole_field.vis.is_accessible_from( | |
| self.body_id.owner.to_def_id(), | |
| self.tcx, | |
| ) |
There was a problem hiding this comment.
No need to restrict to only foreign def id, and we can get a more accurate def id from self.body_id.owner.to_def_id() i think.
There was a problem hiding this comment.
Restriction to foreign def ids is deliberate, see the test:
rust/src/test/ui/mismatched_types/wrap-suggestion-privacy.rs
Lines 10 to 11 in da2752e
There was a problem hiding this comment.
Hm, I guess so. I think that giving an incorrect suggestion isn't as useful, especially in a large codebase, but can you at least note that in a comment?
There was a problem hiding this comment.
Specifically " its privacy can be easily changed " as the justification would be nice to note
There was a problem hiding this comment.
Not sure how to present it in a good way, but I've tried 5bd88df
There was a problem hiding this comment.
haha I meant a comment in the source code, but this works too!
- Use `expr.hir_id.owner` instead of `self.tcx.parent_module(expr.hir_id)` - Use `.type_at()` instead of `.first()` + `.expect_ty()` - Use single `.find()` with `&&` condition Co-authored-by: Michael Goulet <michael@errs.io>
compiler-errors
left a comment
There was a problem hiding this comment.
This looks good for now. It can be tweaked later if anyone complains about it.
|
r=me once CI turns green @bors delegate+ |
|
✌️ @WaffleLapkin can now approve this pull request |
|
@bors r=compiler-errors |
…askrgr Rollup of 9 pull requests Successful merges: - rust-lang#98028 (Add E0790 as more specific variant of E0283) - rust-lang#99384 (use body's param-env when checking if type needs drop) - rust-lang#99401 (Avoid `Symbol` to `&str` conversions) - rust-lang#99419 (Stabilize `core::task::ready!`) - rust-lang#99435 (Revert "Stabilize $$ in Rust 1.63.0") - rust-lang#99438 (Improve suggestions for `NonZeroT` <- `T` coercion error) - rust-lang#99441 (Update mdbook) - rust-lang#99453 (:arrow_up: rust-analyzer) - rust-lang#99457 (use `par_for_each_in` in `par_body_owners` and `collect_crate_mono_items`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Currently, when encountering a type mismatch error with
NonZeroTandT(for exampleNonZeroU8andu8) we errorneusly suggest wrapping expression inNonZeroT:I've removed this suggestion and added suggestions to call
new(forOption<NonZeroT><-Tcase) ornewandunwrap(forNonZeroT<-Tcase):r? @compiler-errors