|
| 1 | +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT |
| 2 | +// file at the top-level directory of this distribution and at |
| 3 | +// http://rust-lang.org/COPYRIGHT. |
| 4 | +// |
| 5 | +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or |
| 6 | +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license |
| 7 | +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your |
| 8 | +// option. This file may not be copied, modified, or distributed |
| 9 | +// except according to those terms. |
| 10 | + |
| 11 | +use syntax::ast; |
| 12 | +use syntax::codemap::Span; |
| 13 | +use CrateCtxt; |
| 14 | + |
| 15 | +/// Check that it is legal to call methods of the trait corresponding |
| 16 | +/// to `trait_id` (this only cares about the trait, not the specific |
| 17 | +/// method that is called) |
| 18 | +pub fn check_legal_trait_for_method_call(ccx: &CrateCtxt, span: Span, trait_id: ast::DefId) { |
| 19 | + let tcx = ccx.tcx; |
| 20 | + let did = Some(trait_id); |
| 21 | + let li = &tcx.lang_items; |
| 22 | + |
| 23 | + if did == li.drop_trait() { |
| 24 | + span_err!(tcx.sess, span, E0040, "explicit use of destructor method"); |
| 25 | + } else if !tcx.sess.features.borrow().unboxed_closures { |
| 26 | + // the #[feature(unboxed_closures)] feature isn't |
| 27 | + // activated so we need to enforce the closure |
| 28 | + // restrictions. |
| 29 | + |
| 30 | + let method = if did == li.fn_trait() { |
| 31 | + "call" |
| 32 | + } else if did == li.fn_mut_trait() { |
| 33 | + "call_mut" |
| 34 | + } else if did == li.fn_once_trait() { |
| 35 | + "call_once" |
| 36 | + } else { |
| 37 | + return // not a closure method, everything is OK. |
| 38 | + }; |
| 39 | + |
| 40 | + span_err!(tcx.sess, span, E0174, |
| 41 | + "explicit use of unboxed closure method `{}` is experimental", |
| 42 | + method); |
| 43 | + span_help!(tcx.sess, span, |
| 44 | + "add `#![feature(unboxed_closures)]` to the crate attributes to enable"); |
| 45 | + } |
| 46 | +} |
0 commit comments