mod.rs 22.4 KB
Newer Older
1
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 3 4 5 6 7 8 9 10
// 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.

11 12
// Coherence phase
//
13 14 15 16
// The job of the coherence phase of typechecking is to ensure that
// each trait has at most one implementation for each type. This is
// done by the orphan and overlap modules. Then we build up various
// mappings. That mapping code resides here.
17

18

19
use metadata::csearch::{each_impl, get_impl_trait};
20
use metadata::csearch;
21
use middle::subst::{self, Subst};
22
use middle::ty::RegionEscape;
23
use middle::ty::{ImplContainer, ImplOrTraitItemId, MethodTraitItemId};
N
Niko Matsakis 已提交
24
use middle::ty::{ParameterEnvironment, TypeTraitItemId, lookup_item_type};
J
Jorge Aparicio 已提交
25
use middle::ty::{Ty, ty_bool, ty_char, ty_enum, ty_err};
26
use middle::ty::{ty_param, TypeScheme, ty_ptr};
27
use middle::ty::{ty_rptr, ty_struct, ty_trait, ty_tup};
28
use middle::ty::{ty_str, ty_vec, ty_float, ty_infer, ty_int};
29
use middle::ty::{ty_uint, ty_closure, ty_uniq, ty_bare_fn};
30
use middle::ty::{ty_projection};
31
use middle::ty;
N
Niko Matsakis 已提交
32
use CrateCtxt;
33 34
use middle::infer::combine::Combine;
use middle::infer::InferCtxt;
35
use middle::infer::{new_infer_ctxt};
36 37 38
use std::collections::{HashSet};
use std::cell::RefCell;
use std::rc::Rc;
39
use syntax::ast::{Crate, DefId};
40 41
use syntax::ast::{Item, ItemImpl};
use syntax::ast::{LOCAL_CRATE, TraitRef};
42
use syntax::ast;
43
use syntax::ast_map::NodeItem;
44
use syntax::ast_map;
45
use syntax::ast_util::{local_def};
46
use syntax::codemap::{Span};
47
use syntax::parse::token;
48
use syntax::visit;
49 50
use util::nodemap::{DefIdMap, FnvHashMap};
use util::ppaux::Repr;
51

52
mod impls;
53 54
mod orphan;
mod overlap;
55
mod unsafety;
56

57 58 59 60 61 62 63 64 65
// Returns the def ID of the base type, if there is one.
fn get_base_type_def_id<'a, 'tcx>(inference_context: &InferCtxt<'a, 'tcx>,
                                  span: Span,
                                  ty: Ty<'tcx>)
                                  -> Option<DefId> {
    match ty.sty {
        ty_enum(def_id, _) |
        ty_struct(def_id, _) => {
            Some(def_id)
66
        }
67

68
        ty_trait(ref t) => {
69
            Some(t.principal_def_id())
N
Nick Cameron 已提交
70
        }
71

A
Alex Crichton 已提交
72 73 74 75
        ty_uniq(_) => {
            inference_context.tcx.lang_items.owned_box()
        }

76
        ty_bool | ty_char | ty_int(..) | ty_uint(..) | ty_float(..) |
J
Jorge Aparicio 已提交
77
        ty_str(..) | ty_vec(..) | ty_bare_fn(..) | ty_tup(..) |
78
        ty_param(..) | ty_err |
79
        ty_ptr(_) | ty_rptr(_, _) | ty_projection(..) => {
B
Brian Anderson 已提交
80
            None
81 82
        }

83
        ty_infer(..) | ty_closure(..) => {
84 85 86 87
            // `ty` comes from a user declaration so we should only expect types
            // that the user can type
            inference_context.tcx.sess.span_bug(
                span,
J
Jorge Aparicio 已提交
88
                &format!("coherence encountered unexpected type searching for base type: {}",
89
                        ty.repr(inference_context.tcx)));
90 91 92
        }
    }
}
93

94 95 96
struct CoherenceChecker<'a, 'tcx: 'a> {
    crate_context: &'a CrateCtxt<'a, 'tcx>,
    inference_context: InferCtxt<'a, 'tcx>,
97
    inherent_impls: RefCell<DefIdMap<Rc<RefCell<Vec<ast::DefId>>>>>,
98 99
}

100 101
struct CoherenceCheckVisitor<'a, 'tcx: 'a> {
    cc: &'a CoherenceChecker<'a, 'tcx>
