Skip to content

Commit ac45a67

Browse files
committed
Use delayed bug for normalization errors in drop elaboration
Normalization can fail from errors from other items so use a delayed bug instead of checking the body.
1 parent 71b68da commit ac45a67

File tree

5 files changed

+70
-10
lines changed

5 files changed

+70
-10
lines changed

compiler/rustc_mir_transform/src/elaborate_drop.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -266,19 +266,16 @@ where
266266
let tcx = self.tcx();
267267

268268
assert_eq!(self.elaborator.typing_env().typing_mode, ty::TypingMode::PostAnalysis);
269-
// The type error for normalization may have been in dropck: see
270-
// `compute_drop_data` in rustc_borrowck, in which case we wouldn't have
271-
// deleted the MIR body and could have an error here as well.
272269
let field_ty = match tcx
273270
.try_normalize_erasing_regions(self.elaborator.typing_env(), f.ty(tcx, args))
274271
{
275272
Ok(t) => t,
276273
Err(_) => Ty::new_error(
277274
self.tcx(),
278-
self.elaborator
279-
.body()
280-
.tainted_by_errors
281-
.expect("Error in drop elaboration not found by dropck."),
275+
self.tcx().dcx().span_delayed_bug(
276+
self.elaborator.body().span,
277+
"Error normalizing in drop elaboration.",
278+
),
282279
),
283280
};
284281

tests/crashes/137287.rs renamed to tests/ui/drop/drop_elaboration_with_errors2.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
//@ known-bug: #137287
1+
// Regression test for #137287
22

33
mod defining_scope {
44
use super::*;
55
pub type Alias<T> = impl Sized;
6+
//~^ ERROR unconstrained opaque type
7+
//~| ERROR `impl Trait` in type aliases is unstable
68

79
pub fn cast<T>(x: Container<Alias<T>, T>) -> Container<T, T> {
810
x
11+
//~^ ERROR mismatched types
912
}
1013
}
1114

@@ -21,6 +24,7 @@ impl<T> Trait<T> for T {
2124
type Assoc = Box<u32>;
2225
}
2326
impl<T> Trait<T> for defining_scope::Alias<T> {
27+
//~^ ERROR conflicting implementations of trait `Trait<_>`
2428
type Assoc = usize;
2529
}
2630

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
error[E0658]: `impl Trait` in type aliases is unstable
2+
--> $DIR/drop_elaboration_with_errors2.rs:5:25
3+
|
4+
LL | pub type Alias<T> = impl Sized;
5+
| ^^^^^^^^^^
6+
|
7+
= note: see issue #63063 <https://github.com/rust-lang/rust/issues/63063> for more information
8+
= help: add `#![feature(type_alias_impl_trait)]` 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[E0119]: conflicting implementations of trait `Trait<_>`
12+
--> $DIR/drop_elaboration_with_errors2.rs:26:1
13+
|
14+
LL | impl<T> Trait<T> for T {
15+
| ---------------------- first implementation here
16+
...
17+
LL | impl<T> Trait<T> for defining_scope::Alias<T> {
18+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation
19+
20+
error: unconstrained opaque type
21+
--> $DIR/drop_elaboration_with_errors2.rs:5:25
22+
|
23+
LL | pub type Alias<T> = impl Sized;
24+
| ^^^^^^^^^^
25+
|
26+
= note: `Alias` must be used in combination with a concrete type within the same crate
27+
28+
error[E0308]: mismatched types
29+
--> $DIR/drop_elaboration_with_errors2.rs:10:9
30+
|
31+
LL | pub type Alias<T> = impl Sized;
32+
| ---------- the found opaque type
33+
...
34+
LL | pub fn cast<T>(x: Container<Alias<T>, T>) -> Container<T, T> {
35+
| - expected this type parameter --------------- expected `Container<T, T>` because of return type
36+
LL | x
37+
| ^ expected `Container<T, T>`, found `Container<Alias<T>, T>`
38+
|
39+
= note: expected struct `Container<T, _>`
40+
found struct `Container<Alias<T>, _>`
41+
= help: type parameters must be constrained to match other types
42+
= note: for more information, visit https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters
43+
44+
error: aborting due to 4 previous errors
45+
46+
Some errors have detailed explanations: E0119, E0308, E0658.
47+
For more information about an error, try `rustc --explain E0119`.

tests/crashes/135668.rs renamed to tests/ui/drop/drop_elaboration_with_errors3.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
//@ known-bug: #135668
1+
// Regression test for #135668
22
//@ edition: 2021
3+
34
use std::future::Future;
45

56
pub async fn foo() {
@@ -11,7 +12,8 @@ async fn create_task() -> impl Sized {
1112
}
1213

1314
async fn documentation() {
14-
include_str!("nonexistent");
15+
compile_error!("bonjour");
16+
//~^ ERROR bonjour
1517
}
1618

1719
fn bind<F>(_filter: F) -> impl Sized
@@ -36,3 +38,5 @@ where
3638
{
3739
type Assoc = F;
3840
}
41+
42+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: bonjour
2+
--> $DIR/drop_elaboration_with_errors3.rs:15:5
3+
|
4+
LL | compile_error!("bonjour");
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
6+
7+
error: aborting due to 1 previous error
8+

0 commit comments

Comments
 (0)