Skip to content

Commit 4ba359b

Browse files
committed
add changes for confusing type params
1 parent 15a1e28 commit 4ba359b

File tree

8 files changed

+38
-25
lines changed

8 files changed

+38
-25
lines changed

src/librustc/ich/impls_ty.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,8 @@ for ty::TypeVariants<'gcx>
661661

662662
impl_stable_hash_for!(struct ty::ParamTy {
663663
idx,
664-
name
664+
name,
665+
span
665666
});
666667

667668
impl_stable_hash_for!(struct ty::TypeAndMut<'tcx> {

src/librustc/traits/util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ impl<'cx, 'gcx, 'tcx> Elaborator<'cx, 'gcx, 'tcx> {
221221
},
222222

223223
Component::Param(p) => {
224-
let ty = tcx.mk_param(p.idx, p.name);
224+
let ty = tcx.mk_param(p.idx, p.name, p.span);
225225
Some(ty::Predicate::TypeOutlives(
226226
ty::Binder(ty::OutlivesPredicate(ty, r_min))))
227227
},

src/librustc/ty/context.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ use syntax::ast::{self, Name, NodeId};
7272
use syntax::attr;
7373
use syntax::codemap::MultiSpan;
7474
use syntax::symbol::{Symbol, keywords};
75-
use syntax_pos::Span;
75+
use syntax_pos::{Span, DUMMY_SP};
7676

7777
use hir;
7878

@@ -2095,18 +2095,20 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
20952095
self.mk_ty(TyInfer(it))
20962096
}
20972097

2098+
20982099
pub fn mk_param(self,
20992100
index: u32,
2100-
name: Name) -> Ty<'tcx> {
2101-
self.mk_ty(TyParam(ParamTy { idx: index, name: name }))
2101+
name: Name,
2102+
span: Span) -> Ty<'tcx> {
2103+
self.mk_ty(TyParam(ParamTy { idx: index, name: name, span:span }))
21022104
}
21032105

21042106
pub fn mk_self_type(self) -> Ty<'tcx> {
2105-
self.mk_param(0, keywords::SelfType.name())
2107+
self.mk_param(0, keywords::SelfType.name(), DUMMY_SP)
21062108
}
21072109

21082110
pub fn mk_param_from_def(self, def: &ty::TypeParameterDef) -> Ty<'tcx> {
2109-
self.mk_param(def.index, def.name)
2111+
self.mk_param(def.index, def.name, DUMMY_SP)
21102112
}
21112113

21122114
pub fn mk_anon(self, def_id: DefId, substs: &'tcx Substs<'tcx>) -> Ty<'tcx> {

src/librustc/ty/error.rs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ impl<'a, 'gcx, 'lcx, 'tcx> ty::TyS<'tcx> {
239239
if p.is_self() {
240240
"Self".to_string()
241241
} else {
242-
"type parameter".to_string()
242+
p.to_string()
243243
}
244244
}
245245
ty::TyAnon(..) => "anonymized type".to_string(),
@@ -256,13 +256,21 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
256256
use self::TypeError::*;
257257

