Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions compiler/noirc_frontend/src/elaborator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2192,9 +2192,35 @@ impl<'context> Elaborator<'context> {

let (trait_id, mut trait_generics, path_location) = match &trait_impl.r#trait.typ {
UnresolvedTypeData::Named(trait_path, trait_generics, _) => {
let mut trait_generics = trait_generics.clone();
let location = trait_path.location;
let trait_path = self.validate_path(trait_path.clone());
let trait_id = self.resolve_trait_by_path(trait_path);

// Check and remove and any generic that is specifying an associated item
if !trait_generics.named_args.is_empty() {
if let Some(trait_id) = trait_id {
let associated_types =
self.interner.get_trait(trait_id).associated_types.clone();
trait_generics.named_args.retain(|(name, typ)| {
let associated_type = associated_types.iter().find(|associated_type| {
associated_type.name.as_str() == name.as_str()
});
if associated_type.is_some() {
let location = name.location().merge(typ.location);
self.push_err(
ResolverError::AssociatedItemConstraintsNotAllowedInGenerics {
location,
},
);
false
} else {
true
}
});
}
}

(trait_id, trait_generics.clone(), location)
}
UnresolvedTypeData::Resolved(quoted_type_id) => {
Expand Down
14 changes: 13 additions & 1 deletion compiler/noirc_frontend/src/hir/resolution/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ pub enum ResolverError {
UnconstrainedTypeParameter { ident: Ident },
#[error("Unreachable statement")]
UnreachableStatement { location: Location, break_or_continue_location: Location },
#[error("Associated item constraints are not allowed here")]
AssociatedItemConstraintsNotAllowedInGenerics { location: Location },
}

impl ResolverError {
Expand Down Expand Up @@ -237,7 +239,10 @@ impl ResolverError {
| ResolverError::FoldAttributeOnUnconstrained { location, .. }
| ResolverError::OracleMarkedAsConstrained { location, .. }
| ResolverError::LowLevelFunctionOutsideOfStdlib { location }
| ResolverError::UnreachableStatement { location, .. } => *location,
| ResolverError::UnreachableStatement { location, .. }
| ResolverError::AssociatedItemConstraintsNotAllowedInGenerics { location } => {
*location
}
ResolverError::UnusedVariable { ident }
| ResolverError::UnusedItem { ident, .. }
| ResolverError::DuplicateField { field: ident }
Expand Down Expand Up @@ -748,6 +753,13 @@ impl<'a> From<&'a ResolverError> for Diagnostic {
diagnostic.add_secondary("Any code following this expression is unreachable".to_string(), *break_or_continue_location);
diagnostic
}
ResolverError::AssociatedItemConstraintsNotAllowedInGenerics { location} => {
Diagnostic::simple_error(
"Associated item constraints are not allowed here".to_string(),
"Consider removing this associated item binding".to_string(),
*location,
)
}
}
}
}
4 changes: 3 additions & 1 deletion noir_stdlib/src/hash/mod.nr
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,12 @@ pub trait BuildHasher {

pub struct BuildHasherDefault<H>;

impl<H> BuildHasher<H = H> for BuildHasherDefault<H>
impl<H> BuildHasher for BuildHasherDefault<H>
where
H: Hasher + Default,
{
type H = H;

fn build_hasher(_self: Self) -> H {
H::default()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "associated_type_in_impl_trait_generic"
type = "bin"
authors = [""]
compiler_version = ">=0.33.0"

[dependencies]
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
trait Trait {
type T;
}

impl Trait<T = i32> for bool {
}

fn main() {}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Loading
Loading