Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit cdd93fd

Browse files
authoredFeb 17, 2021
Rollup merge of #81972 - matthewjasper:hrtb-error-cleanup, r=nikomatsakis
Placeholder lifetime error cleanup - Remove note of trait definition - Avoid repeating the same self type - Use original region names when possible - Use this error kind more often - Print closure signatures when they are suppose to implement `Fn*` traits Works towards #57374 r? ```@nikomatsakis```
2 parents f79be2c + f852160 commit cdd93fd

34 files changed

+283
-451
lines changed
 

‎compiler/rustc_infer/src/infer/error_reporting/nice_region_error/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ impl<'cx, 'tcx> NiceRegionError<'cx, 'tcx> {
4343
self.infcx.tcx
4444
}
4545

46-
pub fn try_report_from_nll(&self) -> Option<DiagnosticBuilder<'cx>> {
46+
pub fn try_report_from_nll(&self) -> Option<DiagnosticBuilder<'tcx>> {
4747
// Due to the improved diagnostics returned by the MIR borrow checker, only a subset of
4848
// the nice region errors are required when running under the MIR borrow checker.
4949
self.try_report_named_anon_conflict().or_else(|| self.try_report_placeholder_conflict())

‎compiler/rustc_infer/src/infer/error_reporting/nice_region_error/named_anon_conflict.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_middle::ty;
99
impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
1010
/// When given a `ConcreteFailure` for a function with parameters containing a named region and
1111
/// an anonymous region, emit an descriptive diagnostic error.
12-
pub(super) fn try_report_named_anon_conflict(&self) -> Option<DiagnosticBuilder<'a>> {
12+
pub(super) fn try_report_named_anon_conflict(&self) -> Option<DiagnosticBuilder<'tcx>> {
1313
let (span, sub, sup) = self.regions()?;
1414

1515
debug!(

‎compiler/rustc_infer/src/infer/error_reporting/nice_region_error/placeholder_error.rs

Lines changed: 126 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use std::fmt::{self, Write};
1616
impl NiceRegionError<'me, 'tcx> {
1717
/// When given a `ConcreteFailure` for a function with arguments containing a named region and
1818
/// an anonymous region, emit a descriptive diagnostic error.
19-
pub(super) fn try_report_placeholder_conflict(&self) -> Option<DiagnosticBuilder<'me>> {
19+
pub(super) fn try_report_placeholder_conflict(&self) -> Option<DiagnosticBuilder<'tcx>> {
2020
match &self.error {
2121
///////////////////////////////////////////////////////////////////////////
2222
// NB. The ordering of cases in this match is very
@@ -30,157 +30,153 @@ impl NiceRegionError<'me, 'tcx> {
3030
Some(RegionResolutionError::SubSupConflict(
3131
vid,
3232
_,
33-
SubregionOrigin::Subtype(box TypeTrace {
34-
cause,
35-
values: ValuePairs::TraitRefs(ExpectedFound { expected, found }),
36-
}),
33+
SubregionOrigin::Subtype(box TypeTrace { cause, values }),
3734
sub_placeholder @ ty::RePlaceholder(_),
3835
_,
3936
sup_placeholder @ ty::RePlaceholder(_),
40-
)) if expected.def_id == found.def_id => Some(self.try_report_placeholders_trait(
37+
)) => self.try_report_trait_placeholder_mismatch(
4138
Some(self.tcx().mk_region(ty::ReVar(*vid))),
4239
cause,
4340
Some(sub_placeholder),
4441
Some(sup_placeholder),
45-
expected.def_id,
46-
expected.substs,
47-
found.substs,
48-
)),
42+
values,
43+
),
4944

5045
Some(RegionResolutionError::SubSupConflict(
5146
vid,
5247
_,
53-
SubregionOrigin::Subtype(box TypeTrace {
54-
cause,
55-
values: ValuePairs::TraitRefs(ExpectedFound { expected, found }),
56-
}),
48+
SubregionOrigin::Subtype(box TypeTrace { cause, values }),
5749
sub_placeholder @ ty::RePlaceholder(_),
5850
_,
5951
_,
60-
)) if expected.def_id == found.def_id => Some(self.try_report_placeholders_trait(
52+
)) => self.try_report_trait_placeholder_mismatch(
6153
Some(self.tcx().mk_region(ty::ReVar(*vid))),
6254
cause,
6355
Some(sub_placeholder),
6456
None,
65-
expected.def_id,
66-
expected.substs,
67-
found.substs,
68-
)),
57+
values,
58+
),
6959

7060
Some(RegionResolutionError::SubSupConflict(
7161
vid,
7262
_,
73-
SubregionOrigin::Subtype(box TypeTrace {
74-
cause,
75-
values: ValuePairs::TraitRefs(ExpectedFound { expected, found }),
76-
}),
63+
SubregionOrigin::Subtype(box TypeTrace { cause, values }),
7764
_,
7865
_,
7966
sup_placeholder @ ty::RePlaceholder(_),
80-
)) if expected.def_id == found.def_id => Some(self.try_report_placeholders_trait(
67+
)) => self.try_report_trait_placeholder_mismatch(
8168
Some(self.tcx().mk_region(ty::ReVar(*vid))),
8269
cause,
8370
None,
8471
Some(*sup_placeholder),
85-
expected.def_id,
86-
expected.substs,
87-
found.substs,
88-
)),
72+
values,
73+
),
8974

9075
Some(RegionResolutionError::SubSupConflict(
9176
vid,
9277
_,
9378
_,
9479
_,
95-
SubregionOrigin::Subtype(box TypeTrace {
96-
cause,
97-
values: ValuePairs::TraitRefs(ExpectedFound { expected, found }),
98-
}),
80+
SubregionOrigin::Subtype(box TypeTrace { cause, values }),
9981
sup_placeholder @ ty::RePlaceholder(_),
100-
)) if expected.def_id == found.def_id => Some(self.try_report_placeholders_trait(
82+
)) => self.try_report_trait_placeholder_mismatch(
10183
Some(self.tcx().mk_region(ty::ReVar(*vid))),
10284
cause,
10385
None,
10486
Some(*sup_placeholder),
105-
expected.def_id,
106-
expected.substs,
107-
found.substs,
108-
)),
87+
values,
88+
),
10989

11090
Some(RegionResolutionError::UpperBoundUniverseConflict(
11191
vid,
11292
_,
11393
_,
114-
SubregionOrigin::Subtype(box TypeTrace {
115-
cause,
116-
values: ValuePairs::TraitRefs(ExpectedFound { expected, found }),
117-
}),
94+
SubregionOrigin::Subtype(box TypeTrace { cause, values }),
11895
sup_placeholder @ ty::RePlaceholder(_),
119-
)) if expected.def_id == found.def_id => Some(self.try_report_placeholders_trait(
96+
)) => self.try_report_trait_placeholder_mismatch(
12097
Some(self.tcx().mk_region(ty::ReVar(*vid))),
12198
cause,
12299
None,
123100
Some(*sup_placeholder),
124-
expected.def_id,
125-
expected.substs,
126-
found.substs,
127-
)),
101+
values,
102+
),
128103

129104
Some(RegionResolutionError::ConcreteFailure(
130-
SubregionOrigin::Subtype(box TypeTrace {
131-
cause,
132-
values: ValuePairs::TraitRefs(ExpectedFound { expected, found }),
133-
}),
105+
SubregionOrigin::Subtype(box TypeTrace { cause, values }),
134106
sub_region @ ty::RePlaceholder(_),
135107
sup_region @ ty::RePlaceholder(_),
136-
)) if expected.def_id == found.def_id => Some(self.try_report_placeholders_trait(
108+
)) => self.try_report_trait_placeholder_mismatch(
137109
None,
138110
cause,
139111
Some(*sub_region),
140112
Some(*sup_region),
141-
expected.def_id,
142-
expected.substs,
143-
found.substs,
144-
)),
113+
values,
114+
),
145115

