]> git.lizzy.rs Git - rust.git/commitdiff
Auto merge of #55236 - petrochenkov:pfail, r=davidtwco
authorbors <bors@rust-lang.org>
Sun, 21 Oct 2018 17:26:16 +0000 (17:26 +0000)
committerbors <bors@rust-lang.org>
Sun, 21 Oct 2018 17:26:16 +0000 (17:26 +0000)
Move parse-fail tests to UI

cc https://github.com/rust-lang/rust/issues/53353

r? @davidtwco

165 files changed:
src/librustc/ich/impls_mir.rs
src/librustc/ich/impls_ty.rs
src/librustc/infer/canonical/canonicalizer.rs
src/librustc/infer/canonical/mod.rs
src/librustc/infer/canonical/query_response.rs
src/librustc/infer/canonical/substitute.rs
src/librustc/infer/freshen.rs
src/librustc/mir/interpret/mod.rs
src/librustc/mir/mod.rs
src/librustc/traits/select.rs
src/librustc/ty/error.rs
src/librustc/ty/flags.rs
src/librustc/ty/mod.rs
src/librustc/ty/sty.rs
src/librustc/ty/subst.rs
src/librustc/util/ppaux.rs
src/librustc_mir/borrow_check/error_reporting.rs
src/librustc_mir/borrow_check/nll/explain_borrow/mod.rs
src/librustc_mir/borrow_check/nll/mod.rs
src/librustc_mir/borrow_check/nll/region_infer/error_reporting/mod.rs
src/librustc_mir/borrow_check/nll/region_infer/mod.rs
src/librustc_mir/borrow_check/nll/type_check/mod.rs
src/librustc_mir/const_eval.rs
src/librustc_mir/diagnostics.rs
src/librustc_mir/interpret/cast.rs
src/librustc_mir/interpret/eval_context.rs
src/librustc_mir/interpret/machine.rs
src/librustc_mir/interpret/memory.rs
src/librustc_mir/interpret/mod.rs
src/librustc_mir/interpret/place.rs
src/librustc_mir/interpret/snapshot.rs
src/librustc_mir/interpret/step.rs
src/librustc_mir/interpret/terminator.rs
src/librustc_mir/interpret/traits.rs
src/librustc_mir/interpret/validity.rs
src/librustc_mir/util/borrowck_errors.rs
src/test/ui/borrowck/borrowck-borrow-from-temporary.nll.stderr
src/test/ui/borrowck/borrowck-escaping-closure-error-1.nll.stderr
src/test/ui/borrowck/borrowck-escaping-closure-error-2.nll.stderr
src/test/ui/borrowck/borrowck-fn-in-const-c.nll.stderr
src/test/ui/borrowck/borrowck-loan-of-static-data-issue-27616.nll.stderr
src/test/ui/borrowck/borrowck-local-borrow-outlives-fn.ast.nll.stderr
src/test/ui/borrowck/borrowck-local-borrow-outlives-fn.mir.stderr
src/test/ui/borrowck/borrowck-local-borrow-outlives-fn.rs
src/test/ui/borrowck/borrowck-local-borrow-with-panic-outlives-fn.ast.nll.stderr
src/test/ui/borrowck/borrowck-local-borrow-with-panic-outlives-fn.mir.stderr
src/test/ui/borrowck/borrowck-return-variable-on-stack-via-clone.nll.stderr
src/test/ui/borrowck/borrowck-vec-pattern-element-loan.nll.stderr
src/test/ui/borrowck/borrowck-vec-pattern-tail-element-loan.nll.stderr
src/test/ui/borrowck/issue-45983.nll.stderr
src/test/ui/borrowck/mut-borrow-in-loop.nll.stderr
src/test/ui/borrowck/promote-ref-mut-in-let-issue-46557.nll.stderr
src/test/ui/borrowck/two-phase-surprise-no-conflict.nll.stderr
src/test/ui/consts/const-eval/dont_promote_unstable_const_fn.nll.stderr
src/test/ui/consts/const-eval/dont_promote_unstable_const_fn_cross_crate.nll.stderr
src/test/ui/consts/const-eval/promoted_const_fn_fail.nll.stderr
src/test/ui/consts/const-eval/promoted_raw_ptr_ops.nll.stderr
src/test/ui/consts/const-eval/transmute-const-promotion.nll.stderr
src/test/ui/consts/const-eval/union_promotion.nll.stderr
src/test/ui/consts/const-int-conversion.nll.stderr
src/test/ui/consts/const-int-overflowing.nll.stderr
src/test/ui/consts/const-int-rotate.nll.stderr
src/test/ui/consts/const-int-sign.nll.stderr
src/test/ui/consts/const-int-wrapping.nll.stderr
src/test/ui/consts/issue-54224.stderr
src/test/ui/consts/min_const_fn/min_const_fn.nll.stderr
src/test/ui/consts/min_const_fn/min_const_fn_dyn.nll.stderr
src/test/ui/consts/min_const_fn/promotion.nll.stderr
src/test/ui/dropck/drop-with-active-borrows-2.nll.stderr
src/test/ui/dropck/dropck_trait_cycle_checked.nll.stderr
src/test/ui/dst/dst-bad-coerce3.nll.stderr
src/test/ui/generator/generator-region-requirements.nll.stderr
src/test/ui/generator/ref-escapes-but-not-over-yield.nll.stderr
src/test/ui/issues/issue-11681.nll.stderr
src/test/ui/issues/issue-12470.nll.stderr
src/test/ui/issues/issue-13497-2.nll.stderr
src/test/ui/issues/issue-17545.nll.stderr
src/test/ui/issues/issue-17718-constants-not-static.nll.stderr
src/test/ui/issues/issue-18118.nll.stderr
src/test/ui/issues/issue-27592.nll.stderr
src/test/ui/issues/issue-30438-a.nll.stderr
src/test/ui/issues/issue-30438-b.nll.stderr
src/test/ui/issues/issue-30438-c.nll.stderr
src/test/ui/issues/issue-4335.nll.stderr
src/test/ui/issues/issue-44373.nll.stderr
src/test/ui/issues/issue-45696-scribble-on-boxed-borrow.migrate.stderr
src/test/ui/issues/issue-45696-scribble-on-boxed-borrow.nll.stderr
src/test/ui/issues/issue-46036.stderr
src/test/ui/issues/issue-46471.rs
src/test/ui/issues/issue-46471.stderr
src/test/ui/issues/issue-46472.rs
src/test/ui/issues/issue-46472.stderr
src/test/ui/issues/issue-47184.stderr
src/test/ui/issues/issue-52049.nll.stderr
src/test/ui/nll/borrowed-universal-error-2.rs
src/test/ui/nll/borrowed-universal-error-2.stderr
src/test/ui/nll/borrowed-universal-error.rs
src/test/ui/nll/borrowed-universal-error.stderr
src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-comparing-against-free.stderr
src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-no-bound.stderr
src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-wrong-bound.stderr
src/test/ui/nll/do-not-ignore-lifetime-bounds-in-copy.stderr
src/test/ui/nll/enum-drop-access.stderr
src/test/ui/nll/get_default.nll.stderr
src/test/ui/nll/get_default.stderr
src/test/ui/nll/issue-31567.stderr
src/test/ui/nll/issue-47470.rs
src/test/ui/nll/issue-47470.stderr
src/test/ui/nll/issue-52059-report-when-borrow-and-drop-conflict.stderr
src/test/ui/nll/issue-52534-1.stderr
src/test/ui/nll/polonius-smoke-test.stderr
src/test/ui/nll/relate_tys/var-appears-twice.stderr
src/test/ui/nll/return-ref-mut-issue-46557.rs
src/test/ui/nll/return-ref-mut-issue-46557.stderr
src/test/ui/nll/user-annotations/adt-brace-enums.stderr
src/test/ui/nll/user-annotations/adt-brace-structs.stderr
src/test/ui/nll/user-annotations/adt-nullary-enums.stderr
src/test/ui/nll/user-annotations/adt-tuple-enums.stderr
src/test/ui/nll/user-annotations/adt-tuple-struct.stderr
src/test/ui/nll/user-annotations/cast_static_lifetime.stderr
src/test/ui/nll/user-annotations/fns.stderr
src/test/ui/nll/user-annotations/method-call.stderr
src/test/ui/nll/user-annotations/method-ufcs-1.stderr
src/test/ui/nll/user-annotations/method-ufcs-2.stderr
src/test/ui/nll/user-annotations/method-ufcs-3.stderr
src/test/ui/nll/user-annotations/method-ufcs-inherent-1.stderr
src/test/ui/nll/user-annotations/method-ufcs-inherent-2.stderr
src/test/ui/nll/user-annotations/method-ufcs-inherent-3.stderr
src/test/ui/nll/user-annotations/method-ufcs-inherent-4.stderr
src/test/ui/nll/user-annotations/normalization.stderr
src/test/ui/nll/user-annotations/pattern_substs_on_brace_enum_variant.stderr
src/test/ui/nll/user-annotations/pattern_substs_on_brace_struct.stderr
src/test/ui/nll/user-annotations/pattern_substs_on_tuple_enum_variant.stderr
src/test/ui/nll/user-annotations/pattern_substs_on_tuple_struct.stderr
src/test/ui/nll/user-annotations/patterns.stderr
src/test/ui/nll/user-annotations/type_ascription_static_lifetime.stderr
src/test/ui/nll/where_clauses_in_functions.stderr
src/test/ui/regions/region-borrow-params-issue-29793-big.ast.nll.stderr
src/test/ui/regions/region-borrow-params-issue-29793-big.mir.stderr
src/test/ui/regions/region-borrow-params-issue-29793-big.rs
src/test/ui/regions/region-borrow-params-issue-29793-small.nll.stderr
src/test/ui/regions/region-object-lifetime-5.nll.stderr
src/test/ui/regions/regions-addr-of-arg.nll.stderr
src/test/ui/regions/regions-close-object-into-object-1.nll.stderr
src/test/ui/regions/regions-close-object-into-object-3.nll.stderr
src/test/ui/regions/regions-creating-enums.nll.stderr
src/test/ui/regions/regions-free-region-ordering-caller1.nll.stderr
src/test/ui/regions/regions-infer-borrow-scope-too-big.nll.stderr
src/test/ui/regions/regions-infer-proc-static-upvar.nll.stderr
src/test/ui/regions/regions-lifetime-of-struct-or-enum-variant.nll.stderr
src/test/ui/regions/regions-nested-fns-2.nll.stderr
src/test/ui/regions/regions-pattern-typing-issue-19552.nll.stderr
src/test/ui/regions/regions-ref-in-fn-arg.nll.stderr
src/test/ui/regions/regions-ret.nll.stderr
src/test/ui/regions/regions-return-stack-allocated-vec.nll.stderr
src/test/ui/regions/regions-trait-variance.nll.stderr
src/test/ui/span/issue-11925.nll.stderr
src/test/ui/static/static-drop-scope.nll.stderr
src/test/ui/static/static-lifetime-bound.nll.stderr
src/test/ui/static/static-reference-to-fn-2.nll.stderr
src/test/ui/static/static-region-bound.nll.stderr
src/test/ui/traits/trait-coercion-generic-regions.nll.stderr
src/test/ui/unboxed-closures/unboxed-closures-failed-recursive-fn-1.nll.stderr
src/test/ui/wf/wf-misc-methods-issue-28609.nll.stderr
src/tools/miri

index a82a8ca6bdff0e1ef312a615b0984010a21596f5..4f68569c60032a278ada9a43b259ded1d0ac7d8a 100644 (file)
@@ -557,6 +557,8 @@ fn hash_stable<W: StableHasherResult>(&self,
 
 impl_stable_hash_for!(enum mir::ConstraintCategory {
     Return,
+    UseAsConst,
+    UseAsStatic,
     TypeAnnotation,
     Cast,
     ClosureBounds,
index 2a3d40c0e3fc1f94abf719f60b12d62f1f537225..642eb11006649f5e0b3e3cb63bbff5c60d6f9ac3 100644 (file)
@@ -147,7 +147,7 @@ fn hash_stable<W: StableHasherResult>(&self,
     }
 }
 
-impl<'gcx> HashStable<StableHashingContext<'gcx>> for ty::CanonicalVar {
+impl<'gcx> HashStable<StableHashingContext<'gcx>> for ty::BoundTyIndex {
     #[inline]
     fn hash_stable<W: StableHasherResult>(&self,
                                           hcx: &mut StableHashingContext<'gcx>,
@@ -915,7 +915,7 @@ fn hash_stable<W: StableHasherResult>(&self,
     FreshTy(a),
     FreshIntTy(a),
     FreshFloatTy(a),
-    CanonicalTy(a),
+    BoundTy(a),
 });
 
 impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
index 8c87c2a01c04fff99a3fe16ccc06ac3a71dfc5e9..2b085a3407ccc40f453da1af6f17ab6d2fd370ac 100644 (file)
@@ -23,7 +23,7 @@
 use std::sync::atomic::Ordering;
 use ty::fold::{TypeFoldable, TypeFolder};
 use ty::subst::Kind;
-use ty::{self, CanonicalVar, Lift, List, Ty, TyCtxt, TypeFlags};
+use ty::{self, BoundTy, BoundTyIndex, Lift, List, Ty, TyCtxt, TypeFlags};
 
 use rustc_data_structures::fx::FxHashMap;
 use rustc_data_structures::indexed_vec::Idx;
@@ -225,7 +225,7 @@ struct Canonicalizer<'cx, 'gcx: 'tcx, 'tcx: 'cx> {
     query_state: &'cx mut OriginalQueryValues<'tcx>,
     // Note that indices is only used once `var_values` is big enough to be
     // heap-allocated.
-    indices: FxHashMap<Kind<'tcx>, CanonicalVar>,
+    indices: FxHashMap<Kind<'tcx>, BoundTyIndex>,
     canonicalize_region_mode: &'cx dyn CanonicalizeRegionMode,
     needs_canonical_flags: TypeFlags,
 }
@@ -283,7 +283,7 @@ fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> {
                 bug!("encountered a fresh type during canonicalization")
             }
 
-            ty::Infer(ty::CanonicalTy(_)) => {
+            ty::Infer(ty::BoundTy(_)) => {
                 bug!("encountered a canonical type during canonicalization")
             }
 
@@ -393,7 +393,7 @@ fn canonicalize<V>(
     /// or returns an existing variable if `kind` has already been
     /// seen. `kind` is expected to be an unbound variable (or
     /// potentially a free region).
-    fn canonical_var(&mut self, info: CanonicalVarInfo, kind: Kind<'tcx>) -> CanonicalVar {
+    fn canonical_var(&mut self, info: CanonicalVarInfo, kind: Kind<'tcx>) -> BoundTy {
         let Canonicalizer {
             variables,
             query_state,
@@ -408,12 +408,12 @@ fn canonical_var(&mut self, info: CanonicalVarInfo, kind: Kind<'tcx>) -> Canonic
         // avoid allocations in those cases. We also don't use `indices` to
         // determine if a kind has been seen before until the limit of 8 has
         // been exceeded, to also avoid allocations for `indices`.
-        if !var_values.spilled() {
+        let var = if !var_values.spilled() {
             // `var_values` is stack-allocated. `indices` isn't used yet. Do a
             // direct linear search of `var_values`.
             if let Some(idx) = var_values.iter().position(|&k| k == kind) {
                 // `kind` is already present in `var_values`.
-                CanonicalVar::new(idx)
+                BoundTyIndex::new(idx)
             } else {
                 // `kind` isn't present in `var_values`. Append it. Likewise
                 // for `info` and `variables`.
@@ -428,11 +428,11 @@ fn canonical_var(&mut self, info: CanonicalVarInfo, kind: Kind<'tcx>) -> Canonic
                     *indices = var_values
                         .iter()
                         .enumerate()
-                        .map(|(i, &kind)| (kind, CanonicalVar::new(i)))
+                        .map(|(i, &kind)| (kind, BoundTyIndex::new(i)))
                         .collect();
                 }
                 // The cv is the index of the appended element.
-                CanonicalVar::new(var_values.len() - 1)
+                BoundTyIndex::new(var_values.len() - 1)
             }
         } else {
             // `var_values` is large. Do a hashmap search via `indices`.
@@ -440,8 +440,13 @@ fn canonical_var(&mut self, info: CanonicalVarInfo, kind: Kind<'tcx>) -> Canonic
                 variables.push(info);
                 var_values.push(kind);
                 assert_eq!(variables.len(), var_values.len());
-                CanonicalVar::new(variables.len() - 1)
+                BoundTyIndex::new(variables.len() - 1)
             })
+        };
+
+        BoundTy {
+            level: ty::INNERMOST,
+            var,
         }
     }
 
@@ -449,8 +454,9 @@ fn canonical_var_for_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx>
         let info = CanonicalVarInfo {
             kind: CanonicalVarKind::Region,
         };
-        let cvar = self.canonical_var(info, r.into());
-        self.tcx().mk_region(ty::ReCanonical(cvar))
+        let b = self.canonical_var(info, r.into());
+        debug_assert_eq!(ty::INNERMOST, b.level);
+        self.tcx().mk_region(ty::ReCanonical(b.var))
     }
 
     /// Given a type variable `ty_var` of the given kind, first check
@@ -466,8 +472,9 @@ fn canonicalize_ty_var(&mut self, ty_kind: CanonicalTyVarKind, ty_var: Ty<'tcx>)
             let info = CanonicalVarInfo {
                 kind: CanonicalVarKind::Ty(ty_kind),
             };
-            let cvar = self.canonical_var(info, ty_var.into());
-            self.tcx().mk_infer(ty::InferTy::CanonicalTy(cvar))
+            let b = self.canonical_var(info, ty_var.into());
+            debug_assert_eq!(ty::INNERMOST, b.level);
+            self.tcx().mk_infer(ty::InferTy::BoundTy(b))
         }
     }
 }
index 1863f08930f5f55b04b1f24fd13ff6b3ecc0c375..e3bd407d17a90785a27ff6da5fc02dbda78211ed 100644 (file)
@@ -40,7 +40,7 @@
 use syntax::source_map::Span;
 use ty::fold::TypeFoldable;
 use ty::subst::Kind;
-use ty::{self, CanonicalVar, Lift, Region, List, TyCtxt};
+use ty::{self, BoundTyIndex, Lift, Region, List, TyCtxt};
 
 mod canonicalizer;
 
@@ -72,7 +72,7 @@ impl<'gcx> UseSpecializedDecodable for CanonicalVarInfos<'gcx> {}
 /// canonicalized query response.
 #[derive(Clone, Debug, PartialEq, Eq, Hash, RustcDecodable, RustcEncodable)]
 pub struct CanonicalVarValues<'tcx> {
-    pub var_values: IndexVec<CanonicalVar, Kind<'tcx>>,
+    pub var_values: IndexVec<BoundTyIndex, Kind<'tcx>>,
 }
 
 /// When we canonicalize a value to form a query, we wind up replacing
@@ -264,7 +264,7 @@ fn fresh_inference_vars_for_canonical_vars(
         span: Span,
         variables: &List<CanonicalVarInfo>,
     ) -> CanonicalVarValues<'tcx> {
-        let var_values: IndexVec<CanonicalVar, Kind<'tcx>> = variables
+        let var_values: IndexVec<BoundTyIndex, Kind<'tcx>> = variables
             .iter()
             .map(|info| self.fresh_inference_var_for_canonical_var(span, *info))
             .collect();
@@ -367,10 +367,10 @@ impl<'a, 'tcx, R> Lift<'tcx> for QueryResponse<'a, R> {
     } where R: Lift<'tcx>
 }
 
-impl<'tcx> Index<CanonicalVar> for CanonicalVarValues<'tcx> {
+impl<'tcx> Index<BoundTyIndex> for CanonicalVarValues<'tcx> {
     type Output = Kind<'tcx>;
 
-    fn index(&self, value: CanonicalVar) -> &Kind<'tcx> {
+    fn index(&self, value: BoundTyIndex) -> &Kind<'tcx> {
         &self.var_values[value]
     }
 }
index b9edc9f51eaa890d8be3297b1784b42aa346662d..38788186eb0710ddb6ccbd8262aa58a0cbcf1fb4 100644 (file)
@@ -35,7 +35,7 @@
 use traits::{Obligation, ObligationCause, PredicateObligation};
 use ty::fold::TypeFoldable;
 use ty::subst::{Kind, UnpackedKind};
-use ty::{self, CanonicalVar, Lift, Ty, TyCtxt};
+use ty::{self, BoundTyIndex, Lift, Ty, TyCtxt};
 
 impl<'cx, 'gcx, 'tcx> InferCtxtBuilder<'cx, 'gcx, 'tcx> {
     /// The "main method" for a canonicalized trait query. Given the
@@ -273,7 +273,7 @@ pub fn instantiate_nll_query_response_and_region_obligations<R>(
         for (index, original_value) in original_values.var_values.iter().enumerate() {
             // ...with the value `v_r` of that variable from the query.
             let result_value = query_response.substitute_projected(self.tcx, &result_subst, |v| {
-                &v.var_values[CanonicalVar::new(index)]
+                &v.var_values[BoundTyIndex::new(index)]
             });
             match (original_value.unpack(), result_value.unpack()) {
                 (UnpackedKind::Lifetime(ty::ReErased), UnpackedKind::Lifetime(ty::ReErased)) => {
@@ -408,7 +408,7 @@ fn query_response_substitution_guess<R>(
         // is directly equal to one of the canonical variables in the
         // result, then we can type the corresponding value from the
         // input. See the example above.
-        let mut opt_values: IndexVec<CanonicalVar, Option<Kind<'tcx>>> =
+        let mut opt_values: IndexVec<BoundTyIndex, Option<Kind<'tcx>>> =
             IndexVec::from_elem_n(None, query_response.variables.len());
 
         // In terms of our example above, we are iterating over pairs like:
@@ -417,9 +417,9 @@ fn query_response_substitution_guess<R>(
             match result_value.unpack() {
                 UnpackedKind::Type(result_value) => {
                     // e.g., here `result_value` might be `?0` in the example above...
-                    if let ty::Infer(ty::InferTy::CanonicalTy(index)) = result_value.sty {
+                    if let ty::Infer(ty::InferTy::BoundTy(b)) = result_value.sty {
                         // in which case we would set `canonical_vars[0]` to `Some(?U)`.
-                        opt_values[index] = Some(*original_value);
+                        opt_values[b.var] = Some(*original_value);
                     }
                 }
                 UnpackedKind::Lifetime(result_value) => {
@@ -440,7 +440,7 @@ fn query_response_substitution_guess<R>(
                 .variables
                 .iter()
                 .enumerate()
-                .map(|(index, info)| opt_values[CanonicalVar::new(index)].unwrap_or_else(||
+                .map(|(index, info)| opt_values[BoundTyIndex::new(index)].unwrap_or_else(||
                     self.fresh_inference_var_for_canonical_var(cause.span, *info)
                 ))
                 .collect(),
@@ -470,7 +470,7 @@ fn unify_query_response_substitution_guess<R>(
         // canonical variable; this is taken from
         // `query_response.var_values` after applying the substitution
         // `result_subst`.
-        let substituted_query_response = |index: CanonicalVar| -> Kind<'tcx> {
+        let substituted_query_response = |index: BoundTyIndex| -> Kind<'tcx> {
             query_response.substitute_projected(self.tcx, &result_subst, |v| &v.var_values[index])
         };
 
@@ -526,12 +526,12 @@ fn unify_canonical_vars(
         cause: &ObligationCause<'tcx>,
         param_env: ty::ParamEnv<'tcx>,
         variables1: &OriginalQueryValues<'tcx>,
-        variables2: impl Fn(CanonicalVar) -> Kind<'tcx>,
+        variables2: impl Fn(BoundTyIndex) -> Kind<'tcx>,
     ) -> InferResult<'tcx, ()> {
         self.commit_if_ok(|_| {
             let mut obligations = vec![];
             for (index, value1) in variables1.var_values.iter().enumerate() {
-                let value2 = variables2(CanonicalVar::new(index));
+                let value2 = variables2(BoundTyIndex::new(index));
 
                 match (value1.unpack(), value2.unpack()) {
                     (UnpackedKind::Type(v1), UnpackedKind::Type(v2)) => {
index f3fe01d5fd121659b064b389ac35e240fb200034..03441c3dee35e2ba40c49fb6b7e12bbe19fa3afa 100644 (file)
@@ -85,10 +85,11 @@ fn tcx(&self) -> TyCtxt<'_, 'gcx, 'tcx> {
 
     fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> {
         match t.sty {
-            ty::Infer(ty::InferTy::CanonicalTy(c)) => {
-                match self.var_values.var_values[c].unpack() {
+            ty::Infer(ty::InferTy::BoundTy(b)) => {
+                debug_assert_eq!(ty::INNERMOST, b.level);
+                match self.var_values.var_values[b.var].unpack() {
                     UnpackedKind::Type(ty) => ty,
-                    r => bug!("{:?} is a type but value is {:?}", c, r),
+                    r => bug!("{:?} is a type but value is {:?}", b, r),
                 }
             }
             _ => {
index c7785d831717376fe7b9c03d4f8cf2249245efcc..1647f259db9fb27e855ae0db4fe08cdb39480104 100644 (file)
@@ -171,7 +171,7 @@ fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> {
                 t
             }
 
-            ty::Infer(ty::CanonicalTy(..)) =>
+            ty::Infer(ty::BoundTy(..)) =>
                 bug!("encountered canonical ty during freshening"),
 
             ty::Generator(..) |
index 8c8073080aaf8cbf5ba0cebd7dd91137329ee794..4c2b2b2d41d1ba6f36f391c9497316fc76c7a14a 100644 (file)
@@ -524,7 +524,7 @@ pub fn set_id_same_memory(&mut self, id: AllocId, mem: M) {
 }
 
 #[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable)]
-pub struct Allocation<Tag=()> {
+pub struct Allocation<Tag=(),Extra=()> {
     /// The actual bytes of the allocation.
     /// Note that the bytes of a pointer represent the offset of the pointer
     pub bytes: Vec<u8>,
@@ -541,9 +541,11 @@ pub struct Allocation<Tag=()> {
     /// Also used by codegen to determine if a static should be put into mutable memory,
     /// which happens for `static mut` and `static` with interior mutability.
     pub mutability: Mutability,
+    /// Extra state for the machine.
+    pub extra: Extra,
 }
 
-impl<Tag> Allocation<Tag> {
+impl<Tag, Extra: Default> Allocation<Tag, Extra> {
     /// Creates a read-only allocation initialized by the given bytes
     pub fn from_bytes(slice: &[u8], align: Align) -> Self {
         let mut undef_mask = UndefMask::new(Size::ZERO);
@@ -554,6 +556,7 @@ pub fn from_bytes(slice: &[u8], align: Align) -> Self {
             undef_mask,
             align,
             mutability: Mutability::Immutable,
+            extra: Extra::default(),
         }
     }
 
@@ -569,6 +572,7 @@ pub fn undef(size: Size, align: Align) -> Self {
             undef_mask: UndefMask::new(size),
             align,
             mutability: Mutability::Mutable,
+            extra: Extra::default(),
         }
     }
 }
index 34fc81a495e249682fa9ccd9bf63c2ab47b731e5..62b5327ae4692237d33e0b3899dd54ae0c811c69 100644 (file)
@@ -2725,6 +2725,8 @@ pub struct ClosureOutlivesRequirement<'tcx> {
 #[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable)]
 pub enum ConstraintCategory {
     Return,
+    UseAsConst,
+    UseAsStatic,
     TypeAnnotation,
     Cast,
 
index 39c623de677d3872d05af3cce8a4039420645969..49f3717935493ef4bf99765864174bc347e3e23f 100644 (file)
@@ -2421,7 +2421,7 @@ fn sized_conditions(
             ty::Infer(ty::TyVar(_)) => Ambiguous,
 
             ty::UnnormalizedProjection(..)
-            | ty::Infer(ty::CanonicalTy(_))
+            | ty::Infer(ty::BoundTy(_))
             | ty::Infer(ty::FreshTy(_))
             | ty::Infer(ty::FreshIntTy(_))
             | ty::Infer(ty::FreshFloatTy(_)) => {
@@ -2506,7 +2506,7 @@ fn copy_clone_conditions(
             }
 
             ty::UnnormalizedProjection(..)
-            | ty::Infer(ty::CanonicalTy(_))
+            | ty::Infer(ty::BoundTy(_))
             | ty::Infer(ty::FreshTy(_))
             | ty::Infer(ty::FreshIntTy(_))
             | ty::Infer(ty::FreshFloatTy(_)) => {
@@ -2549,7 +2549,7 @@ fn constituent_types_for_ty(&self, t: Ty<'tcx>) -> Vec<Ty<'tcx>> {
             | ty::Param(..)
             | ty::Foreign(..)
             | ty::Projection(..)
-            | ty::Infer(ty::CanonicalTy(_))
+            | ty::Infer(ty::BoundTy(_))
             | ty::Infer(ty::TyVar(_))
             | ty::Infer(ty::FreshTy(_))
             | ty::Infer(ty::FreshIntTy(_))
index d886d5ed204139d22deaede765828a80f14cdad0..ed6e372fe7637d21427081b9994c1d10f970c44a 100644 (file)
@@ -217,7 +217,7 @@ pub fn sort_string(&self, tcx: TyCtxt<'a, 'gcx, 'lcx>) -> Cow<'static, str> {
             ty::Infer(ty::TyVar(_)) => "inferred type".into(),
             ty::Infer(ty::IntVar(_)) => "integral variable".into(),
             ty::Infer(ty::FloatVar(_)) => "floating-point variable".into(),
-            ty::Infer(ty::CanonicalTy(_)) |
+            ty::Infer(ty::BoundTy(_)) |
             ty::Infer(ty::FreshTy(_)) => "fresh type".into(),
             ty::Infer(ty::FreshIntTy(_)) => "fresh integral type".into(),
             ty::Infer(ty::FreshFloatTy(_)) => "fresh floating-point type".into(),
index 10a90dfc8a8cf936a56662820ca3300e8600c0be..a7b21688fbeb3ab1f0e3a4dc6db32a9da5318e39 100644 (file)
@@ -122,7 +122,7 @@ fn add_sty(&mut self, st: &ty::TyKind<'_>) {
                     ty::FreshTy(_) |
                     ty::FreshIntTy(_) |
                     ty::FreshFloatTy(_) |
-                    ty::CanonicalTy(_) => {
+                    ty::BoundTy(_) => {
                         self.add_flags(TypeFlags::HAS_CANONICAL_VARS);
                     }
 
index 760114a58388540eade32b9c83add67797936bc1..5602ce479c8dca75fc75d1ee44e1770796a4a725 100644 (file)
@@ -63,7 +63,7 @@
 
 use hir;
 
-pub use self::sty::{Binder, CanonicalVar, DebruijnIndex, INNERMOST};
+pub use self::sty::{Binder, BoundTy, BoundTyIndex, DebruijnIndex, INNERMOST};
 pub use self::sty::{FnSig, GenSig, PolyFnSig, PolyGenSig};
 pub use self::sty::{InferTy, ParamTy, ProjectionTy, ExistentialPredicate};
 pub use self::sty::{ClosureSubsts, GeneratorSubsts, UpvarSubsts, TypeAndMut};
index cc6e6b2861ecb8578cb48180132d475185793aa6..828915838701570a97b0a615d6f556c66ac579ea 100644 (file)
@@ -1165,7 +1165,7 @@ pub enum RegionKind {
     ReClosureBound(RegionVid),
 
     /// Canonicalized region, used only when preparing a trait query.
-    ReCanonical(CanonicalVar),
+    ReCanonical(BoundTyIndex),
 }
 
 impl<'tcx> serialize::UseSpecializedDecodable for Region<'tcx> {}
@@ -1217,14 +1217,22 @@ pub enum InferTy {
     FreshIntTy(u32),
     FreshFloatTy(u32),
 
-    /// Canonicalized type variable, used only when preparing a trait query.
-    CanonicalTy(CanonicalVar),
+    /// Bound type variable, used only when preparing a trait query.
+    BoundTy(BoundTy),
 }
 
 newtype_index! {
-    pub struct CanonicalVar { .. }
+    pub struct BoundTyIndex { .. }
 }
 
+#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, RustcEncodable, RustcDecodable)]
+pub struct BoundTy {
+    pub level: DebruijnIndex,
+    pub var: BoundTyIndex,
+}
+
+impl_stable_hash_for!(struct BoundTy { level, var });
+
 /// A `ProjectionPredicate` for an `ExistentialTraitRef`.
 #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, RustcEncodable, RustcDecodable)]
 pub struct ExistentialProjection<'tcx> {
@@ -1919,7 +1927,7 @@ pub fn is_trivially_sized(&self, tcx: TyCtxt<'_, '_, 'tcx>) -> bool {
 
             ty::Infer(ty::TyVar(_)) => false,
 
-            ty::Infer(ty::CanonicalTy(_)) |
+            ty::Infer(ty::BoundTy(_)) |
             ty::Infer(ty::FreshTy(_)) |
             ty::Infer(ty::FreshIntTy(_)) |
             ty::Infer(ty::FreshFloatTy(_)) =>
index 64cfba7df6e7d4df3379bcedafd58acf72aaef4c..02b5d36ecce6ea0dab9088b61e202d5438116a64 100644 (file)
@@ -12,7 +12,7 @@
 
 use hir::def_id::DefId;
 use infer::canonical::Canonical;
-use ty::{self, CanonicalVar, Lift, List, Ty, TyCtxt};
+use ty::{self, BoundTyIndex, Lift, List, Ty, TyCtxt};
 use ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
 
 use serialize::{self, Encodable, Encoder, Decodable, Decoder};
@@ -553,10 +553,10 @@ pub fn is_identity(&self) -> bool {
             return false;
         }
 
-        self.value.substs.iter().zip(CanonicalVar::new(0)..).all(|(kind, cvar)| {
+        self.value.substs.iter().zip(BoundTyIndex::new(0)..).all(|(kind, cvar)| {
             match kind.unpack() {
                 UnpackedKind::Type(ty) => match ty.sty {
-                    ty::Infer(ty::CanonicalTy(cvar1)) => cvar == cvar1,
+                    ty::Infer(ty::BoundTy(ref b)) => cvar == b.var,
                     _ => false,
                 },
 
index bfa2203cc04b24507081140b582166b86c9e03b2..709b844526529dbbcf4fe6c6e9f196481d986075 100644 (file)
@@ -984,7 +984,7 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
                     ty::TyVar(_) => write!(f, "_"),
                     ty::IntVar(_) => write!(f, "{}", "{integer}"),
                     ty::FloatVar(_) => write!(f, "{}", "{float}"),
-                    ty::CanonicalTy(_) => write!(f, "_"),
+                    ty::BoundTy(_) => write!(f, "_"),
                     ty::FreshTy(v) => write!(f, "FreshTy({})", v),
                     ty::FreshIntTy(v) => write!(f, "FreshIntTy({})", v),
                     ty::FreshFloatTy(v) => write!(f, "FreshFloatTy({})", v)
@@ -996,7 +996,7 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
                 ty::TyVar(ref v) => write!(f, "{:?}", v),
                 ty::IntVar(ref v) => write!(f, "{:?}", v),
                 ty::FloatVar(ref v) => write!(f, "{:?}", v),
-                ty::CanonicalTy(v) => write!(f, "?{:?}", v.index()),
+                ty::BoundTy(v) => write!(f, "?{:?}", v.var.index()),
                 ty::FreshTy(v) => write!(f, "FreshTy({:?})", v),
                 ty::FreshIntTy(v) => write!(f, "FreshIntTy({:?})", v),
                 ty::FreshFloatTy(v) => write!(f, "FreshFloatTy({:?})", v)
index 66f2e9291df8e3350c69a27130f17ef1dfd79ddd..b6bb130d3e27f22615d5a73a3e90e23e55e0fe5e 100644 (file)
@@ -9,19 +9,22 @@
 // except according to those terms.
 
 use borrow_check::nll::explain_borrow::BorrowExplanation;
+use borrow_check::nll::region_infer::{RegionName, RegionNameSource};
 use borrow_check::prefixes::IsPrefixOf;
 use borrow_check::WriteKind;
 use rustc::hir;
 use rustc::hir::def_id::DefId;
 use rustc::middle::region::ScopeTree;
 use rustc::mir::{
-    self, AggregateKind, BindingForm, BorrowKind, ClearCrossCrate, Constant, Field, Local,
-    LocalDecl, LocalKind, Location, Operand, Place, PlaceProjection, ProjectionElem,
-    Rvalue, Statement, StatementKind, TerminatorKind, VarBindingForm,
+    self, AggregateKind, BindingForm, BorrowKind, ClearCrossCrate, Constant,
+    ConstraintCategory, Field, Local, LocalDecl, LocalKind, Location, Operand,
+    Place, PlaceProjection, ProjectionElem, Rvalue, Statement, StatementKind,
+    TerminatorKind, VarBindingForm,
 };
 use rustc::ty::{self, DefIdTree};
 use rustc::util::ppaux::with_highlight_region_for_bound_region;
 use rustc_data_structures::fx::FxHashSet;
+use rustc_data_structures::indexed_vec::Idx;
 use rustc_data_structures::sync::Lrc;
 use rustc_errors::{Applicability, DiagnosticBuilder};
 use syntax_pos::Span;
@@ -29,7 +32,6 @@
 use super::borrow_set::BorrowData;
 use super::{Context, MirBorrowckCtxt};
 use super::{InitializationRequiringAction, PrefixSet};
-
 use dataflow::drop_flag_effects;
 use dataflow::move_paths::indexes::MoveOutIndex;
 use dataflow::move_paths::MovePathIndex;
@@ -581,26 +583,81 @@ pub(super) fn report_borrowed_value_does_not_live_long_enough(
             }
         }
 
-        let err = match &self.describe_place(&borrow.borrowed_place) {
-            Some(_) if self.is_place_thread_local(root_place) => {
+        let place_desc = self.describe_place(&borrow.borrowed_place);
+
+        let kind_place = kind.filter(|_| place_desc.is_some()).map(|k| (k, place_span.0));
+        let explanation = self.explain_why_borrow_contains_point(context, &borrow, kind_place);
+
+        let err = match (place_desc, explanation) {
+            (Some(_), _) if self.is_place_thread_local(root_place) => {
                 self.report_thread_local_value_does_not_live_long_enough(drop_span, borrow_span)
             }
-            Some(name) => self.report_local_value_does_not_live_long_enough(
+            // If the outlives constraint comes from inside the closure,
+            // for example:
+            //
+            // let x = 0;
+            // let y = &x;
+            // Box::new(|| y) as Box<Fn() -> &'static i32>
+            //
+            // then just use the normal error. The closure isn't escaping
+            // and `move` will not help here.
+            (
+                Some(ref name),
+                BorrowExplanation::MustBeValidFor {
+                    category: category @ ConstraintCategory::Return,
+                    from_closure: false,
+                    ref region_name,
+                    span,
+                    ..
+                },
+            )
+            | (
+                Some(ref name),
+                BorrowExplanation::MustBeValidFor {
+                    category: category @ ConstraintCategory::CallArgument,
+                    from_closure: false,
+                    ref region_name,
+                    span,
+                    ..
+                },
+            ) if borrow_spans.for_closure() => self.report_escaping_closure_capture(
+                borrow_spans.args_or_use(),
+                borrow_span,
+                region_name,
+                category,
+                span,
+                &format!("`{}`", name),
+            ),
+            (
+                ref name,
+                BorrowExplanation::MustBeValidFor {
+                    category: ConstraintCategory::Assignment,
+                    from_closure: false,
+                    region_name: RegionName {
+                        source: RegionNameSource::AnonRegionFromUpvar(upvar_span, ref upvar_name),
+                        ..
+                    },
+                    span,
+                    ..
+                },
+            ) => self.report_escaping_data(borrow_span, name, upvar_span, upvar_name, span),
+            (Some(name), explanation) => self.report_local_value_does_not_live_long_enough(
                 context,
-                name,
+                &name,
                 &scope_tree,
                 &borrow,
                 drop_span,
                 borrow_spans,
-                kind.map(|k| (k, place_span.0)),
+                explanation,
             ),
-            None => self.report_temporary_value_does_not_live_long_enough(
+            (None, explanation) => self.report_temporary_value_does_not_live_long_enough(
                 context,
                 &scope_tree,
                 &borrow,
                 drop_span,
                 borrow_spans,
                 proper_span,
+                explanation,
             ),
         };
 
@@ -615,7 +672,7 @@ fn report_local_value_does_not_live_long_enough(
         borrow: &BorrowData<'tcx>,
         drop_span: Span,
         borrow_spans: UseSpans,
-        kind_place: Option<(WriteKind, &Place<'tcx>)>,
+        explanation: BorrowExplanation,
     ) -> DiagnosticBuilder<'cx> {
         debug!(
             "report_local_value_does_not_live_long_enough(\
@@ -625,13 +682,27 @@ fn report_local_value_does_not_live_long_enough(
         );
 
         let borrow_span = borrow_spans.var_or_use();
+        if let BorrowExplanation::MustBeValidFor {
+            category: ConstraintCategory::Return,
+            span,
+            ref opt_place_desc,
+            from_closure: false,
+            ..
+        } = explanation {
+            return self.report_cannot_return_reference_to_local(
+                borrow,
+                borrow_span,
+                span,
+                opt_place_desc.as_ref(),
+            );
+        }
+
         let mut err = self.infcx.tcx.path_does_not_live_long_enough(
             borrow_span,
             &format!("`{}`", name),
             Origin::Mir,
         );
 
-        let explanation = self.explain_why_borrow_contains_point(context, borrow, kind_place);
         if let Some(annotation) = self.annotate_argument_and_return_for_borrow(borrow) {
             let region_name = annotation.emit(&mut err);
 
@@ -665,7 +736,7 @@ fn report_local_value_does_not_live_long_enough(
                 );
             }
 
-            if let BorrowExplanation::MustBeValidFor(..) = explanation {
+            if let BorrowExplanation::MustBeValidFor { .. } = explanation {
             } else {
                 explanation.add_explanation_to_diagnostic(self.infcx.tcx, self.mir, &mut err, "");
             }
@@ -693,7 +764,7 @@ fn report_local_value_does_not_live_long_enough(
         err
     }
 
-    pub(super) fn report_borrow_conflicts_with_destructor(
+    fn report_borrow_conflicts_with_destructor(
         &mut self,
         context: Context,
         borrow: &BorrowData<'tcx>,
@@ -785,6 +856,7 @@ fn report_temporary_value_does_not_live_long_enough(
         drop_span: Span,
         borrow_spans: UseSpans,
         proper_span: Span,
+        explanation: BorrowExplanation,
     ) -> DiagnosticBuilder<'cx> {
         debug!(
             "report_temporary_value_does_not_live_long_enough(\
@@ -793,6 +865,20 @@ fn report_temporary_value_does_not_live_long_enough(
             context, scope_tree, borrow, drop_span, proper_span
         );
 
+        if let BorrowExplanation::MustBeValidFor {
+            category: ConstraintCategory::Return,
+            span,
+            from_closure: false,
+            ..
+        } = explanation {
+            return self.report_cannot_return_reference_to_local(
+                borrow,
+                proper_span,
+                span,
+                None,
+            );
+        }
+
         let tcx = self.infcx.tcx;
         let mut err = tcx.temporary_value_borrowed_for_too_long(proper_span, Origin::Mir);
         err.span_label(
@@ -804,7 +890,6 @@ fn report_temporary_value_does_not_live_long_enough(
             "temporary value is freed at the end of this statement",
         );
 
-        let explanation = self.explain_why_borrow_contains_point(context, borrow, None);
         match explanation {
             BorrowExplanation::UsedLater(..)
             | BorrowExplanation::UsedLaterInLoop(..)
@@ -830,6 +915,189 @@ fn report_temporary_value_does_not_live_long_enough(
         err
     }
 
+    fn report_cannot_return_reference_to_local(
+        &self,
+        borrow: &BorrowData<'tcx>,
+        borrow_span: Span,
+        return_span: Span,
+        opt_place_desc: Option<&String>,
+    ) -> DiagnosticBuilder<'cx> {
+        let tcx = self.infcx.tcx;
+
+        // FIXME use a better heuristic than Spans
+        let reference_desc = if return_span == self.mir.source_info(borrow.reserve_location).span {
+            "reference to"
+        } else {
+            "value referencing"
+        };
+
+        let (place_desc, note) = if let Some(place_desc) = opt_place_desc {
+            let local_kind = match borrow.borrowed_place {
+                Place::Local(local) => {
+                    match self.mir.local_kind(local) {
+                        LocalKind::ReturnPointer
+                        | LocalKind::Temp => bug!("temporary or return pointer with a name"),
+                        LocalKind::Var => "local variable ",
+                        LocalKind::Arg
+                        if !self.mir.upvar_decls.is_empty()
+                            && local == Local::new(1) => {
+                            "variable captured by `move` "
+                        }
+                        LocalKind::Arg => {
+                            "function parameter "
+                        }
+                    }
+                }
+                _ => "local data ",
+            };
+            (
+                format!("{}`{}`", local_kind, place_desc),
+                format!("`{}` is borrowed here", place_desc),
+            )
+        } else {
+            let root_place = self.prefixes(&borrow.borrowed_place, PrefixSet::All)
+                .last()
+                .unwrap();
+            let local = if let Place::Local(local) = *root_place {
+                local
+            } else {
+                bug!("report_cannot_return_reference_to_local: not a local")
+            };
+            match self.mir.local_kind(local) {
+                LocalKind::ReturnPointer | LocalKind::Temp => {
+                    (
+                        "temporary value".to_string(),
+                        "temporary value created here".to_string(),
+                    )
+                }
+                LocalKind::Arg => {
+                    (
+                        "function parameter".to_string(),
+                        "function parameter borrowed here".to_string(),
+                    )
+                },
+                LocalKind::Var => bug!("local variable without a name"),
+            }
+        };
+
+        let mut err = tcx.cannot_return_reference_to_local(
+            return_span,
+            reference_desc,
+            &place_desc,
+            Origin::Mir,
+        );
+
+        if return_span != borrow_span {
+            err.span_label(borrow_span, note);
+        }
+
+        err
+    }
+
+    fn report_escaping_closure_capture(
+        &mut self,
+        args_span: Span,
+        var_span: Span,
+        fr_name: &RegionName,
+        category: ConstraintCategory,
+        constraint_span: Span,
+        captured_var: &str,
+    ) -> DiagnosticBuilder<'cx> {
+        let tcx = self.infcx.tcx;
+
+        let mut err = tcx.cannot_capture_in_long_lived_closure(
+            args_span,
+            captured_var,
+            var_span,
+          Origin::Mir,
+        );
+
+        let suggestion = match tcx.sess.source_map().span_to_snippet(args_span) {
+            Ok(string) => format!("move {}", string),
+            Err(_) => "move |<args>| <body>".to_string()
+        };
+
+        err.span_suggestion_with_applicability(
+            args_span,
+            &format!("to force the closure to take ownership of {} (and any \
+                      other referenced variables), use the `move` keyword",
+                      captured_var),
+            suggestion,
+            Applicability::MachineApplicable,
+        );
+
+        match category {
+            ConstraintCategory::Return => {
+                err.span_note(constraint_span, &format!("closure is returned here"));
+            }
+            ConstraintCategory::CallArgument => {
+                fr_name.highlight_region_name(&mut err);
+                err.span_note(
+                    constraint_span,
+                    &format!("function requires argument type to outlive `{}`", fr_name),
+                );
+            }
+            _ => bug!("report_escaping_closure_capture called with unexpected constraint \
+                       category: `{:?}`", category),
+        }
+        err
+    }
+
+    fn report_escaping_data(
+        &mut self,
+        borrow_span: Span,
+        name: &Option<String>,
+        upvar_span: Span,
+        upvar_name: &str,
+        escape_span: Span,
+    ) -> DiagnosticBuilder<'cx> {
+        let tcx = self.infcx.tcx;
+
+        let escapes_from = if tcx.is_closure(self.mir_def_id) {
+            let tables = tcx.typeck_tables_of(self.mir_def_id);
+            let mir_hir_id = tcx.hir.def_index_to_hir_id(self.mir_def_id.index);
+            match tables.node_id_to_type(mir_hir_id).sty {
+                ty::Closure(..) => "closure",
+                ty::Generator(..) => "generator",
+                _ => bug!("Closure body doesn't have a closure or generator type"),
+            }
+        } else {
+            "function"
+        };
+
+        let mut err = tcx.borrowed_data_escapes_closure(escape_span, escapes_from, Origin::Mir);
+
+        err.span_label(
+            upvar_span,
+            format!(
+                "`{}` is declared here, outside of the {} body",
+                upvar_name, escapes_from
+            ),
+        );
+
+        err.span_label(
+            borrow_span,
+            format!(
+                "borrow is only valid in the {} body",
+                escapes_from
+            ),
+        );
+
+        if let Some(name) = name {
+            err.span_label(
+                escape_span,
+                format!("reference to `{}` escapes the {} body here", name, escapes_from),
+            );
+        } else {
+            err.span_label(
+                escape_span,
+                format!("reference escapes the {} body here", escapes_from),
+            );
+        }
+
+        err
+    }
+
     fn get_moved_indexes(&mut self, context: Context, mpi: MovePathIndex) -> Vec<MoveSite> {
         let mir = self.mir;
 
index a0f832c54493430ff52b70f6d362e2457b4f73cb..2bf531d1d3e56660f45b6138024cab33cb14c70e 100644 (file)
 
 use borrow_check::borrow_set::BorrowData;
 use borrow_check::error_reporting::UseSpans;
-use borrow_check::nll::region_infer::Cause;
+use borrow_check::nll::ConstraintDescription;
+use borrow_check::nll::region_infer::{Cause, RegionName};
 use borrow_check::{Context, MirBorrowckCtxt, WriteKind};
-use rustc::ty::{self, Region, TyCtxt};
+use rustc::ty::{self, TyCtxt};
 use rustc::mir::{
-    CastKind, FakeReadCause, Local, Location, Mir, Operand, Place, Projection, ProjectionElem,
-    Rvalue, Statement, StatementKind, TerminatorKind
+    CastKind, ConstraintCategory, FakeReadCause, Local, Location, Mir, Operand,
+    Place, Projection, ProjectionElem, Rvalue, Statement, StatementKind,
+    TerminatorKind
 };
 use rustc_errors::DiagnosticBuilder;
 use syntax_pos::Span;
 
 mod find_use;
 
-pub(in borrow_check) enum BorrowExplanation<'tcx> {
+pub(in borrow_check) enum BorrowExplanation {
     UsedLater(LaterUseKind, Span),
     UsedLaterInLoop(LaterUseKind, Span),
     UsedLaterWhenDropped {
@@ -30,7 +32,13 @@ pub(in borrow_check) enum BorrowExplanation<'tcx> {
         dropped_local: Local,
         should_note_order: bool,
     },
-    MustBeValidFor(Region<'tcx>),
+    MustBeValidFor {
+        category: ConstraintCategory,
+        from_closure: bool,
+        span: Span,
+        region_name: RegionName,
+        opt_place_desc: Option<String>,
+    },
     Unexplained,
 }
 
@@ -43,8 +51,8 @@ pub(in borrow_check) enum LaterUseKind {
     Other,
 }
 
-impl<'tcx> BorrowExplanation<'tcx> {
-    pub(in borrow_check) fn add_explanation_to_diagnostic<'cx, 'gcx>(
+impl BorrowExplanation {
+    pub(in borrow_check) fn add_explanation_to_diagnostic<'cx, 'gcx, 'tcx>(
         &self,
         tcx: TyCtxt<'cx, 'gcx, 'tcx>,
         mir: &Mir<'tcx>,
@@ -142,15 +150,27 @@ pub(in borrow_check) fn add_explanation_to_diagnostic<'cx, 'gcx>(
                         }
                     }
                 }
-            }
-
-            BorrowExplanation::MustBeValidFor(region) => {
-                tcx.note_and_explain_free_region(
-                    err,
-                    &format!("{}{}", borrow_desc, "borrowed value must be valid for "),
-                    region,
-                    "...",
-                );
+            },
+            BorrowExplanation::MustBeValidFor {
+                category,
+                span,
+                ref region_name,
+                ref opt_place_desc,
+                from_closure: _,
+            } => {
+                region_name.highlight_region_name(err);
+
+                if let Some(desc) = opt_place_desc {
+                    err.span_label(span, format!(
+                        "{}requires that `{}` is borrowed for `{}`",
+                        category.description(), desc, region_name,
+                    ));
+                } else {
+                    err.span_label(span, format!(
+                        "{}requires that {}borrow lasts for `{}`",
+                        category.description(), borrow_desc, region_name,
+                    ));
+                };
             },
             _ => {},
         }
@@ -176,7 +196,7 @@ pub(in borrow_check) fn explain_why_borrow_contains_point(
         context: Context,
         borrow: &BorrowData<'tcx>,
         kind_place: Option<(WriteKind, &Place<'tcx>)>,
-    ) -> BorrowExplanation<'tcx> {
+    ) -> BorrowExplanation {
         debug!(
             "explain_why_borrow_contains_point(context={:?}, borrow={:?}, kind_place={:?})",
             context, borrow, kind_place
@@ -241,11 +261,27 @@ pub(in borrow_check) fn explain_why_borrow_contains_point(
                  }
             }
 
-            None => if let Some(region) = regioncx.to_error_region(region_sub) {
-                BorrowExplanation::MustBeValidFor(region)
+            None => if let Some(region) = regioncx.to_error_region_vid(borrow_region_vid) {
+                let (category, from_closure, span, region_name) = self
+                    .nonlexical_regioncx
+                    .free_region_constraint_info(
+                        self.mir,
+                        self.mir_def_id,
+                        self.infcx,
+                        borrow_region_vid,
+                        region,
+                    );
+                let opt_place_desc = self.describe_place(&borrow.borrowed_place);
+                BorrowExplanation::MustBeValidFor {
+                    category,
+                    from_closure,
+                    span,
+                    region_name,
+                    opt_place_desc,
+                }
             } else {
                 BorrowExplanation::Unexplained
-            },
+            }
         }
     }
 
index e538524f33a10820de6cd5aaa913028c8daf6230..8fc54b6ff92a3e2b0099aade09ff191e0fe7f6b2 100644 (file)
@@ -371,3 +371,7 @@ fn to_region_vid(self) -> RegionVid {
         self
     }
 }
+
+crate trait ConstraintDescription {
+    fn description(&self) -> &'static str;
+}
index 5ff50c606d641c6e17e143a1ec3f8650f1dbe091..ccb44c670f72fd9873469655ddbacfbcdd2b3a67 100644 (file)
@@ -8,11 +8,12 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+use borrow_check::nll::ConstraintDescription;
 use borrow_check::nll::constraints::{OutlivesConstraint};
 use borrow_check::nll::region_infer::RegionInferenceContext;
-use borrow_check::nll::region_infer::error_reporting::region_name::RegionNameSource;
 use borrow_check::nll::type_check::Locations;
 use borrow_check::nll::universal_regions::DefiningTy;
+use util::borrowck_errors::{BorrowckErrors, Origin};
 use rustc::hir::def_id::DefId;
 use rustc::infer::error_reporting::nice_region_error::NiceRegionError;
 use rustc::infer::InferCtxt;
 mod region_name;
 mod var_name;
 
-use self::region_name::RegionName;
-
-trait ConstraintDescription {
-    fn description(&self) -> &'static str;
-}
+crate use self::region_name::{RegionName, RegionNameSource};
 
 impl ConstraintDescription for ConstraintCategory {
     fn description(&self) -> &'static str {
@@ -40,6 +37,8 @@ fn description(&self) -> &'static str {
         match self {
             ConstraintCategory::Assignment => "assignment ",
             ConstraintCategory::Return => "returning this value ",
+            ConstraintCategory::UseAsConst => "using this value as a constant ",
+            ConstraintCategory::UseAsStatic => "using this value as a static ",
             ConstraintCategory::Cast => "cast ",
             ConstraintCategory::CallArgument => "argument ",
             ConstraintCategory::TypeAnnotation => "type annotation ",
@@ -73,7 +72,7 @@ fn best_blame_constraint(
         mir: &Mir<'tcx>,
         from_region: RegionVid,
         target_test: impl Fn(RegionVid) -> bool,
-    ) -> (ConstraintCategory, Span, RegionVid) {
+    ) -> (ConstraintCategory, bool, Span) {
         debug!("best_blame_constraint(from_region={:?})", from_region);
 
         // Find all paths
@@ -93,13 +92,13 @@ fn best_blame_constraint(
         );
 
         // Classify each of the constraints along the path.
-        let mut categorized_path: Vec<(ConstraintCategory, Span)> = path
+        let mut categorized_path: Vec<(ConstraintCategory, bool, Span)> = path
             .iter()
             .map(|constraint| {
                 if constraint.category == ConstraintCategory::ClosureBounds {
                     self.retrieve_closure_constraint_info(mir, &constraint)
                 } else {
-                    (constraint.category, constraint.locations.span(mir))
+                    (constraint.category, false, constraint.locations.span(mir))
                 }
             })
             .collect();
@@ -138,12 +137,13 @@ fn best_blame_constraint(
                 | ConstraintCategory::Boring
                 | ConstraintCategory::BoringNoLocation
                 | ConstraintCategory::Internal => false,
+                ConstraintCategory::TypeAnnotation
+                | ConstraintCategory::Return => true,
                 _ => constraint_sup_scc != target_scc,
             }
         });
         if let Some(i) = best_choice {
-            let (category, span) = categorized_path[i];
-            return (category, span, target_region);
+            return categorized_path[i]
         }
 
         // If that search fails, that is.. unusual. Maybe everything
@@ -151,11 +151,9 @@ fn best_blame_constraint(
         // appears to be the most interesting point to report to the
         // user via an even more ad-hoc guess.
         categorized_path.sort_by(|p0, p1| p0.0.cmp(&p1.0));
-        debug!("best_blame_constraint: sorted_path={:#?}", categorized_path);
+        debug!("`: sorted_path={:#?}", categorized_path);
 
-        let &(category, span) = categorized_path.first().unwrap();
-
-        (category, span, target_region)
+        *categorized_path.first().unwrap()
     }
 
     /// Walks the graph of constraints (where `'a: 'b` is considered
@@ -242,7 +240,7 @@ pub(super) fn report_error(
     ) {
         debug!("report_error(fr={:?}, outlived_fr={:?})", fr, outlived_fr);
 
-        let (category, span, _) = self.best_blame_constraint(
+        let (category, _, span) = self.best_blame_constraint(
             mir,
             fr,
             |r| r == outlived_fr
@@ -373,21 +371,25 @@ fn report_escaping_data_error(
         let outlived_fr_name_and_span =
             self.get_var_name_and_span_for_region(infcx.tcx, mir, outlived_fr);
 
-        let escapes_from = if infcx.tcx.is_closure(mir_def_id) { "closure" } else { "function" };
+        let escapes_from = match self.universal_regions.defining_ty {
+            DefiningTy::Closure(..) => "closure",
+            DefiningTy::Generator(..) => "generator",
+            DefiningTy::FnDef(..) => "function",
+            DefiningTy::Const(..) => "const"
+        };
 
         // Revert to the normal error in these cases.
         // Assignments aren't "escapes" in function items.
         if (fr_name_and_span.is_none() && outlived_fr_name_and_span.is_none())
             || (category == ConstraintCategory::Assignment && escapes_from == "function")
+            || escapes_from == "const"
         {
             return self.report_general_error(mir, infcx, mir_def_id,
                                              fr, true, outlived_fr, false,
                                              category, span, errors_buffer);
         }
 
-        let mut diag = infcx.tcx.sess.struct_span_err(
-            span, &format!("borrowed data escapes outside of {}", escapes_from),
-        );
+        let mut diag = infcx.tcx.borrowed_data_escapes_closure(span, escapes_from, Origin::Mir);
 
         if let Some((Some(outlived_fr_name), outlived_fr_span)) = outlived_fr_name_and_span {
             diag.span_label(
@@ -571,6 +573,24 @@ fn add_static_impl_trait_suggestion(
         }
     }
 
+    crate fn free_region_constraint_info(
+        &self,
+        mir: &Mir<'tcx>,
+        mir_def_id: DefId,
+        infcx: &InferCtxt<'_, '_, 'tcx>,
+        borrow_region: RegionVid,
+        outlived_region: RegionVid,
+    ) -> (ConstraintCategory, bool, Span, RegionName) {
+        let (category, from_closure, span) = self.best_blame_constraint(
+            mir,
+            borrow_region,
+            |r| r == outlived_region
+        );
+        let outlived_fr_name = self.give_region_a_name(
+            infcx, mir, mir_def_id, outlived_region, &mut 1);
+        (category, from_closure, span, outlived_fr_name)
+    }
+
     // Finds some region R such that `fr1: R` and `R` is live at
     // `elem`.
     crate fn find_sub_region_live_at(&self, fr1: RegionVid, elem: Location) -> RegionVid {
@@ -589,7 +609,7 @@ fn add_static_impl_trait_suggestion(
         fr1: RegionVid,
         fr2: RegionVid,
     ) -> (ConstraintCategory, Span) {
-        let (category, span, _) = self.best_blame_constraint(mir, fr1, |r| r == fr2);
+        let (category, _, span) = self.best_blame_constraint(mir, fr1, |r| r == fr2);
         (category, span)
     }
 
@@ -597,16 +617,18 @@ fn retrieve_closure_constraint_info(
         &self,
         mir: &Mir<'tcx>,
         constraint: &OutlivesConstraint
-    ) -> (ConstraintCategory, Span) {
+    ) -> (ConstraintCategory, bool, Span) {
         let loc = match constraint.locations {
-            Locations::All(span) => return (constraint.category, span),
+            Locations::All(span) => return (constraint.category, false, span),
             Locations::Single(loc) => loc,
         };
 
         let opt_span_category = self
             .closure_bounds_mapping[&loc]
             .get(&(constraint.sup, constraint.sub));
-        *opt_span_category.unwrap_or(&(constraint.category, mir.source_info(loc).span))
+        opt_span_category
+            .map(|&(category, span)| (category, true, span))
+            .unwrap_or((constraint.category, false, mir.source_info(loc).span))
     }
 
     /// Returns `true` if a closure is inferred to be an `FnMut` closure.
index 2c84a9e014e93ffcf6c71925fb3a50cc005dbc7e..5ed25406da4e67f8a547c538f73b672aa2fffee5 100644 (file)
@@ -35,6 +35,7 @@
 
 mod dump_mir;
 mod error_reporting;
+crate use self::error_reporting::{RegionName, RegionNameSource};
 mod graphviz;
 pub mod values;
 use self::values::{LivenessValues, RegionValueElements, RegionValues};
@@ -669,13 +670,19 @@ fn check_type_tests<'gcx>(
     /// to find a good name from that. Returns `None` if we can't find
     /// one (e.g., this is just some random part of the CFG).
     pub fn to_error_region(&self, r: RegionVid) -> Option<ty::Region<'tcx>> {
+        self.to_error_region_vid(r).and_then(|r| self.definitions[r].external_name)
+    }
+
+    /// Returns the [RegionVid] corresponding to the region returned by
+    /// `to_error_region`.
+    pub fn to_error_region_vid(&self, r: RegionVid) -> Option<RegionVid> {
         if self.universal_regions.is_universal_region(r) {
-            return self.definitions[r].external_name;
+            Some(r)
         } else {
             let r_scc = self.constraint_sccs.scc(r);
             let upper_bound = self.universal_upper_bound(r);
             if self.scc_values.contains(r_scc, upper_bound) {
-                self.to_error_region(upper_bound)
+                self.to_error_region_vid(upper_bound)
             } else {
                 None
             }
index ed8ca9a637f29acb64c49580702e2e55814b9c6c..6d152fc87bd33bbda96a5bf8e8de204ad5a8c2c1 100644 (file)
@@ -23,7 +23,7 @@
 use borrow_check::nll::type_check::free_region_relations::{
     CreateResult, UniversalRegionRelations,
 };
-use borrow_check::nll::universal_regions::UniversalRegions;
+use borrow_check::nll::universal_regions::{DefiningTy, UniversalRegions};
 use borrow_check::nll::ToRegionVid;
 use dataflow::move_paths::MoveData;
 use dataflow::FlowAtLocation;
@@ -1209,7 +1209,21 @@ fn check_stmt(&mut self, mir: &Mir<'tcx>, stmt: &Statement<'tcx>, location: Loca
                 // of lowering. Assignments to other sorts of places *are* interesting
                 // though.
                 let category = match *place {
-                    Place::Local(RETURN_PLACE) => ConstraintCategory::Return,
+                    Place::Local(RETURN_PLACE) => if let Some(BorrowCheckContext {
+                        universal_regions: UniversalRegions {
+                            defining_ty: DefiningTy::Const(def_id, _),
+                            ..
+                        },
+                        ..
+                    }) = self.borrowck_context {
+                        if tcx.is_static(*def_id).is_some() {
+                            ConstraintCategory::UseAsStatic
+                        } else {
+                            ConstraintCategory::UseAsConst
+                        }
+                    } else {
+                        ConstraintCategory::Return
+                    }
                     Place::Local(l) if !mir.local_decls[l].is_user_variable.is_some() => {
                         ConstraintCategory::Boring
                     }
@@ -1391,6 +1405,7 @@ fn check_terminator(
                 ref func,
                 ref args,
                 ref destination,
+                from_hir_call,
                 ..
             } => {
                 let func_ty = func.ty(mir, tcx);
@@ -1435,7 +1450,7 @@ fn check_terminator(
                     }
                 }
 
-                self.check_call_inputs(mir, term, &sig, args, term_location);
+                self.check_call_inputs(mir, term, &sig, args, term_location, from_hir_call);
             }
             TerminatorKind::Assert {
                 ref cond, ref msg, ..
@@ -1493,7 +1508,23 @@ fn check_call_dest(
             Some((ref dest, _target_block)) => {
                 let dest_ty = dest.ty(mir, tcx).to_ty(tcx);
                 let category = match *dest {
-                    Place::Local(RETURN_PLACE) => ConstraintCategory::Return,
+                    Place::Local(RETURN_PLACE) => {
+                        if let Some(BorrowCheckContext {
+                            universal_regions: UniversalRegions {
+                                defining_ty: DefiningTy::Const(def_id, _),
+                                ..
+                            },
+                            ..
+                        }) = self.borrowck_context {
+                            if tcx.is_static(*def_id).is_some() {
+                                ConstraintCategory::UseAsStatic
+                            } else {
+                                ConstraintCategory::UseAsConst
+                            }
+                        } else {
+                            ConstraintCategory::Return
+                        }
+                    },
                     Place::Local(l) if !mir.local_decls[l].is_user_variable.is_some() => {
                         ConstraintCategory::Boring
                     }
@@ -1538,6 +1569,7 @@ fn check_call_inputs(
         sig: &ty::FnSig<'tcx>,
         args: &[Operand<'tcx>],
         term_location: Location,
+        from_hir_call: bool,
     ) {
         debug!("check_call_inputs({:?}, {:?})", sig, args);
         if args.len() < sig.inputs().len() || (args.len() > sig.inputs().len() && !sig.variadic) {
@@ -1545,11 +1577,16 @@ fn check_call_inputs(
         }
         for (n, (fn_arg, op_arg)) in sig.inputs().iter().zip(args).enumerate() {
             let op_arg_ty = op_arg.ty(mir, self.tcx());
+            let category = if from_hir_call {
+                ConstraintCategory::CallArgument
+            } else {
+                ConstraintCategory::Boring
+            };
             if let Err(terr) = self.sub_types(
                 op_arg_ty,
                 fn_arg,
                 term_location.to_locations(),
-                ConstraintCategory::CallArgument,
+                category,
             ) {
                 span_mirbug!(
                     self,
index 2cfd058831f054da31b36d3ac8b66ee24df658cc..bc917140bbd679a7907d8ffdc54b63ba21499bc7 100644 (file)
@@ -19,8 +19,8 @@
 use rustc::hir::{self, def_id::DefId};
 use rustc::mir::interpret::ConstEvalErr;
 use rustc::mir;
-use rustc::ty::{self, TyCtxt, Instance, query::TyCtxtAt};
-use rustc::ty::layout::{self, LayoutOf, TyLayout};
+use rustc::ty::{self, Ty, TyCtxt, Instance, query::TyCtxtAt};
+use rustc::ty::layout::{self, Size, LayoutOf, TyLayout};
 use rustc::ty::subst::Subst;
 use rustc_data_structures::indexed_vec::IndexVec;
 use rustc_data_structures::fx::FxHashMap;
 use syntax::ast::Mutability;
 use syntax::source_map::{Span, DUMMY_SP};
 
-use rustc::mir::interpret::{
-    EvalResult, EvalError, EvalErrorKind, GlobalId,
-    Scalar, Allocation, AllocId, ConstValue,
-};
 use interpret::{self,
-    PlaceTy, MemPlace, OpTy, Operand, Value,
-    EvalContext, StackPopCleanup, MemoryKind,
+    PlaceTy, MemPlace, OpTy, Operand, Value, Pointer, Scalar, ConstValue,
+    EvalResult, EvalError, EvalErrorKind, GlobalId, EvalContext, StackPopCleanup,
+    Allocation, AllocId, MemoryKind,
     snapshot,
 };
 
@@ -53,7 +50,7 @@ pub fn mk_borrowck_eval_cx<'a, 'mir, 'tcx>(
 ) -> EvalResult<'tcx, CompileTimeEvalContext<'a, 'mir, 'tcx>> {
     debug!("mk_borrowck_eval_cx: {:?}", instance);
     let param_env = tcx.param_env(instance.def_id());
-    let mut ecx = EvalContext::new(tcx.at(span), param_env, CompileTimeInterpreter::new(), ());
+    let mut ecx = EvalContext::new(tcx.at(span), param_env, CompileTimeInterpreter::new());
     // insert a stack frame so any queries have the correct substs
     // cannot use `push_stack_frame`; if we do `const_prop` explodes
     ecx.stack.push(interpret::Frame {
@@ -76,7 +73,7 @@ pub fn mk_eval_cx<'a, 'tcx>(
 ) -> EvalResult<'tcx, CompileTimeEvalContext<'a, 'tcx, 'tcx>> {
     debug!("mk_eval_cx: {:?}, {:?}", instance, param_env);
     let span = tcx.def_span(instance.def_id());
-    let mut ecx = EvalContext::new(tcx.at(span), param_env, CompileTimeInterpreter::new(), ());
+    let mut ecx = EvalContext::new(tcx.at(span), param_env, CompileTimeInterpreter::new());
     let mir = ecx.load_mir(instance.def)?;
     // insert a stack frame so any queries have the correct substs
     ecx.push_stack_frame(
@@ -155,7 +152,7 @@ fn eval_body_and_ecx<'a, 'mir, 'tcx>(
     // and try improving it down the road when more information is available
     let span = tcx.def_span(cid.instance.def_id());
     let span = mir.map(|mir| mir.span).unwrap_or(span);
-    let mut ecx = EvalContext::new(tcx.at(span), param_env, CompileTimeInterpreter::new(), ());
+    let mut ecx = EvalContext::new(tcx.at(span), param_env, CompileTimeInterpreter::new());
     let r = eval_body_using_ecx(&mut ecx, cid, mir, param_env);
     (r, ecx)
 }
@@ -333,16 +330,25 @@ fn get_mut_or<E>(
 type CompileTimeEvalContext<'a, 'mir, 'tcx> =
     EvalContext<'a, 'mir, 'tcx, CompileTimeInterpreter<'a, 'mir, 'tcx>>;
 
+impl interpret::MayLeak for ! {
+    #[inline(always)]
+    fn may_leak(self) -> bool {
+        // `self` is uninhabited
+        self
+    }
+}
+
 impl<'a, 'mir, 'tcx> interpret::Machine<'a, 'mir, 'tcx>
     for CompileTimeInterpreter<'a, 'mir, 'tcx>
 {
-    type MemoryData = ();
     type MemoryKinds = !;
+    type AllocExtra = ();
     type PointerTag = ();
 
-    type MemoryMap = FxHashMap<AllocId, (MemoryKind<!>, Allocation<()>)>;
+    type MemoryMap = FxHashMap<AllocId, (MemoryKind<!>, Allocation)>;
 
     const STATIC_KIND: Option<!> = None; // no copying of statics allowed
+    const ENABLE_PTR_TRACKING_HOOKS: bool = false; // we don't have no provenance
 
     #[inline(always)]
     fn enforce_validity(_ecx: &EvalContext<'a, 'mir, 'tcx, Self>) -> bool {
@@ -456,6 +462,26 @@ fn before_terminator(ecx: &mut EvalContext<'a, 'mir, 'tcx, Self>) -> EvalResult<
             &ecx.stack[..],
         )
     }
+
+    #[inline(always)]
+    fn tag_reference(
+        _ecx: &mut EvalContext<'a, 'mir, 'tcx, Self>,
+        _ptr: Pointer<Self::PointerTag>,
+        _pointee_ty: Ty<'tcx>,
+        _pointee_size: Size,
+        _borrow_kind: Option<mir::BorrowKind>,
+    ) -> EvalResult<'tcx, Self::PointerTag> {
+        Ok(())
+    }
+
+    #[inline(always)]
+    fn tag_dereference(
+        _ecx: &EvalContext<'a, 'mir, 'tcx, Self>,
+        _ptr: Pointer<Self::PointerTag>,
+        _ptr_ty: Ty<'tcx>,
+    ) -> EvalResult<'tcx, Self::PointerTag> {
+        Ok(())
+    }
 }
 
 /// Project to a field of a (variant of a) const
index 56031054b918387e762f3a2ec3b83534ce110537..bb3e4a8d8813f7968a4adc6da21b557422b97c57 100644 (file)
@@ -2011,6 +2011,46 @@ fn main() {
 ```
 "##,
 
+E0515: r##"
+Cannot return value that references local variable
+
+Local variables, function parameters and temporaries are all dropped before the
+end of the function body. So a reference to them cannot be returned.
+
+```compile_fail,E0515
+#![feature(nll)]
+fn get_dangling_reference() -> &'static i32 {
+    let x = 0;
+    &x
+}
+```
+
+```compile_fail,E0515
+#![feature(nll)]
+use std::slice::Iter;
+fn get_dangling_iterator<'a>() -> Iter<'a, i32> {
+    let v = vec![1, 2, 3];
+    v.iter()
+}
+```
+
+Consider returning an owned value instead:
+
+```
+use std::vec::IntoIter;
+
+fn get_integer() -> i32 {
+    let x = 0;
+    x
+}
+
+fn get_owned_iterator() -> IntoIter<i32> {
+    let v = vec![1, 2, 3];
+    v.into_iter()
+}
+```
+"##,
+
 E0595: r##"
 Closures cannot mutate immutable captured variables.
 
@@ -2339,6 +2379,7 @@ fn foo() -> i32 { 22 }
 //  E0471, // constant evaluation error (in pattern)
 //    E0385, // {} in an aliasable location
     E0493, // destructors cannot be evaluated at compile-time
+    E0521,  // borrowed data escapes outside of closure
     E0524, // two closures require unique access to `..` at the same time
     E0526, // shuffle indices are not constant
     E0594, // cannot assign to {}
index 1504b694be19254994191bcf4cbf4d27f45fa3ff..81e7a6e4373d2790f663b59048dc4080034fa96c 100644 (file)
@@ -37,8 +37,6 @@ pub fn cast(
         kind: CastKind,
         dest: PlaceTy<'tcx, M::PointerTag>,
     ) -> EvalResult<'tcx> {
-        let src_layout = src.layout;
-        let dst_layout = dest.layout;
         use rustc::mir::CastKind::*;
         match kind {
             Unsize => {
@@ -46,15 +44,28 @@ pub fn cast(
             }
 
             Misc => {
+                let src_layout = src.layout;
                 let src = self.read_value(src)?;
+
+                let src = if M::ENABLE_PTR_TRACKING_HOOKS && src_layout.ty.is_region_ptr() {
+                    // The only `Misc` casts on references are those creating raw pointers.
+                    assert!(dest.layout.ty.is_unsafe_ptr());
+                    // For the purpose of the "ptr tag hooks", treat this as creating
+                    // a new, raw reference.
+                    let place = self.ref_to_mplace(src)?;
+                    self.create_ref(place, None)?
+                } else {
+                    *src
+                };
+
                 if self.type_is_fat_ptr(src_layout.ty) {
-                    match (*src, self.type_is_fat_ptr(dest.layout.ty)) {
+                    match (src, self.type_is_fat_ptr(dest.layout.ty)) {
                         // pointers to extern types
                         (Value::Scalar(_),_) |
                         // slices and trait objects to other slices/trait objects
                         (Value::ScalarPair(..), true) => {
                             // No change to value
-                            self.write_value(*src, dest)?;
+                            self.write_value(src, dest)?;
                         }
                         // slices and trait objects to thin pointers (dropping the metadata)
                         (Value::ScalarPair(data, _), false) => {
@@ -65,11 +76,13 @@ pub fn cast(
                     match src_layout.variants {
                         layout::Variants::Single { index } => {
                             if let Some(def) = src_layout.ty.ty_adt_def() {
+                                // Cast from a univariant enum
+                                assert!(src_layout.is_zst());
                                 let discr_val = def
                                     .discriminant_for_variant(*self.tcx, index)
                                     .val;
                                 return self.write_scalar(
-                                    Scalar::from_uint(discr_val, dst_layout.size),
+                                    Scalar::from_uint(discr_val, dest.layout.size),
                                     dest);
                             }
                         }
@@ -85,7 +98,7 @@ pub fn cast(
 
             ReifyFnPointer => {
                 // The src operand does not matter, just its type
-                match src_layout.ty.sty {
+                match src.layout.ty.sty {
                     ty::FnDef(def_id, substs) => {
                         if self.tcx.has_attr(def_id, "rustc_args_required_const") {
                             bug!("reifying a fn ptr that requires \
@@ -117,7 +130,7 @@ pub fn cast(
 
             ClosureFnPointer => {
                 // The src operand does not matter, just its type
-                match src_layout.ty.sty {
+                match src.layout.ty.sty {
                     ty::Closure(def_id, substs) => {
                         let substs = self.tcx.subst_and_normalize_erasing_regions(
                             self.substs(),
index cf5358a9896720365448dc3b7f741eb56c608926..92cc09f4867b9ea632aa81e088e9a9ec2375efa0 100644 (file)
@@ -11,6 +11,7 @@
 use std::fmt::Write;
 use std::mem;
 
+use syntax::source_map::{self, Span, DUMMY_SP};
 use rustc::hir::def_id::DefId;
 use rustc::hir::def::Def;
 use rustc::hir::map::definitions::DefPathData;
@@ -29,8 +30,6 @@
 };
 use rustc_data_structures::fx::FxHashMap;
 
-use syntax::source_map::{self, Span};
-
 use super::{
     Value, Operand, MemPlace, MPlaceTy, Place, PlaceTy, ScalarMaybeUndef,
     Memory, Machine
@@ -205,63 +204,59 @@ pub fn new(
         tcx: TyCtxtAt<'a, 'tcx, 'tcx>,
         param_env: ty::ParamEnv<'tcx>,
         machine: M,
-        memory_data: M::MemoryData,
     ) -> Self {
         EvalContext {
             machine,
             tcx,
             param_env,
-            memory: Memory::new(tcx, memory_data),
+            memory: Memory::new(tcx),
             stack: Vec::new(),
             vtables: FxHashMap::default(),
         }
     }
 
+    #[inline(always)]
     pub fn memory(&self) -> &Memory<'a, 'mir, 'tcx, M> {
         &self.memory
     }
 
+    #[inline(always)]
     pub fn memory_mut(&mut self) -> &mut Memory<'a, 'mir, 'tcx, M> {
         &mut self.memory
     }
 
+    #[inline(always)]
     pub fn stack(&self) -> &[Frame<'mir, 'tcx, M::PointerTag>] {
         &self.stack
     }
 
-    #[inline]
+    #[inline(always)]
     pub fn cur_frame(&self) -> usize {
         assert!(self.stack.len() > 0);
         self.stack.len() - 1
     }
 
-    /// Mark a storage as live, killing the previous content and returning it.
-    /// Remember to deallocate that!
-    pub fn storage_live(
-        &mut self,
-        local: mir::Local
-    ) -> EvalResult<'tcx, LocalValue<M::PointerTag>> {
-        assert!(local != mir::RETURN_PLACE, "Cannot make return place live");
-        trace!("{:?} is now live", local);
-
-        let layout = self.layout_of_local(self.cur_frame(), local)?;
-        let init = LocalValue::Live(self.uninit_operand(layout)?);
-        // StorageLive *always* kills the value that's currently stored
-        Ok(mem::replace(&mut self.frame_mut().locals[local], init))
+    #[inline(always)]
+    pub fn frame(&self) -> &Frame<'mir, 'tcx, M::PointerTag> {
+        self.stack.last().expect("no call frames exist")
     }
 
-    /// Returns the old value of the local.
-    /// Remember to deallocate that!
-    pub fn storage_dead(&mut self, local: mir::Local) -> LocalValue<M::PointerTag> {
-        assert!(local != mir::RETURN_PLACE, "Cannot make return place dead");
-        trace!("{:?} is now dead", local);
+    #[inline(always)]
+    pub fn frame_mut(&mut self) -> &mut Frame<'mir, 'tcx, M::PointerTag> {
+        self.stack.last_mut().expect("no call frames exist")
+    }
 
-        mem::replace(&mut self.frame_mut().locals[local], LocalValue::Dead)
+    #[inline(always)]
+    pub(super) fn mir(&self) -> &'mir mir::Mir<'tcx> {
+        self.frame().mir
     }
 
-    pub fn str_to_value(&mut self, s: &str) -> EvalResult<'tcx, Value<M::PointerTag>> {
-        let ptr = self.memory.allocate_static_bytes(s.as_bytes());
-        Ok(Value::new_slice(Scalar::Ptr(ptr), s.len() as u64, self.tcx.tcx))
+    pub fn substs(&self) -> &'tcx Substs<'tcx> {
+        if let Some(frame) = self.stack.last() {
+            frame.instance.substs
+        } else {
+            Substs::empty()
+        }
     }
 
     pub(super) fn resolve(
@@ -285,10 +280,14 @@ pub(super) fn resolve(
         ).ok_or_else(|| EvalErrorKind::TooGeneric.into())
     }
 
-    pub(super) fn type_is_sized(&self, ty: Ty<'tcx>) -> bool {
+    pub fn type_is_sized(&self, ty: Ty<'tcx>) -> bool {
         ty.is_sized(self.tcx, self.param_env)
     }
 
+    pub fn type_is_freeze(&self, ty: Ty<'tcx>) -> bool {
+        ty.is_freeze(*self.tcx, self.param_env, DUMMY_SP)
+    }
+
     pub fn load_mir(
         &self,
         instance: ty::InstanceDef<'tcx>,
@@ -336,6 +335,11 @@ pub fn layout_of_local(
         self.layout_of(local_ty)
     }
 
+    pub fn str_to_value(&mut self, s: &str) -> EvalResult<'tcx, Value<M::PointerTag>> {
+        let ptr = self.memory.allocate_static_bytes(s.as_bytes());
+        Ok(Value::new_slice(Scalar::Ptr(ptr), s.len() as u64, self.tcx.tcx))
+    }
+
     /// Return the actual dynamic size and alignment of the place at the given type.
     /// Only the "meta" (metadata) part of the place matters.
     /// This can fail to provide an answer for extern types.
@@ -354,11 +358,11 @@ pub(super) fn size_and_align_of(
                 // and it also rounds up to alignment, which we want to avoid,
                 // as the unsized field's alignment could be smaller.
                 assert!(!layout.ty.is_simd());
-                debug!("DST layout: {:?}", layout);
+                trace!("DST layout: {:?}", layout);
 
                 let sized_size = layout.fields.offset(layout.fields.count() - 1);
                 let sized_align = layout.align;
-                debug!(
+                trace!(
                     "DST {} statically sized prefix size: {:?} align: {:?}",
                     layout.ty,
                     sized_size,
@@ -434,6 +438,9 @@ pub fn push_stack_frame(
         return_place: Option<PlaceTy<'tcx, M::PointerTag>>,
         return_to_block: StackPopCleanup,
     ) -> EvalResult<'tcx> {
+        if self.stack.len() > 1 { // FIXME should be "> 0", printing topmost frame crashes rustc...
+            debug!("PAUSING({}) {}", self.cur_frame(), self.frame().instance);
+        }
         ::log_settings::settings().indentation += 1;
 
         // first push a stack frame so we have access to the local substs
@@ -498,6 +505,10 @@ pub fn push_stack_frame(
             self.frame_mut().locals = locals;
         }
 
+        if self.stack.len() > 1 { // FIXME no check should be needed, but some instances ICE
+            debug!("ENTERING({}) {}", self.cur_frame(), self.frame().instance);
+        }
+
         if self.stack.len() > self.tcx.sess.const_eval_stack_frame_limit {
             err!(StackFrameLimitReached)
         } else {
@@ -506,6 +517,9 @@ pub fn push_stack_frame(
     }
 
     pub(super) fn pop_stack_frame(&mut self) -> EvalResult<'tcx> {
+        if self.stack.len() > 1 { // FIXME no check should be needed, but some instances ICE
+            debug!("LEAVING({}) {}", self.cur_frame(), self.frame().instance);
+        }
         ::log_settings::settings().indentation -= 1;
         let frame = self.stack.pop().expect(
             "tried to pop a stack frame, but there were none",
@@ -549,9 +563,37 @@ pub(super) fn pop_stack_frame(&mut self) -> EvalResult<'tcx> {
             return err!(Unreachable);
         }
 
+        if self.stack.len() > 1 { // FIXME should be "> 0", printing topmost frame crashes rustc...
+            debug!("CONTINUING({}) {}", self.cur_frame(), self.frame().instance);
+        }
+
         Ok(())
     }
 
+    /// Mark a storage as live, killing the previous content and returning it.
+    /// Remember to deallocate that!
+    pub fn storage_live(
+        &mut self,
+        local: mir::Local
+    ) -> EvalResult<'tcx, LocalValue<M::PointerTag>> {
+        assert!(local != mir::RETURN_PLACE, "Cannot make return place live");
+        trace!("{:?} is now live", local);
+
+        let layout = self.layout_of_local(self.cur_frame(), local)?;
+        let init = LocalValue::Live(self.uninit_operand(layout)?);
+        // StorageLive *always* kills the value that's currently stored
+        Ok(mem::replace(&mut self.frame_mut().locals[local], init))
+    }
+
+    /// Returns the old value of the local.
+    /// Remember to deallocate that!
+    pub fn storage_dead(&mut self, local: mir::Local) -> LocalValue<M::PointerTag> {
+        assert!(local != mir::RETURN_PLACE, "Cannot make return place dead");
+        trace!("{:?} is now dead", local);
+
+        mem::replace(&mut self.frame_mut().locals[local], LocalValue::Dead)
+    }
+
     pub(super) fn deallocate_local(
         &mut self,
         local: LocalValue<M::PointerTag>,
@@ -576,28 +618,6 @@ pub fn const_eval(&self, gid: GlobalId<'tcx>) -> EvalResult<'tcx, &'tcx ty::Cons
             .map_err(|err| EvalErrorKind::ReferencedConstant(err).into())
     }
 
-    #[inline(always)]
-    pub fn frame(&self) -> &Frame<'mir, 'tcx, M::PointerTag> {
-        self.stack.last().expect("no call frames exist")
-    }
-
-    #[inline(always)]
-    pub fn frame_mut(&mut self) -> &mut Frame<'mir, 'tcx, M::PointerTag> {
-        self.stack.last_mut().expect("no call frames exist")
-    }
-
-    pub(super) fn mir(&self) -> &'mir mir::Mir<'tcx> {
-        self.frame().mir
-    }
-
-    pub fn substs(&self) -> &'tcx Substs<'tcx> {
-        if let Some(frame) = self.stack.last() {
-            frame.instance.substs
-        } else {
-            Substs::empty()
-        }
-    }
-
     pub fn dump_place(&self, place: Place<M::PointerTag>) {
         // Debug output
         if !log_enabled!(::log::Level::Trace) {
index 560698f3f57a22249661ac13f568ec6a4a5b0100..1318bbe1c2bf286d22ec255726afd7e001061f9c 100644 (file)
 use std::hash::Hash;
 
 use rustc::hir::def_id::DefId;
-use rustc::mir::interpret::{Allocation, AllocId, EvalResult, Scalar};
 use rustc::mir;
-use rustc::ty::{self, layout::TyLayout, query::TyCtxtAt};
+use rustc::ty::{self, Ty, layout::{Size, TyLayout}, query::TyCtxtAt};
+
+use super::{
+    Allocation, AllocId, EvalResult, Scalar,
+    EvalContext, PlaceTy, OpTy, Pointer, MemoryKind,
+};
+
+/// Classifying memory accesses
+#[derive(Clone, Copy, Debug, PartialEq, Eq)]
+pub enum MemoryAccess {
+    Read,
+    Write,
+}
 
-use super::{EvalContext, PlaceTy, OpTy, MemoryKind};
+/// Whether this kind of memory is allowed to leak
+pub trait MayLeak: Copy {
+    fn may_leak(self) -> bool;
+}
 
 /// The functionality needed by memory to manage its allocations
 pub trait AllocMap<K: Hash + Eq, V> {
@@ -62,29 +76,36 @@ fn get_mut_or<E>(
 /// Methods of this trait signifies a point where CTFE evaluation would fail
 /// and some use case dependent behaviour can instead be applied.
 pub trait Machine<'a, 'mir, 'tcx>: Sized {
-    /// Additional data that can be accessed via the Memory
-    type MemoryData;
-
     /// Additional memory kinds a machine wishes to distinguish from the builtin ones
-    type MemoryKinds: ::std::fmt::Debug + Copy + Eq;
+    type MemoryKinds: ::std::fmt::Debug + MayLeak + Eq + 'static;
+
+    /// Tag tracked alongside every pointer.  This is used to implement "Stacked Borrows"
+    /// <https://www.ralfj.de/blog/2018/08/07/stacked-borrows.html>.
+    type PointerTag: ::std::fmt::Debug + Default + Copy + Eq + Hash + 'static;
+
+    /// Extra data stored in every allocation.
+    type AllocExtra: ::std::fmt::Debug + Default + Clone;
 
     /// Memory's allocation map
     type MemoryMap:
-        AllocMap<AllocId, (MemoryKind<Self::MemoryKinds>, Allocation<Self::PointerTag>)> +
+        AllocMap<
+            AllocId,
+            (MemoryKind<Self::MemoryKinds>, Allocation<Self::PointerTag, Self::AllocExtra>)
+        > +
         Default +
         Clone;
 
-    /// Tag tracked alongside every pointer.  This is inert for now, in preparation for
-    /// a future implementation of "Stacked Borrows"
-    /// <https://www.ralfj.de/blog/2018/08/07/stacked-borrows.html>.
-    type PointerTag: ::std::fmt::Debug + Default + Copy + Eq + Hash + 'static;
-
     /// The memory kind to use for copied statics -- or None if those are not supported.
     /// Statics are copied under two circumstances: When they are mutated, and when
     /// `static_with_default_tag` or `find_foreign_static` (see below) returns an owned allocation
     /// that is added to the memory so that the work is not done twice.
     const STATIC_KIND: Option<Self::MemoryKinds>;
 
+    /// As an optimization, you can prevent the pointer tracking hooks from ever being
+    /// called.  You should only do this if you do not care about provenance tracking.
+    /// This controls the `tag_reference` and `tag_dereference` hooks.
+    const ENABLE_PTR_TRACKING_HOOKS: bool;
+
     /// Whether to enforce the validity invariant
     fn enforce_validity(ecx: &EvalContext<'a, 'mir, 'tcx, Self>) -> bool;
 
@@ -127,7 +148,7 @@ fn call_intrinsic(
     fn find_foreign_static(
         tcx: TyCtxtAt<'a, 'tcx, 'tcx>,
         def_id: DefId,
-    ) -> EvalResult<'tcx, Cow<'tcx, Allocation<Self::PointerTag>>>;
+    ) -> EvalResult<'tcx, Cow<'tcx, Allocation<Self::PointerTag, Self::AllocExtra>>>;
 
     /// Called to turn an allocation obtained from the `tcx` into one that has
     /// the appropriate tags on each pointer.
@@ -138,7 +159,7 @@ fn find_foreign_static(
     /// owned allocation to the map even when the map is shared.)
     fn static_with_default_tag(
         alloc: &'_ Allocation
-    ) -> Cow<'_, Allocation<Self::PointerTag>>;
+    ) -> Cow<'_, Allocation<Self::PointerTag, Self::AllocExtra>>;
 
     /// Called for all binary operations on integer(-like) types when one operand is a pointer
     /// value, and for the `Offset` operation that is inherently about pointers.
@@ -153,15 +174,57 @@ fn ptr_op(
         right_layout: TyLayout<'tcx>,
     ) -> EvalResult<'tcx, (Scalar<Self::PointerTag>, bool)>;
 
-    /// Heap allocations via the `box` keyword
-    ///
-    /// Returns a pointer to the allocated memory
+    /// Heap allocations via the `box` keyword.
     fn box_alloc(
         ecx: &mut EvalContext<'a, 'mir, 'tcx, Self>,
         dest: PlaceTy<'tcx, Self::PointerTag>,
     ) -> EvalResult<'tcx>;
 
+    /// Hook for performing extra checks on a memory access.
+    ///
+    /// Takes read-only access to the allocation so we can keep all the memory read
+    /// operations take `&self`.  Use a `RefCell` in `AllocExtra` if you
+    /// need to mutate.
+    #[inline]
+    fn memory_accessed(
+        _alloc: &Allocation<Self::PointerTag, Self::AllocExtra>,
+        _ptr: Pointer<Self::PointerTag>,
+        _size: Size,
+        _access: MemoryAccess,
+    ) -> EvalResult<'tcx> {
+        Ok(())
+    }
+
+    /// Hook for performing extra checks when memory gets deallocated.
+    #[inline]
+    fn memory_deallocated(
+        _alloc: &mut Allocation<Self::PointerTag, Self::AllocExtra>,
+        _ptr: Pointer<Self::PointerTag>,
+    ) -> EvalResult<'tcx> {
+        Ok(())
+    }
+
+    /// Executed when evaluating the `&` operator: Creating a new reference.
+    /// This has the chance to adjust the tag.
+    /// `borrow_kind` can be `None` in case a raw ptr is being created.
+    fn tag_reference(
+        ecx: &mut EvalContext<'a, 'mir, 'tcx, Self>,
+        ptr: Pointer<Self::PointerTag>,
+        pointee_ty: Ty<'tcx>,
+        pointee_size: Size,
+        borrow_kind: Option<mir::BorrowKind>,
+    ) -> EvalResult<'tcx, Self::PointerTag>;
+
+    /// Executed when evaluating the `*` operator: Following a reference.
+    /// This has the change to adjust the tag.
+    fn tag_dereference(
+        ecx: &EvalContext<'a, 'mir, 'tcx, Self>,
+        ptr: Pointer<Self::PointerTag>,
+        ptr_ty: Ty<'tcx>,
+    ) -> EvalResult<'tcx, Self::PointerTag>;
+
     /// Execute a validation operation
+    #[inline]
     fn validation_op(
         _ecx: &mut EvalContext<'a, 'mir, 'tcx, Self>,
         _op: ::rustc::mir::ValidationOp,
index 4b0c0c3ee6173fdb8ce38c409012cdded050b52b..9febcceae068e60f90d4dd4b68b0b35c059b6fe1 100644 (file)
 
 use rustc::ty::{self, Instance, ParamEnv, query::TyCtxtAt};
 use rustc::ty::layout::{self, Align, TargetDataLayout, Size, HasDataLayout};
-use rustc::mir::interpret::{
-    Pointer, AllocId, Allocation, ConstValue, GlobalId,
-    EvalResult, Scalar, EvalErrorKind, AllocType, PointerArithmetic,
-    truncate
-};
-pub use rustc::mir::interpret::{write_target_uint, read_target_uint};
+pub use rustc::mir::interpret::{truncate, write_target_uint, read_target_uint};
 use rustc_data_structures::fx::{FxHashSet, FxHashMap};
 
 use syntax::ast::Mutability;
 
-use super::{Machine, AllocMap, ScalarMaybeUndef};
+use super::{
+    Pointer, AllocId, Allocation, ConstValue, GlobalId,
+    EvalResult, Scalar, EvalErrorKind, AllocType, PointerArithmetic,
+    Machine, MemoryAccess, AllocMap, MayLeak, ScalarMaybeUndef,
+};
 
 #[derive(Debug, PartialEq, Eq, Copy, Clone, Hash)]
 pub enum MemoryKind<T> {
@@ -44,12 +43,20 @@ pub enum MemoryKind<T> {
     Machine(T),
 }
 
+impl<T: MayLeak> MayLeak for MemoryKind<T> {
+    #[inline]
+    fn may_leak(self) -> bool {
+        match self {
+            MemoryKind::Stack => false,
+            MemoryKind::Vtable => true,
+            MemoryKind::Machine(k) => k.may_leak()
+        }
+    }
+}
+
 // `Memory` has to depend on the `Machine` because some of its operations
 // (e.g. `get`) call a `Machine` hook.
 pub struct Memory<'a, 'mir, 'tcx: 'a + 'mir, M: Machine<'a, 'mir, 'tcx>> {
-    /// Additional data required by the Machine
-    pub data: M::MemoryData,
-
     /// Allocations local to this instance of the miri engine.  The kind
     /// helps ensure that the same mechanism is used for allocation and
     /// deallocation.  When an allocation is not found here, it is a
@@ -91,11 +98,9 @@ fn data_layout(&self) -> &TargetDataLayout {
 // carefully copy only the reachable parts.
 impl<'a, 'mir, 'tcx: 'a + 'mir, M: Machine<'a, 'mir, 'tcx>>
     Clone for Memory<'a, 'mir, 'tcx, M>
-    where M::MemoryData: Clone
 {
     fn clone(&self) -> Self {
         Memory {
-            data: self.data.clone(),
             alloc_map: self.alloc_map.clone(),
             dead_alloc_map: self.dead_alloc_map.clone(),
             tcx: self.tcx,
@@ -104,9 +109,8 @@ fn clone(&self) -> Self {
 }
 
 impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> Memory<'a, 'mir, 'tcx, M> {
-    pub fn new(tcx: TyCtxtAt<'a, 'tcx, 'tcx>, data: M::MemoryData) -> Self {
+    pub fn new(tcx: TyCtxtAt<'a, 'tcx, 'tcx>) -> Self {
         Memory {
-            data,
             alloc_map: Default::default(),
             dead_alloc_map: FxHashMap::default(),
             tcx,
@@ -123,7 +127,7 @@ pub fn allocate_static_bytes(&mut self, bytes: &[u8]) -> Pointer<M::PointerTag>
 
     pub fn allocate_with(
         &mut self,
-        alloc: Allocation<M::PointerTag>,
+        alloc: Allocation<M::PointerTag, M::AllocExtra>,
         kind: MemoryKind<M::MemoryKinds>,
     ) -> EvalResult<'tcx, AllocId> {
         let id = self.tcx.alloc_map.lock().reserve();
@@ -186,13 +190,13 @@ pub fn deallocate(
         size_and_align: Option<(Size, Align)>,
         kind: MemoryKind<M::MemoryKinds>,
     ) -> EvalResult<'tcx> {
-        debug!("deallocating: {}", ptr.alloc_id);
+        trace!("deallocating: {}", ptr.alloc_id);
 
         if ptr.offset.bytes() != 0 {
             return err!(DeallocateNonBasePtr);
         }
 
-        let (alloc_kind, alloc) = match self.alloc_map.remove(&ptr.alloc_id) {
+        let (alloc_kind, mut alloc) = match self.alloc_map.remove(&ptr.alloc_id) {
             Some(alloc) => alloc,
             None => {
                 // Deallocating static memory -- always an error
@@ -227,6 +231,9 @@ pub fn deallocate(
             }
         }
 
+        // Let the machine take some extra action
+        M::memory_deallocated(&mut alloc, ptr)?;
+
         // Don't forget to remember size and align of this now-dead allocation
         let old = self.dead_alloc_map.insert(
             ptr.alloc_id,
@@ -334,7 +341,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> Memory<'a, 'mir, 'tcx, M> {
     fn get_static_alloc(
         tcx: TyCtxtAt<'a, 'tcx, 'tcx>,
         id: AllocId,
-    ) -> EvalResult<'tcx, Cow<'tcx, Allocation<M::PointerTag>>> {
+    ) -> EvalResult<'tcx, Cow<'tcx, Allocation<M::PointerTag, M::AllocExtra>>> {
         let alloc = tcx.alloc_map.lock().get(id);
         let def_id = match alloc {
             Some(AllocType::Memory(mem)) => {
@@ -376,7 +383,7 @@ fn get_static_alloc(
         })
     }
 
-    pub fn get(&self, id: AllocId) -> EvalResult<'tcx, &Allocation<M::PointerTag>> {
+    pub fn get(&self, id: AllocId) -> EvalResult<'tcx, &Allocation<M::PointerTag, M::AllocExtra>> {
         // The error type of the inner closure here is somewhat funny.  We have two
         // ways of "erroring": An actual error, or because we got a reference from
         // `get_static_alloc` that we can actually use directly without inserting anything anywhere.
@@ -409,7 +416,7 @@ pub fn get(&self, id: AllocId) -> EvalResult<'tcx, &Allocation<M::PointerTag>> {
     pub fn get_mut(
         &mut self,
         id: AllocId,
-    ) -> EvalResult<'tcx, &mut Allocation<M::PointerTag>> {
+    ) -> EvalResult<'tcx, &mut Allocation<M::PointerTag, M::AllocExtra>> {
         let tcx = self.tcx;
         let a = self.alloc_map.get_mut_or(id, || {
             // Need to make a copy, even if `get_static_alloc` is able
@@ -482,12 +489,12 @@ pub fn dump_alloc(&self, id: AllocId) {
         self.dump_allocs(vec![id]);
     }
 
-    fn dump_alloc_helper<Tag>(
+    fn dump_alloc_helper<Tag, Extra>(
         &self,
         allocs_seen: &mut FxHashSet<AllocId>,
         allocs_to_print: &mut VecDeque<AllocId>,
         mut msg: String,
-        alloc: &Allocation<Tag>,
+        alloc: &Allocation<Tag, Extra>,
         extra: String,
     ) {
         use std::fmt::Write;
@@ -590,13 +597,7 @@ pub fn dump_allocs(&self, mut allocs: Vec<AllocId>) {
     pub fn leak_report(&self) -> usize {
         trace!("### LEAK REPORT ###");
         let leaks: Vec<_> = self.alloc_map.filter_map_collect(|&id, &(kind, _)| {
-            // exclude statics and vtables
-            let exclude = match kind {
-                MemoryKind::Stack => false,
-                MemoryKind::Vtable => true,
-                MemoryKind::Machine(k) => Some(k) == M::STATIC_KIND,
-            };
-            if exclude { None } else { Some(id) }
+            if kind.may_leak() { None } else { Some(id) }
         });
         let n = leaks.len();
         self.dump_allocs(leaks);
@@ -633,6 +634,8 @@ fn get_bytes_internal(
         }
 
         let alloc = self.get(ptr.alloc_id)?;
+        M::memory_accessed(alloc, ptr, size, MemoryAccess::Read)?;
+
         assert_eq!(ptr.offset.bytes() as usize as u64, ptr.offset.bytes());
         assert_eq!(size.bytes() as usize as u64, size.bytes());
         let offset = ptr.offset.bytes() as usize;
@@ -677,6 +680,8 @@ fn get_bytes_mut(
         self.clear_relocations(ptr, size)?;
 
         let alloc = self.get_mut(ptr.alloc_id)?;
+        M::memory_accessed(alloc, ptr, size, MemoryAccess::Write)?;
+
         assert_eq!(ptr.offset.bytes() as usize as u64, ptr.offset.bytes());
         assert_eq!(size.bytes() as usize as u64, size.bytes());
         let offset = ptr.offset.bytes() as usize;
@@ -687,8 +692,8 @@ fn get_bytes_mut(
 /// Interning (for CTFE)
 impl<'a, 'mir, 'tcx, M> Memory<'a, 'mir, 'tcx, M>
 where
-    M: Machine<'a, 'mir, 'tcx, PointerTag=()>,
-    M::MemoryMap: AllocMap<AllocId, (MemoryKind<M::MemoryKinds>, Allocation<()>)>,
+    M: Machine<'a, 'mir, 'tcx, PointerTag=(), AllocExtra=()>,
+    M::MemoryMap: AllocMap<AllocId, (MemoryKind<M::MemoryKinds>, Allocation)>,
 {
     /// mark an allocation as static and initialized, either mutable or not
     pub fn intern_static(
index 39628598ef31cd1d1172d9fa35e16e0ce22bb964..55037a99e0124827ce4adffb000862d856e30bcd 100644 (file)
@@ -24,6 +24,8 @@
 mod validity;
 mod intrinsics;
 
+pub use rustc::mir::interpret::*; // have all the `interpret` symbols in one place: here
+
 pub use self::eval_context::{
     EvalContext, Frame, StackPopCleanup, LocalValue,
 };
@@ -32,7 +34,7 @@
 
 pub use self::memory::{Memory, MemoryKind};
 
-pub use self::machine::{Machine, AllocMap};
+pub use self::machine::{Machine, AllocMap, MemoryAccess, MayLeak};
 
 pub use self::operand::{ScalarMaybeUndef, Value, ValTy, Operand, OpTy};
 
index e4055947b6421ffaee8b4b3438b2003da87ce19b..af3d6948628398cb7b8134bf4fc17b6a18c6a3fb 100644 (file)
@@ -144,17 +144,6 @@ pub fn to_ptr(self) -> EvalResult<'tcx, Pointer<Tag>> {
         // it now must be aligned.
         self.to_scalar_ptr_align().0.to_ptr()
     }
-
-    /// Turn a mplace into a (thin or fat) pointer, as a reference, pointing to the same space.
-    /// This is the inverse of `ref_to_mplace`.
-    pub fn to_ref(self) -> Value<Tag> {
-        // We ignore the alignment of the place here -- special handling for packed structs ends
-        // at the `&` operator.
-        match self.meta {
-            None => Value::Scalar(self.ptr.into()),
-            Some(meta) => Value::ScalarPair(self.ptr.into(), meta.into()),
-        }
-    }
 }
 
 impl<'tcx, Tag> MPlaceTy<'tcx, Tag> {
@@ -267,25 +256,59 @@ impl<'a, 'mir, 'tcx, Tag, M> EvalContext<'a, 'mir, 'tcx, M>
 where
     Tag: ::std::fmt::Debug+Default+Copy+Eq+Hash+'static,
     M: Machine<'a, 'mir, 'tcx, PointerTag=Tag>,
-    M::MemoryMap: AllocMap<AllocId, (MemoryKind<M::MemoryKinds>, Allocation<Tag>)>,
+    M::MemoryMap: AllocMap<AllocId, (MemoryKind<M::MemoryKinds>, Allocation<Tag, M::AllocExtra>)>,
 {
     /// Take a value, which represents a (thin or fat) reference, and make it a place.
-    /// Alignment is just based on the type.  This is the inverse of `MemPlace::to_ref`.
+    /// Alignment is just based on the type.  This is the inverse of `create_ref`.
     pub fn ref_to_mplace(
-        &self, val: ValTy<'tcx, M::PointerTag>
+        &self,
+        val: ValTy<'tcx, M::PointerTag>,
     ) -> EvalResult<'tcx, MPlaceTy<'tcx, M::PointerTag>> {
+        let ptr = match val.to_scalar_ptr()? {
+            Scalar::Ptr(ptr) if M::ENABLE_PTR_TRACKING_HOOKS => {
+                // Machine might want to track the `*` operator
+                let tag = M::tag_dereference(self, ptr, val.layout.ty)?;
+                Scalar::Ptr(Pointer::new_with_tag(ptr.alloc_id, ptr.offset, tag))
+            }
+            other => other,
+        };
+
         let pointee_type = val.layout.ty.builtin_deref(true).unwrap().ty;
         let layout = self.layout_of(pointee_type)?;
         let align = layout.align;
+
         let mplace = match *val {
-            Value::Scalar(ptr) =>
-                MemPlace { ptr: ptr.not_undef()?, align, meta: None },
-            Value::ScalarPair(ptr, meta) =>
-                MemPlace { ptr: ptr.not_undef()?, align, meta: Some(meta.not_undef()?) },
+            Value::Scalar(_) =>
+                MemPlace { ptr, align, meta: None },
+            Value::ScalarPair(_, meta) =>
+                MemPlace { ptr, align, meta: Some(meta.not_undef()?) },
         };
         Ok(MPlaceTy { mplace, layout })
     }
 
+    /// Turn a mplace into a (thin or fat) pointer, as a reference, pointing to the same space.
+    /// This is the inverse of `ref_to_mplace`.
+    pub fn create_ref(
+        &mut self,
+        place: MPlaceTy<'tcx, M::PointerTag>,
+        borrow_kind: Option<mir::BorrowKind>,
+    ) -> EvalResult<'tcx, Value<M::PointerTag>> {
+        let ptr = match place.ptr {
+            Scalar::Ptr(ptr) if M::ENABLE_PTR_TRACKING_HOOKS => {
+                // Machine might want to track the `&` operator
+                let (size, _) = self.size_and_align_of_mplace(place)?
+                    .expect("create_ref cannot determine size");
+                let tag = M::tag_reference(self, ptr, place.layout.ty, size, borrow_kind)?;
+                Scalar::Ptr(Pointer::new_with_tag(ptr.alloc_id, ptr.offset, tag))
+            },
+            other => other,
+        };
+        Ok(match place.meta {
+            None => Value::Scalar(ptr.into()),
+            Some(meta) => Value::ScalarPair(ptr.into(), meta.into()),
+        })
+    }
+
     /// Offset a pointer to project to a field. Unlike place_field, this is always
     /// possible without allocating, so it can take &self. Also return the field's layout.
     /// This supports both struct and array fields.
index 11d5785bc565dbd502a54eb7711c0b96fca8ca94..047a0125f78af968bad83a63ec91696ed517d7f6 100644 (file)
@@ -305,7 +305,7 @@ impl<'a, Ctx> Snapshot<'a, Ctx> for &'a Allocation
     type Item = AllocationSnapshot<'a>;
 
     fn snapshot(&self, ctx: &'a Ctx) -> Self::Item {
-        let Allocation { bytes, relocations, undef_mask, align, mutability } = self;
+        let Allocation { bytes, relocations, undef_mask, align, mutability, extra: () } = self;
 
         AllocationSnapshot {
             bytes,
index d15867eacddc60dc11c9f3581192e9e77264796a..1bab536e3e0f079d2d21eac24984f5c3e1a80b36 100644 (file)
@@ -248,9 +248,10 @@ fn eval_rvalue_into_place(
                 )?;
             }
 
-            Ref(_, _, ref place) => {
+            Ref(_, borrow_kind, ref place) => {
                 let src = self.eval_place(place)?;
-                let val = self.force_allocation(src)?.to_ref();
+                let val = self.force_allocation(src)?;
+                let val = self.create_ref(val, Some(borrow_kind))?;
                 self.write_value(val, dest)?;
             }
 
index a339fa34ae1f64cc6fd45cc176c788f5cd8dad4f..c759727f546c89b83e679aec7b88677fcbc0f848 100644 (file)
@@ -446,7 +446,10 @@ fn drop_in_place(
         };
 
         let arg = OpTy {
-            op: Operand::Immediate(place.to_ref()),
+            op: Operand::Immediate(self.create_ref(
+                place,
+                None // this is a "raw reference"
+            )?),
             layout: self.layout_of(self.tcx.mk_mut_ptr(place.layout.ty))?,
         };
 
index 2b0febc1ce717eb507740c88029c639dc9adc97c..a2d4eee2842c7ce7a6fc5fa31733ebf5dfdf3f74 100644 (file)
@@ -26,7 +26,7 @@ pub fn get_vtable(
         ty: Ty<'tcx>,
         poly_trait_ref: ty::PolyExistentialTraitRef<'tcx>,
     ) -> EvalResult<'tcx, Pointer<M::PointerTag>> {
-        debug!("get_vtable(trait_ref={:?})", poly_trait_ref);
+        trace!("get_vtable(trait_ref={:?})", poly_trait_ref);
 
         let (ty, poly_trait_ref) = self.tcx.erase_regions(&(ty, poly_trait_ref));
 
index d7b2f67a581e387e1bd0ba134e5d10f1794f81e2..38cf79d8fa0b9836fcf29422155a58a3ea1716df 100644 (file)
@@ -163,6 +163,8 @@ fn validate_primitive_type(
                     scalar_format(value), path, "a valid unicode codepoint");
             },
             ty::Float(_) | ty::Int(_) | ty::Uint(_) => {
+                // NOTE: Keep this in sync with the array optimization for int/float
+                // types below!
                 let size = value.layout.size;
                 let value = value.to_scalar_or_undef();
                 if const_mode {
@@ -511,6 +513,8 @@ pub fn validate_operand(
                         // This is the size in bytes of the whole array.
                         let size = Size::from_bytes(ty_size * len);
 
+                        // NOTE: Keep this in sync with the handling of integer and float
+                        // types above, in `validate_primitive_type`.
                         // In run-time mode, we accept pointers in here.  This is actually more
                         // permissive than a per-element check would be, e.g. we accept
                         // an &[u8] that contains a pointer even though bytewise checking would
index 5a7268c057bd8feca0aa0d1b798887228717f8f4..1715086686c4224dfb70900f34c14a9cf37a0a16 100644 (file)
@@ -632,6 +632,31 @@ fn path_does_not_live_long_enough(
         self.cancel_if_wrong_origin(err, o)
     }
 
+    fn cannot_return_reference_to_local(
+        self,
+        span: Span,
+        reference_desc: &str,
+        path_desc: &str,
+        o: Origin,
+    ) -> DiagnosticBuilder<'cx> {
+        let mut err = struct_span_err!(
+            self,
+            span,
+            E0515,
+            "cannot return {REFERENCE} {LOCAL}{OGN}",
+            REFERENCE=reference_desc,
+            LOCAL=path_desc,
+            OGN = o
+        );
+
+        err.span_label(
+            span,
+            format!("returns a {} data owned by the current function", reference_desc),
+        );
+
+        self.cancel_if_wrong_origin(err, o)
+    }
+
     fn lifetime_too_short_for_reborrow(
         self,
         span: Span,
@@ -717,6 +742,24 @@ fn cannot_capture_in_long_lived_closure(
         self.cancel_if_wrong_origin(err, o)
     }
 
+    fn borrowed_data_escapes_closure(
+        self,
+        escape_span: Span,
+        escapes_from: &str,
+        o: Origin,
+    ) -> DiagnosticBuilder<'cx> {
+        let err = struct_span_err!(
+            self,
+            escape_span,
+            E0521,
+            "borrowed data escapes outside of {}{OGN}",
+            escapes_from,
+            OGN = o
+        );
+
+        self.cancel_if_wrong_origin(err, o)
+    }
+
     fn thread_local_value_does_not_live_long_enough(
         self,
         span: Span,
index fe2bc0ca79b2351b910727b65ea253c3cea954d7..d8df914a8b9f31c6fb1188f9ff0c3e9234a8e2ee 100644 (file)
@@ -1,18 +1,11 @@
-error[E0716]: temporary value dropped while borrowed
-  --> $DIR/borrowck-borrow-from-temporary.rs:19:24
+error[E0515]: cannot return value referencing temporary value
+  --> $DIR/borrowck-borrow-from-temporary.rs:20:5
    |
 LL |     let &Foo(ref x) = &id(Foo(3)); //~ ERROR borrowed value does not live long enough
-   |                        ^^^^^^^^^^ creates a temporary which is freed while still in use
+   |                        ---------- temporary value created here
 LL |     x
-LL | }
-   | - temporary value is freed at the end of this statement
-   |
-note: borrowed value must be valid for the lifetime 'a as defined on the function body at 18:8...
-  --> $DIR/borrowck-borrow-from-temporary.rs:18:8
-   |
-LL | fn foo<'a>() -> &'a isize {
-   |        ^^
+   |     ^ returns a value referencing data owned by the current function
 
 error: aborting due to previous error
 
-For more information about this error, try `rustc --explain E0716`.
+For more information about this error, try `rustc --explain E0515`.
index 426419a7b3b7f830a10d2aeb87a2a388846010d1..ceb145eea7721e535f15ccd39f51280b1e585582 100644 (file)
@@ -1,16 +1,21 @@
-error[E0597]: `books` does not live long enough
-  --> $DIR/borrowck-escaping-closure-error-1.rs:23:14
+error[E0373]: closure may outlive the current function, but it borrows `books`, which is owned by the current function
+  --> $DIR/borrowck-escaping-closure-error-1.rs:23:11
    |
 LL |     spawn(|| books.push(4));
-   |           -- ^^^^^ borrowed value does not live long enough
+   |           ^^ ----- `books` is borrowed here
    |           |
-   |           value captured here
-LL |     //~^ ERROR E0373
-LL | }
-   | - `books` dropped here while still borrowed
+   |           may outlive borrowed value `books`
    |
-   = note: borrowed value must be valid for the static lifetime...
+note: function requires argument type to outlive `'static`
+  --> $DIR/borrowck-escaping-closure-error-1.rs:23:5
+   |
+LL |     spawn(|| books.push(4));
+   |     ^^^^^^^^^^^^^^^^^^^^^^^
+help: to force the closure to take ownership of `books` (and any other referenced variables), use the `move` keyword
+   |
+LL |     spawn(move || books.push(4));
+   |           ^^^^^^^
 
 error: aborting due to previous error
 
-For more information about this error, try `rustc --explain E0597`.
+For more information about this error, try `rustc --explain E0373`.
index d5f3a0ed6d82eb082c216adb23b729492dc288fe..454264727de79a552cf68d33ca73f25f8348fe1d 100644 (file)
@@ -1,20 +1,21 @@
-error[E0597]: `books` does not live long enough
-  --> $DIR/borrowck-escaping-closure-error-2.rs:21:17
+error[E0373]: closure may outlive the current function, but it borrows `books`, which is owned by the current function
+  --> $DIR/borrowck-escaping-closure-error-2.rs:21:14
    |
 LL |     Box::new(|| books.push(4))
-   |              -- ^^^^^ borrowed value does not live long enough
+   |              ^^ ----- `books` is borrowed here
    |              |
-   |              value captured here
-LL |     //~^ ERROR E0373
-LL | }
-   | - `books` dropped here while still borrowed
+   |              may outlive borrowed value `books`
    |
-note: borrowed value must be valid for the lifetime 'a as defined on the function body at 19:8...
-  --> $DIR/borrowck-escaping-closure-error-2.rs:19:8
+note: closure is returned here
+  --> $DIR/borrowck-escaping-closure-error-2.rs:21:5
    |
-LL | fn foo<'a>(x: &'a i32) -> Box<FnMut()+'a> {
-   |        ^^
+LL |     Box::new(|| books.push(4))
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^
+help: to force the closure to take ownership of `books` (and any other referenced variables), use the `move` keyword
+   |
+LL |     Box::new(move || books.push(4))
+   |              ^^^^^^^
 
 error: aborting due to previous error
 
-For more information about this error, try `rustc --explain E0597`.
+For more information about this error, try `rustc --explain E0373`.
index 5c70294a1b90c0abc22028a7e7937939c078212b..70173058a3676808d5a5420b21e618c39249ffe0 100644 (file)
@@ -2,11 +2,9 @@ error[E0713]: borrow may still be in use when destructor runs
   --> $DIR/borrowck-fn-in-const-c.rs:27:16
    |
 LL |         return &local.inner; //~ ERROR does not live long enough
-   |                ^^^^^^^^^^^^
+   |                ^^^^^^^^^^^^ returning this value requires that `local.inner` is borrowed for `'static`
 LL |     }
    |     - here, drop of `local` needs exclusive access to `local.inner`, because the type `DropString` implements the `Drop` trait
-   |
-   = note: borrowed value must be valid for the static lifetime...
 
 error: aborting due to previous error
 
index eb9e72a6c5c78c0dde31b67564d498f0afd85ad9..54865123b7112d61473509f25ca2295395fe27a5 100644 (file)
@@ -2,12 +2,12 @@ error[E0506]: cannot assign to `*s` because it is borrowed
   --> $DIR/borrowck-loan-of-static-data-issue-27616.rs:26:5
    |
 LL |     let alias: &'static mut String = s;
-   |                                      - borrow of `*s` occurs here
+   |                -------------------   - borrow of `*s` occurs here
+   |                |
+   |                type annotation requires that `*s` is borrowed for `'static`
 ...
 LL |     *s = String::new(); //~ ERROR cannot assign
    |     ^^ assignment to borrowed `*s` occurs here
-   |
-   = note: borrowed value must be valid for the static lifetime...
 
 error: aborting due to previous error
 
index 97bf509a4584043762fd92ab3a2d5ba3a02f849d..c806545c591784eaf63adc815dc4cb259336e6a3 100644 (file)
@@ -1,14 +1,9 @@
-error[E0597]: `x` does not live long enough
+error[E0515]: cannot return reference to function parameter `x`
   --> $DIR/borrowck-local-borrow-outlives-fn.rs:15:5
    |
 LL |     &x
-   |     ^^ borrowed value does not live long enough
-...
-LL | }
-   |  - `x` dropped here while still borrowed
-   |
-   = note: borrowed value must be valid for the static lifetime...
+   |     ^^ returns a reference to data owned by the current function
 
 error: aborting due to previous error
 
-For more information about this error, try `rustc --explain E0597`.
+For more information about this error, try `rustc --explain E0515`.
index 97bf509a4584043762fd92ab3a2d5ba3a02f849d..c806545c591784eaf63adc815dc4cb259336e6a3 100644 (file)
@@ -1,14 +1,9 @@
-error[E0597]: `x` does not live long enough
+error[E0515]: cannot return reference to function parameter `x`
   --> $DIR/borrowck-local-borrow-outlives-fn.rs:15:5
    |
 LL |     &x
-   |     ^^ borrowed value does not live long enough
-...
-LL | }
-   |  - `x` dropped here while still borrowed
-   |
-   = note: borrowed value must be valid for the static lifetime...
+   |     ^^ returns a reference to data owned by the current function
 
 error: aborting due to previous error
 
-For more information about this error, try `rustc --explain E0597`.
+For more information about this error, try `rustc --explain E0515`.
index 0d5feb6b9cc84b2489521f0d5ab999f8041a6030..7d78925f2db0cf1b1dd472ae2d073bbb1b59568f 100644 (file)
@@ -14,7 +14,7 @@
 fn cplusplus_mode(x: isize) -> &'static isize {
     &x
     //[ast]~^ ERROR `x` does not live long enough [E0597]
-    //[mir]~^^ ERROR `x` does not live long enough [E0597]
+    //[mir]~^^ ERROR cannot return reference to function parameter `x` [E0515]
 }
 
 fn main() {}
index 5e2b469e68fd1ff577c4c19b97f9c9e437f83397..c62cbfd1ee9f639da5dc99573d285a7564ddba49 100644 (file)
@@ -2,12 +2,13 @@ error[E0597]: `z.1` does not live long enough
   --> $DIR/borrowck-local-borrow-with-panic-outlives-fn.rs:16:15
    |
 LL |     *x = Some(&mut z.1);
-   |               ^^^^^^^^ borrowed value does not live long enough
+   |     ----------^^^^^^^^-
+   |     |         |
+   |     |         borrowed value does not live long enough
+   |     assignment requires that `z.1` is borrowed for `'static`
 ...
 LL | }
    | - `z.1` dropped here while still borrowed
-   |
-   = note: borrowed value must be valid for the static lifetime...
 
 error: aborting due to previous error
 
index 5e2b469e68fd1ff577c4c19b97f9c9e437f83397..c62cbfd1ee9f639da5dc99573d285a7564ddba49 100644 (file)
@@ -2,12 +2,13 @@ error[E0597]: `z.1` does not live long enough
   --> $DIR/borrowck-local-borrow-with-panic-outlives-fn.rs:16:15
    |
 LL |     *x = Some(&mut z.1);
-   |               ^^^^^^^^ borrowed value does not live long enough
+   |     ----------^^^^^^^^-
+   |     |         |
+   |     |         borrowed value does not live long enough
+   |     assignment requires that `z.1` is borrowed for `'static`
 ...
 LL | }
    | - `z.1` dropped here while still borrowed
-   |
-   = note: borrowed value must be valid for the static lifetime...
 
 error: aborting due to previous error
 
index 93436d0ca9745f57dac1d726f9bcb99a11205b2b..7d6b670e53658fcf74ad147a3a0645e4ef294c85 100644 (file)
@@ -1,17 +1,12 @@
-error[E0597]: `x` does not live long enough
+error[E0515]: cannot return value referencing function parameter `x`
   --> $DIR/borrowck-return-variable-on-stack-via-clone.rs:17:5
    |
 LL |     (&x).clone() //~ ERROR `x` does not live long enough
-   |     ^^^^ borrowed value does not live long enough
-LL | }
-   | - `x` dropped here while still borrowed
-   |
-note: borrowed value must be valid for the lifetime 'a as defined on the function body at 16:9...
-  --> $DIR/borrowck-return-variable-on-stack-via-clone.rs:16:9
-   |
-LL | fn leak<'a, T>(x: T) -> &'a T {
-   |         ^^
+   |     ----^^^^^^^^
+   |     |
+   |     returns a value referencing data owned by the current function
+   |     `x` is borrowed here
 
 error: aborting due to previous error
 
-For more information about this error, try `rustc --explain E0597`.
+For more information about this error, try `rustc --explain E0515`.
index 374256c6bd6b9faef40839cca19ff6c0bd33bc88..f32509737a1ddecffce42926a79ce76900e08877 100644 (file)
@@ -1,48 +1,30 @@
-error[E0597]: `vec` does not live long enough
-  --> $DIR/borrowck-vec-pattern-element-loan.rs:15:25
+error[E0515]: cannot return value referencing local variable `vec`
+  --> $DIR/borrowck-vec-pattern-element-loan.rs:20:5
    |
 LL |     let vec: &[isize] = &vec; //~ ERROR does not live long enough
-   |                         ^^^^ borrowed value does not live long enough
+   |                         ---- `vec` is borrowed here
 ...
-LL | }
-   | - `vec` dropped here while still borrowed
-   |
-note: borrowed value must be valid for the lifetime 'a as defined on the function body at 13:6...
-  --> $DIR/borrowck-vec-pattern-element-loan.rs:13:6
-   |
-LL | fn a<'a>() -> &'a [isize] {
-   |      ^^
+LL |     tail
+   |     ^^^^ returns a value referencing data owned by the current function
 
-error[E0597]: `vec` does not live long enough
-  --> $DIR/borrowck-vec-pattern-element-loan.rs:25:25
+error[E0515]: cannot return value referencing local variable `vec`
+  --> $DIR/borrowck-vec-pattern-element-loan.rs:30:5
    |
 LL |     let vec: &[isize] = &vec; //~ ERROR does not live long enough
-   |                         ^^^^ borrowed value does not live long enough
+   |                         ---- `vec` is borrowed here
 ...
-LL | }
-   | - `vec` dropped here while still borrowed
-   |
-note: borrowed value must be valid for the lifetime 'a as defined on the function body at 23:6...
-  --> $DIR/borrowck-vec-pattern-element-loan.rs:23:6
-   |
-LL | fn b<'a>() -> &'a [isize] {
-   |      ^^
+LL |     init
+   |     ^^^^ returns a value referencing data owned by the current function
 
-error[E0597]: `vec` does not live long enough
-  --> $DIR/borrowck-vec-pattern-element-loan.rs:35:25
+error[E0515]: cannot return value referencing local variable `vec`
+  --> $DIR/borrowck-vec-pattern-element-loan.rs:40:5
    |
 LL |     let vec: &[isize] = &vec; //~ ERROR does not live long enough
-   |                         ^^^^ borrowed value does not live long enough
+   |                         ---- `vec` is borrowed here
 ...
-LL | }
-   | - `vec` dropped here while still borrowed
-   |
-note: borrowed value must be valid for the lifetime 'a as defined on the function body at 33:6...
-  --> $DIR/borrowck-vec-pattern-element-loan.rs:33:6
-   |
-LL | fn c<'a>() -> &'a [isize] {
-   |      ^^
+LL |     slice
+   |     ^^^^^ returns a value referencing data owned by the current function
 
 error: aborting due to 3 previous errors
 
-For more information about this error, try `rustc --explain E0597`.
+For more information about this error, try `rustc --explain E0515`.
index 6d45f1541a0fe532769a71da1e28336fc3c80a4a..dcbc283062ffb32991590dc37c60a4e60fd5f318 100644 (file)
@@ -1,18 +1,12 @@
-error[E0597]: `vec` does not live long enough
-  --> $DIR/borrowck-vec-pattern-tail-element-loan.rs:15:25
+error[E0515]: cannot return value referencing local variable `vec`
+  --> $DIR/borrowck-vec-pattern-tail-element-loan.rs:20:5
    |
 LL |     let vec: &[isize] = &vec; //~ ERROR `vec` does not live long enough
-   |                         ^^^^ borrowed value does not live long enough
+   |                         ---- `vec` is borrowed here
 ...
-LL | }
-   | - `vec` dropped here while still borrowed
-   |
-note: borrowed value must be valid for the lifetime 'a as defined on the function body at 13:6...
-  --> $DIR/borrowck-vec-pattern-tail-element-loan.rs:13:6
-   |
-LL | fn a<'a>() -> &'a isize {
-   |      ^^
+LL |     tail
+   |     ^^^^ returns a value referencing data owned by the current function
 
 error: aborting due to previous error
 
-For more information about this error, try `rustc --explain E0597`.
+For more information about this error, try `rustc --explain E0515`.
index 18411b528a3e30d2455b51cbd20587f4ed5d75de..6588215c221fb9ec27d110e766c4181682814328 100644 (file)
@@ -1,4 +1,4 @@
-error: borrowed data escapes outside of closure
+error[E0521]: borrowed data escapes outside of closure
   --> $DIR/issue-45983.rs:36:18
    |
 LL |     let x = None;
@@ -18,4 +18,5 @@ LL |     give_any(|y| x = Some(y));
 
 error: aborting due to 2 previous errors
 
-For more information about this error, try `rustc --explain E0594`.
+Some errors occurred: E0521, E0594.
+For more information about an error, try `rustc --explain E0521`.
index c6aa243b6cff7d26da06554bde3743acb0b99964..e57c64ae12730394a36d5a5557e18eacdb1f2b0c 100644 (file)
@@ -1,38 +1,38 @@
 error[E0499]: cannot borrow `*arg` as mutable more than once at a time
   --> $DIR/mut-borrow-in-loop.rs:20:25
    |
-LL |             (self.func)(arg) //~ ERROR cannot borrow
-   |                         ^^^ mutable borrow starts here in previous iteration of loop
-   |
-note: first borrowed value must be valid for the lifetime 'a as defined on the impl at 17:6...
-  --> $DIR/mut-borrow-in-loop.rs:17:6
-   |
 LL | impl<'a, T : 'a> FuncWrapper<'a, T> {
-   |      ^^
+   |      -- lifetime `'a` defined here
+...
+LL |             (self.func)(arg) //~ ERROR cannot borrow
+   |             ------------^^^-
+   |             |           |
+   |             |           mutable borrow starts here in previous iteration of loop
+   |             argument requires that `*arg` is borrowed for `'a`
 
 error[E0499]: cannot borrow `*arg` as mutable more than once at a time
   --> $DIR/mut-borrow-in-loop.rs:26:25
    |
-LL |             (self.func)(arg) //~ ERROR cannot borrow
-   |                         ^^^ mutable borrow starts here in previous iteration of loop
-   |
-note: first borrowed value must be valid for the lifetime 'a as defined on the impl at 17:6...
-  --> $DIR/mut-borrow-in-loop.rs:17:6
-   |
 LL | impl<'a, T : 'a> FuncWrapper<'a, T> {
-   |      ^^
+   |      -- lifetime `'a` defined here
+...
+LL |             (self.func)(arg) //~ ERROR cannot borrow
+   |             ------------^^^-
+   |             |           |
+   |             |           mutable borrow starts here in previous iteration of loop
+   |             argument requires that `*arg` is borrowed for `'a`
 
 error[E0499]: cannot borrow `*arg` as mutable more than once at a time
   --> $DIR/mut-borrow-in-loop.rs:33:25
    |
-LL |             (self.func)(arg) //~ ERROR cannot borrow
-   |                         ^^^ mutable borrow starts here in previous iteration of loop
-   |
-note: first borrowed value must be valid for the lifetime 'a as defined on the impl at 17:6...
-  --> $DIR/mut-borrow-in-loop.rs:17:6
-   |
 LL | impl<'a, T : 'a> FuncWrapper<'a, T> {
-   |      ^^
+   |      -- lifetime `'a` defined here
+...
+LL |             (self.func)(arg) //~ ERROR cannot borrow
+   |             ------------^^^-
+   |             |           |
+   |             |           mutable borrow starts here in previous iteration of loop
+   |             argument requires that `*arg` is borrowed for `'a`
 
 error: aborting due to 3 previous errors
 
index 101fb530a91015c95de826d1bf9991c1e85ea8e3..229da2a330bd676697cb23cd0040c9e77943a137 100644 (file)
@@ -1,57 +1,50 @@
-error[E0716]: temporary value dropped while borrowed
-  --> $DIR/promote-ref-mut-in-let-issue-46557.rs:15:21
+error[E0515]: cannot return value referencing temporary value
+  --> $DIR/promote-ref-mut-in-let-issue-46557.rs:16:5
    |
 LL |     let ref mut x = 1234543; //~ ERROR
-   |                     ^^^^^^^ creates a temporary which is freed while still in use
+   |                     ------- temporary value created here
 LL |     x
-LL | }
-   | - temporary value is freed at the end of this statement
-   |
-   = note: borrowed value must be valid for the static lifetime...
+   |     ^ returns a value referencing data owned by the current function
 
-error[E0716]: temporary value dropped while borrowed
-  --> $DIR/promote-ref-mut-in-let-issue-46557.rs:20:25
+error[E0515]: cannot return value referencing temporary value
+  --> $DIR/promote-ref-mut-in-let-issue-46557.rs:21:5
    |
 LL |     let (ref mut x, ) = (1234543, ); //~ ERROR
-   |                         ^^^^^^^^^^^ creates a temporary which is freed while still in use
+   |                         ----------- temporary value created here
 LL |     x
-LL | }
-   | - temporary value is freed at the end of this statement
-   |
-   = note: borrowed value must be valid for the static lifetime...
+   |     ^ returns a value referencing data owned by the current function
 
-error[E0716]: temporary value dropped while borrowed
-  --> $DIR/promote-ref-mut-in-let-issue-46557.rs:25:11
-   |
-LL |     match 1234543 {
-   |           ^^^^^^^ creates a temporary which is freed while still in use
-...
-LL | }
-   | - temporary value is freed at the end of this statement
-   |
-   = note: borrowed value must be valid for the static lifetime...
+error[E0515]: cannot return value referencing temporary value
+  --> $DIR/promote-ref-mut-in-let-issue-46557.rs:25:5
+   |
+LL |       match 1234543 {
+   |       ^     ------- temporary value created here
+   |  _____|
+   | |
+LL | |         ref mut x => x //~ ERROR
+LL | |     }
+   | |_____^ returns a value referencing data owned by the current function
 
-error[E0716]: temporary value dropped while borrowed
-  --> $DIR/promote-ref-mut-in-let-issue-46557.rs:31:11
-   |
-LL |     match (123443,) {
-   |           ^^^^^^^^^ creates a temporary which is freed while still in use
-...
-LL | }
-   | - temporary value is freed at the end of this statement
-   |
-   = note: borrowed value must be valid for the static lifetime...
+error[E0515]: cannot return value referencing temporary value
+  --> $DIR/promote-ref-mut-in-let-issue-46557.rs:31:5
+   |
+LL |       match (123443,) {
+   |       ^     --------- temporary value created here
+   |  _____|
+   | |
+LL | |         (ref mut x,) => x, //~ ERROR
+LL | |     }
+   | |_____^ returns a value referencing data owned by the current function
 
-error[E0716]: temporary value dropped while borrowed
-  --> $DIR/promote-ref-mut-in-let-issue-46557.rs:37:10
+error[E0515]: cannot return reference to temporary value
+  --> $DIR/promote-ref-mut-in-let-issue-46557.rs:37:5
    |
 LL |     &mut 1234543 //~ ERROR
-   |          ^^^^^^^ creates a temporary which is freed while still in use
-LL | }
-   | - temporary value is freed at the end of this statement
-   |
-   = note: borrowed value must be valid for the static lifetime...
+   |     ^^^^^-------
+   |     |    |
+   |     |    temporary value created here
+   |     returns a reference to data owned by the current function
 
 error: aborting due to 5 previous errors
 
-For more information about this error, try `rustc --explain E0716`.
+For more information about this error, try `rustc --explain E0515`.
index b1f947aceb5c86961c48d39b53ea88f4727ec5d2..5a90a9ff52c0830236863abb606309b4ff52681f 100644 (file)
@@ -68,17 +68,15 @@ LL |     reg.register_bound(Box::new(CapturePass::new(&reg.sess_mut)));
 error[E0502]: cannot borrow `*reg` as mutable because it is also borrowed as immutable
   --> $DIR/two-phase-surprise-no-conflict.rs:183:5
    |
+LL | fn register_plugins<'a>(mk_reg: impl Fn() -> &'a mut Registry<'a>) {
+   |                     -- lifetime `'a` defined here
+...
 LL |     reg.register_univ(Box::new(CapturePass::new(&reg.sess_mut)));
-   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-------------^^^
-   |     |                                           |
-   |     |                                           immutable borrow occurs here
+   |     ^^^^^^^^^^^^^^^^^^-----------------------------------------^
+   |     |                 |                         |
+   |     |                 |                         immutable borrow occurs here
+   |     |                 cast requires that `reg.sess_mut` is borrowed for `'a`
    |     mutable borrow occurs here
-   |
-note: immutable borrowed value must be valid for the lifetime 'a as defined on the function body at 122:21...
-  --> $DIR/two-phase-surprise-no-conflict.rs:122:21
-   |
-LL | fn register_plugins<'a>(mk_reg: impl Fn() -> &'a mut Registry<'a>) {
-   |                     ^^
 
 error[E0502]: cannot borrow `*reg` as mutable because it is also borrowed as immutable
   --> $DIR/two-phase-surprise-no-conflict.rs:188:5
@@ -112,17 +110,15 @@ LL |     reg.register_bound(Box::new(CapturePass::new_mut(&mut reg.sess_mut)));
 error[E0499]: cannot borrow `*reg` as mutable more than once at a time
   --> $DIR/two-phase-surprise-no-conflict.rs:206:5
    |
+LL | fn register_plugins<'a>(mk_reg: impl Fn() -> &'a mut Registry<'a>) {
+   |                     -- lifetime `'a` defined here
+...
 LL |     reg.register_univ(Box::new(CapturePass::new_mut(&mut reg.sess_mut)));
-   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-----------------^^^
-   |     |                                               |
-   |     |                                               first mutable borrow occurs here
+   |     ^^^^^^^^^^^^^^^^^^-------------------------------------------------^
+   |     |                 |                             |
+   |     |                 |                             first mutable borrow occurs here
+   |     |                 cast requires that `reg.sess_mut` is borrowed for `'a`
    |     second mutable borrow occurs here
-   |
-note: first borrowed value must be valid for the lifetime 'a as defined on the function body at 122:21...
-  --> $DIR/two-phase-surprise-no-conflict.rs:122:21
-   |
-LL | fn register_plugins<'a>(mk_reg: impl Fn() -> &'a mut Registry<'a>) {
-   |                     ^^
 
 error[E0499]: cannot borrow `reg.sess_mut` as mutable more than once at a time
   --> $DIR/two-phase-surprise-no-conflict.rs:206:53
index bae8b89f3d0f54f355cec75b0e3bd7db726666d3..8c4806cddfe0d40f7b7aa048a5d96afd40339098 100644 (file)
@@ -10,33 +10,33 @@ error[E0716]: temporary value dropped while borrowed
   --> $DIR/dont_promote_unstable_const_fn.rs:28:28
    |
 LL |     let _: &'static u32 = &foo(); //~ ERROR does not live long enough
-   |                            ^^^^^ creates a temporary which is freed while still in use
+   |            ------------    ^^^^^ creates a temporary which is freed while still in use
+   |            |
+   |            type annotation requires that borrow lasts for `'static`
 LL | }
    | - temporary value is freed at the end of this statement
-   |
-   = note: borrowed value must be valid for the static lifetime...
 
 error[E0716]: temporary value dropped while borrowed
   --> $DIR/dont_promote_unstable_const_fn.rs:32:28
    |
 LL |     let _: &'static u32 = &meh(); //~ ERROR does not live long enough
-   |                            ^^^^^ creates a temporary which is freed while still in use
+   |            ------------    ^^^^^ creates a temporary which is freed while still in use
+   |            |
+   |            type annotation requires that borrow lasts for `'static`
 ...
 LL | }
    | - temporary value is freed at the end of this statement
-   |
-   = note: borrowed value must be valid for the static lifetime...
 
 error[E0716]: temporary value dropped while borrowed
   --> $DIR/dont_promote_unstable_const_fn.rs:33:26
    |
 LL |     let x: &'static _ = &std::time::Duration::from_millis(42).subsec_millis();
-   |                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ creates a temporary which is freed while still in use
+   |            ----------    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ creates a temporary which is freed while still in use
+   |            |
+   |            type annotation requires that borrow lasts for `'static`
 LL |     //~^ ERROR does not live long enough
 LL | }
    | - temporary value is freed at the end of this statement
-   |
-   = note: borrowed value must be valid for the static lifetime...
 
 error: aborting due to 4 previous errors
 
index c4feb1129014c1f895ebc2ed4bc2cb0723a716cb..15fd28cd5a50a231050262b525eb87479f792fbc 100644 (file)
@@ -2,22 +2,22 @@ error[E0716]: temporary value dropped while borrowed
   --> $DIR/dont_promote_unstable_const_fn_cross_crate.rs:18:28
    |
 LL |     let _: &'static u32 = &foo(); //~ ERROR does not live long enough
-   |                            ^^^^^ creates a temporary which is freed while still in use
+   |            ------------    ^^^^^ creates a temporary which is freed while still in use
+   |            |
+   |            type annotation requires that borrow lasts for `'static`
 LL |     let _x: &'static u32 = &foo(); //~ ERROR does not live long enough
 LL | }
    | - temporary value is freed at the end of this statement
-   |
-   = note: borrowed value must be valid for the static lifetime...
 
 error[E0716]: temporary value dropped while borrowed
   --> $DIR/dont_promote_unstable_const_fn_cross_crate.rs:19:29
    |
 LL |     let _x: &'static u32 = &foo(); //~ ERROR does not live long enough
-   |                             ^^^^^ creates a temporary which is freed while still in use
+   |             ------------    ^^^^^ creates a temporary which is freed while still in use
+   |             |
+   |             type annotation requires that borrow lasts for `'static`
 LL | }
    | - temporary value is freed at the end of this statement
-   |
-   = note: borrowed value must be valid for the static lifetime...
 
 error: aborting due to 2 previous errors
 
index b8e2d6a96c509c150d48d6aa7d3b33df0d931aad..bd14b1a2b5d41b6522ccc7be7431e2a425baab4a 100644 (file)
@@ -2,12 +2,12 @@ error[E0716]: temporary value dropped while borrowed
   --> $DIR/promoted_const_fn_fail.rs:30:27
    |
 LL |     let x: &'static u8 = &(bar() + 1); //~ ERROR does not live long enough
-   |                           ^^^^^^^^^^^ creates a temporary which is freed while still in use
+   |            -----------    ^^^^^^^^^^^ creates a temporary which is freed while still in use
+   |            |
+   |            type annotation requires that borrow lasts for `'static`
 ...
 LL | }
    | - temporary value is freed at the end of this statement
-   |
-   = note: borrowed value must be valid for the static lifetime...
 
 error: aborting due to previous error
 
index f31d962852e4a92cf13290e7e4f78de240fd09db..7141d7ac8b8625396852c91bb6cee85fc7598781 100644 (file)
@@ -2,44 +2,44 @@ error[E0716]: temporary value dropped while borrowed
   --> $DIR/promoted_raw_ptr_ops.rs:14:29
    |
 LL |     let x: &'static bool = &(42 as *const i32 == 43 as *const i32);
-   |                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ creates a temporary which is freed while still in use
+   |            -------------    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ creates a temporary which is freed while still in use
+   |            |
+   |            type annotation requires that borrow lasts for `'static`
 ...
 LL | }
    | - temporary value is freed at the end of this statement
-   |
-   = note: borrowed value must be valid for the static lifetime...
 
 error[E0716]: temporary value dropped while borrowed
   --> $DIR/promoted_raw_ptr_ops.rs:16:30
    |
 LL |     let y: &'static usize = &(&1 as *const i32 as usize + 1); //~ ERROR does not live long enough
-   |                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ creates a temporary which is freed while still in use
+   |            --------------    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ creates a temporary which is freed while still in use
+   |            |
+   |            type annotation requires that borrow lasts for `'static`
 ...
 LL | }
    | - temporary value is freed at the end of this statement
-   |
-   = note: borrowed value must be valid for the static lifetime...
 
 error[E0716]: temporary value dropped while borrowed
   --> $DIR/promoted_raw_ptr_ops.rs:17:28
    |
 LL |     let z: &'static i32 = &(unsafe { *(42 as *const i32) }); //~ ERROR does not live long enough
-   |                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ creates a temporary which is freed while still in use
+   |            ------------    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ creates a temporary which is freed while still in use
+   |            |
+   |            type annotation requires that borrow lasts for `'static`
 LL |     let a: &'static bool = &(main as fn() == main as fn()); //~ ERROR does not live long enough
 LL | }
    | - temporary value is freed at the end of this statement
-   |
-   = note: borrowed value must be valid for the static lifetime...
 
 error[E0716]: temporary value dropped while borrowed
   --> $DIR/promoted_raw_ptr_ops.rs:18:29
    |
 LL |     let a: &'static bool = &(main as fn() == main as fn()); //~ ERROR does not live long enough
-   |                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ creates a temporary which is freed while still in use
+   |            -------------    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ creates a temporary which is freed while still in use
+   |            |
+   |            type annotation requires that borrow lasts for `'static`
 LL | }
    | - temporary value is freed at the end of this statement
-   |
-   = note: borrowed value must be valid for the static lifetime...
 
 error: aborting due to 4 previous errors
 
index cf3678e7d60ddd97f90c85c276b0da8dc42d1251..a8ae44362660e49b7ccc9b47e3eac9c1e5a52d71 100644 (file)
@@ -2,12 +2,12 @@ error[E0716]: temporary value dropped while borrowed
   --> $DIR/transmute-const-promotion.rs:16:37
    |
 LL |     let x: &'static u32 = unsafe { &mem::transmute(3.0f32) };
-   |                                     ^^^^^^^^^^^^^^^^^^^^^^ creates a temporary which is freed while still in use
+   |            ------------             ^^^^^^^^^^^^^^^^^^^^^^ creates a temporary which is freed while still in use
+   |            |
+   |            type annotation requires that borrow lasts for `'static`
 LL |     //~^ ERROR value does not live long enough
 LL | }
    | - temporary value is freed at the end of this statement
-   |
-   = note: borrowed value must be valid for the static lifetime...
 
 error: aborting due to previous error
 
index afc5c462c4633948f8df7c3b9f6324e36da6159c..60ce75a6f9b3933fc2d603524619f1c6810019cc 100644 (file)
@@ -2,14 +2,14 @@ error[E0716]: temporary value dropped while borrowed
   --> $DIR/union_promotion.rs:19:29
    |
 LL |       let x: &'static bool = &unsafe { //~ borrowed value does not live long enough
-   |  _____________________________^
+   |  ____________-------------____^
+   | |            |
+   | |            type annotation requires that borrow lasts for `'static`
 LL | |         Foo { a: &1 }.b == Foo { a: &2 }.b
 LL | |     };
    | |_____^ creates a temporary which is freed while still in use
 LL |   }
    |   - temporary value is freed at the end of this statement
-   |
-   = note: borrowed value must be valid for the static lifetime...
 
 error: aborting due to previous error
 
index 8fe6816f0b21a18f7731f8c8957741e4143aad45..fbf0803214b5661f54d26f3f0ab85340b8363b1e 100644 (file)
@@ -2,78 +2,78 @@ error[E0716]: temporary value dropped while borrowed
   --> $DIR/const-int-conversion.rs:14:28
    |
 LL |     let x: &'static i32 = &(5_i32.reverse_bits());
-   |                            ^^^^^^^^^^^^^^^^^^^^^^ creates a temporary which is freed while still in use
+   |            ------------    ^^^^^^^^^^^^^^^^^^^^^^ creates a temporary which is freed while still in use
+   |            |
+   |            type annotation requires that borrow lasts for `'static`
 ...
 LL | }
    | - temporary value is freed at the end of this statement
-   |
-   = note: borrowed value must be valid for the static lifetime...
 
 error[E0716]: temporary value dropped while borrowed
   --> $DIR/const-int-conversion.rs:16:28
    |
 LL |     let y: &'static i32 = &(i32::from_be_bytes([0x12, 0x34, 0x56, 0x78]));
-   |                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ creates a temporary which is freed while still in use
+   |            ------------    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ creates a temporary which is freed while still in use
+   |            |
+   |            type annotation requires that borrow lasts for `'static`
 ...
 LL | }
    | - temporary value is freed at the end of this statement
-   |
-   = note: borrowed value must be valid for the static lifetime...
 
 error[E0716]: temporary value dropped while borrowed
   --> $DIR/const-int-conversion.rs:18:28
    |
 LL |     let z: &'static i32 = &(i32::from_le_bytes([0x12, 0x34, 0x56, 0x78]));
-   |                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ creates a temporary which is freed while still in use
+   |            ------------    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ creates a temporary which is freed while still in use
+   |            |
+   |            type annotation requires that borrow lasts for `'static`
 ...
 LL | }
    | - temporary value is freed at the end of this statement
-   |
-   = note: borrowed value must be valid for the static lifetime...
 
 error[E0716]: temporary value dropped while borrowed
   --> $DIR/const-int-conversion.rs:20:28
    |
 LL |     let a: &'static i32 = &(i32::from_be(i32::from_ne_bytes([0x80, 0, 0, 0])));
-   |                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ creates a temporary which is freed while still in use
+   |            ------------    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ creates a temporary which is freed while still in use
+   |            |
+   |            type annotation requires that borrow lasts for `'static`
 ...
 LL | }
    | - temporary value is freed at the end of this statement
-   |
-   = note: borrowed value must be valid for the static lifetime...
 
 error[E0716]: temporary value dropped while borrowed
   --> $DIR/const-int-conversion.rs:22:29
    |
 LL |     let b: &'static [u8] = &(0x12_34_56_78_i32.to_be_bytes());
-   |                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ creates a temporary which is freed while still in use
+   |            -------------    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ creates a temporary which is freed while still in use
+   |            |
+   |            type annotation requires that borrow lasts for `'static`
 ...
 LL | }
    | - temporary value is freed at the end of this statement
-   |
-   = note: borrowed value must be valid for the static lifetime...
 
 error[E0716]: temporary value dropped while borrowed
   --> $DIR/const-int-conversion.rs:24:29
    |
 LL |     let c: &'static [u8] = &(0x12_34_56_78_i32.to_le_bytes());
-   |                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ creates a temporary which is freed while still in use
+   |            -------------    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ creates a temporary which is freed while still in use
+   |            |
+   |            type annotation requires that borrow lasts for `'static`
 ...
 LL | }
    | - temporary value is freed at the end of this statement
-   |
-   = note: borrowed value must be valid for the static lifetime...
 
 error[E0716]: temporary value dropped while borrowed
   --> $DIR/const-int-conversion.rs:26:29
    |
 LL |     let d: &'static [u8] = &(i32::min_value().to_be().to_ne_bytes());
-   |                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ creates a temporary which is freed while still in use
+   |            -------------    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ creates a temporary which is freed while still in use
+   |            |
+   |            type annotation requires that borrow lasts for `'static`
 LL |         //~^ ERROR does not live long enough
 LL | }
    | - temporary value is freed at the end of this statement
-   |
-   = note: borrowed value must be valid for the static lifetime...
 
 error: aborting due to 7 previous errors
 
index 3f4a7562ce9b011c45328bc8d8b8d7e9ac55e0e4..64ea01dd1d6ac0659b2f31c95da8f1e861383692 100644 (file)
@@ -2,33 +2,33 @@ error[E0716]: temporary value dropped while borrowed
   --> $DIR/const-int-overflowing.rs:12:36
    |
 LL |     let x: &'static (i32, bool) = &(5_i32.overflowing_add(3)); //~ ERROR does not live long enough
-   |                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^ creates a temporary which is freed while still in use
+   |            --------------------    ^^^^^^^^^^^^^^^^^^^^^^^^^^ creates a temporary which is freed while still in use
+   |            |
+   |            type annotation requires that borrow lasts for `'static`
 ...
 LL | }
    | - temporary value is freed at the end of this statement
-   |
-   = note: borrowed value must be valid for the static lifetime...
 
 error[E0716]: temporary value dropped while borrowed
   --> $DIR/const-int-overflowing.rs:13:36
    |
 LL |     let y: &'static (i32, bool) = &(5_i32.overflowing_sub(3)); //~ ERROR does not live long enough
-   |                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^ creates a temporary which is freed while still in use
+   |            --------------------    ^^^^^^^^^^^^^^^^^^^^^^^^^^ creates a temporary which is freed while still in use
+   |            |
+   |            type annotation requires that borrow lasts for `'static`
 LL |     let z: &'static (i32, bool) = &(5_i32.overflowing_mul(3)); //~ ERROR does not live long enough
 LL | }
    | - temporary value is freed at the end of this statement
-   |
-   = note: borrowed value must be valid for the static lifetime...
 
 error[E0716]: temporary value dropped while borrowed
   --> $DIR/const-int-overflowing.rs:14:36
    |
 LL |     let z: &'static (i32, bool) = &(5_i32.overflowing_mul(3)); //~ ERROR does not live long enough
-   |                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^ creates a temporary which is freed while still in use
+   |            --------------------    ^^^^^^^^^^^^^^^^^^^^^^^^^^ creates a temporary which is freed while still in use
+   |            |
+   |            type annotation requires that borrow lasts for `'static`
 LL | }
    | - temporary value is freed at the end of this statement
-   |
-   = note: borrowed value must be valid for the static lifetime...
 
 error: aborting due to 3 previous errors
 
index 8a0c49a6d845138776ad491787dd773dae465374..a8a7973bc03beba6311e0d34150b7409c21ac829 100644 (file)
@@ -2,22 +2,22 @@ error[E0716]: temporary value dropped while borrowed
   --> $DIR/const-int-rotate.rs:12:28
    |
 LL |     let x: &'static i32 = &(5_i32.rotate_left(3)); //~ ERROR does not live long enough
-   |                            ^^^^^^^^^^^^^^^^^^^^^^ creates a temporary which is freed while still in use
+   |            ------------    ^^^^^^^^^^^^^^^^^^^^^^ creates a temporary which is freed while still in use
+   |            |
+   |            type annotation requires that borrow lasts for `'static`
 LL |     let y: &'static i32 = &(5_i32.rotate_right(3)); //~ ERROR does not live long enough
 LL | }
    | - temporary value is freed at the end of this statement
-   |
-   = note: borrowed value must be valid for the static lifetime...
 
 error[E0716]: temporary value dropped while borrowed
   --> $DIR/const-int-rotate.rs:13:28
    |
 LL |     let y: &'static i32 = &(5_i32.rotate_right(3)); //~ ERROR does not live long enough
-   |                            ^^^^^^^^^^^^^^^^^^^^^^^ creates a temporary which is freed while still in use
+   |            ------------    ^^^^^^^^^^^^^^^^^^^^^^^ creates a temporary which is freed while still in use
+   |            |
+   |            type annotation requires that borrow lasts for `'static`
 LL | }
    | - temporary value is freed at the end of this statement
-   |
-   = note: borrowed value must be valid for the static lifetime...
 
 error: aborting due to 2 previous errors
 
index 53bcba8c77e542daa1a49395ec2b4d965184b326..afc994457b6cccf0ea74a2de83a222a780cfbff4 100644 (file)
@@ -2,22 +2,22 @@ error[E0716]: temporary value dropped while borrowed
   --> $DIR/const-int-sign.rs:12:29
    |
 LL |     let x: &'static bool = &(5_i32.is_negative()); //~ ERROR does not live long enough
-   |                             ^^^^^^^^^^^^^^^^^^^^^ creates a temporary which is freed while still in use
+   |            -------------    ^^^^^^^^^^^^^^^^^^^^^ creates a temporary which is freed while still in use
+   |            |
+   |            type annotation requires that borrow lasts for `'static`
 LL |     let y: &'static bool = &(5_i32.is_positive()); //~ ERROR does not live long enough
 LL | }
    | - temporary value is freed at the end of this statement
-   |
-   = note: borrowed value must be valid for the static lifetime...
 
 error[E0716]: temporary value dropped while borrowed
   --> $DIR/const-int-sign.rs:13:29
    |
 LL |     let y: &'static bool = &(5_i32.is_positive()); //~ ERROR does not live long enough
-   |                             ^^^^^^^^^^^^^^^^^^^^^ creates a temporary which is freed while still in use
+   |            -------------    ^^^^^^^^^^^^^^^^^^^^^ creates a temporary which is freed while still in use
+   |            |
+   |            type annotation requires that borrow lasts for `'static`
 LL | }
    | - temporary value is freed at the end of this statement
-   |
-   = note: borrowed value must be valid for the static lifetime...
 
 error: aborting due to 2 previous errors
 
index 3fd83090a4df5390b65e9da6923f6dd695c02387..4f89c79b83bf08af6a925ea185254f79874b2e89 100644 (file)
@@ -2,55 +2,55 @@ error[E0716]: temporary value dropped while borrowed
   --> $DIR/const-int-wrapping.rs:12:28
    |
 LL |     let x: &'static i32 = &(5_i32.wrapping_add(3)); //~ ERROR does not live long enough
-   |                            ^^^^^^^^^^^^^^^^^^^^^^^ creates a temporary which is freed while still in use
+   |            ------------    ^^^^^^^^^^^^^^^^^^^^^^^ creates a temporary which is freed while still in use
+   |            |
+   |            type annotation requires that borrow lasts for `'static`
 ...
 LL | }
    | - temporary value is freed at the end of this statement
-   |
-   = note: borrowed value must be valid for the static lifetime...
 
 error[E0716]: temporary value dropped while borrowed
   --> $DIR/const-int-wrapping.rs:13:28
    |
 LL |     let y: &'static i32 = &(5_i32.wrapping_sub(3)); //~ ERROR does not live long enough
-   |                            ^^^^^^^^^^^^^^^^^^^^^^^ creates a temporary which is freed while still in use
+   |            ------------    ^^^^^^^^^^^^^^^^^^^^^^^ creates a temporary which is freed while still in use
+   |            |
+   |            type annotation requires that borrow lasts for `'static`
 ...
 LL | }
    | - temporary value is freed at the end of this statement
-   |
-   = note: borrowed value must be valid for the static lifetime...
 
 error[E0716]: temporary value dropped while borrowed
   --> $DIR/const-int-wrapping.rs:14:28
    |
 LL |     let z: &'static i32 = &(5_i32.wrapping_mul(3)); //~ ERROR does not live long enough
-   |                            ^^^^^^^^^^^^^^^^^^^^^^^ creates a temporary which is freed while still in use
+   |            ------------    ^^^^^^^^^^^^^^^^^^^^^^^ creates a temporary which is freed while still in use
+   |            |
+   |            type annotation requires that borrow lasts for `'static`
 ...
 LL | }
    | - temporary value is freed at the end of this statement
-   |
-   = note: borrowed value must be valid for the static lifetime...
 
 error[E0716]: temporary value dropped while borrowed
   --> $DIR/const-int-wrapping.rs:15:28
    |
 LL |     let a: &'static i32 = &(5_i32.wrapping_shl(3)); //~ ERROR does not live long enough
-   |                            ^^^^^^^^^^^^^^^^^^^^^^^ creates a temporary which is freed while still in use
+   |            ------------    ^^^^^^^^^^^^^^^^^^^^^^^ creates a temporary which is freed while still in use
+   |            |
+   |            type annotation requires that borrow lasts for `'static`
 LL |     let b: &'static i32 = &(5_i32.wrapping_shr(3)); //~ ERROR does not live long enough
 LL | }
    | - temporary value is freed at the end of this statement
-   |
-   = note: borrowed value must be valid for the static lifetime...
 
 error[E0716]: temporary value dropped while borrowed
   --> $DIR/const-int-wrapping.rs:16:28
    |
 LL |     let b: &'static i32 = &(5_i32.wrapping_shr(3)); //~ ERROR does not live long enough
-   |                            ^^^^^^^^^^^^^^^^^^^^^^^ creates a temporary which is freed while still in use
+   |            ------------    ^^^^^^^^^^^^^^^^^^^^^^^ creates a temporary which is freed while still in use
+   |            |
+   |            type annotation requires that borrow lasts for `'static`
 LL | }
    | - temporary value is freed at the end of this statement
-   |
-   = note: borrowed value must be valid for the static lifetime...
 
 error: aborting due to 5 previous errors
 
index 39879254cf85d87b819c30099ac362902b8e0919..451f49c1cb57abecf1253e7298ccedeabcc1b9e6 100644 (file)
@@ -2,21 +2,21 @@ error[E0716]: temporary value dropped while borrowed
   --> $DIR/issue-54224.rs:3:39
    |
 LL | const FOO: Option<&[[u8; 3]]> = Some(&[*b"foo"]); //~ ERROR temporary value dropped while borrowed
-   |                                       ^^^^^^^^^- temporary value is freed at the end of this statement
-   |                                       |
-   |                                       creates a temporary which is freed while still in use
-   |
-   = note: borrowed value must be valid for the static lifetime...
+   |                                 ------^^^^^^^^^-
+   |                                 |     |        |
+   |                                 |     |        temporary value is freed at the end of this statement
+   |                                 |     creates a temporary which is freed while still in use
+   |                                 using this value as a constant requires that borrow lasts for `'static`
 
 error[E0716]: temporary value dropped while borrowed
   --> $DIR/issue-54224.rs:11:57
    |
 LL | pub const Z: Cow<'static, [ [u8; 3] ]> = Cow::Borrowed(&[*b"ABC"]);
-   |                                                         ^^^^^^^^^- temporary value is freed at the end of this statement
-   |                                                         |
-   |                                                         creates a temporary which is freed while still in use
-   |
-   = note: borrowed value must be valid for the static lifetime...
+   |                                          ---------------^^^^^^^^^-
+   |                                          |              |        |
+   |                                          |              |        temporary value is freed at the end of this statement
+   |                                          |              creates a temporary which is freed while still in use
+   |                                          using this value as a constant requires that borrow lasts for `'static`
 
 error: aborting due to 2 previous errors
 
index 38937904f47d6f402454d863fbd8f8b1e6666aef..f43befb37c134ad72629ffde0c713f995dc34081 100644 (file)
@@ -190,15 +190,15 @@ error: trait bounds other than `Sized` on const fn parameters are unstable
 LL | const fn no_dyn_trait_ret() -> &'static dyn std::fmt::Debug { &() }
    |                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
-warning[E0716]: temporary value dropped while borrowed
-  --> $DIR/min_const_fn.rs:142:64
+warning[E0515]: cannot return reference to temporary value
+  --> $DIR/min_const_fn.rs:142:63
    |
 LL | const fn no_dyn_trait_ret() -> &'static dyn std::fmt::Debug { &() }
-   |                                                                ^^ - temporary value is freed at the end of this statement
-   |                                                                |
-   |                                                                creates a temporary which is freed while still in use
+   |                                                               ^--
+   |                                                               ||
+   |                                                               |temporary value created here
+   |                                                               returns a reference to data owned by the current function
    |
-   = note: borrowed value must be valid for the static lifetime...
    = warning: This error has been downgraded to a warning for backwards compatibility with previous releases.
            It represents potential unsoundness in your code.
            This warning will become a hard error in the future.
@@ -223,5 +223,5 @@ LL | const fn no_fn_ptrs2() -> fn() { fn foo() {} foo }
 
 error: aborting due to 35 previous errors
 
-Some errors occurred: E0493, E0716.
+Some errors occurred: E0493, E0515.
 For more information about an error, try `rustc --explain E0493`.
index a1d40cbfd46ad335f0a66069d9438cd9b45050e6..4ec00a164566a899faadf02060660d6019ecb6f0 100644 (file)
@@ -14,11 +14,11 @@ warning[E0716]: temporary value dropped while borrowed
   --> $DIR/min_const_fn_dyn.rs:22:67
    |
 LL | const fn no_inner_dyn_trait_ret() -> Hide { Hide(HasDyn { field: &0 }) }
-   |                                                                   ^    - temporary value is freed at the end of this statement
-   |                                                                   |
-   |                                                                   creates a temporary which is freed while still in use
+   |                                                                  -^    - temporary value is freed at the end of this statement
+   |                                                                  ||
+   |                                                                  |creates a temporary which is freed while still in use
+   |                                                                  cast requires that borrow lasts for `'static`
    |
-   = note: borrowed value must be valid for the static lifetime...
    = warning: This error has been downgraded to a warning for backwards compatibility with previous releases.
            It represents potential unsoundness in your code.
            This warning will become a hard error in the future.
index 396b58dd219d8d57532fd34173b625a773cb4781..eb186ce4951372189cb8f8c32096cf53bd5b3639 100644 (file)
@@ -2,66 +2,66 @@ error[E0716]: temporary value dropped while borrowed
   --> $DIR/promotion.rs:11:27
    |
 LL |     let x: &'static () = &foo1(); //~ ERROR does not live long enough
-   |                           ^^^^^^ creates a temporary which is freed while still in use
+   |            -----------    ^^^^^^ creates a temporary which is freed while still in use
+   |            |
+   |            type annotation requires that borrow lasts for `'static`
 ...
 LL | }
    | - temporary value is freed at the end of this statement
-   |
-   = note: borrowed value must be valid for the static lifetime...
 
 error[E0716]: temporary value dropped while borrowed
   --> $DIR/promotion.rs:12:28
    |
 LL |     let y: &'static i32 = &foo2(42); //~ ERROR does not live long enough
-   |                            ^^^^^^^^ creates a temporary which is freed while still in use
+   |            ------------    ^^^^^^^^ creates a temporary which is freed while still in use
+   |            |
+   |            type annotation requires that borrow lasts for `'static`
 ...
 LL | }
    | - temporary value is freed at the end of this statement
-   |
-   = note: borrowed value must be valid for the static lifetime...
 
 error[E0716]: temporary value dropped while borrowed
   --> $DIR/promotion.rs:13:28
    |
 LL |     let z: &'static i32 = &foo3(); //~ ERROR does not live long enough
-   |                            ^^^^^^ creates a temporary which is freed while still in use
+   |            ------------    ^^^^^^ creates a temporary which is freed while still in use
+   |            |
+   |            type annotation requires that borrow lasts for `'static`
 ...
 LL | }
    | - temporary value is freed at the end of this statement
-   |
-   = note: borrowed value must be valid for the static lifetime...
 
 error[E0716]: temporary value dropped while borrowed
   --> $DIR/promotion.rs:14:34
    |
 LL |     let a: &'static Cell<i32> = &foo4();  //~ ERROR does not live long enough
-   |                                  ^^^^^^ creates a temporary which is freed while still in use
+   |            ------------------    ^^^^^^ creates a temporary which is freed while still in use
+   |            |
+   |            type annotation requires that borrow lasts for `'static`
 ...
 LL | }
    | - temporary value is freed at the end of this statement
-   |
-   = note: borrowed value must be valid for the static lifetime...
 
 error[E0716]: temporary value dropped while borrowed
   --> $DIR/promotion.rs:15:42
    |
 LL |     let a: &'static Option<Cell<i32>> = &foo5(); //~ ERROR does not live long enough
-   |                                          ^^^^^^ creates a temporary which is freed while still in use
+   |            --------------------------    ^^^^^^ creates a temporary which is freed while still in use
+   |            |
+   |            type annotation requires that borrow lasts for `'static`
 LL |     let a: &'static Option<Cell<i32>> = &foo6(); //~ ERROR does not live long enough
 LL | }
    | - temporary value is freed at the end of this statement
-   |
-   = note: borrowed value must be valid for the static lifetime...
 
 error[E0716]: temporary value dropped while borrowed
   --> $DIR/promotion.rs:16:42
    |
 LL |     let a: &'static Option<Cell<i32>> = &foo6(); //~ ERROR does not live long enough
-   |                                          ^^^^^^ creates a temporary which is freed while still in use
+   |            --------------------------    ^^^^^^ creates a temporary which is freed while still in use
+   |            |
+   |            type annotation requires that borrow lasts for `'static`
 LL | }
    | - temporary value is freed at the end of this statement
-   |
-   = note: borrowed value must be valid for the static lifetime...
 
 error: aborting due to 6 previous errors
 
index 4f792a9c9d28f5635ba68f03dba751bc60590232..6200ec3722cbf88159f6d415c2c9900b0702d9e5 100644 (file)
@@ -1,18 +1,12 @@
-error[E0597]: `raw_lines` does not live long enough
+error[E0515]: cannot return value referencing local variable `raw_lines`
   --> $DIR/drop-with-active-borrows-2.rs:13:5
    |
 LL |     raw_lines.iter().map(|l| l.trim()).collect()
-   |     ^^^^^^^^^ borrowed value does not live long enough
-LL |     //~^ ERROR `raw_lines` does not live long enough
-LL | }
-   | - `raw_lines` dropped here while still borrowed
-   |
-note: borrowed value must be valid for the lifetime 'a as defined on the function body at 11:24...
-  --> $DIR/drop-with-active-borrows-2.rs:11:24
-   |
-LL | fn read_lines_borrowed<'a>() -> Vec<&'a str> {
-   |                        ^^
+   |     ---------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |     |
+   |     returns a value referencing data owned by the current function
+   |     `raw_lines` is borrowed here
 
 error: aborting due to previous error
 
-For more information about this error, try `rustc --explain E0597`.
+For more information about this error, try `rustc --explain E0515`.
index a47229cdca0bb90c707aa09726b7a5751aed2b92..d4b74841b0db71fa8685a7ec3fa08061cdf7ce56 100644 (file)
@@ -1,67 +1,72 @@
 error[E0597]: `o2` does not live long enough
   --> $DIR/dropck_trait_cycle_checked.rs:121:13
    |
+LL |     let (o1, o2, o3): (Box<Obj>, Box<Obj>, Box<Obj>) = (O::new(), O::new(), O::new());
+   |                                                                   -------- cast requires that `o2` is borrowed for `'static`
 LL |     o1.set0(&o2); //~ ERROR `o2` does not live long enough
    |             ^^^ borrowed value does not live long enough
 ...
 LL | }
    | - `o2` dropped here while still borrowed
-   |
-   = note: borrowed value must be valid for the static lifetime...
 
 error[E0597]: `o3` does not live long enough
   --> $DIR/dropck_trait_cycle_checked.rs:122:13
    |
+LL |     let (o1, o2, o3): (Box<Obj>, Box<Obj>, Box<Obj>) = (O::new(), O::new(), O::new());
+   |                                                                             -------- cast requires that `o3` is borrowed for `'static`
+LL |     o1.set0(&o2); //~ ERROR `o2` does not live long enough
 LL |     o1.set1(&o3); //~ ERROR `o3` does not live long enough
    |             ^^^ borrowed value does not live long enough
 ...
 LL | }
    | - `o3` dropped here while still borrowed
-   |
-   = note: borrowed value must be valid for the static lifetime...
 
 error[E0597]: `o2` does not live long enough
   --> $DIR/dropck_trait_cycle_checked.rs:123:13
    |
+LL |     let (o1, o2, o3): (Box<Obj>, Box<Obj>, Box<Obj>) = (O::new(), O::new(), O::new());
+   |                                                                   -------- cast requires that `o2` is borrowed for `'static`
+...
 LL |     o2.set0(&o2); //~ ERROR `o2` does not live long enough
    |             ^^^ borrowed value does not live long enough
 ...
 LL | }
    | - `o2` dropped here while still borrowed
-   |
-   = note: borrowed value must be valid for the static lifetime...
 
 error[E0597]: `o3` does not live long enough
   --> $DIR/dropck_trait_cycle_checked.rs:124:13
    |
+LL |     let (o1, o2, o3): (Box<Obj>, Box<Obj>, Box<Obj>) = (O::new(), O::new(), O::new());
+   |                                                                             -------- cast requires that `o3` is borrowed for `'static`
+...
 LL |     o2.set1(&o3); //~ ERROR `o3` does not live long enough
    |             ^^^ borrowed value does not live long enough
 ...
 LL | }
    | - `o3` dropped here while still borrowed
-   |
-   = note: borrowed value must be valid for the static lifetime...
 
 error[E0597]: `o1` does not live long enough
   --> $DIR/dropck_trait_cycle_checked.rs:125:13
    |
+LL |     let (o1, o2, o3): (Box<Obj>, Box<Obj>, Box<Obj>) = (O::new(), O::new(), O::new());
+   |                                                         -------- cast requires that `o1` is borrowed for `'static`
+...
 LL |     o3.set0(&o1); //~ ERROR `o1` does not live long enough
    |             ^^^ borrowed value does not live long enough
 LL |     o3.set1(&o2); //~ ERROR `o2` does not live long enough
 LL | }
    | - `o1` dropped here while still borrowed
-   |
-   = note: borrowed value must be valid for the static lifetime...
 
 error[E0597]: `o2` does not live long enough
   --> $DIR/dropck_trait_cycle_checked.rs:126:13
    |
+LL |     let (o1, o2, o3): (Box<Obj>, Box<Obj>, Box<Obj>) = (O::new(), O::new(), O::new());
+   |                                                                   -------- cast requires that `o2` is borrowed for `'static`
+...
 LL |     o3.set1(&o2); //~ ERROR `o2` does not live long enough
    |             ^^^ borrowed value does not live long enough
 LL | }
    | - `o2` dropped here while still borrowed
-   |
-   = note: borrowed value must be valid for the static lifetime...
 
 error: aborting due to 6 previous errors
 
index bc5b4ca71cfd45d23c47910bd05ba5e5669fb33a..4f85266e3fd7fa3203c927745b4760097da4af02 100644 (file)
@@ -1,62 +1,57 @@
 error[E0597]: `f1` does not live long enough
   --> $DIR/dst-bad-coerce3.rs:26:32
    |
+LL | fn baz<'a>() {
+   |        -- lifetime `'a` defined here
+...
 LL |     let f2: &Fat<[isize; 3]> = &f1; //~ ERROR `f1` does not live long enough
    |                                ^^^ borrowed value does not live long enough
+LL |     let f3: &'a Fat<[isize]> = f2;
+   |             ---------------- type annotation requires that `f1` is borrowed for `'a`
 ...
 LL | }
    | - `f1` dropped here while still borrowed
-   |
-note: borrowed value must be valid for the lifetime 'a as defined on the function body at 23:8...
-  --> $DIR/dst-bad-coerce3.rs:23:8
-   |
-LL | fn baz<'a>() {
-   |        ^^
 
 error[E0597]: `f1` does not live long enough
   --> $DIR/dst-bad-coerce3.rs:31:25
    |
+LL | fn baz<'a>() {
+   |        -- lifetime `'a` defined here
+...
 LL |     let f2: &Fat<Foo> = &f1; //~ ERROR `f1` does not live long enough
    |                         ^^^ borrowed value does not live long enough
+LL |     let f3: &'a Fat<Bar> = f2;
+   |             ------------ type annotation requires that `f1` is borrowed for `'a`
 ...
 LL | }
    | - `f1` dropped here while still borrowed
-   |
-note: borrowed value must be valid for the lifetime 'a as defined on the function body at 23:8...
-  --> $DIR/dst-bad-coerce3.rs:23:8
-   |
-LL | fn baz<'a>() {
-   |        ^^
 
 error[E0597]: `f1` does not live long enough
   --> $DIR/dst-bad-coerce3.rs:36:30
    |
+LL | fn baz<'a>() {
+   |        -- lifetime `'a` defined here
+...
 LL |     let f2: &([isize; 3],) = &f1; //~ ERROR `f1` does not live long enough
    |                              ^^^ borrowed value does not live long enough
+LL |     let f3: &'a ([isize],) = f2;
+   |             -------------- type annotation requires that `f1` is borrowed for `'a`
 ...
 LL | }
    | - `f1` dropped here while still borrowed
-   |
-note: borrowed value must be valid for the lifetime 'a as defined on the function body at 23:8...
-  --> $DIR/dst-bad-coerce3.rs:23:8
-   |
-LL | fn baz<'a>() {
-   |        ^^
 
 error[E0597]: `f1` does not live long enough
   --> $DIR/dst-bad-coerce3.rs:41:23
    |
+LL | fn baz<'a>() {
+   |        -- lifetime `'a` defined here
+...
 LL |     let f2: &(Foo,) = &f1; //~ ERROR `f1` does not live long enough
    |                       ^^^ borrowed value does not live long enough
 LL |     let f3: &'a (Bar,) = f2;
+   |             ---------- type annotation requires that `f1` is borrowed for `'a`
 LL | }
    | - `f1` dropped here while still borrowed
-   |
-note: borrowed value must be valid for the lifetime 'a as defined on the function body at 23:8...
-  --> $DIR/dst-bad-coerce3.rs:23:8
-   |
-LL | fn baz<'a>() {
-   |        ^^
 
 error: aborting due to 4 previous errors
 
index 5d1050dc3526e490f52cb892a30541ee85ed4699..6a423aea7eceb24e6046d4106e9b38d89eb4aa35 100644 (file)
@@ -1,11 +1,11 @@
 error[E0621]: explicit lifetime required in the type of `x`
-  --> $DIR/generator-region-requirements.rs:11:9
+  --> $DIR/generator-region-requirements.rs:15:51
    |
 LL | fn dangle(x: &mut i32) -> &'static mut i32 {
    |              -------- help: add explicit lifetime `'static` to the type of `x`: `&'static mut i32`
 ...
-LL |         x
-   |         ^ lifetime `'static` required
+LL |             GeneratorState::Complete(c) => return c,
+   |                                                   ^ lifetime `'static` required
 
 error: aborting due to previous error
 
index 56d853c2966c5de5b0e2f6cc89d9eecd64a37122..b9096c42a0d420bb0f929b23c9bc49302a0a6914 100644 (file)
@@ -1,12 +1,15 @@
-error[E0597]: `b` does not live long enough
-  --> $DIR/ref-escapes-but-not-over-yield.rs:24:13
+error[E0521]: borrowed data escapes outside of generator
+  --> $DIR/ref-escapes-but-not-over-yield.rs:24:9
    |
+LL |     let mut a = &3;
+   |         ----- `a` is declared here, outside of the generator body
+...
 LL |         a = &b;
-   |             ^^ borrowed value does not live long enough
-LL |         //~^ ERROR `b` does not live long enough
-LL |     };
-   |     - `b` dropped here while still borrowed
+   |         ^^^^--
+   |         |   |
+   |         |   borrow is only valid in the generator body
+   |         reference to `b` escapes the generator body here
 
 error: aborting due to previous error
 
-For more information about this error, try `rustc --explain E0597`.
+For more information about this error, try `rustc --explain E0521`.
index f818f5b6195f356196e12e482efc5faa63aa9a5d..0ea60fdf461056ace4f99833e990b88f45ab2218 100644 (file)
@@ -1,18 +1,11 @@
-error[E0716]: temporary value dropped while borrowed
-  --> $DIR/issue-11681.rs:22:20
+error[E0515]: cannot return value referencing temporary value
+  --> $DIR/issue-11681.rs:23:10
    |
 LL |   let testValue = &Test; //~ ERROR borrowed value does not live long enough
-   |                    ^^^^ creates a temporary which is freed while still in use
+   |                    ---- temporary value created here
 LL |   return testValue;
-LL | }
-   | - temporary value is freed at the end of this statement
-   |
-note: borrowed value must be valid for the lifetime 'a as defined on the function body at 21:15...
-  --> $DIR/issue-11681.rs:21:15
-   |
-LL | fn createTest<'a>() -> &'a Test {
-   |               ^^
+   |          ^^^^^^^^^ returns a value referencing data owned by the current function
 
 error: aborting due to previous error
 
-For more information about this error, try `rustc --explain E0716`.
+For more information about this error, try `rustc --explain E0515`.
index 6eb2765514054d15f2e0eddbd297ecb495f193c4..af4fa8de0e93fa1b8485f987d70ed4c99ab96584 100644 (file)
@@ -1,18 +1,11 @@
-error[E0597]: `*b` does not live long enough
-  --> $DIR/issue-12470.rs:38:18
+error[E0515]: cannot return value referencing local data `*b`
+  --> $DIR/issue-12470.rs:39:5
    |
 LL |     let bb: &B = &*b;    //~ ERROR does not live long enough
-   |                  ^^^ borrowed value does not live long enough
+   |                  --- `*b` is borrowed here
 LL |     make_a(bb)
-LL | }
-   | - `*b` dropped here while still borrowed
-   |
-note: borrowed value must be valid for the lifetime 'a as defined on the function body at 36:16...
-  --> $DIR/issue-12470.rs:36:16
-   |
-LL | fn make_make_a<'a>() -> A<'a> {
-   |                ^^
+   |     ^^^^^^^^^^ returns a value referencing data owned by the current function
 
 error: aborting due to previous error
 
-For more information about this error, try `rustc --explain E0597`.
+For more information about this error, try `rustc --explain E0515`.
index 5c592f6f37523e4454bf6bf65bd78c5ac5691ae8..e66afef93143a1c8ac51b6007ff73be6c35e0cf5 100644 (file)
@@ -1,18 +1,14 @@
-error[E0597]: `rawLines` does not live long enough
+error[E0515]: cannot return value referencing local variable `rawLines`
   --> $DIR/issue-13497-2.rs:13:5
    |
-LL |     rawLines //~ ERROR `rawLines` does not live long enough
-   |     ^^^^^^^^ borrowed value does not live long enough
-LL |         .iter().map(|l| l.trim()).collect()
-LL | }
-   | - `rawLines` dropped here while still borrowed
-   |
-note: borrowed value must be valid for the lifetime 'a as defined on the function body at 11:24...
-  --> $DIR/issue-13497-2.rs:11:24
-   |
-LL | fn read_lines_borrowed<'a>() -> Vec<&'a str> {
-   |                        ^^
+LL |       rawLines //~ ERROR `rawLines` does not live long enough
+   |       ^-------
+   |       |
+   |  _____`rawLines` is borrowed here
+   | |
+LL | |         .iter().map(|l| l.trim()).collect()
+   | |___________________________________________^ returns a value referencing data owned by the current function
 
 error: aborting due to previous error
 
-For more information about this error, try `rustc --explain E0597`.
+For more information about this error, try `rustc --explain E0515`.
index 889bfa07ab9be6ffec86bf99f4e00ffebce78930..b64bbe10477a6c42252cb0a5bbbec59895c79bb8 100644 (file)
@@ -1,16 +1,15 @@
 error[E0716]: temporary value dropped while borrowed
   --> $DIR/issue-17545.rs:17:10
    |
-LL |         &id(()), //~ ERROR borrowed value does not live long enough
-   |          ^^^^^^ creates a temporary which is freed while still in use
-LL |     ));
-   |       - temporary value is freed at the end of this statement
-   |
-note: borrowed value must be valid for the lifetime 'a as defined on the function body at 15:12...
-  --> $DIR/issue-17545.rs:15:12
-   |
-LL | pub fn foo<'a, F: Fn(&'a ())>(bar: F) {
-   |            ^^
+LL |   pub fn foo<'a, F: Fn(&'a ())>(bar: F) {
+   |              -- lifetime `'a` defined here
+LL | /     bar.call((
+LL | |         &id(()), //~ ERROR borrowed value does not live long enough
+   | |          ^^^^^^ creates a temporary which is freed while still in use
+LL | |     ));
+   | |      -- temporary value is freed at the end of this statement
+   | |______|
+   |        argument requires that borrow lasts for `'a`
 
 error: aborting due to previous error
 
index 03fc31b7a7b54819c5f3de08bf844d4b622b6121..b59bd5a0f9725025a431ac3d52a45061469c8563 100644 (file)
@@ -1,13 +1,12 @@
-error[E0716]: temporary value dropped while borrowed
-  --> $DIR/issue-17718-constants-not-static.rs:15:31
+error[E0515]: cannot return reference to temporary value
+  --> $DIR/issue-17718-constants-not-static.rs:15:30
    |
 LL | fn foo() -> &'static usize { &id(FOO) }
-   |                               ^^^^^^^ - temporary value is freed at the end of this statement
-   |                               |
-   |                               creates a temporary which is freed while still in use
-   |
-   = note: borrowed value must be valid for the static lifetime...
+   |                              ^-------
+   |                              ||
+   |                              |temporary value created here
+   |                              returns a reference to data owned by the current function
 
 error: aborting due to previous error
 
-For more information about this error, try `rustc --explain E0716`.
+For more information about this error, try `rustc --explain E0515`.
index 860359b5937cc15634ab505f6483fc7a35649dcc..9e680e87f79a89aa81b69556dcd94fb5610b67b0 100644 (file)
@@ -54,12 +54,13 @@ error[E0597]: `p` does not live long enough
   --> $DIR/issue-18118.rs:18:9
    |
 LL |         &p //~ ERROR `p` does not live long enough
-   |         ^^ borrowed value does not live long enough
+   |         ^^
+   |         |
+   |         borrowed value does not live long enough
+   |         using this value as a constant requires that `p` is borrowed for `'static`
 LL |         //~^ ERROR let bindings in constants are unstable
 LL |     };
    |     - `p` dropped here while still borrowed
-   |
-   = note: borrowed value must be valid for the static lifetime...
 
 error: aborting due to 6 previous errors
 
index a1d8c7aeb0eb9c143a1b69dadb3e8e4c6a924846..630eab8613da0944d83bdda63ae5648f5e8cb54b 100644 (file)
@@ -1,19 +1,21 @@
-error[E0716]: temporary value dropped while borrowed
-  --> $DIR/issue-27592.rs:26:27
+error[E0515]: cannot return value referencing temporary value
+  --> $DIR/issue-27592.rs:26:14
    |
 LL |     write(|| format_args!("{}", String::from("Hello world")));
-   |                           ^^^^                             - temporary value is freed at the end of this statement
-   |                           |
-   |                           creates a temporary which is freed while still in use
+   |              ^^^^^^^^^^^^^^^^^^^---------------------------^
+   |              |                  |
+   |              |                  temporary value created here
+   |              returns a value referencing data owned by the current function
 
-error[E0716]: temporary value dropped while borrowed
-  --> $DIR/issue-27592.rs:26:33
+error[E0515]: cannot return value referencing temporary value
+  --> $DIR/issue-27592.rs:26:14
    |
 LL |     write(|| format_args!("{}", String::from("Hello world")));
-   |                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^- temporary value is freed at the end of this statement
-   |                                 |
-   |                                 creates a temporary which is freed while still in use
+   |              ^^^^^^^^^^^^^----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |              |            |
+   |              |            temporary value created here
+   |              returns a value referencing data owned by the current function
 
 error: aborting due to 2 previous errors
 
-For more information about this error, try `rustc --explain E0716`.
+For more information about this error, try `rustc --explain E0515`.
index 7a11743fe462136751af36981d49acb0746e2164..8f7afc8a78d5f27fe504697ea211ec24a5f98977 100644 (file)
@@ -1,20 +1,12 @@
-error[E0716]: temporary value dropped while borrowed
-  --> $DIR/issue-30438-a.rs:22:17
+error[E0515]: cannot return reference to temporary value
+  --> $DIR/issue-30438-a.rs:22:16
    |
 LL |         return &Test { s: &self.s};
-   |                 ^^^^^^^^^^^^^^^^^^- temporary value is freed at the end of this statement
-   |                 |
-   |                 creates a temporary which is freed while still in use
-   |
-note: borrowed value must be valid for the anonymous lifetime #1 defined on the method body at 21:5...
-  --> $DIR/issue-30438-a.rs:21:5
-   |
-LL | /     fn index(&self, _: usize) -> &Self::Output {
-LL | |         return &Test { s: &self.s};
-LL | |         //~^ ERROR: borrowed value does not live long enough
-LL | |     }
-   | |_____^
+   |                ^------------------
+   |                ||
+   |                |temporary value created here
+   |                returns a reference to data owned by the current function
 
 error: aborting due to previous error
 
-For more information about this error, try `rustc --explain E0716`.
+For more information about this error, try `rustc --explain E0515`.
index ae1022f593ed55a8a6ebc8fb4bfb67c7c58e6490..6be8180e00720ac895731cf3f2cbe292ad5d2c87 100644 (file)
@@ -1,21 +1,12 @@
-error[E0716]: temporary value dropped while borrowed
-  --> $DIR/issue-30438-b.rs:23:10
+error[E0515]: cannot return reference to temporary value
+  --> $DIR/issue-30438-b.rs:23:9
    |
 LL |         &Test { s: &self.s}
-   |          ^^^^^^^^^^^^^^^^^^ creates a temporary which is freed while still in use
-LL |         //~^ ERROR: borrowed value does not live long enough
-LL |     }
-   |     - temporary value is freed at the end of this statement
-   |
-note: borrowed value must be valid for the anonymous lifetime #1 defined on the method body at 22:5...
-  --> $DIR/issue-30438-b.rs:22:5
-   |
-LL | /     fn index(&self, _: usize) -> &Self::Output {
-LL | |         &Test { s: &self.s}
-LL | |         //~^ ERROR: borrowed value does not live long enough
-LL | |     }
-   | |_____^
+   |         ^------------------
+   |         ||
+   |         |temporary value created here
+   |         returns a reference to data owned by the current function
 
 error: aborting due to previous error
 
-For more information about this error, try `rustc --explain E0716`.
+For more information about this error, try `rustc --explain E0515`.
index 3d2c95013ab0fba127fc513c6beed6eea3d10372..bce4bc4812a179d4551b8a3c4de349f83e51073a 100644 (file)
@@ -1,21 +1,9 @@
-error[E0597]: `x` does not live long enough
+error[E0515]: cannot return reference to local variable `x`
   --> $DIR/issue-30438-c.rs:19:5
    |
-LL | fn silly<'y, 'z>(_s: &'y Test<'z>) -> &'y <Test<'z> as Trait>::Out where 'z: 'static {
-   |                       --               -- also has lifetime `'y`
-   |                       |
-   |                       has lifetime `'y`
-LL |     let x = Test { s: "this cannot last" };
 LL |     &x
-   |     ^^ `x` would have to be valid for `'y`...
-LL |     //~^ ERROR: `x` does not live long enough
-LL | }
-   | - ...but `x` will be dropped here, when the function `silly` returns
-   |
-   = help: use data from the highlighted arguments which match the `'y` lifetime of the return type
-   = note: functions cannot return a borrow to data owned within the function's scope, functions can only return borrows to data passed as arguments
-   = note: to learn more, visit <https://doc.rust-lang.org/book/second-edition/ch04-02-references-and-borrowing.html#dangling-references>
+   |     ^^ returns a reference to data owned by the current function
 
 error: aborting due to previous error
 
-For more information about this error, try `rustc --explain E0597`.
+For more information about this error, try `rustc --explain E0515`.
index fb123de2139283cc4900fe876ceae59677f37793..beb853fc91ae504c96115018b02595406c2ee959 100644 (file)
@@ -15,24 +15,25 @@ LL |     id(Box::new(|| *v))
    |                    cannot move out of `*v` which is behind a `&` reference
    |                    cannot move
 
-error[E0597]: `v` does not live long enough
-  --> $DIR/issue-4335.rs:16:21
+error[E0373]: closure may outlive the current function, but it borrows `v`, which is owned by the current function
+  --> $DIR/issue-4335.rs:16:17
    |
 LL |     id(Box::new(|| *v))
-   |                 --  ^ borrowed value does not live long enough
+   |                 ^^  - `v` is borrowed here
    |                 |
-   |                 value captured here
-...
-LL | }
-   | - `v` dropped here while still borrowed
+   |                 may outlive borrowed value `v`
    |
-note: borrowed value must be valid for the lifetime 'r as defined on the function body at 15:6...
-  --> $DIR/issue-4335.rs:15:6
+note: closure is returned here
+  --> $DIR/issue-4335.rs:16:5
    |
-LL | fn f<'r, T>(v: &'r T) -> Box<FnMut() -> T + 'r> {
-   |      ^^
+LL |     id(Box::new(|| *v))
+   |     ^^^^^^^^^^^^^^^^^^^
+help: to force the closure to take ownership of `v` (and any other referenced variables), use the `move` keyword
+   |
+LL |     id(Box::new(move || *v))
+   |                 ^^^^^^^
 
 error: aborting due to 3 previous errors
 
-Some errors occurred: E0507, E0597.
-For more information about an error, try `rustc --explain E0507`.
+Some errors occurred: E0373, E0507.
+For more information about an error, try `rustc --explain E0373`.
index dadd58cf4805db8470b229540182107a8d58ee38..f214d4661593b2e58b371fb535891b92486d60ce 100644 (file)
@@ -2,11 +2,11 @@ error[E0716]: temporary value dropped while borrowed
   --> $DIR/issue-44373.rs:15:42
    |
 LL |     let _val: &'static [&'static u32] = &[&FOO]; //~ ERROR borrowed value does not live long enough
-   |                                          ^^^^^^ creates a temporary which is freed while still in use
+   |               -----------------------    ^^^^^^ creates a temporary which is freed while still in use
+   |               |
+   |               type annotation requires that borrow lasts for `'static`
 LL | }
    | - temporary value is freed at the end of this statement
-   |
-   = note: borrowed value must be valid for the static lifetime...
 
 error: aborting due to previous error
 
index 5c753817e358d2cab177bd83a664f59ab9cfed0e..00df5c859bf07366993eb1d3bd16927e7ac1df66 100644 (file)
@@ -1,17 +1,14 @@
 warning[E0713]: borrow may still be in use when destructor runs
   --> $DIR/issue-45696-scribble-on-boxed-borrow.rs:63:5
    |
+LL | fn scribbled<'a>(s: Scribble<'a>) -> &'a mut u32 {
+   |              -- lifetime `'a` defined here
 LL |     &mut *s.0 //[nll]~ ERROR borrow may still be in use when destructor runs [E0713]
-   |     ^^^^^^^^^
+   |     ^^^^^^^^^ returning this value requires that `*s.0` is borrowed for `'a`
 ...
 LL | }
    | - here, drop of `s` needs exclusive access to `*s.0`, because the type `Scribble<'_>` implements the `Drop` trait
    |
-note: borrowed value must be valid for the lifetime 'a as defined on the function body at 62:14...
-  --> $DIR/issue-45696-scribble-on-boxed-borrow.rs:62:14
-   |
-LL | fn scribbled<'a>(s: Scribble<'a>) -> &'a mut u32 {
-   |              ^^
    = warning: This error has been downgraded to a warning for backwards compatibility with previous releases.
            It represents potential unsoundness in your code.
            This warning will become a hard error in the future.
@@ -19,17 +16,14 @@ LL | fn scribbled<'a>(s: Scribble<'a>) -> &'a mut u32 {
 warning[E0713]: borrow may still be in use when destructor runs
   --> $DIR/issue-45696-scribble-on-boxed-borrow.rs:73:5
    |
+LL | fn boxed_scribbled<'a>(s: Box<Scribble<'a>>) -> &'a mut u32 {
+   |                    -- lifetime `'a` defined here
 LL |     &mut *(*s).0 //[nll]~ ERROR borrow may still be in use when destructor runs [E0713]
-   |     ^^^^^^^^^^^^
+   |     ^^^^^^^^^^^^ returning this value requires that `*s.0` is borrowed for `'a`
 ...
 LL | }
    | - here, drop of `s` needs exclusive access to `*s.0`, because the type `Scribble<'_>` implements the `Drop` trait
    |
-note: borrowed value must be valid for the lifetime 'a as defined on the function body at 72:20...
-  --> $DIR/issue-45696-scribble-on-boxed-borrow.rs:72:20
-   |
-LL | fn boxed_scribbled<'a>(s: Box<Scribble<'a>>) -> &'a mut u32 {
-   |                    ^^
    = warning: This error has been downgraded to a warning for backwards compatibility with previous releases.
            It represents potential unsoundness in your code.
            This warning will become a hard error in the future.
@@ -37,17 +31,14 @@ LL | fn boxed_scribbled<'a>(s: Box<Scribble<'a>>) -> &'a mut u32 {
 warning[E0713]: borrow may still be in use when destructor runs
   --> $DIR/issue-45696-scribble-on-boxed-borrow.rs:83:5
    |
+LL | fn boxed_boxed_scribbled<'a>(s: Box<Box<Scribble<'a>>>) -> &'a mut u32 {
+   |                          -- lifetime `'a` defined here
 LL |     &mut *(**s).0 //[nll]~ ERROR borrow may still be in use when destructor runs [E0713]
-   |     ^^^^^^^^^^^^^
+   |     ^^^^^^^^^^^^^ returning this value requires that `*s.0` is borrowed for `'a`
 ...
 LL | }
    | - here, drop of `s` needs exclusive access to `*s.0`, because the type `Scribble<'_>` implements the `Drop` trait
    |
-note: borrowed value must be valid for the lifetime 'a as defined on the function body at 82:26...
-  --> $DIR/issue-45696-scribble-on-boxed-borrow.rs:82:26
-   |
-LL | fn boxed_boxed_scribbled<'a>(s: Box<Box<Scribble<'a>>>) -> &'a mut u32 {
-   |                          ^^
    = warning: This error has been downgraded to a warning for backwards compatibility with previous releases.
            It represents potential unsoundness in your code.
            This warning will become a hard error in the future.
index 79a7c0631f4804ffca17f6cd553b4858b2ff0781..5640dbd4e8c2c4849227a307eaa048ea70e52fa3 100644 (file)
@@ -1,47 +1,35 @@
 error[E0713]: borrow may still be in use when destructor runs
   --> $DIR/issue-45696-scribble-on-boxed-borrow.rs:63:5
    |
+LL | fn scribbled<'a>(s: Scribble<'a>) -> &'a mut u32 {
+   |              -- lifetime `'a` defined here
 LL |     &mut *s.0 //[nll]~ ERROR borrow may still be in use when destructor runs [E0713]
-   |     ^^^^^^^^^
+   |     ^^^^^^^^^ returning this value requires that `*s.0` is borrowed for `'a`
 ...
 LL | }
    | - here, drop of `s` needs exclusive access to `*s.0`, because the type `Scribble<'_>` implements the `Drop` trait
-   |
-note: borrowed value must be valid for the lifetime 'a as defined on the function body at 62:14...
-  --> $DIR/issue-45696-scribble-on-boxed-borrow.rs:62:14
-   |
-LL | fn scribbled<'a>(s: Scribble<'a>) -> &'a mut u32 {
-   |              ^^
 
 error[E0713]: borrow may still be in use when destructor runs
   --> $DIR/issue-45696-scribble-on-boxed-borrow.rs:73:5
    |
+LL | fn boxed_scribbled<'a>(s: Box<Scribble<'a>>) -> &'a mut u32 {
+   |                    -- lifetime `'a` defined here
 LL |     &mut *(*s).0 //[nll]~ ERROR borrow may still be in use when destructor runs [E0713]
-   |     ^^^^^^^^^^^^
+   |     ^^^^^^^^^^^^ returning this value requires that `*s.0` is borrowed for `'a`
 ...
 LL | }
    | - here, drop of `s` needs exclusive access to `*s.0`, because the type `Scribble<'_>` implements the `Drop` trait
-   |
-note: borrowed value must be valid for the lifetime 'a as defined on the function body at 72:20...
-  --> $DIR/issue-45696-scribble-on-boxed-borrow.rs:72:20
-   |
-LL | fn boxed_scribbled<'a>(s: Box<Scribble<'a>>) -> &'a mut u32 {
-   |                    ^^
 
 error[E0713]: borrow may still be in use when destructor runs
   --> $DIR/issue-45696-scribble-on-boxed-borrow.rs:83:5
    |
+LL | fn boxed_boxed_scribbled<'a>(s: Box<Box<Scribble<'a>>>) -> &'a mut u32 {
+   |                          -- lifetime `'a` defined here
 LL |     &mut *(**s).0 //[nll]~ ERROR borrow may still be in use when destructor runs [E0713]
-   |     ^^^^^^^^^^^^^
+   |     ^^^^^^^^^^^^^ returning this value requires that `*s.0` is borrowed for `'a`
 ...
 LL | }
    | - here, drop of `s` needs exclusive access to `*s.0`, because the type `Scribble<'_>` implements the `Drop` trait
-   |
-note: borrowed value must be valid for the lifetime 'a as defined on the function body at 82:26...
-  --> $DIR/issue-45696-scribble-on-boxed-borrow.rs:82:26
-   |
-LL | fn boxed_boxed_scribbled<'a>(s: Box<Box<Scribble<'a>>>) -> &'a mut u32 {
-   |                          ^^
 
 error: aborting due to 3 previous errors
 
index 463abaede88f9315d3f886e1e5f8638bd7850ff5..55f13a699d0efeba6fb2d07cb8f05a1ad9ecb3d3 100644 (file)
@@ -2,12 +2,13 @@ error[E0597]: `a` does not live long enough
   --> $DIR/issue-46036.rs:19:24
    |
 LL |     let foo = Foo { x: &a }; //~ ERROR E0597
-   |                        ^^ borrowed value does not live long enough
+   |                        ^^
+   |                        |
+   |                        borrowed value does not live long enough
+   |                        requires that `a` is borrowed for `'static`
 LL |     loop { }
 LL | }
    | - `a` dropped here while still borrowed
-   |
-   = note: borrowed value must be valid for the static lifetime...
 
 error: aborting due to previous error
 
index 8faedb738429faa31ae95051c44b188e932fc531..654a3d8f964d2871618afd7d1c8a5b9fa0fa8d24 100644 (file)
@@ -14,7 +14,7 @@ fn foo() -> &'static u32 {
     let x = 0;
     &x
     //~^ ERROR `x` does not live long enough (Ast) [E0597]
-    //~| ERROR `x` does not live long enough (Mir) [E0597]
+    //~| ERROR cannot return reference to local variable `x` (Mir) [E0515]
 }
 
 fn main() { }
index 560c341b4df051606a804be229d743b8d14957fe..e6ec6831fe9641cf2ddbb0dd6c93cba76a543c6d 100644 (file)
@@ -9,17 +9,13 @@ LL | }
    |
    = note: borrowed value must be valid for the static lifetime...
 
-error[E0597]: `x` does not live long enough (Mir)
+error[E0515]: cannot return reference to local variable `x` (Mir)
   --> $DIR/issue-46471.rs:15:5
    |
 LL |     &x
-   |     ^^ borrowed value does not live long enough
-...
-LL | }
-   | - `x` dropped here while still borrowed
-   |
-   = note: borrowed value must be valid for the static lifetime...
+   |     ^^ returns a reference to data owned by the current function
 
 error: aborting due to 2 previous errors
 
-For more information about this error, try `rustc --explain E0597`.
+Some errors occurred: E0515, E0597.
+For more information about an error, try `rustc --explain E0515`.
index 84e30a4d29167a0765207d1927f84d9763426a36..8137cd2dd89137a603ea2b9a4d2c00e53125001a 100644 (file)
@@ -13,7 +13,7 @@
 fn bar<'a>() -> &'a mut u32 {
     &mut 4
     //~^ ERROR borrowed value does not live long enough (Ast) [E0597]
-    //~| ERROR temporary value dropped while borrowed (Mir) [E0716]
+    //~| ERROR cannot return reference to temporary value (Mir) [E0515]
 }
 
 fn main() { }
index 4c0e6544a93939d32798fc29b37a521c6bf5b6b5..b1d34ff24d4b0bdbba53a84345f0a7b59412b208 100644 (file)
@@ -13,22 +13,16 @@ note: borrowed value must be valid for the lifetime 'a as defined on the functio
 LL | fn bar<'a>() -> &'a mut u32 {
    |        ^^
 
-error[E0716]: temporary value dropped while borrowed (Mir)
-  --> $DIR/issue-46472.rs:14:10
+error[E0515]: cannot return reference to temporary value (Mir)
+  --> $DIR/issue-46472.rs:14:5
    |
 LL |     &mut 4
-   |          ^ creates a temporary which is freed while still in use
-...
-LL | }
-   | - temporary value is freed at the end of this statement
-   |
-note: borrowed value must be valid for the lifetime 'a as defined on the function body at 13:8...
-  --> $DIR/issue-46472.rs:13:8
-   |
-LL | fn bar<'a>() -> &'a mut u32 {
-   |        ^^
+   |     ^^^^^-
+   |     |    |
+   |     |    temporary value created here
+   |     returns a reference to data owned by the current function
 
 error: aborting due to 2 previous errors
 
-Some errors occurred: E0597, E0716.
-For more information about an error, try `rustc --explain E0597`.
+Some errors occurred: E0515, E0597.
+For more information about an error, try `rustc --explain E0515`.
index 4a8e9255723cc6c8a15955357d5c30c259666a14..62ca682b1e342ea60f154c84599211add1f40f0e 100644 (file)
@@ -2,11 +2,10 @@ error[E0716]: temporary value dropped while borrowed
   --> $DIR/issue-47184.rs:14:44
    |
 LL |     let _vec: Vec<&'static String> = vec![&String::new()];
-   |                                            ^^^^^^^^^^^^^ - temporary value is freed at the end of this statement
-   |                                            |
-   |                                            creates a temporary which is freed while still in use
-   |
-   = note: borrowed value must be valid for the static lifetime...
+   |               --------------------         ^^^^^^^^^^^^^ - temporary value is freed at the end of this statement
+   |               |                            |
+   |               |                            creates a temporary which is freed while still in use
+   |               type annotation requires that borrow lasts for `'static`
 
 error: aborting due to previous error
 
index eb984fbde03a81ec1e71f61c1b382d125fd75e2f..d64332bf07c87c82cba32df01f7b05ef05ccf5f8 100644 (file)
@@ -2,11 +2,12 @@ error[E0716]: temporary value dropped while borrowed
   --> $DIR/issue-52049.rs:16:10
    |
 LL |     foo(&unpromotable(5u32));
-   |          ^^^^^^^^^^^^^^^^^^ creates a temporary which is freed while still in use
+   |     -----^^^^^^^^^^^^^^^^^^-
+   |     |    |
+   |     |    creates a temporary which is freed while still in use
+   |     argument requires that borrow lasts for `'static`
 LL | }
    | - temporary value is freed at the end of this statement
-   |
-   = note: borrowed value must be valid for the static lifetime...
 
 error: aborting due to previous error
 
index 9a59cebfccbe2089e47ce430f22ed9fe26f8326f..283b32df99c210b1de6973934ddd8aee8b6547d3 100644 (file)
@@ -14,7 +14,7 @@
 fn foo<'a>(x: &'a (u32,)) -> &'a u32 {
     let v = 22;
     &v
-    //~^ ERROR `v` does not live long enough [E0597]
+    //~^ ERROR cannot return reference to local variable `v` [E0515]
 }
 
 fn main() {}
index c35a14ca70443a97a8ad07e1ae3b34cbadd08d49..ae160338013b18fc0cd8ae46d404559f2e98e036 100644 (file)
@@ -1,21 +1,9 @@
-error[E0597]: `v` does not live long enough
+error[E0515]: cannot return reference to local variable `v`
   --> $DIR/borrowed-universal-error-2.rs:16:5
    |
-LL | fn foo<'a>(x: &'a (u32,)) -> &'a u32 {
-   |                --             -- also has lifetime `'a`
-   |                |
-   |                has lifetime `'a`
-LL |     let v = 22;
 LL |     &v
-   |     ^^ `v` would have to be valid for `'a`...
-LL |     //~^ ERROR `v` does not live long enough [E0597]
-LL | }
-   | - ...but `v` will be dropped here, when the function `foo` returns
-   |
-   = help: use data from the highlighted arguments which match the `'a` lifetime of the return type
-   = note: functions cannot return a borrow to data owned within the function's scope, functions can only return borrows to data passed as arguments
-   = note: to learn more, visit <https://doc.rust-lang.org/book/second-edition/ch04-02-references-and-borrowing.html#dangling-references>
+   |     ^^ returns a reference to data owned by the current function
 
 error: aborting due to previous error
 
-For more information about this error, try `rustc --explain E0597`.
+For more information about this error, try `rustc --explain E0515`.
index 016a4f49e504ac525126b1074fb464800f5f7ff0..68a7237fdd6c61e8215be37d2f590255319cb152 100644 (file)
@@ -18,7 +18,7 @@ fn gimme(x: &(u32,)) -> &u32 {
 fn foo<'a>(x: &'a (u32,)) -> &'a u32 {
     let v = 22;
     gimme(&(v,))
-    //~^ ERROR temporary value dropped while borrowed [E0716]
+    //~^ ERROR cannot return value referencing temporary value [E0515]
 }
 
 fn main() {}
index d7ab5cec4a84ae856122f817e15ab0c751d0bc3c..a5b3e6bcf35010d2a08a18ff276c1956b8403989 100644 (file)
@@ -1,18 +1,12 @@
-error[E0716]: temporary value dropped while borrowed
-  --> $DIR/borrowed-universal-error.rs:20:12
+error[E0515]: cannot return value referencing temporary value
+  --> $DIR/borrowed-universal-error.rs:20:5
    |
 LL |     gimme(&(v,))
-   |            ^^^^ creates a temporary which is freed while still in use
-LL |     //~^ ERROR temporary value dropped while borrowed [E0716]
-LL | }
-   | - temporary value is freed at the end of this statement
-   |
-note: borrowed value must be valid for the lifetime 'a as defined on the function body at 18:8...
-  --> $DIR/borrowed-universal-error.rs:18:8
-   |
-LL | fn foo<'a>(x: &'a (u32,)) -> &'a u32 {
-   |        ^^
+   |     ^^^^^^^----^
+   |     |      |
+   |     |      temporary value created here
+   |     returns a value referencing data owned by the current function
 
 error: aborting due to previous error
 
-For more information about this error, try `rustc --explain E0716`.
+For more information about this error, try `rustc --explain E0515`.
index c855cee3c606ae9e72326b67bc5f07f59ae734a0..43b4844bbf9b4214fd119f14934d42cbf432a162 100644 (file)
@@ -13,7 +13,7 @@ LL | |     })
                for<'r> extern "rust-call" fn((std::cell::Cell<&'_#1r u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 'r)) u32>))
            ]
 
-error: borrowed data escapes outside of closure
+error[E0521]: borrowed data escapes outside of closure
   --> $DIR/propagate-approximated-shorter-to-static-comparing-against-free.rs:32:9
    |
 LL |     foo(cell, |cell_a, cell_x| {
@@ -71,13 +71,15 @@ error[E0597]: `a` does not live long enough
   --> $DIR/propagate-approximated-shorter-to-static-comparing-against-free.rs:40:26
    |
 LL |     let cell = Cell::new(&a);
-   |                          ^^ borrowed value does not live long enough
+   |                ----------^^-
+   |                |         |
+   |                |         borrowed value does not live long enough
+   |                argument requires that `a` is borrowed for `'static`
 ...
 LL | }
    | - `a` dropped here while still borrowed
-   |
-   = note: borrowed value must be valid for the static lifetime...
 
 error: aborting due to 2 previous errors
 
-For more information about this error, try `rustc --explain E0597`.
+Some errors occurred: E0521, E0597.
+For more information about an error, try `rustc --explain E0521`.
index 7ebd36e10b5645fe05dff563e6242584caa5f077..a5435cc65caa06802e6903999a483d8dcf3228da 100644 (file)
@@ -34,7 +34,7 @@ LL | | }
    |
    = note: defining type: DefId(0/0:6 ~ propagate_approximated_shorter_to_static_no_bound[317d]::supply[0]) with substs []
 
-error: borrowed data escapes outside of function
+error[E0521]: borrowed data escapes outside of function
   --> $DIR/propagate-approximated-shorter-to-static-no-bound.rs:45:5
    |
 LL |   fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
@@ -61,3 +61,4 @@ LL |         demand_y(x, y, x.get())
 
 error: aborting due to 2 previous errors
 
+For more information about this error, try `rustc --explain E0521`.
index d62910576b0c3a886dfc47df5afd83aaf810a113..35692414081ac1b545caa5cb48b20c8e2d3133d5 100644 (file)
@@ -33,7 +33,7 @@ LL | | }
    |
    = note: defining type: DefId(0/0:6 ~ propagate_approximated_shorter_to_static_wrong_bound[317d]::supply[0]) with substs []
 
-error: borrowed data escapes outside of function
+error[E0521]: borrowed data escapes outside of function
   --> $DIR/propagate-approximated-shorter-to-static-wrong-bound.rs:48:5
    |
 LL |   fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
@@ -59,3 +59,4 @@ LL |         demand_y(x, y, x.get())
 
 error: aborting due to 2 previous errors
 
+For more information about this error, try `rustc --explain E0521`.
index edf32d3d22318574398aabde5efb87ad148d325e..fc4118a0998994335bfe1bad533c24da1679b21d 100644 (file)
@@ -3,11 +3,11 @@ error[E0597]: `s` does not live long enough
    |
 LL |     let a = Foo(&s); //~ ERROR `s` does not live long enough [E0597]
    |                 ^^ borrowed value does not live long enough
-...
+LL |     drop(a);
+   |          - copying this value requires that `s` is borrowed for `'static`
+LL |     drop(a);
 LL | }
    | - `s` dropped here while still borrowed
-   |
-   = note: borrowed value must be valid for the static lifetime...
 
 error: aborting due to previous error
 
index 57daf26596dfb55830b0a8fa948418f52e369b8f..da9c96f7bc2e803691155bc47f38cdbe38ceecc8 100644 (file)
@@ -1,44 +1,30 @@
 error[E0713]: borrow may still be in use when destructor runs
   --> $DIR/enum-drop-access.rs:15:31
    |
+LL | fn drop_enum(opt: DropOption<&mut i32>) -> Option<&mut i32> {
+   |                              - let's call the lifetime of this reference `'1`
+LL |     match opt {
 LL |         DropOption::Some(&mut ref mut r) => { //~ ERROR
    |                               ^^^^^^^^^
+LL |             Some(r)
+   |             ------- returning this value requires that `*opt.0` is borrowed for `'1`
 ...
 LL | }
    | - here, drop of `opt` needs exclusive access to `*opt.0`, because the type `DropOption<&mut i32>` implements the `Drop` trait
-   |
-note: borrowed value must be valid for the anonymous lifetime #1 defined on the function body at 13:1...
-  --> $DIR/enum-drop-access.rs:13:1
-   |
-LL | / fn drop_enum(opt: DropOption<&mut i32>) -> Option<&mut i32> {
-LL | |     match opt {
-LL | |         DropOption::Some(&mut ref mut r) => { //~ ERROR
-LL | |             Some(r)
-...  |
-LL | |     }
-LL | | }
-   | |_^
 
 error[E0713]: borrow may still be in use when destructor runs
   --> $DIR/enum-drop-access.rs:24:36
    |
+LL | fn optional_drop_enum(opt: Option<DropOption<&mut i32>>) -> Option<&mut i32> {
+   |                                              - let's call the lifetime of this reference `'1`
+LL |     match opt {
 LL |         Some(DropOption::Some(&mut ref mut r)) => { //~ ERROR
    |                                    ^^^^^^^^^
+LL |             Some(r)
+   |             ------- returning this value requires that `*opt.0.0` is borrowed for `'1`
 ...
 LL | }
    | - here, drop of `opt` needs exclusive access to `*opt.0.0`, because the type `DropOption<&mut i32>` implements the `Drop` trait
-   |
-note: borrowed value must be valid for the anonymous lifetime #1 defined on the function body at 22:1...
-  --> $DIR/enum-drop-access.rs:22:1
-   |
-LL | / fn optional_drop_enum(opt: Option<DropOption<&mut i32>>) -> Option<&mut i32> {
-LL | |     match opt {
-LL | |         Some(DropOption::Some(&mut ref mut r)) => { //~ ERROR
-LL | |             Some(r)
-...  |
-LL | |     }
-LL | | }
-   | |_^
 
 error: aborting due to 2 previous errors
 
index a22f3032f304986cc826cf2e7b63c6fdbf72a972..4f9c832d423bb11c915a6232f3b5f65a5e1f6f84 100644 (file)
@@ -37,65 +37,47 @@ LL | }
 error[E0502]: cannot borrow `*map` as mutable because it is also borrowed as immutable (Mir)
   --> $DIR/get_default.rs:33:17
    |
+LL | fn ok(map: &mut Map) -> &String {
+   |            - let's call the lifetime of this reference `'1`
+LL |     loop {
 LL |         match map.get() {
    |               --- immutable borrow occurs here
+LL |             Some(v) => {
+LL |                 return v;
+   |                        - returning this value requires that `*map` is borrowed for `'1`
 ...
 LL |                 map.set(String::new()); // Ideally, this would not error.
    |                 ^^^^^^^^^^^^^^^^^^^^^^ mutable borrow occurs here
-   |
-note: immutable borrowed value must be valid for the anonymous lifetime #1 defined on the function body at 26:1...
-  --> $DIR/get_default.rs:26:1
-   |
-LL | / fn ok(map: &mut Map) -> &String {
-LL | |     loop {
-LL | |         match map.get() {
-LL | |             Some(v) => {
-...  |
-LL | |     }
-LL | | }
-   | |_^
 
 error[E0502]: cannot borrow `*map` as mutable because it is also borrowed as immutable (Mir)
   --> $DIR/get_default.rs:45:17
    |
+LL | fn err(map: &mut Map) -> &String {
+   |             - let's call the lifetime of this reference `'1`
+LL |     loop {
 LL |         match map.get() {
    |               --- immutable borrow occurs here
 LL |             Some(v) => {
 LL |                 map.set(String::new()); // Both AST and MIR error here
    |                 ^^^^^^^^^^^^^^^^^^^^^^ mutable borrow occurs here
-   |
-note: immutable borrowed value must be valid for the anonymous lifetime #1 defined on the function body at 41:1...
-  --> $DIR/get_default.rs:41:1
-   |
-LL | / fn err(map: &mut Map) -> &String {
-LL | |     loop {
-LL | |         match map.get() {
-LL | |             Some(v) => {
-...  |
-LL | |     }
-LL | | }
-   | |_^
+...
+LL |                 return v;
+   |                        - returning this value requires that `*map` is borrowed for `'1`
 
 error[E0502]: cannot borrow `*map` as mutable because it is also borrowed as immutable (Mir)
   --> $DIR/get_default.rs:51:17
    |
+LL | fn err(map: &mut Map) -> &String {
+   |             - let's call the lifetime of this reference `'1`
+LL |     loop {
 LL |         match map.get() {
    |               --- immutable borrow occurs here
 ...
+LL |                 return v;
+   |                        - returning this value requires that `*map` is borrowed for `'1`
+...
 LL |                 map.set(String::new()); // Ideally, just AST would error here
    |                 ^^^^^^^^^^^^^^^^^^^^^^ mutable borrow occurs here
-   |
-note: immutable borrowed value must be valid for the anonymous lifetime #1 defined on the function body at 41:1...
-  --> $DIR/get_default.rs:41:1
-   |
-LL | / fn err(map: &mut Map) -> &String {
-LL | |     loop {
-LL | |         match map.get() {
-LL | |             Some(v) => {
-...  |
-LL | |     }
-LL | | }
-   | |_^
 
 error: aborting due to 6 previous errors
 
index 8c93eb059e8cdd80c59e2cc4eee358ec8b8b59b3..98112e8b8629add81b22ad8790c98682b1aa13c6 100644 (file)
@@ -37,65 +37,47 @@ LL | }
 error[E0502]: cannot borrow `*map` as mutable because it is also borrowed as immutable (Mir)
   --> $DIR/get_default.rs:33:17
    |
+LL | fn ok(map: &mut Map) -> &String {
+   |            - let's call the lifetime of this reference `'1`
+LL |     loop {
 LL |         match map.get() {
    |               --- immutable borrow occurs here
+LL |             Some(v) => {
+LL |                 return v;
+   |                        - returning this value requires that `*map` is borrowed for `'1`
 ...
 LL |                 map.set(String::new()); // Ideally, this would not error.
    |                 ^^^ mutable borrow occurs here
-   |
-note: immutable borrowed value must be valid for the anonymous lifetime #1 defined on the function body at 26:1...
-  --> $DIR/get_default.rs:26:1
-   |
-LL | / fn ok(map: &mut Map) -> &String {
-LL | |     loop {
-LL | |         match map.get() {
-LL | |             Some(v) => {
-...  |
-LL | |     }
-LL | | }
-   | |_^
 
 error[E0502]: cannot borrow `*map` as mutable because it is also borrowed as immutable (Mir)
   --> $DIR/get_default.rs:45:17
    |
+LL | fn err(map: &mut Map) -> &String {
+   |             - let's call the lifetime of this reference `'1`
+LL |     loop {
 LL |         match map.get() {
    |               --- immutable borrow occurs here
 LL |             Some(v) => {
 LL |                 map.set(String::new()); // Both AST and MIR error here
    |                 ^^^ mutable borrow occurs here
-   |
-note: immutable borrowed value must be valid for the anonymous lifetime #1 defined on the function body at 41:1...
-  --> $DIR/get_default.rs:41:1
-   |
-LL | / fn err(map: &mut Map) -> &String {
-LL | |     loop {
-LL | |         match map.get() {
-LL | |             Some(v) => {
-...  |
-LL | |     }
-LL | | }
-   | |_^
+...
+LL |                 return v;
+   |                        - returning this value requires that `*map` is borrowed for `'1`
 
 error[E0502]: cannot borrow `*map` as mutable because it is also borrowed as immutable (Mir)
   --> $DIR/get_default.rs:51:17
    |
+LL | fn err(map: &mut Map) -> &String {
+   |             - let's call the lifetime of this reference `'1`
+LL |     loop {
 LL |         match map.get() {
    |               --- immutable borrow occurs here
 ...
+LL |                 return v;
+   |                        - returning this value requires that `*map` is borrowed for `'1`
+...
 LL |                 map.set(String::new()); // Ideally, just AST would error here
    |                 ^^^ mutable borrow occurs here
-   |
-note: immutable borrowed value must be valid for the anonymous lifetime #1 defined on the function body at 41:1...
-  --> $DIR/get_default.rs:41:1
-   |
-LL | / fn err(map: &mut Map) -> &String {
-LL | |     loop {
-LL | |         match map.get() {
-LL | |             Some(v) => {
-...  |
-LL | |     }
-LL | | }
-   | |_^
 
 error: aborting due to 6 previous errors
 
index 63330f303198156a2348ecf79ecebe12d700c537..106f53dcf70a81d346c490a10c24163fea4682a1 100644 (file)
@@ -1,17 +1,15 @@
 error[E0713]: borrow may still be in use when destructor runs
   --> $DIR/issue-31567.rs:22:26
    |
+LL | fn get_dangling<'a>(v: VecWrapper<'a>) -> &'a u32 {
+   |                 -- lifetime `'a` defined here
 LL |     let s_inner: &'a S = &*v.0; //~ ERROR borrow may still be in use when destructor runs [E0713]
-   |                          ^^^^^
+   |                  -----   ^^^^^
+   |                  |
+   |                  type annotation requires that `*v.0` is borrowed for `'a`
 LL |     &s_inner.0
 LL | }
    | - here, drop of `v` needs exclusive access to `*v.0`, because the type `VecWrapper<'_>` implements the `Drop` trait
-   |
-note: borrowed value must be valid for the lifetime 'a as defined on the function body at 21:17...
-  --> $DIR/issue-31567.rs:21:17
-   |
-LL | fn get_dangling<'a>(v: VecWrapper<'a>) -> &'a u32 {
-   |                 ^^
 
 error: aborting due to previous error
 
index c962f193cd5b09043e55b0253f238db486d754a1..38edb19a970aa680c17c422e416a5c50907c6ef4 100644 (file)
@@ -24,7 +24,7 @@ impl<'a> Bar for Foo<'a> {
     type Assoc = &'a u32;
     fn get(self) -> Self::Assoc {
         let local = 42;
-        &local //~ ERROR `local` does not live long enough
+        &local //~ ERROR cannot return reference to local variable `local`
     }
 }
 
index e73df61a30371963f3a1dcdea36aab51a4198ca9..143566413aa7e540d9a6d40c3f101ec6ffb1981c 100644 (file)
@@ -1,17 +1,9 @@
-error[E0597]: `local` does not live long enough
+error[E0515]: cannot return reference to local variable `local`
   --> $DIR/issue-47470.rs:27:9
    |
-LL |         &local //~ ERROR `local` does not live long enough
-   |         ^^^^^^ borrowed value does not live long enough
-LL |     }
-   |     - `local` dropped here while still borrowed
-   |
-note: borrowed value must be valid for the lifetime 'a as defined on the impl at 23:6...
-  --> $DIR/issue-47470.rs:23:6
-   |
-LL | impl<'a> Bar for Foo<'a> {
-   |      ^^
+LL |         &local //~ ERROR cannot return reference to local variable `local`
+   |         ^^^^^^ returns a reference to data owned by the current function
 
 error: aborting due to previous error
 
-For more information about this error, try `rustc --explain E0597`.
+For more information about this error, try `rustc --explain E0515`.
index 71c97b7ad6b80091d0bf8e410dc02d307cec57d2..e2036ee4ac0c10be77c62e402cd456b4c6f4cf7b 100644 (file)
@@ -1,50 +1,32 @@
 error[E0713]: borrow may still be in use when destructor runs
   --> $DIR/issue-52059-report-when-borrow-and-drop-conflict.rs:14:5
    |
+LL | fn finish_1(s: S) -> &mut String {
+   |             - has type `S<'1>`
 LL |     s.url
-   |     ^^^^^
+   |     ^^^^^ returning this value requires that `*s.url` is borrowed for `'1`
 LL | }
    | - here, drop of `s` needs exclusive access to `*s.url`, because the type `S<'_>` implements the `Drop` trait
-   |
-note: borrowed value must be valid for the anonymous lifetime #1 defined on the function body at 13:1...
-  --> $DIR/issue-52059-report-when-borrow-and-drop-conflict.rs:13:1
-   |
-LL | / fn finish_1(s: S) -> &mut String {
-LL | |     s.url
-LL | | }
-   | |_^
 
 error[E0713]: borrow may still be in use when destructor runs
   --> $DIR/issue-52059-report-when-borrow-and-drop-conflict.rs:19:13
    |
+LL | fn finish_2(s: S) -> &mut String {
+   |             - has type `S<'1>`
 LL |     let p = &mut *s.url; p
-   |             ^^^^^^^^^^^
+   |             ^^^^^^^^^^^  - returning this value requires that `*s.url` is borrowed for `'1`
 LL | }
    | - here, drop of `s` needs exclusive access to `*s.url`, because the type `S<'_>` implements the `Drop` trait
-   |
-note: borrowed value must be valid for the anonymous lifetime #1 defined on the function body at 18:1...
-  --> $DIR/issue-52059-report-when-borrow-and-drop-conflict.rs:18:1
-   |
-LL | / fn finish_2(s: S) -> &mut String {
-LL | |     let p = &mut *s.url; p
-LL | | }
-   | |_^
 
 error[E0713]: borrow may still be in use when destructor runs
   --> $DIR/issue-52059-report-when-borrow-and-drop-conflict.rs:24:21
    |
+LL | fn finish_3(s: S) -> &mut String {
+   |             - has type `S<'1>`
 LL |     let p: &mut _ = s.url; p
-   |                     ^^^^^
+   |                     ^^^^^  - returning this value requires that `*s.url` is borrowed for `'1`
 LL | }
    | - here, drop of `s` needs exclusive access to `*s.url`, because the type `S<'_>` implements the `Drop` trait
-   |
-note: borrowed value must be valid for the anonymous lifetime #1 defined on the function body at 23:1...
-  --> $DIR/issue-52059-report-when-borrow-and-drop-conflict.rs:23:1
-   |
-LL | / fn finish_3(s: S) -> &mut String {
-LL | |     let p: &mut _ = s.url; p
-LL | | }
-   | |_^
 
 error[E0509]: cannot move out of type `S<'_>`, which implements the `Drop` trait
   --> $DIR/issue-52059-report-when-borrow-and-drop-conflict.rs:29:13
index 0d071915a3b892547de0c9ce13c3f4c1787ea8e6..44a3ef3bb5d48d46768eddbfe1b711ec30b54c6e 100644 (file)
-error[E0597]: `x` does not live long enough
+error[E0515]: cannot return reference to local variable `x`
   --> $DIR/issue-52534-1.rs:19:9
    |
-LL |     fn bar(&self, x: &u32) -> &u32 {
-   |            -----              ---- has type `&'0 u32`
-   |            |
-   |            has type `&'0 Test`
-LL |         let x = 22;
 LL |         &x
-   |         ^^ `x` would have to be valid for `'0`...
-LL |     }
-   |     - ...but `x` will be dropped here, when the function `bar` returns
-   |
-   = note: argument and return type have the same lifetime due to lifetime elision rules
-   = note: to learn more, visit <https://doc.rust-lang.org/book/second-edition/ch10-03-lifetime-syntax.html#lifetime-elision>
-   = note: functions cannot return a borrow to data owned within the function's scope, functions can only return borrows to data passed as arguments
-   = note: to learn more, visit <https://doc.rust-lang.org/book/second-edition/ch04-02-references-and-borrowing.html#dangling-references>
+   |         ^^ returns a reference to data owned by the current function
 
-error[E0597]: `x` does not live long enough
+error[E0515]: cannot return reference to local variable `x`
   --> $DIR/issue-52534-1.rs:25:5
    |
-LL | fn foo(x: &u32) -> &u32 {
-   |           ----     ---- also has type `&'0 u32`
-   |           |
-   |           has type `&'0 u32`
-LL |     let x = 22;
 LL |     &x
-   |     ^^ `x` would have to be valid for `'0`...
-LL | }
-   | - ...but `x` will be dropped here, when the function `foo` returns
-   |
-   = note: argument and return type have the same lifetime due to lifetime elision rules
-   = note: to learn more, visit <https://doc.rust-lang.org/book/second-edition/ch10-03-lifetime-syntax.html#lifetime-elision>
-   = note: functions cannot return a borrow to data owned within the function's scope, functions can only return borrows to data passed as arguments
-   = note: to learn more, visit <https://doc.rust-lang.org/book/second-edition/ch04-02-references-and-borrowing.html#dangling-references>
+   |     ^^ returns a reference to data owned by the current function
 
-error[E0597]: `x` does not live long enough
-  --> $DIR/issue-52534-1.rs:30:6
+error[E0515]: cannot return value referencing local variable `x`
+  --> $DIR/issue-52534-1.rs:30:5
    |
-LL | fn baz(x: &u32) -> &&u32 {
-   |           ----     ----- has type `&'0 &'0 u32`
-   |           |
-   |           has type `&'0 u32`
-LL |     let x = 22;
 LL |     &&x
-   |      ^^ `x` would have to be valid for `'0`...
-LL | }
-   | - ...but `x` will be dropped here, when the function `baz` returns
-   |
-   = note: argument and return type have the same lifetime due to lifetime elision rules
-   = note: to learn more, visit <https://doc.rust-lang.org/book/second-edition/ch10-03-lifetime-syntax.html#lifetime-elision>
-   = note: functions cannot return a borrow to data owned within the function's scope, functions can only return borrows to data passed as arguments
-   = note: to learn more, visit <https://doc.rust-lang.org/book/second-edition/ch04-02-references-and-borrowing.html#dangling-references>
+   |     ^--
+   |     ||
+   |     |`x` is borrowed here
+   |     returns a value referencing data owned by the current function
 
-error[E0716]: temporary value dropped while borrowed
-  --> $DIR/issue-52534-1.rs:30:6
+error[E0515]: cannot return reference to temporary value
+  --> $DIR/issue-52534-1.rs:30:5
    |
 LL |     &&x
-   |      ^^ creates a temporary which is freed while still in use
-LL | }
-   | - temporary value is freed at the end of this statement
-   |
-note: borrowed value must be valid for the anonymous lifetime #1 defined on the function body at 28:1...
-  --> $DIR/issue-52534-1.rs:28:1
-   |
-LL | / fn baz(x: &u32) -> &&u32 {
-LL | |     let x = 22;
-LL | |     &&x
-LL | | }
-   | |_^
+   |     ^--
+   |     ||
+   |     |temporary value created here
+   |     returns a reference to data owned by the current function
 
-error[E0597]: `x` does not live long enough
+error[E0515]: cannot return reference to local variable `x`
   --> $DIR/issue-52534-1.rs:35:5
    |
-LL | fn foobazbar<'a>(x: u32, y: &'a u32) -> &'a u32 {
-   |                              --          -- also has lifetime `'a`
-   |                              |
-   |                              has lifetime `'a`
-LL |     let x = 22;
 LL |     &x
-   |     ^^ `x` would have to be valid for `'a`...
-LL | }
-   | - ...but `x` will be dropped here, when the function `foobazbar` returns
-   |
-   = help: use data from the highlighted arguments which match the `'a` lifetime of the return type
-   = note: functions cannot return a borrow to data owned within the function's scope, functions can only return borrows to data passed as arguments
-   = note: to learn more, visit <https://doc.rust-lang.org/book/second-edition/ch04-02-references-and-borrowing.html#dangling-references>
+   |     ^^ returns a reference to data owned by the current function
 
-error[E0597]: `x` does not live long enough
+error[E0515]: cannot return reference to local variable `x`
   --> $DIR/issue-52534-1.rs:40:5
    |
-LL | fn foobar<'a>(x: &'a u32) -> &'a u32 {
-   |                   --          -- also has lifetime `'a`
-   |                   |
-   |                   has lifetime `'a`
-LL |     let x = 22;
 LL |     &x
-   |     ^^ `x` would have to be valid for `'a`...
-LL | }
-   | - ...but `x` will be dropped here, when the function `foobar` returns
-   |
-   = help: use data from the highlighted arguments which match the `'a` lifetime of the return type
-   = note: functions cannot return a borrow to data owned within the function's scope, functions can only return borrows to data passed as arguments
-   = note: to learn more, visit <https://doc.rust-lang.org/book/second-edition/ch04-02-references-and-borrowing.html#dangling-references>
+   |     ^^ returns a reference to data owned by the current function
 
-error[E0597]: `x` does not live long enough
+error[E0515]: cannot return reference to local variable `x`
   --> $DIR/issue-52534-1.rs:45:5
    |
-LL | fn foobaz<'a, 'b>(x: &'a u32, y: &'b u32) -> &'a u32 {
-   |                       -- has lifetime `'a`    -- also has lifetime `'a`
-LL |     let x = 22;
 LL |     &x
-   |     ^^ `x` would have to be valid for `'a`...
-LL | }
-   | - ...but `x` will be dropped here, when the function `foobaz` returns
-   |
-   = help: use data from the highlighted arguments which match the `'a` lifetime of the return type
-   = note: functions cannot return a borrow to data owned within the function's scope, functions can only return borrows to data passed as arguments
-   = note: to learn more, visit <https://doc.rust-lang.org/book/second-edition/ch04-02-references-and-borrowing.html#dangling-references>
+   |     ^^ returns a reference to data owned by the current function
 
-error[E0597]: `x` does not live long enough
+error[E0515]: cannot return reference to local variable `x`
   --> $DIR/issue-52534-1.rs:50:5
    |
-LL | fn foobarbaz<'a, 'b>(x: &'a u32, y: &'b u32, z: &'a u32) -> &'a u32 {
-   |                          --                      --          -- also has lifetime `'a`
-   |                          |                       |
-   |                          has lifetime `'a`       has lifetime `'a`
-LL |     let x = 22;
 LL |     &x
-   |     ^^ `x` would have to be valid for `'a`...
-LL | }
-   | - ...but `x` will be dropped here, when the function `foobarbaz` returns
-   |
-   = help: use data from the highlighted arguments which match the `'a` lifetime of the return type
-   = note: functions cannot return a borrow to data owned within the function's scope, functions can only return borrows to data passed as arguments
-   = note: to learn more, visit <https://doc.rust-lang.org/book/second-edition/ch04-02-references-and-borrowing.html#dangling-references>
+   |     ^^ returns a reference to data owned by the current function
 
 error: aborting due to 8 previous errors
 
-Some errors occurred: E0597, E0716.
-For more information about an error, try `rustc --explain E0597`.
+For more information about this error, try `rustc --explain E0515`.
index a30d522f3ff0748afc99208657e7040473c66bcf..c4aab0b8b1d6a50fe97dfa44d41880dd13af446e 100644 (file)
@@ -1,12 +1,8 @@
-error[E0597]: `x` does not live long enough
+error[E0515]: cannot return reference to local variable `x`
   --> $DIR/polonius-smoke-test.rs:7:5
    |
 LL |     &x //~ ERROR
-   |     ^^ borrowed value does not live long enough
-LL | }
-   | - `x` dropped here while still borrowed
-   |
-   = note: borrowed value must be valid for the static lifetime...
+   |     ^^ returns a reference to data owned by the current function
 
 error[E0503]: cannot use `x` because it was mutably borrowed
   --> $DIR/polonius-smoke-test.rs:13:13
@@ -41,5 +37,5 @@ LL |     tmp;
 
 error: aborting due to 4 previous errors
 
-Some errors occurred: E0503, E0505, E0597.
+Some errors occurred: E0503, E0505, E0515.
 For more information about an error, try `rustc --explain E0503`.
index 15c4cc2e100b511625582520edec60fd32a419a1..9a46f8d7e92f55a08a82cfac5a625635173ffda3 100644 (file)
@@ -2,12 +2,12 @@ error[E0597]: `b` does not live long enough
   --> $DIR/var-appears-twice.rs:33:38
    |
 LL |     let x: DoubleCell<_> = make_cell(&b); //~ ERROR
-   |                                      ^^ borrowed value does not live long enough
+   |            -------------             ^^ borrowed value does not live long enough
+   |            |
+   |            type annotation requires that `b` is borrowed for `'static`
 ...
 LL | }
    | - `b` dropped here while still borrowed
-   |
-   = note: borrowed value must be valid for the static lifetime...
 
 error: aborting due to previous error
 
index e598147bdab770d2163cdd6bb3098eefd28ea1af..a1feadfb0d1f55a289d35977c7c712154756c417 100644 (file)
@@ -14,8 +14,8 @@
 #![allow(dead_code)]
 
 fn gimme_static_mut() -> &'static mut u32 {
-    let ref mut x = 1234543; //~ ERROR temporary value dropped while borrowed [E0716]
-    x
+    let ref mut x = 1234543;
+    x //~ ERROR cannot return value referencing temporary value [E0515]
 }
 
 fn main() {}
index 368cc67747185b7581da86261036aec06018fc75..4b74aa042f7593992419ba67b0d6785c8a448431 100644 (file)
@@ -1,14 +1,11 @@
-error[E0716]: temporary value dropped while borrowed
-  --> $DIR/return-ref-mut-issue-46557.rs:17:21
+error[E0515]: cannot return value referencing temporary value
+  --> $DIR/return-ref-mut-issue-46557.rs:18:5
    |
-LL |     let ref mut x = 1234543; //~ ERROR temporary value dropped while borrowed [E0716]
-   |                     ^^^^^^^ creates a temporary which is freed while still in use
-LL |     x
-LL | }
-   | - temporary value is freed at the end of this statement
-   |
-   = note: borrowed value must be valid for the static lifetime...
+LL |     let ref mut x = 1234543;
+   |                     ------- temporary value created here
+LL |     x //~ ERROR cannot return value referencing temporary value [E0515]
+   |     ^ returns a value referencing data owned by the current function
 
 error: aborting due to previous error
 
-For more information about this error, try `rustc --explain E0716`.
+For more information about this error, try `rustc --explain E0515`.
index 842bb622bc323b360563eb0d02deedb2dd7fd562..7a4a62a9fb22d75ee522207191751bd24f1e9b42 100644 (file)
@@ -2,39 +2,40 @@ error[E0597]: `c` does not live long enough
   --> $DIR/adt-brace-enums.rs:37:48
    |
 LL |     SomeEnum::SomeVariant::<&'static u32> { t: &c }; //~ ERROR
-   |                                                ^^ borrowed value does not live long enough
+   |                                                ^^
+   |                                                |
+   |                                                borrowed value does not live long enough
+   |                                                requires that `c` is borrowed for `'static`
 LL | }
    | - `c` dropped here while still borrowed
-   |
-   = note: borrowed value must be valid for the static lifetime...
 
 error[E0597]: `c` does not live long enough
   --> $DIR/adt-brace-enums.rs:42:43
    |
+LL | fn annot_reference_named_lifetime<'a>(_d: &'a u32) {
+   |                                   -- lifetime `'a` defined here
+LL |     let c = 66;
 LL |     SomeEnum::SomeVariant::<&'a u32> { t: &c }; //~ ERROR
-   |                                           ^^ borrowed value does not live long enough
+   |                                           ^^
+   |                                           |
+   |                                           borrowed value does not live long enough
+   |                                           requires that `c` is borrowed for `'a`
 LL | }
    | - `c` dropped here while still borrowed
-   |
-note: borrowed value must be valid for the lifetime 'a as defined on the function body at 40:35...
-  --> $DIR/adt-brace-enums.rs:40:35
-   |
-LL | fn annot_reference_named_lifetime<'a>(_d: &'a u32) {
-   |                                   ^^
 
 error[E0597]: `c` does not live long enough
   --> $DIR/adt-brace-enums.rs:52:47
    |
+LL | fn annot_reference_named_lifetime_in_closure<'a>(_: &'a u32) {
+   |                                              -- lifetime `'a` defined here
+...
 LL |         SomeEnum::SomeVariant::<&'a u32> { t: &c }; //~ ERROR
-   |                                               ^^ borrowed value does not live long enough
+   |                                               ^^
+   |                                               |
+   |                                               borrowed value does not live long enough
+   |                                               requires that `c` is borrowed for `'a`
 LL |     };
    |     - `c` dropped here while still borrowed
-   |
-note: borrowed value must be valid for the lifetime 'a as defined on the function body at 49:46...
-  --> $DIR/adt-brace-enums.rs:49:46
-   |
-LL | fn annot_reference_named_lifetime_in_closure<'a>(_: &'a u32) {
-   |                                              ^^
 
 error: aborting due to 3 previous errors
 
index 7ba76212dc5204b058904235c83dba9183deba9d..8b057a3eb8c86c6c55db70a2d8042ba34a844bc4 100644 (file)
@@ -2,39 +2,40 @@ error[E0597]: `c` does not live long enough
   --> $DIR/adt-brace-structs.rs:35:37
    |
 LL |     SomeStruct::<&'static u32> { t: &c }; //~ ERROR
-   |                                     ^^ borrowed value does not live long enough
+   |                                     ^^
+   |                                     |
+   |                                     borrowed value does not live long enough
+   |                                     requires that `c` is borrowed for `'static`
 LL | }
    | - `c` dropped here while still borrowed
-   |
-   = note: borrowed value must be valid for the static lifetime...
 
 error[E0597]: `c` does not live long enough
   --> $DIR/adt-brace-structs.rs:40:32
    |
+LL | fn annot_reference_named_lifetime<'a>(_d: &'a u32) {
+   |                                   -- lifetime `'a` defined here
+LL |     let c = 66;
 LL |     SomeStruct::<&'a u32> { t: &c }; //~ ERROR
-   |                                ^^ borrowed value does not live long enough
+   |                                ^^
+   |                                |
+   |                                borrowed value does not live long enough
+   |                                requires that `c` is borrowed for `'a`
 LL | }
    | - `c` dropped here while still borrowed
-   |
-note: borrowed value must be valid for the lifetime 'a as defined on the function body at 38:35...
-  --> $DIR/adt-brace-structs.rs:38:35
-   |
-LL | fn annot_reference_named_lifetime<'a>(_d: &'a u32) {
-   |                                   ^^
 
 error[E0597]: `c` does not live long enough
   --> $DIR/adt-brace-structs.rs:50:36
    |
+LL | fn annot_reference_named_lifetime_in_closure<'a>(_: &'a u32) {
+   |                                              -- lifetime `'a` defined here
+...
 LL |         SomeStruct::<&'a u32> { t: &c }; //~ ERROR
-   |                                    ^^ borrowed value does not live long enough
+   |                                    ^^
+   |                                    |
+   |                                    borrowed value does not live long enough
+   |                                    requires that `c` is borrowed for `'a`
 LL |     };
    |     - `c` dropped here while still borrowed
-   |
-note: borrowed value must be valid for the lifetime 'a as defined on the function body at 47:46...
-  --> $DIR/adt-brace-structs.rs:47:46
-   |
-LL | fn annot_reference_named_lifetime_in_closure<'a>(_: &'a u32) {
-   |                                              ^^
 
 error: aborting due to 3 previous errors
 
index fa251f3df17b9765c43736cc1082a4d00d974ed7..1626dc333a89bd258ed33256a96a82a26ecc4c83 100644 (file)
@@ -2,42 +2,43 @@ error[E0597]: `c` does not live long enough
   --> $DIR/adt-nullary-enums.rs:44:41
    |
 LL |         SomeEnum::SomeVariant(Cell::new(&c)), //~ ERROR
-   |                                         ^^ borrowed value does not live long enough
+   |                               ----------^^-
+   |                               |         |
+   |                               |         borrowed value does not live long enough
+   |                               argument requires that `c` is borrowed for `'static`
 ...
 LL | }
    | - `c` dropped here while still borrowed
-   |
-   = note: borrowed value must be valid for the static lifetime...
 
 error[E0597]: `c` does not live long enough
   --> $DIR/adt-nullary-enums.rs:52:41
    |
+LL | fn annot_reference_named_lifetime<'a>(_d: &'a u32) {
+   |                                   -- lifetime `'a` defined here
+...
 LL |         SomeEnum::SomeVariant(Cell::new(&c)), //~ ERROR
-   |                                         ^^ borrowed value does not live long enough
+   |                               ----------^^-
+   |                               |         |
+   |                               |         borrowed value does not live long enough
+   |                               argument requires that `c` is borrowed for `'a`
 ...
 LL | }
    | - `c` dropped here while still borrowed
-   |
-note: borrowed value must be valid for the lifetime 'a as defined on the function body at 49:35...
-  --> $DIR/adt-nullary-enums.rs:49:35
-   |
-LL | fn annot_reference_named_lifetime<'a>(_d: &'a u32) {
-   |                                   ^^
 
 error[E0597]: `c` does not live long enough
   --> $DIR/adt-nullary-enums.rs:65:45
    |
+LL | fn annot_reference_named_lifetime_in_closure<'a>(_: &'a u32) {
+   |                                              -- lifetime `'a` defined here
+...
 LL |             SomeEnum::SomeVariant(Cell::new(&c)), //~ ERROR
-   |                                             ^^ borrowed value does not live long enough
+   |                                   ----------^^-
+   |                                   |         |
+   |                                   |         borrowed value does not live long enough
+   |                                   argument requires that `c` is borrowed for `'a`
 ...
 LL |     };
    |     - `c` dropped here while still borrowed
-   |
-note: borrowed value must be valid for the lifetime 'a as defined on the function body at 61:46...
-  --> $DIR/adt-nullary-enums.rs:61:46
-   |
-LL | fn annot_reference_named_lifetime_in_closure<'a>(_: &'a u32) {
-   |                                              ^^
 
 error: aborting due to 3 previous errors
 
index 18d1cc7e087937290196f3ab111cf227308145f1..6e47eb1a3edc1d75bd2e2bbd89fd0693a851e262 100644 (file)
@@ -2,39 +2,40 @@ error[E0597]: `c` does not live long enough
   --> $DIR/adt-tuple-enums.rs:39:43
    |
 LL |     SomeEnum::SomeVariant::<&'static u32>(&c); //~ ERROR
-   |                                           ^^ borrowed value does not live long enough
+   |                                           ^^
+   |                                           |
+   |                                           borrowed value does not live long enough
+   |                                           requires that `c` is borrowed for `'static`
 LL | }
    | - `c` dropped here while still borrowed
-   |
-   = note: borrowed value must be valid for the static lifetime...
 
 error[E0597]: `c` does not live long enough
   --> $DIR/adt-tuple-enums.rs:44:38
    |
+LL | fn annot_reference_named_lifetime<'a>(_d: &'a u32) {
+   |                                   -- lifetime `'a` defined here
+LL |     let c = 66;
 LL |     SomeEnum::SomeVariant::<&'a u32>(&c); //~ ERROR
-   |                                      ^^ borrowed value does not live long enough
+   |                                      ^^
+   |                                      |
+   |                                      borrowed value does not live long enough
+   |                                      requires that `c` is borrowed for `'a`
 LL | }
    | - `c` dropped here while still borrowed
-   |
-note: borrowed value must be valid for the lifetime 'a as defined on the function body at 42:35...
-  --> $DIR/adt-tuple-enums.rs:42:35
-   |
-LL | fn annot_reference_named_lifetime<'a>(_d: &'a u32) {
-   |                                   ^^
 
 error[E0597]: `c` does not live long enough
   --> $DIR/adt-tuple-enums.rs:54:42
    |
+LL | fn annot_reference_named_lifetime_in_closure<'a>(_: &'a u32) {
+   |                                              -- lifetime `'a` defined here
+...
 LL |         SomeEnum::SomeVariant::<&'a u32>(&c); //~ ERROR
-   |                                          ^^ borrowed value does not live long enough
+   |                                          ^^
+   |                                          |
+   |                                          borrowed value does not live long enough
+   |                                          requires that `c` is borrowed for `'a`
 LL |     };
    |     - `c` dropped here while still borrowed
-   |
-note: borrowed value must be valid for the lifetime 'a as defined on the function body at 51:46...
-  --> $DIR/adt-tuple-enums.rs:51:46
-   |
-LL | fn annot_reference_named_lifetime_in_closure<'a>(_: &'a u32) {
-   |                                              ^^
 
 error: aborting due to 3 previous errors
 
index 397016e52d0f7e72f854c637a66d0a3e675b8883..136c727550ce8e48dccbf9700516e956d6bc946e 100644 (file)
@@ -2,39 +2,40 @@ error[E0597]: `c` does not live long enough
   --> $DIR/adt-tuple-struct.rs:35:32
    |
 LL |     SomeStruct::<&'static u32>(&c); //~ ERROR
-   |                                ^^ borrowed value does not live long enough
+   |                                ^^
+   |                                |
+   |                                borrowed value does not live long enough
+   |                                requires that `c` is borrowed for `'static`
 LL | }
    | - `c` dropped here while still borrowed
-   |
-   = note: borrowed value must be valid for the static lifetime...
 
 error[E0597]: `c` does not live long enough
   --> $DIR/adt-tuple-struct.rs:40:27
    |
+LL | fn annot_reference_named_lifetime<'a>(_d: &'a u32) {
+   |                                   -- lifetime `'a` defined here
+LL |     let c = 66;
 LL |     SomeStruct::<&'a u32>(&c); //~ ERROR
-   |                           ^^ borrowed value does not live long enough
+   |                           ^^
+   |                           |
+   |                           borrowed value does not live long enough
+   |                           requires that `c` is borrowed for `'a`
 LL | }
    | - `c` dropped here while still borrowed
-   |
-note: borrowed value must be valid for the lifetime 'a as defined on the function body at 38:35...
-  --> $DIR/adt-tuple-struct.rs:38:35
-   |
-LL | fn annot_reference_named_lifetime<'a>(_d: &'a u32) {
-   |                                   ^^
 
 error[E0597]: `c` does not live long enough
   --> $DIR/adt-tuple-struct.rs:50:31
    |
+LL | fn annot_reference_named_lifetime_in_closure<'a>(_: &'a u32) {
+   |                                              -- lifetime `'a` defined here
+...
 LL |         SomeStruct::<&'a u32>(&c); //~ ERROR
-   |                               ^^ borrowed value does not live long enough
+   |                               ^^
+   |                               |
+   |                               borrowed value does not live long enough
+   |                               requires that `c` is borrowed for `'a`
 LL |     };
    |     - `c` dropped here while still borrowed
-   |
-note: borrowed value must be valid for the lifetime 'a as defined on the function body at 47:46...
-  --> $DIR/adt-tuple-struct.rs:47:46
-   |
-LL | fn annot_reference_named_lifetime_in_closure<'a>(_: &'a u32) {
-   |                                              ^^
 
 error: aborting due to 3 previous errors
 
index a35035b07ba5463256bf0e95a9f4b3deddb27adc..c664746437d2ecbf98f0bf50b5bdf3ae5e7ac530 100644 (file)
@@ -2,11 +2,12 @@ error[E0597]: `x` does not live long enough
   --> $DIR/cast_static_lifetime.rs:16:19
    |
 LL |     let y: &u32 = (&x) as &'static u32;
-   |                   ^^^^ borrowed value does not live long enough
+   |                   ^^^^----------------
+   |                   |
+   |                   borrowed value does not live long enough
+   |                   type annotation requires that `x` is borrowed for `'static`
 LL | }
    | - `x` dropped here while still borrowed
-   |
-   = note: borrowed value must be valid for the static lifetime...
 
 error: aborting due to previous error
 
index b6ef336567ca0da7b4cfed90140031314b992fe1..80b79bfef8b6c61194e5e9022539c91b2a25c56d 100644 (file)
@@ -2,39 +2,40 @@ error[E0597]: `c` does not live long enough
   --> $DIR/fns.rs:35:29
    |
 LL |     some_fn::<&'static u32>(&c); //~ ERROR
-   |                             ^^ borrowed value does not live long enough
+   |     ------------------------^^-
+   |     |                       |
+   |     |                       borrowed value does not live long enough
+   |     argument requires that `c` is borrowed for `'static`
 LL | }
    | - `c` dropped here while still borrowed
-   |
-   = note: borrowed value must be valid for the static lifetime...
 
 error[E0597]: `c` does not live long enough
   --> $DIR/fns.rs:40:24
    |
+LL | fn annot_reference_named_lifetime<'a>(_d: &'a u32) {
+   |                                   -- lifetime `'a` defined here
+LL |     let c = 66;
 LL |     some_fn::<&'a u32>(&c); //~ ERROR
-   |                        ^^ borrowed value does not live long enough
+   |     -------------------^^-
+   |     |                  |
+   |     |                  borrowed value does not live long enough
+   |     argument requires that `c` is borrowed for `'a`
 LL | }
    | - `c` dropped here while still borrowed
-   |
-note: borrowed value must be valid for the lifetime 'a as defined on the function body at 38:35...
-  --> $DIR/fns.rs:38:35
-   |
-LL | fn annot_reference_named_lifetime<'a>(_d: &'a u32) {
-   |                                   ^^
 
 error[E0597]: `c` does not live long enough
   --> $DIR/fns.rs:50:28
    |
+LL | fn annot_reference_named_lifetime_in_closure<'a>(_: &'a u32) {
+   |                                              -- lifetime `'a` defined here
+...
 LL |         some_fn::<&'a u32>(&c); //~ ERROR
-   |                            ^^ borrowed value does not live long enough
+   |         -------------------^^-
+   |         |                  |
+   |         |                  borrowed value does not live long enough
+   |         argument requires that `c` is borrowed for `'a`
 LL |     };
    |     - `c` dropped here while still borrowed
-   |
-note: borrowed value must be valid for the lifetime 'a as defined on the function body at 47:46...
-  --> $DIR/fns.rs:47:46
-   |
-LL | fn annot_reference_named_lifetime_in_closure<'a>(_: &'a u32) {
-   |                                              ^^
 
 error: aborting due to 3 previous errors
 
index f1c7ff1e0fb19e98f1b844134a298da70ea9c591..32803839d31c537814e868203c0e4fcc8ac7e43e 100644 (file)
@@ -2,39 +2,40 @@ error[E0597]: `c` does not live long enough
   --> $DIR/method-call.rs:48:34
    |
 LL |     a.method::<&'static u32>(b,  &c); //~ ERROR
-   |                                  ^^ borrowed value does not live long enough
+   |     -----------------------------^^-
+   |     |                            |
+   |     |                            borrowed value does not live long enough
+   |     argument requires that `c` is borrowed for `'static`
 LL | }
    | - `c` dropped here while still borrowed
-   |
-   = note: borrowed value must be valid for the static lifetime...
 
 error[E0597]: `c` does not live long enough
   --> $DIR/method-call.rs:55:29
    |
+LL | fn annot_reference_named_lifetime<'a>(_d: &'a u32) {
+   |                                   -- lifetime `'a` defined here
+...
 LL |     a.method::<&'a u32>(b,  &c); //~ ERROR
-   |                             ^^ borrowed value does not live long enough
+   |     ------------------------^^-
+   |     |                       |
+   |     |                       borrowed value does not live long enough
+   |     argument requires that `c` is borrowed for `'a`
 LL | }
    | - `c` dropped here while still borrowed
-   |
-note: borrowed value must be valid for the lifetime 'a as defined on the function body at 51:35...
-  --> $DIR/method-call.rs:51:35
-   |
-LL | fn annot_reference_named_lifetime<'a>(_d: &'a u32) {
-   |                                   ^^
 
 error[E0597]: `c` does not live long enough
   --> $DIR/method-call.rs:69:33
    |
+LL | fn annot_reference_named_lifetime_in_closure<'a>(_: &'a u32) {
+   |                                              -- lifetime `'a` defined here
+...
 LL |         a.method::<&'a u32>(b,  &c); //~ ERROR
-   |                                 ^^ borrowed value does not live long enough
+   |         ------------------------^^-
+   |         |                       |
+   |         |                       borrowed value does not live long enough
+   |         argument requires that `c` is borrowed for `'a`
 LL |     };
    |     - `c` dropped here while still borrowed
-   |
-note: borrowed value must be valid for the lifetime 'a as defined on the function body at 64:46...
-  --> $DIR/method-call.rs:64:46
-   |
-LL | fn annot_reference_named_lifetime_in_closure<'a>(_: &'a u32) {
-   |                                              ^^
 
 error: aborting due to 3 previous errors
 
index f439748ef97b970ccecb7d6c1c082dc747049c16..10a2f10bb7fb535d84f51ec1bbe4edd8d80bdaa6 100644 (file)
@@ -2,43 +2,44 @@ error[E0597]: `a` does not live long enough
   --> $DIR/method-ufcs-1.rs:42:7
    |
 LL |     x(&a, b, c); //~ ERROR
-   |       ^^ borrowed value does not live long enough
+   |     --^^-------
+   |     | |
+   |     | borrowed value does not live long enough
+   |     argument requires that `a` is borrowed for `'static`
 LL | }
    | - `a` dropped here while still borrowed
-   |
-   = note: borrowed value must be valid for the static lifetime...
 
 error[E0597]: `a` does not live long enough
   --> $DIR/method-ufcs-1.rs:49:36
    |
+LL | fn annot_reference_named_lifetime<'a>(_d: &'a u32) {
+   |                                   -- lifetime `'a` defined here
+...
 LL |     <&'a u32 as Bazoom<_>>::method(&a, b, c); //~ ERROR
-   |                                    ^^ borrowed value does not live long enough
+   |     -------------------------------^^-------
+   |     |                              |
+   |     |                              borrowed value does not live long enough
+   |     argument requires that `a` is borrowed for `'a`
 LL | }
    | - `a` dropped here while still borrowed
-   |
-note: borrowed value must be valid for the lifetime 'a as defined on the function body at 45:35...
-  --> $DIR/method-ufcs-1.rs:45:35
-   |
-LL | fn annot_reference_named_lifetime<'a>(_d: &'a u32) {
-   |                                   ^^
 
 error[E0597]: `a` does not live long enough
   --> $DIR/method-ufcs-1.rs:63:41
    |
+LL | fn annot_reference_named_lifetime_in_closure<'a>(_: &'a u32) {
+   |                                              -- lifetime `'a` defined here
+...
 LL |     let _closure = || {
    |                    -- value captured here
 LL |         let c = 66;
 LL |         <&'a u32 as Bazoom<_>>::method(&a, b, c); //~ ERROR
-   |                                         ^ borrowed value does not live long enough
+   |         --------------------------------^-------
+   |         |                               |
+   |         |                               borrowed value does not live long enough
+   |         argument requires that `a` is borrowed for `'a`
 LL |     };
 LL | }
    | - `a` dropped here while still borrowed
-   |
-note: borrowed value must be valid for the lifetime 'a as defined on the function body at 58:46...
-  --> $DIR/method-ufcs-1.rs:58:46
-   |
-LL | fn annot_reference_named_lifetime_in_closure<'a>(_: &'a u32) {
-   |                                              ^^
 
 error: aborting due to 3 previous errors
 
index dc0f559659001fa97da7d1cb799572dcb7baa097..972f6af24ebfb00bb04bb40bc4cf828c0c67645c 100644 (file)
@@ -2,43 +2,44 @@ error[E0597]: `a` does not live long enough
   --> $DIR/method-ufcs-2.rs:42:7
    |
 LL |     x(&a, b, c); //~ ERROR
-   |       ^^ borrowed value does not live long enough
+   |     --^^-------
+   |     | |
+   |     | borrowed value does not live long enough
+   |     argument requires that `a` is borrowed for `'static`
 LL | }
    | - `a` dropped here while still borrowed
-   |
-   = note: borrowed value must be valid for the static lifetime...
 
 error[E0597]: `b` does not live long enough
   --> $DIR/method-ufcs-2.rs:49:39
    |
+LL | fn annot_reference_named_lifetime<'a>(_d: &'a u32) {
+   |                                   -- lifetime `'a` defined here
+...
 LL |     <_ as Bazoom<&'a u32>>::method(a, &b, c); //~ ERROR
-   |                                       ^^ borrowed value does not live long enough
+   |     ----------------------------------^^----
+   |     |                                 |
+   |     |                                 borrowed value does not live long enough
+   |     argument requires that `b` is borrowed for `'a`
 LL | }
    | - `b` dropped here while still borrowed
-   |
-note: borrowed value must be valid for the lifetime 'a as defined on the function body at 45:35...
-  --> $DIR/method-ufcs-2.rs:45:35
-   |
-LL | fn annot_reference_named_lifetime<'a>(_d: &'a u32) {
-   |                                   ^^
 
 error[E0597]: `b` does not live long enough
   --> $DIR/method-ufcs-2.rs:63:44
    |
+LL | fn annot_reference_named_lifetime_in_closure<'a>(_: &'a u32) {
+   |                                              -- lifetime `'a` defined here
+...
 LL |     let _closure = || {
    |                    -- value captured here
 LL |         let c = 66;
 LL |         <_ as Bazoom<&'a u32>>::method(a, &b, c); //~ ERROR
-   |                                            ^ borrowed value does not live long enough
+   |         -----------------------------------^----
+   |         |                                  |
+   |         |                                  borrowed value does not live long enough
+   |         argument requires that `b` is borrowed for `'a`
 LL |     };
 LL | }
    | - `b` dropped here while still borrowed
-   |
-note: borrowed value must be valid for the lifetime 'a as defined on the function body at 58:46...
-  --> $DIR/method-ufcs-2.rs:58:46
-   |
-LL | fn annot_reference_named_lifetime_in_closure<'a>(_: &'a u32) {
-   |                                              ^^
 
 error: aborting due to 3 previous errors
 
index 7ddea3eb2c62fb5f227281836e8b1bd49fc33564..7313787fa170ba0116155f4257ce82516305a519 100644 (file)
@@ -2,39 +2,40 @@ error[E0597]: `c` does not live long enough
   --> $DIR/method-ufcs-3.rs:48:53
    |
 LL |     <_ as Bazoom<_>>::method::<&'static u32>(&a, b, &c); //~ ERROR
-   |                                                     ^^ borrowed value does not live long enough
+   |     ------------------------------------------------^^-
+   |     |                                               |
+   |     |                                               borrowed value does not live long enough
+   |     argument requires that `c` is borrowed for `'static`
 LL | }
    | - `c` dropped here while still borrowed
-   |
-   = note: borrowed value must be valid for the static lifetime...
 
 error[E0597]: `c` does not live long enough
   --> $DIR/method-ufcs-3.rs:55:48
    |
+LL | fn annot_reference_named_lifetime<'a>(_d: &'a u32) {
+   |                                   -- lifetime `'a` defined here
+...
 LL |     <_ as Bazoom<_>>::method::<&'a u32>(&a, b, &c); //~ ERROR
-   |                                                ^^ borrowed value does not live long enough
+   |     -------------------------------------------^^-
+   |     |                                          |
+   |     |                                          borrowed value does not live long enough
+   |     argument requires that `c` is borrowed for `'a`
 LL | }
    | - `c` dropped here while still borrowed
-   |
-note: borrowed value must be valid for the lifetime 'a as defined on the function body at 51:35...
-  --> $DIR/method-ufcs-3.rs:51:35
-   |
-LL | fn annot_reference_named_lifetime<'a>(_d: &'a u32) {
-   |                                   ^^
 
 error[E0597]: `c` does not live long enough
   --> $DIR/method-ufcs-3.rs:69:52
    |
+LL | fn annot_reference_named_lifetime_in_closure<'a>(_: &'a u32) {
+   |                                              -- lifetime `'a` defined here
+...
 LL |         <_ as Bazoom<_>>::method::<&'a u32>(&a, b, &c); //~ ERROR
-   |                                                    ^^ borrowed value does not live long enough
+   |         -------------------------------------------^^-
+   |         |                                          |
+   |         |                                          borrowed value does not live long enough
+   |         argument requires that `c` is borrowed for `'a`
 LL |     };
    |     - `c` dropped here while still borrowed
-   |
-note: borrowed value must be valid for the lifetime 'a as defined on the function body at 64:46...
-  --> $DIR/method-ufcs-3.rs:64:46
-   |
-LL | fn annot_reference_named_lifetime_in_closure<'a>(_: &'a u32) {
-   |                                              ^^
 
 error: aborting due to 3 previous errors
 
index aa133ce286d51f7f6f9deac228fc88fd5c889d37..cb6cc6479646100170dca4741c4e48b2e4dca548 100644 (file)
@@ -1,17 +1,17 @@
 error[E0597]: `v` does not live long enough
   --> $DIR/method-ufcs-inherent-1.rs:16:26
    |
+LL | fn foo<'a>() {
+   |        -- lifetime `'a` defined here
+LL |     let v = 22;
 LL |     let x = A::<'a>::new(&v, 22);
-   |                          ^^ borrowed value does not live long enough
+   |             -------------^^-----
+   |             |            |
+   |             |            borrowed value does not live long enough
+   |             argument requires that `v` is borrowed for `'a`
 LL |     //~^ ERROR
 LL | }
    | - `v` dropped here while still borrowed
-   |
-note: borrowed value must be valid for the lifetime 'a as defined on the function body at 14:8...
-  --> $DIR/method-ufcs-inherent-1.rs:14:8
-   |
-LL | fn foo<'a>() {
-   |        ^^
 
 error: aborting due to previous error
 
index f1f4787d05869f90831eb3f166fea9a1ab02ac1e..4dc534b2e77acb5b5e8285d09f85ef8c499f7e0a 100644 (file)
@@ -1,32 +1,32 @@
 error[E0597]: `v` does not live long enough
   --> $DIR/method-ufcs-inherent-2.rs:16:37
    |
+LL | fn foo<'a>() {
+   |        -- lifetime `'a` defined here
+LL |     let v = 22;
 LL |     let x = A::<'a>::new::<&'a u32>(&v, &v);
-   |                                     ^^ borrowed value does not live long enough
+   |             ------------------------^^-----
+   |             |                       |
+   |             |                       borrowed value does not live long enough
+   |             argument requires that `v` is borrowed for `'a`
 ...
 LL | }
    | - `v` dropped here while still borrowed
-   |
-note: borrowed value must be valid for the lifetime 'a as defined on the function body at 14:8...
-  --> $DIR/method-ufcs-inherent-2.rs:14:8
-   |
-LL | fn foo<'a>() {
-   |        ^^
 
 error[E0597]: `v` does not live long enough
   --> $DIR/method-ufcs-inherent-2.rs:16:41
    |
+LL | fn foo<'a>() {
+   |        -- lifetime `'a` defined here
+LL |     let v = 22;
 LL |     let x = A::<'a>::new::<&'a u32>(&v, &v);
-   |                                         ^^ borrowed value does not live long enough
+   |             ----------------------------^^-
+   |             |                           |
+   |             |                           borrowed value does not live long enough
+   |             argument requires that `v` is borrowed for `'a`
 ...
 LL | }
    | - `v` dropped here while still borrowed
-   |
-note: borrowed value must be valid for the lifetime 'a as defined on the function body at 14:8...
-  --> $DIR/method-ufcs-inherent-2.rs:14:8
-   |
-LL | fn foo<'a>() {
-   |        ^^
 
 error: aborting due to 2 previous errors
 
index f3766a8c8e52d6fdda448f3b618420990f6ccdfb..2f83283ef912247566020b36ea4fb47f7476d8cb 100644 (file)
@@ -1,17 +1,17 @@
 error[E0597]: `v` does not live long enough
   --> $DIR/method-ufcs-inherent-3.rs:16:26
    |
+LL | fn foo<'a>() {
+   |        -- lifetime `'a` defined here
+LL |     let v = 22;
 LL |     let x = <A<'a>>::new(&v, 22);
-   |                          ^^ borrowed value does not live long enough
+   |             -------------^^-----
+   |             |            |
+   |             |            borrowed value does not live long enough
+   |             argument requires that `v` is borrowed for `'a`
 LL |     //~^ ERROR
 LL | }
    | - `v` dropped here while still borrowed
-   |
-note: borrowed value must be valid for the lifetime 'a as defined on the function body at 14:8...
-  --> $DIR/method-ufcs-inherent-3.rs:14:8
-   |
-LL | fn foo<'a>() {
-   |        ^^
 
 error: aborting due to previous error
 
index c9bce5077d62960bd9db1d8b358bbe1df0acbba7..a41cf50465e876dbfeedb290cc69a5dd111d592b 100644 (file)
@@ -1,32 +1,32 @@
 error[E0597]: `v` does not live long enough
   --> $DIR/method-ufcs-inherent-4.rs:17:37
    |
+LL | fn foo<'a>() {
+   |        -- lifetime `'a` defined here
+LL |     let v = 22;
 LL |     let x = <A<'a>>::new::<&'a u32>(&v, &v);
-   |                                     ^^ borrowed value does not live long enough
+   |             ------------------------^^-----
+   |             |                       |
+   |             |                       borrowed value does not live long enough
+   |             argument requires that `v` is borrowed for `'a`
 ...
 LL | }
    | - `v` dropped here while still borrowed
-   |
-note: borrowed value must be valid for the lifetime 'a as defined on the function body at 15:8...
-  --> $DIR/method-ufcs-inherent-4.rs:15:8
-   |
-LL | fn foo<'a>() {
-   |        ^^
 
 error[E0597]: `v` does not live long enough
   --> $DIR/method-ufcs-inherent-4.rs:17:41
    |
+LL | fn foo<'a>() {
+   |        -- lifetime `'a` defined here
+LL |     let v = 22;
 LL |     let x = <A<'a>>::new::<&'a u32>(&v, &v);
-   |                                         ^^ borrowed value does not live long enough
+   |             ----------------------------^^-
+   |             |                           |
+   |             |                           borrowed value does not live long enough
+   |             argument requires that `v` is borrowed for `'a`
 ...
 LL | }
    | - `v` dropped here while still borrowed
-   |
-note: borrowed value must be valid for the lifetime 'a as defined on the function body at 15:8...
-  --> $DIR/method-ufcs-inherent-4.rs:15:8
-   |
-LL | fn foo<'a>() {
-   |        ^^
 
 error: aborting due to 2 previous errors
 
index 489f9feb044c83f0c64fa3c5328ad9a584d47d7b..b059d5aa89ad0758207e5d7b0888412afe11ab5c 100644 (file)
@@ -2,11 +2,11 @@ error[E0597]: `a` does not live long enough
   --> $DIR/normalization.rs:12:31
    |
 LL |     let b: <() as Foo>::Out = &a; //~ ERROR
-   |                               ^^ borrowed value does not live long enough
+   |            ----------------   ^^ borrowed value does not live long enough
+   |            |
+   |            type annotation requires that `a` is borrowed for `'static`
 LL | }
    | - `a` dropped here while still borrowed
-   |
-   = note: borrowed value must be valid for the static lifetime...
 
 error: aborting due to previous error
 
index 5dbbf7c5b4811d388413e20b7b4d06bb74312bb7..800c822058d0aec8300f352582a550db88680241 100644 (file)
@@ -3,11 +3,11 @@ error[E0597]: `y` does not live long enough
    |
 LL |     let foo = Foo::Bar { field: &y };
    |                                 ^^ borrowed value does not live long enough
-...
+LL |     //~^ ERROR `y` does not live long enough
+LL |     let Foo::Bar::<'static> { field: _z } = foo;
+   |         --------------------------------- type annotation requires that `y` is borrowed for `'static`
 LL | }
    | - `y` dropped here while still borrowed
-   |
-   = note: borrowed value must be valid for the static lifetime...
 
 error[E0597]: `y` does not live long enough
   --> $DIR/pattern_substs_on_brace_enum_variant.rs:16:33
@@ -15,10 +15,11 @@ error[E0597]: `y` does not live long enough
 LL |     let foo = Foo::Bar { field: &y };
    |                                 ^^ borrowed value does not live long enough
 ...
+LL |         Foo::Bar::<'static> { field: _z } => {
+   |         --------------------------------- type annotation requires that `y` is borrowed for `'static`
+...
 LL | }
    | - `y` dropped here while still borrowed
-   |
-   = note: borrowed value must be valid for the static lifetime...
 
 error: aborting due to 2 previous errors
 
index 0108a185b1f3ea9b20eec34a01f0acf347229b6e..8adadfb8b6796f2ed1beca41e8e1ca5fdde17839 100644 (file)
@@ -3,11 +3,11 @@ error[E0597]: `y` does not live long enough
    |
 LL |     let foo = Foo { field: &y };
    |                            ^^ borrowed value does not live long enough
-...
+LL |     //~^ ERROR `y` does not live long enough
+LL |     let Foo::<'static> { field: _z } = foo;
+   |         ---------------------------- type annotation requires that `y` is borrowed for `'static`
 LL | }
    | - `y` dropped here while still borrowed
-   |
-   = note: borrowed value must be valid for the static lifetime...
 
 error[E0597]: `y` does not live long enough
   --> $DIR/pattern_substs_on_brace_struct.rs:14:28
@@ -15,10 +15,11 @@ error[E0597]: `y` does not live long enough
 LL |     let foo = Foo { field: &y };
    |                            ^^ borrowed value does not live long enough
 ...
+LL |         Foo::<'static> { field: _z } => {
+   |         ---------------------------- type annotation requires that `y` is borrowed for `'static`
+...
 LL | }
    | - `y` dropped here while still borrowed
-   |
-   = note: borrowed value must be valid for the static lifetime...
 
 error: aborting due to 2 previous errors
 
index b18fdc30ac2d62a551e07da0ea56db657b82bac4..0fd5fc3578d57de8b3e7e3dbebcd214206590043 100644 (file)
@@ -3,11 +3,11 @@ error[E0597]: `y` does not live long enough
    |
 LL |     let foo = Foo::Bar(&y);
    |                        ^^ borrowed value does not live long enough
-...
+LL |     //~^ ERROR `y` does not live long enough
+LL |     let Foo::Bar::<'static>(_z) = foo;
+   |         ----------------------- type annotation requires that `y` is borrowed for `'static`
 LL | }
    | - `y` dropped here while still borrowed
-   |
-   = note: borrowed value must be valid for the static lifetime...
 
 error[E0597]: `y` does not live long enough
   --> $DIR/pattern_substs_on_tuple_enum_variant.rs:16:24
@@ -15,10 +15,11 @@ error[E0597]: `y` does not live long enough
 LL |     let foo = Foo::Bar(&y);
    |                        ^^ borrowed value does not live long enough
 ...
+LL |         Foo::Bar::<'static>(_z) => {
+   |         ----------------------- type annotation requires that `y` is borrowed for `'static`
+...
 LL | }
    | - `y` dropped here while still borrowed
-   |
-   = note: borrowed value must be valid for the static lifetime...
 
 error: aborting due to 2 previous errors
 
index b72fda955801c65068486cdc645b5a163a4bb1c4..3d114fa5d7535d2e9fee02aefd45aaf437444188 100644 (file)
@@ -3,11 +3,11 @@ error[E0597]: `y` does not live long enough
    |
 LL |     let foo = Foo(&y);
    |                   ^^ borrowed value does not live long enough
-...
+LL |     //~^ ERROR `y` does not live long enough
+LL |     let Foo::<'static>(_z) = foo;
+   |         ------------------ type annotation requires that `y` is borrowed for `'static`
 LL | }
    | - `y` dropped here while still borrowed
-   |
-   = note: borrowed value must be valid for the static lifetime...
 
 error[E0597]: `y` does not live long enough
   --> $DIR/pattern_substs_on_tuple_struct.rs:14:19
@@ -15,10 +15,11 @@ error[E0597]: `y` does not live long enough
 LL |     let foo = Foo(&y);
    |                   ^^ borrowed value does not live long enough
 ...
+LL |         Foo::<'static>(_z) => {
+   |         ------------------ type annotation requires that `y` is borrowed for `'static`
+...
 LL | }
    | - `y` dropped here while still borrowed
-   |
-   = note: borrowed value must be valid for the static lifetime...
 
 error: aborting due to 2 previous errors
 
index 0b0848e99137eb3d619633bf201eaa6a85e174bc..0c50b98ee2713ad7219a97bed9d2f655d421653c 100644 (file)
 error[E0597]: `x` does not live long enough
   --> $DIR/patterns.rs:8:9
    |
+LL |     let y: &'static u32;
+   |            ------------ type annotation requires that `x` is borrowed for `'static`
 LL |     y = &x; //~ ERROR
    |         ^^ borrowed value does not live long enough
 LL | }
    | - `x` dropped here while still borrowed
-   |
-   = note: borrowed value must be valid for the static lifetime...
 
 error[E0597]: `x` does not live long enough
   --> $DIR/patterns.rs:22:13
    |
 LL |     let y = &x; //~ ERROR
    |             ^^ borrowed value does not live long enough
-...
+LL |     let ref z: &'static u32 = y;
+   |                ------------ type annotation requires that `x` is borrowed for `'static`
+LL |     **z
 LL | }
    | - `x` dropped here while still borrowed
-   |
-   = note: borrowed value must be valid for the static lifetime...
 
 error[E0597]: `x` does not live long enough
   --> $DIR/patterns.rs:46:27
    |
 LL |     let y: &'static u32 = &x; //~ ERROR
-   |                           ^^ borrowed value does not live long enough
+   |            ------------   ^^ borrowed value does not live long enough
+   |            |
+   |            type annotation requires that `x` is borrowed for `'static`
 LL | }
    | - `x` dropped here while still borrowed
-   |
-   = note: borrowed value must be valid for the static lifetime...
 
 error[E0597]: `x` does not live long enough
   --> $DIR/patterns.rs:51:27
    |
 LL |     let _: &'static u32 = &x; //~ ERROR
-   |                           ^^ borrowed value does not live long enough
+   |            ------------   ^^ borrowed value does not live long enough
+   |            |
+   |            type annotation requires that `x` is borrowed for `'static`
 ...
 LL | }
    | - `x` dropped here while still borrowed
-   |
-   = note: borrowed value must be valid for the static lifetime...
 
 error[E0716]: temporary value dropped while borrowed
   --> $DIR/patterns.rs:53:41
    |
 LL |     let _: Vec<&'static String> = vec![&String::new()];
-   |                                         ^^^^^^^^^^^^^ - temporary value is freed at the end of this statement
-   |                                         |
-   |                                         creates a temporary which is freed while still in use
-   |
-   = note: borrowed value must be valid for the static lifetime...
+   |            --------------------         ^^^^^^^^^^^^^ - temporary value is freed at the end of this statement
+   |            |                            |
+   |            |                            creates a temporary which is freed while still in use
+   |            type annotation requires that borrow lasts for `'static`
 
 error[E0716]: temporary value dropped while borrowed
   --> $DIR/patterns.rs:56:52
    |
 LL |     let (_, a): (Vec<&'static String>, _) = (vec![&String::new()], 44);
-   |                                                    ^^^^^^^^^^^^^      - temporary value is freed at the end of this statement
-   |                                                    |
-   |                                                    creates a temporary which is freed while still in use
-   |
-   = note: borrowed value must be valid for the static lifetime...
+   |                 -------------------------          ^^^^^^^^^^^^^      - temporary value is freed at the end of this statement
+   |                 |                                  |
+   |                 |                                  creates a temporary which is freed while still in use
+   |                 type annotation requires that borrow lasts for `'static`
 
 error[E0716]: temporary value dropped while borrowed
   --> $DIR/patterns.rs:59:53
    |
 LL |     let (_a, b): (Vec<&'static String>, _) = (vec![&String::new()], 44);
-   |                                                     ^^^^^^^^^^^^^      - temporary value is freed at the end of this statement
-   |                                                     |
-   |                                                     creates a temporary which is freed while still in use
-   |
-   = note: borrowed value must be valid for the static lifetime...
+   |                  -------------------------          ^^^^^^^^^^^^^      - temporary value is freed at the end of this statement
+   |                  |                                  |
+   |                  |                                  creates a temporary which is freed while still in use
+   |                  type annotation requires that borrow lasts for `'static`
 
 error[E0597]: `x` does not live long enough
   --> $DIR/patterns.rs:65:40
    |
 LL |     let (_, _): (&'static u32, u32) = (&x, 44); //~ ERROR
-   |                                        ^^ borrowed value does not live long enough
+   |                 -------------------    ^^ borrowed value does not live long enough
+   |                 |
+   |                 type annotation requires that `x` is borrowed for `'static`
 LL | }
    | - `x` dropped here while still borrowed
-   |
-   = note: borrowed value must be valid for the static lifetime...
 
 error[E0597]: `x` does not live long enough
   --> $DIR/patterns.rs:70:40
    |
 LL |     let (y, _): (&'static u32, u32) = (&x, 44); //~ ERROR
-   |                                        ^^ borrowed value does not live long enough
+   |                 -------------------    ^^ borrowed value does not live long enough
+   |                 |
+   |                 type annotation requires that `x` is borrowed for `'static`
 LL | }
    | - `x` dropped here while still borrowed
-   |
-   = note: borrowed value must be valid for the static lifetime...
 
 error[E0597]: `x` does not live long enough
   --> $DIR/patterns.rs:75:69
    |
 LL |     let Single { value: y }: Single<&'static u32> = Single { value: &x }; //~ ERROR
-   |                                                                     ^^ borrowed value does not live long enough
+   |                              --------------------                   ^^ borrowed value does not live long enough
+   |                              |
+   |                              type annotation requires that `x` is borrowed for `'static`
 LL | }
    | - `x` dropped here while still borrowed
-   |
-   = note: borrowed value must be valid for the static lifetime...
 
 error[E0597]: `x` does not live long enough
   --> $DIR/patterns.rs:80:69
    |
 LL |     let Single { value: _ }: Single<&'static u32> = Single { value: &x }; //~ ERROR
-   |                                                                     ^^ borrowed value does not live long enough
+   |                              --------------------                   ^^ borrowed value does not live long enough
+   |                              |
+   |                              type annotation requires that `x` is borrowed for `'static`
 LL | }
    | - `x` dropped here while still borrowed
-   |
-   = note: borrowed value must be valid for the static lifetime...
 
 error[E0597]: `x` does not live long enough
   --> $DIR/patterns.rs:88:17
    |
+LL |     let Double { value1: _, value2: _ }: Double<&'static u32> = Double {
+   |                                          -------------------- type annotation requires that `x` is borrowed for `'static`
 LL |         value1: &x, //~ ERROR
    |                 ^^ borrowed value does not live long enough
 ...
 LL | }
    | - `x` dropped here while still borrowed
-   |
-   = note: borrowed value must be valid for the static lifetime...
 
 error: unsatisfied lifetime constraints
   --> $DIR/patterns.rs:101:5
index 2303ed64db94da0203981e609ec2bd838941e486..50df5f615fae511e9ac7a320d4bf4ddf9b562db3 100644 (file)
@@ -2,11 +2,12 @@ error[E0597]: `x` does not live long enough
   --> $DIR/type_ascription_static_lifetime.rs:18:19
    |
 LL |     let y: &u32 = &x: &'static u32; //~ ERROR E0597
-   |                   ^^ borrowed value does not live long enough
+   |                   ^^--------------
+   |                   |
+   |                   borrowed value does not live long enough
+   |                   type annotation requires that `x` is borrowed for `'static`
 LL | }
    | - `x` dropped here while still borrowed
-   |
-   = note: borrowed value must be valid for the static lifetime...
 
 error: aborting due to previous error
 
index 0c6913911ed5c995bcbba94c710566b86c353a33..19cb16d495b4af50f20bb46457e30ee192aad77d 100644 (file)
@@ -6,7 +6,7 @@ LL | fn bar<'a, 'b>(x: &'a u32, y: &'b u32) -> (&'a u32, &'b u32) {
    |        |
    |        lifetime `'a` defined here
 LL |     foo(x, y)
-   |     ^^^^^^^^^ argument requires that `'a` must outlive `'b`
+   |     ^^^^^^^^^ function was supposed to return data with lifetime `'b` but it is returning data with lifetime `'a`
 
 error: aborting due to previous error
 
index 5f386e58fac7d319b54622ad23672647fdd60bba..d41d36075000e8ee16c2a5a3a0491c7e163f30d9 100644 (file)
@@ -1,25 +1,39 @@
-error[E0597]: `x` does not live long enough
-  --> $DIR/region-borrow-params-issue-29793-big.rs:81:43
+error[E0373]: closure may outlive the current function, but it borrows `x`, which is owned by the current function
+  --> $DIR/region-borrow-params-issue-29793-big.rs:81:26
    |
 LL |         WrapB::new().set(|t: bool| if t { x } else { y }) // (separate errors for `x` vs `y`)
-   |                          ---------        ^ borrowed value does not live long enough
+   |                          ^^^^^^^^^        - `x` is borrowed here
    |                          |
-   |                          value captured here
-...
-LL |     });
-   |     - `x` dropped here while still borrowed
+   |                          may outlive borrowed value `x`
+   |
+note: closure is returned here
+  --> $DIR/region-borrow-params-issue-29793-big.rs:81:9
+   |
+LL |         WrapB::new().set(|t: bool| if t { x } else { y }) // (separate errors for `x` vs `y`)
+   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+help: to force the closure to take ownership of `x` (and any other referenced variables), use the `move` keyword
+   |
+LL |         WrapB::new().set(move |t: bool| if t { x } else { y }) // (separate errors for `x` vs `y`)
+   |                          ^^^^^^^^^^^^^^
 
-error[E0597]: `y` does not live long enough
-  --> $DIR/region-borrow-params-issue-29793-big.rs:81:54
+error[E0373]: closure may outlive the current function, but it borrows `y`, which is owned by the current function
+  --> $DIR/region-borrow-params-issue-29793-big.rs:81:26
    |
 LL |         WrapB::new().set(|t: bool| if t { x } else { y }) // (separate errors for `x` vs `y`)
-   |                          ---------                   ^ borrowed value does not live long enough
+   |                          ^^^^^^^^^                   - `y` is borrowed here
    |                          |
-   |                          value captured here
-...
-LL |     });
-   |     - `y` dropped here while still borrowed
+   |                          may outlive borrowed value `y`
+   |
+note: closure is returned here
+  --> $DIR/region-borrow-params-issue-29793-big.rs:81:9
+   |
+LL |         WrapB::new().set(|t: bool| if t { x } else { y }) // (separate errors for `x` vs `y`)
+   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+help: to force the closure to take ownership of `y` (and any other referenced variables), use the `move` keyword
+   |
+LL |         WrapB::new().set(move |t: bool| if t { x } else { y }) // (separate errors for `x` vs `y`)
+   |                          ^^^^^^^^^^^^^^
 
 error: aborting due to 2 previous errors
 
-For more information about this error, try `rustc --explain E0597`.
+For more information about this error, try `rustc --explain E0373`.
index 5f386e58fac7d319b54622ad23672647fdd60bba..d41d36075000e8ee16c2a5a3a0491c7e163f30d9 100644 (file)
@@ -1,25 +1,39 @@
-error[E0597]: `x` does not live long enough
-  --> $DIR/region-borrow-params-issue-29793-big.rs:81:43
+error[E0373]: closure may outlive the current function, but it borrows `x`, which is owned by the current function
+  --> $DIR/region-borrow-params-issue-29793-big.rs:81:26
    |
 LL |         WrapB::new().set(|t: bool| if t { x } else { y }) // (separate errors for `x` vs `y`)
-   |                          ---------        ^ borrowed value does not live long enough
+   |                          ^^^^^^^^^        - `x` is borrowed here
    |                          |
-   |                          value captured here
-...
-LL |     });
-   |     - `x` dropped here while still borrowed
+   |                          may outlive borrowed value `x`
+   |
+note: closure is returned here
+  --> $DIR/region-borrow-params-issue-29793-big.rs:81:9
+   |
+LL |         WrapB::new().set(|t: bool| if t { x } else { y }) // (separate errors for `x` vs `y`)
+   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+help: to force the closure to take ownership of `x` (and any other referenced variables), use the `move` keyword
+   |
+LL |         WrapB::new().set(move |t: bool| if t { x } else { y }) // (separate errors for `x` vs `y`)
+   |                          ^^^^^^^^^^^^^^
 
-error[E0597]: `y` does not live long enough
-  --> $DIR/region-borrow-params-issue-29793-big.rs:81:54
+error[E0373]: closure may outlive the current function, but it borrows `y`, which is owned by the current function
+  --> $DIR/region-borrow-params-issue-29793-big.rs:81:26
    |
 LL |         WrapB::new().set(|t: bool| if t { x } else { y }) // (separate errors for `x` vs `y`)
-   |                          ---------                   ^ borrowed value does not live long enough
+   |                          ^^^^^^^^^                   - `y` is borrowed here
    |                          |
-   |                          value captured here
-...
-LL |     });
-   |     - `y` dropped here while still borrowed
+   |                          may outlive borrowed value `y`
+   |
+note: closure is returned here
+  --> $DIR/region-borrow-params-issue-29793-big.rs:81:9
+   |
+LL |         WrapB::new().set(|t: bool| if t { x } else { y }) // (separate errors for `x` vs `y`)
+   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+help: to force the closure to take ownership of `y` (and any other referenced variables), use the `move` keyword
+   |
+LL |         WrapB::new().set(move |t: bool| if t { x } else { y }) // (separate errors for `x` vs `y`)
+   |                          ^^^^^^^^^^^^^^
 
 error: aborting due to 2 previous errors
 
-For more information about this error, try `rustc --explain E0597`.
+For more information about this error, try `rustc --explain E0373`.
index 642e90f6de8e622f92f3e1df039bfdb2d0980a31..ecd48d0b819e97cd6f7da4673ea07ed241401f67 100644 (file)
@@ -81,8 +81,8 @@ fn main() {
         WrapB::new().set(|t: bool| if t { x } else { y }) // (separate errors for `x` vs `y`)
             //[ast]~^ ERROR `x` does not live long enough
             //[ast]~| ERROR `y` does not live long enough
-            //[mir]~^^^ ERROR `x` does not live long enough
-            //[mir]~| ERROR `y` does not live long enough
+            //[mir]~^^^ ERROR closure may outlive the current function
+            //[mir]~| ERROR closure may outlive the current function
     });
 
     w.handle(); // This works
index d0d6bd4c78570c08bd349033b32a4855d9f205e6..f2d6e796872c5fba1349e431b78704c62ffce1f9 100644 (file)
-error[E0597]: `x` does not live long enough
-  --> $DIR/region-borrow-params-issue-29793-small.rs:19:34
+error[E0373]: closure may outlive the current function, but it borrows `x`, which is owned by the current function
+  --> $DIR/region-borrow-params-issue-29793-small.rs:19:17
    |
 LL |         let f = |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`)
-   |                 ---------        ^ borrowed value does not live long enough
+   |                 ^^^^^^^^^        - `x` is borrowed here
    |                 |
-   |                 value captured here
-...
-LL |     };
-   |      - `x` dropped here while still borrowed
+   |                 may outlive borrowed value `x`
+   |
+note: closure is returned here
+  --> $DIR/region-borrow-params-issue-29793-small.rs:22:16
+   |
+LL |         return f;
+   |                ^
+help: to force the closure to take ownership of `x` (and any other referenced variables), use the `move` keyword
+   |
+LL |         let f = move |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`)
+   |                 ^^^^^^^^^^^^^^
 
-error[E0597]: `y` does not live long enough
-  --> $DIR/region-borrow-params-issue-29793-small.rs:19:45
+error[E0373]: closure may outlive the current function, but it borrows `y`, which is owned by the current function
+  --> $DIR/region-borrow-params-issue-29793-small.rs:19:17
    |
 LL |         let f = |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`)
-   |                 ---------                   ^ borrowed value does not live long enough
+   |                 ^^^^^^^^^                   - `y` is borrowed here
    |                 |
-   |                 value captured here
-...
-LL |     };
-   |      - `y` dropped here while still borrowed
+   |                 may outlive borrowed value `y`
+   |
+note: closure is returned here
+  --> $DIR/region-borrow-params-issue-29793-small.rs:22:16
+   |
+LL |         return f;
+   |                ^
+help: to force the closure to take ownership of `y` (and any other referenced variables), use the `move` keyword
+   |
+LL |         let f = move |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`)
+   |                 ^^^^^^^^^^^^^^
 
-error[E0597]: `x` does not live long enough
-  --> $DIR/region-borrow-params-issue-29793-small.rs:34:34
+error[E0373]: closure may outlive the current function, but it borrows `x`, which is owned by the current function
+  --> $DIR/region-borrow-params-issue-29793-small.rs:34:17
    |
 LL |         let f = |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`)
-   |                 ---------        ^ borrowed value does not live long enough
+   |                 ^^^^^^^^^        - `x` is borrowed here
    |                 |
-   |                 value captured here
-...
-LL |     };
-   |      - `x` dropped here while still borrowed
+   |                 may outlive borrowed value `x`
+   |
+note: closure is returned here
+  --> $DIR/region-borrow-params-issue-29793-small.rs:37:9
+   |
+LL |         f
+   |         ^
+help: to force the closure to take ownership of `x` (and any other referenced variables), use the `move` keyword
+   |
+LL |         let f = move |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`)
+   |                 ^^^^^^^^^^^^^^
 
-error[E0597]: `y` does not live long enough
-  --> $DIR/region-borrow-params-issue-29793-small.rs:34:45
+error[E0373]: closure may outlive the current function, but it borrows `y`, which is owned by the current function
+  --> $DIR/region-borrow-params-issue-29793-small.rs:34:17
    |
 LL |         let f = |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`)
-   |                 ---------                   ^ borrowed value does not live long enough
+   |                 ^^^^^^^^^                   - `y` is borrowed here
    |                 |
-   |                 value captured here
-...
-LL |     };
-   |      - `y` dropped here while still borrowed
+   |                 may outlive borrowed value `y`
+   |
+note: closure is returned here
+  --> $DIR/region-borrow-params-issue-29793-small.rs:37:9
+   |
+LL |         f
+   |         ^
+help: to force the closure to take ownership of `y` (and any other referenced variables), use the `move` keyword
+   |
+LL |         let f = move |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`)
+   |                 ^^^^^^^^^^^^^^
 
-error[E0597]: `x` does not live long enough
-  --> $DIR/region-borrow-params-issue-29793-small.rs:65:34
+error[E0373]: closure may outlive the current function, but it borrows `x`, which is owned by the current function
+  --> $DIR/region-borrow-params-issue-29793-small.rs:65:17
    |
 LL |         let f = |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`)
-   |                 ---------        ^ borrowed value does not live long enough
+   |                 ^^^^^^^^^        - `x` is borrowed here
    |                 |
-   |                 value captured here
-...
-LL |     };
-   |     - `x` dropped here while still borrowed
+   |                 may outlive borrowed value `x`
+   |
+note: closure is returned here
+  --> $DIR/region-borrow-params-issue-29793-small.rs:68:16
    |
-note: borrowed value must be valid for the lifetime 'a as defined on the function body at 64:10...
-  --> $DIR/region-borrow-params-issue-29793-small.rs:64:10
+LL |         return Box::new(f);
+   |                ^^^^^^^^^^^
+help: to force the closure to take ownership of `x` (and any other referenced variables), use the `move` keyword
    |
-LL |     fn g<'a>(x: usize, y:usize) -> Box<Fn(bool) -> usize + 'a> {
-   |          ^^
+LL |         let f = move |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`)
+   |                 ^^^^^^^^^^^^^^
 
-error[E0597]: `y` does not live long enough
-  --> $DIR/region-borrow-params-issue-29793-small.rs:65:45
+error[E0373]: closure may outlive the current function, but it borrows `y`, which is owned by the current function
+  --> $DIR/region-borrow-params-issue-29793-small.rs:65:17
    |
 LL |         let f = |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`)
-   |                 ---------                   ^ borrowed value does not live long enough
+   |                 ^^^^^^^^^                   - `y` is borrowed here
    |                 |
-   |                 value captured here
-...
-LL |     };
-   |     - `y` dropped here while still borrowed
+   |                 may outlive borrowed value `y`
+   |
+note: closure is returned here
+  --> $DIR/region-borrow-params-issue-29793-small.rs:68:16
    |
-note: borrowed value must be valid for the lifetime 'a as defined on the function body at 64:10...
-  --> $DIR/region-borrow-params-issue-29793-small.rs:64:10
+LL |         return Box::new(f);
+   |                ^^^^^^^^^^^
+help: to force the closure to take ownership of `y` (and any other referenced variables), use the `move` keyword
    |
-LL |     fn g<'a>(x: usize, y:usize) -> Box<Fn(bool) -> usize + 'a> {
-   |          ^^
+LL |         let f = move |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`)
+   |                 ^^^^^^^^^^^^^^
 
-error[E0597]: `x` does not live long enough
-  --> $DIR/region-borrow-params-issue-29793-small.rs:76:34
+error[E0373]: closure may outlive the current function, but it borrows `x`, which is owned by the current function
+  --> $DIR/region-borrow-params-issue-29793-small.rs:76:17
    |
 LL |         let f = |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`)
-   |                 ---------        ^ borrowed value does not live long enough
+   |                 ^^^^^^^^^        - `x` is borrowed here
    |                 |
-   |                 value captured here
-...
-LL |     };
-   |     - `x` dropped here while still borrowed
+   |                 may outlive borrowed value `x`
    |
-note: borrowed value must be valid for the lifetime 'a as defined on the function body at 75:10...
-  --> $DIR/region-borrow-params-issue-29793-small.rs:75:10
+note: closure is returned here
+  --> $DIR/region-borrow-params-issue-29793-small.rs:79:9
    |
-LL |     fn g<'a>(x: usize, y:usize) -> Box<Fn(bool) -> usize + 'a> {
-   |          ^^
+LL |         Box::new(f)
+   |         ^^^^^^^^^^^
+help: to force the closure to take ownership of `x` (and any other referenced variables), use the `move` keyword
+   |
+LL |         let f = move |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`)
+   |                 ^^^^^^^^^^^^^^
 
-error[E0597]: `y` does not live long enough
-  --> $DIR/region-borrow-params-issue-29793-small.rs:76:45
+error[E0373]: closure may outlive the current function, but it borrows `y`, which is owned by the current function
+  --> $DIR/region-borrow-params-issue-29793-small.rs:76:17
    |
 LL |         let f = |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`)
-   |                 ---------                   ^ borrowed value does not live long enough
+   |                 ^^^^^^^^^                   - `y` is borrowed here
    |                 |
-   |                 value captured here
-...
-LL |     };
-   |     - `y` dropped here while still borrowed
+   |                 may outlive borrowed value `y`
+   |
+note: closure is returned here
+  --> $DIR/region-borrow-params-issue-29793-small.rs:79:9
    |
-note: borrowed value must be valid for the lifetime 'a as defined on the function body at 75:10...
-  --> $DIR/region-borrow-params-issue-29793-small.rs:75:10
+LL |         Box::new(f)
+   |         ^^^^^^^^^^^
+help: to force the closure to take ownership of `y` (and any other referenced variables), use the `move` keyword
    |
-LL |     fn g<'a>(x: usize, y:usize) -> Box<Fn(bool) -> usize + 'a> {
-   |          ^^
+LL |         let f = move |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`)
+   |                 ^^^^^^^^^^^^^^
 
-error[E0597]: `x` does not live long enough
-  --> $DIR/region-borrow-params-issue-29793-small.rs:100:38
+error[E0373]: closure may outlive the current function, but it borrows `x`, which is owned by the current function
+  --> $DIR/region-borrow-params-issue-29793-small.rs:100:21
    |
 LL |             let f = |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`)
-   |                     ---------        ^ borrowed value does not live long enough
+   |                     ^^^^^^^^^        - `x` is borrowed here
    |                     |
-   |                     value captured here
-...
-LL |         }
-   |         - `x` dropped here while still borrowed
+   |                     may outlive borrowed value `x`
    |
-note: borrowed value must be valid for the lifetime 'a as defined on the method body at 99:14...
-  --> $DIR/region-borrow-params-issue-29793-small.rs:99:14
+note: closure is returned here
+  --> $DIR/region-borrow-params-issue-29793-small.rs:103:20
    |
-LL |         fn g<'a>(&self, x: usize, y:usize) -> Box<Fn(bool) -> usize + 'a> {
-   |              ^^
+LL |             return Box::new(f);
+   |                    ^^^^^^^^^^^
+help: to force the closure to take ownership of `x` (and any other referenced variables), use the `move` keyword
+   |
+LL |             let f = move |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`)
+   |                     ^^^^^^^^^^^^^^
 
-error[E0597]: `y` does not live long enough
-  --> $DIR/region-borrow-params-issue-29793-small.rs:100:49
+error[E0373]: closure may outlive the current function, but it borrows `y`, which is owned by the current function
+  --> $DIR/region-borrow-params-issue-29793-small.rs:100:21
    |
 LL |             let f = |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`)
-   |                     ---------                   ^ borrowed value does not live long enough
+   |                     ^^^^^^^^^                   - `y` is borrowed here
    |                     |
-   |                     value captured here
-...
-LL |         }
-   |         - `y` dropped here while still borrowed
+   |                     may outlive borrowed value `y`
+   |
+note: closure is returned here
+  --> $DIR/region-borrow-params-issue-29793-small.rs:103:20
    |
-note: borrowed value must be valid for the lifetime 'a as defined on the method body at 99:14...
-  --> $DIR/region-borrow-params-issue-29793-small.rs:99:14
+LL |             return Box::new(f);
+   |                    ^^^^^^^^^^^
+help: to force the closure to take ownership of `y` (and any other referenced variables), use the `move` keyword
    |
-LL |         fn g<'a>(&self, x: usize, y:usize) -> Box<Fn(bool) -> usize + 'a> {
-   |              ^^
+LL |             let f = move |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`)
+   |                     ^^^^^^^^^^^^^^
 
-error[E0597]: `x` does not live long enough
-  --> $DIR/region-borrow-params-issue-29793-small.rs:114:38
+error[E0373]: closure may outlive the current function, but it borrows `x`, which is owned by the current function
+  --> $DIR/region-borrow-params-issue-29793-small.rs:114:21
    |
 LL |             let f = |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`)
-   |                     ---------        ^ borrowed value does not live long enough
+   |                     ^^^^^^^^^        - `x` is borrowed here
    |                     |
-   |                     value captured here
-...
-LL |         }
-   |         - `x` dropped here while still borrowed
+   |                     may outlive borrowed value `x`
    |
-note: borrowed value must be valid for the lifetime 'a as defined on the method body at 113:14...
-  --> $DIR/region-borrow-params-issue-29793-small.rs:113:14
+note: closure is returned here
+  --> $DIR/region-borrow-params-issue-29793-small.rs:117:13
    |
-LL |         fn g<'a>(&self, x: usize, y:usize) -> Box<Fn(bool) -> usize + 'a> {
-   |              ^^
+LL |             Box::new(f)
+   |             ^^^^^^^^^^^
+help: to force the closure to take ownership of `x` (and any other referenced variables), use the `move` keyword
+   |
+LL |             let f = move |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`)
+   |                     ^^^^^^^^^^^^^^
 
-error[E0597]: `y` does not live long enough
-  --> $DIR/region-borrow-params-issue-29793-small.rs:114:49
+error[E0373]: closure may outlive the current function, but it borrows `y`, which is owned by the current function
+  --> $DIR/region-borrow-params-issue-29793-small.rs:114:21
    |
 LL |             let f = |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`)
-   |                     ---------                   ^ borrowed value does not live long enough
+   |                     ^^^^^^^^^                   - `y` is borrowed here
    |                     |
-   |                     value captured here
-...
-LL |         }
-   |         - `y` dropped here while still borrowed
+   |                     may outlive borrowed value `y`
+   |
+note: closure is returned here
+  --> $DIR/region-borrow-params-issue-29793-small.rs:117:13
    |
-note: borrowed value must be valid for the lifetime 'a as defined on the method body at 113:14...
-  --> $DIR/region-borrow-params-issue-29793-small.rs:113:14
+LL |             Box::new(f)
+   |             ^^^^^^^^^^^
+help: to force the closure to take ownership of `y` (and any other referenced variables), use the `move` keyword
    |
-LL |         fn g<'a>(&self, x: usize, y:usize) -> Box<Fn(bool) -> usize + 'a> {
-   |              ^^
+LL |             let f = move |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`)
+   |                     ^^^^^^^^^^^^^^
 
-error[E0597]: `x` does not live long enough
-  --> $DIR/region-borrow-params-issue-29793-small.rs:142:38
+error[E0373]: closure may outlive the current function, but it borrows `x`, which is owned by the current function
+  --> $DIR/region-borrow-params-issue-29793-small.rs:142:21
    |
 LL |             let f = |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`)
-   |                     ---------        ^ borrowed value does not live long enough
+   |                     ^^^^^^^^^        - `x` is borrowed here
    |                     |
-   |                     value captured here
-...
-LL |         }
-   |         - `x` dropped here while still borrowed
+   |                     may outlive borrowed value `x`
+   |
+note: closure is returned here
+  --> $DIR/region-borrow-params-issue-29793-small.rs:145:20
    |
-note: borrowed value must be valid for the lifetime 'a as defined on the method body at 141:14...
-  --> $DIR/region-borrow-params-issue-29793-small.rs:141:14
+LL |             return Box::new(f);
+   |                    ^^^^^^^^^^^
+help: to force the closure to take ownership of `x` (and any other referenced variables), use the `move` keyword
    |
-LL |         fn g<'a>(&self, x: usize, y:usize) -> Box<Fn(bool) -> usize + 'a> {
-   |              ^^
+LL |             let f = move |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`)
+   |                     ^^^^^^^^^^^^^^
 
-error[E0597]: `y` does not live long enough
-  --> $DIR/region-borrow-params-issue-29793-small.rs:142:49
+error[E0373]: closure may outlive the current function, but it borrows `y`, which is owned by the current function
+  --> $DIR/region-borrow-params-issue-29793-small.rs:142:21
    |
 LL |             let f = |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`)
-   |                     ---------                   ^ borrowed value does not live long enough
+   |                     ^^^^^^^^^                   - `y` is borrowed here
    |                     |
-   |                     value captured here
-...
-LL |         }
-   |         - `y` dropped here while still borrowed
+   |                     may outlive borrowed value `y`
    |
-note: borrowed value must be valid for the lifetime 'a as defined on the method body at 141:14...
-  --> $DIR/region-borrow-params-issue-29793-small.rs:141:14
+note: closure is returned here
+  --> $DIR/region-borrow-params-issue-29793-small.rs:145:20
    |
-LL |         fn g<'a>(&self, x: usize, y:usize) -> Box<Fn(bool) -> usize + 'a> {
-   |              ^^
+LL |             return Box::new(f);
+   |                    ^^^^^^^^^^^
+help: to force the closure to take ownership of `y` (and any other referenced variables), use the `move` keyword
+   |
+LL |             let f = move |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`)
+   |                     ^^^^^^^^^^^^^^
 
-error[E0597]: `x` does not live long enough
-  --> $DIR/region-borrow-params-issue-29793-small.rs:157:38
+error[E0373]: closure may outlive the current function, but it borrows `x`, which is owned by the current function
+  --> $DIR/region-borrow-params-issue-29793-small.rs:157:21
    |
 LL |             let f = |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`)
-   |                     ---------        ^ borrowed value does not live long enough
+   |                     ^^^^^^^^^        - `x` is borrowed here
    |                     |
-   |                     value captured here
-...
-LL |         }
-   |         - `x` dropped here while still borrowed
+   |                     may outlive borrowed value `x`
+   |
+note: closure is returned here
+  --> $DIR/region-borrow-params-issue-29793-small.rs:160:13
    |
-note: borrowed value must be valid for the lifetime 'a as defined on the method body at 156:14...
-  --> $DIR/region-borrow-params-issue-29793-small.rs:156:14
+LL |             Box::new(f)
+   |             ^^^^^^^^^^^
+help: to force the closure to take ownership of `x` (and any other referenced variables), use the `move` keyword
    |
-LL |         fn g<'a>(&self, x: usize, y:usize) -> Box<Fn(bool) -> usize + 'a> {
-   |              ^^
+LL |             let f = move |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`)
+   |                     ^^^^^^^^^^^^^^
 
-error[E0597]: `y` does not live long enough
-  --> $DIR/region-borrow-params-issue-29793-small.rs:157:49
+error[E0373]: closure may outlive the current function, but it borrows `y`, which is owned by the current function
+  --> $DIR/region-borrow-params-issue-29793-small.rs:157:21
    |
 LL |             let f = |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`)
-   |                     ---------                   ^ borrowed value does not live long enough
+   |                     ^^^^^^^^^                   - `y` is borrowed here
    |                     |
-   |                     value captured here
-...
-LL |         }
-   |         - `y` dropped here while still borrowed
+   |                     may outlive borrowed value `y`
    |
-note: borrowed value must be valid for the lifetime 'a as defined on the method body at 156:14...
-  --> $DIR/region-borrow-params-issue-29793-small.rs:156:14
+note: closure is returned here
+  --> $DIR/region-borrow-params-issue-29793-small.rs:160:13
    |
-LL |         fn g<'a>(&self, x: usize, y:usize) -> Box<Fn(bool) -> usize + 'a> {
-   |              ^^
+LL |             Box::new(f)
+   |             ^^^^^^^^^^^
+help: to force the closure to take ownership of `y` (and any other referenced variables), use the `move` keyword
+   |
+LL |             let f = move |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`)
+   |                     ^^^^^^^^^^^^^^
 
-error[E0597]: `x` does not live long enough
-  --> $DIR/region-borrow-params-issue-29793-small.rs:185:38
+error[E0373]: closure may outlive the current function, but it borrows `x`, which is owned by the current function
+  --> $DIR/region-borrow-params-issue-29793-small.rs:185:21
    |
 LL |             let f = |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`)
-   |                     ---------        ^ borrowed value does not live long enough
+   |                     ^^^^^^^^^        - `x` is borrowed here
    |                     |
-   |                     value captured here
-...
-LL |         }
-   |         - `x` dropped here while still borrowed
+   |                     may outlive borrowed value `x`
+   |
+note: closure is returned here
+  --> $DIR/region-borrow-params-issue-29793-small.rs:188:20
    |
-note: borrowed value must be valid for the lifetime 'a as defined on the method body at 184:14...
-  --> $DIR/region-borrow-params-issue-29793-small.rs:184:14
+LL |             return Box::new(f);
+   |                    ^^^^^^^^^^^
+help: to force the closure to take ownership of `x` (and any other referenced variables), use the `move` keyword
    |
-LL |         fn g<'a>(&self, x: usize, y:usize) -> Box<Fn(bool) -> usize + 'a> {
-   |              ^^
+LL |             let f = move |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`)
+   |                     ^^^^^^^^^^^^^^
 
-error[E0597]: `y` does not live long enough
-  --> $DIR/region-borrow-params-issue-29793-small.rs:185:49
+error[E0373]: closure may outlive the current function, but it borrows `y`, which is owned by the current function
+  --> $DIR/region-borrow-params-issue-29793-small.rs:185:21
    |
 LL |             let f = |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`)
-   |                     ---------                   ^ borrowed value does not live long enough
+   |                     ^^^^^^^^^                   - `y` is borrowed here
    |                     |
-   |                     value captured here
-...
-LL |         }
-   |         - `y` dropped here while still borrowed
+   |                     may outlive borrowed value `y`
    |
-note: borrowed value must be valid for the lifetime 'a as defined on the method body at 184:14...
-  --> $DIR/region-borrow-params-issue-29793-small.rs:184:14
+note: closure is returned here
+  --> $DIR/region-borrow-params-issue-29793-small.rs:188:20
    |
-LL |         fn g<'a>(&self, x: usize, y:usize) -> Box<Fn(bool) -> usize + 'a> {
-   |              ^^
+LL |             return Box::new(f);
+   |                    ^^^^^^^^^^^
+help: to force the closure to take ownership of `y` (and any other referenced variables), use the `move` keyword
+   |
+LL |             let f = move |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`)
+   |                     ^^^^^^^^^^^^^^
 
-error[E0597]: `x` does not live long enough
-  --> $DIR/region-borrow-params-issue-29793-small.rs:199:38
+error[E0373]: closure may outlive the current function, but it borrows `x`, which is owned by the current function
+  --> $DIR/region-borrow-params-issue-29793-small.rs:199:21
    |
 LL |             let f = |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`)
-   |                     ---------        ^ borrowed value does not live long enough
+   |                     ^^^^^^^^^        - `x` is borrowed here
    |                     |
-   |                     value captured here
-...
-LL |         }
-   |         - `x` dropped here while still borrowed
+   |                     may outlive borrowed value `x`
+   |
+note: closure is returned here
+  --> $DIR/region-borrow-params-issue-29793-small.rs:202:13
    |
-note: borrowed value must be valid for the lifetime 'a as defined on the method body at 198:14...
-  --> $DIR/region-borrow-params-issue-29793-small.rs:198:14
+LL |             Box::new(f)
+   |             ^^^^^^^^^^^
+help: to force the closure to take ownership of `x` (and any other referenced variables), use the `move` keyword
    |
-LL |         fn g<'a>(&self, x: usize, y:usize) -> Box<Fn(bool) -> usize + 'a> {
-   |              ^^
+LL |             let f = move |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`)
+   |                     ^^^^^^^^^^^^^^
 
-error[E0597]: `y` does not live long enough
-  --> $DIR/region-borrow-params-issue-29793-small.rs:199:49
+error[E0373]: closure may outlive the current function, but it borrows `y`, which is owned by the current function
+  --> $DIR/region-borrow-params-issue-29793-small.rs:199:21
    |
 LL |             let f = |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`)
-   |                     ---------                   ^ borrowed value does not live long enough
+   |                     ^^^^^^^^^                   - `y` is borrowed here
    |                     |
-   |                     value captured here
-...
-LL |         }
-   |         - `y` dropped here while still borrowed
+   |                     may outlive borrowed value `y`
+   |
+note: closure is returned here
+  --> $DIR/region-borrow-params-issue-29793-small.rs:202:13
    |
-note: borrowed value must be valid for the lifetime 'a as defined on the method body at 198:14...
-  --> $DIR/region-borrow-params-issue-29793-small.rs:198:14
+LL |             Box::new(f)
+   |             ^^^^^^^^^^^
+help: to force the closure to take ownership of `y` (and any other referenced variables), use the `move` keyword
    |
-LL |         fn g<'a>(&self, x: usize, y:usize) -> Box<Fn(bool) -> usize + 'a> {
-   |              ^^
+LL |             let f = move |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`)
+   |                     ^^^^^^^^^^^^^^
 
 error: aborting due to 20 previous errors
 
-For more information about this error, try `rustc --explain E0597`.
+For more information about this error, try `rustc --explain E0373`.
index 3bfa5ec3941a26aaaa1c0346f5025289dad893c3..59871a510d3f3dde0880cd073668150a7ceb9a97 100644 (file)
@@ -1,13 +1,12 @@
-error[E0597]: `*x` does not live long enough
+error[E0515]: cannot return value referencing local data `*x`
   --> $DIR/region-object-lifetime-5.rs:21:5
    |
 LL |     x.borrowed() //~ ERROR `*x` does not live long enough
-   |     ^ borrowed value does not live long enough
-LL | }
-   | - `*x` dropped here while still borrowed
-   |
-   = note: borrowed value must be valid for the static lifetime...
+   |     -^^^^^^^^^^^
+   |     |
+   |     returns a value referencing data owned by the current function
+   |     `*x` is borrowed here
 
 error: aborting due to previous error
 
-For more information about this error, try `rustc --explain E0597`.
+For more information about this error, try `rustc --explain E0515`.
index 9bfc80c94595a3266b23ec405db714d05ff599dd..bfe5bd8ae69f1c84fac1fc0d892008aea034d645 100644 (file)
@@ -2,26 +2,19 @@ error[E0597]: `a` does not live long enough
   --> $DIR/regions-addr-of-arg.rs:15:30
    |
 LL |     let _p: &'static isize = &a; //~ ERROR `a` does not live long enough
-   |                              ^^ borrowed value does not live long enough
+   |             --------------   ^^ borrowed value does not live long enough
+   |             |
+   |             type annotation requires that `a` is borrowed for `'static`
 LL | }
    |  - `a` dropped here while still borrowed
-   |
-   = note: borrowed value must be valid for the static lifetime...
 
-error[E0597]: `a` does not live long enough
+error[E0515]: cannot return reference to function parameter `a`
   --> $DIR/regions-addr-of-arg.rs:23:5
    |
 LL |     &a //~ ERROR `a` does not live long enough
-   |     ^^ borrowed value does not live long enough
-LL | }
-   |  - `a` dropped here while still borrowed
-   |
-note: borrowed value must be valid for the lifetime 'a as defined on the function body at 22:8...
-  --> $DIR/regions-addr-of-arg.rs:22:8
-   |
-LL | fn zed<'a>(a: isize) -> &'a isize {
-   |        ^^
+   |     ^^ returns a reference to data owned by the current function
 
 error: aborting due to 2 previous errors
 
-For more information about this error, try `rustc --explain E0597`.
+Some errors occurred: E0515, E0597.
+For more information about an error, try `rustc --explain E0515`.
index 84e486872a70587e97d5182c97d4deecfeb5b590..9ad7ee8d4470c13186de62f24b2ff9fc67006d24 100644 (file)
@@ -1,13 +1,12 @@
-error[E0597]: `*v` does not live long enough
-  --> $DIR/regions-close-object-into-object-1.rs:22:11
+error[E0515]: cannot return value referencing local data `*v`
+  --> $DIR/regions-close-object-into-object-1.rs:22:5
    |
 LL |     box B(&*v) as Box<X> //~ ERROR `*v` does not live long enough
-   |           ^^^ borrowed value does not live long enough
-LL | }
-   | - `*v` dropped here while still borrowed
-   |
-   = note: borrowed value must be valid for the static lifetime...
+   |     ^^^^^^---^^^^^^^^^^^
+   |     |     |
+   |     |     `*v` is borrowed here
+   |     returns a value referencing data owned by the current function
 
 error: aborting due to previous error
 
-For more information about this error, try `rustc --explain E0597`.
+For more information about this error, try `rustc --explain E0515`.
index 62504ab8d8025396f23aa1aca02c8ecb91ed43b6..56ce993dc71dd2c33fd0d578fe6dd9a3a9ccc4a5 100644 (file)
@@ -1,13 +1,12 @@
-error[E0597]: `*v` does not live long enough
-  --> $DIR/regions-close-object-into-object-3.rs:21:11
+error[E0515]: cannot return value referencing local data `*v`
+  --> $DIR/regions-close-object-into-object-3.rs:21:5
    |
 LL |     box B(&*v) as Box<X> //~ ERROR `*v` does not live long enough
-   |           ^^^ borrowed value does not live long enough
-LL | }
-   | - `*v` dropped here while still borrowed
-   |
-   = note: borrowed value must be valid for the static lifetime...
+   |     ^^^^^^---^^^^^^^^^^^
+   |     |     |
+   |     |     `*v` is borrowed here
+   |     returns a value referencing data owned by the current function
 
 error: aborting due to previous error
 
-For more information about this error, try `rustc --explain E0597`.
+For more information about this error, try `rustc --explain E0515`.
index a98cacaad99bf5f8938efbc489d30ceaa98dd8c2..de3142939b799a167344b276289378ff7b7fcd6d 100644 (file)
@@ -1,31 +1,21 @@
-error[E0716]: temporary value dropped while borrowed
-  --> $DIR/regions-creating-enums.rs:33:17
+error[E0515]: cannot return reference to temporary value
+  --> $DIR/regions-creating-enums.rs:33:16
    |
 LL |         return &ast::num((*f)(x)); //~ ERROR borrowed value does not live long enough
-   |                 ^^^^^^^^^^^^^^^^^- temporary value is freed at the end of this statement
-   |                 |
-   |                 creates a temporary which is freed while still in use
-   |
-note: borrowed value must be valid for the lifetime 'a as defined on the function body at 30:13...
-  --> $DIR/regions-creating-enums.rs:30:13
-   |
-LL | fn map_nums<'a,'b, F>(x: &ast, f: &mut F) -> &'a ast<'b> where F: FnMut(usize) -> usize {
-   |             ^^
+   |                ^-----------------
+   |                ||
+   |                |temporary value created here
+   |                returns a reference to data owned by the current function
 
-error[E0716]: temporary value dropped while borrowed
-  --> $DIR/regions-creating-enums.rs:38:17
+error[E0515]: cannot return reference to temporary value
+  --> $DIR/regions-creating-enums.rs:38:16
    |
 LL |         return &ast::add(m_x, m_y);  //~ ERROR borrowed value does not live long enough
-   |                 ^^^^^^^^^^^^^^^^^^- temporary value is freed at the end of this statement
-   |                 |
-   |                 creates a temporary which is freed while still in use
-   |
-note: borrowed value must be valid for the lifetime 'a as defined on the function body at 30:13...
-  --> $DIR/regions-creating-enums.rs:30:13
-   |
-LL | fn map_nums<'a,'b, F>(x: &ast, f: &mut F) -> &'a ast<'b> where F: FnMut(usize) -> usize {
-   |             ^^
+   |                ^------------------
+   |                ||
+   |                |temporary value created here
+   |                returns a reference to data owned by the current function
 
 error: aborting due to 2 previous errors
 
-For more information about this error, try `rustc --explain E0716`.
+For more information about this error, try `rustc --explain E0515`.
index 9747602f1ba481343e3468f14faeac69cad1dc14..c6bd5b7fa0d2492554a924205a7db6f93cfde8fa 100644 (file)
@@ -1,32 +1,30 @@
 error[E0716]: temporary value dropped while borrowed
   --> $DIR/regions-free-region-ordering-caller1.rs:19:27
    |
+LL | fn call1<'a>(x: &'a usize) {
+   |          -- lifetime `'a` defined here
+...
 LL |     let z: &'a & usize = &(&y);
-   |                           ^^^^ creates a temporary which is freed while still in use
+   |            -----------    ^^^^ creates a temporary which is freed while still in use
+   |            |
+   |            type annotation requires that borrow lasts for `'a`
 ...
 LL | }
    | - temporary value is freed at the end of this statement
-   |
-note: borrowed value must be valid for the lifetime 'a as defined on the function body at 15:10...
-  --> $DIR/regions-free-region-ordering-caller1.rs:15:10
-   |
-LL | fn call1<'a>(x: &'a usize) {
-   |          ^^
 
 error[E0597]: `y` does not live long enough
   --> $DIR/regions-free-region-ordering-caller1.rs:19:27
    |
+LL | fn call1<'a>(x: &'a usize) {
+   |          -- lifetime `'a` defined here
+...
 LL |     let z: &'a & usize = &(&y);
-   |                           ^^^^ borrowed value does not live long enough
+   |            -----------    ^^^^ borrowed value does not live long enough
+   |            |
+   |            type annotation requires that `y` is borrowed for `'a`
 ...
 LL | }
    | - `y` dropped here while still borrowed
-   |
-note: borrowed value must be valid for the lifetime 'a as defined on the function body at 15:10...
-  --> $DIR/regions-free-region-ordering-caller1.rs:15:10
-   |
-LL | fn call1<'a>(x: &'a usize) {
-   |          ^^
 
 error: aborting due to 2 previous errors
 
index 28bf252bc9570b9ed4b2989e6f1edd78af9c30c4..a444f90bbe1c9e2c3abbcaaa71d7b44b971e7edc 100644 (file)
@@ -1,18 +1,12 @@
-error[E0597]: `*p` does not live long enough
-  --> $DIR/regions-infer-borrow-scope-too-big.rs:22:22
+error[E0515]: cannot return value referencing local data `*p`
+  --> $DIR/regions-infer-borrow-scope-too-big.rs:24:12
    |
 LL |     let xc = x_coord(&*p); //~ ERROR `*p` does not live long enough
-   |                      ^^^ borrowed value does not live long enough
-...
-LL | }
-   | - `*p` dropped here while still borrowed
-   |
-note: borrowed value must be valid for the lifetime 'a as defined on the function body at 21:8...
-  --> $DIR/regions-infer-borrow-scope-too-big.rs:21:8
-   |
-LL | fn foo<'a>(p: Box<point>) -> &'a isize {
-   |        ^^
+   |                      --- `*p` is borrowed here
+LL |     assert_eq!(*xc, 3);
+LL |     return xc;
+   |            ^^ returns a value referencing data owned by the current function
 
 error: aborting due to previous error
 
-For more information about this error, try `rustc --explain E0597`.
+For more information about this error, try `rustc --explain E0515`.
index fa358a9cc45c26074175df2d7161af0efaa34212..67b9e0975a777cadaa384afb14381bdd39c271b8 100644 (file)
@@ -1,13 +1,14 @@
 error[E0597]: `x` does not live long enough
   --> $DIR/regions-infer-proc-static-upvar.rs:20:13
    |
-LL |     let y = &x; //~ ERROR `x` does not live long enough
-   |             ^^ borrowed value does not live long enough
-...
-LL | }
-   | - `x` dropped here while still borrowed
-   |
-   = note: borrowed value must be valid for the static lifetime...
+LL |       let y = &x; //~ ERROR `x` does not live long enough
+   |               ^^ borrowed value does not live long enough
+LL | /     foo(move|| {
+LL | |         let _a = *y;
+LL | |     });
+   | |______- argument requires that `x` is borrowed for `'static`
+LL |   }
+   |   - `x` dropped here while still borrowed
 
 error: aborting due to previous error
 
index eb870d55e0f4b54e505495b51c8f0b708465d51b..c3a9a57d9eebbfa99e447ae3127e8d33b3a6d4b8 100644 (file)
@@ -1,33 +1,21 @@
-error[E0716]: temporary value dropped while borrowed
-  --> $DIR/regions-lifetime-of-struct-or-enum-variant.rs:24:20
+error[E0515]: cannot return value referencing temporary value
+  --> $DIR/regions-lifetime-of-struct-or-enum-variant.rs:26:3
    |
 LL |   let testValue = &id(Test);
-   |                    ^^^^^^^^ creates a temporary which is freed while still in use
-...
-LL | }
-   | - temporary value is freed at the end of this statement
-   |
-note: borrowed value must be valid for the lifetime 'a as defined on the function body at 23:19...
-  --> $DIR/regions-lifetime-of-struct-or-enum-variant.rs:23:19
-   |
-LL | fn structLifetime<'a>() -> &'a Test {
-   |                   ^^
+   |                    -------- temporary value created here
+LL |   //~^ ERROR borrowed value does not live long enough
+LL |   testValue
+   |   ^^^^^^^^^ returns a value referencing data owned by the current function
 
-error[E0716]: temporary value dropped while borrowed
-  --> $DIR/regions-lifetime-of-struct-or-enum-variant.rs:30:20
+error[E0515]: cannot return value referencing temporary value
+  --> $DIR/regions-lifetime-of-struct-or-enum-variant.rs:32:3
    |
 LL |   let testValue = &id(MyEnum::Variant1);
-   |                    ^^^^^^^^^^^^^^^^^^^^ creates a temporary which is freed while still in use
-...
-LL | }
-   | - temporary value is freed at the end of this statement
-   |
-note: borrowed value must be valid for the lifetime 'a as defined on the function body at 29:20...
-  --> $DIR/regions-lifetime-of-struct-or-enum-variant.rs:29:20
-   |
-LL | fn variantLifetime<'a>() -> &'a MyEnum {
-   |                    ^^
+   |                    -------------------- temporary value created here
+LL |   //~^ ERROR borrowed value does not live long enough
+LL |   testValue
+   |   ^^^^^^^^^ returns a value referencing data owned by the current function
 
 error: aborting due to 2 previous errors
 
-For more information about this error, try `rustc --explain E0716`.
+For more information about this error, try `rustc --explain E0515`.
index 1b5bb7d5007798038855dcb2287971fb8a05df2b..c45325f8c1e6056975960912172fad10e79f5492 100644 (file)
@@ -5,12 +5,13 @@ LL |         |z| {
    |         --- value captured here
 LL |             //~^ ERROR E0373
 LL |             if false { &y } else { z }
-   |                         ^ borrowed value does not live long enough
+   |                        -^
+   |                        ||
+   |                        |borrowed value does not live long enough
+   |                        returning this value requires that `y` is borrowed for `'static`
 LL |         });
 LL | }
    | - `y` dropped here while still borrowed
-   |
-   = note: borrowed value must be valid for the static lifetime...
 
 error: aborting due to previous error
 
index c39d007312fef08fb07cb05d6ff7fdda46669b28..927865a3d28c2779721cbe609a012ddc260a6031 100644 (file)
@@ -3,11 +3,11 @@ error[E0597]: `line` does not live long enough
    |
 LL |     match [&*line] { //~ ERROR `line` does not live long enough
    |              ^^^^ borrowed value does not live long enough
-...
+LL |         [ word ] => { assert_static(word); }
+   |                       ------------------- argument requires that `line` is borrowed for `'static`
+LL |     }
 LL | }
    | - `line` dropped here while still borrowed
-   |
-   = note: borrowed value must be valid for the static lifetime...
 
 error: aborting due to previous error
 
index 1976a3dc84d834299d5a8ba3b0d7eba06a15b4b3..b6f89540bd46c34cceb527771881a4daf69f8117 100644 (file)
@@ -1,22 +1,19 @@
-error[E0716]: temporary value dropped while borrowed
-  --> $DIR/regions-ref-in-fn-arg.rs:14:13
+error[E0515]: cannot return value referencing function parameter
+  --> $DIR/regions-ref-in-fn-arg.rs:15:5
    |
 LL | fn arg_item(box ref x: Box<isize>) -> &'static isize {
-   |             ^^^^^^^^^ creates a temporary which is freed while still in use
+   |             --------- function parameter borrowed here
 LL |     x //~^ ERROR borrowed value does not live long enough
-LL | }
-   | - temporary value is freed at the end of this statement
-   |
-   = note: borrowed value must be valid for the static lifetime...
+   |     ^ returns a value referencing data owned by the current function
 
-error[E0716]: temporary value dropped while borrowed
-  --> $DIR/regions-ref-in-fn-arg.rs:21:11
+error[E0515]: cannot return value referencing function parameter
+  --> $DIR/regions-ref-in-fn-arg.rs:21:22
    |
 LL |     with(|box ref x| x) //~ ERROR borrowed value does not live long enough
-   |           ^^^^^^^^^  - temporary value is freed at the end of this statement
+   |           ---------  ^ returns a value referencing data owned by the current function
    |           |
-   |           creates a temporary which is freed while still in use
+   |           function parameter borrowed here
 
 error: aborting due to 2 previous errors
 
-For more information about this error, try `rustc --explain E0716`.
+For more information about this error, try `rustc --explain E0515`.
index be4d5bf9da0d505a6832f32c33492f00ea17f3e6..35c1113fb624c6ee3aac614d4be6a8867a10b67b 100644 (file)
@@ -1,19 +1,12 @@
-error[E0716]: temporary value dropped while borrowed
-  --> $DIR/regions-ret.rs:14:13
+error[E0515]: cannot return reference to temporary value
+  --> $DIR/regions-ret.rs:14:12
    |
 LL |     return &id(3); //~ ERROR borrowed value does not live long enough
-   |             ^^^^^- temporary value is freed at the end of this statement
-   |             |
-   |             creates a temporary which is freed while still in use
-   |
-note: borrowed value must be valid for the anonymous lifetime #1 defined on the function body at 13:1...
-  --> $DIR/regions-ret.rs:13:1
-   |
-LL | / fn f(_x: &isize) -> &isize {
-LL | |     return &id(3); //~ ERROR borrowed value does not live long enough
-LL | | }
-   | |_^
+   |            ^-----
+   |            ||
+   |            |temporary value created here
+   |            returns a reference to data owned by the current function
 
 error: aborting due to previous error
 
-For more information about this error, try `rustc --explain E0716`.
+For more information about this error, try `rustc --explain E0515`.
index e175a3e7f2f8fbc7d8299afc2f1cb5f5199625b9..041d627f58447bfc9e45f30b9756bf3937f7a094 100644 (file)
@@ -1,13 +1,12 @@
-error[E0716]: temporary value dropped while borrowed
-  --> $DIR/regions-return-stack-allocated-vec.rs:14:6
+error[E0515]: cannot return reference to temporary value
+  --> $DIR/regions-return-stack-allocated-vec.rs:14:5
    |
 LL |     &[x] //~ ERROR borrowed value does not live long enough
-   |      ^^^ creates a temporary which is freed while still in use
-LL | }
-   | - temporary value is freed at the end of this statement
-   |
-   = note: borrowed value must be valid for the static lifetime...
+   |     ^---
+   |     ||
+   |     |temporary value created here
+   |     returns a reference to data owned by the current function
 
 error: aborting due to previous error
 
-For more information about this error, try `rustc --explain E0716`.
+For more information about this error, try `rustc --explain E0515`.
index c610394c51b7a1e3b0d1b4e1eeca2391c11f2905..92d5a10af3a1d27f93bf807a576c6f53e39498af 100644 (file)
@@ -1,18 +1,11 @@
-error[E0597]: `*b` does not live long enough
-  --> $DIR/regions-trait-variance.rs:47:18
+error[E0515]: cannot return value referencing local data `*b`
+  --> $DIR/regions-trait-variance.rs:48:5
    |
 LL |     let bb: &B = &*b; //~ ERROR `*b` does not live long enough
-   |                  ^^^ borrowed value does not live long enough
+   |                  --- `*b` is borrowed here
 LL |     make_a(bb)
-LL | }
-   | - `*b` dropped here while still borrowed
-   |
-note: borrowed value must be valid for the lifetime 'a as defined on the function body at 43:16...
-  --> $DIR/regions-trait-variance.rs:43:16
-   |
-LL | fn make_make_a<'a>() -> A<'a> {
-   |                ^^
+   |     ^^^^^^^^^^ returns a value referencing data owned by the current function
 
 error: aborting due to previous error
 
-For more information about this error, try `rustc --explain E0597`.
+For more information about this error, try `rustc --explain E0515`.
index e841e6c635bc31aedf064d36f11b50ac3500802c..7f14956e90b9024a2b375d4c495056a0192120bc 100644 (file)
@@ -1,12 +1,9 @@
-error[E0597]: `x` does not live long enough
+error[E0515]: cannot return reference to local data `x`
   --> $DIR/issue-11925.rs:18:35
    |
 LL |         let f = to_fn_once(move|| &x); //~ ERROR does not live long enough
-   |                                   ^-
-   |                                   ||
-   |                                   |`x` dropped here while still borrowed
-   |                                   borrowed value does not live long enough
+   |                                   ^^ returns a reference to data owned by the current function
 
 error: aborting due to previous error
 
-For more information about this error, try `rustc --explain E0597`.
+For more information about this error, try `rustc --explain E0515`.
index a498d80b67b1b2cc694a773c7bf72c0f392ee853..745f390a4f3e9d40aee2c519584653a0af6ef069 100644 (file)
@@ -8,11 +8,11 @@ error[E0716]: temporary value dropped while borrowed
   --> $DIR/static-drop-scope.rs:19:60
    |
 LL | static PROMOTION_FAIL_S: Option<&'static WithDtor> = Some(&WithDtor);
-   |                                                            ^^^^^^^^- temporary value is freed at the end of this statement
-   |                                                            |
-   |                                                            creates a temporary which is freed while still in use
-   |
-   = note: borrowed value must be valid for the static lifetime...
+   |                                                      ------^^^^^^^^-
+   |                                                      |     |       |
+   |                                                      |     |       temporary value is freed at the end of this statement
+   |                                                      |     creates a temporary which is freed while still in use
+   |                                                      using this value as a static requires that borrow lasts for `'static`
 
 error[E0493]: destructors cannot be evaluated at compile-time
   --> $DIR/static-drop-scope.rs:23:59
@@ -24,11 +24,11 @@ error[E0716]: temporary value dropped while borrowed
   --> $DIR/static-drop-scope.rs:23:59
    |
 LL | const PROMOTION_FAIL_C: Option<&'static WithDtor> = Some(&WithDtor);
-   |                                                           ^^^^^^^^- temporary value is freed at the end of this statement
-   |                                                           |
-   |                                                           creates a temporary which is freed while still in use
-   |
-   = note: borrowed value must be valid for the static lifetime...
+   |                                                     ------^^^^^^^^-
+   |                                                     |     |       |
+   |                                                     |     |       temporary value is freed at the end of this statement
+   |                                                     |     creates a temporary which is freed while still in use
+   |                                                     using this value as a constant requires that borrow lasts for `'static`
 
 error[E0493]: destructors cannot be evaluated at compile-time
   --> $DIR/static-drop-scope.rs:27:28
index ad4d04343fefbdec550ef4fbf8a4646bf4c9ca1b..d195b4ce39ab4258eb074e95574e6a8e8ce63301 100644 (file)
@@ -10,11 +10,12 @@ error[E0597]: `x` does not live long enough
   --> $DIR/static-lifetime-bound.rs:15:7
    |
 LL |     f(&x); //~ERROR does not live long enough
-   |       ^^ borrowed value does not live long enough
+   |     --^^-
+   |     | |
+   |     | borrowed value does not live long enough
+   |     argument requires that `x` is borrowed for `'static`
 LL | }
    | - `x` dropped here while still borrowed
-   |
-   = note: borrowed value must be valid for the static lifetime...
 
 error: aborting due to previous error
 
index a9ecc14403ab92006d14aef3db395ec2ac590ea3..eec1a4d9f12433f0b6ea30679c8653e84df1ff7a 100644 (file)
@@ -1,68 +1,47 @@
 error[E0716]: temporary value dropped while borrowed
   --> $DIR/static-reference-to-fn-2.rs:28:22
    |
+LL | fn state1(self_: &mut StateMachineIter) -> Option<&'static str> {
+   |           ----- has type `&mut StateMachineIter<'1>`
 LL |     self_.statefn = &id(state2 as StateMachineFunc);
-   |                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- temporary value is freed at the end of this statement
-   |                      |
-   |                      creates a temporary which is freed while still in use
-   |
-note: borrowed value must be valid for the anonymous lifetime #2 defined on the function body at 27:1...
-  --> $DIR/static-reference-to-fn-2.rs:27:1
-   |
-LL | / fn state1(self_: &mut StateMachineIter) -> Option<&'static str> {
-LL | |     self_.statefn = &id(state2 as StateMachineFunc);
-LL | |     //~^ ERROR borrowed value does not live long enough
-LL | |     return Some("state1");
-LL | | }
-   | |_^
+   |     -----------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- temporary value is freed at the end of this statement
+   |     |                |
+   |     |                creates a temporary which is freed while still in use
+   |     assignment requires that borrow lasts for `'1`
 
 error[E0716]: temporary value dropped while borrowed
   --> $DIR/static-reference-to-fn-2.rs:34:22
    |
+LL | fn state2(self_: &mut StateMachineIter) -> Option<(&'static str)> {
+   |           ----- has type `&mut StateMachineIter<'1>`
 LL |     self_.statefn = &id(state3 as StateMachineFunc);
-   |                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- temporary value is freed at the end of this statement
-   |                      |
-   |                      creates a temporary which is freed while still in use
-   |
-note: borrowed value must be valid for the anonymous lifetime #2 defined on the function body at 33:1...
-  --> $DIR/static-reference-to-fn-2.rs:33:1
-   |
-LL | / fn state2(self_: &mut StateMachineIter) -> Option<(&'static str)> {
-LL | |     self_.statefn = &id(state3 as StateMachineFunc);
-LL | |     //~^ ERROR borrowed value does not live long enough
-LL | |     return Some("state2");
-LL | | }
-   | |_^
+   |     -----------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- temporary value is freed at the end of this statement
+   |     |                |
+   |     |                creates a temporary which is freed while still in use
+   |     assignment requires that borrow lasts for `'1`
 
 error[E0716]: temporary value dropped while borrowed
   --> $DIR/static-reference-to-fn-2.rs:40:22
    |
+LL | fn state3(self_: &mut StateMachineIter) -> Option<(&'static str)> {
+   |           ----- has type `&mut StateMachineIter<'1>`
 LL |     self_.statefn = &id(finished as StateMachineFunc);
-   |                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- temporary value is freed at the end of this statement
-   |                      |
-   |                      creates a temporary which is freed while still in use
-   |
-note: borrowed value must be valid for the anonymous lifetime #2 defined on the function body at 39:1...
-  --> $DIR/static-reference-to-fn-2.rs:39:1
-   |
-LL | / fn state3(self_: &mut StateMachineIter) -> Option<(&'static str)> {
-LL | |     self_.statefn = &id(finished as StateMachineFunc);
-LL | |     //~^ ERROR borrowed value does not live long enough
-LL | |     return Some("state3");
-LL | | }
-   | |_^
+   |     -----------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- temporary value is freed at the end of this statement
+   |     |                |
+   |     |                creates a temporary which is freed while still in use
+   |     assignment requires that borrow lasts for `'1`
 
-error[E0716]: temporary value dropped while borrowed
-  --> $DIR/static-reference-to-fn-2.rs:51:19
-   |
-LL |         statefn: &id(state1 as StateMachineFunc)
-   |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ creates a temporary which is freed while still in use
-...
-LL | }
-   | - temporary value is freed at the end of this statement
-   |
-   = note: borrowed value must be valid for the static lifetime...
+error[E0515]: cannot return value referencing temporary value
+  --> $DIR/static-reference-to-fn-2.rs:50:5
+   |
+LL | /     StateMachineIter {
+LL | |         statefn: &id(state1 as StateMachineFunc)
+   | |                   ------------------------------ temporary value created here
+LL | |         //~^ ERROR borrowed value does not live long enough
+LL | |     }
+   | |_____^ returns a value referencing data owned by the current function
 
 error: aborting due to 4 previous errors
 
-For more information about this error, try `rustc --explain E0716`.
+Some errors occurred: E0515, E0716.
+For more information about an error, try `rustc --explain E0515`.
index 45af062c824369e5befa108f343cb614269b5e7a..c33c1a4554782ab66fef4b2b4d976e17abd0e6cc 100644 (file)
@@ -4,10 +4,9 @@ error[E0716]: temporary value dropped while borrowed
 LL |     let x = &id(3); //~ ERROR borrowed value does not live long enough
    |              ^^^^^ creates a temporary which is freed while still in use
 LL |     f(x);
+   |     ---- argument requires that borrow lasts for `'static`
 LL | }
    | - temporary value is freed at the end of this statement
-   |
-   = note: borrowed value must be valid for the static lifetime...
 
 error: aborting due to previous error
 
index c6a7482c29f6dd2a572bcdf68462a9e3c21c1b75..a5b126f60ecdfb7f4d1064f9e04d136d106cec2b 100644 (file)
@@ -2,12 +2,13 @@ error[E0597]: `person` does not live long enough
   --> $DIR/trait-coercion-generic-regions.rs:27:24
    |
 LL |     let person: &str = &person;  //~ ERROR `person` does not live long enough
-   |                        ^^^^^^^ borrowed value does not live long enough
+   |                        ^^^^^^^
+   |                        |
+   |                        borrowed value does not live long enough
+   |                        assignment requires that `person` is borrowed for `'static`
 LL |     let s: Box<Trait<&'static str>> = Box::new(Struct { person: person });
 LL | }
    | - `person` dropped here while still borrowed
-   |
-   = note: borrowed value must be valid for the static lifetime...
 
 error: aborting due to previous error
 
index ad01f84cd2c142c06c7f8f72ccf512a04cff495e..f1cbb95b1ae42dfd2c098ae3f5621238f0fa0389 100644 (file)
@@ -29,6 +29,9 @@ LL |     factorial = Some(Box::new(f));
 error[E0597]: `factorial` does not live long enough
   --> $DIR/unboxed-closures-failed-recursive-fn-1.rs:38:17
    |
+LL |     let mut factorial: Option<Box<Fn(u32) -> u32 + 'static>> = None;
+   |                        ------------------------------------- type annotation requires that `factorial` is borrowed for `'static`
+LL | 
 LL |     let f = |x: u32| -> u32 {
    |             --------------- value captured here
 LL |         //~^ ERROR closure may outlive the current function, but it borrows `factorial`
@@ -37,12 +40,13 @@ LL |         let g = factorial.as_ref().unwrap();
 ...
 LL | }
    | - `factorial` dropped here while still borrowed
-   |
-   = note: borrowed value must be valid for the static lifetime...
 
 error[E0506]: cannot assign to `factorial` because it is borrowed
   --> $DIR/unboxed-closures-failed-recursive-fn-1.rs:42:5
    |
+LL |     let mut factorial: Option<Box<Fn(u32) -> u32 + 'static>> = None;
+   |                        ------------------------------------- type annotation requires that `factorial` is borrowed for `'static`
+LL | 
 LL |     let f = |x: u32| -> u32 {
    |             --------------- borrow of `factorial` occurs here
 LL |         //~^ ERROR closure may outlive the current function, but it borrows `factorial`
@@ -51,8 +55,6 @@ LL |         let g = factorial.as_ref().unwrap();
 ...
 LL |     factorial = Some(Box::new(f));
    |     ^^^^^^^^^ assignment to borrowed `factorial` occurs here
-   |
-   = note: borrowed value must be valid for the static lifetime...
 
 error: aborting due to 4 previous errors
 
index 7c7c0468c6fcd5d341084225bbeddbc40960e561..f938c219478b34f4dc349b64eb911d912bf6eb6d 100644 (file)
-error[E0716]: temporary value dropped while borrowed
-  --> $DIR/wf-misc-methods-issue-28609.rs:32:31
+error[E0515]: cannot return value referencing temporary value
+  --> $DIR/wf-misc-methods-issue-28609.rs:32:5
    |
 LL |     s.transmute_inherent(&mut 42) //~ ERROR does not live long enough
-   |                               ^^ creates a temporary which is freed while still in use
-LL | }
-   | - temporary value is freed at the end of this statement
-   |
-note: borrowed value must be valid for the anonymous lifetime #1 defined on the function body at 30:1...
-  --> $DIR/wf-misc-methods-issue-28609.rs:30:1
-   |
-LL | / fn return_dangling_pointer_inherent(s: S2) -> &u32 {
-LL | |     let s = s;
-LL | |     s.transmute_inherent(&mut 42) //~ ERROR does not live long enough
-LL | | }
-   | |_^
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^--^
+   |     |                         |
+   |     |                         temporary value created here
+   |     returns a value referencing data owned by the current function
 
-error[E0597]: `four` does not live long enough
-  --> $DIR/wf-misc-methods-issue-28609.rs:45:19
+error[E0515]: cannot return value referencing local variable `four`
+  --> $DIR/wf-misc-methods-issue-28609.rs:46:5
    |
 LL |     s.bomb = Some(&four); //~ ERROR does not live long enough
-   |                   ^^^^^ borrowed value does not live long enough
+   |                   ----- `four` is borrowed here
 LL |     &s
-LL | }
-   | - `four` dropped here while still borrowed
-   |
-note: borrowed value must be valid for the anonymous lifetime #1 defined on the function body at 42:1...
-  --> $DIR/wf-misc-methods-issue-28609.rs:42:1
-   |
-LL | / fn return_dangling_pointer_coerce(s: S2) -> &u32 {
-LL | |     let four = 4;
-LL | |     let mut s = s;
-LL | |     s.bomb = Some(&four); //~ ERROR does not live long enough
-LL | |     &s
-LL | | }
-   | |_^
+   |     ^^ returns a value referencing data owned by the current function
 
-error[E0597]: `four` does not live long enough
-  --> $DIR/wf-misc-methods-issue-28609.rs:52:19
+error[E0515]: cannot return value referencing local variable `four`
+  --> $DIR/wf-misc-methods-issue-28609.rs:53:5
    |
 LL |     s.bomb = Some(&four); //~ ERROR does not live long enough
-   |                   ^^^^^ borrowed value does not live long enough
+   |                   ----- `four` is borrowed here
 LL |     &*s
-LL | }
-   | - `four` dropped here while still borrowed
-   |
-note: borrowed value must be valid for the anonymous lifetime #1 defined on the function body at 49:1...
-  --> $DIR/wf-misc-methods-issue-28609.rs:49:1
-   |
-LL | / fn return_dangling_pointer_unary_op(s: S2) -> &u32 {
-LL | |     let four = 4;
-LL | |     let mut s = s;
-LL | |     s.bomb = Some(&four); //~ ERROR does not live long enough
-LL | |     &*s
-LL | | }
-   | |_^
+   |     ^^^ returns a value referencing data owned by the current function
 
-error[E0716]: temporary value dropped while borrowed
-  --> $DIR/wf-misc-methods-issue-28609.rs:63:15
+error[E0515]: cannot return value referencing temporary value
+  --> $DIR/wf-misc-methods-issue-28609.rs:63:5
    |
 LL |     s << &mut 3 //~ ERROR does not live long enough
-   |               ^ creates a temporary which is freed while still in use
-LL | }
-   | - temporary value is freed at the end of this statement
-   |
-note: borrowed value must be valid for the anonymous lifetime #1 defined on the function body at 61:1...
-  --> $DIR/wf-misc-methods-issue-28609.rs:61:1
-   |
-LL | / fn return_dangling_pointer_binary_op(s: S2) -> &u32 {
-LL | |     let s = s;
-LL | |     s << &mut 3 //~ ERROR does not live long enough
-LL | | }
-   | |_^
+   |     ^^^^^^^^^^-
+   |     |         |
+   |     |         temporary value created here
+   |     returns a value referencing data owned by the current function
 
-error[E0716]: temporary value dropped while borrowed
-  --> $DIR/wf-misc-methods-issue-28609.rs:68:16
+error[E0515]: cannot return value referencing temporary value
+  --> $DIR/wf-misc-methods-issue-28609.rs:68:5
    |
 LL |     s.shl(&mut 3) //~ ERROR does not live long enough
-   |                ^ creates a temporary which is freed while still in use
-LL | }
-   | - temporary value is freed at the end of this statement
-   |
-note: borrowed value must be valid for the anonymous lifetime #1 defined on the function body at 66:1...
-  --> $DIR/wf-misc-methods-issue-28609.rs:66:1
-   |
-LL | / fn return_dangling_pointer_method(s: S2) -> &u32 {
-LL | |     let s = s;
-LL | |     s.shl(&mut 3) //~ ERROR does not live long enough
-LL | | }
-   | |_^
+   |     ^^^^^^^^^^^-^
+   |     |          |
+   |     |          temporary value created here
+   |     returns a value referencing data owned by the current function
 
-error[E0716]: temporary value dropped while borrowed
-  --> $DIR/wf-misc-methods-issue-28609.rs:73:21
+error[E0515]: cannot return value referencing temporary value
+  --> $DIR/wf-misc-methods-issue-28609.rs:73:5
    |
 LL |     S2::shl(s, &mut 3) //~ ERROR does not live long enough
-   |                     ^ creates a temporary which is freed while still in use
-LL | }
-   | - temporary value is freed at the end of this statement
-   |
-note: borrowed value must be valid for the anonymous lifetime #1 defined on the function body at 71:1...
-  --> $DIR/wf-misc-methods-issue-28609.rs:71:1
-   |
-LL | / fn return_dangling_pointer_ufcs(s: S2) -> &u32 {
-LL | |     let s = s;
-LL | |     S2::shl(s, &mut 3) //~ ERROR does not live long enough
-LL | | }
-   | |_^
+   |     ^^^^^^^^^^^^^^^^-^
+   |     |               |
+   |     |               temporary value created here
+   |     returns a value referencing data owned by the current function
 
 error: aborting due to 6 previous errors
 
-Some errors occurred: E0597, E0716.
-For more information about an error, try `rustc --explain E0597`.
+For more information about this error, try `rustc --explain E0515`.
index 8b14b03368429e6ee2a8ac0e0c876505606ab1f1..bbb1d80703f272a5592ceeb3832a489776512251 160000 (submodule)
@@ -1 +1 @@
-Subproject commit 8b14b03368429e6ee2a8ac0e0c876505606ab1f1
+Subproject commit bbb1d80703f272a5592ceeb3832a489776512251