Skip to content

Commit 3c08a50

Browse files
authored
Rollup merge of #140278 - compiler-errors:name-based-comparison, r=nnethercote
Don't use item name to look up associated item from trait item This fix should be self-justifying b/c the fact that we were using identifiers here was kinda sus anyways, esp b/c we have a failproof way of doing the comparison :) I'll leave some info about why this repro needs a macro. Fixes #140259 r? `@nnethercote`
2 parents e534fad + 1d0b3be commit 3c08a50

File tree

3 files changed

+54
-7
lines changed

3 files changed

+54
-7
lines changed

compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -1523,19 +1523,17 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
15231523
return None;
15241524
};
15251525

1526-
let trait_assoc_item = self.tcx.opt_associated_item(proj.projection_term.def_id)?;
1527-
let trait_assoc_ident = trait_assoc_item.ident(self.tcx);
1528-
15291526
let mut associated_items = vec![];
15301527
self.tcx.for_each_relevant_impl(
15311528
self.tcx.trait_of_item(proj.projection_term.def_id)?,
15321529
proj.projection_term.self_ty(),
15331530
|impl_def_id| {
15341531
associated_items.extend(
1535-
self.tcx
1536-
.associated_items(impl_def_id)
1537-
.in_definition_order()
1538-
.find(|assoc| assoc.ident(self.tcx) == trait_assoc_ident),
1532+
self.tcx.associated_items(impl_def_id).in_definition_order().find(
1533+
|assoc| {
1534+
assoc.trait_item_def_id == Some(proj.projection_term.def_id)
1535+
},
1536+
),
15391537
);
15401538
},
15411539
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
trait ServerFn {
2+
type Output;
3+
fn run_body() -> impl Sized;
4+
}
5+
struct MyServerFn {}
6+
7+
macro_rules! f {
8+
() => {
9+
impl ServerFn for MyServerFn {
10+
type Output = ();
11+
fn run_body() -> impl Sized {}
12+
}
13+
};
14+
}
15+
16+
f! {}
17+
18+
fn problem<T: ServerFn<Output = i64>>(_: T) {}
19+
20+
fn main() {
21+
problem(MyServerFn {});
22+
//~^ ERROR type mismatch resolving `<MyServerFn as ServerFn>::Output == i64`
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
error[E0271]: type mismatch resolving `<MyServerFn as ServerFn>::Output == i64`
2+
--> $DIR/dont-probe-missing-item-name-4.rs:21:13
3+
|
4+
LL | problem(MyServerFn {});
5+
| ------- ^^^^^^^^^^^^^ type mismatch resolving `<MyServerFn as ServerFn>::Output == i64`
6+
| |
7+
| required by a bound introduced by this call
8+
|
9+
note: expected this to be `i64`
10+
--> $DIR/dont-probe-missing-item-name-4.rs:10:27
11+
|
12+
LL | type Output = ();
13+
| ^^
14+
...
15+
LL | f! {}
16+
| ----- in this macro invocation
17+
note: required by a bound in `problem`
18+
--> $DIR/dont-probe-missing-item-name-4.rs:18:24
19+
|
20+
LL | fn problem<T: ServerFn<Output = i64>>(_: T) {}
21+
| ^^^^^^^^^^^^ required by this bound in `problem`
22+
= note: this error originates in the macro `f` (in Nightly builds, run with -Z macro-backtrace for more info)
23+
24+
error: aborting due to 1 previous error
25+
26+
For more information about this error, try `rustc --explain E0271`.

0 commit comments

Comments
 (0)