146116
Some(RegionResolutionError::ConcreteFailure(
147-
SubregionOrigin::Subtype(box TypeTrace {
148-
cause,
149-
values: ValuePairs::TraitRefs(ExpectedFound { expected, found }),
150-
}),
117+
SubregionOrigin::Subtype(box TypeTrace { cause, values }),
151118
sub_region @ ty::RePlaceholder(_),
152119
sup_region,
153-
)) if expected.def_id == found.def_id => Some(self.try_report_placeholders_trait(
154-
Some(sup_region),
120+
)) => self.try_report_trait_placeholder_mismatch(
121+
(!sup_region.has_name()).then_some(sup_region),
155122
cause,
156-
Some(*sub_region),
123+
Some(sub_region),
157124
None,
158-
expected.def_id,
159-
expected.substs,
160-
found.substs,
161-
)),
125+
values,
126+
),
162127

163128
Some(RegionResolutionError::ConcreteFailure(
164-
SubregionOrigin::Subtype(box TypeTrace {
165-
cause,
166-
values: ValuePairs::TraitRefs(ExpectedFound { expected, found }),
167-
}),
129+
SubregionOrigin::Subtype(box TypeTrace { cause, values }),
168130
sub_region,
169131
sup_region @ ty::RePlaceholder(_),
170-
)) if expected.def_id == found.def_id => Some(self.try_report_placeholders_trait(
171-
Some(sub_region),
132+
)) => self.try_report_trait_placeholder_mismatch(
133+
(!sub_region.has_name()).then_some(sub_region),
172134
cause,
173135
None,
174-
Some(*sup_region),
175-
expected.def_id,
176-
expected.substs,
177-
found.substs,
178-
)),
136+
Some(sup_region),
137+
values,
138+
),
179139

180140
_ => None,
181141
}
182142
}
183143

