Skip to content

Commit cae0791

Browse files
committed
Auto merge of #116417 - ouz-a:trait_type_detective, r=compiler-errors
Remove is global hack In attempt to fix #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`
2 parents cdca82c + e30d27b commit cae0791

File tree

2 files changed

+23
-23
lines changed

2 files changed

+23
-23
lines changed

compiler/rustc_middle/src/ty/mod.rs

+2-23
Original file line numberDiff line numberDiff line change
@@ -1752,30 +1752,9 @@ impl<'tcx> ParamEnv<'tcx> {
17521752
Self::new(List::empty(), self.reveal())
17531753
}
17541754

1755-
/// Creates a suitable environment in which to perform trait
1756-
/// queries on the given value. When type-checking, this is simply
1757-
/// the pair of the environment plus value. But when reveal is set to
1758-
/// All, then if `value` does not reference any type parameters, we will
1759-
/// pair it with the empty environment. This improves caching and is generally
1760-
/// invisible.
1761-
///
1762-
/// N.B., we preserve the environment when type-checking because it
1763-
/// is possible for the user to have wacky where-clauses like
1764-
/// `where Box<u32>: Copy`, which are clearly never
1765-
/// satisfiable. We generally want to behave as if they were true,
1766-
/// although the surrounding function is never reachable.
1755+
/// Creates a pair of param-env and value for use in queries.
17671756
pub fn and<T: TypeVisitable<TyCtxt<'tcx>>>(self, value: T) -> ParamEnvAnd<'tcx, T> {
1768-
match self.reveal() {
1769-
Reveal::UserFacing => ParamEnvAnd { param_env: self, value },
1770-
1771-
Reveal::All => {
1772-
if value.is_global() {
1773-
ParamEnvAnd { param_env: self.without_caller_bounds(), value }
1774-
} else {
1775-
ParamEnvAnd { param_env: self, value }
1776-
}
1777-
}
1778-
}
1757+
ParamEnvAnd { param_env: self, value }
17791758
}
17801759
}
17811760

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// check-pass
2+
trait Bar<'a> {
3+
type Assoc: 'static;
4+
}
5+
6+
impl<'a> Bar<'a> for () {
7+
type Assoc = ();
8+
}
9+
10+
struct ImplsStatic<CG: Bar<'static>> {
11+
d: &'static <CG as Bar<'static>>::Assoc,
12+
}
13+
14+
fn caller(b: ImplsStatic<()>)
15+
where
16+
for<'a> (): Bar<'a>
17+
{
18+
let _: &<() as Bar<'static>>::Assoc = b.d;
19+
}
20+
21+
fn main() {}

0 commit comments

Comments
 (0)