Skip to content

Commit 1699293

Browse files
committed
Auto merge of rust-lang#46864 - estebank:closure-type-err-sp, r=nikomatsakis
Closure type error ui tweak Do not point at the same span on all notes/help messages, and instead show them without a span.
2 parents 565907f + eed98d5 commit 1699293

13 files changed

+52
-100
lines changed

src/librustc/ty/error.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -260,10 +260,8 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
260260
let expected_str = values.expected.sort_string(self);
261261
let found_str = values.found.sort_string(self);
262262
if expected_str == found_str && expected_str == "closure" {
263-
db.span_note(sp,
264-
"no two closures, even if identical, have the same type");
265-
db.span_help(sp,
266-
"consider boxing your closure and/or using it as a trait object");
263+
db.note("no two closures, even if identical, have the same type");
264+
db.help("consider boxing your closure and/or using it as a trait object");
267265
}
268266
},
269267
TyParamDefaultMismatch(values) => {

src/librustc_const_eval/check_match.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -402,8 +402,8 @@ fn check_arms<'a, 'tcx>(cx: &mut MatchCheckCtxt<'a, 'tcx>,
402402
);
403403
// if we had a catchall pattern, hint at that
404404
if let Some(catchall) = catchall {
405-
err.span_label(pat.span, "this is an unreachable pattern");
406-
err.span_note(catchall, "this pattern matches any value");
405+
err.span_label(pat.span, "unreachable pattern");
406+
err.span_label(catchall, "matches any value");
407407
}
408408
err.emit();
409409
},

src/librustc_resolve/build_reduced_graph.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ impl<'a> Resolver<'a> {
220220
ResolutionError::SelfImportCanOnlyAppearOnceInTheList);
221221

222222
for other_span in self_spans.iter().skip(1) {
223-
e.span_note(*other_span, "another `self` import appears here");
223+
e.span_label(*other_span, "another `self` import appears here");
224224
}
225225

226226
e.emit();

src/librustc_resolve/lib.rs

