Skip to content

Commit 31f5d69

Browse files
committed
Auto merge of #60125 - estebank:continue-evaluating, r=oli-obk
Don't stop evaluating due to errors before borrow checking r? @oli-obk Fix #60005. Follow up to #59903. Blocked on #53708, fixing the ICE in `src/test/ui/consts/match_ice.rs`.
2 parents 0f11354 + 87ef96d commit 31f5d69

Some content is hidden

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

55 files changed

+449
-125
lines changed

src/librustc/traits/codegen/mod.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55

66
use crate::dep_graph::{DepKind, DepTrackingMapConfig};
77
use std::marker::PhantomData;
8-
use syntax_pos::DUMMY_SP;
98
use crate::infer::InferCtxt;
10-
use syntax_pos::Span;
119
use crate::traits::{FulfillmentContext, Obligation, ObligationCause, SelectionContext,
1210
TraitEngine, Vtable};
1311
use crate::ty::{self, Ty, TyCtxt};
@@ -69,7 +67,7 @@ pub fn codegen_fulfill_obligation<'a, 'tcx>(ty: TyCtxt<'a, 'tcx, 'tcx>,
6967
debug!("fulfill_obligation: register_predicate_obligation {:?}", predicate);
7068
fulfill_cx.register_predicate_obligation(&infcx, predicate);
7169
});
72-
let vtable = infcx.drain_fulfillment_cx_or_panic(DUMMY_SP, &mut fulfill_cx, &vtable);
70+
let vtable = infcx.drain_fulfillment_cx_or_panic(&mut fulfill_cx, &vtable);
7371

7472
info!("Cache miss: {:?} => {:?}", trait_ref, vtable);
7573
vtable
@@ -141,7 +139,6 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
141139
/// unified, and hence we need to process those obligations to get
142140
/// the complete picture of the type.
143141
fn drain_fulfillment_cx_or_panic<T>(&self,
144-
span: Span,
145142
fulfill_cx: &mut FulfillmentContext<'tcx>,
146143
result: &T)
147144
-> T::Lifted
@@ -153,15 +150,14 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
153150
// contains unbound type parameters. It could be a slight
154151
// optimization to stop iterating early.
155152
if let Err(errors) = fulfill_cx.select_all_or_error(self) {
156-
span_bug!(span, "Encountered errors `{:?}` resolving bounds after type-checking",
157-
errors);
153+
bug!("Encountered errors `{:?}` resolving bounds after type-checking", errors);
158154
}
159155

160156
let result = self.resolve_type_vars_if_possible(result);
161157
let result = self.tcx.erase_regions(&result);
162158

163159
self.tcx.lift_to_global(&result).unwrap_or_else(||
164-
span_bug!(span, "Uninferred types/regions in `{:?}`", result)
160+
bug!("Uninferred types/regions in `{:?}`", result)
165161
)
166162
}
167163
}

src/librustc/ty/sty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ impl BoundRegion {
8585
/// N.B., if you change this, you'll probably want to change the corresponding
8686
/// AST structure in `libsyntax/ast.rs` as well.
8787
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash,
88-
RustcEncodable, RustcDecodable, HashStable)]
88+
RustcEncodable, RustcDecodable, HashStable, Debug)]
8989
pub enum TyKind<'tcx> {
9090
/// The primitive boolean type. Written as `bool`.
9191
Bool,

src/librustc_interface/passes.rs

-7
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/_match.rs

