Avoid const-eval ICEs from invalid CoerceShared impls - #159497
Avoid const-eval ICEs from invalid CoerceShared impls#159497chenyukang wants to merge 2 commits into
Conversation
|
r? @oli-obk rustbot has assigned @oli-obk. Use Why was this reviewer chosen?The reviewer was selected based on:
|
| let coerce_shared = tcx.require_lang_item(LangItem::CoerceShared, body_span); | ||
| tcx.for_each_relevant_impl(coerce_shared, borrowed_ty, |impl_def_id| { | ||
| if let Some(impl_def_id) = impl_def_id.as_local() | ||
| && let Err(guar) = tcx.ensure_result().coerce_shared_info(impl_def_id) |
There was a problem hiding this comment.
maybe we can get this automatically everywhere by loading coerce_shared_info when the trait solver looks at an impl of CoerceShared and tainting the infcx there. It is fragile to only do it here.
There was a problem hiding this comment.
I moved the check to match_impl, should be a better location.
f6918ff to
9996b9d
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
| return Err(()); | ||
| } | ||
|
|
||
| if self.tcx().is_lang_item(obligation.predicate.def_id(), LangItem::CoerceShared) |
There was a problem hiding this comment.
Doesn't selection already check this language item somewhere? Add the check there
There was a problem hiding this comment.
you means coerce_shared_reborrow at https://github.com/chenyukang/rust/blob/9996b9dc57838ea6611c6328933073060159c854/compiler/rustc_hir_typeck/src/coercion.rs#L980 ?
I have found coerce_unsize have similar check
https://github.com/chenyukang/rust/blob/9996b9dc57838ea6611c6328933073060159c854/compiler/rustc_hir_typeck/src/coercion.rs#L808-L817
There was a problem hiding this comment.
I moved the check into coerce_shared_reborrow
now we can make these tests no ICE:
912df9a
but I find another testcase will be ICE which we can not cover for this fix(also upstream main):
#![feature(reborrow)]
#![allow(dead_code)]
use std::marker::CoerceShared;
struct InvalidMut<'a>(&'a u8);
#[derive(Copy, Clone)]
struct InvalidRef<'a>(&'a ());
fn invalid<'a>(value: InvalidMut<'a>)
where
InvalidMut<'a>: CoerceShared<InvalidRef<'a>>,
{
let _: InvalidRef<'a> = value;
//~^ ERROR mismatched types
}
fn main() {}the reason is we haven't do enough validation for ImplSource::Param.
cc @aapoalas
This comment has been minimized.
This comment has been minimized.
9996b9d to
912df9a
Compare
|
This PR changes a file inside |
|
☔ The latest upstream changes (presumably #160586) made this pull request unmergeable. Please resolve the merge conflicts by rebasing. |
Fixes #158149
Do not allow malformed coercion MIR to reach CTFE, which may trigger a size-mismatch ICE.