about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/librustc_middle/hir/map/mod.rs22
-rw-r--r--src/librustc_mir/borrow_check/diagnostics/mutability_errors.rs2
-rw-r--r--src/test/ui/consts/enum-discr-type-err.stderr8
-rw-r--r--src/test/ui/discrim/discrim-ill-typed.stderr40
-rw-r--r--src/test/ui/issues/issue-31910.stderr5
-rw-r--r--src/test/ui/issues/issue-8761.stderr10
-rw-r--r--src/test/ui/repeat_count.stderr10
7 files changed, 12 insertions, 85 deletions
diff --git a/src/librustc_middle/hir/map/mod.rs b/src/librustc_middle/hir/map/mod.rs
index b823516d64f..c5f0acb3f07 100644
--- a/src/librustc_middle/hir/map/mod.rs
+++ b/src/librustc_middle/hir/map/mod.rs
@@ -374,6 +374,16 @@ impl<'hir> Map<'hir> {
         }
     }
 
+    pub fn enclosing_body_owner(&self, hir_id: HirId) -> HirId {
+        for (parent, _) in self.parent_iter(hir_id) {
+            if let Some(body) = self.maybe_body_owned_by(parent) {
+                return self.body_owner(body);
+            }
+        }
+
+        bug!("no `enclosing_body_owner` for hir_id `{}`", hir_id);
+    }
+
     /// Returns the `HirId` that corresponds to the definition of
     /// which this is the body of, i.e., a `fn`, `const` or `static`
     /// item (possibly associated), a closure, or a `hir::AnonConst`.
@@ -577,17 +587,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 {
-        let parent_id = self.get_parent_item(hir_id);
-        match self.get(parent_id) {
-            Node::Item(&Item { kind: ItemKind::Const(..) | ItemKind::Static(..), .. })
-            | Node::TraitItem(&TraitItem { kind: TraitItemKind::Const(..), .. })
-            | Node::ImplItem(&ImplItem { kind: ImplItemKind::Const(..), .. })
-            | Node::AnonConst(_) => true,
-            Node::Item(&Item { kind: ItemKind::Fn(ref sig, ..), .. }) => {
-                sig.header.constness == Constness::Const
-            }
-            _ => false,
-        }
+        self.body_const_context(self.local_def_id(self.enclosing_body_owner(hir_id))).is_some()
     }
 
     /// Whether `hir_id` corresponds to a `mod` or a crate.
diff --git a/src/librustc_mir/borrow_check/diagnostics/mutability_errors.rs b/src/librustc_mir/borrow_check/diagnostics/mutability_errors.rs
index 402eac47c46..ff90748a9d0 100644
--- a/src/librustc_mir/borrow_check/diagnostics/mutability_errors.rs
+++ b/src/librustc_mir/borrow_check/diagnostics/mutability_errors.rs
@@ -495,7 +495,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
         let closure_id = hir.as_local_hir_id(self.mir_def_id.expect_local());
         let fn_call_id = hir.get_parent_node(closure_id);
         let node = hir.get(fn_call_id);
-        let item_id = hir.get_parent_item(fn_call_id);
+        let item_id = hir.enclosing_body_owner(fn_call_id);
         let mut look_at_return = true;
         // If we can detect the expression to be an `fn` call where the closure was an argument,
         // we point at the `fn` definition argument...
diff --git a/src/test/ui/consts/enum-discr-type-err.stderr b/src/test/ui/consts/enum-discr-type-err.stderr
index 492b79e2e60..9834a99b79a 100644
--- a/src/test/ui/consts/enum-discr-type-err.stderr
+++ b/src/test/ui/consts/enum-discr-type-err.stderr
@@ -11,10 +11,6 @@ LL | | }
    | |_- in this macro invocation
    |
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
-help: you can convert an `i32` to `isize` and panic if the converted value wouldn't fit
-   |
-LL |             $( $v = $s::V.try_into().unwrap(), )*
-   |                     ^^^^^^^^^^^^^^^^^^^^^^^^^
 
 error[E0308]: mismatched types
   --> $DIR/enum-discr-type-err.rs:18:21
@@ -29,10 +25,6 @@ LL | | }
    | |_- in this macro invocation
    |
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
-help: you can convert an `i32` to `isize` and panic if the converted value wouldn't fit
-   |
-LL |             $( $v = $s::V.try_into().unwrap(), )*
-   |                     ^^^^^^^^^^^^^^^^^^^^^^^^^
 
 error: aborting due to 2 previous errors
 
diff --git a/src/test/ui/discrim/discrim-ill-typed.stderr b/src/test/ui/discrim/discrim-ill-typed.stderr
index 7b9f086151a..b0e11ee5a6e 100644
--- a/src/test/ui/discrim/discrim-ill-typed.stderr
+++ b/src/test/ui/discrim/discrim-ill-typed.stderr
@@ -3,88 +3,48 @@ error[E0308]: mismatched types
    |
 LL |         OhNo = 0_u8,
    |                ^^^^ expected `i8`, found `u8`
-   |
-help: change the type of the numeric literal from `u8` to `i8`
-   |
-LL |         OhNo = 0_i8,
-   |                ^^^^
 
 error[E0308]: mismatched types
   --> $DIR/discrim-ill-typed.rs:30:16
    |
 LL |         OhNo = 0_i8,
    |                ^^^^ expected `u8`, found `i8`
