Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only trigger refining_impl_trait lint on reachable traits #116273

Merged
merged 1 commit into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@ pub(super) fn check_refining_return_position_impl_trait_in_trait<'tcx>(
if !tcx.impl_method_has_trait_impl_trait_tys(impl_m.def_id) {
return;
}
// crate-private traits don't have any library guarantees, there's no need to do this check.
if !tcx.visibility(trait_m.container_id(tcx)).is_public() {
// unreachable traits don't have any library guarantees, there's no need to do this check.
if trait_m
.container_id(tcx)
.as_local()
.is_some_and(|trait_def_id| !tcx.effective_visibilities(()).is_reachable(trait_def_id))
{
return;
}

Expand Down
12 changes: 6 additions & 6 deletions tests/ui/async-await/in-trait/missing-feature-flag.stderr
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's up with this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is due to the fact that we call effective_visibilities rather than visibility -- this calls type_of on opaques since visibility computation requires knowing what the hidden type of the opaque is, which requires calling typeck on all of the bodies in-scope. This bubbles up the type error.

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ LL | async fn foo(_: T) -> &'static str;
LL | impl<T> MyTrait<T> for MyStruct {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `foo` in implementation

error[E0308]: mismatched types
--> $DIR/missing-feature-flag.rs:16:42
|
LL | async fn foo(_: i32) -> &'static str {}
| ^^ expected `&str`, found `()`

error[E0520]: `foo` specializes an item from a parent `impl`, but that item is not marked `default`
--> $DIR/missing-feature-flag.rs:16:5
|
Expand All @@ -18,12 +24,6 @@ LL | async fn foo(_: i32) -> &'static str {}
|
= note: to specialize, `foo` in the parent `impl` must be marked `default`

error[E0308]: mismatched types
--> $DIR/missing-feature-flag.rs:16:42
|
LL | async fn foo(_: i32) -> &'static str {}
| ^^ expected `&str`, found `()`

error: aborting due to 3 previous errors

Some errors have detailed explanations: E0046, E0308, E0520.
Expand Down
11 changes: 11 additions & 0 deletions tests/ui/impl-trait/in-trait/refine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,15 @@ impl Late for D {
//~^ ERROR impl method signature does not match trait method signature
}

mod unreachable {
pub trait UnreachablePub {
fn bar() -> impl Sized;
}

struct E;
impl UnreachablePub for E {
fn bar() {}
}
}

fn main() {}
Loading