Skip to content

Commit f149f40

Browse files
Rollup merge of rust-lang#154875 - TaKO8Ki:regression-test-152936-regions-name, r=jackh726
Avoid duplicate diagnostic args in `RegionOriginNote::WithName` Fixes rust-lang#152936 This is a follow up to rust-lang#153508.
2 parents fff9e44 + 989f4cd commit f149f40

3 files changed

Lines changed: 67 additions & 3 deletions

File tree

compiler/rustc_trait_selection/src/errors.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -442,9 +442,11 @@ impl Subdiagnostic for RegionOriginNote<'_> {
442442
label_or_note(diag, span, msg);
443443
}
444444
RegionOriginNote::WithName { span, msg, name, continues } => {
445-
diag.arg("name", name);
446-
diag.arg("continues", continues);
447-
label_or_note(diag, span, msg);
445+
label_or_note(
446+
diag,
447+
span,
448+
msg.arg("name", name).arg("continues", continues).format(),
449+
);
448450
}
449451
RegionOriginNote::WithRequirement {
450452
span,
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Regression test for https://github.com/rust-lang/rust/issues/152936
2+
3+
use std::collections::hash_map::{HashMap, Keys};
4+
use std::marker::PhantomData;
5+
6+
trait MapAssertion<'a, K, V, R> {
7+
fn key_set(&self) -> Subject<Keys<K, V>, (), R>;
8+
}
9+
10+
struct Subject<'a, T, V, R>(PhantomData<(&'a T, V, R)>);
11+
12+
impl<'a, K, V, R> MapAssertion<'a, K, V, R> for Subject<'a, HashMap<K, V>, (), R> {
13+
fn key_set(&self) -> Subject<'static, Keys<K, V>, (), R> {
14+
//~^ ERROR cannot infer an appropriate lifetime for lifetime parameter '_ in generic type due to conflicting requirements
15+
//~| ERROR mismatched types
16+
}
17+
}
18+
19+
fn main() {}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
error[E0803]: cannot infer an appropriate lifetime for lifetime parameter '_ in generic type due to conflicting requirements
2+
--> $DIR/impl-trait-lifetime-conflict-hashmap-keys.rs:13:5
3+
|
4+
LL | fn key_set(&self) -> Subject<'static, Keys<K, V>, (), R> {
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
note: first, the lifetime cannot outlive the lifetime `'a` as defined here...
8+
--> $DIR/impl-trait-lifetime-conflict-hashmap-keys.rs:12:6
9+
|
10+
LL | impl<'a, K, V, R> MapAssertion<'a, K, V, R> for Subject<'a, HashMap<K, V>, (), R> {
11+
| ^^
12+
note: ...so that the reference type `&Subject<'a, HashMap<K, V>, (), R>` does not outlive the data it points at
13+
--> $DIR/impl-trait-lifetime-conflict-hashmap-keys.rs:13:5
14+
|
15+
LL | fn key_set(&self) -> Subject<'static, Keys<K, V>, (), R> {
16+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17+
= note: but, the lifetime must be valid for the static lifetime...
18+
note: ...so that the type `std::collections::hash_map::Keys<'_, K, V>` will meet its required lifetime bounds...
19+
--> $DIR/impl-trait-lifetime-conflict-hashmap-keys.rs:13:5
20+
|
21+
LL | fn key_set(&self) -> Subject<'static, Keys<K, V>, (), R> {
22+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23+
note: ...that is required by this bound
24+
--> $DIR/impl-trait-lifetime-conflict-hashmap-keys.rs:10:29
25+
|
26+
LL | struct Subject<'a, T, V, R>(PhantomData<(&'a T, V, R)>);
27+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
28+
29+
error[E0308]: mismatched types
30+
--> $DIR/impl-trait-lifetime-conflict-hashmap-keys.rs:13:26
31+
|
32+
LL | fn key_set(&self) -> Subject<'static, Keys<K, V>, (), R> {
33+
| ------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `Subject<'_, Keys<'_, K, V>, (), R>`, found `()`
34+
| |
35+
| implicitly returns `()` as its body has no tail or `return` expression
36+
|
37+
= note: expected struct `Subject<'static, std::collections::hash_map::Keys<'_, K, V>, (), R>`
38+
found unit type `()`
39+
40+
error: aborting due to 2 previous errors
41+
42+
Some errors have detailed explanations: E0308, E0803.
43+
For more information about an error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)