Skip to content

Commit f0f182d

Browse files
xizheyincuviper
authored andcommitted
Do not use effective_visibilities query for Adt types of a local trait while proving a where-clause
Signed-off-by: xizheyin <[email protected]> (cherry picked from commit 27e6726)
1 parent fd942a5 commit f0f182d

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2876,7 +2876,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
28762876
// we check if `TraitB` can be reachable from `S`
28772877
// to determine whether to note `TraitA` is sealed trait.
28782878
if let ty::Adt(adt, _) = ty.kind() {
2879-
let visibilities = tcx.effective_visibilities(());
2879+
let visibilities = &tcx.resolutions(()).effective_visibilities;
28802880
visibilities.effective_vis(local).is_none_or(|v| {
28812881
v.at_level(Level::Reexported)
28822882
.is_accessible_from(adt.did(), tcx)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// This test is for regression of issue #145611
2+
// There should not be cycle error in effective_visibilities query.
3+
4+
trait LocalTrait {}
5+
struct SomeType;
6+
fn impls_trait<T: LocalTrait>() {}
7+
fn foo() -> impl Sized {
8+
impls_trait::<SomeType>(); //~ ERROR the trait bound `SomeType: LocalTrait` is not satisfied [E0277]
9+
}
10+
11+
fn main() {}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
error[E0277]: the trait bound `SomeType: LocalTrait` is not satisfied
2+
--> $DIR/trait-bound-adt-issue-145611.rs:8:19
3+
|
4+
LL | impls_trait::<SomeType>();
5+
| ^^^^^^^^ the trait `LocalTrait` is not implemented for `SomeType`
6+
|
7+
help: this trait has no implementations, consider adding one
8+
--> $DIR/trait-bound-adt-issue-145611.rs:4:1
9+
|
10+
LL | trait LocalTrait {}
11+
| ^^^^^^^^^^^^^^^^
12+
note: required by a bound in `impls_trait`
13+
--> $DIR/trait-bound-adt-issue-145611.rs:6:19
14+
|
15+
LL | fn impls_trait<T: LocalTrait>() {}
16+
| ^^^^^^^^^^ required by this bound in `impls_trait`
17+
18+
error: aborting due to 1 previous error
19+
20+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)