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.
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.
12 use syntax::codemap::Span;
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) {
20 let did = Some(trait_id);
21 let li = &tcx.lang_items;
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
30 let method = if did == li.fn_trait() {
32 } else if did == li.fn_mut_trait() {
34 } else if did == li.fn_once_trait() {
37 return // not a closure method, everything is OK.
40 span_err!(tcx.sess, span, E0174,
41 "explicit use of unboxed closure method `{}` is experimental",
43 span_help!(tcx.sess, span,
44 "add `#![feature(unboxed_closures)]` to the crate attributes to enable");