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.
Don't resolve generic instances if they may be shadowed by dyn
1 parent
55ce976
commit a30ad3a
Showing
8 changed files
with
144 additions
and
20 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
24 changes: 24 additions & 0 deletions
24
tests/mir-opt/inline_generically_if_sized.call.Inline.diff
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,24 @@ | ||
- // MIR for `call` before Inline | ||
+ // MIR for `call` after Inline | ||
|
||
fn call(_1: &T) -> i32 { | ||
debug s => _1; | ||
let mut _0: i32; | ||
let mut _2: &T; | ||
+ scope 1 (inlined <T as Foo>::bar) { | ||
+ debug self => _2; | ||
+ } | ||
|
||
bb0: { | ||
StorageLive(_2); | ||
_2 = &(*_1); | ||
- _0 = <T as Foo>::bar(move _2) -> [return: bb1, unwind unreachable]; | ||
- } | ||
- | ||
- bb1: { | ||
+ _0 = const 0_i32; | ||
StorageDead(_2); | ||
return; | ||
} | ||
} | ||
|
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,17 @@ | ||
// unit-test: Inline | ||
// compile-flags: --crate-type=lib -C panic=abort | ||
|
||
trait Foo { | ||
fn bar(&self) -> i32; | ||
} | ||
|
||
impl<T> Foo for T { | ||
fn bar(&self) -> i32 { | ||
0 | ||
} | ||
} | ||
|
||
// EMIT_MIR inline_generically_if_sized.call.Inline.diff | ||
pub fn call<T>(s: &T) -> i32 { | ||
s.bar() | ||
} |
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,26 @@ | ||
// run-pass | ||
|
||
#![feature(inline_const)] | ||
|
||
// Makes sure we don't propagate generic instances of `Self: ?Sized` blanket impls. | ||
// This is relevant when we have an overlapping impl and builtin dyn instance. | ||
// See <https://github.com/rust-lang/rust/pull/114941> for more context. | ||
|
||
trait Trait { | ||
fn foo(&self) -> &'static str; | ||
} | ||
|
||
impl<T: ?Sized> Trait for T { | ||
fn foo(&self) -> &'static str { | ||
std::any::type_name::<T>() | ||
} | ||
} | ||
|
||
fn bar<T: ?Sized>() -> fn(&T) -> &'static str { | ||
const { Trait::foo as fn(&T) -> &'static str } | ||
// If const prop were to propagate the instance | ||
} | ||
|
||
fn main() { | ||
assert_eq!("i32", bar::<dyn Trait>()(&1i32)); | ||
} |
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,24 @@ | ||
// run-pass | ||
|
||
// Makes sure we don't propagate generic instances of `Self: ?Sized` blanket impls. | ||
// This is relevant when we have an overlapping impl and builtin dyn instance. | ||
// See <https://github.com/rust-lang/rust/pull/114941> for more context. | ||
|
||
trait Trait { | ||
fn foo(&self) -> &'static str; | ||
} | ||
|
||
impl<T: ?Sized> Trait for T { | ||
fn foo(&self) -> &'static str { | ||
std::any::type_name::<T>() | ||
} | ||
} | ||
|
||
const fn bar<T: ?Sized>() -> fn(&T) -> &'static str { | ||
Trait::foo | ||
// If const prop were to propagate the instance | ||
} | ||
|
||
fn main() { | ||
assert_eq!("i32", bar::<dyn Trait>()(&1i32)); | ||
} |