mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
Rollup merge of #153790 - zedddie:transmutation-regression, r=jdonszelmann
Fix regression when dealing with generics/values with unresolved inference Follow up for rust-lang/rust#151703, fixing regression caused in rollup rust-lang/rust#152825 Forgot to handle generics & unresolved inference variables (as in `get_safe_transmute_error_and_reason`) in my previous PR. This followup checks for them before trying to normalize. I am not completely sure its right approach to have this check cloned but as `select_transmute_obligation_for_reporting` fn just chooses obligation and doesn't actually return an error, this check shouldn't be removed from `get_safe_transmute_error_and_reasnon`. If there is any better solution, let me kmow. Fixes: rust-lang/rust#153755 r? @jdonszelmann
This commit is contained in:
@@ -2878,6 +2878,10 @@ fn select_transmute_obligation_for_reporting(
|
||||
trait_predicate: ty::PolyTraitPredicate<'tcx>,
|
||||
root_obligation: &PredicateObligation<'tcx>,
|
||||
) -> (PredicateObligation<'tcx>, ty::PolyTraitPredicate<'tcx>) {
|
||||
if obligation.predicate.has_non_region_param() || obligation.has_non_region_infer() {
|
||||
return (obligation.clone(), trait_predicate);
|
||||
}
|
||||
|
||||
let ocx = ObligationCtxt::new(self);
|
||||
let normalized_predicate = self.tcx.erase_and_anonymize_regions(
|
||||
self.tcx.instantiate_bound_regions_with_erased(trait_predicate),
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
//! Regression test for: <https://github.com/rust-lang/rust/issues/153755>
|
||||
#![feature(transmutability)]
|
||||
|
||||
fn foo<T, U>(x: T) -> U {
|
||||
unsafe {
|
||||
std::mem::TransmuteFrom::transmute(x)
|
||||
//~^ ERROR: the trait bound `U: TransmuteFrom<T, _>` is not satisfied [E0277]
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,11 @@
|
||||
error[E0277]: the trait bound `U: TransmuteFrom<T, _>` is not satisfied
|
||||
--> $DIR/generic-transmute-from-regression.rs:6:44
|
||||
|
|
||||
LL | std::mem::TransmuteFrom::transmute(x)
|
||||
| ---------------------------------- ^ the nightly-only, unstable trait `TransmuteFrom<T, _>` is not implemented for `U`
|
||||
| |
|
||||
| required by a bound introduced by this call
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0277`.
|
||||
Reference in New Issue
Block a user