Skip to content

Commit fd45124

Browse files
committed
add generic & unresolved inference variables handling in select_transmute_obligation_for_reporting
1 parent d097a0c commit fd45124

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
@@ -2832,6 +2832,10 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
28322832
trait_predicate: ty::PolyTraitPredicate<'tcx>,
28332833
root_obligation: &PredicateObligation<'tcx>,
28342834
) -> (PredicateObligation<'tcx>, ty::PolyTraitPredicate<'tcx>) {
2835+
if obligation.predicate.has_non_region_param() || obligation.has_non_region_infer() {
2836+
return (obligation.clone(), trait_predicate);
2837+
}
2838+
28352839
let ocx = ObligationCtxt::new(self);
28362840
let normalized_predicate = self.tcx.erase_and_anonymize_regions(
28372841
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)