E
Eduard Burtescu 已提交
102
}
103

104
impl<'a, 'tcx, 'v> visit::Visitor<'v> for CoherenceCheckVisitor<'a, 'tcx> {
105
    fn visit_item(&mut self, item: &Item) {
E
Eduard Burtescu 已提交
106

107
        //debug!("(checking coherence) item '{}'", token::get_ident(item.ident));
E
Eduard Burtescu 已提交
108

109 110 111
        if let ItemImpl(_, _, _, ref opt_trait, _, _) = item.node {
            self.cc.check_implementation(item, opt_trait.as_ref())
        }
112

113
        visit::walk_item(self, item);
114 115 116
    }
}

117
impl<'a, 'tcx> CoherenceChecker<'a, 'tcx> {
118
    fn check(&self, krate: &Crate) {
119 120 121 122
        // Check implementations and traits. This populates the tables
        // containing the inherent methods and extension methods. It also
        // builds up the trait inheritance table.
        let mut visitor = CoherenceCheckVisitor { cc: self };
123
        visit::walk_crate(&mut visitor, krate);
124

125 126 127 128
        // Copy over the inherent impls we gathered up during the walk into
        // the tcx.
        let mut tcx_inherent_impls =
            self.crate_context.tcx.inherent_impls.borrow_mut();
129
        for (k, v) in &*self.inherent_impls.borrow() {
130 131 132
            tcx_inherent_impls.insert((*k).clone(),
                                      Rc::new((*v.borrow()).clone()));
        }
133 134 135 136 137

        // Bring in external crates. It's fine for this to happen after the
        // coherence checks, because we ensure by construction that no errors
        // can happen at link time.
        self.add_external_crates();
138 139 140 141 142

        // Populate the table of destructors. It might seem a bit strange to
        // do this here, but it's actually the most convenient place, since
        // the coherence tables contain the trait -> type mappings.
        self.populate_destructor_table();
N
Niko Matsakis 已提交
143 144 145

        // Check to make sure implementations of `Copy` are legal.
        self.check_implementations_of_copy();
146 147
    }

148
    fn check_implementation(&self, item: &Item, opt_trait: Option<&TraitRef>) {
149
        let tcx = self.crate_context.tcx;
E
Eduard Burtescu 已提交
150 151
        let impl_did = local_def(item.id);
        let self_type = ty::lookup_item_type(tcx, impl_did);
152 153 154 155

        // If there are no traits, then this implementation must have a
        // base type.

156
        let impl_items = self.create_impl_from_item(item);
157

158 159
        if opt_trait.is_some() {
            let trait_ref = ty::impl_id_to_trait_ref(self.crate_context.tcx, item.id);
160
            debug!("(checking implementation) adding impl for trait '{}', item '{}'",
161
                   trait_ref.repr(self.crate_context.tcx),
162
                   token::get_ident(item.ident));
163

164 165 166
            enforce_trait_manually_implementable(self.crate_context.tcx,
                                                 item.span,
                                                 trait_ref.def_id);
E
Eduard Burtescu 已提交
167
            self.add_trait_impl(trait_ref.def_id, impl_did);
168
        }
169 170

        // Add the implementation to the mapping from implementation to base
171 172
        // type def ID, if there is a base type for this implementation and
        // the implementation does not have any associated traits.
E
Eduard Burtescu 已提交
173
        match get_base_type_def_id(&self.inference_context,
L
Lindsey Kuper 已提交
174 175
                                   item.span,
                                   self_type.ty) {
B
Brian Anderson 已提交
176
            None => {
177 178
                // Nothing to do.
            }
B
Brian Anderson 已提交
179
            Some(base_type_def_id) => {
180
                // FIXME: Gather up default methods?
181
                if opt_trait.is_none() {
E
Eduard Burtescu 已提交
182
                    self.add_inherent_impl(base_type_def_id, impl_did);
183
                }
184 185
            }
        }
186

187
        tcx.impl_items.borrow_mut().insert(impl_did, impl_items);
188 189
    }

190 191 192
    // Creates default method IDs and performs type substitutions for an impl
    // and trait pair. Then, for each provided method in the trait, inserts a
    // `ProvidedMethodInfo` instance into the `provided_method_sources` map.
193 194 195
    fn instantiate_default_methods(
            &self,
            impl_id: DefId,
196
            trait_ref: &ty::TraitRef<'tcx>,
197
            all_impl_items: &mut Vec<ImplOrTraitItemId>) {
198
        let tcx = self.crate_context.tcx;
199
        debug!("instantiate_default_methods(impl_id={:?}, trait_ref={})",
200 201
               impl_id, trait_ref.repr(tcx));

202
        let impl_type_scheme = ty::lookup_item_type(tcx, impl_id);
203

204
        let prov = ty::provided_trait_methods(tcx, trait_ref.def_id);
205
        for trait_method in &prov {
206
            // Synthesize an ID.
207
            let new_id = tcx.sess.next_node_id();
208 209
            let new_did = local_def(new_id);

210
            debug!("new_did={:?} trait_method={}", new_did, trait_method.repr(tcx));
211 212 213

            // Create substitutions for the various trait parameters.
            let new_method_ty =
E
Eduard Burtescu 已提交
214
                Rc::new(subst_receiver_types_in_method_ty(
215 216
                    tcx,
                    impl_id,
217
                    &impl_type_scheme,
218 219
                    trait_ref,
                    new_did,
E
Eduard Burtescu 已提交
220 221
                    &**trait_method,
                    Some(trait_method.def_id)));
222

223
            debug!("new_method_ty={}", new_method_ty.repr(tcx));
224
            all_impl_items.push(MethodTraitItemId(new_did));
225

226 227 228
            // construct the polytype for the method based on the
            // method_ty.  it will have all the generics from the
            // impl, plus its own.
229
            let new_polytype = ty::TypeScheme {
230
                generics: new_method_ty.generics.clone(),
231 232
                ty: ty::mk_bare_fn(tcx, Some(new_did),
                                   tcx.mk_bare_fn(new_method_ty.fty.clone()))
233
            };
234
            debug!("new_polytype={}", new_polytype.repr(tcx));
235

236
            tcx.tcache.borrow_mut().insert(new_did, new_polytype);
237
            tcx.predicates.borrow_mut().insert(new_did, new_method_ty.predicates.clone());
238 239 240
            tcx.impl_or_trait_items
               .borrow_mut()
               .insert(new_did, ty::MethodTraitItem(new_method_ty));
241 242 243

            // Pair the new synthesized ID up with the
            // ID of the method.
244 245
            self.crate_context.tcx.provided_method_sources.borrow_mut()
                .insert(new_did, trait_method.def_id);
246 247 248
        }
    }

E
Eduard Burtescu 已提交
249
    fn add_inherent_impl(&self, base_def_id: DefId, impl_def_id: DefId) {
250
        match self.inherent_impls.borrow().get(&base_def_id) {
E
Eduard Burtescu 已提交
251
            Some(implementation_list) => {
E
Eduard Burtescu 已提交
252
                implementation_list.borrow_mut().push(impl_def_id);
E
Eduard Burtescu 已提交
253
                return;
254
            }
E
Eduard Burtescu 已提交
255
            None => {}
256
        }
257

258 259 260
        self.inherent_impls.borrow_mut().insert(
            base_def_id,
            Rc::new(RefCell::new(vec!(impl_def_id))));
261 262
    }

E
Eduard Burtescu 已提交
263
    fn add_trait_impl(&self, base_def_id: DefId, impl_def_id: DefId) {
264
        debug!("add_trait_impl: base_def_id={:?} impl_def_id={:?}",
265
               base_def_id, impl_def_id);
E
Eduard Burtescu 已提交
266 267
        ty::record_trait_implementation(self.crate_context.tcx,
                                        base_def_id,
E
Eduard Burtescu 已提交
268
                                        impl_def_id);
269 270
    }

E
Eduard Burtescu 已提交
271
    fn get_self_type_for_implementation(&self, impl_did: DefId)
272
                                        -> TypeScheme<'tcx> {
273
        self.crate_context.tcx.tcache.borrow()[impl_did].clone()
274
    }