144+
fn try_report_trait_placeholder_mismatch(
145+
&self,
146+
vid: Option<ty::Region<'tcx>>,
147+
cause: &ObligationCause<'tcx>,
148+
sub_placeholder: Option<ty::Region<'tcx>>,
149+
sup_placeholder: Option<ty::Region<'tcx>>,
150+
value_pairs: &ValuePairs<'tcx>,
151+
) -> Option<DiagnosticBuilder<'tcx>> {
152+
let (expected_substs, found_substs, trait_def_id) = match value_pairs {
153+
ValuePairs::TraitRefs(ExpectedFound { expected, found })
154+
if expected.def_id == found.def_id =>
155+
{
156+
(expected.substs, found.substs, expected.def_id)
157+
}
158+
ValuePairs::PolyTraitRefs(ExpectedFound { expected, found })
159+
if expected.def_id() == found.def_id() =>
160+
{
161+
// It's possible that the placeholders come from a binder
162+
// outside of this value pair. Use `no_bound_vars` as a
163+
// simple heuristic for that.
164+
(expected.no_bound_vars()?.substs, found.no_bound_vars()?.substs, expected.def_id())
165+
}
166+
_ => return None,
167+
};
168+
169+
Some(self.report_trait_placeholder_mismatch(
170+
vid,
171+
cause,
172+
sub_placeholder,
173+
sup_placeholder,
174+
trait_def_id,
175+
expected_substs,
176+
found_substs,
177+
))
178+
}
179+
184180
// error[E0308]: implementation of `Foo` does not apply to enough lifetimes
185181
// --> /home/nmatsakis/tmp/foo.rs:12:5
186182
// |
@@ -190,7 +186,8 @@ impl NiceRegionError<'me, 'tcx> {
190186
// = note: Due to a where-clause on the function `all`,
191187
// = note: `T` must implement `...` for any two lifetimes `'1` and `'2`.
192188
// = note: However, the type `T` only implements `...` for some specific lifetime `'2`.
193-
fn try_report_placeholders_trait(
189+
#[instrument(level = "debug", skip(self))]
190+
fn report_trait_placeholder_mismatch(
194191
&self,
195192
vid: Option<ty::Region<'tcx>>,
196193
cause: &ObligationCause<'tcx>,
@@ -199,28 +196,13 @@ impl NiceRegionError<'me, 'tcx> {
199196
trait_def_id: DefId,
200197
expected_substs: SubstsRef<'tcx>,
201198
actual_substs: SubstsRef<'tcx>,
202-
) -> DiagnosticBuilder<'me> {
203-
debug!(
204-
"try_report_placeholders_trait(\
205-
vid={:?}, \
206-
sub_placeholder={:?}, \
207-
sup_placeholder={:?}, \
208-
trait_def_id={:?}, \
209-
expected_substs={:?}, \
210-
actual_substs={:?})",
211-
vid, sub_placeholder, sup_placeholder, trait_def_id, expected_substs, actual_substs
212-
);
213-
199+
) -> DiagnosticBuilder<'tcx> {
214200
let span = cause.span(self.tcx());
215201
let msg = format!(
216202
"implementation of `{}` is not general enough",
217203
self.tcx().def_path_str(trait_def_id),
218204
);
219205
let mut err = self.tcx().sess.struct_span_err(span, &msg);
220-
err.span_label(
221-
self.tcx().def_span(trait_def_id),
222-
format!("trait `{}` defined here", self.tcx().def_path_str(trait_def_id)),
223-
);
224206

225207
let leading_ellipsis = if let ObligationCauseCode::ItemObligation(def_id) = cause.code {
226208
err.span_label(span, "doesn't satisfy where-clause");
@@ -285,17 +267,13 @@ impl NiceRegionError<'me, 'tcx> {
285267

286268
let any_self_ty_has_vid = actual_self_ty_has_vid || expected_self_ty_has_vid;
287269

288-
debug!("try_report_placeholders_trait: actual_has_vid={:?}", actual_has_vid);
289-
debug!("try_report_placeholders_trait: expected_has_vid={:?}", expected_has_vid);
290-
debug!("try_report_placeholders_trait: has_sub={:?}", has_sub);
291-
debug!("try_report_placeholders_trait: has_sup={:?}", has_sup);
292270
debug!(
293-
"try_report_placeholders_trait: actual_self_ty_has_vid={:?}",
294-
actual_self_ty_has_vid
295-
);
296-
debug!(
297-
"try_report_placeholders_trait: expected_self_ty_has_vid={:?}",
298-
expected_self_ty_has_vid
271+
?actual_has_vid,
272+
?expected_has_vid,
273+
?has_sub,
274+
?has_sup,
275+
?actual_self_ty_has_vid,
276+
?expected_self_ty_has_vid,
299277
);
300278

301279
self.explain_actual_impl_that_was_found(
@@ -388,6 +366,8 @@ impl NiceRegionError<'me, 'tcx> {
388366
value: trait_ref,
389367
};
390368

369+
let same_self_type = actual_trait_ref.self_ty() == expected_trait_ref.self_ty();
370+
391371
let mut expected_trait_ref = highlight_trait_ref(expected_trait_ref);
392372
expected_trait_ref.highlight.maybe_highlighting_region(sub_placeholder, has_sub);
393373
expected_trait_ref.highlight.maybe_highlighting_region(sup_placeholder, has_sup);
@@ -403,7 +383,42 @@ impl NiceRegionError<'me, 'tcx> {
403383
}
404384
};
405385

406-
let mut note = if passive_voice {
386+
let mut note = if same_self_type {
387+
let mut self_ty = expected_trait_ref.map(|tr| tr.self_ty());
388+
self_ty.highlight.maybe_highlighting_region(vid, actual_has_vid);
389+
390+
if self_ty.value.is_closure()
391+
&& self
392+
.tcx()
393+
.fn_trait_kind_from_lang_item(expected_trait_ref.value.def_id)
394+
.is_some()
395+
{
396+
let closure_sig = self_ty.map(|closure| {
397+
if let ty::Closure(_, substs) = closure.kind() {
398+
self.tcx().signature_unclosure(
399+
substs.as_closure().sig(),
400+
rustc_hir::Unsafety::Normal,
401+
)
402+
} else {
403+
bug!("type is not longer closure");
404+
}
405+
});
406+
407+
format!(
408+
"{}closure with signature `{}` must implement `{}`",
409+
if leading_ellipsis { "..." } else { "" },
410+
closure_sig,
411+
expected_trait_ref.map(|tr| tr.print_only_trait_path()),
412+
)
413+
} else {
414+
format!(
415+
"{}`{}` must implement `{}`",
416+
if leading_ellipsis { "..." } else { "" },
417+
self_ty,
418+
expected_trait_ref.map(|tr| tr.print_only_trait_path()),
419+
)
420+
}
421+
} else if passive_voice {
407422
format!(
408423
"{}`{}` would have to be implemented for the type `{}`",
409424
if leading_ellipsis { "..." } else { "" },
@@ -449,7 +464,12 @@ impl NiceRegionError<'me, 'tcx> {
449464
None => true,
450465
};
451466

452-
let mut note = if passive_voice {
467+
let mut note = if same_self_type {
468+
format!(
469+
"...but it actually implements `{}`",
470+
actual_trait_ref.map(|tr| tr.print_only_trait_path()),
471+
)
472+
} else if passive_voice {
453473
format!(
454474
"...but `{}` is actually implemented for the type `{}`",
455475
actual_trait_ref.map(|tr| tr.print_only_trait_path()),

‎src/test/ui/associated-types/associated-types-eq-hr.stderr

Lines changed: 15 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -31,82 +31,47 @@ LL | bar::<IntStruct>();
3131
error: implementation of `TheTrait` is not general enough
3232
--> $DIR/associated-types-eq-hr.rs:96:5
3333
|
34-
LL | / pub trait TheTrait<T> {
35-
LL | | type A;
36-
LL | |
37-
LL | | fn get(&self, t: T) -> Self::A;
38-
LL | | }
39-
| |_- trait `TheTrait` defined here
40-
...
41-
LL | tuple_one::<Tuple>();
42-
| ^^^^^^^^^^^^^^^^^^ implementation of `TheTrait` is not general enough
34+
LL | tuple_one::<Tuple>();
35+
| ^^^^^^^^^^^^^^^^^^ implementation of `TheTrait` is not general enough
4336
|
4437
= note: `Tuple` must implement `TheTrait<(&'0 isize, &'1 isize)>`, for any two lifetimes `'0` and `'1`...
45-
= note: ...but `Tuple` actually implements `TheTrait<(&'2 isize, &'2 isize)>`, for some specific lifetime `'2`
38+
= note: ...but it actually implements `TheTrait<(&'2 isize, &'2 isize)>`, for some specific lifetime `'2`
4639

4740
error: implementation of `TheTrait` is not general enough
4841
--> $DIR/associated-types-eq-hr.rs:96:5
4942
|
50-
LL | / pub trait TheTrait<T> {
51-
LL | | type A;
52-
LL | |
53-
LL | | fn get(&self, t: T) -> Self::A;
54-
LL | | }
55-
| |_- trait `TheTrait` defined here
56-
...
57-
LL | tuple_one::<Tuple>();
58-
| ^^^^^^^^^^^^^^^^^^ implementation of `TheTrait` is not general enough
43+
LL | tuple_one::<Tuple>();
44+
| ^^^^^^^^^^^^^^^^^^ implementation of `TheTrait` is not general enough
5945
|
6046
= note: `Tuple` must implement `TheTrait<(&'0 isize, &'1 isize)>`, for any two lifetimes `'0` and `'1`...
61-
= note: ...but `Tuple` actually implements `TheTrait<(&'2 isize, &'2 isize)>`, for some specific lifetime `'2`
47+
= note: ...but it actually implements `TheTrait<(&'2 isize, &'2 isize)>`, for some specific lifetime `'2`
6248

6349
error: implementation of `TheTrait` is not general enough
6450
--> $DIR/associated-types-eq-hr.rs:102:5
6551
|
66-
LL | / pub trait TheTrait<T> {
67-
LL | | type A;
68-
LL | |
69-
LL | | fn get(&self, t: T) -> Self::A;
70-
LL | | }
71-
| |_- trait `TheTrait` defined here
72-
...
73-
LL | tuple_two::<Tuple>();
74-
| ^^^^^^^^^^^^^^^^^^ implementation of `TheTrait` is not general enough
52+
LL | tuple_two::<Tuple>();
53+
| ^^^^^^^^^^^^^^^^^^ implementation of `TheTrait` is not general enough
7554
|
7655
= note: `Tuple` must implement `TheTrait<(&'0 isize, &'1 isize)>`, for any two lifetimes `'0` and `'1`...
77-
= note: ...but `Tuple` actually implements `TheTrait<(&'2 isize, &'2 isize)>`, for some specific lifetime `'2`
56+
= note: ...but it actually implements `TheTrait<(&'2 isize, &'2 isize)>`, for some specific lifetime `'2`
7857

7958
error: implementation of `TheTrait` is not general enough
8059
--> $DIR/associated-types-eq-hr.rs:102:5
8160
|
82-
LL | / pub trait TheTrait<T> {
83-
LL | | type A;
84-
LL | |
85-
LL | | fn get(&self, t: T) -> Self::A;
86-
LL | | }
87-
| |_- trait `TheTrait` defined here
88-
...
89-
LL | tuple_two::<Tuple>();
90-
| ^^^^^^^^^^^^^^^^^^ implementation of `TheTrait` is not general enough
61+
LL | tuple_two::<Tuple>();
62+
| ^^^^^^^^^^^^^^^^^^ implementation of `TheTrait` is not general enough
9163
|
9264
= note: `Tuple` must implement `TheTrait<(&'0 isize, &'1 isize)>`, for any two lifetimes `'0` and `'1`...
93-
= note: ...but `Tuple` actually implements `TheTrait<(&'2 isize, &'2 isize)>`, for some specific lifetime `'2`
65+
= note: ...but it actually implements `TheTrait<(&'2 isize, &'2 isize)>`, for some specific lifetime `'2`
9466

9567
error: implementation of `TheTrait` is not general enough
9668
--> $DIR/associated-types-eq-hr.rs:112:5
9769
|
98-
LL | / pub trait TheTrait<T> {
99-
LL | | type A;
100-
LL | |
101-
LL | | fn get(&self, t: T) -> Self::A;
102-
LL | | }
103-
| |_- trait `TheTrait` defined here
104-
...
105-
LL | tuple_four::<Tuple>();
106-
| ^^^^^^^^^^^^^^^^^^^ implementation of `TheTrait` is not general enough
70+
LL | tuple_four::<Tuple>();
71+
| ^^^^^^^^^^^^^^^^^^^ implementation of `TheTrait` is not general enough
10772
|
10873
= note: `Tuple` must implement `TheTrait<(&'0 isize, &'1 isize)>`, for any two lifetimes `'0` and `'1`...
109-
= note: ...but `Tuple` actually implements `TheTrait<(&'2 isize, &'2 isize)>`, for some specific lifetime `'2`
74+
= note: ...but it actually implements `TheTrait<(&'2 isize, &'2 isize)>`, for some specific lifetime `'2`
11075

11176
error: aborting due to 7 previous errors
11277

‎src/test/ui/generator/auto-trait-regions.stderr

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,24 @@
11
error: implementation of `Foo` is not general enough
22
--> $DIR/auto-trait-regions.rs:31:5
33
|
4-
LL | auto trait Foo {}
5-
| ----------------- trait `Foo` defined here
6-
...
74
LL | assert_foo(gen);
85
| ^^^^^^^^^^ implementation of `Foo` is not general enough
96
|
10-
= note: `Foo` would have to be implemented for the type `&'0 OnlyFooIfStaticRef`, for any lifetime `'0`...
11-
= note: ...but `Foo` is actually implemented for the type `&'1 OnlyFooIfStaticRef`, for some specific lifetime `'1`
7+
= note: `&'0 OnlyFooIfStaticRef` must implement `Foo`, for any lifetime `'0`...
8+
= note: ...but `Foo` is actually implemented for the type `&'static OnlyFooIfStaticRef`
129

1310
error: implementation of `Foo` is not general enough
1411
--> $DIR/auto-trait-regions.rs:31:5
1512
|
16-
LL | auto trait Foo {}
17-
| ----------------- trait `Foo` defined here
18-
...
1913
LL | assert_foo(gen);
2014
| ^^^^^^^^^^ implementation of `Foo` is not general enough
2115
|
22-
= note: `Foo` would have to be implemented for the type `&'0 OnlyFooIfStaticRef`, for any lifetime `'0`...
23-
= note: ...but `Foo` is actually implemented for the type `&'1 OnlyFooIfStaticRef`, for some specific lifetime `'1`
16+
= note: `&'0 OnlyFooIfStaticRef` must implement `Foo`, for any lifetime `'0`...
17+
= note: ...but `Foo` is actually implemented for the type `&'static OnlyFooIfStaticRef`
2418

2519
error: implementation of `Foo` is not general enough
2620
--> $DIR/auto-trait-regions.rs:50:5
2721
|
28-
LL | auto trait Foo {}
29-
| ----------------- trait `Foo` defined here
30-
...
3122
LL | assert_foo(gen);
3223
| ^^^^^^^^^^ implementation of `Foo` is not general enough
3324
|
@@ -37,9 +28,6 @@ LL | assert_foo(gen);
3728
error: implementation of `Foo` is not general enough
3829
--> $DIR/auto-trait-regions.rs:50:5
3930
|
40-
LL | auto trait Foo {}
41-
| ----------------- trait `Foo` defined here
42-
...
4331
LL | assert_foo(gen);
4432
| ^^^^^^^^^^ implementation of `Foo` is not general enough
4533
|

‎src/test/ui/hrtb/due-to-where-clause.stderr

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ error: implementation of `Foo` is not general enough
33
|
44
LL | test::<FooS>(&mut 42);
55
| ^^^^^^^^^^^^ implementation of `Foo` is not general enough
6-
...
7-
LL | trait Foo<'a> {}
8-
| ---------------- trait `Foo` defined here
96
|
107
= note: `FooS<'_>` must implement `Foo<'0>`, for any lifetime `'0`...
118
= note: ...but `FooS<'_>` actually implements `Foo<'1>`, for some specific lifetime `'1`

‎src/test/ui/hrtb/hrtb-cache-issue-54302.stderr

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
error: implementation of `Deserialize` is not general enough
22
--> $DIR/hrtb-cache-issue-54302.rs:19:5
33
|
4-
LL | trait Deserialize<'de> {}
5-
| ------------------------- trait `Deserialize` defined here
6-
...
74
LL | assert_deserialize_owned::<&'static str>();
85
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ implementation of `Deserialize` is not general enough
96
|
Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
11
error: implementation of `Foo` is not general enough
22
--> $DIR/hrtb-conflate-regions.rs:27:10
33
|
4-
LL | / trait Foo<X> {
5-
LL | | fn foo(&self, x: X) { }
6-
LL | | }
7-
| |_- trait `Foo` defined here
8-
...
9-
LL | fn b() { want_foo2::<SomeStruct>(); }
10-
| ^^^^^^^^^^^^^^^^^^^^^^^ implementation of `Foo` is not general enough
4+
LL | fn b() { want_foo2::<SomeStruct>(); }
5+
| ^^^^^^^^^^^^^^^^^^^^^^^ implementation of `Foo` is not general enough
116
|
127
= note: `SomeStruct` must implement `Foo<(&'0 isize, &'1 isize)>`, for any two lifetimes `'0` and `'1`...
13-
= note: ...but `SomeStruct` actually implements `Foo<(&'2 isize, &'2 isize)>`, for some specific lifetime `'2`
8+
= note: ...but it actually implements `Foo<(&'2 isize, &'2 isize)>`, for some specific lifetime `'2`
149

1510
error: aborting due to previous error
1611

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
error: implementation of `Trait` is not general enough
22
--> $DIR/hrtb-exists-forall-trait-contravariant.rs:34:5
33
|
4-
LL | trait Trait<T> {}
5-
| ----------------- trait `Trait` defined here
6-
...
74
LL | foo::<()>();
85
| ^^^^^^^^^ implementation of `Trait` is not general enough
96
|
107
= note: `()` must implement `Trait<for<'b> fn(&'b u32)>`
11-
= note: ...but `()` actually implements `Trait<fn(&'0 u32)>`, for some specific lifetime `'0`
8+
= note: ...but it actually implements `Trait<fn(&'0 u32)>`, for some specific lifetime `'0`
129

1310
error: aborting due to previous error
1411

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
error: implementation of `Trait` is not general enough
22
--> $DIR/hrtb-exists-forall-trait-invariant.rs:28:5
33
|
4-
LL | trait Trait<T> {}
5-
| ----------------- trait `Trait` defined here
6-
...
74
LL | foo::<()>();
85
| ^^^^^^^^^ implementation of `Trait` is not general enough
96
|
107
= note: `()` must implement `Trait<for<'b> fn(Cell<&'b u32>)>`
11-
= note: ...but `()` actually implements `Trait<fn(Cell<&'0 u32>)>`, for some specific lifetime `'0`
8+
= note: ...but it actually implements `Trait<fn(Cell<&'0 u32>)>`, for some specific lifetime `'0`
129

1310
error: aborting due to previous error
1411

‎src/test/ui/hrtb/hrtb-just-for-static.stderr

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,17 @@
11
error: implementation of `Foo` is not general enough
22
--> $DIR/hrtb-just-for-static.rs:24:5
33
|
4-
LL | / trait Foo<X> {
5-
LL | | fn foo(&self, x: X) { }
6-
LL | | }
7-
| |_- trait `Foo` defined here
8-
...
9-
LL | want_hrtb::<StaticInt>()
10-
| ^^^^^^^^^^^^^^^^^^^^^^ implementation of `Foo` is not general enough
4+
LL | want_hrtb::<StaticInt>()
5+
| ^^^^^^^^^^^^^^^^^^^^^^ implementation of `Foo` is not general enough
116
|
127
= note: `StaticInt` must implement `Foo<&'0 isize>`, for any lifetime `'0`...
13-
= note: ...but `StaticInt` actually implements `Foo<&'1 isize>`, for some specific lifetime `'1`
8+
= note: ...but it actually implements `Foo<&'static isize>`
149

1510
error: implementation of `Foo` is not general enough
1611
--> $DIR/hrtb-just-for-static.rs:30:5
1712
|
18-
LL | / trait Foo<X> {
19-
LL | | fn foo(&self, x: X) { }
20-
LL | | }
21-
| |_- trait `Foo` defined here
22-
...
23-
LL | want_hrtb::<&'a u32>()
24-
| ^^^^^^^^^^^^^^^^^^^^ implementation of `Foo` is not general enough
13+
LL | want_hrtb::<&'a u32>()
14+
| ^^^^^^^^^^^^^^^^^^^^ implementation of `Foo` is not general enough
2515
|
2616
= note: `Foo<&'0 isize>` would have to be implemented for the type `&'a u32`, for any lifetime `'0`...
2717
= note: ...but `Foo<&'1 isize>` is actually implemented for the type `&'1 u32`, for some specific lifetime `'1`

‎src/test/ui/hrtb/hrtb-perfect-forwarding.nll.stderr

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
warning: function cannot return without recursing
2-
--> $DIR/hrtb-perfect-forwarding.rs:22:1
2+
--> $DIR/hrtb-perfect-forwarding.rs:16:1
33
|
4-
LL | / fn no_hrtb<'b,T>(mut t: T)
5-
LL | | where T : Bar<&'b isize>
4+
LL | / fn no_hrtb<'b, T>(mut t: T)
5+
LL | | where
6+
LL | | T: Bar<&'b isize>,
67
LL | | {
7-
LL | | // OK -- `T : Bar<&'b isize>`, and thus the impl above ensures that
8-
LL | | // `&mut T : Bar<&'b isize>`.
8+
... |
99
LL | | no_hrtb(&mut t);
1010
| | --------------- recursive call site
1111
LL | | }
@@ -15,12 +15,12 @@ LL | | }
1515
= help: a `loop` may express intention better if this is on purpose
1616

1717
warning: function cannot return without recursing
18-
--> $DIR/hrtb-perfect-forwarding.rs:30:1
18+
--> $DIR/hrtb-perfect-forwarding.rs:25:1
1919
|
2020
LL | / fn bar_hrtb<T>(mut t: T)
21-
LL | | where T : for<'b> Bar<&'b isize>
21+
LL | | where
22+
LL | | T: for<'b> Bar<&'b isize>,
2223
LL | | {
23-
LL | | // OK -- `T : for<'b> Bar<&'b isize>`, and thus the impl above
2424
... |
2525
LL | | bar_hrtb(&mut t);
2626
| | ---------------- recursive call site
@@ -30,25 +30,26 @@ LL | | }
3030
= help: a `loop` may express intention better if this is on purpose
3131

3232
warning: function cannot return without recursing
33-
--> $DIR/hrtb-perfect-forwarding.rs:39:1
33+
--> $DIR/hrtb-perfect-forwarding.rs:35:1
3434
|
35-
LL | / fn foo_hrtb_bar_not<'b,T>(mut t: T)
36-
LL | | where T : for<'a> Foo<&'a isize> + Bar<&'b isize>
35+
LL | / fn foo_hrtb_bar_not<'b, T>(mut t: T)
36+
LL | | where
37+
LL | | T: for<'a> Foo<&'a isize> + Bar<&'b isize>,
3738
LL | | {
38-
LL | | // Not OK -- The forwarding impl for `Foo` requires that `Bar` also
3939
... |
4040
LL | | foo_hrtb_bar_not(&mut t);
4141
| | ------------------------ recursive call site
4242
LL | |
43+
LL | |
4344
LL | | }
4445
| |_^ cannot return without recursing
4546
|
4647
= help: a `loop` may express intention better if this is on purpose
4748

4849
error: lifetime may not live long enough
49-
--> $DIR/hrtb-perfect-forwarding.rs:46:5
50+
--> $DIR/hrtb-perfect-forwarding.rs:43:5
5051
|
51-
LL | fn foo_hrtb_bar_not<'b,T>(mut t: T)
52+
LL | fn foo_hrtb_bar_not<'b, T>(mut t: T)
5253
| -- lifetime `'b` defined here
5354
...
5455
LL | foo_hrtb_bar_not(&mut t);
@@ -57,18 +58,19 @@ LL | foo_hrtb_bar_not(&mut t);
5758
= help: consider replacing `'b` with `'static`
5859

5960
error: higher-ranked subtype error
60-
--> $DIR/hrtb-perfect-forwarding.rs:46:5
61+
--> $DIR/hrtb-perfect-forwarding.rs:43:5
6162
|
6263
LL | foo_hrtb_bar_not(&mut t);
6364
| ^^^^^^^^^^^^^^^^^^^^^^^^
6465

6566
warning: function cannot return without recursing
66-
--> $DIR/hrtb-perfect-forwarding.rs:50:1
67+
--> $DIR/hrtb-perfect-forwarding.rs:48:1
6768
|
6869
LL | / fn foo_hrtb_bar_hrtb<T>(mut t: T)
69-
LL | | where T : for<'a> Foo<&'a isize> + for<'b> Bar<&'b isize>
70+
LL | | where
71+
LL | | T: for<'a> Foo<&'a isize> + for<'b> Bar<&'b isize>,
7072
LL | | {
71-
LL | | // OK -- now we have `T : for<'b> Bar&'b isize>`.
73+
LL | | // OK -- now we have `T : for<'b> Bar<&'b isize>`.
7274
LL | | foo_hrtb_bar_hrtb(&mut t);
7375
| | ------------------------- recursive call site
7476
LL | | }

‎src/test/ui/hrtb/hrtb-perfect-forwarding.rs

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,56 +2,55 @@
22
// is being applied to `for<'a> Foo<&'a mut X>`. Issue #19730.
33

44
trait Foo<X> {
5-
fn foo(&mut self, x: X) { }
5+
fn foo(&mut self, x: X) {}
66
}
77

88
trait Bar<X> {
9-
fn bar(&mut self, x: X) { }
9+
fn bar(&mut self, x: X) {}
1010
}
1111

12-
impl<'a,X,F> Foo<X> for &'a mut F
13-
where F : Foo<X> + Bar<X>
14-
{
15-
}
12+
impl<'a, X, F> Foo<X> for &'a mut F where F: Foo<X> + Bar<X> {}
1613

17-
impl<'a,X,F> Bar<X> for &'a mut F
18-
where F : Bar<X>
19-
{
20-
}
14+
impl<'a, X, F> Bar<X> for &'a mut F where F: Bar<X> {}
2115

22-
fn no_hrtb<'b,T>(mut t: T)
23-
where T : Bar<&'b isize>
16+
fn no_hrtb<'b, T>(mut t: T)
17+
where
18+
T: Bar<&'b isize>,
2419
{
2520
// OK -- `T : Bar<&'b isize>`, and thus the impl above ensures that
2621
// `&mut T : Bar<&'b isize>`.
2722
no_hrtb(&mut t);
2823
}
2924

3025
fn bar_hrtb<T>(mut t: T)
31-
where T : for<'b> Bar<&'b isize>
26+
where
27+
T: for<'b> Bar<&'b isize>,
3228
{
3329
// OK -- `T : for<'b> Bar<&'b isize>`, and thus the impl above
3430
// ensures that `&mut T : for<'b> Bar<&'b isize>`. This is an
3531
// example of a "perfect forwarding" impl.
3632
bar_hrtb(&mut t);
3733
}
3834

39-
fn foo_hrtb_bar_not<'b,T>(mut t: T)
40-
where T : for<'a> Foo<&'a isize> + Bar<&'b isize>
35+
fn foo_hrtb_bar_not<'b, T>(mut t: T)
36+
where
37+
T: for<'a> Foo<&'a isize> + Bar<&'b isize>,
4138
{
4239
// Not OK -- The forwarding impl for `Foo` requires that `Bar` also
4340
// be implemented. Thus to satisfy `&mut T : for<'a> Foo<&'a
4441
// isize>`, we require `T : for<'a> Bar<&'a isize>`, but the where
4542
// clause only specifies `T : Bar<&'b isize>`.
46-
foo_hrtb_bar_not(&mut t); //~ ERROR mismatched types
47-
//~| ERROR mismatched types
43+
foo_hrtb_bar_not(&mut t);
44+
//~^ ERROR implementation of `Bar` is not general enough
45+
//~| ERROR implementation of `Bar` is not general enough
4846
}
4947

5048
fn foo_hrtb_bar_hrtb<T>(mut t: T)
51-
where T : for<'a> Foo<&'a isize> + for<'b> Bar<&'b isize>
49+
where
50+
T: for<'a> Foo<&'a isize> + for<'b> Bar<&'b isize>,
5251
{
53-
// OK -- now we have `T : for<'b> Bar&'b isize>`.
52+
// OK -- now we have `T : for<'b> Bar<&'b isize>`.
5453
foo_hrtb_bar_hrtb(&mut t);
5554
}
5655

57-
fn main() { }
56+
fn main() {}
Lines changed: 10 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,20 @@
1-
error[E0308]: mismatched types
2-
--> $DIR/hrtb-perfect-forwarding.rs:46:5
1+
error: implementation of `Bar` is not general enough
2+
--> $DIR/hrtb-perfect-forwarding.rs:43:5
33
|
44
LL | foo_hrtb_bar_not(&mut t);
5-
| ^^^^^^^^^^^^^^^^ lifetime mismatch
5+
| ^^^^^^^^^^^^^^^^ implementation of `Bar` is not general enough
66
|
7-
= note: expected type `Bar<&'a isize>`
8-
found type `Bar<&'b isize>`
9-
note: the required lifetime does not necessarily outlive the lifetime `'b` as defined on the function body at 39:21
10-
--> $DIR/hrtb-perfect-forwarding.rs:39:21
11-
|
12-
LL | fn foo_hrtb_bar_not<'b,T>(mut t: T)
13-
| ^^
14-
note: the lifetime requirement is introduced here
15-
--> $DIR/hrtb-perfect-forwarding.rs:40:15
16-
|
17-
LL | where T : for<'a> Foo<&'a isize> + Bar<&'b isize>
18-
| ^^^^^^^^^^^^^^^^^^^^^^
7+
= note: `T` must implement `Bar<&'0 isize>`, for any lifetime `'0`...
8+
= note: ...but it actually implements `Bar<&'b isize>`
199

20-
error[E0308]: mismatched types
21-
--> $DIR/hrtb-perfect-forwarding.rs:46:5
10+
error: implementation of `Bar` is not general enough
11+
--> $DIR/hrtb-perfect-forwarding.rs:43:5
2212
|
2313
LL | foo_hrtb_bar_not(&mut t);
24-
| ^^^^^^^^^^^^^^^^ lifetime mismatch
25-
|
26-
= note: expected type `Bar<&'a isize>`
27-
found type `Bar<&'b isize>`
28-
note: the lifetime `'b` as defined on the function body at 39:21 doesn't meet the lifetime requirements
29-
--> $DIR/hrtb-perfect-forwarding.rs:39:21
30-
|
31-
LL | fn foo_hrtb_bar_not<'b,T>(mut t: T)
32-
| ^^
33-
note: the lifetime requirement is introduced here
34-
--> $DIR/hrtb-perfect-forwarding.rs:40:15
14+
| ^^^^^^^^^^^^^^^^ implementation of `Bar` is not general enough
3515
|
36-
LL | where T : for<'a> Foo<&'a isize> + Bar<&'b isize>
37-
| ^^^^^^^^^^^^^^^^^^^^^^
16+
= note: `T` must implement `Bar<&'0 isize>`, for any lifetime `'0`...
17+
= note: ...but it actually implements `Bar<&'b isize>`
3818

3919
error: aborting due to 2 previous errors
4020

41-
For more information about this error, try `rustc --explain E0308`.

‎src/test/ui/hrtb/issue-46989.stderr

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
error: implementation of `Foo` is not general enough
22
--> $DIR/issue-46989.rs:38:5
33
|
4-
LL | trait Foo {}
5-
| ------------ trait `Foo` defined here
6-
...
74
LL | assert_foo::<fn(&i32)>();
85
| ^^^^^^^^^^^^^^^^^^^^^^ implementation of `Foo` is not general enough
96
|

‎src/test/ui/issues/issue-54302-cases.stderr

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,35 @@
11
error: implementation of `Foo` is not general enough
22
--> $DIR/issue-54302-cases.rs:63:5
33
|
4-
LL | / trait Foo<'x, T> {
5-
LL | | fn foo(self) -> &'x T;
6-
LL | | }
7-
| |_- trait `Foo` defined here
8-
...
9-
LL | <u32 as RefFoo<u32>>::ref_foo(a)
10-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ implementation of `Foo` is not general enough
4+
LL | <u32 as RefFoo<u32>>::ref_foo(a)
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ implementation of `Foo` is not general enough
116
|
127
= note: `Foo<'static, u32>` would have to be implemented for the type `&'0 u32`, for any lifetime `'0`...
138
= note: ...but `Foo<'_, u32>` is actually implemented for the type `&'1 u32`, for some specific lifetime `'1`
149

1510
error: implementation of `Foo` is not general enough
1611
--> $DIR/issue-54302-cases.rs:69:5
1712
|
18-
LL | / trait Foo<'x, T> {
19-
LL | | fn foo(self) -> &'x T;
20-
LL | | }
21-
| |_- trait `Foo` defined here
22-
...
23-
LL | <i32 as RefFoo<i32>>::ref_foo(a)
24-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ implementation of `Foo` is not general enough
13+
LL | <i32 as RefFoo<i32>>::ref_foo(a)
14+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ implementation of `Foo` is not general enough
2515
|
2616
= note: `Foo<'static, i32>` would have to be implemented for the type `&'0 i32`, for any lifetime `'0`...
2717
= note: ...but `Foo<'_, i32>` is actually implemented for the type `&'1 i32`, for some specific lifetime `'1`
2818

2919
error: implementation of `Foo` is not general enough
3020
--> $DIR/issue-54302-cases.rs:75:5
3121
|
32-
LL | / trait Foo<'x, T> {
33-
LL | | fn foo(self) -> &'x T;
34-
LL | | }
35-
| |_- trait `Foo` defined here
36-
...
37-
LL | <u64 as RefFoo<u64>>::ref_foo(a)
38-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ implementation of `Foo` is not general enough
22+
LL | <u64 as RefFoo<u64>>::ref_foo(a)
23+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ implementation of `Foo` is not general enough
3924
|
4025
= note: `Foo<'static, u64>` would have to be implemented for the type `&'0 u64`, for any lifetime `'0`...
4126
= note: ...but `Foo<'_, u64>` is actually implemented for the type `&'1 u64`, for some specific lifetime `'1`
4227

4328
error: implementation of `Foo` is not general enough
4429
--> $DIR/issue-54302-cases.rs:81:5
4530
|
46-
LL | / trait Foo<'x, T> {
47-
LL | | fn foo(self) -> &'x T;
48-
LL | | }
49-
| |_- trait `Foo` defined here
50-
...
51-
LL | <i64 as RefFoo<i64>>::ref_foo(a)
52-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ implementation of `Foo` is not general enough
31+
LL | <i64 as RefFoo<i64>>::ref_foo(a)
32+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ implementation of `Foo` is not general enough
5333
|
5434
= note: `Foo<'static, i64>` would have to be implemented for the type `&'0 i64`, for any lifetime `'0`...
5535
= note: ...but `Foo<'_, i64>` is actually implemented for the type `&'1 i64`, for some specific lifetime `'1`

‎src/test/ui/issues/issue-54302.stderr

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
error: implementation of `Deserialize` is not general enough
22
--> $DIR/issue-54302.rs:13:5
33
|
4-
LL | trait Deserialize<'de> {}
5-
| ------------------------- trait `Deserialize` defined here
6-
...
74
LL | assert_deserialize_owned::<&'static str>();
85
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ implementation of `Deserialize` is not general enough
96
|

‎src/test/ui/issues/issue-55731.stderr

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
error: implementation of `DistributedIteratorMulti` is not general enough
22
--> $DIR/issue-55731.rs:48:5
33
|
4-
LL | / trait DistributedIteratorMulti<Source> {
5-
LL | | type Item;
6-
LL | | }
7-
| |_- trait `DistributedIteratorMulti` defined here
8-
...
9-
LL | multi(Map {
10-
| ^^^^^ implementation of `DistributedIteratorMulti` is not general enough
4+
LL | multi(Map {
5+
| ^^^^^ implementation of `DistributedIteratorMulti` is not general enough
116
|
127
= note: `DistributedIteratorMulti<&'0 ()>` would have to be implemented for the type `Cloned<&()>`, for any lifetime `'0`...
138
= note: ...but `DistributedIteratorMulti<&'1 ()>` is actually implemented for the type `Cloned<&'1 ()>`, for some specific lifetime `'1`

‎src/test/ui/issues/issue-57843.nll.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: higher-ranked subtype error
2-
--> $DIR/issue-57843.rs:23:9
2+
--> $DIR/issue-57843.rs:25:9
33
|
44
LL | Foo(Box::new(|_| ()));
55
| ^^^^^^^^^^^^^^^^

‎src/test/ui/issues/issue-57843.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ trait ClonableFn<T> {
1111
}
1212

1313
impl<T, F: 'static> ClonableFn<T> for F
14-
where F: Fn(T) + Clone {
14+
where
15+
F: Fn(T) + Clone,
16+
{
1517
fn clone(&self) -> Box<dyn Fn(T)> {
1618
Box::new(self.clone())
1719
}
@@ -20,5 +22,5 @@ where F: Fn(T) + Clone {
2022
struct Foo(Box<dyn for<'a> ClonableFn<&'a bool>>);
2123

2224
fn main() {
23-
Foo(Box::new(|_| ())); //~ ERROR mismatched types
25+
Foo(Box::new(|_| ())); //~ ERROR implementation of `FnOnce` is not general enough
2426
}

‎src/test/ui/issues/issue-57843.stderr

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
1-
error[E0308]: mismatched types
2-
--> $DIR/issue-57843.rs:23:9
1+
error: implementation of `FnOnce` is not general enough
2+
--> $DIR/issue-57843.rs:25:9
33
|
44
LL | Foo(Box::new(|_| ()));
5-
| ^^^^^^^^^^^^^^^^ one type is more general than the other
5+
| ^^^^^^^^^^^^^^^^ implementation of `FnOnce` is not general enough
66
|
7-
= note: expected type `FnOnce<(&'a bool,)>`
8-
found type `FnOnce<(&bool,)>`
9-
note: this closure does not fulfill the lifetime requirements
10-
--> $DIR/issue-57843.rs:23:18
11-
|
12-
LL | Foo(Box::new(|_| ()));
13-
| ^^^^^^
7+
= note: closure with signature `fn(&'2 bool)` must implement `FnOnce<(&'1 bool,)>`, for any lifetime `'1`...
8+
= note: ...but it actually implements `FnOnce<(&'2 bool,)>`, for some specific lifetime `'2`
149

1510
error: aborting due to previous error
1611

17-
For more information about this error, try `rustc --explain E0308`.

‎src/test/ui/lifetimes/issue-79187.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ fn thing(x: impl FnOnce(&u32)) {}
22

33
fn main() {
44
let f = |_| ();
5-
thing(f); //~ERROR mismatched types
5+
thing(f); //~ERROR implementation of `FnOnce` is not general enough
66
}
Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,11 @@
1-
error[E0308]: mismatched types
1+
error: implementation of `FnOnce` is not general enough
22
--> $DIR/issue-79187.rs:5:5
33
|
44
LL | thing(f);
5-
| ^^^^^ lifetime mismatch
5+
| ^^^^^ implementation of `FnOnce` is not general enough
66
|
7-
= note: expected type `FnOnce<(&u32,)>`
8-
found type `FnOnce<(&u32,)>`
9-
note: this closure does not fulfill the lifetime requirements
10-
--> $DIR/issue-79187.rs:4:13
11-
|
12-
LL | let f = |_| ();
13-
| ^^^^^^
14-
note: the lifetime requirement is introduced here
15-
--> $DIR/issue-79187.rs:1:18
16-
|
17-
LL | fn thing(x: impl FnOnce(&u32)) {}
18-
| ^^^^^^^^^^^^
7+
= note: closure with signature `fn(&'2 u32)` must implement `FnOnce<(&'1 u32,)>`, for any lifetime `'1`...
8+
= note: ...but it actually implements `FnOnce<(&'2 u32,)>`, for some specific lifetime `'2`
199

2010
error: aborting due to previous error
2111

22-
For more information about this error, try `rustc --explain E0308`.

‎src/test/ui/mismatched_types/closure-arg-type-mismatch.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ fn main() {
88
fn baz<F: Fn(*mut &u32)>(_: F) {}
99
fn _test<'a>(f: fn(*mut &'a u32)) {
1010
baz(f);
11-
//~^ ERROR mismatched types
12-
//~| ERROR mismatched types
11+
//~^ ERROR implementation of `FnOnce` is not general enough
12+
//~| ERROR implementation of `FnOnce` is not general enough
1313
//~| ERROR mismatched types
1414
//~| ERROR mismatched types
1515
}

‎src/test/ui/mismatched_types/closure-arg-type-mismatch.stderr

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -41,24 +41,14 @@ note: the lifetime requirement is introduced here
4141
LL | fn baz<F: Fn(*mut &u32)>(_: F) {}
4242
| ^^^^^^^^^^^^^
4343

44-
error[E0308]: mismatched types
44+
error: implementation of `FnOnce` is not general enough
4545
--> $DIR/closure-arg-type-mismatch.rs:10:5
4646
|
4747
LL | baz(f);
48-
| ^^^ lifetime mismatch
49-
|
50-
= note: expected type `FnOnce<(*mut &u32,)>`
51-
found type `FnOnce<(*mut &'a u32,)>`
52-
note: the required lifetime does not necessarily outlive the lifetime `'a` as defined on the function body at 9:10
53-
--> $DIR/closure-arg-type-mismatch.rs:9:10
54-
|
55-
LL | fn _test<'a>(f: fn(*mut &'a u32)) {
56-
| ^^
57-
note: the lifetime requirement is introduced here
58-
--> $DIR/closure-arg-type-mismatch.rs:8:11
48+
| ^^^ implementation of `FnOnce` is not general enough
5949
|
60-
LL | fn baz<F: Fn(*mut &u32)>(_: F) {}
61-
| ^^^^^^^^^^^^^
50+
= note: `fn(*mut &'a u32)` must implement `FnOnce<(*mut &'0 u32,)>`, for any lifetime `'0`...
51+
= note: ...but it actually implements `FnOnce<(*mut &'a u32,)>`
6252

6353
error[E0308]: mismatched types
6454
--> $DIR/closure-arg-type-mismatch.rs:10:5
@@ -79,24 +69,14 @@ note: the lifetime requirement is introduced here
7969
LL | fn baz<F: Fn(*mut &u32)>(_: F) {}
8070
| ^^^^^^^^^^^^^
8171

82-
error[E0308]: mismatched types
72+
error: implementation of `FnOnce` is not general enough
8373
--> $DIR/closure-arg-type-mismatch.rs:10:5
8474
|
8575
LL | baz(f);
86-
| ^^^ lifetime mismatch
87-
|
88-
= note: expected type `FnOnce<(*mut &u32,)>`
89-
found type `FnOnce<(*mut &'a u32,)>`
90-
note: the lifetime `'a` as defined on the function body at 9:10 doesn't meet the lifetime requirements
91-
--> $DIR/closure-arg-type-mismatch.rs:9:10
92-
|
93-
LL | fn _test<'a>(f: fn(*mut &'a u32)) {
94-
| ^^
95-
note: the lifetime requirement is introduced here
96-
--> $DIR/closure-arg-type-mismatch.rs:8:11
76+
| ^^^ implementation of `FnOnce` is not general enough
9777
|
98-
LL | fn baz<F: Fn(*mut &u32)>(_: F) {}
99-
| ^^^^^^^^^^^^^
78+
= note: `fn(*mut &'a u32)` must implement `FnOnce<(*mut &'0 u32,)>`, for any lifetime `'0`...
79+
= note: ...but it actually implements `FnOnce<(*mut &'a u32,)>`
10080

10181
error: aborting due to 7 previous errors
10282

‎src/test/ui/rfc1623.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ static SOME_STRUCT: &SomeStruct = &SomeStruct {
2222
foo: &Foo { bools: &[false, true] },
2323
bar: &Bar { bools: &[true, true] },
2424
f: &id,
25-
//~^ ERROR mismatched types
25+
//~^ ERROR implementation of `FnOnce` is not general enough
2626
};
2727

2828
// very simple test for a 'static static with default lifetime

‎src/test/ui/rfc1623.stderr

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
error[E0308]: mismatched types
1+
error: implementation of `FnOnce` is not general enough
22
--> $DIR/rfc1623.rs:24:8
33
|
44
LL | f: &id,
5-
| ^^^ one type is more general than the other
5+
| ^^^ implementation of `FnOnce` is not general enough
66
|
7-
= note: expected type `FnOnce<(&'a Foo<'b>,)>`
8-
found type `FnOnce<(&Foo<'_>,)>`
7+
= note: `fn(&'2 Foo<'_>) -> &'2 Foo<'_> {id::<&'2 Foo<'_>>}` must implement `FnOnce<(&'1 Foo<'b>,)>`, for any lifetime `'1`...
8+
= note: ...but it actually implements `FnOnce<(&'2 Foo<'_>,)>`, for some specific lifetime `'2`
99

1010
error: aborting due to previous error
1111

12-
For more information about this error, try `rustc --explain E0308`.

‎src/test/ui/type-alias-impl-trait/issue-57611-trait-alias.nll.stderr

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,14 @@ note: this closure does not fulfill the lifetime requirements
2424
LL | |x| x
2525
| ^^^^^
2626

27-
error[E0308]: mismatched types
27+
error: implementation of `FnOnce` is not general enough
2828
--> $DIR/issue-57611-trait-alias.rs:17:16
2929
|
3030
LL | type Bar = impl Baz<Self, Self>;
31-
| ^^^^^^^^^^^^^^^^^^^^ one type is more general than the other
31+
| ^^^^^^^^^^^^^^^^^^^^ implementation of `FnOnce` is not general enough
3232
|
33-
= note: expected type `FnOnce<(&X,)>`
34-
found type `FnOnce<(&'static X,)>`
35-
note: this closure does not fulfill the lifetime requirements
36-
--> $DIR/issue-57611-trait-alias.rs:25:9
37-
|
38-
LL | |x| x
39-
| ^^^^^
33+
= note: closure with signature `fn(&'static X) -> &'static X` must implement `FnOnce<(&'0 X,)>`, for any lifetime `'0`...
34+
= note: ...but it actually implements `FnOnce<(&'static X,)>`
4035

4136
error: aborting due to 4 previous errors
4237

‎src/test/ui/type-alias-impl-trait/issue-57611-trait-alias.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ struct X;
1515

1616
impl Foo for X {
1717
type Bar = impl Baz<Self, Self>;
18-
//~^ ERROR mismatched types
19-
//~| ERROR mismatched types
20-
//~| ERROR mismatched types
18+
//~^ ERROR implementation of `FnOnce` is not general enough
19+
//~| ERROR implementation of `FnOnce` is not general enough
20+
//~| ERROR implementation of `FnOnce` is not general enough
2121
//~| ERROR mismatched types
2222
//~| ERROR mismatched types
2323

‎src/test/ui/type-alias-impl-trait/issue-57611-trait-alias.stderr

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
1-
error[E0308]: mismatched types
1+
error: implementation of `FnOnce` is not general enough
22
--> $DIR/issue-57611-trait-alias.rs:17:16
33
|
44
LL | type Bar = impl Baz<Self, Self>;
5-
| ^^^^^^^^^^^^^^^^^^^^ one type is more general than the other
6-
|
7-
= note: expected type `FnOnce<(&X,)>`
8-
found type `FnOnce<(&X,)>`
9-
note: this closure does not fulfill the lifetime requirements
10-
--> $DIR/issue-57611-trait-alias.rs:25:9
5+
| ^^^^^^^^^^^^^^^^^^^^ implementation of `FnOnce` is not general enough
116
|
12-
LL | |x| x
13-
| ^^^^^
7+
= note: closure with signature `fn(&'2 X) -> &X` must implement `FnOnce<(&'1 X,)>`, for any lifetime `'1`...
8+
= note: ...but it actually implements `FnOnce<(&'2 X,)>`, for some specific lifetime `'2`
149

1510
error[E0308]: mismatched types
1611
--> $DIR/issue-57611-trait-alias.rs:17:16
@@ -26,19 +21,14 @@ note: this closure does not fulfill the lifetime requirements
2621
LL | |x| x
2722
| ^^^^^
2823

29-
error[E0308]: mismatched types
24+
error: implementation of `FnOnce` is not general enough
3025
--> $DIR/issue-57611-trait-alias.rs:17:16
3126
|
3227
LL | type Bar = impl Baz<Self, Self>;
33-
| ^^^^^^^^^^^^^^^^^^^^ one type is more general than the other
28+
| ^^^^^^^^^^^^^^^^^^^^ implementation of `FnOnce` is not general enough
3429
|
35-
= note: expected type `FnOnce<(&X,)>`
36-
found type `FnOnce<(&'<empty> X,)>`
37-
note: this closure does not fulfill the lifetime requirements
38-
--> $DIR/issue-57611-trait-alias.rs:25:9
39-
|
40-
LL | |x| x
41-
| ^^^^^
30+
= note: closure with signature `fn(&'2 X) -> &'2 X` must implement `FnOnce<(&'1 X,)>`, for any lifetime `'1`...
31+
= note: ...but it actually implements `FnOnce<(&'2 X,)>`, for some specific lifetime `'2`
4232

4333
error[E0308]: mismatched types
4434
--> $DIR/issue-57611-trait-alias.rs:17:16
@@ -54,19 +44,14 @@ note: this closure does not fulfill the lifetime requirements
5444
LL | |x| x
5545
| ^^^^^
5646

57-
error[E0308]: mismatched types
47+
error: implementation of `FnOnce` is not general enough
5848
--> $DIR/issue-57611-trait-alias.rs:17:16
5949
|
6050
LL | type Bar = impl Baz<Self, Self>;
61-
| ^^^^^^^^^^^^^^^^^^^^ one type is more general than the other
51+
| ^^^^^^^^^^^^^^^^^^^^ implementation of `FnOnce` is not general enough
6252
|
63-
= note: expected type `FnOnce<(&X,)>`
64-
found type `FnOnce<(&'<empty> X,)>`
65-
note: this closure does not fulfill the lifetime requirements
66-
--> $DIR/issue-57611-trait-alias.rs:25:9
67-
|
68-
LL | |x| x
69-
| ^^^^^
53+
= note: closure with signature `fn(&'2 X) -> &'2 X` must implement `FnOnce<(&'1 X,)>`, for any lifetime `'1`...
54+
= note: ...but it actually implements `FnOnce<(&'2 X,)>`, for some specific lifetime `'2`
7055

7156
error: aborting due to 5 previous errors
7257

‎src/test/ui/unboxed-closures/issue-30906.nll.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: higher-ranked subtype error
2-
--> $DIR/issue-30906.rs:15:5
2+
--> $DIR/issue-30906.rs:18:5
33
|
44
LL | test(Compose(f, |_| {}));
55
| ^^^^^^^^^^^^^^^^^^^^^^^^

‎src/test/ui/unboxed-closures/issue-30906.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,21 @@
22

33
fn test<F: for<'x> FnOnce<(&'x str,)>>(_: F) {}
44

5-
struct Compose<F,G>(F,G);
6-
impl<T,F,G> FnOnce<(T,)> for Compose<F,G>
7-
where F: FnOnce<(T,)>, G: FnOnce<(F::Output,)> {
5+
struct Compose<F, G>(F, G);
6+
impl<T, F, G> FnOnce<(T,)> for Compose<F, G>
7+
where
8+
F: FnOnce<(T,)>,
9+
G: FnOnce<(F::Output,)>,
10+
{
811
type Output = G::Output;
912
extern "rust-call" fn call_once(self, (x,): (T,)) -> G::Output {
1013
(self.1)((self.0)(x))
1114
}
1215
}
1316

1417
fn bad<T>(f: fn(&'static str) -> T) {
15-
test(Compose(f, |_| {})); //~ ERROR: mismatched types
18+
test(Compose(f, |_| {}));
19+
//~^ ERROR: implementation of `FnOnce` is not general enough
1620
}
1721

1822
fn main() {}
Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
1-
error[E0308]: mismatched types
2-
--> $DIR/issue-30906.rs:15:5
1+
error: implementation of `FnOnce` is not general enough
2+
--> $DIR/issue-30906.rs:18:5
33
|
44
LL | test(Compose(f, |_| {}));
5-
| ^^^^ lifetime mismatch
5+
| ^^^^ implementation of `FnOnce` is not general enough
66
|
7-
= note: expected type `FnOnce<(&'x str,)>`
8-
found type `FnOnce<(&str,)>`
9-
note: the lifetime requirement is introduced here
10-
--> $DIR/issue-30906.rs:3:12
11-
|
12-
LL | fn test<F: for<'x> FnOnce<(&'x str,)>>(_: F) {}
13-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
7+
= note: `fn(&'2 str) -> T` must implement `FnOnce<(&'1 str,)>`, for any lifetime `'1`...
8+
= note: ...but it actually implements `FnOnce<(&'2 str,)>`, for some specific lifetime `'2`
149

1510
error: aborting due to previous error
1611

17-
For more information about this error, try `rustc --explain E0308`.
Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
11
error: implementation of `Bar` is not general enough
22
--> $DIR/where-for-self-2.rs:23:5
33
|
4-
LL | / trait Bar {
5-
LL | | fn bar(&self);
6-
LL | | }
7-
| |_- trait `Bar` defined here
8-
...
9-
LL | foo(&X);
10-
| ^^^ implementation of `Bar` is not general enough
4+
LL | foo(&X);
5+
| ^^^ implementation of `Bar` is not general enough
116
|
12-
= note: `Bar` would have to be implemented for the type `&'0 u32`, for any lifetime `'0`...
13-
= note: ...but `Bar` is actually implemented for the type `&'1 u32`, for some specific lifetime `'1`
7+
= note: `&'0 u32` must implement `Bar`, for any lifetime `'0`...
8+
= note: ...but `Bar` is actually implemented for the type `&'static u32`
149

1510
error: aborting due to previous error
1611

0 commit comments

Comments
 (0)
Please sign in to comment.