Skip to content

Commit 6cd87bc

Browse files
authored
Merge pull request #408 from dtolnay/assoctype
Generate trait bounds on associated types
2 parents c535cec + 6b3e1e5 commit 6cd87bc

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

impl/src/generics.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@ impl<'a> ParamsInScope<'a> {
2525

2626
fn crawl(in_scope: &ParamsInScope, ty: &Type, found: &mut bool) {
2727
if let Type::Path(ty) = ty {
28-
if ty.qself.is_none() {
29-
if let Some(ident) = ty.path.get_ident() {
30-
if in_scope.names.contains(ident) {
31-
*found = true;
32-
}
28+
if let Some(qself) = &ty.qself {
29+
crawl(in_scope, &qself.ty, found);
30+
} else {
31+
let front = ty.path.segments.first().unwrap();
32+
if front.arguments.is_none() && in_scope.names.contains(&front.ident) {
33+
*found = true;
3334
}
3435
}
3536
for segment in &ty.path.segments {

tests/test_generics.rs

+19
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#![allow(clippy::needless_late_init, clippy::uninlined_format_args)]
22

33
use core::fmt::{self, Debug, Display};
4+
use core::str::FromStr;
45
use thiserror::Error;
56

67
pub struct NoFormat;
@@ -160,6 +161,24 @@ pub struct StructFromGeneric<E> {
160161
#[error(transparent)]
161162
pub struct StructTransparentGeneric<E>(pub E);
162163

164+
// Should expand to:
165+
//
166+
// impl<T: FromStr> Display for AssociatedTypeError<T>
167+
// where
168+
// T::Err: Display;
169+
//
170+
// impl<T: FromStr> Error for AssociatedTypeError<T>
171+
// where
172+
// Self: Debug + Display;
173+
//
174+
#[derive(Error, Debug)]
175+
pub enum AssociatedTypeError<T: FromStr> {
176+
#[error("couldn't parse matrix")]
177+
Other,
178+
#[error("couldn't parse entry: {0}")]
179+
EntryParseError(T::Err),
180+
}
181+
163182
// Regression test for https://github.com/dtolnay/thiserror/issues/345
164183
#[test]
165184
fn test_no_bound_on_named_fmt() {

0 commit comments

Comments
 (0)