Skip to content

Conversation

compiler-errors
Copy link
Member

The implementation for InferCtxtExt::could_impl_trait was very wrong. Along with being pretty poorly named, way too specific to ADTs, it was also doing impl substitution wrong -- this caused an ICE (#119915).

This PR generalizes that code, gives it a clearer name, makes it stop using the new trait solver (lol), and fixes some fallout bad suggestions that are made worse with the code fix.

Fixes #119915

@rustbot
Copy link
Collaborator

rustbot commented Jan 13, 2024

r? @jackh726

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jan 13, 2024
//
// A correct suggestion here would take into account the fact
// that inference may be affected by missing types on bindings,
// etc., to improve "tests/ui/borrowck/issue-91206.stderr", for
Copy link
Member Author

Choose a reason for hiding this comment

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

91206 is the only test that i consider to have regressed with this PR. the problem is that fixing this code makes it much harder to only tailor the suggestion for when it should apply. I don't think that it's worth it.

_ => false,
})
{
let mut fulfill_cx = FulfillmentCtxt::new(self);
Copy link
Member Author

Choose a reason for hiding this comment

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

Why were we using the new trait solver!?

let obligations = self
.tcx
.predicates_of(impl_def_id)
.instantiate(self.tcx, args)
Copy link
Member Author

Choose a reason for hiding this comment

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

Here is the cause of the ICE -- we were trying to substitute an ADT's args into an impl's predicates. There's no guarantee that these generics line up.

&self,
trait_def_id: DefId,
ty: Ty<'tcx>,
param_env: ty::ParamEnv<'tcx>,
) -> Option<Vec<traits::FulfillmentError<'tcx>>> {
self.probe(|_snapshot| {
if let ty::Adt(def, args) = ty.kind()
Copy link
Member Author

Choose a reason for hiding this comment

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

Why is this name "could_impl_trait" if it was specific to ADTs? No comment too! :(

@compiler-errors compiler-errors changed the title Make InferCtxtExt::could_impl_trait less messed up Make InferCtxtExt::could_impl_trait more precise, less ICEy Jan 13, 2024
@jackh726
Copy link
Member

Seems like this was added in 210a672#diff-622a7d238c727ee83660b2a7fe4dbd2c0fd0ac25a432fc531dfdb17c3e516bf1

Using the new trait solver was probably an accident. I'm wondering if it's worth linting against it.

@compiler-errors
Copy link
Member Author

I don't think it's worth linting, but I can add assertions against it.

@rustbot
Copy link
Collaborator

rustbot commented Jan 13, 2024

Some changes occurred to the core trait solver

cc @rust-lang/initiative-trait-system-refactor

@rustbot rustbot added the WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) label Jan 13, 2024
@jackh726
Copy link
Member

r=me with CI green

cc @estebank

@compiler-errors
Copy link
Member Author

(elaborated the comment a bit more, fixed a typo)

@compiler-errors
Copy link
Member Author

@bors r=jackh726

@bors
Copy link
Collaborator

bors commented Jan 13, 2024

📌 Commit 7724ba7 has been approved by jackh726

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 13, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 14, 2024
Make `InferCtxtExt::could_impl_trait` more precise, less ICEy

The implementation for `InferCtxtExt::could_impl_trait` was very wrong. Along with being pretty poorly named, way too specific to ADTs, it was also doing impl substitution wrong -- this caused an ICE (rust-lang#119915).

This PR generalizes that code, gives it a clearer name, makes it stop using the new trait solver (lol), and fixes some fallout bad suggestions that are made worse with the code fix.

Fixes rust-lang#119915
@bors
Copy link
Collaborator

bors commented Jan 14, 2024

⌛ Testing commit 7724ba7 with merge 7f4e7ea...

@bors
Copy link
Collaborator

bors commented Jan 14, 2024

💥 Test timed out

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jan 14, 2024
@compiler-errors
Copy link
Member Author

@bors retry

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 14, 2024
@rust-log-analyzer
Copy link
Collaborator

A job failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)

@bors
Copy link
Collaborator

bors commented Jan 14, 2024

⌛ Testing commit 7724ba7 with merge 0dab65b...

@bors
Copy link
Collaborator

bors commented Jan 14, 2024

☀️ Test successful - checks-actions
Approved by: jackh726
Pushing 0dab65b to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Jan 14, 2024
@bors bors merged commit 0dab65b into rust-lang:master Jan 14, 2024
@rustbot rustbot added this to the 1.77.0 milestone Jan 14, 2024
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (0dab65b): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
2.6% [2.6%, 2.6%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 666.086s -> 668.181s (0.31%)
Artifact size: 308.21 MiB -> 308.18 MiB (-0.01%)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ICE: Compiler incorrectly assumes a Copy bound is met for a type.
6 participants