Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 8 pull requests #130964

Merged
merged 26 commits into from
Sep 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
ba3b536
Fix `io::Take::read_buf`
a1phyr May 22, 2024
04710e2
Fix `io::BufReader` uses of `read_buf`
a1phyr May 22, 2024
bf76888
Fix `io::default_read_to_end` uses of `read_buf`
a1phyr May 22, 2024
4b8a66c
Add tests
a1phyr Sep 23, 2024
d77664b
Add a comment to `Read::read_buf`
a1phyr Sep 23, 2024
d4ee408
Check allow instantiating object trait binder when upcasting and in n…
compiler-errors Sep 25, 2024
fa3215d
Reference UNSPECIFIED instead of INADDR_ANY in join_multicast_v4
tyilo Sep 27, 2024
0bf9289
Make clashing_extern_declarations considering generic args for ADT field
surechen Sep 27, 2024
3b9db47
rustdoc: update `ProcMacro` docs section on helper attributes
obi1kenobi Sep 27, 2024
282d044
Revert "ci: Try to remove unused Xcode dirs"
workingjubilee Sep 27, 2024
a2a4ea0
Partially revert "ci: Use mv instead of cp in upload step"
workingjubilee Sep 27, 2024
8302f2e
add even more tests for ptr-to-ptr casts on trait objects
Sep 27, 2024
53f45c4
borrowck: use subtyping instead of equality for ptr-to-ptr casts
Sep 27, 2024
4fb097a
Instantiate binders when checking supertrait upcasting
compiler-errors Sep 27, 2024
d753aba
Get rid of a_is_expected from ToTrace
compiler-errors Sep 27, 2024
bcf8cf2
tests: issue-69488.rs => load-preserves-partial-init-issue-69488.rs
workingjubilee Sep 26, 2024
a1fbf25
tests: issue-14309.* => repr-rust-is-undefined.*
workingjubilee Sep 27, 2024
19d5568
tests: issue-34798.rs => allow-phantomdata-in-ffi.rs
workingjubilee Sep 27, 2024
6e9db86
Rollup merge of #125404 - a1phyr:fix-read_buf-uses, r=workingjubilee
matthiaskrgr Sep 28, 2024
4e510da
Rollup merge of #130866 - compiler-errors:dyn-instantiate-binder, r=lcnr
matthiaskrgr Sep 28, 2024
9c4b81c
Rollup merge of #130922 - tyilo:udp-unspecified, r=ibraheemdev
matthiaskrgr Sep 28, 2024
2df6b07
Rollup merge of #130924 - surechen:fix_130851, r=compiler-errors
matthiaskrgr Sep 28, 2024
7e32221
Rollup merge of #130939 - obi1kenobi:patch-2, r=aDotInTheVoid
matthiaskrgr Sep 28, 2024
6b5cd4e
Rollup merge of #130940 - workingjubilee:remove-space-saving-operatio…
matthiaskrgr Sep 28, 2024
58d0730
Rollup merge of #130944 - lukas-code:ptr-ptr-sub, r=compiler-errors
matthiaskrgr Sep 28, 2024
5d7db93
Rollup merge of #130953 - workingjubilee:rename-a-few-ctypes-tests, r…
matthiaskrgr Sep 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_borrowck/src/type_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2437,7 +2437,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {

debug!(?src_tty, ?dst_tty, ?src_obj, ?dst_obj);

self.eq_types(
self.sub_types(
src_obj,
dst_obj,
location.to_locations(),
Expand Down
164 changes: 54 additions & 110 deletions compiler/rustc_infer/src/infer/at.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,7 @@ impl<'tcx> InferCtxt<'tcx> {
}

pub trait ToTrace<'tcx>: Relate<TyCtxt<'tcx>> + Copy {
fn to_trace(
cause: &ObligationCause<'tcx>,
a_is_expected: bool,
a: Self,
b: Self,
) -> TypeTrace<'tcx>;
fn to_trace(cause: &ObligationCause<'tcx>, a: Self, b: Self) -> TypeTrace<'tcx>;
}

impl<'a, 'tcx> At<'a, 'tcx> {
Expand All @@ -116,7 +111,7 @@ impl<'a, 'tcx> At<'a, 'tcx> {
{
let mut fields = CombineFields::new(
self.infcx,
ToTrace::to_trace(self.cause, true, expected, actual),
ToTrace::to_trace(self.cause, expected, actual),
self.param_env,
define_opaque_types,
);
Expand All @@ -136,7 +131,7 @@ impl<'a, 'tcx> At<'a, 'tcx> {
{
let mut fields = CombineFields::new(
self.infcx,
ToTrace::to_trace(self.cause, true, expected, actual),
ToTrace::to_trace(self.cause, expected, actual),
self.param_env,
define_opaque_types,
);
Expand All @@ -154,12 +149,26 @@ impl<'a, 'tcx> At<'a, 'tcx> {
where
T: ToTrace<'tcx>,
{
let mut fields = CombineFields::new(
self.infcx,
ToTrace::to_trace(self.cause, true, expected, actual),
self.param_env,
self.eq_trace(
define_opaque_types,
);
ToTrace::to_trace(self.cause, expected, actual),
expected,
actual,
)
}

/// Makes `expected == actual`.
pub fn eq_trace<T>(
self,
define_opaque_types: DefineOpaqueTypes,
trace: TypeTrace<'tcx>,
expected: T,
actual: T,
) -> InferResult<'tcx, ()>
where
T: Relate<TyCtxt<'tcx>>,
{
let mut fields = CombineFields::new(self.infcx, trace, self.param_env, define_opaque_types);
fields.equate(StructurallyRelateAliases::No).relate(expected, actual)?;
Ok(InferOk {
value: (),
Expand Down Expand Up @@ -192,7 +201,7 @@ impl<'a, 'tcx> At<'a, 'tcx> {
assert!(self.infcx.next_trait_solver());
let mut fields = CombineFields::new(
self.infcx,
ToTrace::to_trace(self.cause, true, expected, actual),
ToTrace::to_trace(self.cause, expected, actual),
self.param_env,
DefineOpaqueTypes::Yes,
);
Expand Down Expand Up @@ -284,7 +293,7 @@ impl<'a, 'tcx> At<'a, 'tcx> {
{
let mut fields = CombineFields::new(
self.infcx,
ToTrace::to_trace(self.cause, true, expected, actual),
ToTrace::to_trace(self.cause, expected, actual),
self.param_env,
define_opaque_types,
);
Expand All @@ -306,7 +315,7 @@ impl<'a, 'tcx> At<'a, 'tcx> {
{
let mut fields = CombineFields::new(
self.infcx,
ToTrace::to_trace(self.cause, true, expected, actual),
ToTrace::to_trace(self.cause, expected, actual),
self.param_env,
define_opaque_types,
);
Expand All @@ -316,18 +325,13 @@ impl<'a, 'tcx> At<'a, 'tcx> {
}

impl<'tcx> ToTrace<'tcx> for ImplSubject<'tcx> {
fn to_trace(
cause: &ObligationCause<'tcx>,
a_is_expected: bool,
a: Self,
b: Self,
) -> TypeTrace<'tcx> {
fn to_trace(cause: &ObligationCause<'tcx>, a: Self, b: Self) -> TypeTrace<'tcx> {
match (a, b) {
(ImplSubject::Trait(trait_ref_a), ImplSubject::Trait(trait_ref_b)) => {
ToTrace::to_trace(cause, a_is_expected, trait_ref_a, trait_ref_b)
ToTrace::to_trace(cause, trait_ref_a, trait_ref_b)
}
(ImplSubject::Inherent(ty_a), ImplSubject::Inherent(ty_b)) => {
ToTrace::to_trace(cause, a_is_expected, ty_a, ty_b)
ToTrace::to_trace(cause, ty_a, ty_b)
}
(ImplSubject::Trait(_), ImplSubject::Inherent(_))
| (ImplSubject::Inherent(_), ImplSubject::Trait(_)) => {
Expand All @@ -338,65 +342,45 @@ impl<'tcx> ToTrace<'tcx> for ImplSubject<'tcx> {
}

impl<'tcx> ToTrace<'tcx> for Ty<'tcx> {
fn to_trace(
cause: &ObligationCause<'tcx>,
a_is_expected: bool,
a: Self,
b: Self,
) -> TypeTrace<'tcx> {
fn to_trace(cause: &ObligationCause<'tcx>, a: Self, b: Self) -> TypeTrace<'tcx> {
TypeTrace {
cause: cause.clone(),
values: ValuePairs::Terms(ExpectedFound::new(a_is_expected, a.into(), b.into())),
values: ValuePairs::Terms(ExpectedFound::new(true, a.into(), b.into())),
}
}
}

impl<'tcx> ToTrace<'tcx> for ty::Region<'tcx> {
fn to_trace(
cause: &ObligationCause<'tcx>,
a_is_expected: bool,
a: Self,
b: Self,
) -> TypeTrace<'tcx> {
fn to_trace(cause: &ObligationCause<'tcx>, a: Self, b: Self) -> TypeTrace<'tcx> {
TypeTrace {
cause: cause.clone(),
values: ValuePairs::Regions(ExpectedFound::new(a_is_expected, a, b)),
values: ValuePairs::Regions(ExpectedFound::new(true, a, b)),
}
}
}

impl<'tcx> ToTrace<'tcx> for Const<'tcx> {
fn to_trace(
cause: &ObligationCause<'tcx>,
a_is_expected: bool,
a: Self,
b: Self,
) -> TypeTrace<'tcx> {
fn to_trace(cause: &ObligationCause<'tcx>, a: Self, b: Self) -> TypeTrace<'tcx> {
TypeTrace {
cause: cause.clone(),
values: ValuePairs::Terms(ExpectedFound::new(a_is_expected, a.into(), b.into())),
values: ValuePairs::Terms(ExpectedFound::new(true, a.into(), b.into())),
}
}
}

impl<'tcx> ToTrace<'tcx> for ty::GenericArg<'tcx> {
fn to_trace(
cause: &ObligationCause<'tcx>,
a_is_expected: bool,
a: Self,
b: Self,
) -> TypeTrace<'tcx> {
fn to_trace(cause: &ObligationCause<'tcx>, a: Self, b: Self) -> TypeTrace<'tcx> {
TypeTrace {
cause: cause.clone(),
values: match (a.unpack(), b.unpack()) {
(GenericArgKind::Lifetime(a), GenericArgKind::Lifetime(b)) => {
ValuePairs::Regions(ExpectedFound::new(a_is_expected, a, b))
ValuePairs::Regions(ExpectedFound::new(true, a, b))
}
(GenericArgKind::Type(a), GenericArgKind::Type(b)) => {
ValuePairs::Terms(ExpectedFound::new(a_is_expected, a.into(), b.into()))
ValuePairs::Terms(ExpectedFound::new(true, a.into(), b.into()))
}
(GenericArgKind::Const(a), GenericArgKind::Const(b)) => {
ValuePairs::Terms(ExpectedFound::new(a_is_expected, a.into(), b.into()))
ValuePairs::Terms(ExpectedFound::new(true, a.into(), b.into()))
}

(
Expand All @@ -419,72 +403,47 @@ impl<'tcx> ToTrace<'tcx> for ty::GenericArg<'tcx> {
}

impl<'tcx> ToTrace<'tcx> for ty::Term<'tcx> {
fn to_trace(
cause: &ObligationCause<'tcx>,
a_is_expected: bool,
a: Self,
b: Self,
) -> TypeTrace<'tcx> {
fn to_trace(cause: &ObligationCause<'tcx>, a: Self, b: Self) -> TypeTrace<'tcx> {
TypeTrace {
cause: cause.clone(),
values: ValuePairs::Terms(ExpectedFound::new(a_is_expected, a, b)),
values: ValuePairs::Terms(ExpectedFound::new(true, a, b)),
}
}
}

impl<'tcx> ToTrace<'tcx> for ty::TraitRef<'tcx> {
fn to_trace(
cause: &ObligationCause<'tcx>,
a_is_expected: bool,
a: Self,
b: Self,
) -> TypeTrace<'tcx> {
fn to_trace(cause: &ObligationCause<'tcx>, a: Self, b: Self) -> TypeTrace<'tcx> {
TypeTrace {
cause: cause.clone(),
values: ValuePairs::TraitRefs(ExpectedFound::new(a_is_expected, a, b)),
values: ValuePairs::TraitRefs(ExpectedFound::new(true, a, b)),
}
}
}

impl<'tcx> ToTrace<'tcx> for ty::AliasTy<'tcx> {
fn to_trace(
cause: &ObligationCause<'tcx>,
a_is_expected: bool,
a: Self,
b: Self,
) -> TypeTrace<'tcx> {
fn to_trace(cause: &ObligationCause<'tcx>, a: Self, b: Self) -> TypeTrace<'tcx> {
TypeTrace {
cause: cause.clone(),
values: ValuePairs::Aliases(ExpectedFound::new(a_is_expected, a.into(), b.into())),
values: ValuePairs::Aliases(ExpectedFound::new(true, a.into(), b.into())),
}
}
}

impl<'tcx> ToTrace<'tcx> for ty::AliasTerm<'tcx> {
fn to_trace(
cause: &ObligationCause<'tcx>,
a_is_expected: bool,
a: Self,
b: Self,
) -> TypeTrace<'tcx> {
fn to_trace(cause: &ObligationCause<'tcx>, a: Self, b: Self) -> TypeTrace<'tcx> {
TypeTrace {
cause: cause.clone(),
values: ValuePairs::Aliases(ExpectedFound::new(a_is_expected, a, b)),
values: ValuePairs::Aliases(ExpectedFound::new(true, a, b)),
}
}
}

impl<'tcx> ToTrace<'tcx> for ty::FnSig<'tcx> {
fn to_trace(
cause: &ObligationCause<'tcx>,
a_is_expected: bool,
a: Self,
b: Self,
) -> TypeTrace<'tcx> {
fn to_trace(cause: &ObligationCause<'tcx>, a: Self, b: Self) -> TypeTrace<'tcx> {
TypeTrace {
cause: cause.clone(),
values: ValuePairs::PolySigs(ExpectedFound::new(
a_is_expected,
true,
ty::Binder::dummy(a),
ty::Binder::dummy(b),
)),
Expand All @@ -493,43 +452,28 @@ impl<'tcx> ToTrace<'tcx> for ty::FnSig<'tcx> {
}

impl<'tcx> ToTrace<'tcx> for ty::PolyFnSig<'tcx> {
fn to_trace(
cause: &ObligationCause<'tcx>,
a_is_expected: bool,
a: Self,
b: Self,
) -> TypeTrace<'tcx> {
fn to_trace(cause: &ObligationCause<'tcx>, a: Self, b: Self) -> TypeTrace<'tcx> {
TypeTrace {
cause: cause.clone(),
values: ValuePairs::PolySigs(ExpectedFound::new(a_is_expected, a, b)),
values: ValuePairs::PolySigs(ExpectedFound::new(true, a, b)),
}
}
}

impl<'tcx> ToTrace<'tcx> for ty::PolyExistentialTraitRef<'tcx> {
fn to_trace(
cause: &ObligationCause<'tcx>,
a_is_expected: bool,
a: Self,
b: Self,
) -> TypeTrace<'tcx> {
fn to_trace(cause: &ObligationCause<'tcx>, a: Self, b: Self) -> TypeTrace<'tcx> {
TypeTrace {
cause: cause.clone(),
values: ValuePairs::ExistentialTraitRef(ExpectedFound::new(a_is_expected, a, b)),
values: ValuePairs::ExistentialTraitRef(ExpectedFound::new(true, a, b)),
}
}
}

impl<'tcx> ToTrace<'tcx> for ty::PolyExistentialProjection<'tcx> {
fn to_trace(
cause: &ObligationCause<'tcx>,
a_is_expected: bool,
a: Self,
b: Self,
) -> TypeTrace<'tcx> {
fn to_trace(cause: &ObligationCause<'tcx>, a: Self, b: Self) -> TypeTrace<'tcx> {
TypeTrace {
cause: cause.clone(),
values: ValuePairs::ExistentialProjection(ExpectedFound::new(a_is_expected, a, b)),
values: ValuePairs::ExistentialProjection(ExpectedFound::new(true, a, b)),
}
}
}
6 changes: 3 additions & 3 deletions compiler/rustc_lint/src/foreign_modules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ fn structurally_same_type_impl<'tcx>(

ensure_sufficient_stack(|| {
match (a.kind(), b.kind()) {
(&Adt(a_def, _), &Adt(b_def, _)) => {
(&Adt(a_def, a_gen_args), &Adt(b_def, b_gen_args)) => {
// Only `repr(C)` types can be compared structurally.
if !(a_def.repr().c() && b_def.repr().c()) {
return false;
Expand All @@ -304,8 +304,8 @@ fn structurally_same_type_impl<'tcx>(
seen_types,
tcx,
param_env,
tcx.type_of(a_did).instantiate_identity(),
tcx.type_of(b_did).instantiate_identity(),
tcx.type_of(a_did).instantiate(tcx, a_gen_args),
tcx.type_of(b_did).instantiate(tcx, b_gen_args),
ckind,
)
},
Expand Down
16 changes: 9 additions & 7 deletions compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,10 +448,10 @@ where
}
}
} else {
self.delegate.enter_forall(kind, |kind| {
let goal = goal.with(self.cx(), ty::Binder::dummy(kind));
self.add_goal(GoalSource::InstantiateHigherRanked, goal);
self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
self.enter_forall(kind, |ecx, kind| {
let goal = goal.with(ecx.cx(), ty::Binder::dummy(kind));
ecx.add_goal(GoalSource::InstantiateHigherRanked, goal);
ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
})
}
}
Expand Down Expand Up @@ -840,12 +840,14 @@ where
self.delegate.instantiate_binder_with_infer(value)
}

/// `enter_forall`, but takes `&mut self` and passes it back through the
/// callback since it can't be aliased during the call.
pub(super) fn enter_forall<T: TypeFoldable<I> + Copy, U>(
&self,
&mut self,
value: ty::Binder<I, T>,
f: impl FnOnce(T) -> U,
f: impl FnOnce(&mut Self, T) -> U,
) -> U {
self.delegate.enter_forall(value, f)
self.delegate.enter_forall(value, |value| f(self, value))
}

pub(super) fn resolve_vars_if_possible<T>(&self, value: T) -> T
Expand Down
Loading
Loading