E0314, // closure outlives stack frame
E0315, // cannot invoke closure outside of its lifetime
E0316, // nested quantification of lifetimes
- E0370 // discriminant overflow
+ E0370, // discriminant overflow
+ E0400 // overloaded derefs are not allowed in constants
}
let node_ty = self.tcx.node_id_to_type(ex.id);
check_expr(self, ex, node_ty);
+ check_adjustments(self, ex);
// Special-case some expressions to avoid certain flags bubbling up.
match ex.node {
}
}
+/// Check the adjustments of an expression
+fn check_adjustments<'a, 'tcx>(v: &mut CheckCrateVisitor<'a, 'tcx>, e: &ast::Expr) {
+ match v.tcx.tables.borrow().adjustments.get(&e.id) {
+ None | Some(&ty::AdjustReifyFnPointer) | Some(&ty::AdjustUnsafeFnPointer) => {}
+ Some(&ty::AdjustDerefRef(ty::AutoDerefRef { autoderefs, .. })) => {
+ if (0..autoderefs as u32).any(|autoderef| {
+ v.tcx.is_overloaded_autoderef(e.id, autoderef)
+ }) {
+ v.add_qualif(ConstQualif::NOT_CONST);
+ if v.mode != Mode::Var {
+ span_err!(v.tcx.sess, e.span, E0400,
+ "user-defined dereference operators are not allowed in {}s",
+ v.msg());
+ }
+ }
+ }
+ }
+}
+
pub fn check_crate(tcx: &ty::ctxt) {
visit::walk_crate(&mut CheckCrateVisitor {
tcx: tcx,
--- /dev/null
+// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+struct A;
+struct B;
+
+static S: &'static B = &A; //~ ERROR user-defined dereference operators
+
+use std::ops::Deref;
+
+impl Deref for A {
+ type Target = B;
+ fn deref(&self)->&B { static B_: B = B; &B_ }
+}
+
+fn main(){}