Skip to content

Commit 7b0e962

Browse files
Tests, suppress refine lint when errors
1 parent 9b53b64 commit 7b0e962

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ use rustc_lint_defs::builtin::{REFINING_IMPL_TRAIT_INTERNAL, REFINING_IMPL_TRAIT
66
use rustc_middle::span_bug;
77
use rustc_middle::traits::{ObligationCause, Reveal};
88
use rustc_middle::ty::{
9-
self, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperVisitable, TypeVisitable, TypeVisitor,
9+
self, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperVisitable, TypeVisitable,
10+
TypeVisitableExt, TypeVisitor,
1011
};
1112
use rustc_span::Span;
1213
use rustc_trait_selection::regions::InferCtxtRegionExt;
@@ -63,6 +64,10 @@ pub(super) fn check_refining_return_position_impl_trait_in_trait<'tcx>(
6364
return;
6465
};
6566

67+
if hidden_tys.items().any(|(_, &ty)| ty.skip_binder().references_error()) {
68+
return;
69+
}
70+
6671
let mut collector = ImplTraitInTraitCollector { tcx, types: FxIndexSet::default() };
6772
trait_m_sig.visit_with(&mut collector);
6873

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#![feature(precise_capturing)]
2+
3+
struct Invariant<'a>(&'a mut &'a mut ());
4+
5+
trait Trait {
6+
fn hello(self_: Invariant<'_>) -> impl Sized + use<Self>;
7+
}
8+
9+
impl Trait for () {
10+
fn hello(self_: Invariant<'_>) -> impl Sized + use<'_> {}
11+
//~^ return type captures more lifetimes than trait definition
12+
}
13+
14+
fn main() {}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error: return type captures more lifetimes than trait definition
2+
--> $DIR/rpitit-impl-captures-too-much.rs:10:39
3+
|
4+
LL | fn hello(self_: Invariant<'_>) -> impl Sized + use<'_> {}
5+
| -- ^^^^^^^^^^^^^^^^^^^^
6+
| |
7+
| this lifetime was captured
8+
|
9+
note: hidden type must only reference lifetimes captured by this impl trait
10+
--> $DIR/rpitit-impl-captures-too-much.rs:6:39
11+
|
12+
LL | fn hello(self_: Invariant<'_>) -> impl Sized + use<Self>;
13+
| ^^^^^^^^^^^^^^^^^^^^^^
14+
= note: hidden type inferred to be `impl Sized`
15+
16+
error: aborting due to 1 previous error
17+

0 commit comments

Comments
 (0)