Skip to content

Commit 5b67e97

Browse files
authored
Unrolled build for rust-lang#127202
Rollup merge of rust-lang#127202 - oli-obk:do_not_count_errors, r=wesleywiser Remove global error count checks from typeck Some of these are not reachable anymore, others can now rely on information local to the current typeck run. One check was actually invalid, because it was relying on wfcheck running before typeck, which is not guaranteed in the query system and usually easy to create ICEing examples for via const eval (which runs typeck before wfcheck)
2 parents 1086aff + 814bfe9 commit 5b67e97

8 files changed

+87
-31
lines changed

compiler/rustc_hir_typeck/src/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
708708
// else an error would have been flagged by the
709709
// `loops` pass for using break with an expression
710710
// where you are not supposed to.
711-
assert!(expr_opt.is_none() || self.dcx().has_errors().is_some());
711+
assert!(expr_opt.is_none() || self.tainted_by_errors().is_some());
712712
}
713713

714714
// If we encountered a `break`, then (no surprise) it may be possible to break from the

compiler/rustc_hir_typeck/src/expr_use_visitor.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -734,9 +734,7 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
734734
// struct; however, when EUV is run during typeck, it
735735
// may not. This will generate an error earlier in typeck,
736736
// so we can just ignore it.
737-
if self.cx.tcx().dcx().has_errors().is_none() {
738-
span_bug!(with_expr.span, "with expression doesn't evaluate to a struct");
739-
}
737+
span_bug!(with_expr.span, "with expression doesn't evaluate to a struct");
740738
}
741739
}
742740

compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1652,7 +1652,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
16521652

16531653
self.warn_if_unreachable(stmt.hir_id, stmt.span, "statement");
16541654

1655-
// Hide the outer diverging and `has_errors` flags.
1655+
// Hide the outer diverging flags.
16561656
let old_diverges = self.diverges.replace(Diverges::Maybe);
16571657

16581658
match stmt.kind {

compiler/rustc_hir_typeck/src/method/confirm.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -510,9 +510,12 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
510510
.report_mismatched_types(&cause, method_self_ty, self_ty, terr)
511511
.emit();
512512
} else {
513-
error!("{self_ty} was a subtype of {method_self_ty} but now is not?");
514-
// This must already have errored elsewhere.
515-
self.dcx().has_errors().unwrap();
513+
// This has/will have errored in wfcheck, which we cannot depend on from here, as typeck on functions
514+
// may run before wfcheck if the function is used in const eval.
515+
self.dcx().span_delayed_bug(
516+
cause.span(),
517+
format!("{self_ty} was a subtype of {method_self_ty} but now is not?"),
518+
);
516519
}
517520
}
518521
}

compiler/rustc_hir_typeck/src/writeback.rs

