diff options
| author | bors <bors@rust-lang.org> | 2023-10-05 19:42:05 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-10-05 19:42:05 +0000 |
| commit | cae0791da47bb01f16885eb233dcd66b0093a6e1 (patch) | |
| tree | bc45b9ef8e62851cf79b52750fceae218eba3a92 | |
| parent | cdca82c2c853c8373c0c333a2fd7d1b480d7f1d2 (diff) | |
| parent | e30d27be00c5fd3dda58cbb04013974f978710da (diff) | |
| download | rust-cae0791da47bb01f16885eb233dcd66b0093a6e1.tar.gz rust-cae0791da47bb01f16885eb233dcd66b0093a6e1.zip | |
Auto merge of #116417 - ouz-a:trait_type_detective, r=compiler-errors
Remove is global hack In attempt to fix https://github.com/rust-lang/rust/issues/114057 we found several issues with how compiler computes layouts, this change removes `is_global` from `and` to stop impl from being shadowed. In depth conversation can be read here https://rust-lang.zulipchat.com/#narrow/stream/146212-t-compiler.2Fconst-eval/topic/Getting.20different.20types.20from.20almost.20same.20inputs This is a fix candidate opened for performance run. r? `@lcnr`
| -rw-r--r-- | compiler/rustc_middle/src/ty/mod.rs | 25 | ||||
| -rw-r--r-- | tests/ui/traits/associated_type_bound/impl-is-shadowed.rs | 21 |
2 files changed, 23 insertions, 23 deletions
diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index 78396358969..b7d2e3d9493 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -1752,30 +1752,9 @@ impl<'tcx> ParamEnv<'tcx> { Self::new(List::empty(), self.reveal()) } - /// Creates a suitable environment in which to perform trait - /// queries on the given value. When type-checking, this is simply - /// the pair of the environment plus value. But when reveal is set to - /// All, then if `value` does not reference any type parameters, we will - /// pair it with the empty environment. This improves caching and is generally - /// invisible. - /// - /// N.B., we preserve the environment when type-checking because it - /// is possible for the user to have wacky where-clauses like - /// `where Box<u32>: Copy`, which are clearly never - /// satisfiable. We generally want to behave as if they were true, - /// although the surrounding function is never reachable. + /// Creates a pair of param-env and value for use in queries. pub fn and<T: TypeVisitable<TyCtxt<'tcx>>>(self, value: T) -> ParamEnvAnd<'tcx, T> { - match self.reveal() { - Reveal::UserFacing => ParamEnvAnd { param_env: self, value }, - - Reveal::All => { - if value.is_global() { - ParamEnvAnd { param_env: self.without_caller_bounds(), value } - } else { - ParamEnvAnd { param_env: self, value } - } - } - } + ParamEnvAnd { param_env: self, value } } } diff --git a/tests/ui/traits/associated_type_bound/impl-is-shadowed.rs b/tests/ui/traits/associated_type_bound/impl-is-shadowed.rs new file mode 100644 index 00000000000..6c3125a9fc5 --- /dev/null +++ b/tests/ui/traits/associated_type_bound/impl-is-shadowed.rs @@ -0,0 +1,21 @@ +// check-pass +trait Bar<'a> { + type Assoc: 'static; +} + +impl<'a> Bar<'a> for () { + type Assoc = (); +} + +struct ImplsStatic<CG: Bar<'static>> { + d: &'static <CG as Bar<'static>>::Assoc, +} + +fn caller(b: ImplsStatic<()>) +where + for<'a> (): Bar<'a> +{ + let _: &<() as Bar<'static>>::Assoc = b.d; +} + +fn main() {} |
