Unnamed repository; edit this file 'description' to name the repository.
Merge pull request #22914 from ChayimFriedman2/remove-old-versions
internal: Cleanup code for old Rust versions
Chayim Refael Friedman 14 days ago
parent 4c734bd · parent add23df · commit 0eb393b
-rw-r--r--crates/hir-def/src/expr_store.rs1
-rw-r--r--crates/hir-def/src/expr_store/lower.rs26
-rw-r--r--crates/hir-def/src/expr_store/lower/format_args.rs564
-rw-r--r--crates/hir-def/src/expr_store/pretty.rs4
-rw-r--r--crates/hir-def/src/expr_store/tests/body.rs187
-rw-r--r--crates/hir-def/src/hir.rs7
-rw-r--r--crates/hir-ty/src/consteval/tests.rs7
-rw-r--r--crates/hir-ty/src/dyn_compatibility.rs18
-rw-r--r--crates/hir-ty/src/infer.rs5
-rw-r--r--crates/hir-ty/src/infer/closure/analysis/expr_use_visitor.rs2
-rw-r--r--crates/hir-ty/src/infer/expr.rs25
-rw-r--r--crates/hir-ty/src/infer/mutability.rs1
-rw-r--r--crates/hir-ty/src/mir.rs14
-rw-r--r--crates/hir-ty/src/mir/borrowck.rs9
-rw-r--r--crates/hir-ty/src/mir/eval.rs8
-rw-r--r--crates/hir-ty/src/mir/eval/shim.rs17
-rw-r--r--crates/hir-ty/src/mir/lower.rs16
-rw-r--r--crates/hir-ty/src/mir/monomorphization.rs3
-rw-r--r--crates/hir-ty/src/mir/pretty.rs6
-rw-r--r--crates/hir-ty/src/tests/regression/new_solver.rs57
-rw-r--r--crates/hir-ty/src/tests/simple.rs44
-rw-r--r--crates/ide-diagnostics/src/handlers/missing_unsafe.rs11
-rw-r--r--crates/ide-diagnostics/src/handlers/mutability_errors.rs7
-rw-r--r--crates/ide/src/references.rs2
-rw-r--r--crates/mbe/src/expander/transcriber.rs2
-rw-r--r--crates/mbe/src/parser.rs48
-rw-r--r--crates/project-model/src/build_dependencies.rs4
-rw-r--r--crates/project-model/src/cargo_config_file.rs13
-rw-r--r--crates/project-model/src/cargo_workspace.rs4
-rw-r--r--crates/test-utils/src/minicore.rs106
30 files changed, 94 insertions, 1124 deletions
diff --git a/crates/hir-def/src/expr_store.rs b/crates/hir-def/src/expr_store.rs
index ca3ca39754..32d16957ae 100644
--- a/crates/hir-def/src/expr_store.rs
+++ b/crates/hir-def/src/expr_store.rs
@@ -776,7 +776,6 @@ impl ExpressionStore {
| Expr::Await { expr }
| Expr::Ref { expr, mutability: _, rawness: _ }
| Expr::UnaryOp { expr, op: _ }
- | Expr::Box { expr }
| Expr::Const(expr) => {
visitor.on_expr(*expr);
}
diff --git a/crates/hir-def/src/expr_store/lower.rs b/crates/hir-def/src/expr_store/lower.rs
index f5cf1180eb..df4fc6e531 100644
--- a/crates/hir-def/src/expr_store/lower.rs
+++ b/crates/hir-def/src/expr_store/lower.rs
@@ -26,8 +26,8 @@ use stdx::never;
use syntax::{
AstNode, AstPtr, SyntaxNodePtr,
ast::{
- self, ArrayExprKind, AstChildren, BlockExpr, ForBinder, HasArgList, HasAttrs,
- HasGenericArgs, HasGenericParams, HasLoopBody, HasName, HasTypeBounds, IsString, RangeItem,
+ self, ArrayExprKind, AstChildren, BlockExpr, ForBinder, HasArgList, HasGenericArgs,
+ HasGenericParams, HasLoopBody, HasName, HasTypeBounds, IsString, RangeItem,
SlicePatComponents,
},
};
@@ -1460,23 +1460,13 @@ impl<'db> ExprCollector<'db> {
ast::Expr::WhileExpr(e) => self.collect_while_loop(syntax_ptr, e),
ast::Expr::ForExpr(e) => self.collect_for_loop(syntax_ptr, e),
ast::Expr::CallExpr(e) => {
- // FIXME(MINIMUM_SUPPORTED_TOOLCHAIN_VERSION): Remove this once we drop support for <1.86, https://github.com/rust-lang/rust/commit/ac9cb908ac4301dfc25e7a2edee574320022ae2c
- let is_rustc_box = {
- let attrs = e.attrs();
- attrs.filter_map(|it| it.as_simple_atom()).any(|it| it == "rustc_box")
- };
- if is_rustc_box {
- let expr = self.collect_expr_opt(e.arg_list().and_then(|it| it.args().next()));
- self.alloc_expr(Expr::Box { expr }, syntax_ptr)
+ let callee = self.collect_expr_opt(e.expr());
+ let args = if let Some(arg_list) = e.arg_list() {
+ arg_list.args().filter_map(|e| self.maybe_collect_expr(e)).collect()
} else {
- let callee = self.collect_expr_opt(e.expr());
- let args = if let Some(arg_list) = e.arg_list() {
- arg_list.args().filter_map(|e| self.maybe_collect_expr(e)).collect()
- } else {
- Box::default()
- };
- self.alloc_expr(Expr::Call { callee, args }, syntax_ptr)
- }
+ Box::default()
+ };
+ self.alloc_expr(Expr::Call { callee, args }, syntax_ptr)
}
ast::Expr::MethodCallExpr(e) => {
let receiver = self.collect_expr_opt(e.receiver());
diff --git a/crates/hir-def/src/expr_store/lower/format_args.rs b/crates/hir-def/src/expr_store/lower/format_args.rs
index 1ecd18fb53..5552213aba 100644
--- a/crates/hir-def/src/expr_store/lower/format_args.rs
+++ b/crates/hir-def/src/expr_store/lower/format_args.rs
@@ -5,18 +5,14 @@ use hir_expand::name::Name;
use intern::{Symbol, sym};
use span::SyntaxContext;
use syntax::{AstPtr, AstToken as _, ast};
-use thin_vec::ThinVec;
use crate::{
- builtin_type::BuiltinUint,
expr_store::{HygieneId, lower::ExprCollector, path::Path},
hir::{
- Array, BindingAnnotation, Expr, ExprId, Literal, Pat, RecordLitField, RecordSpread,
- Statement,
+ Array, BindingAnnotation, Expr, ExprId, Literal, Pat, Statement,
format_args::{
self, FormatAlignment, FormatArgs, FormatArgsPiece, FormatArgument, FormatArgumentKind,
- FormatArgumentsCollector, FormatCount, FormatDebugHex, FormatOptions,
- FormatPlaceholder, FormatSign, FormatTrait,
+ FormatArgumentsCollector, FormatCount, FormatDebugHex, FormatSign, FormatTrait,
},
},
lang_item::LangItemTarget,
@@ -96,11 +92,7 @@ impl<'db> ExprCollector<'db> {
),
};
- let idx = if self.lang_items().FormatCount.is_none() {
- self.collect_format_args_after_1_93_0_impl(syntax_ptr, fmt)
- } else {
- self.collect_format_args_before_1_93_0_impl(syntax_ptr, fmt)
- };
+ let idx = self.collect_format_args_impl(syntax_ptr, fmt);
self.store
.template_map
@@ -110,7 +102,9 @@ impl<'db> ExprCollector<'db> {
idx
}
- fn collect_format_args_after_1_93_0_impl(
+ // This is in separate functions because historically, changes in format_args lowering have forced us to change this
+ // function but not its caller, and for some time support both versions.
+ fn collect_format_args_impl(
&mut self,
syntax_ptr: AstPtr<ast::Expr>,
fmt: FormatArgs,
@@ -433,552 +427,6 @@ impl<'db> ExprCollector<'db> {
}
}
- fn collect_format_args_before_1_93_0_impl(
- &mut self,
- syntax_ptr: AstPtr<ast::Expr>,
- fmt: FormatArgs,
- ) -> ExprId {
- // Create a list of all _unique_ (argument, format trait) combinations.
- // E.g. "{0} {0:x} {0} {1}" -> [(0, Display), (0, LowerHex), (1, Display)]
- let mut argmap = FxIndexSet::default();
- for piece in fmt.template.iter() {
- let FormatArgsPiece::Placeholder(placeholder) = piece else { continue };
- if let Ok(index) = placeholder.argument.index {
- argmap.insert((index, ArgumentType::Format(placeholder.format_trait)));
- }
- }
-
- let lit_pieces = fmt
- .template
- .iter()
- .enumerate()
- .filter_map(|(i, piece)| {
- match piece {
- FormatArgsPiece::Literal(s) => {
- Some(self.alloc_expr_desugared(Expr::Literal(Literal::String(s.clone()))))
- }
- &FormatArgsPiece::Placeholder(_) => {
- // Inject empty string before placeholders when not already preceded by a literal piece.
- if i == 0 || matches!(fmt.template[i - 1], FormatArgsPiece::Placeholder(_))
- {
- Some(self.alloc_expr_desugared(Expr::Literal(Literal::String(
- Symbol::empty(),
- ))))
- } else {
- None
- }
- }
- }
- })
- .collect();
- let lit_pieces =
- self.alloc_expr_desugared(Expr::Array(Array::ElementList { elements: lit_pieces }));
- let lit_pieces = self.alloc_expr_desugared(Expr::Ref {
- expr: lit_pieces,
- rawness: Rawness::Ref,
- mutability: Mutability::Shared,
- });
- let format_options = {
- // Generate:
- // &[format_spec_0, format_spec_1, format_spec_2]
- let elements = fmt
- .template
- .iter()
- .filter_map(|piece| {
- let FormatArgsPiece::Placeholder(placeholder) = piece else { return None };
- Some(self.make_format_spec(placeholder, &mut argmap))
- })
- .collect();
- let array = self.alloc_expr_desugared(Expr::Array(Array::ElementList { elements }));
- self.alloc_expr_desugared(Expr::Ref {
- expr: array,
- rawness: Rawness::Ref,
- mutability: Mutability::Shared,
- })
- };
-
- // Assume that rustc version >= 1.89.0 iff lang item `format_arguments` exists
- // but `format_unsafe_arg` does not
- let lang_items = self.lang_items();
- let fmt_args = lang_items.FormatArguments;
- let fmt_unsafe_arg = lang_items.FormatUnsafeArg;
- let use_format_args_since_1_89_0 = fmt_args.is_some() && fmt_unsafe_arg.is_none();
-
- if use_format_args_since_1_89_0 {
- self.collect_format_args_after_1_89_0_impl(
- syntax_ptr,
- fmt,
- argmap,
- lit_pieces,
- format_options,
- )
- } else {
- self.collect_format_args_before_1_89_0_impl(
- syntax_ptr,
- fmt,
- argmap,
- lit_pieces,
- format_options,
- )
- }
- }
-
- /// `format_args!` expansion implementation for rustc versions < `1.89.0`
- fn collect_format_args_before_1_89_0_impl(
- &mut self,
- syntax_ptr: AstPtr<ast::Expr>,
- fmt: FormatArgs,
- argmap: FxIndexSet<(usize, ArgumentType)>,
- lit_pieces: ExprId,
- format_options: ExprId,
- ) -> ExprId {
- let arguments = &*fmt.arguments.arguments;
-
- let args = if arguments.is_empty() {
- let expr = self
- .alloc_expr_desugared(Expr::Array(Array::ElementList { elements: Box::default() }));
- self.alloc_expr_desugared(Expr::Ref {
- expr,
- rawness: Rawness::Ref,
- mutability: Mutability::Shared,
- })
- } else {
- // Generate:
- // &match (&arg0, &arg1, &…) {
- // args => [
- // <core::fmt::Argument>::new_display(args.0),
- // <core::fmt::Argument>::new_lower_hex(args.1),
- // <core::fmt::Argument>::new_debug(args.0),
- // …
- // ]
- // }
- let args = argmap
- .iter()
- .map(|&(arg_index, ty)| {
- let arg = self.alloc_expr_desugared(Expr::Ref {
- expr: arguments[arg_index].expr,
- rawness: Rawness::Ref,
- mutability: Mutability::Shared,
- });
- let arg_ptr = arguments.get(arg_index).and_then(|it| it.syntax);
- self.make_argument(arg_ptr, arg, ty)
- })
- .collect();
- let array =
- self.alloc_expr_desugared(Expr::Array(Array::ElementList { elements: args }));
- self.alloc_expr_desugared(Expr::Ref {
- expr: array,
- rawness: Rawness::Ref,
- mutability: Mutability::Shared,
- })
- };
-
- // Generate:
- // <core::fmt::Arguments>::new_v1_formatted(
- // lit_pieces,
- // args,
- // format_options,
- // unsafe { ::core::fmt::UnsafeArg::new() }
- // )
-
- let lang_items = self.lang_items();
- let new_v1_formatted =
- self.ty_rel_lang_path_desugared_expr(lang_items.FormatArguments, sym::new_v1_formatted);
- let unsafe_arg_new =
- self.ty_rel_lang_path_desugared_expr(lang_items.FormatUnsafeArg, sym::new);
- let unsafe_arg_new =
- self.alloc_expr_desugared(Expr::Call { callee: unsafe_arg_new, args: Box::default() });
- let mut unsafe_arg_new = self.alloc_expr_desugared(Expr::Unsafe {
- id: None,
- statements: Box::new([]),
- tail: Some(unsafe_arg_new),
- });
- if !fmt.orphans.is_empty() {
- unsafe_arg_new = self.alloc_expr_desugared(Expr::Block {
- id: None,
- // We collect the unused expressions here so that we still infer them instead of
- // dropping them out of the expression tree. We cannot store them in the `Unsafe`
- // block because then unsafe blocks within them will get a false "unused unsafe"
- // diagnostic (rustc has a notion of builtin unsafe blocks, but we don't).
- statements: fmt
- .orphans
- .into_iter()
- .map(|expr| Statement::Expr { expr, has_semi: true })
- .collect(),
- tail: Some(unsafe_arg_new),
- label: None,
- });
- }
-
- self.alloc_expr(
- Expr::Call {
- callee: new_v1_formatted,
- args: Box::new([lit_pieces, args, format_options, unsafe_arg_new]),
- },
- syntax_ptr,
- )
- }
-
- /// `format_args!` expansion implementation for rustc versions >= `1.89.0`,
- /// especially since [this PR](https://github.com/rust-lang/rust/pull/140748)
- fn collect_format_args_after_1_89_0_impl(
- &mut self,
- syntax_ptr: AstPtr<ast::Expr>,
- fmt: FormatArgs,
- argmap: FxIndexSet<(usize, ArgumentType)>,
- lit_pieces: ExprId,
- format_options: ExprId,
- ) -> ExprId {
- let arguments = &*fmt.arguments.arguments;
-
- let (let_stmts, args) = if arguments.is_empty() {
- (
- // Generate:
- // []
- vec![],
- self.alloc_expr_desugared(Expr::Array(Array::ElementList {
- elements: Box::default(),
- })),
- )
- } else if argmap.len() == 1 && arguments.len() == 1 {
- // Only one argument, so we don't need to make the `args` tuple.
- //
- // Generate:
- // super let args = [<core::fmt::Arguments>::new_display(&arg)];
- let args = argmap
- .iter()
- .map(|&(arg_index, ty)| {
- let ref_arg = self.alloc_expr_desugared(Expr::Ref {
- expr: arguments[arg_index].expr,
- rawness: Rawness::Ref,
- mutability: Mutability::Shared,
- });
- let arg_ptr = arguments.get(arg_index).and_then(|it| it.syntax);
- self.make_argument(arg_ptr, ref_arg, ty)
- })
- .collect();
- let args =
- self.alloc_expr_desugared(Expr::Array(Array::ElementList { elements: args }));
- let args_name = self.generate_new_name();
- let args_binding = self.alloc_binding(
- args_name.clone(),
- BindingAnnotation::Unannotated,
- HygieneId::ROOT,
- );
- let args_pat = self.alloc_pat_desugared(Pat::Bind { id: args_binding, subpat: None });
- self.add_definition_to_binding(args_binding, args_pat);
- // TODO: We don't have `super let` yet.
- let let_stmt = Statement::Let {
- pat: args_pat,
- type_ref: None,
- initializer: Some(args),
- else_branch: None,
- };
- (vec![let_stmt], self.alloc_expr_desugared(Expr::Path(args_name.into())))
- } else {
- // Generate:
- // super let args = (&arg0, &arg1, &...);
- let args_name = self.generate_new_name();
- let args_binding = self.alloc_binding(
- args_name.clone(),
- BindingAnnotation::Unannotated,
- HygieneId::ROOT,
- );
- let args_pat = self.alloc_pat_desugared(Pat::Bind { id: args_binding, subpat: None });
- self.add_definition_to_binding(args_binding, args_pat);
- let elements = arguments
- .iter()
- .map(|arg| {
- self.alloc_expr_desugared(Expr::Ref {
- expr: arg.expr,
- rawness: Rawness::Ref,
- mutability: Mutability::Shared,
- })
- })
- .collect();
- let args_tuple = self.alloc_expr_desugared(Expr::Tuple { exprs: elements });
- // TODO: We don't have `super let` yet
- let let_stmt1 = Statement::Let {
- pat: args_pat,
- type_ref: None,
- initializer: Some(args_tuple),
- else_branch: None,
- };
-
- // Generate:
- // super let args = [
- // <core::fmt::Argument>::new_display(args.0),
- // <core::fmt::Argument>::new_lower_hex(args.1),
- // <core::fmt::Argument>::new_debug(args.0),
- // …
- // ];
- let args = argmap
- .iter()
- .map(|&(arg_index, ty)| {
- let args_ident_expr =
- self.alloc_expr_desugared(Expr::Path(args_name.clone().into()));
- let arg = self.alloc_expr_desugared(Expr::Field {
- expr: args_ident_expr,
- name: Name::new_tuple_field(arg_index),
- });
- let arg_ptr = arguments.get(arg_index).and_then(|it| it.syntax);
- self.make_argument(arg_ptr, arg, ty)
- })
- .collect();
- let array =
- self.alloc_expr_desugared(Expr::Array(Array::ElementList { elements: args }));
- let args_binding = self.alloc_binding(
- args_name.clone(),
- BindingAnnotation::Unannotated,
- HygieneId::ROOT,
- );
- let args_pat = self.alloc_pat_desugared(Pat::Bind { id: args_binding, subpat: None });
- self.add_definition_to_binding(args_binding, args_pat);
- let let_stmt2 = Statement::Let {
- pat: args_pat,
- type_ref: None,
- initializer: Some(array),
- else_branch: None,
- };
- (vec![let_stmt1, let_stmt2], self.alloc_expr_desugared(Expr::Path(args_name.into())))
- };
-
- // Generate:
- // &args
- let args = self.alloc_expr_desugared(Expr::Ref {
- expr: args,
- rawness: Rawness::Ref,
- mutability: Mutability::Shared,
- });
-
- let call_block = {
- // Generate:
- // unsafe {
- // <core::fmt::Arguments>::new_v1_formatted(
- // lit_pieces,
- // args,
- // format_options,
- // )
- // }
-
- let new_v1_formatted = self.ty_rel_lang_path_desugared_expr(
- self.lang_items().FormatArguments,
- sym::new_v1_formatted,
- );
- let args = [lit_pieces, args, format_options];
- let call = self
- .alloc_expr_desugared(Expr::Call { callee: new_v1_formatted, args: args.into() });
-
- Expr::Unsafe { id: None, statements: Box::default(), tail: Some(call) }
- };
-
- if !let_stmts.is_empty() {
- // Generate:
- // {
- // super let …
- // super let …
- // <core::fmt::Arguments>::new_…(…)
- // }
- let call = self.alloc_expr_desugared(call_block);
- self.alloc_expr(
- Expr::Block {
- id: None,
- statements: let_stmts.into(),
- tail: Some(call),
- label: None,
- },
- syntax_ptr,
- )
- } else {
- self.alloc_expr(call_block, syntax_ptr)
- }
- }
-
- /// Generate a hir expression for a format_args placeholder specification.
- ///
- /// Generates
- ///
- /// ```text
- /// <core::fmt::rt::Placeholder::new(
- /// …usize, // position
- /// '…', // fill
- /// <core::fmt::rt::Alignment>::…, // alignment
- /// …u32, // flags
- /// <core::fmt::rt::Count::…>, // width
- /// <core::fmt::rt::Count::…>, // precision
- /// )
- /// ```
- fn make_format_spec(
- &mut self,
- placeholder: &FormatPlaceholder,
- argmap: &mut FxIndexSet<(usize, ArgumentType)>,
- ) -> ExprId {
- let lang_items = self.lang_items();
- let position = match placeholder.argument.index {
- Ok(arg_index) => {
- let (i, _) =
- argmap.insert_full((arg_index, ArgumentType::Format(placeholder.format_trait)));
- self.alloc_expr_desugared(Expr::Literal(Literal::Uint(
- i as u128,
- Some(BuiltinUint::Usize),
- )))
- }
- Err(_) => self.missing_expr(),
- };
- let &FormatOptions {
- ref width,
- ref precision,
- alignment,
- fill,
- sign,
- alternate,
- zero_pad,
- debug_hex,
- } = &placeholder.format_options;
-
- let precision_expr = self.make_count_before_1_93_0(precision, argmap);
- let width_expr = self.make_count_before_1_93_0(width, argmap);
-
- if self.krate.workspace_data(self.db).is_atleast_187() {
- // These need to match the constants in library/core/src/fmt/rt.rs.
- let align = match alignment {
- Some(FormatAlignment::Left) => 0,
- Some(FormatAlignment::Right) => 1,
- Some(FormatAlignment::Center) => 2,
- None => 3,
- };
- // This needs to match `Flag` in library/core/src/fmt/rt.rs.
- let flags = fill.unwrap_or(' ') as u32
- | ((sign == Some(FormatSign::Plus)) as u32) << 21
- | ((sign == Some(FormatSign::Minus)) as u32) << 22
- | (alternate as u32) << 23
- | (zero_pad as u32) << 24
- | ((debug_hex == Some(FormatDebugHex::Lower)) as u32) << 25
- | ((debug_hex == Some(FormatDebugHex::Upper)) as u32) << 26
- | (width.is_some() as u32) << 27
- | (precision.is_some() as u32) << 28
- | align << 29
- | 1 << 31; // Highest bit always set.
- let flags = self.alloc_expr_desugared(Expr::Literal(Literal::Uint(
- flags as u128,
- Some(BuiltinUint::U32),
- )));
-
- let position =
- RecordLitField { name: Name::new_symbol_root(sym::position), expr: position };
- let flags = RecordLitField { name: Name::new_symbol_root(sym::flags), expr: flags };
- let precision = RecordLitField {
- name: Name::new_symbol_root(sym::precision),
- expr: precision_expr,
- };
- let width =
- RecordLitField { name: Name::new_symbol_root(sym::width), expr: width_expr };
- match self.lang_path(lang_items.FormatPlaceholder) {
- Some(path) => self.alloc_expr_desugared(Expr::RecordLit {
- path,
- fields: {
- let mut fields = ThinVec::with_capacity(4);
- fields.extend([position, flags, precision, width]);
- fields
- },
- spread: RecordSpread::None,
- }),
- None => self.missing_expr(),
- }
- } else {
- let format_placeholder_new =
- self.ty_rel_lang_path_desugared_expr(lang_items.FormatPlaceholder, sym::new);
- // This needs to match `Flag` in library/core/src/fmt/rt.rs.
- let flags: u32 = ((sign == Some(FormatSign::Plus)) as u32)
- | (((sign == Some(FormatSign::Minus)) as u32) << 1)
- | ((alternate as u32) << 2)
- | ((zero_pad as u32) << 3)
- | (((debug_hex == Some(FormatDebugHex::Lower)) as u32) << 4)
- | (((debug_hex == Some(FormatDebugHex::Upper)) as u32) << 5);
- let flags = self.alloc_expr_desugared(Expr::Literal(Literal::Uint(
- flags as u128,
- Some(BuiltinUint::U32),
- )));
- let fill = self.alloc_expr_desugared(Expr::Literal(Literal::Char(fill.unwrap_or(' '))));
- let align = self.ty_rel_lang_path_desugared_expr(
- lang_items.FormatAlignment,
- match alignment {
- Some(FormatAlignment::Left) => sym::Left,
- Some(FormatAlignment::Right) => sym::Right,
- Some(FormatAlignment::Center) => sym::Center,
- None => sym::Unknown,
- },
- );
- self.alloc_expr_desugared(Expr::Call {
- callee: format_placeholder_new,
- args: Box::new([position, fill, align, flags, precision_expr, width_expr]),
- })
- }
- }
-
- /// Generate a hir expression for a format_args Count.
- ///
- /// Generates:
- ///
- /// ```text
- /// <core::fmt::rt::Count>::Is(…)
- /// ```
- ///
- /// or
- ///
- /// ```text
- /// <core::fmt::rt::Count>::Param(…)
- /// ```
- ///
- /// or
- ///
- /// ```text
- /// <core::fmt::rt::Count>::Implied
- /// ```
- fn make_count_before_1_93_0(
- &mut self,
- count: &Option<FormatCount>,
- argmap: &mut FxIndexSet<(usize, ArgumentType)>,
- ) -> ExprId {
- let lang_items = self.lang_items();
- match count {
- Some(FormatCount::Literal(n)) => {
- let args = self.alloc_expr_desugared(Expr::Literal(Literal::Uint(
- *n as u128,
- // FIXME: Change this to Some(BuiltinUint::U16) once we drop support for toolchains < 1.88
- None,
- )));
- let count_is =
- self.ty_rel_lang_path_desugared_expr(lang_items.FormatCount, sym::Is);
- self.alloc_expr_desugared(Expr::Call { callee: count_is, args: Box::new([args]) })
- }
- Some(FormatCount::Argument(arg)) => {
- if let Ok(arg_index) = arg.index {
- let (i, _) = argmap.insert_full((arg_index, ArgumentType::Usize));
-
- let args = self.alloc_expr_desugared(Expr::Literal(Literal::Uint(
- i as u128,
- Some(BuiltinUint::Usize),
- )));
- let count_param =
- self.ty_rel_lang_path_desugared_expr(lang_items.FormatCount, sym::Param);
- self.alloc_expr_desugared(Expr::Call {
- callee: count_param,
- args: Box::new([args]),
- })
- } else {
- // FIXME: This drops arg causing it to potentially not be resolved/type checked
- // when typing?
- self.missing_expr()
- }
- }
- None => match self.ty_rel_lang_path(lang_items.FormatCount, sym::Implied) {
- Some(count_param) => self.alloc_expr_desugared(Expr::Path(count_param)),
- None => self.missing_expr(),
- },
- }
- }
-
/// Generate a hir expression representing an argument to a format_args invocation.
///
/// Generates:
diff --git a/crates/hir-def/src/expr_store/pretty.rs b/crates/hir-def/src/expr_store/pretty.rs
index 67eb0814c7..1c70922467 100644
--- a/crates/hir-def/src/expr_store/pretty.rs
+++ b/crates/hir-def/src/expr_store/pretty.rs
@@ -727,10 +727,6 @@ impl Printer<'_> {
}
self.print_expr_in(prec, *expr);
}
- Expr::Box { expr } => {
- w!(self, "box ");
- self.print_expr_in(prec, *expr);
- }
Expr::UnaryOp { expr, op } => {
let op = match op {
ast::UnaryOp::Deref => "*",
diff --git a/crates/hir-def/src/expr_store/tests/body.rs b/crates/hir-def/src/expr_store/tests/body.rs
index c7b9edf393..f199ef4f9f 100644
--- a/crates/hir-def/src/expr_store/tests/body.rs
+++ b/crates/hir-def/src/expr_store/tests/body.rs
@@ -194,168 +194,6 @@ fn main() {
}
#[test]
-fn desugar_builtin_format_args_before_1_89_0() {
- pretty_print(
- r#"
-//- minicore: fmt_before_1_89_0
-fn main() {
- let are = "are";
- let count = 10;
- builtin#format_args("\u{1b}hello {count:02} {} friends, we {are:?} {0}{last}", "fancy", orphan = (), last = "!");
-}
-"#,
- expect![[r#"
- fn main() {
- let are = "are";
- let count = 10;
- builtin#lang(Arguments::new_v1_formatted)(
- &[
- "\u{1b}hello ", " ", " friends, we ", " ", "",
- ],
- &[
- builtin#lang(Argument::new_display)(
- &count,
- ), builtin#lang(Argument::new_display)(
- &"fancy",
- ), builtin#lang(Argument::new_debug)(
- &are,
- ), builtin#lang(Argument::new_display)(
- &"!",
- ),
- ],
- &[
- builtin#lang(Placeholder::new)(
- 0usize,
- ' ',
- builtin#lang(Alignment::Unknown),
- 8u32,
- builtin#lang(Count::Implied),
- builtin#lang(Count::Is)(
- 2,
- ),
- ), builtin#lang(Placeholder::new)(
- 1usize,
- ' ',
- builtin#lang(Alignment::Unknown),
- 0u32,
- builtin#lang(Count::Implied),
- builtin#lang(Count::Implied),
- ), builtin#lang(Placeholder::new)(
- 2usize,
- ' ',
- builtin#lang(Alignment::Unknown),
- 0u32,
- builtin#lang(Count::Implied),
- builtin#lang(Count::Implied),
- ), builtin#lang(Placeholder::new)(
- 1usize,
- ' ',
- builtin#lang(Alignment::Unknown),
- 0u32,
- builtin#lang(Count::Implied),
- builtin#lang(Count::Implied),
- ), builtin#lang(Placeholder::new)(
- 3usize,
- ' ',
- builtin#lang(Alignment::Unknown),
- 0u32,
- builtin#lang(Count::Implied),
- builtin#lang(Count::Implied),
- ),
- ],
- {
- ();
- unsafe {
- builtin#lang(UnsafeArg::new)()
- }
- },
- );
- }"#]],
- )
-}
-
-#[test]
-fn desugar_builtin_format_args_before_1_93_0() {
- pretty_print(
- r#"
-//- minicore: fmt_before_1_93_0
-fn main() {
- let are = "are";
- let count = 10;
- builtin#format_args("\u{1b}hello {count:02} {} friends, we {are:?} {0}{last}", "fancy", orphan = (), last = "!");
-}
-"#,
- expect![[r#"
- fn main() {
- let are = "are";
- let count = 10;
- {
- let <ra@gennew>0 = (&"fancy", &(), &"!", &count, &are, );
- let <ra@gennew>0 = [
- builtin#lang(Argument::new_display)(
- <ra@gennew>0.3,
- ), builtin#lang(Argument::new_display)(
- <ra@gennew>0.0,
- ), builtin#lang(Argument::new_debug)(
- <ra@gennew>0.4,
- ), builtin#lang(Argument::new_display)(
- <ra@gennew>0.2,
- ),
- ];
- unsafe {
- builtin#lang(Arguments::new_v1_formatted)(
- &[
- "\u{1b}hello ", " ", " friends, we ", " ", "",
- ],
- &<ra@gennew>0,
- &[
- builtin#lang(Placeholder::new)(
- 0usize,
- ' ',
- builtin#lang(Alignment::Unknown),
- 8u32,
- builtin#lang(Count::Implied),
- builtin#lang(Count::Is)(
- 2,
- ),
- ), builtin#lang(Placeholder::new)(
- 1usize,
- ' ',
- builtin#lang(Alignment::Unknown),
- 0u32,
- builtin#lang(Count::Implied),
- builtin#lang(Count::Implied),
- ), builtin#lang(Placeholder::new)(
- 2usize,
- ' ',
- builtin#lang(Alignment::Unknown),
- 0u32,
- builtin#lang(Count::Implied),
- builtin#lang(Count::Implied),
- ), builtin#lang(Placeholder::new)(
- 1usize,
- ' ',
- builtin#lang(Alignment::Unknown),
- 0u32,
- builtin#lang(Count::Implied),
- builtin#lang(Count::Implied),
- ), builtin#lang(Placeholder::new)(
- 3usize,
- ' ',
- builtin#lang(Alignment::Unknown),
- 0u32,
- builtin#lang(Count::Implied),
- builtin#lang(Count::Implied),
- ),
- ],
- )
- }
- };
- }"#]],
- )
-}
-
-#[test]
fn desugar_builtin_format_args() {
pretty_print(
r#"
@@ -464,7 +302,7 @@ impl SsrError {
fn regression_10300() {
pretty_print(
r#"
-//- minicore: concat, panic, fmt_before_1_89_0
+//- minicore: concat, panic, fmt
mod private {
pub use core::concat;
}
@@ -480,22 +318,15 @@ fn f(a: i32, b: u32) -> String {
}
"#,
expect![[r#"
- fn f(a, b) {
- {
- core::panicking::panic_fmt(
- builtin#lang(Arguments::new_v1_formatted)(
- &[
+ fn f(a, b) {
+ {
+ core::panicking::panic_fmt(
+ builtin#lang(Arguments::from_str)(
"cc",
- ],
- &[],
- &[],
- unsafe {
- builtin#lang(UnsafeArg::new)()
- },
- ),
- );
- };
- }"#]],
+ ),
+ );
+ };
+ }"#]],
)
}
diff --git a/crates/hir-def/src/hir.rs b/crates/hir-def/src/hir.rs
index 75da190dc7..7e56282feb 100644
--- a/crates/hir-def/src/hir.rs
+++ b/crates/hir-def/src/hir.rs
@@ -355,9 +355,6 @@ pub enum Expr {
rawness: Rawness,
mutability: Mutability,
},
- Box {
- expr: ExprId,
- },
UnaryOp {
expr: ExprId,
op: UnaryOp,
@@ -432,9 +429,7 @@ impl Expr {
| Expr::Index { .. }
| Expr::MethodCall { .. } => ExprPrecedence::Postfix,
- Expr::Box { .. } | Expr::Let { .. } | Expr::UnaryOp { .. } | Expr::Ref { .. } => {
- ExprPrecedence::Prefix
- }
+ Expr::Let { .. } | Expr::UnaryOp { .. } | Expr::Ref { .. } => ExprPrecedence::Prefix,
Expr::Cast { .. } => ExprPrecedence::Cast,
diff --git a/crates/hir-ty/src/consteval/tests.rs b/crates/hir-ty/src/consteval/tests.rs
index 95ebdbd409..4eb8c11fac 100644
--- a/crates/hir-ty/src/consteval/tests.rs
+++ b/crates/hir-ty/src/consteval/tests.rs
@@ -2217,14 +2217,17 @@ fn boxes() {
use core::ops::{Deref, DerefMut};
use core::{marker::Unsize, ops::CoerceUnsized};
+#[rustc_intrinsic]
+#[rustc_intrinsic_must_be_overridden]
+pub fn box_new<T>(_x: T) -> Box<T>;
+
#[lang = "owned_box"]
pub struct Box<T: ?Sized> {
inner: *mut T,
}
impl<T> Box<T> {
fn new(t: T) -> Self {
- #[rustc_box]
- Box::new(t)
+ box_new(t)
}
}
diff --git a/crates/hir-ty/src/dyn_compatibility.rs b/crates/hir-ty/src/dyn_compatibility.rs
index 751e1424ab..bf7970d629 100644
--- a/crates/hir-ty/src/dyn_compatibility.rs
+++ b/crates/hir-ty/src/dyn_compatibility.rs
@@ -426,15 +426,9 @@ fn receiver_is_dispatchable<'db>(
return false;
};
- let meta_sized_did = lang_items.MetaSized;
-
- // TODO: This is for supporting dyn compatibility for toolchains doesn't contain `MetaSized`
- // trait. Uncomment and short circuit here once `MINIMUM_SUPPORTED_TOOLCHAIN_VERSION`
- // become > 1.88.0
- //
- // let Some(meta_sized_did) = meta_sized_did else {
- // return false;
- // };
+ let Some(meta_sized_did) = lang_items.MetaSized else {
+ return false;
+ };
// Type `U`
// FIXME: That seems problematic to fake a generic param like that?
@@ -455,8 +449,8 @@ fn receiver_is_dispatchable<'db>(
});
let trait_predicate = TraitRef::new_from_args(interner, trait_.into(), args);
- let meta_sized_predicate = meta_sized_did
- .map(|did| TraitRef::new(interner, did.into(), [unsized_self_ty]).upcast(interner));
+ let meta_sized_predicate =
+ TraitRef::new(interner, meta_sized_did.into(), [unsized_self_ty]).upcast(interner);
ParamEnv {
clauses: Clauses::new_from_iter(
@@ -465,7 +459,7 @@ fn receiver_is_dispatchable<'db>(
.iter_identity()
.map(Unnormalized::skip_norm_wip)
.chain([unsize_predicate.upcast(interner), trait_predicate.upcast(interner)])
- .chain(meta_sized_predicate),
+ .chain(std::iter::once(meta_sized_predicate)),
),
}
};
diff --git a/crates/hir-ty/src/infer.rs b/crates/hir-ty/src/infer.rs
index 2cb6666672..bd00da84ca 100644
--- a/crates/hir-ty/src/infer.rs
+++ b/crates/hir-ty/src/infer.rs
@@ -2637,11 +2637,6 @@ impl<'db> InferenceContext<'db> {
}
}
- fn resolve_boxed_box(&self) -> Option<AdtId> {
- let struct_ = self.lang_items.OwnedBox?;
- Some(struct_.into())
- }
-
fn resolve_range_full(&self) -> Option<AdtId> {
let struct_ = self.lang_items.RangeFull?;
Some(struct_.into())
diff --git a/crates/hir-ty/src/infer/closure/analysis/expr_use_visitor.rs b/crates/hir-ty/src/infer/closure/analysis/expr_use_visitor.rs
index 2b771c5216..4d300f5048 100644
--- a/crates/hir-ty/src/infer/closure/analysis/expr_use_visitor.rs
+++ b/crates/hir-ty/src/infer/closure/analysis/expr_use_visitor.rs
@@ -648,7 +648,7 @@ impl<'a, 'db, D: Delegate<'db>> ExprUseVisitor<'a, 'db, D> {
}
}
- Expr::Become { expr } | Expr::Await { expr } | Expr::Box { expr } => {
+ Expr::Become { expr } | Expr::Await { expr } => {
self.consume_expr(expr)?;
}
diff --git a/crates/hir-ty/src/infer/expr.rs b/crates/hir-ty/src/infer/expr.rs
index b92a83ab7f..20cfc9008a 100644
--- a/crates/hir-ty/src/infer/expr.rs
+++ b/crates/hir-ty/src/infer/expr.rs
@@ -20,7 +20,7 @@ use rustc_ast_ir::Mutability;
use rustc_hash::FxHashMap;
use rustc_type_ir::{
InferTy, Interner,
- inherent::{GenericArgs as _, IntoKind, Ty as _},
+ inherent::{IntoKind, Ty as _},
};
use stdx::never;
use syntax::ast::RangeOp;
@@ -259,7 +259,6 @@ impl<'db> InferenceContext<'db> {
| Expr::Await { .. }
| Expr::Ref { .. }
| Expr::Range { .. }
- | Expr::Box { .. }
| Expr::RecordLit { .. }
| Expr::Yeet { .. }
| Expr::Missing
@@ -621,7 +620,6 @@ impl<'db> InferenceContext<'db> {
expected,
tgt_expr,
),
- &Expr::Box { expr } => self.infer_expr_box(expr, expected),
Expr::UnaryOp { expr, op } => self.infer_unop_expr(*op, *expr, expected, tgt_expr),
Expr::BinaryOp { lhs, rhs, op } => match op {
Some(BinaryOp::Assignment { op: Some(op) }) => {
@@ -1485,27 +1483,6 @@ impl<'db> InferenceContext<'db> {
self.types.types.never
}
- fn infer_expr_box(&mut self, inner_expr: ExprId, expected: &Expectation<'db>) -> Ty<'db> {
- if let Some(box_id) = self.resolve_boxed_box() {
- let table = &mut self.table;
- let inner_exp = expected
- .to_option(table)
- .as_ref()
- .and_then(|e| e.as_adt())
- .filter(|(e_adt, _)| e_adt == &box_id)
- .map(|(_, subts)| {
- let g = subts.type_at(0);
- Expectation::rvalue_hint(self, g)
- })
- .unwrap_or_else(Expectation::none);
-
- let inner_ty = self.infer_expr_inner(inner_expr, &inner_exp, ExprIsRead::Yes);
- Ty::new_box(self.interner(), inner_ty)
- } else {
- self.err_ty()
- }
- }
-
fn infer_block(
&mut self,
expr: ExprId,
diff --git a/crates/hir-ty/src/infer/mutability.rs b/crates/hir-ty/src/infer/mutability.rs
index 9ec297f5f5..7d285a3a21 100644
--- a/crates/hir-ty/src/infer/mutability.rs
+++ b/crates/hir-ty/src/infer/mutability.rs
@@ -159,7 +159,6 @@ impl<'db> InferenceContext<'db> {
| Expr::Range { lhs: Some(expr), rhs: None, range_type: _ }
| Expr::Range { rhs: Some(expr), lhs: None, range_type: _ }
| Expr::Await { expr }
- | Expr::Box { expr }
| Expr::Loop { body: expr, label: _, source: _ }
| Expr::Cast { expr, type_ref: _ } => {
self.infer_mut_expr(*expr, Mutability::Not);
diff --git a/crates/hir-ty/src/mir.rs b/crates/hir-ty/src/mir.rs
index 976f88601e..fe4b383fbe 100644
--- a/crates/hir-ty/src/mir.rs
+++ b/crates/hir-ty/src/mir.rs
@@ -994,16 +994,6 @@ pub enum Rvalue {
/// coroutine lowering, `Coroutine` aggregate kinds are disallowed too.
Aggregate(AggregateKind, Box<[Operand]>),
- /// Transmutes a `*mut u8` into shallow-initialized `Box<T>`.
- ///
- /// This is different from a normal transmute because dataflow analysis will treat the box as
- /// initialized but its content as uninitialized. Like other pointer casts, this in general
- /// affects alias analysis.
- ShallowInitBox(Operand, StoredTy),
-
- /// NON STANDARD: allocates memory with the type's layout, and shallow init the box with the resulting pointer.
- ShallowInitBoxWithAlloc(StoredTy),
-
/// A CopyForDeref is equivalent to a read from a place at the
/// codegen level, but is treated specially by drop elaboration. When such a read happens, it
/// is guaranteed (via nature of the mir_opt `Derefer` in rustc_mir_transform/src/deref_separator)
@@ -1101,9 +1091,7 @@ impl MirBody<'_> {
StatementKind::Assign(p, r) => {
f(p);
match r {
- Rvalue::ShallowInitBoxWithAlloc(_) => (),
- Rvalue::ShallowInitBox(o, _)
- | Rvalue::UnaryOp(_, o)
+ Rvalue::UnaryOp(_, o)
| Rvalue::Cast(_, o, _)
| Rvalue::Repeat(o, _)
| Rvalue::Use(o) => for_operand(o, &mut f),
diff --git a/crates/hir-ty/src/mir/borrowck.rs b/crates/hir-ty/src/mir/borrowck.rs
index c568209541..e860ae8d3e 100644
--- a/crates/hir-ty/src/mir/borrowck.rs
+++ b/crates/hir-ty/src/mir/borrowck.rs
@@ -239,9 +239,7 @@ fn moved_out_of_ref<'db>(
for statement in &block.statements {
match &statement.kind {
StatementKind::Assign(_, r) => match r {
- Rvalue::ShallowInitBoxWithAlloc(_) => (),
- Rvalue::ShallowInitBox(o, _)
- | Rvalue::UnaryOp(_, o)
+ Rvalue::UnaryOp(_, o)
| Rvalue::Cast(_, o, _)
| Rvalue::Repeat(o, _)
| Rvalue::Use(o) => for_operand(o, statement.span),
@@ -324,9 +322,7 @@ fn partially_moved<'db>(
for statement in &block.statements {
match &statement.kind {
StatementKind::Assign(_, r) => match r {
- Rvalue::ShallowInitBoxWithAlloc(_) => (),
- Rvalue::ShallowInitBox(o, _)
- | Rvalue::UnaryOp(_, o)
+ Rvalue::UnaryOp(_, o)
| Rvalue::Cast(_, o, _)
| Rvalue::Repeat(o, _)
| Rvalue::Use(o) => for_operand(o, statement.span),
@@ -636,7 +632,6 @@ fn mutability_of_locals<'db>(
record_usage_for_operand(arg, &mut result);
}
}
- Rvalue::ShallowInitBox(_, _) | Rvalue::ShallowInitBoxWithAlloc(_) => (),
Rvalue::ThreadLocalRef(n)
| Rvalue::AddressOf(n)
| Rvalue::BinaryOp(n)
diff --git a/crates/hir-ty/src/mir/eval.rs b/crates/hir-ty/src/mir/eval.rs
index ab60e81646..e968da5111 100644
--- a/crates/hir-ty/src/mir/eval.rs
+++ b/crates/hir-ty/src/mir/eval.rs
@@ -1479,14 +1479,6 @@ impl<'a, 'db> Evaluator<'a, 'db> {
let size = len * val.len();
Owned(val.iter().copied().cycle().take(size).collect())
}
- Rvalue::ShallowInitBox(_, _) => not_supported!("shallow init box"),
- Rvalue::ShallowInitBoxWithAlloc(ty) => {
- let Some((size, align)) = self.size_align_of(ty.as_ref(), locals)? else {
- not_supported!("unsized box initialization");
- };
- let addr = self.heap_allocate(size, align)?;
- Owned(addr.to_bytes().to_vec())
- }
Rvalue::CopyForDeref(_) => not_supported!("copy for deref"),
Rvalue::Aggregate(kind, values) => {
let values = values
diff --git a/crates/hir-ty/src/mir/eval/shim.rs b/crates/hir-ty/src/mir/eval/shim.rs
index 9db6b36588..e569b32bd7 100644
--- a/crates/hir-ty/src/mir/eval/shim.rs
+++ b/crates/hir-ty/src/mir/eval/shim.rs
@@ -733,9 +733,7 @@ impl<'a, 'db> Evaluator<'a, 'db> {
let size = self.size_of_sized(ty, locals, "size_of arg")?;
destination.write_from_bytes(self, &size.to_le_bytes()[0..destination.size])
}
- // FIXME: `min_align_of` was renamed to `align_of` in Rust 1.89
- // (https://github.com/rust-lang/rust/pull/142410)
- "min_align_of" | "align_of" => {
+ "align_of" => {
let Some(ty) = generic_args.as_slice().first().and_then(|it| it.ty()) else {
return Err(MirEvalError::InternalError(
"align_of generic arg is not provided".into(),
@@ -763,9 +761,7 @@ impl<'a, 'db> Evaluator<'a, 'db> {
destination.write_from_bytes(self, &size.to_le_bytes())
}
}
- // FIXME: `min_align_of_val` was renamed to `align_of_val` in Rust 1.89
- // (https://github.com/rust-lang/rust/pull/142410)
- "min_align_of_val" | "align_of_val" => {
+ "align_of_val" => {
let Some(ty) = generic_args.as_slice().first().and_then(|it| it.ty()) else {
return Err(MirEvalError::InternalError(
"align_of_val generic arg is not provided".into(),
@@ -1415,6 +1411,15 @@ impl<'a, 'db> Evaluator<'a, 'db> {
self.write_memory(location_addr, &location)?;
destination.write_from_bytes(self, &location_addr.to_bytes()[..ptr_size])
}
+ "box_new" => {
+ let ty = generic_args.type_at(0);
+ let Some((size, align)) = self.size_align_of(ty, locals)? else {
+ not_supported!("unsized box initialization");
+ };
+ let addr = self.heap_allocate(size, align)?;
+ self.copy_from_interval(addr, args[0].interval)?;
+ destination.write_from_bytes(self, &addr.to_bytes()[..self.ptr_size()])
+ }
_ if needs_override => not_supported!("intrinsic {name} is not implemented"),
_ => return Ok(false),
}
diff --git a/crates/hir-ty/src/mir/lower.rs b/crates/hir-ty/src/mir/lower.rs
index ed7279790c..1c7e5c2f51 100644
--- a/crates/hir-ty/src/mir/lower.rs
+++ b/crates/hir-ty/src/mir/lower.rs
@@ -999,22 +999,6 @@ impl<'a, 'db> MirLowerCtx<'a, 'db> {
self.push_assignment(current, place, Rvalue::Ref(bk, p.store()), expr_id.into());
Ok(Some(current))
}
- Expr::Box { expr } => {
- let ty = self.expr_ty_after_adjustments(*expr);
- self.push_assignment(
- current,
- place,
- Rvalue::ShallowInitBoxWithAlloc(ty.store()),
- expr_id.into(),
- );
- let Some((operand, current)) = self.lower_expr_to_some_operand(*expr, current)?
- else {
- return Ok(None);
- };
- let p = place.project(ProjectionElem::Deref);
- self.push_assignment(current, p, operand.into(), expr_id.into());
- Ok(Some(current))
- }
Expr::Field { .. }
| Expr::Index { .. }
| Expr::UnaryOp { op: hir_def::hir::UnaryOp::Deref, .. } => {
diff --git a/crates/hir-ty/src/mir/monomorphization.rs b/crates/hir-ty/src/mir/monomorphization.rs
index 93d1aa515a..976ef2c45f 100644
--- a/crates/hir-ty/src/mir/monomorphization.rs
+++ b/crates/hir-ty/src/mir/monomorphization.rs
@@ -179,9 +179,6 @@ impl<'db> Filler<'db> {
super::AggregateKind::Union(_, _) => (),
}
}
- Rvalue::ShallowInitBox(_, ty) | Rvalue::ShallowInitBoxWithAlloc(ty) => {
- self.fill_ty(ty)?;
- }
Rvalue::Use(op) => {
self.fill_operand(op)?;
}
diff --git a/crates/hir-ty/src/mir/pretty.rs b/crates/hir-ty/src/mir/pretty.rs
index 8893069f0c..4a51b5113a 100644
--- a/crates/hir-ty/src/mir/pretty.rs
+++ b/crates/hir-ty/src/mir/pretty.rs
@@ -490,12 +490,6 @@ impl<'a, 'db> MirPrettyCtx<'a, 'db> {
self.place(p);
w!(self, ")");
}
- Rvalue::ShallowInitBoxWithAlloc(_) => w!(self, "ShallowInitBoxWithAlloc"),
- Rvalue::ShallowInitBox(op, _) => {
- w!(self, "ShallowInitBox(");
- self.operand(op);
- w!(self, ")");
- }
Rvalue::CopyForDeref(p) => {
w!(self, "CopyForDeref(");
self.place(p);
diff --git a/crates/hir-ty/src/tests/regression/new_solver.rs b/crates/hir-ty/src/tests/regression/new_solver.rs
index 121e3959ce..154cddf40f 100644
--- a/crates/hir-ty/src/tests/regression/new_solver.rs
+++ b/crates/hir-ty/src/tests/regression/new_solver.rs
@@ -279,63 +279,6 @@ fn main() {
debug(&1);
}"#,
);
-
- // toolchains <= 1.88.0, before sized-hierarchy.
- check_no_mismatches(
- r#"
-#![feature(lang_items)]
-#[lang = "sized"]
-pub trait Sized {}
-
-#[lang = "unsize"]
-pub trait Unsize<T: ?Sized> {}
-
-#[lang = "coerce_unsized"]
-pub trait CoerceUnsized<T: ?Sized> {}
-
-impl<'a, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<&'a mut U> for &'a mut T {}
-
-impl<'a, 'b: 'a, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<&'a U> for &'b mut T {}
-
-impl<'a, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*mut U> for &'a mut T {}
-
-impl<'a, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*const U> for &'a mut T {}
-
-impl<'a, 'b: 'a, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<&'a U> for &'b T {}
-
-impl<'a, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*const U> for &'a T {}
-
-impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*mut U> for *mut T {}
-
-impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*const U> for *mut T {}
-
-impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*const U> for *const T {}
-
-#[lang = "dispatch_from_dyn"]
-pub trait DispatchFromDyn<T> {}
-
-impl<'a, T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<&'a U> for &'a T {}
-
-impl<'a, T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<&'a mut U> for &'a mut T {}
-
-impl<T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<*const U> for *const T {}
-
-impl<T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<*mut U> for *mut T {}
-
-trait Foo {
- fn bar(&self) -> u32 {
- 0xCAFE
- }
-}
-
-fn debug(_: &dyn Foo) {}
-
-impl Foo for i32 {}
-
-fn main() {
- debug(&1);
-}"#,
- );
}
#[test]
diff --git a/crates/hir-ty/src/tests/simple.rs b/crates/hir-ty/src/tests/simple.rs
index 0c57d050f3..e8f378db32 100644
--- a/crates/hir-ty/src/tests/simple.rs
+++ b/crates/hir-ty/src/tests/simple.rs
@@ -2879,6 +2879,10 @@ unsafe impl Allocator for Global {}
#[fundamental]
pub struct Box<T: ?Sized, A: Allocator = Global>(T, A);
+#[rustc_intrinsic]
+#[rustc_intrinsic_must_be_overridden]
+pub fn box_new<T>(_x: T) -> Box<T>;
+
impl<T: ?Sized + Unsize<U>, U: ?Sized, A: Allocator> CoerceUnsized<Box<U, A>> for Box<T, A> {}
pub struct Vec<T, A: Allocator = Global>(T, A);
@@ -2895,8 +2899,8 @@ impl<T> [T] {
}
fn test() {
- let vec = <[_]>::into_vec(#[rustc_box] Box::new([1i32]));
- let v: Vec<Box<dyn B>> = <[_]> :: into_vec(#[rustc_box] Box::new([#[rustc_box] Box::new(Astruct)]));
+ let vec = <[_]>::into_vec(box_new([1i32]));
+ let v: Vec<Box<dyn B>> = <[_]> :: into_vec(box_new([box_new(Astruct)]));
}
trait B{}
@@ -2904,22 +2908,26 @@ struct Astruct;
impl B for Astruct {}
"#,
expect![[r#"
- 639..643 'self': Box<[T], A>
- 672..704 '{ ... }': Vec<T, A>
- 718..888 '{ ...])); }': ()
- 728..731 'vec': Vec<i32, Global>
- 734..749 '<[_]>::into_vec': fn into_vec<i32, Global>(Box<[i32], Global>) -> Vec<i32, Global>
- 734..780 '<[_]>:...i32]))': Vec<i32, Global>
- 750..779 '#[rust...1i32])': Box<[i32; 1], Global>
- 772..778 '[1i32]': [i32; 1]
- 773..777 '1i32': i32
- 790..791 'v': Vec<Box<dyn B + 'static, Global>, Global>
- 811..828 '<[_]> ...to_vec': fn into_vec<Box<dyn B + '?, Global>, Global>(Box<[Box<dyn B + '?, Global>], Global>) -> Vec<Box<dyn B + '?, Global>, Global>
- 811..885 '<[_]> ...ct)]))': Vec<Box<dyn B + '?, Global>, Global>
- 829..884 '#[rust...uct)])': Box<[Box<dyn B + '?, Global>; 1], Global>
- 851..883 '[#[rus...ruct)]': [Box<dyn B + '?, Global>; 1]
- 852..882 '#[rust...truct)': Box<Astruct, Global>
- 874..881 'Astruct': Astruct
+ 428..430 '_x': T
+ 733..737 'self': Box<[T], A>
+ 766..798 '{ ... }': Vec<T, A>
+ 812..940 '{ ...])); }': ()
+ 822..825 'vec': Vec<i32, Global>
+ 828..843 '<[_]>::into_vec': fn into_vec<i32, Global>(Box<[i32], Global>) -> Vec<i32, Global>
+ 828..860 '<[_]>:...i32]))': Vec<i32, Global>
+ 844..851 'box_new': fn box_new<[i32; 1]>([i32; 1]) -> Box<[i32; 1], Global>
+ 844..859 'box_new([1i32])': Box<[i32; 1], Global>
+ 852..858 '[1i32]': [i32; 1]
+ 853..857 '1i32': i32
+ 870..871 'v': Vec<Box<dyn B + 'static, Global>, Global>
+ 891..908 '<[_]> ...to_vec': fn into_vec<Box<dyn B + '?, Global>, Global>(Box<[Box<dyn B + '?, Global>], Global>) -> Vec<Box<dyn B + '?, Global>, Global>
+ 891..937 '<[_]> ...ct)]))': Vec<Box<dyn B + '?, Global>, Global>
+ 909..916 'box_new': fn box_new<[Box<dyn B + '?, Global>; 1]>([Box<dyn B + '?, Global>; 1]) -> Box<[Box<dyn B + '?, Global>; 1], Global>
+ 909..936 'box_ne...uct)])': Box<[Box<dyn B + '?, Global>; 1], Global>
+ 917..935 '[box_n...ruct)]': [Box<dyn B + '?, Global>; 1]
+ 918..925 'box_new': fn box_new<Astruct>(Astruct) -> Box<Astruct, Global>
+ 918..934 'box_ne...truct)': Box<Astruct, Global>
+ 926..933 'Astruct': Astruct
"#]],
)
}
diff --git a/crates/ide-diagnostics/src/handlers/missing_unsafe.rs b/crates/ide-diagnostics/src/handlers/missing_unsafe.rs
index 808b76e082..18859c0db1 100644
--- a/crates/ide-diagnostics/src/handlers/missing_unsafe.rs
+++ b/crates/ide-diagnostics/src/handlers/missing_unsafe.rs
@@ -676,17 +676,6 @@ fn main() {
// Checks that we don't place orphan arguments for formatting under an unsafe block.
check_diagnostics(
r#"
-//- minicore: fmt_before_1_89_0
-fn foo() {
- let p = 0xDEADBEEF as *const i32;
- format_args!("", *p);
- // ^^ error: dereference of raw pointer is unsafe and requires an unsafe function or block
-}
- "#,
- );
-
- check_diagnostics(
- r#"
//- minicore: fmt
fn foo() {
let p = 0xDEADBEEF as *const i32;
diff --git a/crates/ide-diagnostics/src/handlers/mutability_errors.rs b/crates/ide-diagnostics/src/handlers/mutability_errors.rs
index 5c6c979416..fa9a69c996 100644
--- a/crates/ide-diagnostics/src/handlers/mutability_errors.rs
+++ b/crates/ide-diagnostics/src/handlers/mutability_errors.rs
@@ -1096,14 +1096,17 @@ fn x(t: &[u8]) {
use core::ops::{Deref, DerefMut};
use core::{marker::Unsize, ops::CoerceUnsized};
+#[rustc_intrinsic]
+#[rustc_intrinsic_must_be_overridden]
+pub fn box_new<T>(_x: T) -> Box<T>;
+
#[lang = "owned_box"]
pub struct Box<T: ?Sized> {
inner: *mut T,
}
impl<T> Box<T> {
fn new(t: T) -> Self {
- #[rustc_box]
- Box::new(t)
+ box_new(t)
}
}
diff --git a/crates/ide/src/references.rs b/crates/ide/src/references.rs
index d85e01af41..bb79fc2aa0 100644
--- a/crates/ide/src/references.rs
+++ b/crates/ide/src/references.rs
@@ -600,7 +600,7 @@ fn main() {
false,
false,
expect![[r#"
- Some Variant FileId(1) 6737..6769 6762..6766
+ Some Variant FileId(1) 6734..6766 6759..6763
FileId(0) 46..50
"#]],
diff --git a/crates/mbe/src/expander/transcriber.rs b/crates/mbe/src/expander/transcriber.rs
index e135291d89..440e75eb7e 100644
--- a/crates/mbe/src/expander/transcriber.rs
+++ b/crates/mbe/src/expander/transcriber.rs
@@ -275,7 +275,7 @@ fn expand_subtree(
}
}
- let res = count(binding, 0, depth.unwrap_or(0));
+ let res = count(binding, 0, *depth);
builder.push(tt::Leaf::Literal(tt::Literal {
text_and_suffix: sym::Integer::get(res),
diff --git a/crates/mbe/src/parser.rs b/crates/mbe/src/parser.rs
index 9fbd06cf88..7c3d451d04 100644
--- a/crates/mbe/src/parser.rs
+++ b/crates/mbe/src/parser.rs
@@ -92,39 +92,14 @@ impl MetaTemplate {
#[derive(Clone, Debug, PartialEq, Eq)]
pub(crate) enum Op {
- Var {
- name: Symbol,
- kind: Option<MetaVarKind>,
- id: Span,
- },
- Ignore {
- name: Symbol,
- id: Span,
- },
- Index {
- depth: usize,
- },
- Len {
- depth: usize,
- },
- Count {
- name: Symbol,
- // FIXME: `usize` once we drop support for 1.76
- depth: Option<usize>,
- },
- Concat {
- elements: Box<[ConcatMetaVarExprElem]>,
- span: Span,
- },
- Repeat {
- tokens: MetaTemplate,
- kind: RepeatKind,
- separator: Option<Arc<Separator>>,
- },
- Subtree {
- tokens: MetaTemplate,
- delimiter: tt::Delimiter,
- },
+ Var { name: Symbol, kind: Option<MetaVarKind>, id: Span },
+ Ignore { name: Symbol, id: Span },
+ Index { depth: usize },
+ Len { depth: usize },
+ Count { name: Symbol, depth: usize },
+ Concat { elements: Box<[ConcatMetaVarExprElem]>, span: Span },
+ Repeat { tokens: MetaTemplate, kind: RepeatKind, separator: Option<Arc<Separator>> },
+ Subtree { tokens: MetaTemplate, delimiter: tt::Delimiter },
Literal(tt::Literal),
Punct(Box<ArrayVec<tt::Punct, MAX_GLUED_PUNCT_LEN>>),
Ident(tt::Ident),
@@ -432,11 +407,8 @@ fn parse_metavar_expr(src: &mut TtIter<'_>) -> Result<Op, ()> {
s if sym::count == *s => {
args_iter.expect_dollar()?;
let ident = args_iter.expect_ident()?;
- let depth = if try_eat_comma(&mut args_iter) {
- Some(parse_depth(&mut args_iter)?)
- } else {
- None
- };
+ let depth =
+ if try_eat_comma(&mut args_iter) { parse_depth(&mut args_iter)? } else { 0 };
Op::Count { name: ident.sym.clone(), depth }
}
s if sym::concat == *s => {
diff --git a/crates/project-model/src/build_dependencies.rs b/crates/project-model/src/build_dependencies.rs
index 9f84f632d5..926a9e327e 100644
--- a/crates/project-model/src/build_dependencies.rs
+++ b/crates/project-model/src/build_dependencies.rs
@@ -473,10 +473,6 @@ impl WorkspaceBuildScripts {
if let Some(lockfile_copy) = &lockfile_copy {
requires_unstable_options = true;
match lockfile_copy.usage {
- LockfileUsage::WithFlag => {
- cmd.arg("--lockfile-path");
- cmd.arg(lockfile_copy.path.as_str());
- }
LockfileUsage::WithEnvVarUnstable => {
cmd.arg("-Zlockfile-path");
cmd.env(
diff --git a/crates/project-model/src/cargo_config_file.rs b/crates/project-model/src/cargo_config_file.rs
index defd9f96ab..a6bfea8200 100644
--- a/crates/project-model/src/cargo_config_file.rs
+++ b/crates/project-model/src/cargo_config_file.rs
@@ -143,8 +143,6 @@ pub(crate) struct LockfileCopy {
}
pub(crate) enum LockfileUsage {
- /// Rust [1.82.0, 1.95.0). `cargo <subcmd> --lockfile-path <lockfile path>`
- WithFlag,
/// Rust [1.95.0, 1.97.0). `CARGO_RESOLVER_LOCKFILE_PATH=<lockfile path> cargo -Zlockfile-path <subcmd>`
WithEnvVarUnstable,
/// Rust >= 1.97.0. `CARGO_RESOLVER_LOCKFILE_PATH=<lockfile path> cargo <subcmd>`
@@ -155,15 +153,6 @@ pub(crate) fn make_lockfile_copy(
toolchain_version: &semver::Version,
lockfile_path: &Utf8Path,
) -> Option<LockfileCopy> {
- const MINIMUM_TOOLCHAIN_VERSION_SUPPORTING_LOCKFILE_PATH_FLAG: semver::Version =
- semver::Version {
- major: 1,
- minor: 82,
- patch: 0,
- pre: semver::Prerelease::EMPTY,
- build: semver::BuildMetadata::EMPTY,
- };
-
const MINIMUM_TOOLCHAIN_VERSION_SUPPORTING_LOCKFILE_PATH_ENV_UNSTABLE: semver::Version =
semver::Version {
major: 1,
@@ -187,8 +176,6 @@ pub(crate) fn make_lockfile_copy(
} else if *toolchain_version >= MINIMUM_TOOLCHAIN_VERSION_SUPPORTING_LOCKFILE_PATH_ENV_UNSTABLE
{
LockfileUsage::WithEnvVarUnstable
- } else if *toolchain_version >= MINIMUM_TOOLCHAIN_VERSION_SUPPORTING_LOCKFILE_PATH_FLAG {
- LockfileUsage::WithFlag
} else {
return None;
};
diff --git a/crates/project-model/src/cargo_workspace.rs b/crates/project-model/src/cargo_workspace.rs
index 97375fe9dd..3db5a0fffc 100644
--- a/crates/project-model/src/cargo_workspace.rs
+++ b/crates/project-model/src/cargo_workspace.rs
@@ -767,10 +767,6 @@ impl FetchMetadata {
let mut using_lockfile_copy = false;
if let Some(lockfile_copy) = &lockfile_copy {
match lockfile_copy.usage {
- LockfileUsage::WithFlag => {
- other_options.push("--lockfile-path".to_owned());
- other_options.push(lockfile_copy.path.to_string());
- }
LockfileUsage::WithEnvVarUnstable => {
other_options.push("-Zlockfile-path".to_owned());
command.env("CARGO_RESOLVER_LOCKFILE_PATH", lockfile_copy.path.as_os_str());
diff --git a/crates/test-utils/src/minicore.rs b/crates/test-utils/src/minicore.rs
index f3a460b9ac..ca2d824f2c 100644
--- a/crates/test-utils/src/minicore.rs
+++ b/crates/test-utils/src/minicore.rs
@@ -37,8 +37,6 @@
//! error: fmt
//! float_consts:
//! fmt: option, result, transmute, coerce_unsized, copy, clone, derive
-//! fmt_before_1_93_0: fmt
-//! fmt_before_1_89_0: fmt_before_1_93_0
//! fn: sized, tuple
//! from: sized, result
//! future: pin
@@ -1428,111 +1426,8 @@ pub mod fmt {
Center,
Unknown,
}
-
- // region:fmt_before_1_93_0
- #[lang = "format_count"]
- pub enum Count {
- Is(usize),
- Param(usize),
- Implied,
- }
-
- #[lang = "format_placeholder"]
- pub struct Placeholder {
- pub position: usize,
- pub fill: char,
- pub align: Alignment,
- pub flags: u32,
- pub precision: Count,
- pub width: Count,
- }
-
- impl Placeholder {
- pub const fn new(
- position: usize,
- fill: char,
- align: Alignment,
- flags: u32,
- precision: Count,
- width: Count,
- ) -> Self {
- Placeholder { position, fill, align, flags, precision, width }
- }
- }
- // endregion:fmt_before_1_93_0
-
- // region:fmt_before_1_89_0
- #[lang = "format_unsafe_arg"]
- pub struct UnsafeArg {
- _private: (),
- }
-
- impl UnsafeArg {
- pub unsafe fn new() -> Self {
- UnsafeArg { _private: () }
- }
- }
- // endregion:fmt_before_1_89_0
- }
-
- // region:fmt_before_1_93_0
- #[derive(Copy, Clone)]
- #[lang = "format_arguments"]
- pub struct Arguments<'a> {
- pieces: &'a [&'static str],
- fmt: Option<&'a [rt::Placeholder]>,
- args: &'a [rt::Argument<'a>],
- }
-
- impl<'a> Arguments<'a> {
- pub const fn new_v1(pieces: &'a [&'static str], args: &'a [Argument<'a>]) -> Arguments<'a> {
- Arguments { pieces, fmt: None, args }
- }
-
- pub const fn new_const(pieces: &'a [&'static str]) -> Arguments<'a> {
- Arguments { pieces, fmt: None, args: &[] }
- }
-
- // region:fmt_before_1_89_0
- pub fn new_v1_formatted(
- pieces: &'a [&'static str],
- args: &'a [rt::Argument<'a>],
- fmt: &'a [rt::Placeholder],
- _unsafe_arg: rt::UnsafeArg,
- ) -> Arguments<'a> {
- Arguments { pieces, fmt: Some(fmt), args }
- }
- // endregion:fmt_before_1_89_0
-
- // region:!fmt_before_1_89_0
- pub unsafe fn new_v1_formatted(
- pieces: &'a [&'static str],
- args: &'a [rt::Argument<'a>],
- fmt: &'a [rt::Placeholder],
- ) -> Arguments<'a> {
- Arguments { pieces, fmt: Some(fmt), args }
- }
- // endregion:!fmt_before_1_89_0
-
- pub fn from_str_nonconst(s: &'static str) -> Arguments<'a> {
- Self::from_str(s)
- }
-
- pub const fn from_str(s: &'static str) -> Arguments<'a> {
- Arguments { pieces: &[s], fmt: None, args: &[] }
- }
-
- pub const fn as_str(&self) -> Option<&'static str> {
- match (self.pieces, self.args) {
- ([], []) => Some(""),
- ([s], []) => Some(s),
- _ => None,
- }
- }
}
- // endregion:fmt_before_1_93_0
- // region:!fmt_before_1_93_0
#[lang = "format_arguments"]
#[derive(Copy, Clone)]
pub struct Arguments<'a> {
@@ -1564,7 +1459,6 @@ pub mod fmt {
}
}
}
- // endregion:!fmt_before_1_93_0
// region:derive
pub(crate) mod derive {