Skip to content

Commit

Permalink
Rollup merge of #116082 - compiler-errors:default-assoc-ty-msg, r=est…
Browse files Browse the repository at this point in the history
…ebank

Tweak expected message to explain what it's actually signifying

r? ``@estebank`` since you added this
  • Loading branch information
matthiaskrgr authored Sep 23, 2023
2 parents d92a1bd + 82e7cec commit 8c9e516
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -616,9 +616,13 @@ fn foo(&self) -> Self::T { String::new() }
for item in &items[..] {
if let hir::AssocItemKind::Type = item.kind {
let assoc_ty = tcx.type_of(item.id.owner_id).instantiate_identity();

if self.infcx.can_eq(param_env, assoc_ty, found) {
diag.span_label(item.span, "expected this associated type");
if let hir::Defaultness::Default { has_value: true } = tcx.defaultness(item.id.owner_id)
&& self.infcx.can_eq(param_env, assoc_ty, found)
{
diag.span_label(
item.span,
format!("associated type is `default` and may be overridden"),
);
return true;
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/associated-types/defaults-specialization.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ error[E0053]: method `make` has an incompatible type for trait
--> $DIR/defaults-specialization.rs:35:18
|
LL | default type Ty = bool;
| ----------------------- expected this associated type
| ----------------------- associated type is `default` and may be overridden
LL |
LL | fn make() -> bool { true }
| ^^^^
Expand Down Expand Up @@ -76,7 +76,7 @@ error[E0308]: mismatched types
--> $DIR/defaults-specialization.rs:44:29
|
LL | default type Ty = bool;
| ----------------------- expected this associated type
| ----------------------- associated type is `default` and may be overridden
LL |
LL | fn make() -> Self::Ty { true }
| -------- ^^^^ expected associated type, found `bool`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ error[E0308]: mismatched types
--> $DIR/specialization-default-types.rs:15:9
|
LL | default type Output = Box<T>;
| ----------------------------- expected this associated type
| ----------------------------- associated type is `default` and may be overridden
LL | default fn generate(self) -> Self::Output {
| ------------ expected `<T as Example>::Output` because of return type
LL | Box::new(self)
Expand Down

0 comments on commit 8c9e516

Please sign in to comment.