275

276 277
    // Converts an implementation in the AST to a vector of items.
    fn create_impl_from_item(&self, item: &Item) -> Vec<ImplOrTraitItemId> {
278
        match item.node {
279
            ItemImpl(_, _, _, ref opt_trait, _, ref ast_items) => {
280 281 282 283
                let mut items: Vec<ImplOrTraitItemId> =
                        ast_items.iter()
                                 .map(|ast_item| {
                            match *ast_item {
284
                                ast::MethodImplItem(ref ast_method) => {
285 286 287
                                    MethodTraitItemId(
                                        local_def(ast_method.id))
                                }
288 289 290
                                ast::TypeImplItem(ref typedef) => {
                                    TypeTraitItemId(local_def(typedef.id))
                                }
291 292
                            }
                        }).collect();
293

294 295 296
                if opt_trait.is_some() {
                    let trait_ref = ty::impl_id_to_trait_ref(self.crate_context.tcx,
                                                             item.id);
297 298

                    self.instantiate_default_methods(local_def(item.id),
299
                                                     &*trait_ref,
300
                                                     &mut items);
301 302
                }

303
                items
304
            }
B
Brian Anderson 已提交
305
            _ => {
306
                self.crate_context.tcx.sess.span_bug(item.span,
J
Jeong YunWon 已提交
307
                                                     "can't convert a non-impl to an impl");
308 309 310
            }
        }
    }
