Skip to content

Commit 785edea

Browse files
authored
Unrolled build for rust-lang#118730
Rollup merge of rust-lang#118730 - jyn514:cmp_refs, r=estebank,compiler-errors recurse into refs when comparing tys for diagnostics before: ![image](https://github.com/rust-lang/rust/assets/23638587/bf6abd62-c7f3-4c09-a47e-31b6e129de19) after: ![image](https://github.com/rust-lang/rust/assets/23638587/b704d728-ddba-4204-aebe-c07dcbbcb55c) this diff from the test suite is also quite nice imo: ```diff `@@` -4,8 +4,8 `@@` error[E0308]: mismatched types LL | debug_assert_eq!(iter.next(), Some(value)); | ^^^^^^^^^^^ expected `Option<<I as Iterator>::Item>`, found `Option<&<I as Iterator>::Item>` | - = note: expected enum `Option<<I as Iterator>::Item>` - found enum `Option<&<I as Iterator>::Item>` + = note: expected enum `Option<_>` + found enum `Option<&_>` ```
2 parents 2d2f1b2 + eb53721 commit 785edea

File tree

58 files changed

+224
-214
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+224
-214
lines changed

Diff for: compiler/rustc_infer/src/infer/error_reporting/mod.rs

+52-42
Original file line numberDiff line numberDiff line change
@@ -1181,37 +1181,54 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
11811181
debug!("cmp(t1={}, t1.kind={:?}, t2={}, t2.kind={:?})", t1, t1.kind(), t2, t2.kind());
11821182

11831183
// helper functions
1184-
fn equals<'tcx>(a: Ty<'tcx>, b: Ty<'tcx>) -> bool {
1185-
match (a.kind(), b.kind()) {
1186-
(a, b) if *a == *b => true,
1187-
(&ty::Int(_), &ty::Infer(ty::InferTy::IntVar(_)))
1188-
| (
1189-
&ty::Infer(ty::InferTy::IntVar(_)),
1190-
&ty::Int(_) | &ty::Infer(ty::InferTy::IntVar(_)),
1191-
)
1192-
| (&ty::Float(_), &ty::Infer(ty::InferTy::FloatVar(_)))
1193-
| (
1194-
&ty::Infer(ty::InferTy::FloatVar(_)),
1195-
&ty::Float(_) | &ty::Infer(ty::InferTy::FloatVar(_)),
1196-
) => true,
1197-
_ => false,
1184+
let recurse = |t1, t2, values: &mut (DiagnosticStyledString, DiagnosticStyledString)| {
1185+
let (x1, x2) = self.cmp(t1, t2);
1186+
(values.0).0.extend(x1.0);
1187+
(values.1).0.extend(x2.0);
1188+
};
1189+
1190+
fn fmt_region<'tcx>(region: ty::Region<'tcx>) -> String {
1191+
let mut r = region.to_string();
1192+
if r == "'_" {
1193+
r.clear();
1194+
} else {
1195+
r.push(' ');
11981196
}
1197+
format!("&{r}")
11991198
}
12001199

