Skip to content

Commit 6e723c2

Browse files
committed
Never stop due to errors before borrow checking
1 parent c21fbfe commit 6e723c2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+409
-108
lines changed

src/librustc_interface/passes.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -936,13 +936,6 @@ fn analysis<'tcx>(
936936
});
937937
});
938938

939-
// Abort so we don't try to construct MIR with liveness errors.
940-
// We also won't want to continue with errors from rvalue promotion
941-
// We only do so if the only error found so far *isn't* a missing `fn main()`
942-
if !(entry_point.is_none() && sess.err_count() == 1) {
943-
tcx.sess.abort_if_errors();
944-
}
945-
946939
time(sess, "borrow checking", || {
947940
if tcx.use_ast_borrowck() {
948941
borrowck::check_crate(tcx);

src/librustc_mir/hair/pattern/check_match.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,9 @@ fn check_legality_of_move_bindings(
603603
E0009,
604604
"cannot bind by-move and by-ref in the same pattern",
605605
);
606-
err.span_label(by_ref_span.unwrap(), "both by-ref and by-move used");
606+
if let Some(by_ref_span) = by_ref_span {
607+
err.span_label(by_ref_span, "both by-ref and by-move used");
608+
}
607609
for span in span_vec.iter(){
608610
err.span_label(*span, "by-move pattern here");
609611
}

src/librustc_mir/transform/qualify_consts.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1502,9 +1502,11 @@ impl MirPass for QualifyAndPromoteConstants {
15021502
tcx.sess,
15031503
span,
15041504
E0723,
1505-
"{} (see issue #57563)",
1505+
"{}",
15061506
err,
15071507
);
1508+
diag.note("for more information, see issue \
1509+
https://github.com/rust-lang/rust/issues/57563");
15081510
diag.help(
15091511
"add #![feature(const_fn)] to the crate attributes to enable",
15101512
);

src/test/ui/borrowck/borrowck-mutate-in-guard.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,15 @@ fn foo() -> isize {
99
match x {
1010
Enum::A(_) if { x = Enum::B(false); false } => 1,
1111
//~^ ERROR cannot assign in a pattern guard
12+
//~| WARN cannot assign `x` in match guard
13+
//~| WARN this error has been downgraded to a warning for backwards compatibility
14+
//~| WARN this represents potential undefined behavior in your code and this warning will
1215
Enum::A(_) if { let y = &mut x; *y = Enum::B(false); false } => 1,
1316
//~^ ERROR cannot mutably borrow in a pattern guard
14-
//~^^ ERROR cannot assign in a pattern guard
17+
//~| ERROR cannot assign in a pattern guard
18+
//~| WARN cannot mutably borrow `x` in match guard
19+
//~| WARN this error has been downgraded to a warning for backwards compatibility
20+
//~| WARN this represents potential undefined behavior in your code and this warning will
1521
Enum::A(p) => *p,
1622
Enum::B(_) => 2,
1723
}

src/test/ui/borrowck/borrowck-mutate-in-guard.stderr

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,43 @@ LL | Enum::A(_) if { x = Enum::B(false); false } => 1,
55
| ^^^^^^^^^^^^^^^^^^ assignment in pattern guard
66

77
error[E0301]: cannot mutably borrow in a pattern guard
8-
--> $DIR/borrowck-mutate-in-guard.rs:12:38
8+
--> $DIR/borrowck-mutate-in-guard.rs:15:38
99
|
1010
LL | Enum::A(_) if { let y = &mut x; *y = Enum::B(false); false } => 1,
1111
| ^ borrowed mutably in pattern guard
1212
|
1313
= help: add #![feature(bind_by_move_pattern_guards)] to the crate attributes to enable
1414

1515
error[E0302]: cannot assign in a pattern guard
16-
--> $DIR/borrowck-mutate-in-guard.rs:12:41
16+
--> $DIR/borrowck-mutate-in-guard.rs:15:41
1717
|
1818
LL | Enum::A(_) if { let y = &mut x; *y = Enum::B(false); false } => 1,
1919
| ^^^^^^^^^^^^^^^^^^^ assignment in pattern guard
2020

21+
warning[E0510]: cannot assign `x` in match guard
22+
--> $DIR/borrowck-mutate-in-guard.rs:10:25
23+
|
24+
LL | match x {
25+
| - value is immutable in match guard
26+
LL | Enum::A(_) if { x = Enum::B(false); false } => 1,
27+
| ^^^^^^^^^^^^^^^^^^ cannot assign
28+
|
29+
= warning: this error has been downgraded to a warning for backwards compatibility with previous releases
30+
= warning: this represents potential undefined behavior in your code and this warning will become a hard error in the future
31+
32+
warning[E0510]: cannot mutably borrow `x` in match guard
33+
--> $DIR/borrowck-mutate-in-guard.rs:15:33
34+
|
35+
LL | match x {
36+
| - value is immutable in match guard
37+
...
38+
LL | Enum::A(_) if { let y = &mut x; *y = Enum::B(false); false } => 1,
39+
| ^^^^^^ cannot mutably borrow
40+
|
41+
= warning: this error has been downgraded to a warning for backwards compatibility with previous releases
42+
= warning: this represents potential undefined behavior in your code and this warning will become a hard error in the future
43+
2144
error: aborting due to 3 previous errors
2245

23-
Some errors have detailed explanations: E0301, E0302.
46+
Some errors have detailed explanations: E0301, E0302, E0510.
2447
For more information about an error, try `rustc --explain E0301`.
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
fn main() {}
22

33
const fn slice([a, b]: &[i32]) -> i32 { //~ ERROR refutable pattern in function argument
4-
a + b
4+
a + b //~ ERROR can only call other `const fn` within a `const fn`
5+
//~^ WARN use of possibly uninitialized variable: `a`
6+
//~| WARN this error has been downgraded to a warning for backwards compatibility
7+
//~| WARN this represents potential undefined behavior in your code and this warning will
8+
//~| WARN use of possibly uninitialized variable: `b`
9+
//~| WARN this error has been downgraded to a warning for backwards compatibility
10+
//~| WARN this represents potential undefined behavior in your code and this warning will
511
}

src/test/ui/consts/const_let_refutable.stderr

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,34 @@ error[E0005]: refutable pattern in function argument: `&[]` not covered
44
LL | const fn slice([a, b]: &[i32]) -> i32 {
55
| ^^^^^^ pattern `&[]` not covered
66

7-
error: aborting due to previous error
7+
error[E0723]: can only call other `const fn` within a `const fn`, but `const std::ops::Add::add` is not stable as `const fn`
8+
--> $DIR/const_let_refutable.rs:4:5
9+
|
10+
LL | a + b
11+
| ^^^^^
12+
|
13+
= note: for more information, see issue https://github.com/rust-lang/rust/issues/57563
14+
= help: add #![feature(const_fn)] to the crate attributes to enable
15+
16+
warning[E0381]: use of possibly uninitialized variable: `a`
17+
--> $DIR/const_let_refutable.rs:4:5
18+
|
19+
LL | a + b
20+
| ^ use of possibly uninitialized `a`
21+
|
22+
= warning: this error has been downgraded to a warning for backwards compatibility with previous releases
23+
= warning: this represents potential undefined behavior in your code and this warning will become a hard error in the future
24+
25+
warning[E0381]: use of possibly uninitialized variable: `b`
26+
--> $DIR/const_let_refutable.rs:4:9
27+
|
28+
LL | a + b
29+
| ^ use of possibly uninitialized `b`
30+
|
31+
= warning: this error has been downgraded to a warning for backwards compatibility with previous releases
32+
= warning: this represents potential undefined behavior in your code and this warning will become a hard error in the future
33+
34+
error: aborting due to 2 previous errors
835

9-
For more information about this error, try `rustc --explain E0005`.
36+
Some errors have detailed explanations: E0005, E0381, E0723.
37+
For more information about an error, try `rustc --explain E0005`.

src/test/ui/consts/match_ice.stderr

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
error[E0004]: non-exhaustive patterns: `&S` not covered
2-
--> $DIR/match_ice.rs:7:11
2+
--> $DIR/match_ice.rs:8:11
33
|
44
LL | match C {
55
| ^ pattern `&S` not covered
66
|
77
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
88

9-
error: aborting due to previous error
9+
error[E0277]: can't compare `S` with `S`
10+
|
11+
= help: the trait `std::cmp::PartialEq` is not implemented for `S`
12+
= note: required because of the requirements on the impl of `std::cmp::PartialEq` for `&S`
13+
14+
error: aborting due to 2 previous errors
1015

11-
For more information about this error, try `rustc --explain E0004`.
16+
Some errors occurred: E0004, E0277.
17+
For more information about an error, try `rustc --explain E0004`.

src/test/ui/consts/min_const_fn/bad_const_fn_body_ice.stderr

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
error[E0723]: heap allocations are not allowed in const fn (see issue #57563)
1+
error[E0723]: heap allocations are not allowed in const fn
22
--> $DIR/bad_const_fn_body_ice.rs:2:5
33
|
44
LL | vec![1, 2, 3]
55
| ^^^^^^^^^^^^^
66
|
7+
= note: for more information, see issue https://github.com/rust-lang/rust/issues/57563
78
= help: add #![feature(const_fn)] to the crate attributes to enable
89
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
910

src/test/ui/consts/min_const_fn/cast_errors.stderr

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,46 @@
1-
error[E0723]: unsizing casts are not allowed in const fn (see issue #57563)
1+
error[E0723]: unsizing casts are not allowed in const fn
22
--> $DIR/cast_errors.rs:3:41
33
|
44
LL | const fn unsize(x: &[u8; 3]) -> &[u8] { x }
55
| ^
66
|
7+
= note: for more information, see issue https://github.com/rust-lang/rust/issues/57563
78
= help: add #![feature(const_fn)] to the crate attributes to enable
89

9-
error[E0723]: function pointers in const fn are unstable (see issue #57563)
10+
error[E0723]: function pointers in const fn are unstable
1011
--> $DIR/cast_errors.rs:5:23
1112
|
1213
LL | const fn closure() -> fn() { || {} }
1314
| ^^^^
1415
|
16+
= note: for more information, see issue https://github.com/rust-lang/rust/issues/57563
1517
= help: add #![feature(const_fn)] to the crate attributes to enable
1618

17-
error[E0723]: function pointers in const fn are unstable (see issue #57563)
19+
error[E0723]: function pointers in const fn are unstable
1820
--> $DIR/cast_errors.rs:8:5
1921
|
2022
LL | (|| {}) as fn();
2123
| ^^^^^^^^^^^^^^^
2224
|
25+
= note: for more information, see issue https://github.com/rust-lang/rust/issues/57563
2326
= help: add #![feature(const_fn)] to the crate attributes to enable
2427

25-
error[E0723]: function pointers in const fn are unstable (see issue #57563)
28+
error[E0723]: function pointers in const fn are unstable
2629
--> $DIR/cast_errors.rs:11:28
2730
|
2831
LL | const fn reify(f: fn()) -> unsafe fn() { f }
2932
| ^^^^^^^^^^^
3033
|
34+
= note: for more information, see issue https://github.com/rust-lang/rust/issues/57563
3135
= help: add #![feature(const_fn)] to the crate attributes to enable
3236

33-
error[E0723]: function pointers in const fn are unstable (see issue #57563)
37+
error[E0723]: function pointers in const fn are unstable
3438
--> $DIR/cast_errors.rs:13:21
3539
|
3640
LL | const fn reify2() { main as unsafe fn(); }
3741
| ^^^^^^^^^^^^^^^^^^^
3842
|
43+
= note: for more information, see issue https://github.com/rust-lang/rust/issues/57563
3944
= help: add #![feature(const_fn)] to the crate attributes to enable
4045

4146
error: aborting due to 5 previous errors

src/test/ui/consts/min_const_fn/cmp_fn_pointers.stderr

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
error[E0723]: function pointers in const fn are unstable (see issue #57563)
1+
error[E0723]: function pointers in const fn are unstable
22
--> $DIR/cmp_fn_pointers.rs:1:14
33
|
44
LL | const fn cmp(x: fn(), y: fn()) -> bool {
55
| ^
66
|
7+
= note: for more information, see issue https://github.com/rust-lang/rust/issues/57563
78
= help: add #![feature(const_fn)] to the crate attributes to enable
89

910
error: aborting due to previous error

src/test/ui/consts/min_const_fn/loop_ice.stderr

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
error[E0723]: loops are not allowed in const fn (see issue #57563)
1+
error[E0723]: loops are not allowed in const fn
22
--> $DIR/loop_ice.rs:2:5
33
|
44
LL | loop {}
55
| ^^^^^^^
66
|
7+
= note: for more information, see issue https://github.com/rust-lang/rust/issues/57563
78
= help: add #![feature(const_fn)] to the crate attributes to enable
89

910
error: aborting due to previous error

0 commit comments

Comments
 (0)