]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_borrowck/borrowck/mod.rs
rustc: always include elidable lifetimes in HIR types.
[rust.git] / src / librustc_borrowck / borrowck / mod.rs
index 4386a5bd1591d6a8fd37be17c9526bb0d6858fc2..46179b31d5cb45bc2c212baad7a898355109e9e0 100644 (file)
@@ -939,12 +939,12 @@ pub fn report_aliasability_violation(&self,
     /// Given a type, if it is an immutable reference, return a suggestion to make it mutable
     fn suggest_mut_for_immutable(&self, pty: &hir::Ty) -> Option<String> {
         // Check wether the argument is an immutable reference
-        if let hir::TyRptr(opt_lifetime, hir::MutTy {
+        if let hir::TyRptr(lifetime, hir::MutTy {
             mutbl: hir::Mutability::MutImmutable,
             ref ty
         }) = pty.node {
             // Account for existing lifetimes when generating the message
-            if let Some(lifetime) = opt_lifetime {
+            if !lifetime.is_elided() {
                 if let Ok(snippet) = self.tcx.sess.codemap().span_to_snippet(ty.span) {
                     if let Ok(lifetime_snippet) = self.tcx.sess.codemap()
                         .span_to_snippet(lifetime.span) {
@@ -1039,7 +1039,7 @@ pub fn note_and_explain_bckerr(&self, db: &mut DiagnosticBuilder, err: BckError<
             err_mutbl => self.note_and_explain_mutbl_error(db, &err, &error_span),
             err_out_of_scope(super_scope, sub_scope, cause) => {
                 let (value_kind, value_msg) = match err.cmt.cat {
-                    mc::Categorization::Rvalue(_) =>
+                    mc::Categorization::Rvalue(..) =>
                         ("temporary value", "temporary value created here"),
                     _ =>
                         ("borrowed value", "borrow occurs here")
@@ -1133,6 +1133,17 @@ pub fn note_and_explain_bckerr(&self, db: &mut DiagnosticBuilder, err: BckError<
                 if let Some(_) = statement_scope_span(self.tcx, super_scope) {
                     db.note("consider using a `let` binding to increase its lifetime");
                 }
+
+
+
+                match err.cmt.cat {
+                    mc::Categorization::Rvalue(r, or) if r != or => {
+                        db.note("\
+before rustc 1.16, this temporary lived longer - see issue #39283 \
+(https://github.com/rust-lang/rust/issues/39283)");
+                    }
+                    _ => {}
+                }
             }
 
             err_borrowed_pointer_too_short(loan_scope, ptr_scope) => {