1201-
fn push_ty_ref<'tcx>(
1200+
fn push_ref<'tcx>(
12021201
region: ty::Region<'tcx>,
1203-
ty: Ty<'tcx>,
12041202
mutbl: hir::Mutability,
12051203
s: &mut DiagnosticStyledString,
12061204
) {
1207-
let mut r = region.to_string();
1208-
if r == "'_" {
1209-
r.clear();
1205+
s.push_highlighted(fmt_region(region));
1206+
s.push_highlighted(mutbl.prefix_str());
1207+
}
1208+
1209+
fn cmp_ty_refs<'tcx>(
1210+
r1: ty::Region<'tcx>,
1211+
mut1: hir::Mutability,
1212+
r2: ty::Region<'tcx>,
1213+
mut2: hir::Mutability,
1214+
ss: &mut (DiagnosticStyledString, DiagnosticStyledString),
1215+
) {
1216+
let (r1, r2) = (fmt_region(r1), fmt_region(r2));
1217+
if r1 != r2 {
1218+
ss.0.push_highlighted(r1);
1219+
ss.1.push_highlighted(r2);
12101220
} else {
1211-
r.push(' ');
1221+
ss.0.push_normal(r1);
1222+
ss.1.push_normal(r2);
1223+
}
1224+
1225+
if mut1 != mut2 {
1226+
ss.0.push_highlighted(mut1.prefix_str());
1227+
ss.1.push_highlighted(mut2.prefix_str());
1228+
} else {
1229+
ss.0.push_normal(mut1.prefix_str());
1230+
ss.1.push_normal(mut2.prefix_str());
12121231
}
1213-
s.push_highlighted(format!("&{}{}", r, mutbl.prefix_str()));
1214-
s.push_normal(ty.to_string());
12151232
}
12161233

12171234
// process starts here
@@ -1310,9 +1327,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
13101327
values.0.push_normal("_");
13111328
values.1.push_normal("_");
13121329
} else {
1313-
let (x1, x2) = self.cmp(ta1, ta2);
1314-
(values.0).0.extend(x1.0);
1315-
(values.1).0.extend(x2.0);
1330+
recurse(ta1, ta2, &mut values);
13161331
}
13171332
self.push_comma(&mut values.0, &mut values.1, len, i);
13181333
}
@@ -1418,27 +1433,24 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
14181433
}
14191434
}
14201435

