Skip to content

Commit 885fecd

Browse files
committed
Do not use effective_visibilities query for Adt types of a local trait while proving a where-clause
Signed-off-by: xizheyin <[email protected]>
1 parent 425a9c0 commit 885fecd

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-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
@@ -2878,7 +2878,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
28782878
// we check if `TraitB` can be reachable from `S`
28792879
// to determine whether to note `TraitA` is sealed trait.
28802880
if let ty::Adt(adt, _) = ty.kind() {
2881-
let visibilities = tcx.effective_visibilities(());
2881+
let visibilities = &tcx.resolutions(()).effective_visibilities;
28822882
visibilities.effective_vis(local).is_none_or(|v| {
28832883
v.at_level(Level::Reexported)
28842884
.is_accessible_from(adt.did(), tcx)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
trait LocalTrait {}
2+
struct SomeType;
3+
fn impls_trait<T: LocalTrait>() {}
4+
fn foo() -> impl Sized {
5+
impls_trait::<SomeType>(); //~ ERROR the trait bound `SomeType: LocalTrait` is not satisfied [E0277]
6+
}
7+
8+
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:5: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:1:1
9+
|
10+
LL | trait LocalTrait {}
11+
| ^^^^^^^^^^^^^^^^
12+
note: required by a bound in `impls_trait`
13+
--> $DIR/trait-bound-adt-issue-145611.rs:3: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)