Skip to content

Commit d3848cb

Browse files
committed
Auto merge of rust-lang#92064 - matthiaskrgr:rollup-tgj2pai, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - rust-lang#91858 (pass -Wl,-z,origin to set DF_ORIGIN when using rpath) - rust-lang#91923 (Remove `in_band_lifetimes` from `rustc_query_impl`) - rust-lang#91925 (Remove `in_band_lifetimes` from `rustc_privacy`) - rust-lang#91977 (Clean up search code and unify function returned values) - rust-lang#92018 (Fix typo in "new region bound" suggestion) - rust-lang#92022 (Eliminate duplicate codes of expected_found_bool) - rust-lang#92032 (hir: Do not introduce dummy type names for `extern` blocks in def paths) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents d3f3004 + 5e8f934 commit d3848cb

33 files changed

+183
-192
lines changed

compiler/rustc_codegen_ssa/src/back/rpath.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,12 @@ pub fn get_rpath_flags(config: &mut RPathConfig<'_>) -> Vec<String> {
2323
let rpaths = get_rpaths(config);
2424
let mut flags = rpaths_to_flags(&rpaths);
2525

26-
// Use DT_RUNPATH instead of DT_RPATH if available
2726
if config.linker_is_gnu {
27+
// Use DT_RUNPATH instead of DT_RPATH if available
2828
flags.push("-Wl,--enable-new-dtags".to_owned());
29+
30+
// Set DF_ORIGIN for substitute $ORIGIN
31+
flags.push("-Wl,-z,origin".to_owned());
2932
}
3033

3134
flags

compiler/rustc_hir/src/definitions.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,8 @@ pub enum DefPathData {
267267
// Different kinds of items and item-like things:
268268
/// An impl.
269269
Impl,
270+
/// An `extern` block.
271+
ForeignMod,
270272
/// Something in the type namespace.
271273
TypeNs(Symbol),
272274
/// Something in the value namespace.
@@ -469,7 +471,9 @@ impl DefPathData {
469471
match *self {
470472
TypeNs(name) | ValueNs(name) | MacroNs(name) | LifetimeNs(name) => Some(name),
471473

472-
Impl | CrateRoot | Misc | ClosureExpr | Ctor | AnonConst | ImplTrait => None,
474+
Impl | ForeignMod | CrateRoot | Misc | ClosureExpr | Ctor | AnonConst | ImplTrait => {
475+
None
476+
}
473477
}
474478
}
475479

@@ -482,6 +486,7 @@ impl DefPathData {
482486
// Note that this does not show up in user print-outs.
483487
CrateRoot => DefPathDataName::Anon { namespace: kw::Crate },
484488
Impl => DefPathDataName::Anon { namespace: kw::Impl },
489+
ForeignMod => DefPathDataName::Anon { namespace: kw::Extern },
485490
Misc => DefPathDataName::Anon { namespace: sym::misc },
486491
ClosureExpr => DefPathDataName::Anon { namespace: sym::closure },
487492
Ctor => DefPathDataName::Anon { namespace: sym::constructor },

compiler/rustc_infer/src/infer/combine.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use crate::traits::{Obligation, PredicateObligations};
3737
use rustc_data_structures::sso::SsoHashMap;
3838
use rustc_hir::def_id::DefId;
3939
use rustc_middle::traits::ObligationCause;
40-
use rustc_middle::ty::error::TypeError;
40+
use rustc_middle::ty::error::{ExpectedFound, TypeError};
4141
use rustc_middle::ty::relate::{self, Relate, RelateResult, TypeRelation};
4242
use rustc_middle::ty::subst::SubstsRef;
4343
use rustc_middle::ty::{self, InferConst, ToPredicate, Ty, TyCtxt, TypeFoldable};
@@ -790,23 +790,23 @@ pub fn const_unification_error<'tcx>(
790790
a_is_expected: bool,
791791
(a, b): (&'tcx ty::Const<'tcx>, &'tcx ty::Const<'tcx>),
792792
) -> TypeError<'tcx> {
793-
TypeError::ConstMismatch(ty::relate::expected_found_bool(a_is_expected, a, b))
793+
TypeError::ConstMismatch(ExpectedFound::new(a_is_expected, a, b))
794794
}
795795

796796
fn int_unification_error<'tcx>(
797797
a_is_expected: bool,
798798
v: (ty::IntVarValue, ty::IntVarValue),
799799
) -> TypeError<'tcx> {
800800
let (a, b) = v;
801-
TypeError::IntMismatch(ty::relate::expected_found_bool(a_is_expected, a, b))
801+
TypeError::IntMismatch(ExpectedFound::new(a_is_expected, a, b))
802802
}
803803