1421-
// When finding T != &T, highlight only the borrow
1422-
(&ty::Ref(r1, ref_ty1, mutbl1), _) if equals(ref_ty1, t2) => {
1436+
// When finding `&T != &T`, compare the references, then recurse into pointee type
1437+
(&ty::Ref(r1, ref_ty1, mutbl1), &ty::Ref(r2, ref_ty2, mutbl2)) => {
14231438
let mut values = (DiagnosticStyledString::new(), DiagnosticStyledString::new());
1424-
push_ty_ref(r1, ref_ty1, mutbl1, &mut values.0);
1425-
values.1.push_normal(t2.to_string());
1439+
cmp_ty_refs(r1, mutbl1, r2, mutbl2, &mut values);
1440+
recurse(ref_ty1, ref_ty2, &mut values);
14261441
values
14271442
}
1428-
(_, &ty::Ref(r2, ref_ty2, mutbl2)) if equals(t1, ref_ty2) => {
1443+
// When finding T != &T, highlight the borrow
1444+
(&ty::Ref(r1, ref_ty1, mutbl1), _) => {
14291445
let mut values = (DiagnosticStyledString::new(), DiagnosticStyledString::new());
1430-
values.0.push_normal(t1.to_string());
1431-
push_ty_ref(r2, ref_ty2, mutbl2, &mut values.1);
1446+
push_ref(r1, mutbl1, &mut values.0);
1447+
recurse(ref_ty1, t2, &mut values);
14321448
values
14331449
}
1434-
1435-
// When encountering &T != &mut T, highlight only the borrow
1436-
(&ty::Ref(r1, ref_ty1, mutbl1), &ty::Ref(r2, ref_ty2, mutbl2))
1437-
if equals(ref_ty1, ref_ty2) =>
1438-
{
1450+
(_, &ty::Ref(r2, ref_ty2, mutbl2)) => {
14391451
let mut values = (DiagnosticStyledString::new(), DiagnosticStyledString::new());
1440-
push_ty_ref(r1, ref_ty1, mutbl1, &mut values.0);
1441-
push_ty_ref(r2, ref_ty2, mutbl2, &mut values.1);
1452+
push_ref(r2, mutbl2, &mut values.1);
1453+
recurse(t1, ref_ty2, &mut values);
14421454
values
14431455
}
14441456

@@ -1448,9 +1460,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
14481460
(DiagnosticStyledString::normal("("), DiagnosticStyledString::normal("("));
14491461
let len = args1.len();
14501462
for (i, (left, right)) in args1.iter().zip(args2).enumerate() {
1451-
let (x1, x2) = self.cmp(left, right);
1452-
(values.0).0.extend(x1.0);
1453-
(values.1).0.extend(x2.0);
1463+
recurse(left, right, &mut values);
14541464
self.push_comma(&mut values.0, &mut values.1, len, i);
14551465
}
14561466
if len == 1 {

Diff for: tests/ui/associated-consts/associated-const-impl-wrong-lifetime.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ error[E0308]: const not compatible with trait
44
LL | const NAME: &'a str = "unit";
55
| ^^^^^^^^^^^^^^^^^^^ lifetime mismatch
66
|
7-
= note: expected reference `&'static str`
8-
found reference `&'a str`
7+
= note: expected reference `&'static _`
8+
found reference `&'a _`
99
note: the lifetime `'a` as defined here...
1010
--> $DIR/associated-const-impl-wrong-lifetime.rs:6:6
1111
|

Diff for: tests/ui/associated-types/dont-suggest-cyclic-constraint.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ error[E0308]: mismatched types
44
LL | debug_assert_eq!(iter.next(), Some(value));
55
| ^^^^^^^^^^^ expected `Option<<I as Iterator>::Item>`, found `Option<&<I as Iterator>::Item>`
66
|
7-
= note: expected enum `Option<<I as Iterator>::Item>`
8-
found enum `Option<&<I as Iterator>::Item>`
7+
= note: expected enum `Option<_>`
8+
found enum `Option<&_>`
99

1010
error: aborting due to 1 previous error
1111

Diff for: tests/ui/async-await/in-trait/async-example-desugared-boxed-in-trait.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ note: type in trait
99
|
1010
LL | fn foo(&self) -> Pin<Box<dyn Future<Output = i32> + '_>>;
1111
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12-
= note: expected signature `fn(&i32) -> Pin<Box<dyn Future<Output = i32>>>`
13-
found signature `fn(&i32) -> impl Future<Output = i32>`
12+
= note: expected signature `fn(&_) -> Pin<Box<dyn Future<Output = i32>>>`
13+
found signature `fn(&_) -> impl Future<Output = i32>`
1414

1515
error: aborting due to 1 previous error
1616

Diff for: tests/ui/borrowck/regions-bound-missing-bound-in-impl.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ error[E0308]: method not compatible with trait
2222
LL | fn wrong_bound1<'b,'c,'d:'a+'c>(self, b: Inv<'b>, c: Inv<'c>, d: Inv<'d>) {
2323
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lifetime mismatch
2424
|
25-
= note: expected signature `fn(&'a isize, Inv<'c>, Inv<'c>, Inv<'_>)`
26-
found signature `fn(&'a isize, Inv<'_>, Inv<'c>, Inv<'_>)`
25+
= note: expected signature `fn(&'a _, Inv<'c>, Inv<'c>, Inv<'_>)`
26+
found signature `fn(&'a _, Inv<'_>, Inv<'c>, Inv<'_>)`
2727
note: the lifetime `'c` as defined here...
2828
--> $DIR/regions-bound-missing-bound-in-impl.rs:27:24
2929
|
@@ -41,8 +41,8 @@ error[E0308]: method not compatible with trait
4141
LL | fn wrong_bound1<'b,'c,'d:'a+'c>(self, b: Inv<'b>, c: Inv<'c>, d: Inv<'d>) {
4242
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lifetime mismatch
4343
|
44-
= note: expected signature `fn(&'a isize, Inv<'c>, Inv<'c>, Inv<'_>)`
45-
found signature `fn(&'a isize, Inv<'_>, Inv<'c>, Inv<'_>)`
44+
= note: expected signature `fn(&'a _, Inv<'c>, Inv<'c>, Inv<'_>)`
45+
found signature `fn(&'a _, Inv<'_>, Inv<'c>, Inv<'_>)`
4646
note: the lifetime `'c` as defined here...
4747
--> $DIR/regions-bound-missing-bound-in-impl.rs:27:24
4848
|

Diff for: tests/ui/box/issue-82446.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ error[E0308]: mismatched types
44
LL | val
55
| ^^^ expected `Box<dyn MyTrait>`, found `&Box<dyn MyTrait>`
66
|
7-
= note: expected struct `Box<(dyn MyTrait + 'static)>`
8-
found reference `&Box<(dyn MyTrait + 'static)>`
7+
= note: expected struct `Box<_>`
8+
found reference `&Box<_>`
99

1010
error: aborting due to 1 previous error
1111

Diff for: tests/ui/closure-expected-type/expect-fn-supply-fn.stderr

+6-6
Original file line numberDiff line numberDiff line change
@@ -25,26 +25,26 @@ error[E0308]: mismatched types
2525
LL | with_closure_expecting_fn_with_free_region(|x: fn(&u32), y| {});
2626
| ^ one type is more general than the other
2727
|
28-
= note: expected fn pointer `fn(&u32)`
29-
found fn pointer `for<'a> fn(&'a u32)`
28+
= note: expected fn pointer `fn(&_)`
29+
found fn pointer `for<'a> fn(&'a _)`
3030

3131
error[E0308]: mismatched types
3232
--> $DIR/expect-fn-supply-fn.rs:39:50
3333
|
3434
LL | with_closure_expecting_fn_with_bound_region(|x: fn(&'x u32), y| {});
3535
| ^ one type is more general than the other
3636
|
37-
= note: expected fn pointer `for<'a> fn(&'a u32)`
38-
found fn pointer `fn(&u32)`
37+
= note: expected fn pointer `for<'a> fn(&'a _)`
38+
found fn pointer `fn(&_)`
3939

4040
error[E0308]: mismatched types
4141
--> $DIR/expect-fn-supply-fn.rs:48:50
4242
|
4343
LL | with_closure_expecting_fn_with_bound_region(|x: Foo<'_>, y| {
4444
| ^ one type is more general than the other
4545
|
46-
= note: expected fn pointer `for<'a> fn(&'a u32)`
47-
found fn pointer `fn(&u32)`
46+
= note: expected fn pointer `for<'a> fn(&'a _)`
47+
found fn pointer `fn(&_)`
4848

4949
error: aborting due to 5 previous errors
5050

Diff for: tests/ui/closures/multiple-fn-bounds.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ LL | foo(move |x| v);
66
| |
77
| expected due to this
88
|
9-
= note: expected closure signature `fn(char) -> _`
10-
found closure signature `for<'a> fn(&'a char) -> _`
9+
= note: expected closure signature `fn(_) -> _`
10+
found closure signature `for<'a> fn(&'a _) -> _`
1111
note: closure inferred to have a different signature due to this bound
1212
--> $DIR/multiple-fn-bounds.rs:1:11
1313
|

Diff for: tests/ui/fn/fn-pointer-mismatch.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,20 @@ fn main() {
3535
// suggest removing reference
3636
let c: fn(u32) -> u32 = &foo;
3737
//~^ ERROR mismatched types
38-
//~| expected fn pointer `fn(u32) -> u32`
39-
//~| found reference `&fn(u32) -> u32 {foo}`
38+
//~| expected fn pointer `fn(_) -> _`
39+
//~| found reference `&fn(_) -> _ {foo}`
4040

4141
// suggest using reference
4242
let d: &fn(u32) -> u32 = foo;
4343
//~^ ERROR mismatched types
44-
//~| expected reference `&fn(u32) -> u32`
45-
//~| found fn item `fn(u32) -> u32 {foo}`
44+
//~| expected reference `&fn(_) -> _`
45+
//~| found fn item `fn(_) -> _ {foo}`
4646

4747
// suggest casting with reference
4848
let e: &fn(u32) -> u32 = &foo;
4949
//~^ ERROR mismatched types
50-
//~| expected reference `&fn(u32) -> u32`
51-
//~| found reference `&fn(u32) -> u32 {foo}`
50+
//~| expected reference `&fn(_) -> _`
51+
//~| found reference `&fn(_) -> _ {foo}`
5252

5353
// OK
5454
let mut z: fn(u32) -> u32 = foo as fn(u32) -> u32;

Diff for: tests/ui/fn/fn-pointer-mismatch.stderr

+8-8
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ LL | let g = if n % 2 == 0 { &foo } else { &bar };
66
| |
77
| expected because of this
88
|
9-
= note: expected reference `&fn(u32) -> u32 {foo}`
10-
found reference `&fn(u32) -> u32 {bar}`
9+
= note: expected reference `&fn(_) -> _ {foo}`
10+
found reference `&fn(_) -> _ {bar}`
1111
= note: different fn items have unique types, even if their signatures are the same
1212
= help: consider casting both fn items to fn pointers using `as fn(u32) -> u32`
1313

@@ -47,8 +47,8 @@ LL | let c: fn(u32) -> u32 = &foo;
4747
| |
4848
| expected due to this
4949
|
50-
= note: expected fn pointer `fn(u32) -> u32`
51-
found reference `&fn(u32) -> u32 {foo}`
50+
= note: expected fn pointer `fn(_) -> _`
51+
found reference `&fn(_) -> _ {foo}`
5252
help: consider removing the reference
5353
|
5454
LL | let c: fn(u32) -> u32 = foo;
@@ -62,8 +62,8 @@ LL | let d: &fn(u32) -> u32 = foo;
6262
| |
6363
| expected due to this
6464
|
65-
= note: expected reference `&fn(u32) -> u32`
66-
found fn item `fn(u32) -> u32 {foo}`
65+
= note: expected reference `&fn(_) -> _`
66+
found fn item `fn(_) -> _ {foo}`
6767
help: consider using a reference
6868
|
6969
LL | let d: &fn(u32) -> u32 = &foo;
@@ -77,8 +77,8 @@ LL | let e: &fn(u32) -> u32 = &foo;
7777
| |
7878
| expected due to this
7979
|
80-
= note: expected reference `&fn(u32) -> u32`
81-
found reference `&fn(u32) -> u32 {foo}`
80+
= note: expected reference `&fn(_) -> _`
81+
found reference `&fn(_) -> _ {foo}`
8282
= note: fn items are distinct from fn pointers
8383
help: consider casting to a fn pointer
8484
|

Diff for: tests/ui/generic-associated-types/issue-88360.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ LL | fn copy(&self) -> Self::Gat<'_> where T: Copy {
99
LL | *self.test()
1010
| ^^^^^^^^^^^^ expected `&T`, found type parameter `T`
1111
|
12-
= note: expected reference `&T`
13-
found type parameter `T`
12+
= note: expected reference `&_`
13+
found type parameter `_`
1414
help: consider removing deref here
1515
|
1616
LL - *self.test()

Diff for: tests/ui/higher-ranked/subtype/hr-subtype.bound_a_b_ret_a_vs_bound_a_ret_a.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ LL | / check! { bound_a_b_ret_a_vs_bound_a_ret_a: (for<'a,'b> fn(&'a u32, &'b u3
88
LL | | for<'a> fn(&'a u32, &'a u32) -> &'a u32) }
99
| |_____________________________________________- in this macro invocation
1010
|
11-
= note: expected enum `Option<for<'a, 'b> fn(&'a u32, &'b u32) -> &'a u32>`
12-
found enum `Option<for<'a> fn(&'a u32, &'a u32) -> &'a u32>`
11+
= note: expected enum `Option<for<'a, 'b> fn(&'a _, &'b _) -> &'a _>`
12+
found enum `Option<for<'a> fn(&'a _, &'a _) -> &'a _>`
1313
= note: this error originates in the macro `check` (in Nightly builds, run with -Z macro-backtrace for more info)
1414

1515
error: aborting due to 1 previous error

Diff for: tests/ui/higher-ranked/subtype/hr-subtype.bound_a_vs_free_x.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ LL | / check! { bound_a_vs_free_x: (for<'a> fn(&'a u32),
88
LL | | fn(&'x u32)) }
99
| |______________- in this macro invocation
1010
|
11-
= note: expected enum `Option<for<'a> fn(&'a u32)>`
12-
found enum `Option<fn(&u32)>`
11+
= note: expected enum `Option<for<'a> fn(&'a _)>`
12+
found enum `Option<fn(&_)>`
1313
= note: this error originates in the macro `check` (in Nightly builds, run with -Z macro-backtrace for more info)
1414

1515
error: aborting due to 1 previous error

Diff for: tests/ui/higher-ranked/trait-bounds/hrtb-exists-forall-fn.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ LL | let _: for<'b> fn(&'b u32) = foo();
66
| |
77
| expected due to this
88
|
9-
= note: expected fn pointer `for<'b> fn(&'b u32)`
10-
found fn pointer `fn(&u32)`
9+
= note: expected fn pointer `for<'b> fn(&'b _)`
10+
found fn pointer `fn(&_)`
1111

1212
error: aborting due to 1 previous error
1313

Diff for: tests/ui/impl-trait/in-trait/specialization-broken.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ note: type in trait
1515
|
1616
LL | fn bar(&self) -> impl Sized;
1717
| ^^^^^^^^^^
18-
= note: expected signature `fn(&U) -> impl Sized`
19-
found signature `fn(&U) -> U`
18+
= note: expected signature `fn(&_) -> impl Sized`
19+
found signature `fn(&_) -> U`
2020

2121
error: method with return-position `impl Trait` in trait cannot be specialized
2222
--> $DIR/specialization-broken.rs:15:5

Diff for: tests/ui/impl-trait/recursive-type-alias-impl-trait-declaration-too-subtle.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ LL | fn eq(&self, _other: &(Foo, i32)) -> bool {
1818
| expected `a::Bar`, found opaque type
1919
| help: change the parameter type to match the trait: `&(a::Bar, i32)`
2020
|
21-
= note: expected signature `fn(&a::Bar, &(a::Bar, i32)) -> _`
22-
found signature `fn(&a::Bar, &(a::Foo, i32)) -> _`
21+
= note: expected signature `fn(&a::Bar, &(a::Bar, _)) -> _`
22+
found signature `fn(&a::Bar, &(a::Foo, _)) -> _`
2323

2424
error: unconstrained opaque type
2525
--> $DIR/recursive-type-alias-impl-trait-declaration-too-subtle.rs:18:16
@@ -41,8 +41,8 @@ LL | fn eq(&self, _other: &(Bar, i32)) -> bool {
4141
| expected opaque type, found `b::Bar`
4242
| help: change the parameter type to match the trait: `&(b::Foo, i32)`
4343
|
44-
= note: expected signature `fn(&b::Bar, &(b::Foo, i32)) -> _`
45-
found signature `fn(&b::Bar, &(b::Bar, i32)) -> _`
44+
= note: expected signature `fn(&b::Bar, &(b::Foo, _)) -> _`
45+
found signature `fn(&b::Bar, &(b::Bar, _)) -> _`
4646
note: this item must have the opaque type in its signature in order to be able to register hidden types
4747
--> $DIR/recursive-type-alias-impl-trait-declaration-too-subtle.rs:24:12
4848
|

0 commit comments

Comments
 (0)