311

312 313
    // External crate handling

E
Eduard Burtescu 已提交
314 315 316
    fn add_external_impl(&self,
                         impls_seen: &mut HashSet<DefId>,
                         impl_def_id: DefId) {
317
        let tcx = self.crate_context.tcx;
318 319
        let impl_items = csearch::get_impl_items(&tcx.sess.cstore,
                                                 impl_def_id);
320

321
        // Make sure we don't visit the same implementation multiple times.
E
Eduard Burtescu 已提交
322
        if !impls_seen.insert(impl_def_id) {
323 324 325 326
            // Skip this one.
            return
        }
        // Good. Continue.
327

E
Eduard Burtescu 已提交
328 329
        let _ = lookup_item_type(tcx, impl_def_id);
        let associated_traits = get_impl_trait(tcx, impl_def_id);
330

331 332
        // Do a sanity check.
        assert!(associated_traits.is_some());
333

334
        // Record all the trait items.
335
        if let Some(trait_ref) = associated_traits {
336
            self.add_trait_impl(trait_ref.def_id, impl_def_id);
337
        }
338

339 340
        // For any methods that use a default implementation, add them to
        // the map. This is a bit unfortunate.
341
        for item_def_id in &impl_items {
342 343 344
            let impl_item = ty::impl_or_trait_item(tcx, item_def_id.def_id());
            match impl_item {
                ty::MethodTraitItem(ref method) => {
345
                    if let Some(source) = method.provided_source {
346 347 348 349 350
                        tcx.provided_method_sources
                           .borrow_mut()
                           .insert(item_def_id.def_id(), source);
                    }
                }
351
                ty::TypeTraitItem(_) => {}
352
            }
353 354
        }

355
        tcx.impl_items.borrow_mut().insert(impl_def_id, impl_items);
356 357
    }

358 359
    // Adds implementations and traits from external crates to the coherence
    // info.
E
Eduard Burtescu 已提交
360
    fn add_external_crates(&self) {
361
        let mut impls_seen = HashSet::new();
362

E
Eduard Burtescu 已提交
363
        let crate_store = &self.crate_context.tcx.sess.cstore;
S
Steven Fackler 已提交
364
        crate_store.iter_crate_data(|crate_number, _crate_metadata| {
365
            each_impl(crate_store, crate_number, |def_id| {
366
                assert_eq!(crate_number, def_id.krate);
367
                self.add_external_impl(&mut impls_seen, def_id)
368 369
            })
        })
370
    }
371 372 373 374 375

    //
    // Destructors
    //

