Skip to content

Commit 6e79310

Browse files
authored
Rollup merge of #107111 - chenyukang:yukang/fix-107090-fluent-parameters, r=petrochenkov
Fix missing arguments issues and copy-paste bug for fluent Fixes #107090
2 parents d022013 + 81efdab commit 6e79310

File tree

5 files changed

+223
-14
lines changed

5 files changed

+223
-14
lines changed

compiler/rustc_error_messages/locales/en-US/infer.ftl

+13-13
Original file line numberDiff line numberDiff line change
@@ -268,28 +268,28 @@ infer_but_calling_introduces = {$has_param_name ->
268268
[true] `{$param_name}`
269269
*[false] `fn` parameter
270270
} has {$lifetime_kind ->
271-
[named] lifetime `{$lifetime}`
272-
*[anon] an anonymous lifetime `'_`
273-
} but calling `{assoc_item}` introduces an implicit `'static` lifetime requirement
271+
[true] lifetime `{$lifetime}`
272+
*[false] an anonymous lifetime `'_`
273+
} but calling `{$assoc_item}` introduces an implicit `'static` lifetime requirement
274274
.label1 = {$has_lifetime ->
275-
[named] lifetime `{$lifetime}`
276-
*[anon] an anonymous lifetime `'_`
275+
[true] lifetime `{$lifetime}`
276+
*[false] an anonymous lifetime `'_`
277277
}
278278
.label2 = ...is used and required to live as long as `'static` here because of an implicit lifetime bound on the {$has_impl_path ->
279-
[named] `impl` of `{$impl_path}`
280-
*[anon] inherent `impl`
279+
[true] `impl` of `{$impl_path}`
280+
*[false] inherent `impl`
281281
}
282282
283283
infer_but_needs_to_satisfy = {$has_param_name ->
284284
[true] `{$param_name}`
285285
*[false] `fn` parameter
286286
} has {$has_lifetime ->
287-
[named] lifetime `{$lifetime}`
288-
*[anon] an anonymous lifetime `'_`
287+
[true] lifetime `{$lifetime}`
288+
*[false] an anonymous lifetime `'_`
289289
} but it needs to satisfy a `'static` lifetime requirement
290290
.influencer = this data with {$has_lifetime ->
291-
[named] lifetime `{$lifetime}`
292-
*[anon] an anonymous lifetime `'_`
291+
[true] lifetime `{$lifetime}`
292+
*[false] an anonymous lifetime `'_`
293293
}...
294294
.require = {$spans_empty ->
295295
*[true] ...is used and required to live as long as `'static` here
@@ -302,8 +302,8 @@ infer_more_targeted = {$has_param_name ->
302302
[true] `{$param_name}`
303303
*[false] `fn` parameter
304304
} has {$has_lifetime ->
305-
[named] lifetime `{$lifetime}`
306-
*[anon] an anonymous lifetime `'_`
305+
[true] lifetime `{$lifetime}`
306+
*[false] an anonymous lifetime `'_`
307307
} but calling `{$ident}` introduces an implicit `'static` lifetime requirement
308308
309309
infer_ril_introduced_here = `'static` requirement introduced here

compiler/rustc_infer/src/errors/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -927,6 +927,8 @@ pub struct ButNeedsToSatisfy {
927927
#[subdiagnostic]
928928
pub req_introduces_loc: Option<ReqIntroducedLocations>,
929929

930+
pub has_param_name: bool,
931+
pub param_name: String,
930932
pub spans_empty: bool,
931933
pub has_lifetime: bool,
932934
pub lifetime: String,

compiler/rustc_infer/src/infer/error_reporting/nice_region_error/static_impl_trait.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
9898
let sp = var_origin.span();
9999
let return_sp = sub_origin.span();
100100
let param = self.find_param_with_region(*sup_r, *sub_r)?;
101+
let simple_ident = param.param.pat.simple_ident();
101102
let lifetime_name = if sup_r.has_name() { sup_r.to_string() } else { "'_".to_owned() };
102103

103104
let (mention_influencer, influencer_point) =
@@ -187,7 +188,9 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
187188
req_introduces_loc: subdiag,
188189

189190
has_lifetime: sup_r.has_name(),
190-
lifetime: sup_r.to_string(),
191+
lifetime: lifetime_name.clone(),
192+
has_param_name: simple_ident.is_some(),
193+
param_name: simple_ident.map(|x| x.to_string()).unwrap_or_default(),
191194
spans_empty,
192195
bound,
193196
};

tests/ui/inference/issue-107090.rs

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
use std::marker::PhantomData;
2+
struct Foo<'a, 'b, T>(PhantomData<(&'a (), &'b (), T)>)
3+
where
4+
Foo<'short, 'out, T>: Convert<'a, 'b>;
5+
//~^ ERROR mismatched types
6+
//~^^ ERROR mismatched types
7+
//~^^^ ERROR use of undeclared lifetime name
8+
//~| ERROR use of undeclared lifetime name `'out`
9+
10+
trait Convert<'a, 'b>: Sized {
11+
fn cast(&'a self) -> &'b Self;
12+
}
13+
impl<'long: 'short, 'short, T> Convert<'long, 'b> for Foo<'short, 'out, T> {
14+
//~^ ERROR use of undeclared lifetime name
15+
//~^^ ERROR use of undeclared lifetime name `'out`
16+
//~| ERROR cannot infer an appropriate lifetime for lifetime parameter
17+
fn cast(&'long self) -> &'short Foo<'short, 'out, T> {
18+
//~^ ERROR use of undeclared lifetime name
19+
//~| ERROR cannot infer an appropriate lifetime for lifetime parameter
20+
self
21+
}
22+
}
23+
24+
fn badboi<'in_, 'out, T>(x: Foo<'in_, 'out, T>, sadness: &'in_ Foo<'short, 'out, T>) -> &'out T {
25+
//~^ ERROR use of undeclared lifetime name
26+
//~^^ ERROR incompatible lifetime on type
27+
//~| ERROR `x` has lifetime `'in_` but it needs to satisfy a `'static` lifetime requirement
28+
sadness.cast()
29+
}
30+
31+
fn main() {}
+173
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
error[E0261]: use of undeclared lifetime name `'short`
2+
--> $DIR/issue-107090.rs:4:9
3+
|
4+
LL | Foo<'short, 'out, T>: Convert<'a, 'b>;
5+
| ^^^^^^ undeclared lifetime
6+
|
7+
= note: for more information on higher-ranked polymorphism, visit https://doc.rust-lang.org/nomicon/hrtb.html
8+
help: consider making the bound lifetime-generic with a new `'short` lifetime
9+
|
10+
LL | for<'short> Foo<'short, 'out, T>: Convert<'a, 'b>;
11+
| +++++++++++
12+
help: consider introducing lifetime `'short` here
13+
|
14+
LL | struct Foo<'short, 'a, 'b, T>(PhantomData<(&'a (), &'b (), T)>)
15+
| +++++++
16+
17+
error[E0261]: use of undeclared lifetime name `'out`
18+
--> $DIR/issue-107090.rs:4:17
19+
|
20+
LL | Foo<'short, 'out, T>: Convert<'a, 'b>;
21+
| ^^^^ undeclared lifetime
22+
|
23+
help: consider making the bound lifetime-generic with a new `'out` lifetime
24+
|
25+
LL | for<'out> Foo<'short, 'out, T>: Convert<'a, 'b>;
26+
| +++++++++
27+
help: consider introducing lifetime `'out` here
28+
|
29+
LL | struct Foo<'out, 'a, 'b, T>(PhantomData<(&'a (), &'b (), T)>)
30+
| +++++
31+
32+
error[E0261]: use of undeclared lifetime name `'b`
33+
--> $DIR/issue-107090.rs:13:47
34+
|
35+
LL | impl<'long: 'short, 'short, T> Convert<'long, 'b> for Foo<'short, 'out, T> {
36+
| - ^^ undeclared lifetime
37+
| |
38+
| help: consider introducing lifetime `'b` here: `'b,`
39+
40+
error[E0261]: use of undeclared lifetime name `'out`
41+
--> $DIR/issue-107090.rs:13:67
42+
|
43+
LL | impl<'long: 'short, 'short, T> Convert<'long, 'b> for Foo<'short, 'out, T> {
44+
| - help: consider introducing lifetime `'out` here: `'out,` ^^^^ undeclared lifetime
45+
46+
error[E0261]: use of undeclared lifetime name `'out`
47+
--> $DIR/issue-107090.rs:17:49
48+
|
49+
LL | fn cast(&'long self) -> &'short Foo<'short, 'out, T> {
50+
| ^^^^ undeclared lifetime
51+
|
52+
help: consider introducing lifetime `'out` here
53+
|
54+
LL | fn cast<'out>(&'long self) -> &'short Foo<'short, 'out, T> {
55+
| ++++++
56+
help: consider introducing lifetime `'out` here
57+
|
58+
LL | impl<'out, 'long: 'short, 'short, T> Convert<'long, 'b> for Foo<'short, 'out, T> {
59+
| +++++
60+
61+
error[E0261]: use of undeclared lifetime name `'short`
62+
--> $DIR/issue-107090.rs:24:68
63+
|
64+
LL | fn badboi<'in_, 'out, T>(x: Foo<'in_, 'out, T>, sadness: &'in_ Foo<'short, 'out, T>) -> &'out T {
65+
| - ^^^^^^ undeclared lifetime
66+
| |
67+
| help: consider introducing lifetime `'short` here: `'short,`
68+
69+
error[E0308]: mismatched types
70+
--> $DIR/issue-107090.rs:4:27
71+
|
72+
LL | Foo<'short, 'out, T>: Convert<'a, 'b>;
73+
| ^^^^^^^^^^^^^^^ lifetime mismatch
74+
|
75+
= note: expected trait `Convert<'static, 'static>`
76+
found trait `Convert<'a, 'b>`
77+
note: the lifetime `'a` as defined here...
78+
--> $DIR/issue-107090.rs:2:12
79+
|
80+
LL | struct Foo<'a, 'b, T>(PhantomData<(&'a (), &'b (), T)>)
81+
| ^^
82+
= note: ...does not necessarily outlive the static lifetime
83+
84+
error[E0308]: mismatched types
85+
--> $DIR/issue-107090.rs:4:27
86+
|
87+
LL | Foo<'short, 'out, T>: Convert<'a, 'b>;
88+
| ^^^^^^^^^^^^^^^ lifetime mismatch
89+
|
90+
= note: expected trait `Convert<'static, 'static>`
91+
found trait `Convert<'a, 'b>`
92+
note: the lifetime `'b` as defined here...
93+
--> $DIR/issue-107090.rs:2:16
94+
|
95+
LL | struct Foo<'a, 'b, T>(PhantomData<(&'a (), &'b (), T)>)
96+
| ^^
97+
= note: ...does not necessarily outlive the static lifetime
98+
99+
error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'long` due to conflicting requirements
100+
--> $DIR/issue-107090.rs:13:55
101+
|
102+
LL | impl<'long: 'short, 'short, T> Convert<'long, 'b> for Foo<'short, 'out, T> {
103+
| ^^^^^^^^^^^^^^^^^^^^
104+
|
105+
note: first, the lifetime cannot outlive the lifetime `'short` as defined here...
106+
--> $DIR/issue-107090.rs:13:21
107+
|
108+
LL | impl<'long: 'short, 'short, T> Convert<'long, 'b> for Foo<'short, 'out, T> {
109+
| ^^^^^^
110+
= note: ...but the lifetime must also be valid for the static lifetime...
111+
note: ...so that the types are compatible
112+
--> $DIR/issue-107090.rs:13:55
113+
|
114+
LL | impl<'long: 'short, 'short, T> Convert<'long, 'b> for Foo<'short, 'out, T> {
115+
| ^^^^^^^^^^^^^^^^^^^^
116+
= note: expected `Convert<'short, 'static>`
117+
found `Convert<'_, 'static>`
118+
119+
error: incompatible lifetime on type
120+
--> $DIR/issue-107090.rs:24:29
121+
|
122+
LL | fn badboi<'in_, 'out, T>(x: Foo<'in_, 'out, T>, sadness: &'in_ Foo<'short, 'out, T>) -> &'out T {
123+
| ^^^^^^^^^^^^^^^^^^
124+
|
125+
note: because this has an unmet lifetime requirement
126+
--> $DIR/issue-107090.rs:4:27
127+
|
128+
LL | Foo<'short, 'out, T>: Convert<'a, 'b>;
129+
| ^^^^^^^^^^^^^^^ introduces a `'static` lifetime requirement
130+
note: the lifetime `'out` as defined here...
131+
--> $DIR/issue-107090.rs:24:17
132+
|
133+
LL | fn badboi<'in_, 'out, T>(x: Foo<'in_, 'out, T>, sadness: &'in_ Foo<'short, 'out, T>) -> &'out T {
134+
| ^^^^
135+
note: ...does not necessarily outlive the static lifetime introduced by the compatible `impl`
136+
--> $DIR/issue-107090.rs:13:1
137+
|
138+
LL | impl<'long: 'short, 'short, T> Convert<'long, 'b> for Foo<'short, 'out, T> {
139+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
140+
141+
error[E0759]: `x` has lifetime `'in_` but it needs to satisfy a `'static` lifetime requirement
142+
--> $DIR/issue-107090.rs:24:29
143+
|
144+
LL | fn badboi<'in_, 'out, T>(x: Foo<'in_, 'out, T>, sadness: &'in_ Foo<'short, 'out, T>) -> &'out T {
145+
| ^^^^^^^^^^^^^^^^^^
146+
| |
147+
| this data with lifetime `'in_`...
148+
| ...is used and required to live as long as `'static` here
149+
150+
error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'long` due to conflicting requirements
151+
--> $DIR/issue-107090.rs:17:13
152+
|
153+
LL | fn cast(&'long self) -> &'short Foo<'short, 'out, T> {
154+
| ^^^^^^^^^^^
155+
|
156+
note: first, the lifetime cannot outlive the lifetime `'short` as defined here...
157+
--> $DIR/issue-107090.rs:13:21
158+
|
159+
LL | impl<'long: 'short, 'short, T> Convert<'long, 'b> for Foo<'short, 'out, T> {
160+
| ^^^^^^
161+
= note: ...but the lifetime must also be valid for the static lifetime...
162+
note: ...so that the types are compatible
163+
--> $DIR/issue-107090.rs:17:13
164+
|
165+
LL | fn cast(&'long self) -> &'short Foo<'short, 'out, T> {
166+
| ^^^^^^^^^^^
167+
= note: expected `Convert<'short, 'static>`
168+
found `Convert<'_, 'static>`
169+
170+
error: aborting due to 12 previous errors
171+
172+
Some errors have detailed explanations: E0261, E0308, E0495, E0759.
173+
For more information about an error, try `rustc --explain E0261`.

0 commit comments

Comments
 (0)