+20-22
Original file line numberDiff line numberDiff line change
@@ -290,17 +290,17 @@ fn resolve_struct_error<'sess, 'a>(resolver: &'sess Resolver,
290290
"`self` imports are only allowed within a { } list")
291291
}
292292
ResolutionError::SelfImportCanOnlyAppearOnceInTheList => {
293-
struct_span_err!(resolver.session,
294-
span,
295-
E0430,
296-
"`self` import can only appear once in the list")
293+
let mut err = struct_span_err!(resolver.session, span, E0430,
294+
"`self` import can only appear once in an import list");
295+
err.span_label(span, "can only appear once in an import list");
296+
err
297297
}
298298
ResolutionError::SelfImportOnlyInImportListWithNonEmptyPrefix => {
299-
struct_span_err!(resolver.session,
300-
span,
301-
E0431,
302-
"`self` import can only appear in an import list with a \
303-
non-empty prefix")
299+
let mut err = struct_span_err!(resolver.session, span, E0431,
300+
"`self` import can only appear in an import list with \
301+
a non-empty prefix");
302+
err.span_label(span, "can only appear in an import list with a non-empty prefix");
303+
err
304304
}
305305
ResolutionError::UnresolvedImport(name) => {
306306
let (span, msg) = match name {
@@ -320,18 +320,17 @@ fn resolve_struct_error<'sess, 'a>(resolver: &'sess Resolver,
320320
err
321321
}
322322
ResolutionError::CannotCaptureDynamicEnvironmentInFnItem => {
323-
struct_span_err!(resolver.session,
324-
span,
325-
E0434,
326-
"{}",
327-
"can't capture dynamic environment in a fn item; use the || { ... } \
328-
closure form instead")
323+
let mut err = struct_span_err!(resolver.session,
324+
span,
325+
E0434,
326+
"{}",
327+
"can't capture dynamic environment in a fn item");
328+
err.help("use the `|| { ... }` closure form instead");
329+
err
329330
}
330331
ResolutionError::AttemptToUseNonConstantValueInConstant => {
331-
let mut err = struct_span_err!(resolver.session,
332-
span,
333-
E0435,
334-
"attempt to use a non-constant value in a constant");
332+
let mut err = struct_span_err!(resolver.session, span, E0435,
333+
"attempt to use a non-constant value in a constant");
335334
err.span_label(span, "non-constant value");
336335
err
337336
}
@@ -351,8 +350,7 @@ fn resolve_struct_error<'sess, 'a>(resolver: &'sess Resolver,
351350
let mut err = struct_span_err!(resolver.session, span, E0128,
352351
"type parameters with a default cannot use \
353352
forward declared identifiers");
354-
err.span_label(span, format!("defaulted type parameters \
355-
cannot be forward declared"));
353+
err.span_label(span, format!("defaulted type parameters cannot be forward declared"));
356354
err
357355
}
358356
}
@@ -3950,7 +3948,7 @@ impl<'a> Resolver<'a> {
39503948

39513949
feature_err(&self.session.parse_sess, feature,
39523950
attr.span, GateIssue::Language, msg)
3953-
.span_note(binding.span(), "procedural macro imported here")
3951+
.span_label(binding.span(), "procedural macro imported here")
39543952
.emit();
39553953
}
39563954
}

src/test/compile-fail/bad-env-capture.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// error-pattern: can't capture dynamic environment in a fn item;
11+
// error-pattern: can't capture dynamic environment in a fn item
1212
fn foo() {
1313
let x: isize;
1414
fn bar() { log(debug, x); }

src/test/compile-fail/bad-env-capture2.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// error-pattern: can't capture dynamic environment in a fn item;
11+
// error-pattern: can't capture dynamic environment in a fn item
1212
fn foo(x: isize) {
1313
fn bar() { log(debug, x); }
1414
}

src/test/compile-fail/bad-env-capture3.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// error-pattern: can't capture dynamic environment in a fn item;
11+
// error-pattern: can't capture dynamic environment in a fn item
1212
fn foo(x: isize) {
1313
fn mth() {
1414
fn bar() { log(debug, x); }

src/test/compile-fail/capture1.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// except according to those terms.
1010

1111

12-
// error-pattern: can't capture dynamic environment in a fn item;
12+
// error-pattern: can't capture dynamic environment in a fn item
1313

1414
fn main() {
1515
let bar: isize = 5;

src/test/ui/issue-24036.stderr

+4-32
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,8 @@ error[E0308]: mismatched types
66
|
77
= note: expected type `[closure@$DIR/issue-24036.rs:12:17: 12:26]`
88
found type `[closure@$DIR/issue-24036.rs:13:9: 13:18]`
9-
note: no two closures, even if identical, have the same type
10-
--> $DIR/issue-24036.rs:13:9
11-
|
12-
13 | x = |c| c + 1;
13-
| ^^^^^^^^^
14-
help: consider boxing your closure and/or using it as a trait object
15-
--> $DIR/issue-24036.rs:13:9
16-
|
17-
13 | x = |c| c + 1;
18-
| ^^^^^^^^^
9+
= note: no two closures, even if identical, have the same type
10+
= help: consider boxing your closure and/or using it as a trait object
1911

2012
error[E0308]: match arms have incompatible types
2113
--> $DIR/issue-24036.rs:18:13
@@ -31,28 +23,8 @@ error[E0308]: match arms have incompatible types
3123
|
3224
= note: expected type `[closure@$DIR/issue-24036.rs:20:14: 20:23]`
3325
found type `[closure@$DIR/issue-24036.rs:21:14: 21:23]`
34-
note: no two closures, even if identical, have the same type
35-
--> $DIR/issue-24036.rs:18:13
36-
|
37-
18 | let x = match 1usize {
38-
| _____________^
39-
19 | | //~^ ERROR match arms have incompatible types
40-
20 | | 1 => |c| c + 1,
41-
21 | | 2 => |c| c - 1,
42-
22 | | _ => |c| c - 1
43-
23 | | };
44-
| |_____^
45-
help: consider boxing your closure and/or using it as a trait object
46-
--> $DIR/issue-24036.rs:18:13
47-
|
48-
18 | let x = match 1usize {
49-
| _____________^
50-
19 | | //~^ ERROR match arms have incompatible types
51-
20 | | 1 => |c| c + 1,
52-
21 | | 2 => |c| c - 1,
53-
22 | | _ => |c| c - 1
54-
23 | | };
55-
| |_____^
26+
= note: no two closures, even if identical, have the same type
27+
= help: consider boxing your closure and/or using it as a trait object
5628
note: match arm with an incompatible type
5729
--> $DIR/issue-24036.rs:21:14
5830
|

src/test/ui/issue-30302.stderr

+4-6
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,17 @@ warning[E0170]: pattern binding `Nil` is named the same as one of the variants o
99
error: unreachable pattern
1010
--> $DIR/issue-30302.rs:25:9
1111
|
12+
23 | Nil => true,
13+
| --- matches any value
14+
24 | //~^ WARN pattern binding `Nil` is named the same as one of the variants of the type `Stack`
1215
25 | _ => false
13-
| ^ this is an unreachable pattern
16+
| ^ unreachable pattern
1417
|
1518
note: lint level defined here
1619
--> $DIR/issue-30302.rs:14:9
1720
|
1821
14 | #![deny(unreachable_patterns)]
1922
| ^^^^^^^^^^^^^^^^^^^^
20-
note: this pattern matches any value
21-
--> $DIR/issue-30302.rs:23:9
22-
|
23-
23 | Nil => true,
24-
| ^^^
2523

2624
error: aborting due to previous error
2725

src/test/ui/issue-31221.stderr

+9-20
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,32 @@
11
error: unreachable pattern
22
--> $DIR/issue-31221.rs:28:9
33
|
4+
27 | Var3 => (),
5+
| ---- matches any value
46
28 | Var2 => (),
5-
| ^^^^ this is an unreachable pattern
7+
| ^^^^ unreachable pattern
68
|
79
note: lint level defined here
810
--> $DIR/issue-31221.rs:14:9
911
|
1012
14 | #![deny(unreachable_patterns)]
1113
| ^^^^^^^^^^^^^^^^^^^^
12-
note: this pattern matches any value
13-
--> $DIR/issue-31221.rs:27:9
14-
|
15-
27 | Var3 => (),
16-
| ^^^^
1714

1815
error: unreachable pattern
1916
--> $DIR/issue-31221.rs:34:9
2017
|
21-
34 | &Var2 => (),
22-
| ^^^^^ this is an unreachable pattern
23-
|
24-
note: this pattern matches any value
25-
--> $DIR/issue-31221.rs:33:9
26-
|
2718
33 | &Var3 => (),
28-
| ^^^^^
19+
| ----- matches any value
20+
34 | &Var2 => (),
21+
| ^^^^^ unreachable pattern
2922

3023
error: unreachable pattern
3124
--> $DIR/issue-31221.rs:41:9
3225
|
33-
41 | anything => ()
34-
| ^^^^^^^^ this is an unreachable pattern
35-
|
36-
note: this pattern matches any value
37-
--> $DIR/issue-31221.rs:40:9
38-
|
3926
40 | (c, d) => (),
40-
| ^^^^^^
27+
| ------ matches any value
28+
41 | anything => ()
29+
| ^^^^^^^^ unreachable pattern
4130

4231
error: aborting due to 3 previous errors
4332

src/test/ui/use-mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
use foo::bar::{
1212
self,
13-
//~^ ERROR `self` import can only appear once in the list
13+
//~^ ERROR `self` import can only appear once in an import list
1414
Bar,
1515
self
1616
//~^ ERROR the name `bar` is defined multiple times

src/test/ui/use-mod.stderr

+5-8
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
1-
error[E0430]: `self` import can only appear once in the list
1+
error[E0430]: `self` import can only appear once in an import list
22
--> $DIR/use-mod.rs:12:5
33
|
44
12 | self,
5-
| ^^^^
6-
|
7-
note: another `self` import appears here
8-
--> $DIR/use-mod.rs:15:5
9-
|
5+
| ^^^^ can only appear once in an import list
6+
...
107
15 | self
11-
| ^^^^
8+
| ---- another `self` import appears here
129

1310
error[E0431]: `self` import can only appear in an import list with a non-empty prefix
1411
--> $DIR/use-mod.rs:19:6
1512
|
1613
19 | use {self};
17-
| ^^^^
14+
| ^^^^ can only appear in an import list with a non-empty prefix
1815

1916
error[E0252]: the name `bar` is defined multiple times
2017
--> $DIR/use-mod.rs:15:5

0 commit comments

Comments
 (0)