Merge pull request #408 from dtolnay/assoctype

Generate trait bounds on associated types
diff --git a/impl/src/generics.rs b/impl/src/generics.rs
index 254c2ed..26fe0a9 100644
--- a/impl/src/generics.rs
+++ b/impl/src/generics.rs
@@ -25,11 +25,12 @@
 
 fn crawl(in_scope: &ParamsInScope, ty: &Type, found: &mut bool) {
     if let Type::Path(ty) = ty {
-        if ty.qself.is_none() {
-            if let Some(ident) = ty.path.get_ident() {
-                if in_scope.names.contains(ident) {
-                    *found = true;
-                }
+        if let Some(qself) = &ty.qself {
+            crawl(in_scope, &qself.ty, found);
+        } else {
+            let front = ty.path.segments.first().unwrap();
+            if front.arguments.is_none() && in_scope.names.contains(&front.ident) {
+                *found = true;
             }
         }
         for segment in &ty.path.segments {
diff --git a/tests/test_generics.rs b/tests/test_generics.rs
index 36f1181..bcbfee0 100644
--- a/tests/test_generics.rs
+++ b/tests/test_generics.rs
@@ -1,6 +1,7 @@
 #![allow(clippy::needless_late_init, clippy::uninlined_format_args)]
 
 use core::fmt::{self, Debug, Display};
+use core::str::FromStr;
 use thiserror::Error;
 
 pub struct NoFormat;
@@ -160,6 +161,24 @@
 #[error(transparent)]
 pub struct StructTransparentGeneric<E>(pub E);
 
+// Should expand to:
+//
+//     impl<T: FromStr> Display for AssociatedTypeError<T>
+//     where
+//         T::Err: Display;
+//
+//     impl<T: FromStr> Error for AssociatedTypeError<T>
+//     where
+//         Self: Debug + Display;
+//
+#[derive(Error, Debug)]
+pub enum AssociatedTypeError<T: FromStr> {
+    #[error("couldn't parse matrix")]
+    Other,
+    #[error("couldn't parse entry: {0}")]
+    EntryParseError(T::Err),
+}
+
 // Regression test for https://github.com/dtolnay/thiserror/issues/345
 #[test]
 fn test_no_bound_on_named_fmt() {