mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-28 04:45:05 +00:00
Fixup some issues with minicore
This commit is contained in:
parent
563bb6bd6c
commit
5df690e13f
4 changed files with 73 additions and 48 deletions
|
@ -12,7 +12,7 @@ authors = ["rust-analyzer team"]
|
||||||
[profile.dev]
|
[profile.dev]
|
||||||
# Disabling debug info speeds up builds a bunch,
|
# Disabling debug info speeds up builds a bunch,
|
||||||
# and we don't rely on it for debugging that much.
|
# and we don't rely on it for debugging that much.
|
||||||
debug = 0
|
debug = 1
|
||||||
|
|
||||||
[profile.dev.package]
|
[profile.dev.package]
|
||||||
# These speed up local tests.
|
# These speed up local tests.
|
||||||
|
|
|
@ -1869,42 +1869,45 @@ impl ExprCollector<'_> {
|
||||||
) -> ExprId {
|
) -> ExprId {
|
||||||
match count {
|
match count {
|
||||||
Some(FormatCount::Literal(n)) => {
|
Some(FormatCount::Literal(n)) => {
|
||||||
match LangItem::FormatCount.ty_rel_path(self.db, self.krate, name![Is]) {
|
let args = self.alloc_expr_desugared(Expr::Literal(Literal::Uint(
|
||||||
Some(count_is) => {
|
*n as u128,
|
||||||
let count_is = self.alloc_expr_desugared(Expr::Path(count_is));
|
Some(BuiltinUint::Usize),
|
||||||
let args = self.alloc_expr_desugared(Expr::Literal(Literal::Uint(
|
)));
|
||||||
*n as u128,
|
let count_is =
|
||||||
Some(BuiltinUint::Usize),
|
match LangItem::FormatCount.ty_rel_path(self.db, self.krate, name![Is]) {
|
||||||
)));
|
Some(count_is) => self.alloc_expr_desugared(Expr::Path(count_is)),
|
||||||
self.alloc_expr_desugared(Expr::Call {
|
None => self.missing_expr(),
|
||||||
callee: count_is,
|
};
|
||||||
args: Box::new([args]),
|
self.alloc_expr_desugared(Expr::Call {
|
||||||
is_assignee_expr: false,
|
callee: count_is,
|
||||||
})
|
args: Box::new([args]),
|
||||||
}
|
is_assignee_expr: false,
|
||||||
None => self.missing_expr(),
|
})
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Some(FormatCount::Argument(arg)) => {
|
Some(FormatCount::Argument(arg)) => {
|
||||||
if let Ok(arg_index) = arg.index {
|
if let Ok(arg_index) = arg.index {
|
||||||
let (i, _) = argmap.insert_full((arg_index, ArgumentType::Usize));
|
let (i, _) = argmap.insert_full((arg_index, ArgumentType::Usize));
|
||||||
|
|
||||||
match LangItem::FormatCount.ty_rel_path(self.db, self.krate, name![Param]) {
|
let args = self.alloc_expr_desugared(Expr::Literal(Literal::Uint(
|
||||||
Some(count_param) => {
|
i as u128,
|
||||||
let count_param = self.alloc_expr_desugared(Expr::Path(count_param));
|
Some(BuiltinUint::Usize),
|
||||||
let args = self.alloc_expr_desugared(Expr::Literal(Literal::Uint(
|
)));
|
||||||
i as u128,
|
let count_param = match LangItem::FormatCount.ty_rel_path(
|
||||||
Some(BuiltinUint::Usize),
|
self.db,
|
||||||
)));
|
self.krate,
|
||||||
self.alloc_expr_desugared(Expr::Call {
|
name![Param],
|
||||||
callee: count_param,
|
) {
|
||||||
args: Box::new([args]),
|
Some(count_param) => self.alloc_expr_desugared(Expr::Path(count_param)),
|
||||||
is_assignee_expr: false,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
None => self.missing_expr(),
|
None => self.missing_expr(),
|
||||||
}
|
};
|
||||||
|
self.alloc_expr_desugared(Expr::Call {
|
||||||
|
callee: count_param,
|
||||||
|
args: Box::new([args]),
|
||||||
|
is_assignee_expr: false,
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
|
// FIXME: This drops arg causing it to potentially not be resolved/type checked
|
||||||
|
// when typing?
|
||||||
self.missing_expr()
|
self.missing_expr()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1925,7 +1928,8 @@ impl ExprCollector<'_> {
|
||||||
fn make_argument(&mut self, arg: ExprId, ty: ArgumentType) -> ExprId {
|
fn make_argument(&mut self, arg: ExprId, ty: ArgumentType) -> ExprId {
|
||||||
use ArgumentType::*;
|
use ArgumentType::*;
|
||||||
use FormatTrait::*;
|
use FormatTrait::*;
|
||||||
match LangItem::FormatArgument.ty_rel_path(
|
|
||||||
|
let new_fn = match LangItem::FormatArgument.ty_rel_path(
|
||||||
self.db,
|
self.db,
|
||||||
self.krate,
|
self.krate,
|
||||||
match ty {
|
match ty {
|
||||||
|
@ -1941,16 +1945,14 @@ impl ExprCollector<'_> {
|
||||||
Usize => name![from_usize],
|
Usize => name![from_usize],
|
||||||
},
|
},
|
||||||
) {
|
) {
|
||||||
Some(new_fn) => {
|
Some(new_fn) => self.alloc_expr_desugared(Expr::Path(new_fn)),
|
||||||
let new_fn = self.alloc_expr_desugared(Expr::Path(new_fn));
|
|
||||||
self.alloc_expr_desugared(Expr::Call {
|
|
||||||
callee: new_fn,
|
|
||||||
args: Box::new([arg]),
|
|
||||||
is_assignee_expr: false,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
None => self.missing_expr(),
|
None => self.missing_expr(),
|
||||||
}
|
};
|
||||||
|
self.alloc_expr_desugared(Expr::Call {
|
||||||
|
callee: new_fn,
|
||||||
|
args: Box::new([arg]),
|
||||||
|
is_assignee_expr: false,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
// endregion: format
|
// endregion: format
|
||||||
}
|
}
|
||||||
|
|
|
@ -391,6 +391,7 @@ FormatArgsExpr =
|
||||||
FormatArgsArg =
|
FormatArgsArg =
|
||||||
(Name '=')? Expr
|
(Name '=')? Expr
|
||||||
|
|
||||||
|
# MacroCallExpr
|
||||||
MacroExpr =
|
MacroExpr =
|
||||||
MacroCall
|
MacroCall
|
||||||
|
|
||||||
|
|
|
@ -913,6 +913,7 @@ pub mod fmt {
|
||||||
}
|
}
|
||||||
|
|
||||||
mod rt {
|
mod rt {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
type Opaque;
|
type Opaque;
|
||||||
|
@ -930,8 +931,8 @@ pub mod fmt {
|
||||||
unsafe { Argument { formatter: transmute(f), value: transmute(x) } }
|
unsafe { Argument { formatter: transmute(f), value: transmute(x) } }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_display<'b, T: Display>(x: &'b T) -> Argument<'_> {
|
pub fn new_display<'b, T: crate::fmt::Display>(x: &'b T) -> Argument<'_> {
|
||||||
Self::new(x, Display::fmt)
|
Self::new(x, crate::fmt::Display::fmt)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -968,7 +969,9 @@ pub mod fmt {
|
||||||
flags: u32,
|
flags: u32,
|
||||||
precision: Count,
|
precision: Count,
|
||||||
width: Count,
|
width: Count,
|
||||||
) -> Self;
|
) -> Self {
|
||||||
|
Placeholder { position, fill, align, flags, precision, width }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[lang = "format_unsafe_arg"]
|
#[lang = "format_unsafe_arg"]
|
||||||
|
@ -1007,6 +1010,14 @@ pub mod fmt {
|
||||||
) -> Arguments<'a> {
|
) -> Arguments<'a> {
|
||||||
Arguments { pieces, fmt: Some(fmt), args }
|
Arguments { pieces, fmt: Some(fmt), args }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub const fn as_str(&self) -> Option<&'static str> {
|
||||||
|
match (self.pieces, self.args) {
|
||||||
|
([], []) => Some(""),
|
||||||
|
([s], []) => Some(s),
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// region:derive
|
// region:derive
|
||||||
|
@ -1156,8 +1167,8 @@ pub mod pin {
|
||||||
pointer: P,
|
pointer: P,
|
||||||
}
|
}
|
||||||
impl<P> Pin<P> {
|
impl<P> Pin<P> {
|
||||||
pub fn new(_pointer: P) -> Pin<P> {
|
pub fn new(pointer: P) -> Pin<P> {
|
||||||
loop {}
|
Pin { pointer }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// region:deref
|
// region:deref
|
||||||
|
@ -1382,12 +1393,23 @@ mod panic {
|
||||||
|
|
||||||
mod panicking {
|
mod panicking {
|
||||||
#[rustc_const_panic_str] // enforce a &&str argument in const-check and hook this by const-eval
|
#[rustc_const_panic_str] // enforce a &&str argument in const-check and hook this by const-eval
|
||||||
pub const fn panic_display<T: fmt::Display>(x: &T) -> ! {
|
pub const fn panic_display<T: crate::fmt::Display>(x: &T) -> ! {
|
||||||
panic_fmt(format_args!("{}", *x));
|
panic_fmt(crate::format_args!("{}", *x));
|
||||||
|
}
|
||||||
|
|
||||||
|
// This function is used instead of panic_fmt in const eval.
|
||||||
|
#[lang = "const_panic_fmt"]
|
||||||
|
pub const fn const_panic_fmt(fmt: crate::fmt::Arguments<'_>) -> ! {
|
||||||
|
if let Some(msg) = fmt.as_str() {
|
||||||
|
// The panic_display function is hooked by const eval.
|
||||||
|
panic_display(&msg);
|
||||||
|
} else {
|
||||||
|
loop {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[lang = "panic_fmt"] // needed for const-evaluated panics
|
#[lang = "panic_fmt"] // needed for const-evaluated panics
|
||||||
pub const fn panic_fmt(fmt: fmt::Arguments<'_>) -> ! {
|
pub const fn panic_fmt(fmt: crate::fmt::Arguments<'_>) -> ! {
|
||||||
loop {}
|
loop {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue