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 5 pull requests #73042

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions src/librustc_middle/ty/sty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -765,8 +765,8 @@ impl<'tcx> TraitRef<'tcx> {
pub type PolyTraitRef<'tcx> = Binder<TraitRef<'tcx>>;

impl<'tcx> PolyTraitRef<'tcx> {
pub fn self_ty(&self) -> Ty<'tcx> {
self.skip_binder().self_ty()
pub fn self_ty(&self) -> Binder<Ty<'tcx>> {
self.map_bound_ref(|tr| tr.self_ty())
}

pub fn def_id(&self) -> DefId {
Expand Down
4 changes: 3 additions & 1 deletion src/librustc_resolve/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,9 @@ impl<'a> Resolver<'a> {
Res::Def(DefKind::Ctor(..), did) => this.parent(did),
_ => res.opt_def_id(),
};
candidates.push(ImportSuggestion { did, descr: res.descr(), path });
if candidates.iter().all(|v: &ImportSuggestion| v.did != did) {
candidates.push(ImportSuggestion { did, descr: res.descr(), path });
}
}
}
}
Expand Down
32 changes: 21 additions & 11 deletions src/librustc_trait_selection/traits/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
(
Some(format!(
"`?` couldn't convert the error to `{}`",
trait_ref.self_ty(),
trait_ref.skip_binder().self_ty(),
)),
Some(
"the question mark operation (`?`) implicitly performs a \
Expand Down Expand Up @@ -340,7 +340,10 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
if let Some(ret_span) = self.return_type_span(obligation) {
err.span_label(
ret_span,
&format!("expected `{}` because of this", trait_ref.self_ty()),
&format!(
"expected `{}` because of this",
trait_ref.skip_binder().self_ty()
),
);
}
}
Expand All @@ -353,7 +356,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
"{}the trait `{}` is not implemented for `{}`",
pre_message,
trait_ref.print_only_trait_path(),
trait_ref.self_ty(),
trait_ref.skip_binder().self_ty(),
)
};

Expand Down Expand Up @@ -643,7 +646,10 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
return;
}

let found_trait_ty = found_trait_ref.self_ty();
let found_trait_ty = match found_trait_ref.self_ty().no_bound_vars() {
Some(ty) => ty,
None => return,
};

let found_did = match found_trait_ty.kind {
ty::Closure(did, _) | ty::Foreign(did) | ty::FnDef(did, _) => Some(did),
Expand Down Expand Up @@ -1360,11 +1366,15 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
) {
let get_trait_impl = |trait_def_id| {
let mut trait_impl = None;
self.tcx.for_each_relevant_impl(trait_def_id, trait_ref.self_ty(), |impl_def_id| {
if trait_impl.is_none() {
trait_impl = Some(impl_def_id);
}
});
self.tcx.for_each_relevant_impl(
trait_def_id,
trait_ref.skip_binder().self_ty(),
|impl_def_id| {
if trait_impl.is_none() {
trait_impl = Some(impl_def_id);
}
},
);
trait_impl
};
let required_trait_path = self.tcx.def_path_str(trait_ref.def_id());
Expand Down Expand Up @@ -1435,7 +1445,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
let mut err = match predicate.kind() {
ty::PredicateKind::Trait(ref data, _) => {
let trait_ref = data.to_poly_trait_ref();
let self_ty = trait_ref.self_ty();
let self_ty = trait_ref.skip_binder().self_ty();
debug!("self_ty {:?} {:?} trait_ref {:?}", self_ty, self_ty.kind, trait_ref);

if predicate.references_error() {
Expand Down Expand Up @@ -1564,7 +1574,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
}
ty::PredicateKind::Projection(ref data) => {
let trait_ref = data.to_poly_trait_ref(self.tcx);
let self_ty = trait_ref.self_ty();
let self_ty = trait_ref.skip_binder().self_ty();
let ty = data.skip_binder().ty;
if predicate.references_error() {
return;
Expand Down
24 changes: 17 additions & 7 deletions src/librustc_trait_selection/traits/error_reporting/suggestions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
trait_ref: ty::PolyTraitRef<'tcx>,
body_id: hir::HirId,
) {
let self_ty = trait_ref.self_ty();
let self_ty = trait_ref.skip_binder().self_ty();
let (param_ty, projection) = match &self_ty.kind {
ty::Param(_) => (true, None),
ty::Projection(projection) => (false, Some(projection)),
Expand Down Expand Up @@ -524,7 +524,11 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
trait_ref: &ty::Binder<ty::TraitRef<'tcx>>,
points_at_arg: bool,
) {
let self_ty = trait_ref.self_ty();
let self_ty = match trait_ref.self_ty().no_bound_vars() {
None => return,
Some(ty) => ty,
};

let (def_id, output_ty, callable) = match self_ty.kind {
ty::Closure(def_id, substs) => (def_id, substs.as_closure().sig().output(), "closure"),
ty::FnDef(def_id, _) => (def_id, self_ty.fn_sig(self.tcx).output(), "function"),
Expand Down Expand Up @@ -707,7 +711,10 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
return;
}

let mut suggested_ty = trait_ref.self_ty();
let mut suggested_ty = match trait_ref.self_ty().no_bound_vars() {
Some(ty) => ty,
None => return,
};

for refs_remaining in 0..refs_number {
if let ty::Ref(_, inner_ty, _) = suggested_ty.kind {
Expand Down Expand Up @@ -829,6 +836,9 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
span: Span,
trait_ref: &ty::Binder<ty::TraitRef<'tcx>>,
) {
let is_empty_tuple =
|ty: ty::Binder<Ty<'_>>| ty.skip_binder().kind == ty::Tuple(ty::List::empty());

let hir = self.tcx.hir();
let parent_node = hir.get_parent_node(obligation.cause.body_id);
let node = hir.find(parent_node);
Expand All @@ -840,7 +850,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
if let hir::ExprKind::Block(blk, _) = &body.value.kind {
if sig.decl.output.span().overlaps(span)
&& blk.expr.is_none()
&& "()" == &trait_ref.self_ty().to_string()
&& is_empty_tuple(trait_ref.self_ty())
{
// FIXME(estebank): When encountering a method with a trait
// bound not satisfied in the return type with a body that has
Expand Down Expand Up @@ -1271,7 +1281,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
ObligationCauseCode::DerivedObligation(derived_obligation)
| ObligationCauseCode::BuiltinDerivedObligation(derived_obligation)
| ObligationCauseCode::ImplDerivedObligation(derived_obligation) => {
let ty = derived_obligation.parent_trait_ref.self_ty();
let ty = derived_obligation.parent_trait_ref.skip_binder().self_ty();
debug!(
"maybe_note_obligation_cause_for_async_await: \
parent_trait_ref={:?} self_ty.kind={:?}",
Expand Down Expand Up @@ -1917,7 +1927,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {

let impls_future = self.tcx.type_implements_trait((
future_trait,
self_ty,
self_ty.skip_binder(),
ty::List::empty(),
obligation.param_env,
));
Expand All @@ -1933,7 +1943,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
let projection_ty = ty::ProjectionTy {
// `T`
substs: self.tcx.mk_substs_trait(
trait_ref.self_ty(),
trait_ref.self_ty().skip_binder(),
self.fresh_substs_for_item(span, item_def_id),
),
// `Future::Output`
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_trait_selection/traits/specialize/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ fn to_pretty_impl_header(tcx: TyCtxt<'_>, impl_def_id: DefId) -> Option<String>
for (p, _) in predicates {
if let Some(poly_trait_ref) = p.to_opt_poly_trait_ref() {
if Some(poly_trait_ref.def_id()) == sized_trait {
types_without_default_bounds.remove(poly_trait_ref.self_ty());
types_without_default_bounds.remove(poly_trait_ref.self_ty().skip_binder());
continue;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3813,7 +3813,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
trait_ref: ty::PolyTraitRef<'tcx>,
expected_vid: ty::TyVid,
) -> bool {
let self_ty = self.shallow_resolve(trait_ref.self_ty());
let self_ty = self.shallow_resolve(trait_ref.skip_binder().self_ty());
debug!(
"self_type_matches_expected_vid(trait_ref={:?}, self_ty={:?}, expected_vid={:?})",
trait_ref, self_ty, expected_vid
Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ impl<'a> Clean<WherePredicate> for ty::PolyTraitPredicate<'a> {
fn clean(&self, cx: &DocContext<'_>) -> WherePredicate {
let poly_trait_ref = self.map_bound(|pred| pred.trait_ref);
WherePredicate::BoundPredicate {
ty: poly_trait_ref.self_ty().clean(cx),
ty: poly_trait_ref.skip_binder().self_ty().clean(cx),
bounds: vec![poly_trait_ref.clean(cx)],
}
}
Expand Down Expand Up @@ -755,7 +755,7 @@ impl<'a, 'tcx> Clean<Generics> for (&'a ty::Generics, ty::GenericPredicates<'tcx
let mut projection = None;
let param_idx = (|| {
if let Some(trait_ref) = p.to_opt_poly_trait_ref() {
if let ty::Param(param) = trait_ref.self_ty().kind {
if let ty::Param(param) = trait_ref.skip_binder().self_ty().kind {
return Some(param.index);
}
} else if let Some(outlives) = p.to_opt_type_outlives() {
Expand Down
8 changes: 8 additions & 0 deletions src/libstd/net/addr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1000,6 +1000,14 @@ impl ToSocketAddrs for (&str, u16) {
}
}

#[stable(feature = "string_u16_to_socket_addrs", since = "1.46.0")]
impl ToSocketAddrs for (String, u16) {
type Iter = vec::IntoIter<SocketAddr>;
fn to_socket_addrs(&self) -> io::Result<vec::IntoIter<SocketAddr>> {
(&*self.0, self.1).to_socket_addrs()
}
}

// accepts strings like 'localhost:12345'
#[stable(feature = "rust1", since = "1.0.0")]
impl ToSocketAddrs for str {
Expand Down
1 change: 1 addition & 0 deletions src/test/codegen/abi-main-signature-16bit-c-int.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
// ignore-mips64
// ignore-powerpc
// ignore-powerpc64
// ignore-riscv64
// ignore-s390x
// ignore-sparc
// ignore-sparc64
Expand Down
1 change: 1 addition & 0 deletions src/test/codegen/abi-sysv64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

// ignore-arm
// ignore-aarch64
// ignore-riscv64 sysv64 not supported

// compile-flags: -C no-prepopulate-passes

Expand Down
1 change: 1 addition & 0 deletions src/test/codegen/abi-x86-interrupt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

// ignore-arm
// ignore-aarch64
// ignore-riscv64 x86-interrupt is not supported

// compile-flags: -C no-prepopulate-passes

Expand Down
2 changes: 2 additions & 0 deletions src/test/codegen/call-llvm-intrinsics.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// compile-flags: -C no-prepopulate-passes

// ignore-riscv64

#![feature(link_llvm_intrinsics)]
#![crate_type = "lib"]

Expand Down
9 changes: 9 additions & 0 deletions src/test/codegen/catch-unwind.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
// compile-flags: -O

// On x86 the closure is inlined in foo() producting something like
// define i32 @foo() [...] {
// tail call void @bar() [...]
// ret i32 0
// }
// On riscv the closure is another function, placed before fn foo so CHECK can't
// find it
// ignore-riscv64 FIXME

#![crate_type = "lib"]

extern "C" {
Expand Down
1 change: 1 addition & 0 deletions src/test/codegen/fastcall-inreg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
// ignore-powerpc64le
// ignore-powerpc
// ignore-r600
// ignore-riscv64
// ignore-amdgcn
// ignore-sparc
// ignore-sparc64
Expand Down
1 change: 1 addition & 0 deletions src/test/codegen/repr-transparent-aggregates-1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
// ignore-mips64
// ignore-powerpc
// ignore-powerpc64
// ignore-riscv64 see codegen/riscv-abi
// ignore-windows
// See repr-transparent.rs

Expand Down
1 change: 1 addition & 0 deletions src/test/codegen/repr-transparent-aggregates-2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// ignore-powerpc
// ignore-powerpc64
// ignore-powerpc64le
// ignore-riscv64 see codegen/riscv-abi
// ignore-s390x
// ignore-sparc
// ignore-sparc64
Expand Down
3 changes: 3 additions & 0 deletions src/test/codegen/repr-transparent.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
// compile-flags: -C no-prepopulate-passes

// ignore-riscv64 riscv64 has an i128 type used with test_Vector
// see codegen/riscv-abi for riscv functiona call tests

#![crate_type="lib"]
#![feature(repr_simd, transparent_unions)]

Expand Down
30 changes: 30 additions & 0 deletions src/test/codegen/riscv-abi/call-llvm-intrinsics.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// compile-flags: -C no-prepopulate-passes

// only-riscv64

#![feature(link_llvm_intrinsics)]
#![crate_type = "lib"]

struct A;

impl Drop for A {
fn drop(&mut self) {
println!("A");
}
}

extern {
#[link_name = "llvm.sqrt.f32"]
fn sqrt(x: f32) -> f32;
}

pub fn do_call() {
let _a = A;

unsafe {
// Ensure that we `call` LLVM intrinsics instead of trying to `invoke` them
// CHECK: store float 4.000000e+00, float* %{{.}}, align 4
// CHECK: call float @llvm.sqrt.f32(float %{{.}}
sqrt(4.0);
}
}
Loading