Skip to content

Commit dbff283

Browse files
committed
Auto merge of #116082 - compiler-errors:default-assoc-ty-msg, r=estebank
Tweak expected message to explain what it's actually signifying r? `@estebank` since you added this
2 parents 0237aa3 + 82e7cec commit dbff283

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

compiler/rustc_infer/src/infer/error_reporting/note_and_explain.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -616,9 +616,13 @@ fn foo(&self) -> Self::T { String::new() }
616616
for item in &items[..] {
617617
if let hir::AssocItemKind::Type = item.kind {
618618
let assoc_ty = tcx.type_of(item.id.owner_id).instantiate_identity();
619-
620-
if self.infcx.can_eq(param_env, assoc_ty, found) {
621-
diag.span_label(item.span, "expected this associated type");
619+
if let hir::Defaultness::Default { has_value: true } = tcx.defaultness(item.id.owner_id)
620+
&& self.infcx.can_eq(param_env, assoc_ty, found)
621+
{
622+
diag.span_label(
623+
item.span,
624+
format!("associated type is `default` and may be overridden"),
625+
);
622626
return true;
623627
}
624628
}

tests/ui/associated-types/defaults-specialization.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ error[E0053]: method `make` has an incompatible type for trait
2929
--> $DIR/defaults-specialization.rs:35:18
3030
|
3131
LL | default type Ty = bool;
32-
| ----------------------- expected this associated type
32+
| ----------------------- associated type is `default` and may be overridden
3333
LL |
3434
LL | fn make() -> bool { true }
3535
| ^^^^
@@ -76,7 +76,7 @@ error[E0308]: mismatched types
7676
--> $DIR/defaults-specialization.rs:44:29
7777
|
7878
LL | default type Ty = bool;
79-
| ----------------------- expected this associated type
79+
| ----------------------- associated type is `default` and may be overridden
8080
LL |
8181
LL | fn make() -> Self::Ty { true }
8282
| -------- ^^^^ expected associated type, found `bool`

tests/ui/specialization/specialization-default-types.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ error[E0308]: mismatched types
1212
--> $DIR/specialization-default-types.rs:15:9
1313
|
1414
LL | default type Output = Box<T>;
15-
| ----------------------------- expected this associated type
15+
| ----------------------------- associated type is `default` and may be overridden
1616
LL | default fn generate(self) -> Self::Output {
1717
| ------------ expected `<T as Example>::Output` because of return type
1818
LL | Box::new(self)

0 commit comments

Comments
 (0)