Skip to content

Commit 9c1857f

Browse files
committed
Auto merge of #73073 - RalfJung:rollup-i24dh28, r=RalfJung
Rollup of 3 pull requests Successful merges: - #71796 (de-promote Duration::from_secs) - #72508 (Make `PolyTraitRef::self_ty` return `Binder<Ty>`) - #72708 (linker: Add a linker rerun hack for gcc versions not supporting -static-pie) Failed merges: r? @ghost
2 parents 118b505 + d112d8b commit 9c1857f

File tree

10 files changed

+107
-34
lines changed

10 files changed

+107
-34
lines changed

src/libcore/time.rs

-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@ impl Duration {
152152
/// ```
153153
#[stable(feature = "duration", since = "1.3.0")]
154154
#[inline]
155-
#[rustc_promotable]
156155
#[rustc_const_stable(feature = "duration_consts", since = "1.32.0")]
157156
pub const fn from_secs(secs: u64) -> Duration {
158157
Duration { secs, nanos: 0 }

src/librustc_codegen_ssa/back/link.rs

+57-8
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use rustc_session::utils::NativeLibKind;
1212
/// need out of the shared crate context before we get rid of it.
1313
use rustc_session::{filesearch, Session};
1414
use rustc_span::symbol::Symbol;
15-
use rustc_target::spec::crt_objects::CrtObjectsFallback;
15+
use rustc_target::spec::crt_objects::{CrtObjects, CrtObjectsFallback};
1616
use rustc_target::spec::{LinkOutputKind, LinkerFlavor, LldFlavor};
1717
use rustc_target::spec::{PanicStrategy, RelocModel, RelroLevel};
1818

@@ -25,16 +25,10 @@ use crate::{looks_like_rust_object_file, CodegenResults, CrateInfo, METADATA_FIL
2525
use cc::windows_registry;
2626
use tempfile::{Builder as TempFileBuilder, TempDir};
2727

28-
use std::ascii;
29-
use std::char;
30-
use std::env;
3128
use std::ffi::OsString;
32-
use std::fmt;
33-
use std::fs;
34-
use std::io;
3529
use std::path::{Path, PathBuf};
3630
use std::process::{ExitStatus, Output, Stdio};
37-
use std::str;
31+
use std::{ascii, char, env, fmt, fs, io, mem, str};
3832

3933
pub fn remove(sess: &Session, path: &Path) {
4034
if let Err(e) = fs::remove_file(path) {
@@ -543,6 +537,61 @@ fn link_natively<'a, B: ArchiveBuilder<'a>>(
543537
continue;
544538
}
545539

540+
// Detect '-static-pie' used with an older version of gcc or clang not supporting it.
541+
// Fallback from '-static-pie' to '-static' in that case.
542+
if sess.target.target.options.linker_is_gnu
543+
&& flavor != LinkerFlavor::Ld
544+
&& (out.contains("unrecognized command line option")
545+
|| out.contains("unknown argument"))
546+
&& (out.contains("-static-pie") || out.contains("--no-dynamic-linker"))
547+
&& cmd.get_args().iter().any(|e| e.to_string_lossy() == "-static-pie")
548+
{
549+
info!("linker output: {:?}", out);
550+
warn!(
551+
"Linker does not support -static-pie command line option. Retrying with -static instead."
552+
);
553+
// Mirror `add_(pre,post)_link_objects` to replace CRT objects.
554+
let fallback = crt_objects_fallback(sess, crate_type);
555+
let opts = &sess.target.target.options;
556+
let pre_objects =
557+
if fallback { &opts.pre_link_objects_fallback } else { &opts.pre_link_objects };
558+
let post_objects =
559+
if fallback { &opts.post_link_objects_fallback } else { &opts.post_link_objects };
560+
let get_objects = |objects: &CrtObjects, kind| {
561+
objects
562+
.get(&kind)
563+
.iter()
564+
.copied()
565+
.flatten()
566+
.map(|obj| get_object_file_path(sess, obj).into_os_string())
567+
.collect::<Vec<_>>()
568+
};
569+
let pre_objects_static_pie = get_objects(pre_objects, LinkOutputKind::StaticPicExe);
570+
let post_objects_static_pie = get_objects(post_objects, LinkOutputKind::StaticPicExe);
571+
let mut pre_objects_static = get_objects(pre_objects, LinkOutputKind::StaticNoPicExe);
572+
let mut post_objects_static = get_objects(post_objects, LinkOutputKind::StaticNoPicExe);
573+
// Assume that we know insertion positions for the replacement arguments from replaced
574+
// arguments, which is true for all supported targets.
575+
assert!(pre_objects_static.is_empty() || !pre_objects_static_pie.is_empty());
576+
assert!(post_objects_static.is_empty() || !post_objects_static_pie.is_empty());
577+
for arg in cmd.take_args() {
578+
if arg.to_string_lossy() == "-static-pie" {
579+
// Replace the output kind.
580+
cmd.arg("-static");
581+
} else if pre_objects_static_pie.contains(&arg) {
582+
// Replace the pre-link objects (replace the first and remove the rest).
583+
cmd.args(mem::take(&mut pre_objects_static));
584+
} else if post_objects_static_pie.contains(&arg) {
585+
// Replace the post-link objects (replace the first and remove the rest).
586+
cmd.args(mem::take(&mut post_objects_static));
587+
} else {
588+
cmd.arg(arg);
589+
}
590+
}
591+
info!("{:?}", &cmd);
592+
continue;
593+
}
594+
546595
// Here's a terribly awful hack that really shouldn't be present in any
547596
// compiler. Here an environment variable is supported to automatically
548597
// retry the linker invocation if the linker looks like it segfaulted.

src/librustc_middle/ty/sty.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -765,8 +765,8 @@ impl<'tcx> TraitRef<'tcx> {
765765
pub type PolyTraitRef<'tcx> = Binder<TraitRef<'tcx>>;
766766

767767
impl<'tcx> PolyTraitRef<'tcx> {
768-
pub fn self_ty(&self) -> Ty<'tcx> {
769-
self.skip_binder().self_ty()
768+
pub fn self_ty(&self) -> Binder<Ty<'tcx>> {
769+
self.map_bound_ref(|tr| tr.self_ty())
770770
}
771771

772772
pub fn def_id(&self) -> DefId {

src/librustc_target/spec/tests/tests_impl.rs

+5
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,10 @@ impl Target {
3838
assert_eq!(self.options.lld_flavor, LldFlavor::Link);
3939
}
4040
}
41+
assert!(
42+
(self.options.pre_link_objects_fallback.is_empty()
43+
&& self.options.post_link_objects_fallback.is_empty())
44+
|| self.options.crt_objects_fallback.is_some()
45+
);
4146
}
4247
}

src/librustc_trait_selection/traits/error_reporting/mod.rs

+21-11
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
290290
(
291291
Some(format!(
292292
"`?` couldn't convert the error to `{}`",
293-
trait_ref.self_ty(),
293+
trait_ref.skip_binder().self_ty(),
294294
)),
295295
Some(
296296
"the question mark operation (`?`) implicitly performs a \
@@ -340,7 +340,10 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
340340
if let Some(ret_span) = self.return_type_span(obligation) {
341341
err.span_label(
342342
ret_span,
343-
&format!("expected `{}` because of this", trait_ref.self_ty()),
343+
&format!(
344+
"expected `{}` because of this",
345+
trait_ref.skip_binder().self_ty()
346+
),
344347
);
345348
}
346349
}
@@ -353,7 +356,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
353356
"{}the trait `{}` is not implemented for `{}`",
354357
pre_message,
355358
trait_ref.print_only_trait_path(),
356-
trait_ref.self_ty(),
359+
trait_ref.skip_binder().self_ty(),
357360
)
358361
};
359362

@@ -643,7 +646,10 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
643646
return;
644647
}
645648

646-
let found_trait_ty = found_trait_ref.self_ty();
649+
let found_trait_ty = match found_trait_ref.self_ty().no_bound_vars() {
650+
Some(ty) => ty,
651+
None => return,
652+
};
647653

648654
let found_did = match found_trait_ty.kind {
649655
ty::Closure(did, _) | ty::Foreign(did) | ty::FnDef(did, _) => Some(did),
@@ -1360,11 +1366,15 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
13601366
) {
13611367
let get_trait_impl = |trait_def_id| {
13621368
let mut trait_impl = None;
1363-
self.tcx.for_each_relevant_impl(trait_def_id, trait_ref.self_ty(), |impl_def_id| {
1364-
if trait_impl.is_none() {
1365-
trait_impl = Some(impl_def_id);
1366-
}
1367-
});
1369+
self.tcx.for_each_relevant_impl(
1370+
trait_def_id,
1371+
trait_ref.skip_binder().self_ty(),
1372+
|impl_def_id| {
1373+
if trait_impl.is_none() {
1374+
trait_impl = Some(impl_def_id);
1375+
}
1376+
},
1377+
);
13681378
trait_impl
13691379
};
13701380
let required_trait_path = self.tcx.def_path_str(trait_ref.def_id());
@@ -1435,7 +1445,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
14351445
let mut err = match predicate.kind() {
14361446
ty::PredicateKind::Trait(ref data, _) => {
14371447
let trait_ref = data.to_poly_trait_ref();
1438-
let self_ty = trait_ref.self_ty();
1448+
let self_ty = trait_ref.skip_binder().self_ty();
14391449
debug!("self_ty {:?} {:?} trait_ref {:?}", self_ty, self_ty.kind, trait_ref);
14401450

14411451
if predicate.references_error() {
@@ -1564,7 +1574,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
15641574
}
15651575
ty::PredicateKind::Projection(ref data) => {
15661576
let trait_ref = data.to_poly_trait_ref(self.tcx);
1567-
let self_ty = trait_ref.self_ty();
1577+
let self_ty = trait_ref.skip_binder().self_ty();
15681578
let ty = data.skip_binder().ty;
15691579
if predicate.references_error() {
15701580
return;

src/librustc_trait_selection/traits/error_reporting/suggestions.rs

+17-7
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
318318
trait_ref: ty::PolyTraitRef<'tcx>,
319319
body_id: hir::HirId,
320320
) {
321-
let self_ty = trait_ref.self_ty();
321+
let self_ty = trait_ref.skip_binder().self_ty();
322322
let (param_ty, projection) = match &self_ty.kind {
323323
ty::Param(_) => (true, None),
324324
ty::Projection(projection) => (false, Some(projection)),
@@ -524,7 +524,11 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
524524
trait_ref: &ty::Binder<ty::TraitRef<'tcx>>,
525525
points_at_arg: bool,
526526
) {
527-
let self_ty = trait_ref.self_ty();
527+
let self_ty = match trait_ref.self_ty().no_bound_vars() {
528+
None => return,
529+
Some(ty) => ty,
530+
};
531+
528532
let (def_id, output_ty, callable) = match self_ty.kind {
529533
ty::Closure(def_id, substs) => (def_id, substs.as_closure().sig().output(), "closure"),
530534
ty::FnDef(def_id, _) => (def_id, self_ty.fn_sig(self.tcx).output(), "function"),
@@ -707,7 +711,10 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
707711
return;
708712
}
709713

710-
let mut suggested_ty = trait_ref.self_ty();
714+
let mut suggested_ty = match trait_ref.self_ty().no_bound_vars() {
715+
Some(ty) => ty,
716+
None => return,
717+
};
711718

712719
for refs_remaining in 0..refs_number {
713720
if let ty::Ref(_, inner_ty, _) = suggested_ty.kind {
@@ -829,6 +836,9 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
829836
span: Span,
830837
trait_ref: &ty::Binder<ty::TraitRef<'tcx>>,
831838
) {
839+
let is_empty_tuple =
840+
|ty: ty::Binder<Ty<'_>>| ty.skip_binder().kind == ty::Tuple(ty::List::empty());
841+
832842
let hir = self.tcx.hir();
833843
let parent_node = hir.get_parent_node(obligation.cause.body_id);
834844
let node = hir.find(parent_node);
@@ -840,7 +850,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
840850
if let hir::ExprKind::Block(blk, _) = &body.value.kind {
841851
if sig.decl.output.span().overlaps(span)
842852
&& blk.expr.is_none()
843-
&& "()" == &trait_ref.self_ty().to_string()
853+
&& is_empty_tuple(trait_ref.self_ty())
844854
{
845855
// FIXME(estebank): When encountering a method with a trait
846856
// bound not satisfied in the return type with a body that has
@@ -1271,7 +1281,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
12711281
ObligationCauseCode::DerivedObligation(derived_obligation)
12721282
| ObligationCauseCode::BuiltinDerivedObligation(derived_obligation)
12731283
| ObligationCauseCode::ImplDerivedObligation(derived_obligation) => {
1274-
let ty = derived_obligation.parent_trait_ref.self_ty();
1284+
let ty = derived_obligation.parent_trait_ref.skip_binder().self_ty();
12751285
debug!(
12761286
"maybe_note_obligation_cause_for_async_await: \
12771287
parent_trait_ref={:?} self_ty.kind={:?}",
@@ -1917,7 +1927,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
19171927

19181928
let impls_future = self.tcx.type_implements_trait((
19191929
future_trait,
1920-
self_ty,
1930+
self_ty.skip_binder(),
19211931
ty::List::empty(),
19221932
obligation.param_env,
19231933
));
@@ -1933,7 +1943,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
19331943
let projection_ty = ty::ProjectionTy {
19341944
// `T`
19351945
substs: self.tcx.mk_substs_trait(
1936-
trait_ref.self_ty(),
1946+
trait_ref.self_ty().skip_binder(),
19371947
self.fresh_substs_for_item(span, item_def_id),
19381948
),
19391949
// `Future::Output`

src/librustc_trait_selection/traits/specialize/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ fn to_pretty_impl_header(tcx: TyCtxt<'_>, impl_def_id: DefId) -> Option<String>
496496
for (p, _) in predicates {
497497
if let Some(poly_trait_ref) = p.to_opt_poly_trait_ref() {
498498
if Some(poly_trait_ref.def_id()) == sized_trait {
499-
types_without_default_bounds.remove(poly_trait_ref.self_ty());
499+
types_without_default_bounds.remove(poly_trait_ref.self_ty().skip_binder());
500500
continue;
501501
}
502502
}

src/librustc_typeck/check/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3813,7 +3813,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
38133813
trait_ref: ty::PolyTraitRef<'tcx>,
38143814
expected_vid: ty::TyVid,
38153815
) -> bool {
3816-
let self_ty = self.shallow_resolve(trait_ref.self_ty());
3816+
let self_ty = self.shallow_resolve(trait_ref.skip_binder().self_ty());
38173817
debug!(
38183818
"self_type_matches_expected_vid(trait_ref={:?}, self_ty={:?}, expected_vid={:?})",
38193819
trait_ref, self_ty, expected_vid

src/librustdoc/clean/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ impl<'a> Clean<WherePredicate> for ty::PolyTraitPredicate<'a> {
500500
fn clean(&self, cx: &DocContext<'_>) -> WherePredicate {
501501
let poly_trait_ref = self.map_bound(|pred| pred.trait_ref);
502502
WherePredicate::BoundPredicate {
503-
ty: poly_trait_ref.self_ty().clean(cx),
503+
ty: poly_trait_ref.skip_binder().self_ty().clean(cx),
504504
bounds: vec![poly_trait_ref.clean(cx)],
505505
}
506506
}
@@ -755,7 +755,7 @@ impl<'a, 'tcx> Clean<Generics> for (&'a ty::Generics, ty::GenericPredicates<'tcx
755755
let mut projection = None;
756756
let param_idx = (|| {
757757
if let Some(trait_ref) = p.to_opt_poly_trait_ref() {
758-
if let ty::Param(param) = trait_ref.self_ty().kind {
758+
if let ty::Param(param) = trait_ref.skip_binder().self_ty().kind {
759759
return Some(param.index);
760760
}
761761
} else if let Some(outlives) = p.to_opt_type_outlives() {

src/tools/clippy/clippy_lints/src/future_not_send.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for FutureNotSend {
9595
let trait_ref = trait_pred.to_poly_trait_ref();
9696
db.note(&*format!(
9797
"`{}` doesn't implement `{}`",
98-
trait_ref.self_ty(),
98+
trait_ref.skip_binder().self_ty(),
9999
trait_ref.print_only_trait_path(),
100100
));
101101
}

0 commit comments

Comments
 (0)