+2
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ impl<'a, 'tcx> LiteralExpander<'a, 'tcx> {
211211
// the constant's pointee type
212212
crty: Ty<'tcx>,
213213
) -> ConstValue<'tcx> {
214+
debug!("fold_const_value_deref {:?} {:?} {:?}", val, rty, crty);
214215
match (val, &crty.sty, &rty.sty) {
215216
// the easy case, deref a reference
216217
(ConstValue::Scalar(Scalar::Ptr(p)), x, y) if x == y => ConstValue::ByRef(
@@ -238,6 +239,7 @@ impl<'a, 'tcx> LiteralExpander<'a, 'tcx> {
238239

239240
impl<'a, 'tcx> PatternFolder<'tcx> for LiteralExpander<'a, 'tcx> {
240241
fn fold_pattern(&mut self, pat: &Pattern<'tcx>) -> Pattern<'tcx> {
242+
debug!("fold_pattern {:?} {:?} {:?}", pat, pat.ty.sty, pat.kind);
241243
match (&pat.ty.sty, &*pat.kind) {
242244
(
243245
&ty::Ref(_, rty, _),

src/librustc_mir/hair/pattern/check_match.rs

+3-1
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/hair/pattern/mod.rs

+21-4
Original file line numberDiff line numberDiff line change
@@ -974,10 +974,27 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> {
974974
PatternKind::Wild
975975
}
976976
ty::Adt(adt_def, _) if !self.tcx.has_attr(adt_def.did, "structural_match") => {
977-
let msg = format!("to use a constant of type `{}` in a pattern, \
978-
`{}` must be annotated with `#[derive(PartialEq, Eq)]`",
979-
self.tcx.def_path_str(adt_def.did),
980-
self.tcx.def_path_str(adt_def.did));
977+
let path = self.tcx.def_path_str(adt_def.did);
978+
let msg = format!(
979+
"to use a constant of type `{}` in a pattern, \
980+
`{}` must be annotated with `#[derive(PartialEq, Eq)]`",
981+
path,
982+
path,
983+
);
984+
self.tcx.sess.span_err(span, &msg);
985+
PatternKind::Wild
986+
}
987+
ty::Ref(_, ty::TyS { sty: ty::Adt(adt_def, _), .. }, _)
988+
if !self.tcx.has_attr(adt_def.did, "structural_match") => {
989+
// HACK(estebank): Side-step ICE #53708, but anything other than erroring here
990+
// would be wrong. Returnging `PatternKind::Wild` is not technically correct.
991+
let path = self.tcx.def_path_str(adt_def.did);
992+
let msg = format!(
993+
"to use a constant of type `{}` in a pattern, \
994+
`{}` must be annotated with `#[derive(PartialEq, Eq)]`",
995+
path,
996+
path,
997+
);
981998
self.tcx.sess.span_err(span, &msg);
982999
PatternKind::Wild
9831000
}

src/librustc_mir/transform/qualify_consts.rs

+3-1
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

+7-1
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

+26-3
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`.
+7-1
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

+30-2
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.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,17 @@
22

33
struct S;
44

5+
#[derive(PartialEq, Eq)]
6+
struct T;
7+
58
fn main() {
69
const C: &S = &S;
7-
match C { //~ ERROR non-exhaustive
8-
C => {} // this is a common bug around constants and references in patterns
10+
match C {
11+
C => {}
12+
//~^ ERROR to use a constant of type `S` in a pattern, `S` must be annotated with
13+
}
14+
const K: &T = &T;
15+
match K { //~ ERROR non-exhaustive patterns: `&T` not covered
16+
K => {}
917
}
1018
}

src/test/ui/consts/match_ice.stderr

+11-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1-
error[E0004]: non-exhaustive patterns: `&S` not covered
2-
--> $DIR/match_ice.rs:7:11
1+
error: to use a constant of type `S` in a pattern, `S` must be annotated with `#[derive(PartialEq, Eq)]`
2+
--> $DIR/match_ice.rs:11:9
33
|
4-
LL | match C {
5-
| ^ pattern `&S` not covered
4+
LL | C => {}
5+
| ^
6+
7+
error[E0004]: non-exhaustive patterns: `&T` not covered
8+
--> $DIR/match_ice.rs:15:11
9+
|
10+
LL | match K {
11+
| ^ pattern `&T` not covered
612
|
713
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
814

9-
error: aborting due to previous error
15+
error: aborting due to 2 previous errors
1016

1117
For more information about this error, try `rustc --explain E0004`.

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

+2-1
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

+10-5
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

+2-1
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

+2-1
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)