]> git.lizzy.rs Git - rust.git/blob - src/librustc_typeck/check/wfcheck.rs
Auto merge of #28795 - marti1125:28696, r=alexcrichton
[rust.git] / src / librustc_typeck / check / wfcheck.rs
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 astconv::AstConv;
12 use check::{FnCtxt, Inherited, blank_fn_ctxt, regionck};
13 use constrained_type_params::{identify_constrained_type_params, Parameter};
14 use CrateCtxt;
15 use middle::def_id::DefId;
16 use middle::subst::{self, TypeSpace, FnSpace, ParamSpace, SelfSpace};
17 use middle::traits;
18 use middle::ty::{self, Ty};
19 use middle::ty::fold::{TypeFolder};
20
21 use std::cell::RefCell;
22 use std::collections::HashSet;
23 use std::rc::Rc;
24 use syntax::ast;
25 use syntax::codemap::{Span};
26 use syntax::parse::token::{special_idents};
27 use syntax::ptr::P;
28 use rustc_front::visit;
29 use rustc_front::visit::Visitor;
30 use rustc_front::hir;
31
32 pub struct CheckTypeWellFormedVisitor<'ccx, 'tcx:'ccx> {
33     ccx: &'ccx CrateCtxt<'ccx, 'tcx>,
34     code: traits::ObligationCauseCode<'tcx>,
35 }
36
37 impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> {
38     pub fn new(ccx: &'ccx CrateCtxt<'ccx, 'tcx>)
39                -> CheckTypeWellFormedVisitor<'ccx, 'tcx> {
40         CheckTypeWellFormedVisitor {
41             ccx: ccx,
42             code: traits::ObligationCauseCode::RFC1214(
43                 Rc::new(traits::ObligationCauseCode::MiscObligation))
44         }
45     }
46
47     fn tcx(&self) -> &ty::ctxt<'tcx> {
48         self.ccx.tcx
49     }
50
51     /// Checks that the field types (in a struct def'n) or argument types (in an enum def'n) are
52     /// well-formed, meaning that they do not require any constraints not declared in the struct
53     /// definition itself. For example, this definition would be illegal:
54     ///
55     ///     struct Ref<'a, T> { x: &'a T }
56     ///
57     /// because the type did not declare that `T:'a`.
58     ///
59     /// We do this check as a pre-pass before checking fn bodies because if these constraints are
60     /// not included it frequently leads to confusing errors in fn bodies. So it's better to check
61     /// the types first.
62     fn check_item_well_formed(&mut self, item: &hir::Item) {
63         let ccx = self.ccx;
64         debug!("check_item_well_formed(it.id={}, it.name={})",
65                item.id,
66                ccx.tcx.item_path_str(ccx.tcx.map.local_def_id(item.id)));
67
68         match item.node {
69             /// Right now we check that every default trait implementation
70             /// has an implementation of itself. Basically, a case like:
71             ///
72             /// `impl Trait for T {}`
73             ///
74             /// has a requirement of `T: Trait` which was required for default
75             /// method implementations. Although this could be improved now that
76             /// there's a better infrastructure in place for this, it's being left
77             /// for a follow-up work.
78             ///
79             /// Since there's such a requirement, we need to check *just* positive
80             /// implementations, otherwise things like:
81             ///
82             /// impl !Send for T {}
83             ///
84             /// won't be allowed unless there's an *explicit* implementation of `Send`
85             /// for `T`
86             hir::ItemImpl(_, hir::ImplPolarity::Positive, _,
87                           ref trait_ref, ref self_ty, _) => {
88                 self.check_impl(item, self_ty, trait_ref);
89             }
90             hir::ItemImpl(_, hir::ImplPolarity::Negative, _, Some(_), _, _) => {
91                 // FIXME(#27579) what amount of WF checking do we need for neg impls?
92
93                 let trait_ref = ccx.tcx.impl_trait_ref(ccx.tcx.map.local_def_id(item.id)).unwrap();
94                 ccx.tcx.populate_implementations_for_trait_if_necessary(trait_ref.def_id);
95                 match ccx.tcx.lang_items.to_builtin_kind(trait_ref.def_id) {
96                     Some(ty::BoundSend) | Some(ty::BoundSync) => {}
97                     Some(_) | None => {
98                         if !ccx.tcx.trait_has_default_impl(trait_ref.def_id) {
99                             error_192(ccx, item.span);
100                         }
101                     }
102                 }
103             }
104             hir::ItemFn(_, _, _, _, _, ref body) => {
105                 self.check_item_fn(item, body);
106             }
107             hir::ItemStatic(..) => {
108                 self.check_item_type(item);
109             }
110             hir::ItemConst(..) => {
111                 self.check_item_type(item);
112             }
113             hir::ItemStruct(ref struct_def, ref ast_generics) => {
114                 self.check_type_defn(item, |fcx| {
115                     vec![struct_variant(fcx, &**struct_def)]
116                 });
117
118                 self.check_variances_for_type_defn(item, ast_generics);
119             }
120             hir::ItemEnum(ref enum_def, ref ast_generics) => {
121                 self.check_type_defn(item, |fcx| {
122                     enum_variants(fcx, enum_def)
123                 });
124
125                 self.check_variances_for_type_defn(item, ast_generics);
126             }
127             hir::ItemTrait(_, _, _, ref items) => {
128                 self.check_trait(item, items);
129             }
130             _ => {}
131         }
132     }
133
134     fn check_trait_or_impl_item(&mut self, item_id: ast::NodeId, span: Span) {
135         let code = self.code.clone();
136         self.with_fcx(item_id, span, |fcx, this| {
137             let free_substs = &fcx.inh.infcx.parameter_environment.free_substs;
138             let free_id = fcx.inh.infcx.parameter_environment.free_id;
139
140             let item = fcx.tcx().impl_or_trait_item(fcx.tcx().map.local_def_id(item_id));
141
142             let mut implied_bounds = match item.container() {
143                 ty::TraitContainer(_) => vec![],
144                 ty::ImplContainer(def_id) => impl_implied_bounds(fcx, def_id, span)
145             };
146
147             match item {
148                 ty::ConstTraitItem(assoc_const) => {
149                     let ty = fcx.instantiate_type_scheme(span, free_substs, &assoc_const.ty);
150                     fcx.register_wf_obligation(ty, span, code.clone());
151                 }
152                 ty::MethodTraitItem(method) => {
153                     reject_shadowing_type_parameters(fcx.tcx(), span, &method.generics);
154                     let method_ty = fcx.instantiate_type_scheme(span, free_substs, &method.fty);
155                     let predicates = fcx.instantiate_bounds(span, free_substs, &method.predicates);
156                     this.check_fn_or_method(fcx, span, &method_ty, &predicates,
157                                             free_id, &mut implied_bounds);
158                 }
159                 ty::TypeTraitItem(assoc_type) => {
160                     if let Some(ref ty) = assoc_type.ty {
161                         let ty = fcx.instantiate_type_scheme(span, free_substs, ty);
162                         fcx.register_wf_obligation(ty, span, code.clone());
163                     }
164                 }
165             }
166
167             implied_bounds
168         })
169     }
170
171     fn with_item_fcx<F>(&mut self, item: &hir::Item, f: F) where
172         F: for<'fcx> FnMut(&FnCtxt<'fcx, 'tcx>,
173                            &mut CheckTypeWellFormedVisitor<'ccx,'tcx>) -> Vec<Ty<'tcx>>,
174     {
175         self.with_fcx(item.id, item.span, f)
176     }
177
178     fn with_fcx<F>(&mut self, id: ast::NodeId, span: Span, mut f: F) where
179         F: for<'fcx> FnMut(&FnCtxt<'fcx, 'tcx>,
180                            &mut CheckTypeWellFormedVisitor<'ccx,'tcx>) -> Vec<Ty<'tcx>>,
181     {
182         let ccx = self.ccx;
183         let param_env = ty::ParameterEnvironment::for_item(ccx.tcx, id);
184         let tables = RefCell::new(ty::Tables::empty());
185         let inh = Inherited::new(ccx.tcx, &tables, param_env);
186         let fcx = blank_fn_ctxt(ccx, &inh, ty::FnDiverging, id);
187         let wf_tys = f(&fcx, self);
188         fcx.select_all_obligations_or_error();
189         regionck::regionck_item(&fcx, id, span, &wf_tys);
190     }
191
192     /// In a type definition, we check that to ensure that the types of the fields are well-formed.
193     fn check_type_defn<F>(&mut self, item: &hir::Item, mut lookup_fields: F) where
194         F: for<'fcx> FnMut(&FnCtxt<'fcx, 'tcx>) -> Vec<AdtVariant<'tcx>>,
195     {
196         self.with_item_fcx(item, |fcx, this| {
197             let variants = lookup_fields(fcx);
198
199             for variant in &variants {
200                 // For DST, all intermediate types must be sized.
201                 if let Some((_, fields)) = variant.fields.split_last() {
202                     for field in fields {
203                         fcx.register_builtin_bound(
204                             field.ty,
205                             ty::BoundSized,
206                             traits::ObligationCause::new(field.span,
207                                                          fcx.body_id,
208                                                          traits::FieldSized));
209                     }
210                 }
211
212                 // All field types must be well-formed.
213                 for field in &variant.fields {
214                     fcx.register_wf_obligation(field.ty, field.span, this.code.clone())
215                 }
216             }
217
218             let free_substs = &fcx.inh.infcx.parameter_environment.free_substs;
219             let predicates = fcx.tcx().lookup_predicates(fcx.tcx().map.local_def_id(item.id));
220             let predicates = fcx.instantiate_bounds(item.span, free_substs, &predicates);
221             this.check_where_clauses(fcx, item.span, &predicates);
222
223             vec![] // no implied bounds in a struct def'n
224         });
225     }
226
227     fn check_trait(&mut self,
228                    item: &hir::Item,
229                    items: &[P<hir::TraitItem>])
230     {
231         let trait_def_id = self.tcx().map.local_def_id(item.id);
232
233         if self.ccx.tcx.trait_has_default_impl(trait_def_id) {
234             if !items.is_empty() {
235                 error_380(self.ccx, item.span);
236             }
237         }
238
239         self.with_item_fcx(item, |fcx, this| {
240             let free_substs = &fcx.inh.infcx.parameter_environment.free_substs;
241             let predicates = fcx.tcx().lookup_predicates(trait_def_id);
242             let predicates = fcx.instantiate_bounds(item.span, free_substs, &predicates);
243             this.check_where_clauses(fcx, item.span, &predicates);
244             vec![]
245         });
246     }
247
248     fn check_item_fn(&mut self,
249                      item: &hir::Item,
250                      body: &hir::Block)
251     {
252         self.with_item_fcx(item, |fcx, this| {
253             let free_substs = &fcx.inh.infcx.parameter_environment.free_substs;
254             let type_scheme = fcx.tcx().lookup_item_type(fcx.tcx().map.local_def_id(item.id));
255             let item_ty = fcx.instantiate_type_scheme(item.span, free_substs, &type_scheme.ty);
256             let bare_fn_ty = match item_ty.sty {
257                 ty::TyBareFn(_, ref bare_fn_ty) => bare_fn_ty,
258                 _ => {
259                     this.tcx().sess.span_bug(item.span, "Fn item without bare fn type");
260                 }
261             };
262
263             let predicates = fcx.tcx().lookup_predicates(fcx.tcx().map.local_def_id(item.id));
264             let predicates = fcx.instantiate_bounds(item.span, free_substs, &predicates);
265
266             let mut implied_bounds = vec![];
267             this.check_fn_or_method(fcx, item.span, bare_fn_ty, &predicates,
268                                     body.id, &mut implied_bounds);
269             implied_bounds
270         })
271     }
272
273     fn check_item_type(&mut self,
274                        item: &hir::Item)
275     {
276         debug!("check_item_type: {:?}", item);
277
278         self.with_item_fcx(item, |fcx, this| {
279             let type_scheme = fcx.tcx().lookup_item_type(fcx.tcx().map.local_def_id(item.id));
280             let item_ty = fcx.instantiate_type_scheme(item.span,
281                                                       &fcx.inh
282                                                           .infcx
283                                                           .parameter_environment
284                                                           .free_substs,
285                                                       &type_scheme.ty);
286
287             fcx.register_wf_obligation(item_ty, item.span, this.code.clone());
288
289             vec![] // no implied bounds in a const etc
290         });
291     }
292
293     fn check_impl(&mut self,
294                   item: &hir::Item,
295                   ast_self_ty: &hir::Ty,
296                   ast_trait_ref: &Option<hir::TraitRef>)
297     {
298         debug!("check_impl: {:?}", item);
299
300         self.with_item_fcx(item, |fcx, this| {
301             let free_substs = &fcx.inh.infcx.parameter_environment.free_substs;
302             let item_def_id = fcx.tcx().map.local_def_id(item.id);
303
304             match *ast_trait_ref {
305                 Some(ref ast_trait_ref) => {
306                     let trait_ref = fcx.tcx().impl_trait_ref(item_def_id).unwrap();
307                     let trait_ref =
308                         fcx.instantiate_type_scheme(
309                             ast_trait_ref.path.span, free_substs, &trait_ref);
310                     let obligations =
311                         ty::wf::trait_obligations(fcx.infcx(),
312                                                   fcx.body_id,
313                                                   &trait_ref,
314                                                   ast_trait_ref.path.span,
315                                                   true);
316                     for obligation in obligations {
317                         fcx.register_predicate(obligation);
318                     }
319                 }
320                 None => {
321                     let self_ty = fcx.tcx().node_id_to_type(item.id);
322                     let self_ty = fcx.instantiate_type_scheme(item.span, free_substs, &self_ty);
323                     fcx.register_wf_obligation(self_ty, ast_self_ty.span, this.code.clone());
324                 }
325             }
326
327             let predicates = fcx.tcx().lookup_predicates(item_def_id);
328             let predicates = fcx.instantiate_bounds(item.span, free_substs, &predicates);
329             this.check_where_clauses(fcx, item.span, &predicates);
330
331             impl_implied_bounds(fcx, fcx.tcx().map.local_def_id(item.id), item.span)
332         });
333     }
334
335     fn check_where_clauses<'fcx>(&mut self,
336                                  fcx: &FnCtxt<'fcx,'tcx>,
337                                  span: Span,
338                                  predicates: &ty::InstantiatedPredicates<'tcx>)
339     {
340         let obligations =
341             predicates.predicates
342                       .iter()
343                       .flat_map(|p| ty::wf::predicate_obligations(fcx.infcx(),
344                                                                   fcx.body_id,
345                                                                   p,
346                                                                   span,
347                                                                   true));
348
349         for obligation in obligations {
350             fcx.register_predicate(obligation);
351         }
352     }
353
354     fn check_fn_or_method<'fcx>(&mut self,
355                                 fcx: &FnCtxt<'fcx,'tcx>,
356                                 span: Span,
357                                 fty: &ty::BareFnTy<'tcx>,
358                                 predicates: &ty::InstantiatedPredicates<'tcx>,
359                                 free_id: ast::NodeId,
360                                 implied_bounds: &mut Vec<Ty<'tcx>>)
361     {
362         let free_substs = &fcx.inh.infcx.parameter_environment.free_substs;
363         let fty = fcx.instantiate_type_scheme(span, free_substs, fty);
364         let free_id_outlive = fcx.tcx().region_maps.item_extent(free_id);
365         let sig = fcx.tcx().liberate_late_bound_regions(free_id_outlive, &fty.sig);
366
367         for &input_ty in &sig.inputs {
368             fcx.register_wf_obligation(input_ty, span, self.code.clone());
369         }
370         implied_bounds.extend(sig.inputs);
371
372         match sig.output {
373             ty::FnConverging(output) => {
374                 fcx.register_wf_obligation(output, span, self.code.clone());
375
376                 // FIXME(#25759) return types should not be implied bounds
377                 implied_bounds.push(output);
378             }
379             ty::FnDiverging => { }
380         }
381
382         self.check_where_clauses(fcx, span, predicates);
383     }
384
385     fn check_variances_for_type_defn(&self,
386                                      item: &hir::Item,
387                                      ast_generics: &hir::Generics)
388     {
389         let item_def_id = self.tcx().map.local_def_id(item.id);
390         let ty_predicates = self.tcx().lookup_predicates(item_def_id);
391         let variances = self.tcx().item_variances(item_def_id);
392
393         let mut constrained_parameters: HashSet<_> =
394             variances.types
395                      .iter_enumerated()
396                      .filter(|&(_, _, &variance)| variance != ty::Bivariant)
397                      .map(|(space, index, _)| self.param_ty(ast_generics, space, index))
398                      .map(|p| Parameter::Type(p))
399                      .collect();
400
401         identify_constrained_type_params(self.tcx(),
402                                          ty_predicates.predicates.as_slice(),
403                                          None,
404                                          &mut constrained_parameters);
405
406         for (space, index, _) in variances.types.iter_enumerated() {
407             let param_ty = self.param_ty(ast_generics, space, index);
408             if constrained_parameters.contains(&Parameter::Type(param_ty)) {
409                 continue;
410             }
411             let span = self.ty_param_span(ast_generics, item, space, index);
412             self.report_bivariance(span, param_ty.name);
413         }
414
415         for (space, index, &variance) in variances.regions.iter_enumerated() {
416             if variance != ty::Bivariant {
417                 continue;
418             }
419
420             assert_eq!(space, TypeSpace);
421             let span = ast_generics.lifetimes[index].lifetime.span;
422             let name = ast_generics.lifetimes[index].lifetime.name;
423             self.report_bivariance(span, name);
424         }
425     }
426
427     fn param_ty(&self,
428                 ast_generics: &hir::Generics,
429                 space: ParamSpace,
430                 index: usize)
431                 -> ty::ParamTy
432     {
433         let name = match space {
434             TypeSpace => ast_generics.ty_params[index].name,
435             SelfSpace => special_idents::type_self.name,
436             FnSpace => self.tcx().sess.bug("Fn space occupied?"),
437         };
438
439         ty::ParamTy { space: space, idx: index as u32, name: name }
440     }
441
442     fn ty_param_span(&self,
443                      ast_generics: &hir::Generics,
444                      item: &hir::Item,
445                      space: ParamSpace,
446                      index: usize)
447                      -> Span
448     {
449         match space {
450             TypeSpace => ast_generics.ty_params[index].span,
451             SelfSpace => item.span,
452             FnSpace => self.tcx().sess.span_bug(item.span, "Fn space occupied?"),
453         }
454     }
455
456     fn report_bivariance(&self,
457                          span: Span,
458                          param_name: ast::Name)
459     {
460         error_392(self.tcx(), span, param_name);
461
462         let suggested_marker_id = self.tcx().lang_items.phantom_data();
463         match suggested_marker_id {
464             Some(def_id) => {
465                 self.tcx().sess.fileline_help(
466                     span,
467                     &format!("consider removing `{}` or using a marker such as `{}`",
468                              param_name,
469                              self.tcx().item_path_str(def_id)));
470             }
471             None => {
472                 // no lang items, no help!
473             }
474         }
475     }
476 }
477
478 fn reject_shadowing_type_parameters<'tcx>(tcx: &ty::ctxt<'tcx>,
479                                           span: Span,
480                                           generics: &ty::Generics<'tcx>) {
481     let impl_params = generics.types.get_slice(subst::TypeSpace).iter()
482         .map(|tp| tp.name).collect::<HashSet<_>>();
483
484     for method_param in generics.types.get_slice(subst::FnSpace) {
485         if impl_params.contains(&method_param.name) {
486             error_194(tcx, span, method_param.name);
487         }
488     }
489 }
490
491 impl<'ccx, 'tcx, 'v> Visitor<'v> for CheckTypeWellFormedVisitor<'ccx, 'tcx> {
492     fn visit_item(&mut self, i: &hir::Item) {
493         debug!("visit_item: {:?}", i);
494         self.check_item_well_formed(i);
495         visit::walk_item(self, i);
496     }
497
498     fn visit_trait_item(&mut self, trait_item: &'v hir::TraitItem) {
499         debug!("visit_trait_item: {:?}", trait_item);
500         self.check_trait_or_impl_item(trait_item.id, trait_item.span);
501         visit::walk_trait_item(self, trait_item)
502     }
503
504     fn visit_impl_item(&mut self, impl_item: &'v hir::ImplItem) {
505         debug!("visit_impl_item: {:?}", impl_item);
506         self.check_trait_or_impl_item(impl_item.id, impl_item.span);
507         visit::walk_impl_item(self, impl_item)
508     }
509 }
510
511 ///////////////////////////////////////////////////////////////////////////
512 // ADT
513
514 struct AdtVariant<'tcx> {
515     fields: Vec<AdtField<'tcx>>,
516 }
517
518 struct AdtField<'tcx> {
519     ty: Ty<'tcx>,
520     span: Span,
521 }
522
523 fn struct_variant<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
524                             struct_def: &hir::StructDef)
525                             -> AdtVariant<'tcx> {
526     let fields =
527         struct_def.fields
528         .iter()
529         .map(|field| {
530             let field_ty = fcx.tcx().node_id_to_type(field.node.id);
531             let field_ty = fcx.instantiate_type_scheme(field.span,
532                                                        &fcx.inh
533                                                            .infcx
534                                                            .parameter_environment
535                                                            .free_substs,
536                                                        &field_ty);
537             AdtField { ty: field_ty, span: field.span }
538         })
539         .collect();
540     AdtVariant { fields: fields }
541 }
542
543 fn enum_variants<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
544                            enum_def: &hir::EnumDef)
545                            -> Vec<AdtVariant<'tcx>> {
546     enum_def.variants.iter()
547         .map(|variant| {
548             match variant.node.kind {
549                 hir::TupleVariantKind(ref args) if !args.is_empty() => {
550                     let ctor_ty = fcx.tcx().node_id_to_type(variant.node.id);
551
552                     // the regions in the argument types come from the
553                     // enum def'n, and hence will all be early bound
554                     let arg_tys = fcx.tcx().no_late_bound_regions(&ctor_ty.fn_args()).unwrap();
555                     AdtVariant {
556                         fields: args.iter().enumerate().map(|(index, arg)| {
557                             let arg_ty = arg_tys[index];
558                             let arg_ty =
559                                 fcx.instantiate_type_scheme(variant.span,
560                                                             &fcx.inh
561                                                                 .infcx
562                                                                 .parameter_environment
563                                                                 .free_substs,
564                                                             &arg_ty);
565                             AdtField {
566                                 ty: arg_ty,
567                                 span: arg.ty.span
568                             }
569                         }).collect()
570                     }
571                 }
572                 hir::TupleVariantKind(_) => {
573                     AdtVariant {
574                         fields: Vec::new()
575                     }
576                 }
577                 hir::StructVariantKind(ref struct_def) => {
578                     struct_variant(fcx, &**struct_def)
579                 }
580             }
581         })
582         .collect()
583 }
584
585 fn impl_implied_bounds<'fcx,'tcx>(fcx: &FnCtxt<'fcx, 'tcx>,
586                                   impl_def_id: DefId,
587                                   span: Span)
588                                   -> Vec<Ty<'tcx>>
589 {
590     let free_substs = &fcx.inh.infcx.parameter_environment.free_substs;
591     match fcx.tcx().impl_trait_ref(impl_def_id) {
592         Some(ref trait_ref) => {
593             // Trait impl: take implied bounds from all types that
594             // appear in the trait reference.
595             let trait_ref = fcx.instantiate_type_scheme(span, free_substs, trait_ref);
596             trait_ref.substs.types.as_slice().to_vec()
597         }
598
599         None => {
600             // Inherent impl: take implied bounds from the self type.
601             let self_ty = fcx.tcx().lookup_item_type(impl_def_id).ty;
602             let self_ty = fcx.instantiate_type_scheme(span, free_substs, &self_ty);
603             vec![self_ty]
604         }
605     }
606 }
607
608 pub fn error_192<'ccx,'tcx>(ccx: &'ccx CrateCtxt<'ccx, 'tcx>, span: Span) {
609     span_err!(ccx.tcx.sess, span, E0192,
610               "negative impls are only allowed for traits with \
611                default impls (e.g., `Send` and `Sync`)")
612 }
613
614 pub fn error_380<'ccx,'tcx>(ccx: &'ccx CrateCtxt<'ccx, 'tcx>, span: Span) {
615     span_err!(ccx.tcx.sess, span, E0380,
616               "traits with default impls (`e.g. unsafe impl \
617                Trait for ..`) must have no methods or associated items")
618 }
619
620 pub fn error_392<'tcx>(tcx: &ty::ctxt<'tcx>, span: Span, param_name: ast::Name)  {
621     span_err!(tcx.sess, span, E0392,
622               "parameter `{}` is never used", param_name);
623 }
624
625 pub fn error_194<'tcx>(tcx: &ty::ctxt<'tcx>, span: Span, name: ast::Name) {
626     span_err!(tcx.sess, span, E0194,
627               "type parameter `{}` shadows another type parameter of the same name",
628               name);
629 }