-   |
-help: change the type of the numeric literal from `i8` to `u8`
-   |
-LL |         OhNo = 0_u8,
-   |                ^^^^
 
 error[E0308]: mismatched types
   --> $DIR/discrim-ill-typed.rs:43:16
    |
 LL |         OhNo = 0_u16,
    |                ^^^^^ expected `i16`, found `u16`
-   |
-help: change the type of the numeric literal from `u16` to `i16`
-   |
-LL |         OhNo = 0_i16,
-   |                ^^^^^
 
 error[E0308]: mismatched types
   --> $DIR/discrim-ill-typed.rs:56:16
    |
 LL |         OhNo = 0_i16,
    |                ^^^^^ expected `u16`, found `i16`
-   |
-help: change the type of the numeric literal from `i16` to `u16`
-   |
-LL |         OhNo = 0_u16,
-   |                ^^^^^
 
 error[E0308]: mismatched types
   --> $DIR/discrim-ill-typed.rs:69:16
    |
 LL |         OhNo = 0_u32,
    |                ^^^^^ expected `i32`, found `u32`
-   |
-help: change the type of the numeric literal from `u32` to `i32`
-   |
-LL |         OhNo = 0_i32,
-   |                ^^^^^
 
 error[E0308]: mismatched types
   --> $DIR/discrim-ill-typed.rs:82:16
    |
 LL |         OhNo = 0_i32,
    |                ^^^^^ expected `u32`, found `i32`
-   |
-help: change the type of the numeric literal from `i32` to `u32`
-   |
-LL |         OhNo = 0_u32,
-   |                ^^^^^
 
 error[E0308]: mismatched types
   --> $DIR/discrim-ill-typed.rs:95:16
    |
 LL |         OhNo = 0_u64,
    |                ^^^^^ expected `i64`, found `u64`
-   |
-help: change the type of the numeric literal from `u64` to `i64`
-   |
-LL |         OhNo = 0_i64,
-   |                ^^^^^
 
 error[E0308]: mismatched types
   --> $DIR/discrim-ill-typed.rs:108:16
    |
 LL |         OhNo = 0_i64,
    |                ^^^^^ expected `u64`, found `i64`
-   |
-help: change the type of the numeric literal from `i64` to `u64`
-   |
-LL |         OhNo = 0_u64,
-   |                ^^^^^
 
 error: aborting due to 8 previous errors
 
diff --git a/src/test/ui/issues/issue-31910.stderr b/src/test/ui/issues/issue-31910.stderr
index c5c988cdaa7..2603c944207 100644
--- a/src/test/ui/issues/issue-31910.stderr
+++ b/src/test/ui/issues/issue-31910.stderr
@@ -3,11 +3,6 @@ error[E0308]: mismatched types
    |
 LL |     X = Trait::Number,
    |         ^^^^^^^^^^^^^ expected `isize`, found `i32`
-   |
-help: you can convert an `i32` to `isize` and panic if the converted value wouldn't fit
-   |
-LL |     X = Trait::Number.try_into().unwrap(),
-   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 error: aborting due to previous error
 
diff --git a/src/test/ui/issues/issue-8761.stderr b/src/test/ui/issues/issue-8761.stderr
index 836520a28ef..6ab74a9e989 100644
--- a/src/test/ui/issues/issue-8761.stderr
+++ b/src/test/ui/issues/issue-8761.stderr
@@ -3,22 +3,12 @@ error[E0308]: mismatched types
    |
 LL |     A = 1i64,
    |         ^^^^ expected `isize`, found `i64`
-   |
-help: change the type of the numeric literal from `i64` to `isize`
-   |
-LL |     A = 1isize,
-   |         ^^^^^^
 
 error[E0308]: mismatched types
   --> $DIR/issue-8761.rs:5:9
    |
 LL |     B = 2u8
    |         ^^^ expected `isize`, found `u8`
-   |
-help: change the type of the numeric literal from `u8` to `isize`
-   |
-LL |     B = 2isize
-   |         ^^^^^^
 
 error: aborting due to 2 previous errors
 
diff --git a/src/test/ui/repeat_count.stderr b/src/test/ui/repeat_count.stderr
index 4a2d1d9f921..963319892d4 100644
--- a/src/test/ui/repeat_count.stderr
+++ b/src/test/ui/repeat_count.stderr
@@ -39,22 +39,12 @@ error[E0308]: mismatched types
    |
 LL |     let f = [0; -4_isize];
    |                 ^^^^^^^^ expected `usize`, found `isize`
-   |
-help: you can convert an `isize` to `usize` and panic if the converted value wouldn't fit
-   |
-LL |     let f = [0; (-4_isize).try_into().unwrap()];
-   |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 error[E0308]: mismatched types
   --> $DIR/repeat_count.rs:22:23
    |
 LL |     let f = [0_usize; -1_isize];
    |                       ^^^^^^^^ expected `usize`, found `isize`
-   |
-help: you can convert an `isize` to `usize` and panic if the converted value wouldn't fit
-   |
-LL |     let f = [0_usize; (-1_isize).try_into().unwrap()];
-   |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 error: aborting due to 8 previous errors