Skip to content

Commit 4b77d8e

Browse files
authored
Unrolled build for rust-lang#136928
Rollup merge of rust-lang#136928 - lcnr:method-lookup-check-wf, r=compiler-errors eagerly prove WF when resolving fully qualified paths fixes rust-lang/trait-system-refactor-initiative#161. This hopefully shouldn't impact perf. I do think we need to deal with at least part of the fallout here, opening for vibes. r? ``@compiler-errors``
2 parents a567209 + 83a0261 commit 4b77d8e

28 files changed

+338
-158
lines changed

Diff for: compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

+8-25
Original file line numberDiff line numberDiff line change
@@ -798,13 +798,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
798798
bug!("`resolve_ty_and_res_fully_qualified_call` called on `LangItem`")
799799
}
800800
};
801+
802+
self.register_wf_obligation(
803+
ty.raw.into(),
804+
qself.span,
805+
ObligationCauseCode::WellFormed(None),
806+
);
807+
self.select_obligations_where_possible(|_| {});
808+
801809
if let Some(&cached_result) = self.typeck_results.borrow().type_dependent_defs().get(hir_id)
802810
{
803-
self.register_wf_obligation(
804-
ty.raw.into(),
805-
qself.span,
806-
ObligationCauseCode::WellFormed(None),
807-
);
808811
// Return directly on cache hit. This is useful to avoid doubly reporting
809812
// errors with default match binding modes. See #44614.
810813
let def = cached_result.map_or(Res::Err, |(kind, def_id)| Res::Def(kind, def_id));
@@ -824,18 +827,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
824827

825828
let trait_missing_method =
826829
matches!(error, method::MethodError::NoMatch(_)) && ty.normalized.is_trait();
827-
// If we have a path like `MyTrait::missing_method`, then don't register
828-
// a WF obligation for `dyn MyTrait` when method lookup fails. Otherwise,
829-
// register a WF obligation so that we can detect any additional
830-
// errors in the self type.
831-
if !trait_missing_method {
832-
self.register_wf_obligation(
833-
ty.raw.into(),
834-
qself.span,
835-
ObligationCauseCode::WellFormed(None),
836-
);
837-
}
838-
839830
if item_name.name != kw::Empty {
840831
self.report_method_error(
841832
hir_id,
@@ -849,14 +840,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
849840
result
850841
});
851842

852-
if result.is_ok() {
853-
self.register_wf_obligation(
854-
ty.raw.into(),
855-
qself.span,
856-
ObligationCauseCode::WellFormed(None),
857-
);
858-
}
859-
860843
// Write back the new resolution.
861844
self.write_resolution(hir_id, result);
862845
(

Diff for: tests/ui/associated-consts/associated-const-in-trait.rs

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ impl dyn Trait {
88
//~^ ERROR the trait `Trait` is not dyn compatible [E0038]
99
const fn n() -> usize { Self::N }
1010
//~^ ERROR the trait `Trait` is not dyn compatible [E0038]
11+
//~| ERROR the trait `Trait` is not dyn compatible
1112
}
1213

1314
fn main() {}

Diff for: tests/ui/associated-consts/associated-const-in-trait.stderr

+17-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,22 @@ LL | const N: usize;
3030
| ^ ...because it contains this associated `const`
3131
= help: consider moving `N` to another trait
3232

33-
error: aborting due to 2 previous errors
33+
error[E0038]: the trait `Trait` is not dyn compatible
34+
--> $DIR/associated-const-in-trait.rs:9:29
35+
|
36+
LL | const fn n() -> usize { Self::N }
37+
| ^^^^^^^ `Trait` is not dyn compatible
38+
|
39+
note: for a trait to be dyn compatible it needs to allow building a vtable
40+
for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility>
41+
--> $DIR/associated-const-in-trait.rs:4:11
42+
|
43+
LL | trait Trait {
44+
| ----- this trait is not dyn compatible...
45+
LL | const N: usize;
46+
| ^ ...because it contains this associated `const`
47+
= help: consider moving `N` to another trait
48+
49+
error: aborting due to 3 previous errors
3450

3551
For more information about this error, try `rustc --explain E0038`.

Diff for: tests/ui/associated-consts/wrong-projection-self-ty-invalid-bivariant-arg2.stderr

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,3 @@
1-
error[E0599]: no associated item named `C` found for struct `Fail<i32, u32>` in the current scope
2-
--> $DIR/wrong-projection-self-ty-invalid-bivariant-arg2.rs:15:23
3-
|
4-
LL | struct Fail<T: Proj<Assoc = U>, U>(T);
5-
| ---------------------------------- associated item `C` not found for this struct
6-
...
7-
LL | Fail::<i32, u32>::C
8-
| ^ associated item not found in `Fail<i32, u32>`
9-
|
10-
= note: the associated item was found for
11-
- `Fail<i32, i32>`
12-
131
error[E0271]: type mismatch resolving `<i32 as Proj>::Assoc == u32`
142
--> $DIR/wrong-projection-self-ty-invalid-bivariant-arg2.rs:15:5
153
|
@@ -27,6 +15,18 @@ note: required by a bound in `Fail`
2715
LL | struct Fail<T: Proj<Assoc = U>, U>(T);
2816
| ^^^^^^^^^ required by this bound in `Fail`
2917

18+
error[E0599]: no associated item named `C` found for struct `Fail<i32, u32>` in the current scope
19+
--> $DIR/wrong-projection-self-ty-invalid-bivariant-arg2.rs:15:23
20+
|
21+
LL | struct Fail<T: Proj<Assoc = U>, U>(T);
22+
| ---------------------------------- associated item `C` not found for this struct
23+
...
24+
LL | Fail::<i32, u32>::C
25+
| ^ associated item not found in `Fail<i32, u32>`
26+
|
27+
= note: the associated item was found for
28+
- `Fail<i32, i32>`
29+
3030
error: aborting due to 2 previous errors
3131

3232
Some errors have detailed explanations: E0271, E0599.

Diff for: tests/ui/associated-types/hr-associated-type-bound-object.rs

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ fn f<'a, T: X<'a> + ?Sized>(x: &<T as X<'a>>::U) {
99
<<T as X<'_>>::U>::clone(x);
1010
//~^ ERROR the trait bound `for<'b> <T as X<'b>>::U: Clone` is not satisfied
1111
//~| ERROR the trait bound `for<'b> <T as X<'b>>::U: Clone` is not satisfied
12+
//~| ERROR the trait bound `for<'b> <T as X<'b>>::U: Clone` is not satisfied
1213
//~| ERROR the trait bound `<T as X<'_>>::U: Clone` is not satisfied
1314
}
1415

Diff for: tests/ui/associated-types/hr-associated-type-bound-object.stderr

+20-1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,25 @@ help: consider further restricting the associated type
4747
LL | fn f<'a, T: X<'a> + ?Sized>(x: &<T as X<'a>>::U) where <T as X<'_>>::U: Clone {
4848
| ++++++++++++++++++++++++++++
4949

50+
error[E0277]: the trait bound `for<'b> <T as X<'b>>::U: Clone` is not satisfied
51+
--> $DIR/hr-associated-type-bound-object.rs:9:5
52+
|
53+
LL | <<T as X<'_>>::U>::clone(x);
54+
| ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `for<'b> Clone` is not implemented for `<T as X<'b>>::U`
55+
|
56+
note: required by a bound in `X`
57+
--> $DIR/hr-associated-type-bound-object.rs:3:33
58+
|
59+
LL | trait X<'a>
60+
| - required by a bound in this trait
61+
LL | where
62+
LL | for<'b> <Self as X<'b>>::U: Clone,
63+
| ^^^^^ required by this bound in `X`
64+
help: consider further restricting the associated type
65+
|
66+
LL | fn f<'a, T: X<'a> + ?Sized>(x: &<T as X<'a>>::U) where for<'b> <T as X<'b>>::U: Clone {
67+
| ++++++++++++++++++++++++++++++++++++
68+
5069
error[E0277]: the trait bound `for<'b> <T as X<'b>>::U: Clone` is not satisfied
5170
--> $DIR/hr-associated-type-bound-object.rs:9:5
5271
|
@@ -66,6 +85,6 @@ help: consider further restricting the associated type
6685
LL | fn f<'a, T: X<'a> + ?Sized>(x: &<T as X<'a>>::U) where for<'b> <T as X<'b>>::U: Clone {
6786
| ++++++++++++++++++++++++++++++++++++
6887

69-
error: aborting due to 4 previous errors
88+
error: aborting due to 5 previous errors
7089

7190
For more information about this error, try `rustc --explain E0277`.

Diff for: tests/ui/associated-types/hr-associated-type-bound-param-2.rs

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ where
1010
<T::W>::clone(x);
1111
//~^ the trait bound `str: Clone` is not satisfied
1212
//~| the trait bound `str: Clone` is not satisfied
13+
//~| the trait bound `str: Clone` is not satisfied
1314
}
1415
}
1516

Diff for: tests/ui/associated-types/hr-associated-type-bound-param-2.stderr

+19-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ LL | for<'b> <T as Z<'b, u16>>::W: Clone,
1515
| ^^^^^ required by this bound in `Z`
1616

1717
error[E0277]: the trait bound `str: Clone` is not satisfied
18-
--> $DIR/hr-associated-type-bound-param-2.rs:17:14
18+
--> $DIR/hr-associated-type-bound-param-2.rs:18:14
1919
|
2020
LL | type W = str;
2121
| ^^^ the trait `Clone` is not implemented for `str`
@@ -63,6 +63,22 @@ LL | {
6363
LL | type W: ?Sized;
6464
| - required by a bound in this associated type
6565

66+
error[E0277]: the trait bound `str: Clone` is not satisfied
67+
--> $DIR/hr-associated-type-bound-param-2.rs:10:9
68+
|
69+
LL | <T::W>::clone(x);
70+
| ^^^^^^^^^^^^^ the trait `Clone` is not implemented for `str`
71+
|
72+
= help: the trait `Clone` is implemented for `String`
73+
note: required by a bound in `Z`
74+
--> $DIR/hr-associated-type-bound-param-2.rs:6:35
75+
|
76+
LL | trait Z<'a, T: ?Sized>
77+
| - required by a bound in this trait
78+
...
79+
LL | for<'b> <T as Z<'b, u16>>::W: Clone,
80+
| ^^^^^ required by this bound in `Z`
81+
6682
error[E0277]: the trait bound `str: Clone` is not satisfied
6783
--> $DIR/hr-associated-type-bound-param-2.rs:10:9
6884
|
@@ -80,7 +96,7 @@ LL | for<'b> <T as Z<'b, u16>>::W: Clone,
8096
| ^^^^^ required by this bound in `Z`
8197

8298
error[E0277]: the trait bound `str: Clone` is not satisfied
83-
--> $DIR/hr-associated-type-bound-param-2.rs:22:10
99+
--> $DIR/hr-associated-type-bound-param-2.rs:23:10
84100
|
85101
LL | 1u16.h("abc");
86102
| ^ the trait `Clone` is not implemented for `str`
@@ -95,6 +111,6 @@ LL | for<'b> <T as Z<'b, u16>>::W: Clone,
95111
LL | fn h(&self, x: &T::W) {
96112
| - required by a bound in this associated function
97113

98-
error: aborting due to 6 previous errors
114+
error: aborting due to 7 previous errors
99115

100116
For more information about this error, try `rustc --explain E0277`.

Diff for: tests/ui/const-generics/defaults/doesnt_infer.stderr

+12-12
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@ error[E0284]: type annotations needed for `Foo<_>`
22
--> $DIR/doesnt_infer.rs:13:9
33
|
44
LL | let foo = Foo::foo();
5-
| ^^^ ---------- type must be known at this point
5+
| ^^^ --- type must be known at this point
66
|
7-
note: required by a const generic parameter in `Foo::<N>::foo`
8-
--> $DIR/doesnt_infer.rs:5:6
7+
note: required by a const generic parameter in `Foo`
8+
--> $DIR/doesnt_infer.rs:3:12
99
|
10-
LL | impl<const N: u32> Foo<N> {
11-
| ^^^^^^^^^^^^ required by this const generic parameter in `Foo::<N>::foo`
12-
LL | fn foo() -> Self {
13-
| --- required by a bound in this associated function
10+
LL | struct Foo<const N: u32 = 2>;
11+
| ^^^^^^^^^^^^^^^^ required by this const generic parameter in `Foo`
1412
help: consider giving `foo` an explicit type, where the value of const parameter `N` is specified
1513
|
1614
LL | let foo: Foo<N> = Foo::foo();
@@ -20,13 +18,15 @@ error[E0284]: type annotations needed for `Foo<_>`
2018
--> $DIR/doesnt_infer.rs:13:9
2119
|
2220
LL | let foo = Foo::foo();
23-
| ^^^ --- type must be known at this point
21+
| ^^^ ---------- type must be known at this point
2422
|
25-
note: required by a const generic parameter in `Foo`
26-
--> $DIR/doesnt_infer.rs:3:12
23+
note: required by a const generic parameter in `Foo::<N>::foo`
24+
--> $DIR/doesnt_infer.rs:5:6
2725
|
28-
LL | struct Foo<const N: u32 = 2>;
29-
| ^^^^^^^^^^^^^^^^ required by this const generic parameter in `Foo`
26+
LL | impl<const N: u32> Foo<N> {
27+
| ^^^^^^^^^^^^ required by this const generic parameter in `Foo::<N>::foo`
28+
LL | fn foo() -> Self {
29+
| --- required by a bound in this associated function
3030
help: consider giving `foo` an explicit type, where the value of const parameter `N` is specified
3131
|
3232
LL | let foo: Foo<N> = Foo::foo();

Diff for: tests/ui/const-generics/generic_arg_infer/issue-91614.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ error[E0284]: type annotations needed for `Mask<_, _>`
22
--> $DIR/issue-91614.rs:6:9
33
|
44
LL | let y = Mask::<_, _>::splat(false);
5-
| ^ -------------------------- type must be known at this point
5+
| ^ ------------ type must be known at this point
66
|
7-
note: required by a const generic parameter in `Mask::<T, N>::splat`
7+
note: required by a const generic parameter in `Mask`
88
--> $SRC_DIR/core/src/../../portable-simd/crates/core_simd/src/masks.rs:LL:COL
99
help: consider giving `y` an explicit type, where the value of const parameter `N` is specified
1010
|
@@ -15,9 +15,9 @@ error[E0284]: type annotations needed for `Mask<_, _>`
1515
--> $DIR/issue-91614.rs:6:9
1616
|
1717
LL | let y = Mask::<_, _>::splat(false);
18-
| ^ ------------ type must be known at this point
18+
| ^ -------------------------- type must be known at this point
1919
|
20-
note: required by a const generic parameter in `Mask`
20+
note: required by a const generic parameter in `Mask::<T, N>::splat`
2121
--> $SRC_DIR/core/src/../../portable-simd/crates/core_simd/src/masks.rs:LL:COL
2222
help: consider giving `y` an explicit type, where the value of const parameter `N` is specified
2323
|

Diff for: tests/ui/const-generics/generic_const_exprs/issue-62504.full.stderr

+12-12
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,13 @@ error[E0284]: type annotations needed for `ArrayHolder<_>`
2222
--> $DIR/issue-62504.rs:26:9
2323
|
2424
LL | let mut array = ArrayHolder::new();
25-
| ^^^^^^^^^ ------------------ type must be known at this point
25+
| ^^^^^^^^^ ----------- type must be known at this point
2626
|
27-
note: required by a const generic parameter in `ArrayHolder::<X>::new`
28-
--> $DIR/issue-62504.rs:16:6
27+
note: required by a const generic parameter in `ArrayHolder`
28+
--> $DIR/issue-62504.rs:14:20
2929
|
30-
LL | impl<const X: usize> ArrayHolder<X> {
31-
| ^^^^^^^^^^^^^^ required by this const generic parameter in `ArrayHolder::<X>::new`
32-
LL | pub const fn new() -> Self {
33-
| --- required by a bound in this associated function
30+
LL | struct ArrayHolder<const X: usize>([u32; X]);
31+
| ^^^^^^^^^^^^^^ required by this const generic parameter in `ArrayHolder`
3432
help: consider giving `array` an explicit type, where the value of const parameter `X` is specified
3533
|
3634
LL | let mut array: ArrayHolder<X> = ArrayHolder::new();
@@ -40,13 +38,15 @@ error[E0284]: type annotations needed for `ArrayHolder<_>`
4038
--> $DIR/issue-62504.rs:26:9
4139
|
4240
LL | let mut array = ArrayHolder::new();
43-
| ^^^^^^^^^ ----------- type must be known at this point
41+
| ^^^^^^^^^ ------------------ type must be known at this point
4442
|
45-
note: required by a const generic parameter in `ArrayHolder`
46-
--> $DIR/issue-62504.rs:14:20
43+
note: required by a const generic parameter in `ArrayHolder::<X>::new`
44+
--> $DIR/issue-62504.rs:16:6
4745
|
48-
LL | struct ArrayHolder<const X: usize>([u32; X]);
49-
| ^^^^^^^^^^^^^^ required by this const generic parameter in `ArrayHolder`
46+
LL | impl<const X: usize> ArrayHolder<X> {
47+
| ^^^^^^^^^^^^^^ required by this const generic parameter in `ArrayHolder::<X>::new`
48+
LL | pub const fn new() -> Self {
49+
| --- required by a bound in this associated function
5050
help: consider giving `array` an explicit type, where the value of const parameter `X` is specified
5151
|
5252
LL | let mut array: ArrayHolder<X> = ArrayHolder::new();

Diff for: tests/ui/const-generics/generic_const_exprs/issue-62504.min.stderr

+12-12
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,13 @@ error[E0284]: type annotations needed for `ArrayHolder<_>`
2424
--> $DIR/issue-62504.rs:26:9
2525
|
2626
LL | let mut array = ArrayHolder::new();
27-
| ^^^^^^^^^ ------------------ type must be known at this point
27+
| ^^^^^^^^^ ----------- type must be known at this point
2828
|
29-
note: required by a const generic parameter in `ArrayHolder::<X>::new`
30-
--> $DIR/issue-62504.rs:16:6
29+
note: required by a const generic parameter in `ArrayHolder`
30+
--> $DIR/issue-62504.rs:14:20
3131
|
32-
LL | impl<const X: usize> ArrayHolder<X> {
33-
| ^^^^^^^^^^^^^^ required by this const generic parameter in `ArrayHolder::<X>::new`
34-
LL | pub const fn new() -> Self {
35-
| --- required by a bound in this associated function
32+
LL | struct ArrayHolder<const X: usize>([u32; X]);
33+
| ^^^^^^^^^^^^^^ required by this const generic parameter in `ArrayHolder`
3634
help: consider giving `array` an explicit type, where the value of const parameter `X` is specified
3735
|
3836
LL | let mut array: ArrayHolder<X> = ArrayHolder::new();
@@ -42,13 +40,15 @@ error[E0284]: type annotations needed for `ArrayHolder<_>`
4240
--> $DIR/issue-62504.rs:26:9
4341
|
4442
LL | let mut array = ArrayHolder::new();
45-
| ^^^^^^^^^ ----------- type must be known at this point
43+
| ^^^^^^^^^ ------------------ type must be known at this point
4644
|
47-
note: required by a const generic parameter in `ArrayHolder`
48-
--> $DIR/issue-62504.rs:14:20
45+
note: required by a const generic parameter in `ArrayHolder::<X>::new`
46+
--> $DIR/issue-62504.rs:16:6
4947
|
50-
LL | struct ArrayHolder<const X: usize>([u32; X]);
51-
| ^^^^^^^^^^^^^^ required by this const generic parameter in `ArrayHolder`
48+
LL | impl<const X: usize> ArrayHolder<X> {
49+
| ^^^^^^^^^^^^^^ required by this const generic parameter in `ArrayHolder::<X>::new`
50+
LL | pub const fn new() -> Self {
51+
| --- required by a bound in this associated function
5252
help: consider giving `array` an explicit type, where the value of const parameter `X` is specified
5353
|
5454
LL | let mut array: ArrayHolder<X> = ArrayHolder::new();

Diff for: tests/ui/const-generics/generic_const_exprs/issue-80742.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error: internal compiler error: compiler/rustc_const_eval/src/interpret/operator
44

55
Box<dyn Any>
66
query stack during panic:
7-
#0 [eval_to_allocation_raw] const-evaluating + checking `<impl at $DIR/issue-80742.rs:26:1: 28:32>::{constant#0}`
7+
#0 [eval_to_allocation_raw] const-evaluating + checking `Inline::{constant#0}`
88
#1 [eval_to_valtree] evaluating type-level constant
99
... and 2 other queries... use `env RUST_BACKTRACE=1` to see the full query stack
1010
error: aborting due to 1 previous error

0 commit comments

Comments
 (0)