forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#135149 - compiler-errors:mangle, r=oli-obk Use a post-monomorphization typing env when mangling components that come from impls When mangling associated methods of impls, we were previously using the wrong param-env. Instead of using a fully monomorphized param-env like we usually do in codegen, we were taking the post-analysis param-env, and treating it as an early binder to *re-substitute* the impl args. I've pointed out the problematic old code in an inline comment. This would give us param-envs with possibly trivial predicates that would prevent normalization via param-env shadowing. In the example test linked below, `tests/ui/symbol-names/normalize-in-param-env.rs`, this happens when we mangle the impl `impl<P: Point2> MyFrom<P::S> for P` with the substitution `P = Vec2`. Because the where clause of the impl is `P: Point2`, which elaborates to `[P: Point2, P: Point, <P as Point>::S projects-to <P as Point2>::S2]` and the fact that `impl Point2 for Vec2` normalizes `Vec2::S2` to `Vec2::S`, this causes a cycle. The proper fix here is to use a fully monomorphized param-env for the case where the impl is properly substituted. Fixes rust-lang#135143 While rust-lang#134081 uncovered this bug for legacy symbol mangling, it was preexisting for v0 symbol mangling. This PR fixes both. The test requires a "hack" because we strip the args of the instance we're printing for legacy symbol mangling except for drop glue, so we box a closure to ensure we generate drop glue. r? oli-obk
- Loading branch information
Showing
4 changed files
with
99 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
//@ revisions: legacy v0 | ||
//@[v0] compile-flags: -C symbol-mangling-version=v0 | ||
//@[legacy] compile-flags: -C symbol-mangling-version=legacy -Zunstable-options | ||
//@ build-pass | ||
|
||
pub struct Vec2; | ||
|
||
pub trait Point { | ||
type S; | ||
} | ||
impl Point for Vec2 { | ||
type S = f32; | ||
} | ||
|
||
pub trait Point2: Point<S = Self::S2> { | ||
type S2; | ||
} | ||
impl Point2 for Vec2 { | ||
type S2 = Self::S; | ||
} | ||
|
||
trait MyFrom<T> { | ||
fn my_from(); | ||
} | ||
impl<P: Point2> MyFrom<P::S> for P { | ||
fn my_from() { | ||
// This is just a really dumb way to force the legacy symbol mangling to | ||
// mangle the closure's parent impl def path *with* args. Otherwise, | ||
// legacy symbol mangling will strip the args from the instance, meaning | ||
// that we don't trigger the bug. | ||
let c = || {}; | ||
let x = Box::new(c) as Box<dyn Fn()>; | ||
} | ||
} | ||
|
||
fn main() { | ||
<Vec2 as MyFrom<_>>::my_from(); | ||
} |