+3-22
Original file line numberDiff line numberDiff line change
@@ -219,28 +219,9 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
219219
fn fix_index_builtin_expr(&mut self, e: &hir::Expr<'_>) {
220220
if let hir::ExprKind::Index(ref base, ref index, _) = e.kind {
221221
// All valid indexing looks like this; might encounter non-valid indexes at this point.
222-
let base_ty = self.typeck_results.expr_ty_adjusted_opt(base);
223-
if base_ty.is_none() {
224-
// When encountering `return [0][0]` outside of a `fn` body we can encounter a base
225-
// that isn't in the type table. We assume more relevant errors have already been
226-
// emitted. (#64638)
227-
assert!(self.tcx().dcx().has_errors().is_some(), "bad base: `{base:?}`");
228-
}
229-
if let Some(base_ty) = base_ty
230-
&& let ty::Ref(_, base_ty_inner, _) = *base_ty.kind()
231-
{
232-
let index_ty =
233-
self.typeck_results.expr_ty_adjusted_opt(index).unwrap_or_else(|| {
234-
// When encountering `return [0][0]` outside of a `fn` body we would attempt
235-
// to access an nonexistent index. We assume that more relevant errors will
236-
// already have been emitted, so we only gate on this with an ICE if no
237-
// error has been emitted. (#64638)
238-
Ty::new_error_with_message(
239-
self.fcx.tcx,
240-
e.span,
241-
format!("bad index {index:?} for base: `{base:?}`"),
242-
)
243-
});
222+
let base_ty = self.typeck_results.expr_ty_adjusted(base);
223+
if let ty::Ref(_, base_ty_inner, _) = *base_ty.kind() {
224+
let index_ty = self.typeck_results.expr_ty_adjusted(index);
244225
if self.is_builtin_index(e, base_ty_inner, index_ty) {
245226
// Remove the method call record
246227
self.typeck_results.type_dependent_defs_mut().remove(e.hir_id);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//! The same as the non-ICE test, but const eval will run typeck of
2+
//! `get` before running wfcheck (as that may in itself trigger const
3+
//! eval again, and thus cause bogus cycles). This used to ICE because
4+
//! we asserted that an error had already been emitted.
5+
6+
use std::ops::Deref;
7+
8+
struct Foo(u32);
9+
impl Foo {
10+
const fn get<R: Deref<Target = Self>>(self: R) -> u32 {
11+
//~^ ERROR: `R` cannot be used as the type of `self`
12+
//~| ERROR destructor of `R` cannot be evaluated at compile-time
13+
self.0
14+
//~^ ERROR cannot borrow here, since the borrowed element may contain interior mutability
15+
//~| ERROR cannot call non-const fn `<R as Deref>::deref` in constant function
16+
}
17+
}
18+
19+
const FOO: () = {
20+
let foo = Foo(1);
21+
foo.get::<&Foo>();
22+
};
23+
24+
const BAR: [(); {
25+
FOO;
26+
0
27+
}] = [];
28+
29+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
error[E0658]: cannot borrow here, since the borrowed element may contain interior mutability
2+
--> $DIR/arbitrary-self-from-method-substs-ice.rs:13:9
3+
|
4+
LL | self.0
5+
| ^^^^
6+
|
7+
= note: see issue #80384 <https://github.com/rust-lang/rust/issues/80384> for more information
8+
= help: add `#![feature(const_refs_to_cell)]` to the crate attributes to enable
9+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
10+
11+
error[E0015]: cannot call non-const fn `<R as Deref>::deref` in constant functions
12+
--> $DIR/arbitrary-self-from-method-substs-ice.rs:13:9
13+
|
14+
LL | self.0
15+
| ^^^^^^
16+
|
17+
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
18+
help: add `#![feature(const_trait_impl)]` to the crate attributes to enable
19+
|
20+
LL + #![feature(const_trait_impl)]
21+
|
22+
23+
error[E0493]: destructor of `R` cannot be evaluated at compile-time
24+
--> $DIR/arbitrary-self-from-method-substs-ice.rs:10:43
25+
|
26+
LL | const fn get<R: Deref<Target = Self>>(self: R) -> u32 {
27+
| ^^^^ the destructor for this type cannot be evaluated in constant functions
28+
...
29+
LL | }
30+
| - value is dropped here
31+
32+
error[E0658]: `R` cannot be used as the type of `self` without the `arbitrary_self_types` feature
33+
--> $DIR/arbitrary-self-from-method-substs-ice.rs:10:49
34+
|
35+
LL | const fn get<R: Deref<Target = Self>>(self: R) -> u32 {
36+
| ^
37+
|
38+
= note: see issue #44874 <https://github.com/rust-lang/rust/issues/44874> for more information
39+
= help: add `#![feature(arbitrary_self_types)]` to the crate attributes to enable
40+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
41+
= help: consider changing to `self`, `&self`, `&mut self`, `self: Box<Self>`, `self: Rc<Self>`, `self: Arc<Self>`, or `self: Pin<P>` (where P is one of the previous types except `Self`)
42+
43+
error: aborting due to 4 previous errors
44+
45+
Some errors have detailed explanations: E0015, E0493, E0658.
46+
For more information about an error, try `rustc --explain E0015`.

tests/ui/self/arbitrary-self-from-method-substs.default.stderr

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ LL | fn get<R: Deref<Target = Self>>(self: R) -> u32 {
99
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
1010
= help: consider changing to `self`, `&self`, `&mut self`, `self: Box<Self>`, `self: Rc<Self>`, `self: Arc<Self>`, or `self: Pin<P>` (where P is one of the previous types except `Self`)
1111

12-
ERROR rustc_hir_typeck::method::confirm Foo was a subtype of &Foo but now is not?
1312
error: aborting due to 1 previous error
1413

1514
For more information about this error, try `rustc --explain E0658`.

0 commit comments

Comments
 (0)