Skip to content

Commit 0a5a5c3

Browse files
committed
revert making casts atomic, test order dependency
1 parent 7353ef7 commit 0a5a5c3

File tree

5 files changed

+39
-3
lines changed

5 files changed

+39
-3
lines changed

src/librustc_typeck/check/cast.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -389,8 +389,8 @@ impl<'a, 'gcx, 'tcx> CastCheck<'tcx> {
389389
}
390390

391391
pub fn check(mut self, fcx: &FnCtxt<'a, 'gcx, 'tcx>) {
392-
self.expr_ty = fcx.resolve_type_vars_if_possible(&self.expr_ty);
393-
self.cast_ty = fcx.resolve_type_vars_if_possible(&self.cast_ty);
392+
self.expr_ty = fcx.structurally_resolved_type(self.span, self.expr_ty);
393+
self.cast_ty = fcx.structurally_resolved_type(self.span, self.cast_ty);
394394

395395
debug!("check_cast({}, {:?} as {:?})",
396396
self.expr.id,

src/librustc_typeck/check/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3639,7 +3639,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
36393639
needs);
36403640

36413641
if !oprnd_t.references_error() {
3642-
oprnd_t = self.resolve_type_vars_with_obligations(&oprnd_t);
3642+
oprnd_t = self.structurally_resolved_type(expr.span, oprnd_t);
36433643
match unop {
36443644
hir::UnDeref => {
36453645
if let Some(mt) = oprnd_t.builtin_deref(true) {

src/test/run-pass/cast.rs

+5
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,9 @@ pub fn main() {
1919
assert_eq!(i as u8 as i8, 'Q' as u8 as i8);
2020
assert_eq!(0x51 as char, 'Q');
2121
assert_eq!(0 as u32, false as u32);
22+
23+
// Test that `_` is correctly inferred.
24+
let x = &"hello";
25+
let mut y = x as *const _;
26+
y = 0 as *const _;
2227
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
fn main() {
12+
// Tests case where inference fails due to the order in which casts are checked.
13+
// Ideally this would compile, see #48270.
14+
let x = &"hello";
15+
let mut y = 0 as *const _;
16+
//~^ ERROR cannot cast to a pointer of an unknown kind
17+
y = x as *const _;
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
error[E0641]: cannot cast to a pointer of an unknown kind
2+
--> $DIR/order-dependent-cast-inference.rs:15:17
3+
|
4+
LL | let mut y = 0 as *const _;
5+
| ^^^^^--------
6+
| |
7+
| help: consider giving more type information
8+
|
9+
= note: The type information given here is insufficient to check whether the pointer cast is valid
10+
11+
error: aborting due to previous error
12+
13+
For more information about this error, try `rustc --explain E0641`.

0 commit comments

Comments
 (0)