diff --git a/src/librustc/ty/adjustment.rs b/src/librustc/ty/adjustment.rs index 385591e10f7..9aa700e2b44 100644 --- a/src/librustc/ty/adjustment.rs +++ b/src/librustc/ty/adjustment.rs @@ -16,13 +16,13 @@ use syntax_pos::Span; use hir; -#[derive(Copy, Clone, RustcEncodable, RustcDecodable)] +#[derive(Clone, RustcEncodable, RustcDecodable)] pub struct Adjustment<'tcx> { pub kind: Adjust<'tcx>, pub target: Ty<'tcx> } -#[derive(Copy, Clone, Debug, RustcEncodable, RustcDecodable)] +#[derive(Clone, Debug, RustcEncodable, RustcDecodable)] pub enum Adjust<'tcx> { /// Go from ! to any type. NeverToAny, diff --git a/src/librustc_passes/consts.rs b/src/librustc_passes/consts.rs index 698850f0e9e..8f087ac212e 100644 --- a/src/librustc_passes/consts.rs +++ b/src/librustc_passes/consts.rs @@ -442,15 +442,15 @@ fn check_expr<'a, 'tcx>(v: &mut CheckCrateVisitor<'a, 'tcx>, e: &hir::Expr, node fn check_adjustments<'a, 'tcx>(v: &mut CheckCrateVisitor<'a, 'tcx>, e: &hir::Expr) { use rustc::ty::adjustment::*; - match v.tables.adjustments.get(&e.id).map(|adj| adj.kind) { + match v.tables.adjustments.get(&e.id).map(|adj| &adj.kind) { None | - Some(Adjust::NeverToAny) | - Some(Adjust::ReifyFnPointer) | - Some(Adjust::UnsafeFnPointer) | - Some(Adjust::ClosureFnPointer) | - Some(Adjust::MutToConstPointer) => {} + Some(&Adjust::NeverToAny) | + Some(&Adjust::ReifyFnPointer) | + Some(&Adjust::UnsafeFnPointer) | + Some(&Adjust::ClosureFnPointer) | + Some(&Adjust::MutToConstPointer) => {} - Some(Adjust::DerefRef { autoderefs, .. }) => { + Some(&Adjust::DerefRef { autoderefs, .. }) => { if (0..autoderefs as u32) .any(|autoderef| v.tables.is_overloaded_autoderef(e.id, autoderef)) { v.promotable = false; diff --git a/src/librustc_typeck/check/coercion.rs b/src/librustc_typeck/check/coercion.rs index 883a0a9d88a..2d8126225be 100644 --- a/src/librustc_typeck/check/coercion.rs +++ b/src/librustc_typeck/check/coercion.rs @@ -800,8 +800,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { match result { Ok(ok) => { let adjustment = self.register_infer_ok_obligations(ok); + let target = adjustment.target; self.apply_adjustment(new.id, adjustment); - return Ok(adjustment.target); + return Ok(target); } Err(e) => first_error = Some(e), } @@ -812,8 +813,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { // previous expressions, other than noop reborrows (ignoring lifetimes). for expr in exprs { let expr = expr.as_coercion_site(); - let noop = match self.tables.borrow().adjustments.get(&expr.id).map(|adj| adj.kind) { - Some(Adjust::DerefRef { + let noop = match self.tables.borrow().adjustments.get(&expr.id).map(|adj| &adj.kind) { + Some(&Adjust::DerefRef { autoderefs: 1, autoref: Some(AutoBorrow::Ref(_, mutbl_adj)), unsize: false @@ -828,7 +829,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { _ => false, } } - Some(Adjust::NeverToAny) => true, + Some(&Adjust::NeverToAny) => true, Some(_) => false, None => true, }; @@ -857,7 +858,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { let adjustment = self.register_infer_ok_obligations(ok); for expr in exprs { let expr = expr.as_coercion_site(); - self.apply_adjustment(expr.id, adjustment); + self.apply_adjustment(expr.id, adjustment.clone()); } Ok(adjustment.target) } diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 3a6fd51693e..bee4a18523e 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -1805,16 +1805,16 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { Entry::Vacant(entry) => { entry.insert(adj); }, Entry::Occupied(mut entry) => { debug!(" - composing on top of {:?}", entry.get()); - let composed_kind = match (entry.get().kind, adj.kind) { + let composed_kind = match (&entry.get().kind, &adj.kind) { // Applying any adjustment on top of a NeverToAny // is a valid NeverToAny adjustment, because it can't // be reached. - (Adjust::NeverToAny, _) => Adjust::NeverToAny, - (Adjust::DerefRef { + (&Adjust::NeverToAny, _) => Adjust::NeverToAny, + (&Adjust::DerefRef { autoderefs: 1, autoref: Some(AutoBorrow::Ref(..)), unsize: false - }, Adjust::DerefRef { autoderefs, .. }) if autoderefs > 0 => { + }, &Adjust::DerefRef { autoderefs, .. }) if autoderefs > 0 => { // A reborrow has no effect before a dereference. adj.kind }