804804
fn float_unification_error<'tcx>(
805805
a_is_expected: bool,
806806
v: (ty::FloatVarValue, ty::FloatVarValue),
807807
) -> TypeError<'tcx> {
808808
let (ty::FloatVarValue(a), ty::FloatVarValue(b)) = v;
809-
TypeError::FloatMismatch(ty::relate::expected_found_bool(a_is_expected, a, b))
809+
TypeError::FloatMismatch(ExpectedFound::new(a_is_expected, a, b))
810810
}
811811

812812
struct ConstInferUnifier<'cx, 'tcx> {

compiler/rustc_infer/src/infer/error_reporting/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ pub fn unexpected_hidden_region_diagnostic(
275275
fn_returns,
276276
hidden_region.to_string(),
277277
None,
278-
format!("captures {}", hidden_region),
278+
format!("captures `{}`", hidden_region),
279279
None,
280280
)
281281
}

compiler/rustc_lint/src/context.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1030,8 +1030,8 @@ impl<'tcx> LateContext<'tcx> {
10301030
) -> Result<Self::Path, Self::Error> {
10311031
let mut path = print_prefix(self)?;
10321032

1033-
// Skip `::{{constructor}}` on tuple/unit structs.
1034-
if let DefPathData::Ctor = disambiguated_data.data {
1033+
// Skip `::{{extern}}` blocks and `::{{constructor}}` on tuple/unit structs.
1034+
if let DefPathData::ForeignMod | DefPathData::Ctor = disambiguated_data.data {
10351035
return Ok(path);
10361036
}
10371037

compiler/rustc_middle/src/ty/print/pretty.rs

+12-16
Original file line numberDiff line numberDiff line change
@@ -1740,30 +1740,26 @@ impl<F: fmt::Write> Printer<'tcx> for FmtPrinter<'_, 'tcx, F> {
17401740
) -> Result<Self::Path, Self::Error> {
17411741
self = print_prefix(self)?;
17421742

1743-
// Skip `::{{constructor}}` on tuple/unit structs.
1744-
if let DefPathData::Ctor = disambiguated_data.data {
1743+
// Skip `::{{extern}}` blocks and `::{{constructor}}` on tuple/unit structs.
1744+
if let DefPathData::ForeignMod | DefPathData::Ctor = disambiguated_data.data {
17451745
return Ok(self);
17461746
}
17471747

1748-
// FIXME(eddyb) `name` should never be empty, but it
1749-
// currently is for `extern { ... }` "foreign modules".
17501748
let name = disambiguated_data.data.name();
1751-
if name != DefPathDataName::Named(kw::Empty) {
1752-
if !self.empty_path {
1753-
write!(self, "::")?;
1754-
}
1749+
if !self.empty_path {
1750+
write!(self, "::")?;
1751+
}
17551752

1756-
if let DefPathDataName::Named(name) = name {
1757-
if Ident::with_dummy_span(name).is_raw_guess() {
1758-
write!(self, "r#")?;
1759-
}
1753+
if let DefPathDataName::Named(name) = name {
1754+
if Ident::with_dummy_span(name).is_raw_guess() {
1755+
write!(self, "r#")?;
17601756
}
1757+
}
17611758

1762-
let verbose = self.tcx.sess.verbose();
1763-
disambiguated_data.fmt_maybe_verbose(&mut self, verbose)?;
1759+
let verbose = self.tcx.sess.verbose();
1760+
disambiguated_data.fmt_maybe_verbose(&mut self, verbose)?;
17641761

1765-
self.empty_path = false;
1766-
}
1762+
self.empty_path = false;
17671763

17681764
Ok(self)
17691765
}

compiler/rustc_middle/src/ty/relate.rs

+1-9
Original file line numberDiff line numberDiff line change
@@ -836,13 +836,5 @@ pub fn expected_found<R, T>(relation: &mut R, a: T, b: T) -> ExpectedFound<T>
836836
where
837837
R: TypeRelation<'tcx>,
838838
{
839-
expected_found_bool(relation.a_is_expected(), a, b)
840-
}
841-
842-
pub fn expected_found_bool<T>(a_is_expected: bool, a: T, b: T) -> ExpectedFound<T> {
843-
if a_is_expected {
844-
ExpectedFound { expected: a, found: b }
845-
} else {
846-
ExpectedFound { expected: b, found: a }
847-
}
839+
ExpectedFound::new(relation.a_is_expected(), a, b)
848840
}

compiler/rustc_privacy/src/lib.rs

+8-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
2-
#![feature(in_band_lifetimes)]
32
#![feature(nll)]
43
#![feature(control_flow_enum)]
54
#![feature(try_blocks)]
@@ -310,7 +309,7 @@ struct PubRestrictedVisitor<'tcx> {
310309
has_pub_restricted: bool,
311310
}
312311

313-
impl Visitor<'tcx> for PubRestrictedVisitor<'tcx> {
312+
impl<'tcx> Visitor<'tcx> for PubRestrictedVisitor<'tcx> {
314313
type Map = Map<'tcx>;
315314

316315
fn nested_visit_map(&mut self) -> NestedVisitorMap<Self::Map> {
@@ -432,7 +431,7 @@ struct ReachEverythingInTheInterfaceVisitor<'a, 'tcx> {
432431
ev: &'a mut EmbargoVisitor<'tcx>,
433432
}
434433

435-
impl EmbargoVisitor<'tcx> {
434+
impl<'tcx> EmbargoVisitor<'tcx> {
436435
fn get(&self, def_id: LocalDefId) -> Option<AccessLevel> {
437436
self.access_levels.map.get(&def_id).copied()
438437
}
@@ -674,7 +673,7 @@ impl EmbargoVisitor<'tcx> {
674673
}
675674
}
676675

677-
impl Visitor<'tcx> for EmbargoVisitor<'tcx> {
676+
impl<'tcx> Visitor<'tcx> for EmbargoVisitor<'tcx> {
678677
type Map = Map<'tcx>;
679678

680679
/// We want to visit items in the context of their containing
@@ -944,7 +943,7 @@ impl Visitor<'tcx> for EmbargoVisitor<'tcx> {
944943
}
945944
}
946945

947-
impl ReachEverythingInTheInterfaceVisitor<'_, 'tcx> {
946+
impl ReachEverythingInTheInterfaceVisitor<'_, '_> {
948947
fn generics(&mut self) -> &mut Self {
949948
for param in &self.ev.tcx.generics_of(self.item_def_id).params {
950949
match param.kind {
@@ -983,7 +982,7 @@ impl ReachEverythingInTheInterfaceVisitor<'_, 'tcx> {
983982
}
984983
}
985984

986-
impl DefIdVisitor<'tcx> for ReachEverythingInTheInterfaceVisitor<'_, 'tcx> {
985+
impl<'tcx> DefIdVisitor<'tcx> for ReachEverythingInTheInterfaceVisitor<'_, 'tcx> {
987986
fn tcx(&self) -> TyCtxt<'tcx> {
988987
self.ev.tcx
989988
}
@@ -1413,7 +1412,7 @@ impl<'tcx> Visitor<'tcx> for TypePrivacyVisitor<'tcx> {
14131412
}
14141413
}
14151414

1416-
impl DefIdVisitor<'tcx> for TypePrivacyVisitor<'tcx> {
1415+
impl<'tcx> DefIdVisitor<'tcx> for TypePrivacyVisitor<'tcx> {
14171416
fn tcx(&self) -> TyCtxt<'tcx> {
14181417
self.tcx
14191418
}
@@ -1800,7 +1799,7 @@ struct SearchInterfaceForPrivateItemsVisitor<'tcx> {
18001799
in_assoc_ty: bool,
18011800
}
18021801

1803-
impl SearchInterfaceForPrivateItemsVisitor<'tcx> {
1802+
impl SearchInterfaceForPrivateItemsVisitor<'_> {
18041803
fn generics(&mut self) -> &mut Self {
18051804
for param in &self.tcx.generics_of(self.item_def_id).params {
18061805
match param.kind {
@@ -1921,7 +1920,7 @@ impl SearchInterfaceForPrivateItemsVisitor<'tcx> {
19211920
}
19221921
}
19231922

1924-
impl DefIdVisitor<'tcx> for SearchInterfaceForPrivateItemsVisitor<'tcx> {
1923+
impl<'tcx> DefIdVisitor<'tcx> for SearchInterfaceForPrivateItemsVisitor<'tcx> {
19251924
fn tcx(&self) -> TyCtxt<'tcx> {
19261925
self.tcx
19271926
}

compiler/rustc_query_impl/src/keys.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ impl Key for (DefId, DefId) {
151151
}
152152
}
153153

154-
impl Key for (ty::Instance<'tcx>, LocalDefId) {
154+
impl<'tcx> Key for (ty::Instance<'tcx>, LocalDefId) {
155155
#[inline(always)]
156156
fn query_crate_is_local(&self) -> bool {
157157
true

compiler/rustc_query_impl/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
33
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
44
#![feature(crate_visibility_modifier)]
5-
#![feature(in_band_lifetimes)]
65
#![feature(nll)]
76
#![feature(min_specialization)]
87
#![feature(once_cell)]

compiler/rustc_query_impl/src/on_disk_cache.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ impl<'sess> rustc_middle::ty::OnDiskCache<'sess> for OnDiskCache<'sess> {
212212
/// Cache promotions require invoking queries, which needs to read the serialized data.
213213
/// In order to serialize the new on-disk cache, the former on-disk cache file needs to be
214214
/// deleted, hence we won't be able to refer to its memmapped data.
215-
fn drop_serialized_data(&self, tcx: TyCtxt<'tcx>) {
215+
fn drop_serialized_data(&self, tcx: TyCtxt<'_>) {
216216
// Load everything into memory so we can write it out to the on-disk
217217
// cache. The vast majority of cacheable query results should already
218218
// be in memory, so this should be a cheap operation.

compiler/rustc_query_impl/src/plumbing.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ impl<'tcx> std::ops::Deref for QueryCtxt<'tcx> {
3131
}
3232
}
3333

34-
impl HasDepContext for QueryCtxt<'tcx> {
34+
impl<'tcx> HasDepContext for QueryCtxt<'tcx> {
3535
type DepKind = rustc_middle::dep_graph::DepKind;
3636
type DepContext = TyCtxt<'tcx>;
3737

@@ -41,7 +41,7 @@ impl HasDepContext for QueryCtxt<'tcx> {
4141
}
4242
}
4343

44-
impl QueryContext for QueryCtxt<'tcx> {
44+
impl QueryContext for QueryCtxt<'_> {
4545
fn current_query_job(&self) -> Option<QueryJobId<Self::DepKind>> {
4646
tls::with_related_context(**self, |icx| icx.query)
4747
}
@@ -130,7 +130,7 @@ impl<'tcx> QueryCtxt<'tcx> {
130130

131131
pub(super) fn encode_query_results(
132132
self,
133-
encoder: &mut on_disk_cache::CacheEncoder<'a, 'tcx, opaque::FileEncoder>,
133+
encoder: &mut on_disk_cache::CacheEncoder<'_, 'tcx, opaque::FileEncoder>,
134134
query_result_index: &mut on_disk_cache::EncodedDepNodeIndex,
135135
) -> opaque::FileEncodeResult {
136136
macro_rules! encode_queries {
@@ -511,7 +511,7 @@ macro_rules! define_queries_struct {
511511
}
512512
}
513513

514-
impl QueryEngine<'tcx> for Queries<'tcx> {
514+
impl<'tcx> QueryEngine<'tcx> for Queries<'tcx> {
515515
fn as_any(&'tcx self) -> &'tcx dyn std::any::Any {
516516
let this = unsafe { std::mem::transmute::<&Queries<'_>, &Queries<'_>>(self) };
517517
this as _

compiler/rustc_query_impl/src/profiling_support.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ fn alloc_self_profile_query_strings_for_query_cache<'tcx, C>(
295295
/// If we are recording only summary data, the ids will point to
296296
/// just the query names. If we are recording query keys too, we
297297
/// allocate the corresponding strings here.
298-
pub fn alloc_self_profile_query_strings(tcx: TyCtxt<'tcx>) {
298+
pub fn alloc_self_profile_query_strings(tcx: TyCtxt<'_>) {
299299
if !tcx.prof.enabled() {
300300
return;
301301
}

compiler/rustc_resolve/src/def_collector.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,14 @@ impl<'a, 'b> visit::Visitor<'a> for DefCollector<'a, 'b> {
9292
// information we encapsulate into, the better
9393
let def_data = match &i.kind {
9494
ItemKind::Impl { .. } => DefPathData::Impl,
95+
ItemKind::ForeignMod(..) => DefPathData::ForeignMod,
9596
ItemKind::Mod(..)
9697
| ItemKind::Trait(..)
9798
| ItemKind::TraitAlias(..)
9899
| ItemKind::Enum(..)
99100
| ItemKind::Struct(..)
100101
| ItemKind::Union(..)
101102
| ItemKind::ExternCrate(..)
102-
| ItemKind::ForeignMod(..)
103103
| ItemKind::TyAlias(..) => DefPathData::TypeNs(i.ident.name),
104104
ItemKind::Static(..) | ItemKind::Const(..) | ItemKind::Fn(..) => {
105105
DefPathData::ValueNs(i.ident.name)

compiler/rustc_symbol_mangling/src/legacy.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,8 @@ impl<'tcx> Printer<'tcx> for &mut SymbolPrinter<'tcx> {
311311
) -> Result<Self::Path, Self::Error> {
312312
self = print_prefix(self)?;
313313

314-
// Skip `::{{constructor}}` on tuple/unit structs.
315-
if let DefPathData::Ctor = disambiguated_data.data {
314+
// Skip `::{{extern}}` blocks and `::{{constructor}}` on tuple/unit structs.
315+
if let DefPathData::ForeignMod | DefPathData::Ctor = disambiguated_data.data {
316316
return Ok(self);
317317
}
318318

compiler/rustc_symbol_mangling/src/v0.rs

+4
Original file line numberDiff line numberDiff line change
@@ -771,6 +771,10 @@ impl<'tcx> Printer<'tcx> for &mut SymbolMangler<'tcx> {
771771
disambiguated_data: &DisambiguatedDefPathData,
772772
) -> Result<Self::Path, Self::Error> {
773773
let ns = match disambiguated_data.data {
774+
// FIXME: It shouldn't be necessary to add anything for extern block segments,
775+
// but we add 't' for backward compatibility.
776+
DefPathData::ForeignMod => 't',
777+
774778
// Uppercase categories are more stable than lowercase ones.
775779
DefPathData::TypeNs(_) => 't',
776780
DefPathData::ValueNs(_) => 'v',

compiler/rustc_typeck/src/check/expr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ use rustc_infer::infer;
3636
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
3737
use rustc_infer::infer::InferOk;
3838
use rustc_middle::ty::adjustment::{Adjust, Adjustment, AllowTwoPhase};
39+
use rustc_middle::ty::error::ExpectedFound;
3940
use rustc_middle::ty::error::TypeError::{FieldMisMatch, Sorts};
40-
use rustc_middle::ty::relate::expected_found_bool;
4141
use rustc_middle::ty::subst::SubstsRef;
4242
use rustc_middle::ty::{self, AdtKind, Ty, TypeFoldable};
4343
use rustc_session::parse::feature_err;
@@ -1493,7 +1493,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14931493
&self.misc(base_expr.span),
14941494
adt_ty,
14951495
base_ty,
1496-
Sorts(expected_found_bool(true, adt_ty, base_ty)),
1496+
Sorts(ExpectedFound::new(true, adt_ty, base_ty)),
14971497
)
14981498
.emit();
14991499
}

src/bootstrap/builder.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1176,6 +1176,7 @@ impl<'a> Builder<'a> {
11761176
rustflags.arg("-Zosx-rpath-install-name");
11771177
Some("-Wl,-rpath,@loader_path/../lib")
11781178
} else if !target.contains("windows") {
1179+
rustflags.arg("-Clink-args=-Wl,-z,origin");
11791180
Some("-Wl,-rpath,$ORIGIN/../lib")
11801181
} else {
11811182
None

src/librustdoc/clean/inline.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use rustc_data_structures::fx::FxHashSet;
88
use rustc_hir as hir;
99
use rustc_hir::def::{DefKind, Res};
1010
use rustc_hir::def_id::DefId;
11+
use rustc_hir::definitions::DefPathData;
1112
use rustc_hir::Mutability;
1213
use rustc_metadata::creader::{CStore, LoadedMacro};
1314
use rustc_middle::ty::{self, TyCtxt};
@@ -165,9 +166,8 @@ crate fn record_extern_fqn(cx: &mut DocContext<'_>, did: DefId, kind: ItemType)
165166
let crate_name = cx.tcx.crate_name(did.krate).to_string();
166167

167168
let relative = cx.tcx.def_path(did).data.into_iter().filter_map(|elem| {
168-
// extern blocks have an empty name
169-
let s = elem.data.to_string();
170-
if !s.is_empty() { Some(s) } else { None }
169+
// Filter out extern blocks
170+
(elem.data != DefPathData::ForeignMod).then(|| elem.data.to_string())
171171
});
172172
let fqn = if let ItemType::Macro = kind {
173173
// Check to see if it is a macro 2.0 or built-in macro

0 commit comments

Comments
 (0)