Skip to content

Commit

Permalink
is_const_context -> is_inside_const_context
Browse files Browse the repository at this point in the history
  • Loading branch information
lcnr committed May 20, 2020
1 parent ecb5933 commit 6da17d2
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/librustc_middle/hir/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ impl<'hir> Map<'hir> {

/// Whether the expression pointed at by `hir_id` belongs to a `const` evaluation context.
/// Used exclusively for diagnostics, to avoid suggestion function calls.
pub fn is_const_context(&self, hir_id: HirId) -> bool {
pub fn is_inside_const_context(&self, hir_id: HirId) -> bool {
self.body_const_context(self.local_def_id(self.enclosing_body_owner(hir_id))).is_some()
}

Expand Down
4 changes: 2 additions & 2 deletions src/librustc_typeck/check/demand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -800,12 +800,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
if let hir::ExprKind::Lit(lit) = &expr.kind { lit.node.is_suffixed() } else { false }
};

let is_const_context = self.tcx.hir().is_const_context(expr.hir_id);
let in_const_context = self.tcx.hir().is_inside_const_context(expr.hir_id);
let suggest_to_change_suffix_or_into =
|err: &mut DiagnosticBuilder<'_>, is_fallible: bool| {
let msg = if literal_is_ty_suffixed(expr) {
&lit_msg
} else if is_const_context {
} else if in_const_context {
// Do not recommend `into` or `try_into` in const contexts.
return;
} else if is_fallible {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5097,7 +5097,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
expected: Ty<'tcx>,
found: Ty<'tcx>,
) {
if self.tcx.hir().is_const_context(expr.hir_id) {
if self.tcx.hir().is_inside_const_context(expr.hir_id) {
// Do not suggest `Box::new` in const context.
return;
}
Expand Down Expand Up @@ -5134,7 +5134,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
) -> bool {
// Handle #68197.

if self.tcx.hir().is_const_context(expr.hir_id) {
if self.tcx.hir().is_inside_const_context(expr.hir_id) {
// Do not suggest `Box::new` in const context.
return false;
}
Expand Down

0 comments on commit 6da17d2

Please sign in to comment.