pub(super) fn suggest_boxing_when_appropriate(
        &self,
        err: &mut DiagnosticBuilder<'_>,
        expr: &hir::Expr<'_>,
        expected: Ty<'tcx>,
        found: Ty<'tcx>,
    ) {
        if self.tcx.hir().is_inside_const_context(expr.hir_id) {
            // Do not suggest `Box::new` in const context.
            return;
        }
        if !expected.is_box() || found.is_box() {
            return;
        }
        let boxed_found = self.tcx.mk_box(found);
        if let (true, Ok(snippet)) = (
            self.can_coerce(boxed_found, expected),
            self.sess().source_map().span_to_snippet(expr.span),
        ) {
            err.span_suggestion(
                expr.span,
                "store this in the heap by calling `Box::new`",
                format!("Box::new({})", snippet),
                Applicability::MachineApplicable,
            );
            err.note(
                "for more on the distinction between the stack and the heap, read \
                 https://doc.rust-lang.org/book/ch15-01-box.html, \
                 https://doc.rust-lang.org/rust-by-example/std/box.html, and \
                 https://doc.rust-lang.org/std/boxed/index.html",
            );
        }
    }
/// When encountering the expected boxed value allocated in the stack, suggest allocating it
/// in the heap by calling `Box::new()`.
When encountering the expected boxed value allocated in the stack, suggest allocating it
in the heap by calling `Box::new()`.
When encountering the expected boxed value allocated in the stack suggest allocating it in the heap by calling ` Box :: new () ` .
pub(super) fn suggest_boxing_when_appropriate(
        &self,
        err: &mut DiagnosticBuilder<'_>,
        expr: &hir::Expr<'_>,
        expected: Ty<'tcx>,
        found: Ty<'tcx>,
    ) {
        if self.tcx.hir().is_inside_const_context(expr.hir_id) {
            // Do not suggest `Box::new` in const context.
            return;
        }
        if !expected.is_box() || found.is_box() {
            return;
        }
        let boxed_found = self.tcx.mk_box(found);
        if let (true, Ok(snippet)) = (
            self.can_coerce(boxed_found, expected),
            self.sess().source_map().span_to_snippet(expr.span),
        ) {
            err.span_suggestion(
                expr.span,
                "store this in the heap by calling `Box::new`",
                format!("Box::new({})", snippet),
                Applicability::MachineApplicable,
            );
            err.note(
                "for more on the distinction between the stack and the heap, read \
                 https://doc.rust-lang.org/book/ch15-01-box.html, \
                 https://doc.rust-lang.org/rust-by-example/std/box.html, and \
                 https://doc.rust-lang.org/std/boxed/index.html",
            );
        }
    }
pub ( super ) fn suggest_boxing_when_appropriate ( & self , err : & mut DiagnosticBuilder < ' _ > , expr : & hir :: Expr < ' _ > , expected : Ty < ' tcx > , found : Ty < ' tcx > , ) { if self . tcx . hir ( ) . is_inside_const_context ( expr . hir_id ) { // Do not suggest `Box::new` in const context. return ; } if ! expected . is_box ( ) || found . is_box ( ) { return ; } let boxed_found = self . tcx . mk_box ( found ) ; if let ( true , Ok ( snippet ) ) = ( self . can_coerce ( boxed_found , expected ) , self . sess ( ) . source_map ( ) . span_to_snippet ( expr . span ) , ) { err . span_suggestion ( expr . span , " " , format ! ( " " snippet ) , Applicability :: MachineApplicable , ) ; err . note ( " \
 \
 \
 " , ) ; } }
When encountering the expected boxed value allocated in the stack, suggest allocating it
in the heap by calling `Box::new()`.
When encountering the expected boxed value allocated in the stack suggest allocating it in the heap by calling ` Box :: new () ` .
&self
err
&mut DiagnosticBuilder<'_>
expr
&hir::Expr<'_>
expected
Ty<'tcx>
found
Ty<'tcx>
&self
err
&mut DiagnosticBuilder<'_>
expr
&hir::Expr<'_>
expected
Ty<'tcx>
found
Ty<'tcx>