Skip to content

Flush errors before deep normalize in dropck_outlives #140947

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions compiler/rustc_borrowck/src/type_check/liveness/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -621,13 +621,7 @@ impl<'tcx> LivenessContext<'_, '_, '_, 'tcx> {
&ocx, op, span,
) {
Ok(_) => ocx.select_all_or_error(),
Err(e) => {
if e.is_empty() {
ocx.select_all_or_error()
} else {
e
}
}
Err(e) => e,
};

// Could have no errors if a type lowering error, say, caused the query
Expand Down
28 changes: 24 additions & 4 deletions compiler/rustc_trait_selection/src/traits/query/dropck_outlives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,31 @@ where
debug!("dropck_outlives: ty from dtorck_types = {:?}", ty);
ty
} else {
ocx.deeply_normalize(&cause, param_env, ty)?;
// Flush errors b/c `deeply_normalize` doesn't expect pending
// obligations, and we may have pending obligations from the
// branch above (from other types).
let errors = ocx.select_all_or_error();
if !errors.is_empty() {
return Err(errors);
}

let errors = ocx.select_where_possible();
debug!("normalize errors: {ty} ~> {errors:#?}");
return Err(errors);
// When query normalization fails, we don't get back an interesting
// reason that we could use to report an error in borrowck. In order to turn
// this into a reportable error, we deeply normalize again. We don't expect
// this to succeed, so delay a bug if it does.
match ocx.deeply_normalize(&cause, param_env, ty) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pls add comment that we do this match to get FulfillmentErrors to report in case query_normalize failed to avoid ICE due to a delayed bug

Ok(_) => {
tcx.dcx().span_delayed_bug(
span,
format!(
"query normalize succeeded of {ty}, \
but deep normalize failed",
),
);
ty
}
Err(errors) => return Err(errors),
}
};

match ty.kind() {
Expand Down
31 changes: 31 additions & 0 deletions tests/ui/drop/dropck-normalize-errors.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Test that we don't ICE when computing the drop types for

trait Decode<'a> {
type Decoder;
}

trait NonImplementedTrait {
type Assoc;
}
struct NonImplementedStruct;

pub struct ADecoder<'a> {
b: <B as Decode<'a>>::Decoder,
}
fn make_a_decoder<'a>() -> ADecoder<'a> {
//~^ ERROR the trait bound
//~| ERROR the trait bound
panic!()
}

struct B;
impl<'a> Decode<'a> for B {
type Decoder = BDecoder;
//~^ ERROR the trait bound
}
pub struct BDecoder {
non_implemented: <NonImplementedStruct as NonImplementedTrait>::Assoc,
//~^ ERROR the trait bound
}

fn main() {}
76 changes: 76 additions & 0 deletions tests/ui/drop/dropck-normalize-errors.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
error[E0277]: the trait bound `NonImplementedStruct: NonImplementedTrait` is not satisfied in `ADecoder<'a>`
--> $DIR/dropck-normalize-errors.rs:15:28
|
LL | fn make_a_decoder<'a>() -> ADecoder<'a> {
| ^^^^^^^^^^^^ within `ADecoder<'a>`, the trait `NonImplementedTrait` is not implemented for `NonImplementedStruct`
|
help: this trait has no implementations, consider adding one
--> $DIR/dropck-normalize-errors.rs:7:1
|
LL | trait NonImplementedTrait {
| ^^^^^^^^^^^^^^^^^^^^^^^^^
note: required because it appears within the type `BDecoder`
--> $DIR/dropck-normalize-errors.rs:26:12
|
LL | pub struct BDecoder {
| ^^^^^^^^
note: required because it appears within the type `ADecoder<'a>`
--> $DIR/dropck-normalize-errors.rs:12:12
|
LL | pub struct ADecoder<'a> {
| ^^^^^^^^
= note: the return type of a function must have a statically known size

error[E0277]: the trait bound `NonImplementedStruct: NonImplementedTrait` is not satisfied in `BDecoder`
--> $DIR/dropck-normalize-errors.rs:23:20
|
LL | type Decoder = BDecoder;
| ^^^^^^^^ within `BDecoder`, the trait `NonImplementedTrait` is not implemented for `NonImplementedStruct`
|
help: this trait has no implementations, consider adding one
--> $DIR/dropck-normalize-errors.rs:7:1
|
LL | trait NonImplementedTrait {
| ^^^^^^^^^^^^^^^^^^^^^^^^^
note: required because it appears within the type `BDecoder`
--> $DIR/dropck-normalize-errors.rs:26:12
|
LL | pub struct BDecoder {
| ^^^^^^^^
note: required by a bound in `Decode::Decoder`
--> $DIR/dropck-normalize-errors.rs:4:5
|
LL | type Decoder;
| ^^^^^^^^^^^^^ required by this bound in `Decode::Decoder`
help: consider relaxing the implicit `Sized` restriction
|
LL | type Decoder: ?Sized;
| ++++++++

error[E0277]: the trait bound `NonImplementedStruct: NonImplementedTrait` is not satisfied
--> $DIR/dropck-normalize-errors.rs:27:22
|
LL | non_implemented: <NonImplementedStruct as NonImplementedTrait>::Assoc,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `NonImplementedTrait` is not implemented for `NonImplementedStruct`
|
help: this trait has no implementations, consider adding one
--> $DIR/dropck-normalize-errors.rs:7:1
|
LL | trait NonImplementedTrait {
| ^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0277]: the trait bound `NonImplementedStruct: NonImplementedTrait` is not satisfied
--> $DIR/dropck-normalize-errors.rs:15:28
|
LL | fn make_a_decoder<'a>() -> ADecoder<'a> {
| ^^^^^^^^^^^^ the trait `NonImplementedTrait` is not implemented for `NonImplementedStruct`
|
help: this trait has no implementations, consider adding one
--> $DIR/dropck-normalize-errors.rs:7:1
|
LL | trait NonImplementedTrait {
| ^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 4 previous errors

For more information about this error, try `rustc --explain E0277`.
Loading