Skip to content

Commit d53dee3

Browse files
authored
Rollup merge of rust-lang#153790 - zedddie:transmutation-regression, r=jdonszelmann
Fix regression when dealing with generics/values with unresolved inference Follow up for rust-lang#151703, fixing regression caused in rollup rust-lang#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#153755 r? @jdonszelmann
2 parents 9f1223c + fd45124 commit d53dee3

3 files changed

Lines changed: 26 additions & 0 deletions

File tree

compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2878,6 +2878,10 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
28782878
trait_predicate: ty::PolyTraitPredicate<'tcx>,
28792879
root_obligation: &PredicateObligation<'tcx>,
28802880
) -> (PredicateObligation<'tcx>, ty::PolyTraitPredicate<'tcx>) {
2881+
if obligation.predicate.has_non_region_param() || obligation.has_non_region_infer() {
2882+
return (obligation.clone(), trait_predicate);
2883+
}
2884+
28812885
let ocx = ObligationCtxt::new(self);
28822886
let normalized_predicate = self.tcx.erase_and_anonymize_regions(
28832887
self.tcx.instantiate_bound_regions_with_erased(trait_predicate),
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//! Regression test for: <https://github.com/rust-lang/rust/issues/153755>
2+
#![feature(transmutability)]
3+
4+
fn foo<T, U>(x: T) -> U {
5+
unsafe {
6+
std::mem::TransmuteFrom::transmute(x)
7+
//~^ ERROR: the trait bound `U: TransmuteFrom<T, _>` is not satisfied [E0277]
8+
}
9+
}
10+
11+
fn main() {}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0277]: the trait bound `U: TransmuteFrom<T, _>` is not satisfied
2+
--> $DIR/generic-transmute-from-regression.rs:6:44
3+
|
4+
LL | std::mem::TransmuteFrom::transmute(x)
5+
| ---------------------------------- ^ the nightly-only, unstable trait `TransmuteFrom<T, _>` is not implemented for `U`
6+
| |
7+
| required by a bound introduced by this call
8+
9+
error: aborting due to 1 previous error
10+
11+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)