Skip to content

Commit 14e1fd4

Browse files
committed
Add span to error for missing type params on enums.
1 parent 3b9ade0 commit 14e1fd4

File tree

3 files changed

+14
-13
lines changed

3 files changed

+14
-13
lines changed

src/librustc/middle/ty.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2416,13 +2416,13 @@ pub enum Representability {
24162416

24172417
/// Check whether a type is representable. This means it cannot contain unboxed
24182418
/// structural recursion. This check is needed for structs and enums.
2419-
pub fn is_type_representable(cx: &ctxt, ty: t) -> Representability {
2419+
pub fn is_type_representable(cx: &ctxt, sp: Span, ty: t) -> Representability {
24202420

24212421
// Iterate until something non-representable is found
2422-
fn find_nonrepresentable<It: Iterator<t>>(cx: &ctxt, seen: &mut Vec<DefId>,
2422+
fn find_nonrepresentable<It: Iterator<t>>(cx: &ctxt, sp: Span, seen: &mut Vec<DefId>,
24232423
mut iter: It) -> Representability {
24242424
for ty in iter {
2425-
let r = type_structurally_recursive(cx, seen, ty);
2425+
let r = type_structurally_recursive(cx, sp, seen, ty);
24262426
if r != Representable {
24272427
return r
24282428
}
@@ -2432,7 +2432,7 @@ pub fn is_type_representable(cx: &ctxt, ty: t) -> Representability {
24322432

24332433
// Does the type `ty` directly (without indirection through a pointer)
24342434
// contain any types on stack `seen`?
2435-
fn type_structurally_recursive(cx: &ctxt, seen: &mut Vec<DefId>,
2435+
fn type_structurally_recursive(cx: &ctxt, sp: Span, seen: &mut Vec<DefId>,
24362436
ty: t) -> Representability {
24372437
debug!("type_structurally_recursive: {}",
24382438
::util::ppaux::ty_to_str(cx, ty));
@@ -2455,19 +2455,19 @@ pub fn is_type_representable(cx: &ctxt, ty: t) -> Representability {
24552455
match get(ty).sty {
24562456
// Tuples
24572457
ty_tup(ref ts) => {
2458-
find_nonrepresentable(cx, seen, ts.iter().map(|t| *t))
2458+
find_nonrepresentable(cx, sp, seen, ts.iter().map(|t| *t))
24592459
}
24602460
// Fixed-length vectors.
24612461
// FIXME(#11924) Behavior undecided for zero-length vectors.
24622462
ty_vec(ty, VstoreFixed(_)) => {
2463-
type_structurally_recursive(cx, seen, ty)
2463+
type_structurally_recursive(cx, sp, seen, ty)
24642464
}
24652465

24662466
// Push struct and enum def-ids onto `seen` before recursing.
24672467
ty_struct(did, ref substs) => {
24682468
seen.push(did);
24692469
let fields = struct_fields(cx, did, substs);
2470-
let r = find_nonrepresentable(cx, seen,
2470+
let r = find_nonrepresentable(cx, sp, seen,
24712471
fields.iter().map(|f| f.mt.ty));
24722472
seen.pop();
24732473
r
@@ -2478,8 +2478,10 @@ pub fn is_type_representable(cx: &ctxt, ty: t) -> Representability {
24782478

24792479
let mut r = Representable;
24802480
for variant in vs.iter() {
2481-
let iter = variant.args.iter().map(|aty| subst(cx, substs, *aty));
2482-
r = find_nonrepresentable(cx, seen, iter);
2481+
let iter = variant.args.iter().map(|aty| {
2482+
aty.subst_spanned(cx, substs, Some(sp))
2483+
});
2484+
r = find_nonrepresentable(cx, sp, seen, iter);
24832485

24842486
if r != Representable { break }
24852487
}
@@ -2499,7 +2501,7 @@ pub fn is_type_representable(cx: &ctxt, ty: t) -> Representability {
24992501
// contains a different, structurally recursive type, maintain a stack
25002502
// of seen types and check recursion for each of them (issues #3008, #3779).
25012503
let mut seen: Vec<DefId> = Vec::new();
2502-
type_structurally_recursive(cx, &mut seen, ty)
2504+
type_structurally_recursive(cx, sp, &mut seen, ty)
25032505
}
25042506

25052507
pub fn type_is_trait(ty: t) -> bool {

src/librustc/middle/typeck/check/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3356,7 +3356,7 @@ pub fn check_representable(tcx: &ty::ctxt,
33563356
// recursive type. It is only necessary to throw an error on those that
33573357
// contain themselves. For case 2, there must be an inner type that will be
33583358
// caught by case 1.
3359-
match ty::is_type_representable(tcx, rty) {
3359+
match ty::is_type_representable(tcx, sp, rty) {
33603360
ty::SelfRecursive => {
33613361
tcx.sess.span_err(
33623362
sp, format!("illegal recursive {} type; \

src/test/compile-fail/issue-5997-enum.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// error-pattern: missing type param `Z` in the substitution of `Z`
12-
1311
fn f<Z>() -> bool {
1412
enum E { V(Z) }
13+
//~^ ERROR missing type param `Z` in the substitution of `Z`
1514

1615
true
1716
}

0 commit comments

Comments
 (0)