From 540a7777b8ba53950d340ee9537ede1b3fb0b24d Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Sat, 3 Jan 2015 06:01:56 -0500 Subject: [PATCH] Don't ICE just because an impl is missing an associated type. Trust in the other compiler passes. Fixes #17359. --- src/librustc/middle/traits/project.rs | 11 +++++---- .../associated-types-issue-17359.rs | 23 +++++++++++++++++++ 2 files changed, 29 insertions(+), 5 deletions(-) create mode 100644 src/test/compile-fail/associated-types-issue-17359.rs diff --git a/src/librustc/middle/traits/project.rs b/src/librustc/middle/traits/project.rs index d5b41d238062..65f7ad296db5 100644 --- a/src/librustc/middle/traits/project.rs +++ b/src/librustc/middle/traits/project.rs @@ -643,11 +643,12 @@ fn confirm_candidate<'cx,'tcx>( match impl_ty { Some(ty) => (ty, impl_vtable.nested.to_vec()), None => { - selcx.tcx().sess.span_bug( - obligation.cause.span, - format!("impl `{}` did not contain projection for `{}`", - impl_vtable.repr(selcx.tcx()), - obligation.repr(selcx.tcx())).as_slice()); + // This means that the impl is missing a + // definition for the associated type. This error + // ought to be reported by the type checker method + // `check_impl_items_against_trait`, so here we + // just return ty_err. + (selcx.tcx().types.err, vec!()) } } } diff --git a/src/test/compile-fail/associated-types-issue-17359.rs b/src/test/compile-fail/associated-types-issue-17359.rs new file mode 100644 index 000000000000..764b79c4cc64 --- /dev/null +++ b/src/test/compile-fail/associated-types-issue-17359.rs @@ -0,0 +1,23 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Test that we do not ICE when an impl is missing an associated type (and that we report +// a useful error, of course). + +#![feature(associated_types)] + +trait Trait { + type Type; +} + +impl Trait for int {} //~ ERROR missing: `Type` + +fn main() {} +