Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
ShoyuVanilla committed Aug 29, 2024
1 parent 0ae42bd commit 35895fb
Show file tree
Hide file tree
Showing 9 changed files with 405 additions and 28 deletions.
20 changes: 17 additions & 3 deletions crates/hir-ty/src/consteval/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,13 @@ fn floating_point() {

#[test]
fn casts() {
check_number(r#"const GOAL: usize = 12 as *const i32 as usize"#, 12);
check_number(
r#"
//- minicore: sized
const GOAL: usize = 12 as *const i32 as usize
"#,
12,
);
check_number(
r#"
//- minicore: coerce_unsized, index, slice
Expand All @@ -204,7 +210,7 @@ fn casts() {
r#"
//- minicore: coerce_unsized, index, slice
const GOAL: i16 = {
let a = &mut 5;
let a = &mut 5_i16;
let z = a as *mut _;
unsafe { *z }
};
Expand Down Expand Up @@ -244,7 +250,13 @@ fn casts() {
"#,
4,
);
check_number(r#"const GOAL: i32 = -12i8 as i32"#, -12);
check_number(
r#"
//- minicore: sized
const GOAL: i32 = -12i8 as i32
"#,
-12,
);
}

#[test]
Expand Down Expand Up @@ -2422,6 +2434,7 @@ fn statics() {
fn extern_weak_statics() {
check_number(
r#"
//- minicore: sized
extern "C" {
#[linkage = "extern_weak"]
static __dso_handle: *mut u8;
Expand Down Expand Up @@ -2716,6 +2729,7 @@ fn const_trait_assoc() {
);
check_number(
r#"
//- minicore: sized
struct S<T>(*mut T);
trait MySized: Sized {
Expand Down
1 change: 1 addition & 0 deletions crates/hir-ty/src/consteval/tests/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ fn saturating() {
fn allocator() {
check_number(
r#"
//- minicore: sized
extern "Rust" {
#[rustc_allocator]
fn __rust_alloc(size: usize, align: usize) -> *mut u8;
Expand Down
14 changes: 13 additions & 1 deletion crates/hir-ty/src/infer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,10 @@ pub enum InferenceDiagnostic {
expr: ExprId,
expected: Ty,
},
// CastToUnsized {
// expr: ExprId,
// cast_ty: Ty,
// },
}

/// A mismatch between an expected and an inferred type.
Expand Down Expand Up @@ -703,7 +707,15 @@ impl<'a> InferenceContext<'a> {
// Even though coercion casts provide type hints, we check casts after fallback for
// backwards compatibility. This makes fallback a stronger type hint than a cast coercion.
for cast in deferred_cast_checks {
cast.check(&mut table);
let expr = cast.expr();

Check failure on line 710 in crates/hir-ty/src/infer.rs

View workflow job for this annotation

GitHub Actions / Rust (ubuntu-latest)

unused variable: `expr`
match cast.check(&mut table) {
Ok(Some(adjustments)) => {

Check failure on line 712 in crates/hir-ty/src/infer.rs

View workflow job for this annotation

GitHub Actions / Rust (ubuntu-latest)

unused variable: `adjustments`
// Using this causes some mir lowerings failures
// expr_adjustments.insert(expr, adjustments);
}
Ok(None) => (),
Err(diag) => diagnostics.push(diag),
}
}

// FIXME resolve obligations as well (use Guidance if necessary)
Expand Down
Loading

0 comments on commit 35895fb

Please sign in to comment.