258258
match err.clone() {
259-
Sorts(values) => {
260-
let expected_str = values.expected.sort_string(self);
261-
let found_str = values.found.sort_string(self);
262-
if expected_str == found_str && expected_str == "closure" {
263-
db.note("no two closures, even if identical, have the same type");
264-
db.help("consider boxing your closure and/or using it as a trait object");
265-
}
259+
Sorts(values)
260+
=> {
261+
debug!("values = {:?}", values);
262+
match values
263+
{
264+
(ty.sty:TypeVariants::Param(param), _) |
265+
(_, ty.sty:TypeVariants::Param(param)) => {
266+
let expected_str = values.expected.sort_string(self);
267+
let found_str = values.found.sort_string(self);
268+
if expected_str == found_str && expected_str == "closure" {
269+
db.note("no two closures, even if identical, have the same type");
270+
db.help("consider boxing your closure and/or using it as a trait object");
271+
}
272+
},
273+
_=> {}}
266274
},
267275
TyParamDefaultMismatch(values) => {
268276
let expected = values.expected;

src/librustc/ty/sty.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ use std::cmp::Ordering;
2525
use syntax::abi;
2626
use syntax::ast::{self, Name};
2727
use syntax::symbol::keywords;
28+
use syntax_pos::{Span, DUMMY_SP};
2829

2930
use serialize;
3031

@@ -862,23 +863,24 @@ impl<'tcx> PolyFnSig<'tcx> {
862863
pub struct ParamTy {
863864
pub idx: u32,
864865
pub name: Name,
866+
pub span: Span
865867
}
866868

867869
impl<'a, 'gcx, 'tcx> ParamTy {
868-
pub fn new(index: u32, name: Name) -> ParamTy {
869-
ParamTy { idx: index, name: name }
870+
pub fn new(index: u32, name: Name, span: Span) -> ParamTy {
871+
ParamTy { idx: index, name: name, span: span }
870872
}
871873

872874
pub fn for_self() -> ParamTy {
873-
ParamTy::new(0, keywords::SelfType.name())
875+
ParamTy::new(0, keywords::SelfType.name(), DUMMY_SP)
874876
}
875877

876878
pub fn for_def(def: &ty::TypeParameterDef) -> ParamTy {
877-
ParamTy::new(def.index, def.name)
879+
ParamTy::new(def.index, def.name, DUMMY_SP)
878880
}
879881

880882
pub fn to_ty(self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Ty<'tcx> {
881-
tcx.mk_param(self.idx, self.name)
883+
tcx.mk_param(self.idx, self.name, self.span)
882884
}
883885

884886
pub fn is_self(&self) -> bool {

src/librustc_typeck/astconv.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -980,7 +980,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
980980
let item_def_id = tcx.hir.local_def_id(item_id);
981981
let generics = tcx.generics_of(item_def_id);
982982
let index = generics.type_param_to_index[&tcx.hir.local_def_id(node_id).index];
983-
tcx.mk_param(index, tcx.hir.name(node_id))
983+
tcx.mk_param(index, tcx.hir.name(node_id), span)
984984
}
985985
Def::SelfTy(_, Some(def_id)) => {
986986
// Self in impl (we know the concrete type).

src/librustc_typeck/check/intrinsic.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ fn equate_intrinsic_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
7676
/// and in libcore/intrinsics.rs
7777
pub fn check_intrinsic_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
7878
it: &hir::ForeignItem) {
79-
let param = |n| tcx.mk_param(n, Symbol::intern(&format!("P{}", n)));
79+
let param = |n| tcx.mk_param(n, Symbol::intern(&format!("P{}", n)), it.span);
8080
let name = it.name.as_str();
8181
let (n_tps, inputs, output) = if name.starts_with("atomic_") {
8282
let split : Vec<&str> = name.split('_').collect();
@@ -341,7 +341,7 @@ pub fn check_platform_intrinsic_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
341341
it: &hir::ForeignItem) {
342342
let param = |n| {
343343
let name = Symbol::intern(&format!("P{}", n));
344-
tcx.mk_param(n, name)
344+
tcx.mk_param(n, name, it.span)
345345
};
346346

347347
let def_id = tcx.hir.local_def_id(it.id);

src/librustc_typeck/collect.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ fn type_param_predicates<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
241241
let param_owner_def_id = tcx.hir.local_def_id(param_owner);
242242
let generics = tcx.generics_of(param_owner_def_id);
243243
let index = generics.type_param_to_index[&def_id.index];
244-
let ty = tcx.mk_param(index, tcx.hir.ty_param_name(param_id));
244+
let ty = tcx.mk_param(index, tcx.hir.ty_param_name(param_id), DUMMY_SP);
245245

246246
// Don't look for bounds where the type parameter isn't in scope.
247247
let parent = if item_def_id == param_owner_def_id {
@@ -1477,7 +1477,7 @@ fn explicit_predicates_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
14771477
// Collect the predicates that were written inline by the user on each
14781478
// type parameter (e.g., `<T:Foo>`).
14791479
for param in ast_generics.ty_params() {
1480-
let param_ty = ty::ParamTy::new(index, param.name).to_ty(tcx);
1480+
let param_ty = ty::ParamTy::new(index, param.name, param.span).to_ty(tcx);
14811481
index += 1;
14821482

14831483
let bounds = compute_bounds(&icx,

0 commit comments

Comments
 (0)