Skip to content

Commit 5236c8e

Browse files
committed
Auto merge of #116273 - compiler-errors:refine2, r=tmandry
Only trigger `refining_impl_trait` lint on reachable traits Public but unreachable traits don't matter 😸 r? `@tmandry`
2 parents b781645 + 06d9602 commit 5236c8e

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

compiler/rustc_hir_analysis/src/check/compare_impl_item/refine.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,12 @@ pub(super) fn check_refining_return_position_impl_trait_in_trait<'tcx>(
2323
if !tcx.impl_method_has_trait_impl_trait_tys(impl_m.def_id) {
2424
return;
2525
}
26-
// crate-private traits don't have any library guarantees, there's no need to do this check.
27-
if !tcx.visibility(trait_m.container_id(tcx)).is_public() {
26+
// unreachable traits don't have any library guarantees, there's no need to do this check.
27+
if trait_m
28+
.container_id(tcx)
29+
.as_local()
30+
.is_some_and(|trait_def_id| !tcx.effective_visibilities(()).is_reachable(trait_def_id))
31+
{
2832
return;
2933
}
3034

tests/ui/async-await/in-trait/missing-feature-flag.stderr

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

10+
error[E0308]: mismatched types
11+
--> $DIR/missing-feature-flag.rs:16:42
12+
|
13+
LL | async fn foo(_: i32) -> &'static str {}
14+
| ^^ expected `&str`, found `()`
15+
1016
error[E0520]: `foo` specializes an item from a parent `impl`, but that item is not marked `default`
1117
--> $DIR/missing-feature-flag.rs:16:5
1218
|
@@ -18,12 +24,6 @@ LL | async fn foo(_: i32) -> &'static str {}
1824
|
1925
= note: to specialize, `foo` in the parent `impl` must be marked `default`
2026

21-
error[E0308]: mismatched types
22-
--> $DIR/missing-feature-flag.rs:16:42
23-
|
24-
LL | async fn foo(_: i32) -> &'static str {}
25-
| ^^ expected `&str`, found `()`
26-
2727
error: aborting due to 3 previous errors
2828

2929
Some errors have detailed explanations: E0046, E0308, E0520.

tests/ui/impl-trait/in-trait/refine.rs

+11
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,15 @@ impl Late for D {
4545
//~^ ERROR impl method signature does not match trait method signature
4646
}
4747

48+
mod unreachable {
49+
pub trait UnreachablePub {
50+
fn bar() -> impl Sized;
51+
}
52+
53+
struct E;
54+
impl UnreachablePub for E {
55+
fn bar() {}
56+
}
57+
}
58+
4859
fn main() {}

0 commit comments

Comments
 (0)