@@ -20,7 +20,6 @@ use rustc_middle::{bug, span_bug};
2020use rustc_span:: { Span , sym} ;
2121use tracing:: { debug, info, instrument, trace} ;
2222
23- use crate :: errors;
2423use crate :: thir:: cx:: Cx ;
2524use crate :: thir:: util:: UserAnnotatedTyHelpers ;
2625
@@ -380,45 +379,25 @@ impl<'tcx> Cx<'tcx> {
380379 from_hir_call : true ,
381380 fn_span : expr. span ,
382381 }
383- } else {
384- let attrs = tcx. hir ( ) . attrs ( expr. hir_id ) ;
385- if attrs. iter ( ) . any ( |a| a. name_or_empty ( ) == sym:: rustc_box) {
386- if attrs. len ( ) != 1 {
387- tcx. dcx ( ) . emit_err ( errors:: RustcBoxAttributeError {
388- span : attrs[ 0 ] . span ,
389- reason : errors:: RustcBoxAttrReason :: Attributes ,
390- } ) ;
391- } else if let Some ( box_item) = tcx. lang_items ( ) . owned_box ( ) {
392- if let hir:: ExprKind :: Path ( hir:: QPath :: TypeRelative ( ty, fn_path) ) =
393- fun. kind
394- && let hir:: TyKind :: Path ( hir:: QPath :: Resolved ( _, path) ) = ty. kind
395- && path. res . opt_def_id ( ) . is_some_and ( |did| did == box_item)
396- && fn_path. ident . name == sym:: new
397- && let [ value] = args
398- {
399- return Expr {
400- temp_lifetime : TempLifetime {
401- temp_lifetime,
402- backwards_incompatible,
403- } ,
404- ty : expr_ty,
405- span : expr. span ,
406- kind : ExprKind :: Box { value : self . mirror_expr ( value) } ,
407- } ;
408- } else {
409- tcx. dcx ( ) . emit_err ( errors:: RustcBoxAttributeError {
410- span : expr. span ,
411- reason : errors:: RustcBoxAttrReason :: NotBoxNew ,
412- } ) ;
413- }
414- } else {
415- tcx. dcx ( ) . emit_err ( errors:: RustcBoxAttributeError {
416- span : attrs[ 0 ] . span ,
417- reason : errors:: RustcBoxAttrReason :: MissingBox ,
418- } ) ;
419- }
382+ } else if let ty:: FnDef ( def_id, _) = self . typeck_results ( ) . expr_ty ( fun) . kind ( )
383+ && let Some ( intrinsic) = self . tcx . intrinsic ( def_id)
384+ && intrinsic. name == sym:: box_new
385+ {
386+ // We don't actually evaluate `fun` here, so make sure that doesn't miss any side-effects.
387+ if !matches ! ( fun. kind, hir:: ExprKind :: Path ( _) ) {
388+ span_bug ! (
389+ expr. span,
390+ "`box_new` intrinsic can only be called via path expression"
391+ ) ;
420392 }
421-
393+ let value = & args[ 0 ] ;
394+ return Expr {
395+ temp_lifetime : TempLifetime { temp_lifetime, backwards_incompatible } ,
396+ ty : expr_ty,
397+ span : expr. span ,
398+ kind : ExprKind :: Box { value : self . mirror_expr ( value) } ,
399+ } ;
400+ } else {
422401 // Tuple-like ADTs are represented as ExprKind::Call. We convert them here.
423402 let adt_data = if let hir:: ExprKind :: Path ( ref qpath) = fun. kind
424403 && let Some ( adt_def) = expr_ty. ty_adt_def ( )
0 commit comments