Skip to content

Commit 14a75f6

Browse files
committed
Fixup some issues with minicore
1 parent 6f6a6d5 commit 14a75f6

File tree

4 files changed

+73
-48
lines changed

4 files changed

+73
-48
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ authors = ["rust-analyzer team"]
1212
[profile.dev]
1313
# Disabling debug info speeds up builds a bunch,
1414
# and we don't rely on it for debugging that much.
15-
debug = 0
15+
debug = 1
1616

1717
[profile.dev.package]
1818
# These speed up local tests.

crates/hir-def/src/body/lower.rs

+41-39
Original file line numberDiff line numberDiff line change
@@ -1869,42 +1869,45 @@ impl ExprCollector<'_> {
18691869
) -> ExprId {
18701870
match count {
18711871
Some(FormatCount::Literal(n)) => {
1872-
match LangItem::FormatCount.ty_rel_path(self.db, self.krate, name![Is]) {
1873-
Some(count_is) => {
1874-
let count_is = self.alloc_expr_desugared(Expr::Path(count_is));
1875-
let args = self.alloc_expr_desugared(Expr::Literal(Literal::Uint(
1876-
*n as u128,
1877-
Some(BuiltinUint::Usize),
1878-
)));
1879-
self.alloc_expr_desugared(Expr::Call {
1880-
callee: count_is,
1881-
args: Box::new([args]),
1882-
is_assignee_expr: false,
1883-
})
1884-
}
1885-
None => self.missing_expr(),
1886-
}
1872+
let args = self.alloc_expr_desugared(Expr::Literal(Literal::Uint(
1873+
*n as u128,
1874+
Some(BuiltinUint::Usize),
1875+
)));
1876+
let count_is =
1877+
match LangItem::FormatCount.ty_rel_path(self.db, self.krate, name![Is]) {
1878+
Some(count_is) => self.alloc_expr_desugared(Expr::Path(count_is)),
1879+
None => self.missing_expr(),
1880+
};
1881+
self.alloc_expr_desugared(Expr::Call {
1882+
callee: count_is,
1883+
args: Box::new([args]),
1884+
is_assignee_expr: false,
1885+
})
18871886
}
18881887
Some(FormatCount::Argument(arg)) => {
18891888
if let Ok(arg_index) = arg.index {
18901889
let (i, _) = argmap.insert_full((arg_index, ArgumentType::Usize));
18911890

1892-
match LangItem::FormatCount.ty_rel_path(self.db, self.krate, name![Param]) {
1893-
Some(count_param) => {
1894-
let count_param = self.alloc_expr_desugared(Expr::Path(count_param));
1895-
let args = self.alloc_expr_desugared(Expr::Literal(Literal::Uint(
1896-
i as u128,
1897-
Some(BuiltinUint::Usize),
1898-
)));
1899-
self.alloc_expr_desugared(Expr::Call {
1900-
callee: count_param,
1901-
args: Box::new([args]),
1902-
is_assignee_expr: false,
1903-
})
1904-
}
1891+
let args = self.alloc_expr_desugared(Expr::Literal(Literal::Uint(
1892+
i as u128,
1893+
Some(BuiltinUint::Usize),
1894+
)));
1895+
let count_param = match LangItem::FormatCount.ty_rel_path(
1896+
self.db,
1897+
self.krate,
1898+
name![Param],
1899+
) {
1900+
Some(count_param) => self.alloc_expr_desugared(Expr::Path(count_param)),
19051901
None => self.missing_expr(),
1906-
}
1902+
};
1903+
self.alloc_expr_desugared(Expr::Call {
1904+
callee: count_param,
1905+
args: Box::new([args]),
1906+
is_assignee_expr: false,
1907+
})
19071908
} else {
1909+
// FIXME: This drops arg causing it to potentially not be resolved/type checked
1910+
// when typing?
19081911
self.missing_expr()
19091912
}
19101913
}
@@ -1925,7 +1928,8 @@ impl ExprCollector<'_> {
19251928
fn make_argument(&mut self, arg: ExprId, ty: ArgumentType) -> ExprId {
19261929
use ArgumentType::*;
19271930
use FormatTrait::*;
1928-
match LangItem::FormatArgument.ty_rel_path(
1931+
1932+
let new_fn = match LangItem::FormatArgument.ty_rel_path(
19291933
self.db,
19301934
self.krate,
19311935
match ty {
@@ -1941,16 +1945,14 @@ impl ExprCollector<'_> {
19411945
Usize => name![from_usize],
19421946
},
19431947
) {
1944-
Some(new_fn) => {
1945-
let new_fn = self.alloc_expr_desugared(Expr::Path(new_fn));
1946-
self.alloc_expr_desugared(Expr::Call {
1947-
callee: new_fn,
1948-
args: Box::new([arg]),
1949-
is_assignee_expr: false,
1950-
})
1951-
}
1948+
Some(new_fn) => self.alloc_expr_desugared(Expr::Path(new_fn)),
19521949
None => self.missing_expr(),
1953-
}
1950+
};
1951+
self.alloc_expr_desugared(Expr::Call {
1952+
callee: new_fn,
1953+
args: Box::new([arg]),
1954+
is_assignee_expr: false,
1955+
})
19541956
}
19551957
// endregion: format
19561958
}

crates/syntax/rust.ungram

+1
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,7 @@ FormatArgsExpr =
391391
FormatArgsArg =
392392
(Name '=')? Expr
393393

394+
# MacroCallExpr
394395
MacroExpr =
395396
MacroCall
396397

crates/test-utils/src/minicore.rs

+30-8
Original file line numberDiff line numberDiff line change
@@ -913,6 +913,7 @@ pub mod fmt {
913913
}
914914

915915
mod rt {
916+
use super::*;
916917

917918
extern "C" {
918919
type Opaque;
@@ -930,8 +931,8 @@ pub mod fmt {
930931
unsafe { Argument { formatter: transmute(f), value: transmute(x) } }
931932
}
932933

933-
pub fn new_display<'b, T: Display>(x: &'b T) -> Argument<'_> {
934-
Self::new(x, Display::fmt)
934+
pub fn new_display<'b, T: crate::fmt::Display>(x: &'b T) -> Argument<'_> {
935+
Self::new(x, crate::fmt::Display::fmt)
935936
}
936937
}
937938

