Skip to content

Commit 8384357

Browse files
committed
Simple modification of diagnostic information
fixes rust-lang#119067
1 parent b37d43e commit 8384357

11 files changed

+84
-38
lines changed

compiler/rustc_ast_passes/messages.ftl

+3-3
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,13 @@ ast_passes_fn_without_body =
117117
free function without a body
118118
.suggestion = provide a definition for the function
119119
120+
ast_passes_forbidden_bound =
121+
bounds cannot be used in this context
122+
120123
ast_passes_forbidden_default =
121124
`default` is only allowed on items in trait impls
122125
.label = `default` because of this
123126
124-
ast_passes_forbidden_lifetime_bound =
125-
lifetime bounds cannot be used in this context
126-
127127
ast_passes_forbidden_non_lifetime_param =
128128
only lifetime parameters can be used in this context
129129

compiler/rustc_ast_passes/src/errors.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ pub struct TraitFnConst {
5252
}
5353

5454
#[derive(Diagnostic)]
55-
#[diag(ast_passes_forbidden_lifetime_bound)]
56-
pub struct ForbiddenLifetimeBound {
55+
#[diag(ast_passes_forbidden_bound)]
56+
pub struct ForbiddenBound {
5757
#[primary_span]
5858
pub spans: Vec<Span>,
5959
}

compiler/rustc_ast_passes/src/feature_gate.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,7 @@ impl<'a> PostExpansionVisitor<'a> {
152152
}
153153

154154
fn check_late_bound_lifetime_defs(&self, params: &[ast::GenericParam]) {
155-
// Check only lifetime parameters are present and that the lifetime
156-
// parameters that are present have no bounds.
155+
// Check parameters that are present have no bounds.
157156
let non_lt_param_spans = params.iter().filter_map(|param| match param.kind {
158157
ast::GenericParamKind::Lifetime { .. } => None,
159158
_ => Some(param.ident.span),
@@ -164,10 +163,11 @@ impl<'a> PostExpansionVisitor<'a> {
164163
non_lt_param_spans,
165164
crate::fluent_generated::ast_passes_forbidden_non_lifetime_param
166165
);
166+
167167
for param in params {
168168
if !param.bounds.is_empty() {
169169
let spans: Vec<_> = param.bounds.iter().map(|b| b.span()).collect();
170-
self.sess.emit_err(errors::ForbiddenLifetimeBound { spans });
170+
self.sess.emit_err(errors::ForbiddenBound { spans });
171171
}
172172
}
173173
}

tests/ui/bounds-lifetime.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
type A = for<'b, 'a: 'b> fn(); //~ ERROR lifetime bounds cannot be used in this context
2-
type B = for<'b, 'a: 'b,> fn(); //~ ERROR lifetime bounds cannot be used in this context
3-
type C = for<'b, 'a: 'b +> fn(); //~ ERROR lifetime bounds cannot be used in this context
1+
type A = for<'b, 'a: 'b> fn(); //~ ERROR bounds cannot be used in this context
2+
type B = for<'b, 'a: 'b,> fn(); //~ ERROR bounds cannot be used in this context
3+
type C = for<'b, 'a: 'b +> fn(); //~ ERROR bounds cannot be used in this context
44
type D = for<'a, T> fn(); //~ ERROR only lifetime parameters can be used in this context
55
type E = dyn for<T, U> Fn(); //~ ERROR only lifetime parameters can be used in this context
66

tests/ui/bounds-lifetime.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
error: lifetime bounds cannot be used in this context
1+
error: bounds cannot be used in this context
22
--> $DIR/bounds-lifetime.rs:1:22
33
|
44
LL | type A = for<'b, 'a: 'b> fn();
55
| ^^
66

7-
error: lifetime bounds cannot be used in this context
7+
error: bounds cannot be used in this context
88
--> $DIR/bounds-lifetime.rs:2:22
99
|
1010
LL | type B = for<'b, 'a: 'b,> fn();
1111
| ^^
1212

13-
error: lifetime bounds cannot be used in this context
13+
error: bounds cannot be used in this context
1414
--> $DIR/bounds-lifetime.rs:3:22
1515
|
1616
LL | type C = for<'b, 'a: 'b +> fn();

tests/ui/higher-ranked/higher-lifetime-bounds.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ fn bar1<'a, 'b>(
66
x: &'a i32,
77
y: &'b i32,
88
f: for<'xa, 'xb: 'xa+'xa> fn(&'xa i32, &'xb i32) -> &'xa i32)
9-
//~^ ERROR lifetime bounds cannot be used in this context
9+
//~^ ERROR bounds cannot be used in this context
1010
{
1111
// If the bound in f's type would matter, the call below would (have to)
1212
// be rejected.
1313
f(x, y);
1414
}
1515

1616
fn bar2<'a, 'b, F: for<'xa, 'xb: 'xa> Fn(&'xa i32, &'xb i32) -> &'xa i32>(
17-
//~^ ERROR lifetime bounds cannot be used in this context
17+
//~^ ERROR bounds cannot be used in this context
1818
x: &'a i32,
1919
y: &'b i32,
2020
f: F)
@@ -29,7 +29,7 @@ fn bar3<'a, 'b, F>(
2929
y: &'b i32,
3030
f: F)
3131
where F: for<'xa, 'xb: 'xa> Fn(&'xa i32, &'xb i32) -> &'xa i32
32-
//~^ ERROR lifetime bounds cannot be used in this context
32+
//~^ ERROR bounds cannot be used in this context
3333
{
3434
// If the bound in f's type would matter, the call below would (have to)
3535
// be rejected.
@@ -41,29 +41,29 @@ fn bar4<'a, 'b, F>(
4141
y: &'b i32,
4242
f: F)
4343
where for<'xa, 'xb: 'xa> F: Fn(&'xa i32, &'xb i32) -> &'xa i32
44-
//~^ ERROR lifetime bounds cannot be used in this context
44+
//~^ ERROR bounds cannot be used in this context
4545
{
4646
// If the bound in f's type would matter, the call below would (have to)
4747
// be rejected.
4848
f(x, y);
4949
}
5050

5151
struct S1<F: for<'xa, 'xb: 'xa> Fn(&'xa i32, &'xb i32) -> &'xa i32>(F);
52-
//~^ ERROR lifetime bounds cannot be used in this context
52+
//~^ ERROR bounds cannot be used in this context
5353
struct S2<F>(F) where F: for<'xa, 'xb: 'xa> Fn(&'xa i32, &'xb i32) -> &'xa i32;
54-
//~^ ERROR lifetime bounds cannot be used in this context
54+
//~^ ERROR bounds cannot be used in this context
5555
struct S3<F>(F) where for<'xa, 'xb: 'xa> F: Fn(&'xa i32, &'xb i32) -> &'xa i32;
56-
//~^ ERROR lifetime bounds cannot be used in this context
56+
//~^ ERROR bounds cannot be used in this context
5757

5858
struct S_fnty(for<'xa, 'xb: 'xa> fn(&'xa i32, &'xb i32) -> &'xa i32);
59-
//~^ ERROR lifetime bounds cannot be used in this context
59+
//~^ ERROR bounds cannot be used in this context
6060

6161
type T1 = Box<dyn for<'xa, 'xb: 'xa> Fn(&'xa i32, &'xb i32) -> &'xa i32>;
62-
//~^ ERROR lifetime bounds cannot be used in this context
62+
//~^ ERROR bounds cannot be used in this context
6363

6464
fn main() {
6565
let _ : Option<for<'xa, 'xb: 'xa> fn(&'xa i32, &'xb i32) -> &'xa i32> = None;
66-
//~^ ERROR lifetime bounds cannot be used in this context
66+
//~^ ERROR bounds cannot be used in this context
6767
let _ : Option<Box<dyn for<'xa, 'xb: 'xa> Fn(&'xa i32, &'xb i32) -> &'xa i32>> = None;
68-
//~^ ERROR lifetime bounds cannot be used in this context
68+
//~^ ERROR bounds cannot be used in this context
6969
}

tests/ui/higher-ranked/higher-lifetime-bounds.stderr

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,64 @@
1-
error: lifetime bounds cannot be used in this context
1+
error: bounds cannot be used in this context
22
--> $DIR/higher-lifetime-bounds.rs:8:22
33
|
44
LL | f: for<'xa, 'xb: 'xa+'xa> fn(&'xa i32, &'xb i32) -> &'xa i32)
55
| ^^^ ^^^
66

7-
error: lifetime bounds cannot be used in this context
7+
error: bounds cannot be used in this context
88
--> $DIR/higher-lifetime-bounds.rs:16:34
99
|
1010
LL | fn bar2<'a, 'b, F: for<'xa, 'xb: 'xa> Fn(&'xa i32, &'xb i32) -> &'xa i32>(
1111
| ^^^
1212

13-
error: lifetime bounds cannot be used in this context
13+
error: bounds cannot be used in this context
1414
--> $DIR/higher-lifetime-bounds.rs:31:28
1515
|
1616
LL | where F: for<'xa, 'xb: 'xa> Fn(&'xa i32, &'xb i32) -> &'xa i32
1717
| ^^^
1818

19-
error: lifetime bounds cannot be used in this context
19+
error: bounds cannot be used in this context
2020
--> $DIR/higher-lifetime-bounds.rs:43:25
2121
|
2222
LL | where for<'xa, 'xb: 'xa> F: Fn(&'xa i32, &'xb i32) -> &'xa i32
2323
| ^^^
2424

25-
error: lifetime bounds cannot be used in this context
25+
error: bounds cannot be used in this context
2626
--> $DIR/higher-lifetime-bounds.rs:51:28
2727
|
2828
LL | struct S1<F: for<'xa, 'xb: 'xa> Fn(&'xa i32, &'xb i32) -> &'xa i32>(F);
2929
| ^^^
3030

31-
error: lifetime bounds cannot be used in this context
31+
error: bounds cannot be used in this context
3232
--> $DIR/higher-lifetime-bounds.rs:53:40
3333
|
3434
LL | struct S2<F>(F) where F: for<'xa, 'xb: 'xa> Fn(&'xa i32, &'xb i32) -> &'xa i32;
3535
| ^^^
3636

37-
error: lifetime bounds cannot be used in this context
37+
error: bounds cannot be used in this context
3838
--> $DIR/higher-lifetime-bounds.rs:55:37
3939
|
4040
LL | struct S3<F>(F) where for<'xa, 'xb: 'xa> F: Fn(&'xa i32, &'xb i32) -> &'xa i32;
4141
| ^^^
4242

43-
error: lifetime bounds cannot be used in this context
43+
error: bounds cannot be used in this context
4444
--> $DIR/higher-lifetime-bounds.rs:58:29
4545
|
4646
LL | struct S_fnty(for<'xa, 'xb: 'xa> fn(&'xa i32, &'xb i32) -> &'xa i32);
4747
| ^^^
4848

49-
error: lifetime bounds cannot be used in this context
49+
error: bounds cannot be used in this context
5050
--> $DIR/higher-lifetime-bounds.rs:61:33
5151
|
5252
LL | type T1 = Box<dyn for<'xa, 'xb: 'xa> Fn(&'xa i32, &'xb i32) -> &'xa i32>;
5353
| ^^^
5454

55-
error: lifetime bounds cannot be used in this context
55+
error: bounds cannot be used in this context
5656
--> $DIR/higher-lifetime-bounds.rs:65:34
5757
|
5858
LL | let _ : Option<for<'xa, 'xb: 'xa> fn(&'xa i32, &'xb i32) -> &'xa i32> = None;
5959
| ^^^
6060

61-
error: lifetime bounds cannot be used in this context
61+
error: bounds cannot be used in this context
6262
--> $DIR/higher-lifetime-bounds.rs:67:42
6363
|
6464
LL | let _ : Option<Box<dyn for<'xa, 'xb: 'xa> Fn(&'xa i32, &'xb i32) -> &'xa i32>> = None;

tests/ui/parser/recover/recover-fn-ptr-with-generics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ fn main() {
2121

2222
let _: extern fn<'a: 'static>();
2323
//~^ ERROR function pointer types may not have generic parameters
24-
//~| ERROR lifetime bounds cannot be used in this context
24+
//~| ERROR bounds cannot be used in this context
2525

2626
let _: for<'any> extern "C" fn<'u>();
2727
//~^ ERROR function pointer types may not have generic parameters

tests/ui/parser/recover/recover-fn-ptr-with-generics.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ error[E0412]: cannot find type `T` in this scope
100100
LL | type Identity = fn<T>(T) -> T;
101101
| ^ not found in this scope
102102

103-
error: lifetime bounds cannot be used in this context
103+
error: bounds cannot be used in this context
104104
--> $DIR/recover-fn-ptr-with-generics.rs:22:26
105105
|
106106
LL | let _: extern fn<'a: 'static>();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// check-fail
2+
3+
#![allow(incomplete_features)]
4+
#![feature(non_lifetime_binders)]
5+
#![feature(closure_lifetime_binder)]
6+
7+
trait Trait {}
8+
9+
trait Trait2
10+
where for <T: Trait> ():{}
11+
//~^ ERROR bounds cannot be used in this context
12+
13+
fn main() {
14+
let _ = for<T: Trait> || {};
15+
//~^ ERROR bounds cannot be used in this context
16+
//~| ERROR implicit types in closure signatures are forbidden
17+
//~| ERROR late-bound type parameter not allowed on closure
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
error: bounds cannot be used in this context
2+
--> $DIR/non-lifetime-binders-issue-119067.rs:10:19
3+
|
4+
LL | where for <T: Trait> ():{}
5+
| ^^^^^
6+
7+
error: bounds cannot be used in this context
8+
--> $DIR/non-lifetime-binders-issue-119067.rs:14:20
9+
|
10+
LL | let _ = for<T: Trait> || {};
11+
| ^^^^^
12+
13+
error: implicit types in closure signatures are forbidden when `for<...>` is present
14+
--> $DIR/non-lifetime-binders-issue-119067.rs:14:29
15+
|
16+
LL | let _ = for<T: Trait> || {};
17+
| ------------- ^
18+
| |
19+
| `for<...>` is here
20+
21+
error: late-bound type parameter not allowed on closures
22+
--> $DIR/non-lifetime-binders-issue-119067.rs:14:17
23+
|
24+
LL | let _ = for<T: Trait> || {};
25+
| ^
26+
27+
error: aborting due to 4 previous errors
28+

0 commit comments

Comments
 (0)