E
Eduard Burtescu 已提交
376
    fn populate_destructor_table(&self) {
377
        let tcx = self.crate_context.tcx;
A
Alex Crichton 已提交
378 379 380
        let drop_trait = match tcx.lang_items.drop_trait() {
            Some(id) => id, None => { return }
        };
381

382
        let impl_items = tcx.impl_items.borrow();
383
        let trait_impls = match tcx.trait_impls.borrow().get(&drop_trait).cloned() {
384
            None => return, // No types with (new-style) dtors present.
E
Eduard Burtescu 已提交
385 386
            Some(found_impls) => found_impls
        };
387

388
        for &impl_did in &*trait_impls.borrow() {
389
            let items = &(*impl_items)[impl_did];
390
            if items.len() < 1 {
391
                // We'll error out later. For now, just don't ICE.
392
                continue;
393
            }
394
            let method_def_id = items[0];
395

E
Eduard Burtescu 已提交
396
            let self_type = self.get_self_type_for_implementation(impl_did);
397
            match self_type.ty.sty {
398
                ty::ty_enum(type_def_id, _) |
399
                ty::ty_struct(type_def_id, _) |
400
                ty::ty_closure(type_def_id, _, _) => {
401 402 403 404 405 406
                    tcx.destructor_for_type
                       .borrow_mut()
                       .insert(type_def_id, method_def_id.def_id());
                    tcx.destructors
                       .borrow_mut()
                       .insert(method_def_id.def_id());
407 408 409
                }
                _ => {
                    // Destructors only work on nominal types.
E
Eduard Burtescu 已提交
410
                    if impl_did.krate == ast::LOCAL_CRATE {
P
Patrick Walton 已提交
411
                        {
E
Eduard Burtescu 已提交
412
                            match tcx.map.find(impl_did.node) {
413
                                Some(ast_map::NodeItem(item)) => {
J
Jakub Wieczorek 已提交
414 415
                                    span_err!(tcx.sess, item.span, E0120,
                                        "the Drop trait may only be implemented on structures");
P
Patrick Walton 已提交
416 417 418 419 420
                                }
                                _ => {
                                    tcx.sess.bug("didn't find impl in ast \
                                                  map");
                                }
421 422 423
                            }
                        }
                    } else {
J
Jeong YunWon 已提交
424 425
                        tcx.sess.bug("found external impl of Drop trait on \
                                      something other than a struct");
426 427 428 429 430
                    }
                }
            }
        }
    }
N
Niko Matsakis 已提交
431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454

    /// Ensures that implementations of the built-in trait `Copy` are legal.
    fn check_implementations_of_copy(&self) {
        let tcx = self.crate_context.tcx;
        let copy_trait = match tcx.lang_items.copy_trait() {
            Some(id) => id,
            None => return,
        };

        let trait_impls = match tcx.trait_impls
                                   .borrow()
                                   .get(&copy_trait)
                                   .cloned() {
            None => {
                debug!("check_implementations_of_copy(): no types with \
                        implementations of `Copy` found");
                return
            }
            Some(found_impls) => found_impls
        };

        // Clone first to avoid a double borrow error.
        let trait_impls = trait_impls.borrow().clone();

455
        for &impl_did in &trait_impls {
456 457 458
            debug!("check_implementations_of_copy: impl_did={}",
                   impl_did.repr(tcx));

N
Niko Matsakis 已提交
459 460 461 462 463 464 465
            if impl_did.krate != ast::LOCAL_CRATE {
                debug!("check_implementations_of_copy(): impl not in this \
                        crate");
                continue
            }

            let self_type = self.get_self_type_for_implementation(impl_did);
466 467 468
            debug!("check_implementations_of_copy: self_type={} (bound)",
                   self_type.repr(tcx));

N
Niko Matsakis 已提交
469
            let span = tcx.map.span(impl_did.node);
470
            let param_env = ParameterEnvironment::for_item(tcx, impl_did.node);
N
Niko Matsakis 已提交
471
            let self_type = self_type.ty.subst(tcx, &param_env.free_substs);
472
            assert!(!self_type.has_escaping_regions());
N
Niko Matsakis 已提交
473

474
            debug!("check_implementations_of_copy: self_type={} (free)",
475 476
                   self_type.repr(tcx));

477
            match ty::can_type_implement_copy(&param_env, span, self_type) {
N
Niko Matsakis 已提交
478 479
                Ok(()) => {}
                Err(ty::FieldDoesNotImplementCopy(name)) => {
B
Brian Anderson 已提交
480 481
                       span_err!(tcx.sess, span, E0204,
                                 "the trait `Copy` may not be \
N
Niko Matsakis 已提交
482 483
                                          implemented for this type; field \
                                          `{}` does not implement `Copy`",
B
Brian Anderson 已提交
484
                                         token::get_name(name))
N
Niko Matsakis 已提交
485 486
                }
                Err(ty::VariantDoesNotImplementCopy(name)) => {
B
Brian Anderson 已提交
487 488
                       span_err!(tcx.sess, span, E0205,
                                 "the trait `Copy` may not be \
N
Niko Matsakis 已提交
489 490
                                          implemented for this type; variant \
                                          `{}` does not implement `Copy`",
B
Brian Anderson 已提交
491
                                         token::get_name(name))
N
Niko Matsakis 已提交
492 493
                }
                Err(ty::TypeIsStructural) => {
B
Brian Anderson 已提交
494
                       span_err!(tcx.sess, span, E0206,
N
Niko Matsakis 已提交
495 496 497 498
                                 "the trait `Copy` may not be implemented \
                                  for this type; type is not a structure or \
                                  enumeration")
                }
499 500 501 502 503
                Err(ty::TypeHasDestructor) => {
                    span_err!(tcx.sess, span, E0184,
                              "the trait `Copy` may not be implemented for this type; \
                               the type has a destructor");
                }
N
Niko Matsakis 已提交
504 505 506
            }
        }
    }
