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.
11 use check::{Inherited, FnCtxt};
12 use constrained_type_params::{identify_constrained_type_params, Parameter};
14 use hir::def_id::DefId;
15 use rustc::traits::{self, ObligationCauseCode};
16 use rustc::ty::{self, Lift, Ty, TyCtxt};
17 use rustc::ty::util::ExplicitSelf;
18 use rustc::util::nodemap::{FxHashSet, FxHashMap};
19 use rustc::middle::lang_items;
22 use syntax::feature_gate::{self, GateIssue};
24 use errors::{DiagnosticBuilder, DiagnosticId};
26 use rustc::hir::intravisit::{self, Visitor, NestedVisitorMap};
29 pub struct CheckTypeWellFormedVisitor<'a, 'tcx:'a> {
30 tcx: TyCtxt<'a, 'tcx, 'tcx>,
31 code: ObligationCauseCode<'tcx>,
34 /// Helper type of a temporary returned by .for_item(...).
35 /// Necessary because we can't write the following bound:
36 /// F: for<'b, 'tcx> where 'gcx: 'tcx FnOnce(FnCtxt<'b, 'gcx, 'tcx>).
37 struct CheckWfFcxBuilder<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
38 inherited: super::InheritedBuilder<'a, 'gcx, 'tcx>,
39 code: ObligationCauseCode<'gcx>,
42 param_env: ty::ParamEnv<'tcx>,
45 impl<'a, 'gcx, 'tcx> CheckWfFcxBuilder<'a, 'gcx, 'tcx> {
46 fn with_fcx<F>(&'tcx mut self, f: F) where
47 F: for<'b> FnOnce(&FnCtxt<'b, 'gcx, 'tcx>,
48 &mut CheckTypeWellFormedVisitor<'b, 'gcx>) -> Vec<Ty<'tcx>>
50 let code = self.code.clone();
53 let param_env = self.param_env;
54 self.inherited.enter(|inh| {
55 let fcx = FnCtxt::new(&inh, param_env, id);
56 let wf_tys = f(&fcx, &mut CheckTypeWellFormedVisitor {
57 tcx: fcx.tcx.global_tcx(),
60 fcx.select_all_obligations_or_error();
61 fcx.regionck_item(id, span, &wf_tys);
66 impl<'a, 'gcx> CheckTypeWellFormedVisitor<'a, 'gcx> {
67 pub fn new(tcx: TyCtxt<'a, 'gcx, 'gcx>)
68 -> CheckTypeWellFormedVisitor<'a, 'gcx> {
69 CheckTypeWellFormedVisitor {
71 code: ObligationCauseCode::MiscObligation
75 /// Checks that the field types (in a struct def'n) or argument types (in an enum def'n) are
76 /// well-formed, meaning that they do not require any constraints not declared in the struct
77 /// definition itself. For example, this definition would be illegal:
79 /// struct Ref<'a, T> { x: &'a T }
81 /// because the type did not declare that `T:'a`.
83 /// We do this check as a pre-pass before checking fn bodies because if these constraints are
84 /// not included it frequently leads to confusing errors in fn bodies. So it's better to check
86 fn check_item_well_formed(&mut self, item: &hir::Item) {
88 debug!("check_item_well_formed(it.id={}, it.name={})",
90 tcx.item_path_str(tcx.hir.local_def_id(item.id)));
93 // Right now we check that every default trait implementation
94 // has an implementation of itself. Basically, a case like:
96 // `impl Trait for T {}`
98 // has a requirement of `T: Trait` which was required for default
99 // method implementations. Although this could be improved now that
100 // there's a better infrastructure in place for this, it's being left
101 // for a follow-up work.
103 // Since there's such a requirement, we need to check *just* positive
104 // implementations, otherwise things like:
106 // impl !Send for T {}
108 // won't be allowed unless there's an *explicit* implementation of `Send`
110 hir::ItemImpl(_, polarity, defaultness, _, ref trait_ref, ref self_ty, _) => {
111 let is_auto = tcx.impl_trait_ref(tcx.hir.local_def_id(item.id))
112 .map_or(false, |trait_ref| tcx.trait_is_auto(trait_ref.def_id));
113 if let (hir::Defaultness::Default { .. }, true) = (defaultness, is_auto) {
114 tcx.sess.span_err(item.span, "impls of auto traits cannot be default");
116 if polarity == hir::ImplPolarity::Positive {
117 self.check_impl(item, self_ty, trait_ref);
119 // FIXME(#27579) what amount of WF checking do we need for neg impls?
120 if trait_ref.is_some() && !is_auto {
121 span_err!(tcx.sess, item.span, E0192,
122 "negative impls are only allowed for \
123 auto traits (e.g., `Send` and `Sync`)")
128 self.check_item_fn(item);
130 hir::ItemStatic(..) => {
131 self.check_item_type(item);
133 hir::ItemConst(..) => {
134 self.check_item_type(item);
136 hir::ItemStruct(ref struct_def, ref ast_generics) => {
137 self.check_type_defn(item, false, |fcx| {
138 vec![fcx.non_enum_variant(struct_def)]
141 self.check_variances_for_type_defn(item, ast_generics);
143 hir::ItemUnion(ref struct_def, ref ast_generics) => {
144 self.check_type_defn(item, true, |fcx| {
145 vec![fcx.non_enum_variant(struct_def)]
148 self.check_variances_for_type_defn(item, ast_generics);
150 hir::ItemEnum(ref enum_def, ref ast_generics) => {
151 self.check_type_defn(item, true, |fcx| {
152 fcx.enum_variants(enum_def)
155 self.check_variances_for_type_defn(item, ast_generics);
157 hir::ItemTrait(..) => {
158 self.check_trait(item);
164 fn check_associated_item(&mut self,
165 item_id: ast::NodeId,
167 sig_if_method: Option<&hir::MethodSig>) {
168 let code = self.code.clone();
169 self.for_id(item_id, span).with_fcx(|fcx, this| {
170 let item = fcx.tcx.associated_item(fcx.tcx.hir.local_def_id(item_id));
172 let (mut implied_bounds, self_ty) = match item.container {
173 ty::TraitContainer(_) => (vec![], fcx.tcx.mk_self_type()),
174 ty::ImplContainer(def_id) => (fcx.impl_implied_bounds(def_id, span),
175 fcx.tcx.type_of(def_id))
179 ty::AssociatedKind::Const => {
180 let ty = fcx.tcx.type_of(item.def_id);
181 let ty = fcx.normalize_associated_types_in(span, &ty);
182 fcx.register_wf_obligation(ty, span, code.clone());
184 ty::AssociatedKind::Method => {
185 reject_shadowing_type_parameters(fcx.tcx, item.def_id);
186 let sig = fcx.tcx.fn_sig(item.def_id);
187 let sig = fcx.normalize_associated_types_in(span, &sig);
188 this.check_fn_or_method(fcx, span, sig,
189 item.def_id, &mut implied_bounds);
190 let sig_if_method = sig_if_method.expect("bad signature for method");
191 this.check_method_receiver(fcx, sig_if_method, &item, self_ty);
193 ty::AssociatedKind::Type => {
194 if item.defaultness.has_value() {
195 let ty = fcx.tcx.type_of(item.def_id);
196 let ty = fcx.normalize_associated_types_in(span, &ty);
197 fcx.register_wf_obligation(ty, span, code.clone());
206 fn for_item<'tcx>(&self, item: &hir::Item)
207 -> CheckWfFcxBuilder<'a, 'gcx, 'tcx> {
208 self.for_id(item.id, item.span)
211 fn for_id<'tcx>(&self, id: ast::NodeId, span: Span)
212 -> CheckWfFcxBuilder<'a, 'gcx, 'tcx> {
213 let def_id = self.tcx.hir.local_def_id(id);
215 inherited: Inherited::build(self.tcx, def_id),
216 code: self.code.clone(),
219 param_env: self.tcx.param_env(def_id),
223 /// In a type definition, we check that to ensure that the types of the fields are well-formed.
224 fn check_type_defn<F>(&mut self, item: &hir::Item, all_sized: bool, mut lookup_fields: F)
225 where F: for<'fcx, 'tcx> FnMut(&FnCtxt<'fcx, 'gcx, 'tcx>) -> Vec<AdtVariant<'tcx>>
227 self.for_item(item).with_fcx(|fcx, this| {
228 let variants = lookup_fields(fcx);
229 let def_id = fcx.tcx.hir.local_def_id(item.id);
230 let packed = fcx.tcx.adt_def(def_id).repr.packed();
232 for variant in &variants {
233 // For DST, or when drop needs to copy things around, all
234 // intermediate types must be sized.
235 let needs_drop_copy = || {
237 let ty = variant.fields.last().unwrap().ty;
238 let ty = fcx.tcx.erase_regions(&ty).lift_to_tcx(this.tcx)
240 span_bug!(item.span, "inference variables in {:?}", ty)
242 ty.needs_drop(this.tcx, this.tcx.param_env(def_id))
247 variant.fields.is_empty() ||
254 for field in &variant.fields[..variant.fields.len() - unsized_len] {
257 fcx.tcx.require_lang_item(lang_items::SizedTraitLangItem),
258 traits::ObligationCause::new(field.span,
260 traits::FieldSized(match item.node.adt_kind() {
266 // All field types must be well-formed.
267 for field in &variant.fields {
268 fcx.register_wf_obligation(field.ty, field.span, this.code.clone())
272 self.check_where_clauses(fcx, item.span, def_id);
274 vec![] // no implied bounds in a struct def'n
278 fn check_trait(&mut self, item: &hir::Item) {
279 let trait_def_id = self.tcx.hir.local_def_id(item.id);
280 self.for_item(item).with_fcx(|fcx, _| {
281 self.check_where_clauses(fcx, item.span, trait_def_id);
286 fn check_item_fn(&mut self, item: &hir::Item) {
287 self.for_item(item).with_fcx(|fcx, this| {
288 let def_id = fcx.tcx.hir.local_def_id(item.id);
289 let sig = fcx.tcx.fn_sig(def_id);
290 let sig = fcx.normalize_associated_types_in(item.span, &sig);
291 let mut implied_bounds = vec![];
292 this.check_fn_or_method(fcx, item.span, sig,
293 def_id, &mut implied_bounds);
298 fn check_item_type(&mut self,
301 debug!("check_item_type: {:?}", item);
303 self.for_item(item).with_fcx(|fcx, this| {
304 let ty = fcx.tcx.type_of(fcx.tcx.hir.local_def_id(item.id));
305 let item_ty = fcx.normalize_associated_types_in(item.span, &ty);
307 fcx.register_wf_obligation(item_ty, item.span, this.code.clone());
309 vec![] // no implied bounds in a const etc
313 fn check_impl(&mut self,
315 ast_self_ty: &hir::Ty,
316 ast_trait_ref: &Option<hir::TraitRef>)
318 debug!("check_impl: {:?}", item);
320 self.for_item(item).with_fcx(|fcx, this| {
321 let item_def_id = fcx.tcx.hir.local_def_id(item.id);
323 match *ast_trait_ref {
324 Some(ref ast_trait_ref) => {
325 let trait_ref = fcx.tcx.impl_trait_ref(item_def_id).unwrap();
327 fcx.normalize_associated_types_in(
328 ast_trait_ref.path.span, &trait_ref);
330 ty::wf::trait_obligations(fcx,
334 ast_trait_ref.path.span);
335 for obligation in obligations {
336 fcx.register_predicate(obligation);
340 let self_ty = fcx.tcx.type_of(item_def_id);
341 let self_ty = fcx.normalize_associated_types_in(item.span, &self_ty);
342 fcx.register_wf_obligation(self_ty, ast_self_ty.span, this.code.clone());
346 this.check_where_clauses(fcx, item.span, item_def_id);
348 fcx.impl_implied_bounds(item_def_id, item.span)
352 /// Checks where clauses and inline bounds that are declared on def_id.
353 fn check_where_clauses<'fcx, 'tcx>(&mut self,
354 fcx: &FnCtxt<'fcx, 'gcx, 'tcx>,
357 use ty::subst::Subst;
358 use rustc::ty::TypeFoldable;
360 let mut predicates = fcx.tcx.predicates_of(def_id);
361 let mut substituted_predicates = Vec::new();
363 let generics = self.tcx.generics_of(def_id);
364 let is_our_default = |def: &ty::TypeParameterDef|
365 def.has_default && def.index >= generics.parent_count() as u32;
367 // Check that concrete defaults are well-formed. See test `type-check-defaults.rs`.
368 // For example this forbids the declaration:
369 // struct Foo<T = Vec<[u32]>> { .. }
370 // Here the default `Vec<[u32]>` is not WF because `[u32]: Sized` does not hold.
371 for d in generics.types.iter().cloned().filter(is_our_default).map(|p| p.def_id) {
372 let ty = fcx.tcx.type_of(d);
373 // ignore dependent defaults -- that is, where the default of one type
374 // parameter includes another (e.g., <T, U = T>). In those cases, we can't
375 // be sure if it will error or not as user might always specify the other.
376 if !ty.needs_subst() {
377 fcx.register_wf_obligation(ty, fcx.tcx.def_span(d), self.code.clone());
381 // Check that trait predicates are WF when params are substituted by their defaults.
382 // We don't want to overly constrain the predicates that may be written but we want to
383 // catch cases where a default my never be applied such as `struct Foo<T: Copy = String>`.
384 // Therefore we check if a predicate which contains a single type param
385 // with a concrete default is WF with that default substituted.
386 // For more examples see tests `defaults-well-formedness.rs` and `type-check-defaults.rs`.
388 // First we build the defaulted substitution.
389 let substs = ty::subst::Substs::for_item(fcx.tcx, def_id, |def, _| {
390 // All regions are identity.
391 fcx.tcx.mk_region(ty::ReEarlyBound(def.to_early_bound_region_data()))
393 // If the param has a default,
394 if is_our_default(def) {
395 let default_ty = fcx.tcx.type_of(def.def_id);
396 // and it's not a dependent default
397 if !default_ty.needs_subst() {
398 // then substitute with the default.
402 // Mark unwanted params as err.
405 // Now we build the substituted predicates.
406 for &pred in predicates.predicates.iter() {
407 struct CountParams { params: FxHashSet<u32> }
408 impl<'tcx> ty::fold::TypeVisitor<'tcx> for CountParams {
409 fn visit_ty(&mut self, t: Ty<'tcx>) -> bool {
412 self.params.insert(p.idx);
413 t.super_visit_with(self)
415 _ => t.super_visit_with(self)
419 let mut param_count = CountParams { params: FxHashSet() };
420 pred.visit_with(&mut param_count);
421 let substituted_pred = pred.subst(fcx.tcx, substs);
422 // Don't check non-defaulted params, dependent defaults or preds with multiple params.
423 if substituted_pred.references_error() || param_count.params.len() > 1 {
426 // Avoid duplication of predicates that contain no parameters, for example.
427 if !predicates.predicates.contains(&substituted_pred) {
428 substituted_predicates.push(substituted_pred);
432 predicates.predicates.extend(substituted_predicates);
433 let predicates = predicates.instantiate_identity(fcx.tcx);
434 let predicates = fcx.normalize_associated_types_in(span, &predicates);
437 predicates.predicates
439 .flat_map(|p| ty::wf::predicate_obligations(fcx,
445 for obligation in obligations {
446 fcx.register_predicate(obligation);
450 fn check_fn_or_method<'fcx, 'tcx>(&mut self,
451 fcx: &FnCtxt<'fcx, 'gcx, 'tcx>,
453 sig: ty::PolyFnSig<'tcx>,
455 implied_bounds: &mut Vec<Ty<'tcx>>)
457 let sig = fcx.normalize_associated_types_in(span, &sig);
458 let sig = fcx.tcx.liberate_late_bound_regions(def_id, &sig);
460 for input_ty in sig.inputs() {
461 fcx.register_wf_obligation(&input_ty, span, self.code.clone());
463 implied_bounds.extend(sig.inputs());
465 fcx.register_wf_obligation(sig.output(), span, self.code.clone());
467 // FIXME(#25759) return types should not be implied bounds
468 implied_bounds.push(sig.output());
470 self.check_where_clauses(fcx, span, def_id);
473 fn check_method_receiver<'fcx, 'tcx>(&mut self,
474 fcx: &FnCtxt<'fcx, 'gcx, 'tcx>,
475 method_sig: &hir::MethodSig,
476 method: &ty::AssociatedItem,
479 // check that the method has a valid receiver type, given the type `Self`
480 debug!("check_method_receiver({:?}, self_ty={:?})",
483 if !method.method_has_self_argument {
487 let span = method_sig.decl.inputs[0].span;
489 let sig = fcx.tcx.fn_sig(method.def_id);
490 let sig = fcx.normalize_associated_types_in(span, &sig);
491 let sig = fcx.tcx.liberate_late_bound_regions(method.def_id, &sig);
493 debug!("check_method_receiver: sig={:?}", sig);
495 let self_ty = fcx.normalize_associated_types_in(span, &self_ty);
496 let self_ty = fcx.tcx.liberate_late_bound_regions(
501 let self_arg_ty = sig.inputs()[0];
503 let cause = fcx.cause(span, ObligationCauseCode::MethodReceiver);
504 let self_arg_ty = fcx.normalize_associated_types_in(span, &self_arg_ty);
505 let self_arg_ty = fcx.tcx.liberate_late_bound_regions(
507 &ty::Binder(self_arg_ty)
510 let mut autoderef = fcx.autoderef(span, self_arg_ty).include_raw_pointers();
513 if let Some((potential_self_ty, _)) = autoderef.next() {
514 debug!("check_method_receiver: potential self type `{:?}` to match `{:?}`",
515 potential_self_ty, self_ty);
517 if fcx.infcx.can_eq(fcx.param_env, self_ty, potential_self_ty).is_ok() {
518 autoderef.finalize();
519 if let Some(mut err) = fcx.demand_eqtype_with_origin(
520 &cause, self_ty, potential_self_ty) {
526 fcx.tcx.sess.diagnostic().mut_span_err(
527 span, &format!("invalid `self` type: {:?}", self_arg_ty))
528 .note(&format!("type must be `{:?}` or a type that dereferences to it`", self_ty))
529 .help("consider changing to `self`, `&self`, `&mut self`, or `self: Box<Self>`")
530 .code(DiagnosticId::Error("E0307".into()))
536 let is_self_ty = |ty| fcx.infcx.can_eq(fcx.param_env, self_ty, ty).is_ok();
537 let self_kind = ExplicitSelf::determine(self_arg_ty, is_self_ty);
539 if !fcx.tcx.sess.features.borrow().arbitrary_self_types {
541 ExplicitSelf::ByValue |
542 ExplicitSelf::ByReference(_, _) |
543 ExplicitSelf::ByBox => (),
545 ExplicitSelf::ByRawPointer(_) => {
546 feature_gate::feature_err(
547 &fcx.tcx.sess.parse_sess,
548 "arbitrary_self_types",
551 "raw pointer `self` is unstable")
552 .help("consider changing to `self`, `&self`, `&mut self`, or `self: Box<Self>`")
556 ExplicitSelf::Other => {
557 feature_gate::feature_err(
558 &fcx.tcx.sess.parse_sess,
559 "arbitrary_self_types",
561 GateIssue::Language,"arbitrary `self` types are unstable")
562 .help("consider changing to `self`, `&self`, `&mut self`, or `self: Box<Self>`")
569 fn check_variances_for_type_defn(&self,
571 ast_generics: &hir::Generics)
573 let item_def_id = self.tcx.hir.local_def_id(item.id);
574 let ty = self.tcx.type_of(item_def_id);
575 if self.tcx.has_error_field(ty) {
579 let ty_predicates = self.tcx.predicates_of(item_def_id);
580 assert_eq!(ty_predicates.parent, None);
581 let variances = self.tcx.variances_of(item_def_id);
583 let mut constrained_parameters: FxHashSet<_> =
584 variances.iter().enumerate()
585 .filter(|&(_, &variance)| variance != ty::Bivariant)
586 .map(|(index, _)| Parameter(index as u32))
589 identify_constrained_type_params(self.tcx,
590 ty_predicates.predicates.as_slice(),
592 &mut constrained_parameters);
594 for (index, _) in variances.iter().enumerate() {
595 if constrained_parameters.contains(&Parameter(index as u32)) {
599 let (span, name) = match ast_generics.params[index] {
600 hir::GenericParam::Lifetime(ref ld) => (ld.lifetime.span, ld.lifetime.name.name()),
601 hir::GenericParam::Type(ref tp) => (tp.span, tp.name),
603 self.report_bivariance(span, name);
607 fn report_bivariance(&self,
609 param_name: ast::Name)
611 let mut err = error_392(self.tcx, span, param_name);
613 let suggested_marker_id = self.tcx.lang_items().phantom_data();
614 match suggested_marker_id {
617 &format!("consider removing `{}` or using a marker such as `{}`",
619 self.tcx.item_path_str(def_id)));
622 // no lang items, no help!
629 fn reject_shadowing_type_parameters(tcx: TyCtxt, def_id: DefId) {
630 let generics = tcx.generics_of(def_id);
631 let parent = tcx.generics_of(generics.parent.unwrap());
632 let impl_params: FxHashMap<_, _> = parent.types
634 .map(|tp| (tp.name, tp.def_id))
637 for method_param in &generics.types {
638 if impl_params.contains_key(&method_param.name) {
639 // Tighten up the span to focus on only the shadowing type
640 let type_span = tcx.def_span(method_param.def_id);
642 // The expectation here is that the original trait declaration is
643 // local so it should be okay to just unwrap everything.
644 let trait_def_id = impl_params[&method_param.name];
645 let trait_decl_span = tcx.def_span(trait_def_id);
646 error_194(tcx, type_span, trait_decl_span, method_param.name);
651 impl<'a, 'tcx, 'v> Visitor<'v> for CheckTypeWellFormedVisitor<'a, 'tcx> {
652 fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'v> {
653 NestedVisitorMap::None
656 fn visit_item(&mut self, i: &hir::Item) {
657 debug!("visit_item: {:?}", i);
658 self.check_item_well_formed(i);
659 intravisit::walk_item(self, i);
662 fn visit_trait_item(&mut self, trait_item: &'v hir::TraitItem) {
663 debug!("visit_trait_item: {:?}", trait_item);
664 let method_sig = match trait_item.node {
665 hir::TraitItemKind::Method(ref sig, _) => Some(sig),
668 self.check_associated_item(trait_item.id, trait_item.span, method_sig);
669 intravisit::walk_trait_item(self, trait_item)
672 fn visit_impl_item(&mut self, impl_item: &'v hir::ImplItem) {
673 debug!("visit_impl_item: {:?}", impl_item);
674 let method_sig = match impl_item.node {
675 hir::ImplItemKind::Method(ref sig, _) => Some(sig),
678 self.check_associated_item(impl_item.id, impl_item.span, method_sig);
679 intravisit::walk_impl_item(self, impl_item)
683 ///////////////////////////////////////////////////////////////////////////
686 struct AdtVariant<'tcx> {
687 fields: Vec<AdtField<'tcx>>,
690 struct AdtField<'tcx> {
695 impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
696 fn non_enum_variant(&self, struct_def: &hir::VariantData) -> AdtVariant<'tcx> {
698 struct_def.fields().iter()
700 let field_ty = self.tcx.type_of(self.tcx.hir.local_def_id(field.id));
701 let field_ty = self.normalize_associated_types_in(field.span,
703 AdtField { ty: field_ty, span: field.span }
706 AdtVariant { fields: fields }
709 fn enum_variants(&self, enum_def: &hir::EnumDef) -> Vec<AdtVariant<'tcx>> {
710 enum_def.variants.iter()
711 .map(|variant| self.non_enum_variant(&variant.node.data))
715 fn impl_implied_bounds(&self, impl_def_id: DefId, span: Span) -> Vec<Ty<'tcx>> {
716 match self.tcx.impl_trait_ref(impl_def_id) {
717 Some(ref trait_ref) => {
718 // Trait impl: take implied bounds from all types that
719 // appear in the trait reference.
720 let trait_ref = self.normalize_associated_types_in(span, trait_ref);
721 trait_ref.substs.types().collect()
725 // Inherent impl: take implied bounds from the self type.
726 let self_ty = self.tcx.type_of(impl_def_id);
727 let self_ty = self.normalize_associated_types_in(span, &self_ty);
734 fn error_392<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, span: Span, param_name: ast::Name)
735 -> DiagnosticBuilder<'tcx> {
736 let mut err = struct_span_err!(tcx.sess, span, E0392,
737 "parameter `{}` is never used", param_name);
738 err.span_label(span, "unused type parameter");
742 fn error_194(tcx: TyCtxt, span: Span, trait_decl_span: Span, name: ast::Name) {
743 struct_span_err!(tcx.sess, span, E0194,
744 "type parameter `{}` shadows another type parameter of the same name",
746 .span_label(span, "shadows another type parameter")
747 .span_label(trait_decl_span, format!("first `{}` declared here", name))