@@ -968,7 +969,9 @@ pub mod fmt {
968969
flags: u32,
969970
precision: Count,
970971
width: Count,
971-
) -> Self;
972+
) -> Self {
973+
Placeholder { position, fill, align, flags, precision, width }
974+
}
972975
}
973976

974977
#[lang = "format_unsafe_arg"]
@@ -1007,6 +1010,14 @@ pub mod fmt {
10071010
) -> Arguments<'a> {
10081011
Arguments { pieces, fmt: Some(fmt), args }
10091012
}
1013+
1014+
pub const fn as_str(&self) -> Option<&'static str> {
1015+
match (self.pieces, self.args) {
1016+
([], []) => Some(""),
1017+
([s], []) => Some(s),
1018+
_ => None,
1019+
}
1020+
}
10101021
}
10111022

10121023
// region:derive
@@ -1156,8 +1167,8 @@ pub mod pin {
11561167
pointer: P,
11571168
}
11581169
impl<P> Pin<P> {
1159-
pub fn new(_pointer: P) -> Pin<P> {
1160-
loop {}
1170+
pub fn new(pointer: P) -> Pin<P> {
1171+
Pin { pointer }
11611172
}
11621173
}
11631174
// region:deref
@@ -1382,12 +1393,23 @@ mod panic {
13821393

13831394
mod panicking {
13841395
#[rustc_const_panic_str] // enforce a &&str argument in const-check and hook this by const-eval
1385-
pub const fn panic_display<T: fmt::Display>(x: &T) -> ! {
1386-
panic_fmt(format_args!("{}", *x));
1396+
pub const fn panic_display<T: crate::fmt::Display>(x: &T) -> ! {
1397+
panic_fmt(crate::format_args!("{}", *x));
1398+
}
1399+
1400+
// This function is used instead of panic_fmt in const eval.
1401+
#[lang = "const_panic_fmt"]
1402+
pub const fn const_panic_fmt(fmt: crate::fmt::Arguments<'_>) -> ! {
1403+
if let Some(msg) = fmt.as_str() {
1404+
// The panic_display function is hooked by const eval.
1405+
panic_display(&msg);
1406+
} else {
1407+
loop {}
1408+
}
13871409
}
13881410

13891411
#[lang = "panic_fmt"] // needed for const-evaluated panics
1390-
pub const fn panic_fmt(fmt: fmt::Arguments<'_>) -> ! {
1412+
pub const fn panic_fmt(fmt: crate::fmt::Arguments<'_>) -> ! {
13911413
loop {}
13921414
}
13931415

0 commit comments

Comments
 (0)