507 508
}

509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525
fn enforce_trait_manually_implementable(tcx: &ty::ctxt, sp: Span, trait_def_id: ast::DefId) {
    if tcx.sess.features.borrow().unboxed_closures {
        // the feature gate allows all of them
        return
    }
    let did = Some(trait_def_id);
    let li = &tcx.lang_items;

    let trait_name = if did == li.fn_trait() {
        "Fn"
    } else if did == li.fn_mut_trait() {
        "FnMut"
    } else if did == li.fn_once_trait() {
        "FnOnce"
    } else {
        return // everything OK
    };
N
Nick Cameron 已提交
526
    span_err!(tcx.sess, sp, E0183, "manual implementations of `{}` are experimental", trait_name);
527 528 529 530
    span_help!(tcx.sess, sp,
               "add `#![feature(unboxed_closures)]` to the crate attributes to enable");
}

531 532
fn subst_receiver_types_in_method_ty<'tcx>(tcx: &ty::ctxt<'tcx>,
                                           impl_id: ast::DefId,
533
                                           impl_type_scheme: &ty::TypeScheme<'tcx>,
534 535 536 537 538
                                           trait_ref: &ty::TraitRef<'tcx>,
                                           new_def_id: ast::DefId,
                                           method: &ty::Method<'tcx>,
                                           provided_source: Option<ast::DefId>)
                                           -> ty::Method<'tcx>
539
{
540
    let combined_substs = ty::make_substs_for_receiver_types(tcx, trait_ref, method);
541 542 543 544

    debug!("subst_receiver_types_in_method_ty: combined_substs={}",
           combined_substs.repr(tcx));

545
    let method_predicates = method.predicates.subst(tcx, &combined_substs);
546 547 548 549
    let mut method_generics = method.generics.subst(tcx, &combined_substs);

    // replace the type parameters declared on the trait with those
    // from the impl
550
    for &space in &[subst::TypeSpace, subst::SelfSpace] {
551 552
        method_generics.types.replace(
            space,
553
            impl_type_scheme.generics.types.get_slice(space).to_vec());
554 555
        method_generics.regions.replace(
            space,
556
            impl_type_scheme.generics.regions.get_slice(space).to_vec());
557
    }
558

559 560
    debug!("subst_receiver_types_in_method_ty: method_generics={}",
           method_generics.repr(tcx));
561

562
    let method_fty = method.fty.subst(tcx, &combined_substs);
563

564 565
    debug!("subst_receiver_types_in_method_ty: method_ty={}",
           method.fty.repr(tcx));
566

567
    ty::Method::new(
568
        method.name,
569
        method_generics,
570
        method_predicates,
571
        method_fty,
572 573
        method.explicit_self,
        method.vis,
574
        new_def_id,
575
        ImplContainer(impl_id),
576
        provided_source
577
    )
578 579
}

580
pub fn check_coherence(crate_context: &CrateCtxt) {
E
Eduard Burtescu 已提交
581 582 583
    CoherenceChecker {
        crate_context: crate_context,
        inference_context: new_infer_ctxt(crate_context.tcx),
584
        inherent_impls: RefCell::new(FnvHashMap()),
585
    }.check(crate_context.tcx.map.krate());
586
    impls::check(crate_context.tcx);
587
    unsafety::check(crate_context.tcx);
588 589
    orphan::check(crate_context.tcx);
    overlap::check(crate_context.tcx);
590
}