Skip to content

Commit 429a381

Browse files
committed
Auto merge of rust-lang#15363 - HKalbasi:mir, r=HKalbasi
Support `Self` without field in mir lowering
2 parents cecbed9 + a9d81ae commit 429a381

File tree

2 files changed

+45
-4
lines changed

2 files changed

+45
-4
lines changed

crates/hir-ty/src/mir/eval/tests.rs

+44
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,50 @@ fn main() {
613613
);
614614
}
615615

616+
#[test]
617+
fn self_with_capital_s() {
618+
check_pass(
619+
r#"
620+
//- minicore: fn, add, copy
621+
622+
struct S1;
623+
624+
impl S1 {
625+
fn f() {
626+
Self;
627+
}
628+
}
629+
630+
struct S2 {
631+
f1: i32,
632+
}
633+
634+
impl S2 {
635+
fn f() {
636+
Self { f1: 5 };
637+
}
638+
}
639+
640+
struct S3(i32);
641+
642+
impl S3 {
643+
fn f() {
644+
Self(2);
645+
Self;
646+
let this = Self;
647+
this(2);
648+
}
649+
}
650+
651+
fn main() {
652+
S1::f();
653+
S2::f();
654+
S3::f();
655+
}
656+
"#,
657+
);
658+
}
659+
616660
#[test]
617661
fn syscalls() {
618662
check_pass(

crates/hir-ty/src/mir/lower.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -486,13 +486,10 @@ impl<'ctx> MirLowerCtx<'ctx> {
486486
);
487487
Ok(Some(current))
488488
}
489-
ValueNs::FunctionId(_) | ValueNs::StructId(_) => {
489+
ValueNs::FunctionId(_) | ValueNs::StructId(_) | ValueNs::ImplSelf(_) => {
490490
// It's probably a unit struct or a zero sized function, so no action is needed.
491491
Ok(Some(current))
492492
}
493-
it => {
494-
not_supported!("unknown name {it:?} in value name space");
495-
}
496493
}
497494
}
498495
Expr::If { condition, then_branch, else_branch } => {

0 commit comments

Comments
 (0)