Skip to content

Commit

Permalink
Auto merge of rust-lang#116417 - ouz-a:trait_type_detective, r=<try>
Browse files Browse the repository at this point in the history
Remove is global hack

In attempt to fix rust-lang#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`
  • Loading branch information
bors committed Oct 4, 2023
2 parents 9fbd593 + 56d336a commit aaa6b9c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
14 changes: 2 additions & 12 deletions compiler/rustc_middle/src/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1754,10 +1754,7 @@ impl<'tcx> ParamEnv<'tcx> {

/// 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.
/// the pair of the environment plus value.
///
/// N.B., we preserve the environment when type-checking because it
/// is possible for the user to have wacky where-clauses like
Expand All @@ -1767,14 +1764,7 @@ impl<'tcx> ParamEnv<'tcx> {
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 }
}
}
Reveal::All => ParamEnvAnd { param_env: self, value },
}
}
}
Expand Down
21 changes: 21 additions & 0 deletions tests/ui/traits/associated_type_bound/impl-is-shadowed.rs
Original file line number Diff line number Diff line change
@@ -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() {}

0 comments on commit aaa6b9c

Please sign in to comment.