From 77a0c65264ebe36ac7e3fecc775cfe05dfeeec46 Mon Sep 17 00:00:00 2001 From: LegionMammal978 Date: Tue, 14 Dec 2021 12:13:07 -0500 Subject: [PATCH 1/8] Remove `in_band_lifetimes` from `rustc_query_impl` See #91867 for more information. --- compiler/rustc_query_impl/src/keys.rs | 2 +- compiler/rustc_query_impl/src/lib.rs | 1 - compiler/rustc_query_impl/src/on_disk_cache.rs | 2 +- compiler/rustc_query_impl/src/plumbing.rs | 8 ++++---- compiler/rustc_query_impl/src/profiling_support.rs | 2 +- 5 files changed, 7 insertions(+), 8 deletions(-) diff --git a/compiler/rustc_query_impl/src/keys.rs b/compiler/rustc_query_impl/src/keys.rs index 344892875961a..581a2bce2e50e 100644 --- a/compiler/rustc_query_impl/src/keys.rs +++ b/compiler/rustc_query_impl/src/keys.rs @@ -151,7 +151,7 @@ impl Key for (DefId, DefId) { } } -impl Key for (ty::Instance<'tcx>, LocalDefId) { +impl<'tcx> Key for (ty::Instance<'tcx>, LocalDefId) { #[inline(always)] fn query_crate_is_local(&self) -> bool { true diff --git a/compiler/rustc_query_impl/src/lib.rs b/compiler/rustc_query_impl/src/lib.rs index 440b6f1983e6e..de9d425353712 100644 --- a/compiler/rustc_query_impl/src/lib.rs +++ b/compiler/rustc_query_impl/src/lib.rs @@ -2,7 +2,6 @@ #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] #![feature(crate_visibility_modifier)] -#![feature(in_band_lifetimes)] #![feature(nll)] #![feature(min_specialization)] #![feature(once_cell)] diff --git a/compiler/rustc_query_impl/src/on_disk_cache.rs b/compiler/rustc_query_impl/src/on_disk_cache.rs index c42decdccff35..11f54ea66fa51 100644 --- a/compiler/rustc_query_impl/src/on_disk_cache.rs +++ b/compiler/rustc_query_impl/src/on_disk_cache.rs @@ -212,7 +212,7 @@ impl<'sess> rustc_middle::ty::OnDiskCache<'sess> for OnDiskCache<'sess> { /// Cache promotions require invoking queries, which needs to read the serialized data. /// In order to serialize the new on-disk cache, the former on-disk cache file needs to be /// deleted, hence we won't be able to refer to its memmapped data. - fn drop_serialized_data(&self, tcx: TyCtxt<'tcx>) { + fn drop_serialized_data(&self, tcx: TyCtxt<'_>) { // Load everything into memory so we can write it out to the on-disk // cache. The vast majority of cacheable query results should already // be in memory, so this should be a cheap operation. diff --git a/compiler/rustc_query_impl/src/plumbing.rs b/compiler/rustc_query_impl/src/plumbing.rs index 2854ba5158b4e..6d76d09f6190e 100644 --- a/compiler/rustc_query_impl/src/plumbing.rs +++ b/compiler/rustc_query_impl/src/plumbing.rs @@ -31,7 +31,7 @@ impl<'tcx> std::ops::Deref for QueryCtxt<'tcx> { } } -impl HasDepContext for QueryCtxt<'tcx> { +impl<'tcx> HasDepContext for QueryCtxt<'tcx> { type DepKind = rustc_middle::dep_graph::DepKind; type DepContext = TyCtxt<'tcx>; @@ -41,7 +41,7 @@ impl HasDepContext for QueryCtxt<'tcx> { } } -impl QueryContext for QueryCtxt<'tcx> { +impl QueryContext for QueryCtxt<'_> { fn current_query_job(&self) -> Option> { tls::with_related_context(**self, |icx| icx.query) } @@ -130,7 +130,7 @@ impl<'tcx> QueryCtxt<'tcx> { pub(super) fn encode_query_results( self, - encoder: &mut on_disk_cache::CacheEncoder<'a, 'tcx, opaque::FileEncoder>, + encoder: &mut on_disk_cache::CacheEncoder<'_, 'tcx, opaque::FileEncoder>, query_result_index: &mut on_disk_cache::EncodedDepNodeIndex, ) -> opaque::FileEncodeResult { macro_rules! encode_queries { @@ -511,7 +511,7 @@ macro_rules! define_queries_struct { } } - impl QueryEngine<'tcx> for Queries<'tcx> { + impl<'tcx> QueryEngine<'tcx> for Queries<'tcx> { fn as_any(&'tcx self) -> &'tcx dyn std::any::Any { let this = unsafe { std::mem::transmute::<&Queries<'_>, &Queries<'_>>(self) }; this as _ diff --git a/compiler/rustc_query_impl/src/profiling_support.rs b/compiler/rustc_query_impl/src/profiling_support.rs index 95edc1e93a538..41ee75c2432d8 100644 --- a/compiler/rustc_query_impl/src/profiling_support.rs +++ b/compiler/rustc_query_impl/src/profiling_support.rs @@ -295,7 +295,7 @@ fn alloc_self_profile_query_strings_for_query_cache<'tcx, C>( /// If we are recording only summary data, the ids will point to /// just the query names. If we are recording query keys too, we /// allocate the corresponding strings here. -pub fn alloc_self_profile_query_strings(tcx: TyCtxt<'tcx>) { +pub fn alloc_self_profile_query_strings(tcx: TyCtxt<'_>) { if !tcx.prof.enabled() { return; } From 29c56fef275b1dc8f3f8ea6b61f215aa87d795a3 Mon Sep 17 00:00:00 2001 From: LegionMammal978 Date: Tue, 14 Dec 2021 12:38:06 -0500 Subject: [PATCH 2/8] Remove `in_band_lifetimes` from `rustc_privacy` See #91867 for more information. --- compiler/rustc_privacy/src/lib.rs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/compiler/rustc_privacy/src/lib.rs b/compiler/rustc_privacy/src/lib.rs index e3d2c9837cf51..10f6f6b1a9fac 100644 --- a/compiler/rustc_privacy/src/lib.rs +++ b/compiler/rustc_privacy/src/lib.rs @@ -1,5 +1,4 @@ #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] -#![feature(in_band_lifetimes)] #![feature(nll)] #![feature(control_flow_enum)] #![feature(try_blocks)] @@ -310,7 +309,7 @@ struct PubRestrictedVisitor<'tcx> { has_pub_restricted: bool, } -impl Visitor<'tcx> for PubRestrictedVisitor<'tcx> { +impl<'tcx> Visitor<'tcx> for PubRestrictedVisitor<'tcx> { type Map = Map<'tcx>; fn nested_visit_map(&mut self) -> NestedVisitorMap { @@ -432,7 +431,7 @@ struct ReachEverythingInTheInterfaceVisitor<'a, 'tcx> { ev: &'a mut EmbargoVisitor<'tcx>, } -impl EmbargoVisitor<'tcx> { +impl<'tcx> EmbargoVisitor<'tcx> { fn get(&self, def_id: LocalDefId) -> Option { self.access_levels.map.get(&def_id).copied() } @@ -674,7 +673,7 @@ impl EmbargoVisitor<'tcx> { } } -impl Visitor<'tcx> for EmbargoVisitor<'tcx> { +impl<'tcx> Visitor<'tcx> for EmbargoVisitor<'tcx> { type Map = Map<'tcx>; /// We want to visit items in the context of their containing @@ -944,7 +943,7 @@ impl Visitor<'tcx> for EmbargoVisitor<'tcx> { } } -impl ReachEverythingInTheInterfaceVisitor<'_, 'tcx> { +impl ReachEverythingInTheInterfaceVisitor<'_, '_> { fn generics(&mut self) -> &mut Self { for param in &self.ev.tcx.generics_of(self.item_def_id).params { match param.kind { @@ -983,7 +982,7 @@ impl ReachEverythingInTheInterfaceVisitor<'_, 'tcx> { } } -impl DefIdVisitor<'tcx> for ReachEverythingInTheInterfaceVisitor<'_, 'tcx> { +impl<'tcx> DefIdVisitor<'tcx> for ReachEverythingInTheInterfaceVisitor<'_, 'tcx> { fn tcx(&self) -> TyCtxt<'tcx> { self.ev.tcx } @@ -1413,7 +1412,7 @@ impl<'tcx> Visitor<'tcx> for TypePrivacyVisitor<'tcx> { } } -impl DefIdVisitor<'tcx> for TypePrivacyVisitor<'tcx> { +impl<'tcx> DefIdVisitor<'tcx> for TypePrivacyVisitor<'tcx> { fn tcx(&self) -> TyCtxt<'tcx> { self.tcx } @@ -1800,7 +1799,7 @@ struct SearchInterfaceForPrivateItemsVisitor<'tcx> { in_assoc_ty: bool, } -impl SearchInterfaceForPrivateItemsVisitor<'tcx> { +impl SearchInterfaceForPrivateItemsVisitor<'_> { fn generics(&mut self) -> &mut Self { for param in &self.tcx.generics_of(self.item_def_id).params { match param.kind { @@ -1921,7 +1920,7 @@ impl SearchInterfaceForPrivateItemsVisitor<'tcx> { } } -impl DefIdVisitor<'tcx> for SearchInterfaceForPrivateItemsVisitor<'tcx> { +impl<'tcx> DefIdVisitor<'tcx> for SearchInterfaceForPrivateItemsVisitor<'tcx> { fn tcx(&self) -> TyCtxt<'tcx> { self.tcx } From ba824ec52beb0e49b64e86837c1402a0c2d0c971 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 15 Dec 2021 20:52:37 +0100 Subject: [PATCH 3/8] Clean up search code and unify function returned values --- src/librustdoc/html/static/js/search.js | 204 +++++++++++------------- 1 file changed, 96 insertions(+), 108 deletions(-) diff --git a/src/librustdoc/html/static/js/search.js b/src/librustdoc/html/static/js/search.js index 7c55d10836c45..061a9ec774df2 100644 --- a/src/librustdoc/html/static/js/search.js +++ b/src/librustdoc/html/static/js/search.js @@ -176,16 +176,13 @@ window.initSearch = function(rawSearchIndex) { var ar = []; for (var entry in results) { if (hasOwnPropertyRustdoc(results, entry)) { - ar.push(results[entry]); + var result = results[entry]; + result.word = searchWords[result.id]; + result.item = searchIndex[result.id] || {}; + ar.push(result); } } results = ar; - var i, len, result; - for (i = 0, len = results.length; i < len; ++i) { - result = results[i]; - result.word = searchWords[result.id]; - result.item = searchIndex[result.id] || {}; - } // if there are no results then return to default and fail if (results.length === 0) { return []; @@ -258,7 +255,7 @@ window.initSearch = function(rawSearchIndex) { return 0; }); - for (i = 0, len = results.length; i < len; ++i) { + for (var i = 0, len = results.length; i < len; ++i) { result = results[i]; // this validation does not make sense when searching by types @@ -344,7 +341,17 @@ window.initSearch = function(rawSearchIndex) { return MAX_LEV_DISTANCE + 1; } - // Check for type name and type generics (if any). + /** + * This function checks if the object (`obj`) matches the given type (`val`) and its + * generics (if any). + * + * @param {Object} obj + * @param {string} val + * @param {boolean} literalSearch + * + * @return {integer} - Returns a Levenshtein distance to the best match. If there is + * no match, returns `MAX_LEV_DISTANCE + 1`. + */ function checkType(obj, val, literalSearch) { var lev_distance = MAX_LEV_DISTANCE + 1; var tmp_lev = MAX_LEV_DISTANCE + 1; @@ -363,24 +370,23 @@ window.initSearch = function(rawSearchIndex) { elems[obj[GENERICS_DATA][x][NAME]] += 1; } - var allFound = true; len = val.generics.length; for (x = 0; x < len; ++x) { firstGeneric = val.generics[x]; if (elems[firstGeneric]) { elems[firstGeneric] -= 1; } else { - allFound = false; - break; + // Something wasn't found and this is a literal search so + // abort and return a "failing" distance. + return MAX_LEV_DISTANCE + 1; } } - if (allFound) { - return true; - } + // Everything was found, success! + return 0; } - return false; + return MAX_LEV_DISTANCE + 1; } - return true; + return 0; } else { // If the type has generics but don't match, then it won't return at this point. // Otherwise, `checkGenerics` will return 0 and it'll return. @@ -392,14 +398,15 @@ window.initSearch = function(rawSearchIndex) { } } } else if (literalSearch) { + var found = false; if ((!val.generics || val.generics.length === 0) && obj.length > GENERICS_DATA && obj[GENERICS_DATA].length > 0) { - return obj[GENERICS_DATA].some( + found = obj[GENERICS_DATA].some( function(gen) { return gen[NAME] === val.name; }); } - return false; + return found ? 0 : MAX_LEV_DISTANCE + 1; } lev_distance = Math.min(levenshtein(obj[NAME], val.name), lev_distance); if (lev_distance <= MAX_LEV_DISTANCE) { @@ -430,6 +437,17 @@ window.initSearch = function(rawSearchIndex) { return Math.min(lev_distance, tmp_lev) + 1; } + /** + * This function checks if the object (`obj`) has an argument with the given type (`val`). + * + * @param {Object} obj + * @param {string} val + * @param {boolean} literalSearch + * @param {integer} typeFilter + * + * @return {integer} - Returns a Levenshtein distance to the best match. If there is no + * match, returns `MAX_LEV_DISTANCE + 1`. + */ function findArg(obj, val, literalSearch, typeFilter) { var lev_distance = MAX_LEV_DISTANCE + 1; @@ -441,19 +459,15 @@ window.initSearch = function(rawSearchIndex) { continue; } tmp = checkType(tmp, val, literalSearch); - if (literalSearch) { - if (tmp) { - return true; - } + if (tmp === 0) { + return 0; + } else if (literalSearch) { continue; } lev_distance = Math.min(tmp, lev_distance); - if (lev_distance === 0) { - return 0; - } } } - return literalSearch ? false : lev_distance; + return literalSearch ? MAX_LEV_DISTANCE + 1 : lev_distance; } function checkReturned(obj, val, literalSearch, typeFilter) { @@ -470,19 +484,15 @@ window.initSearch = function(rawSearchIndex) { continue; } tmp = checkType(tmp, val, literalSearch); - if (literalSearch) { - if (tmp) { - return true; - } + if (tmp === 0) { + return 0; + } else if (literalSearch) { continue; } lev_distance = Math.min(tmp, lev_distance); - if (lev_distance === 0) { - return 0; - } } } - return literalSearch ? false : lev_distance; + return literalSearch ? MAX_LEV_DISTANCE + 1 : lev_distance; } function checkPath(contains, lastElem, ty) { @@ -612,6 +622,44 @@ window.initSearch = function(rawSearchIndex) { onEach(crateAliases, pushFunc); } + /** + * This function adds the given result into the provided `res` map if it matches the + * following condition: + * + * * If it is a "literal search" (`isExact`), then `lev` must be 0. + * * If it is not a "literal search", `lev` must be <= `MAX_LEV_DISTANCE`. + * + * The `res` map contains information which will be used to sort the search results: + * + * * `fullId` is a `string`` used as the key of the object we use for the `res` map. + * * `id` is the index in both `searchWords` and `searchIndex` arrays for this element. + * * `index` is an `integer`` used to sort by the position of the word in the item's name. + * * `lev` is the main metric used to sort the search results. + * + * @param {boolean} isExact + * @param {Object} res + * @param {string} fullId + * @param {integer} id + * @param {integer} index + * @param {integer} lev + */ + function addIntoResults(isExact, res, fullId, id, index, lev) { + if (lev === 0 || (!isExact && lev <= MAX_LEV_DISTANCE)) { + if (res[fullId] !== undefined) { + var result = res[fullId]; + if (result.dontValidate || result.lev <= lev) { + return; + } + } + res[fullId] = { + id: id, + index: index, + dontValidate: isExact, + lev: lev, + }; + } + } + // quoted values mean literal search var nSearchWords = searchWords.length; var i, it; @@ -634,28 +682,11 @@ window.initSearch = function(rawSearchIndex) { fullId = ty.id; if (searchWords[i] === val.name - && typePassesFilter(typeFilter, searchIndex[i].ty) - && results[fullId] === undefined) { - results[fullId] = { - id: i, - index: -1, - dontValidate: true, - }; - } - if (in_args && results_in_args[fullId] === undefined) { - results_in_args[fullId] = { - id: i, - index: -1, - dontValidate: true, - }; - } - if (returned && results_returned[fullId] === undefined) { - results_returned[fullId] = { - id: i, - index: -1, - dontValidate: true, - }; + && typePassesFilter(typeFilter, searchIndex[i].ty)) { + addIntoResults(true, results, fullId, i, -1, 0); } + addIntoResults(true, results_in_args, fullId, i, -1, in_args); + addIntoResults(true, results_returned, fullId, i, -1, returned); } query.inputs = [val]; query.output = val; @@ -684,39 +715,23 @@ window.initSearch = function(rawSearchIndex) { fullId = ty.id; returned = checkReturned(ty, output, true, NO_TYPE_FILTER); - if (output.name === "*" || returned) { + if (output.name === "*" || returned === 0) { in_args = false; var is_module = false; if (input === "*") { is_module = true; } else { - var allFound = true; - for (it = 0, len = inputs.length; allFound && it < len; it++) { + var allFound = 0; + for (it = 0, len = inputs.length; allFound === 0 && it < len; it++) { allFound = checkType(type, inputs[it], true); } in_args = allFound; } - if (in_args) { - results_in_args[fullId] = { - id: i, - index: -1, - dontValidate: true, - }; - } - if (returned) { - results_returned[fullId] = { - id: i, - index: -1, - dontValidate: true, - }; - } + addIntoResults(true, results_in_args, fullId, i, -1, in_args); + addIntoResults(true, results_returned, fullId, i, -1, returned); if (is_module) { - results[fullId] = { - id: i, - index: -1, - dontValidate: true, - }; + addIntoResults(true, results, fullId, i, -1, 0); } } } @@ -788,41 +803,14 @@ window.initSearch = function(rawSearchIndex) { lev = 0; } } - if (in_args <= MAX_LEV_DISTANCE) { - if (results_in_args[fullId] === undefined) { - results_in_args[fullId] = { - id: j, - index: index, - lev: in_args, - }; - } - results_in_args[fullId].lev = - Math.min(results_in_args[fullId].lev, in_args); - } - if (returned <= MAX_LEV_DISTANCE) { - if (results_returned[fullId] === undefined) { - results_returned[fullId] = { - id: j, - index: index, - lev: returned, - }; - } - results_returned[fullId].lev = - Math.min(results_returned[fullId].lev, returned); - } + addIntoResults(false, results_in_args, fullId, j, index, in_args); + addIntoResults(false, results_returned, fullId, j, index, returned); if (typePassesFilter(typeFilter, ty.ty) && (index !== -1 || lev <= MAX_LEV_DISTANCE)) { if (index !== -1 && paths.length < 2) { lev = 0; } - if (results[fullId] === undefined) { - results[fullId] = { - id: j, - index: index, - lev: lev, - }; - } - results[fullId].lev = Math.min(results[fullId].lev, lev); + addIntoResults(false, results, fullId, j, index, lev); } } } From 080b9261351e109444b4955c9980b2cce7a9bb5c Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 16 Dec 2021 23:17:03 +0100 Subject: [PATCH 4/8] Make loop more clear by renaming variables --- src/librustdoc/html/static/js/search.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/librustdoc/html/static/js/search.js b/src/librustdoc/html/static/js/search.js index 061a9ec774df2..d419e384a594a 100644 --- a/src/librustdoc/html/static/js/search.js +++ b/src/librustdoc/html/static/js/search.js @@ -722,11 +722,15 @@ window.initSearch = function(rawSearchIndex) { if (input === "*") { is_module = true; } else { - var allFound = 0; - for (it = 0, len = inputs.length; allFound === 0 && it < len; it++) { - allFound = checkType(type, inputs[it], true); + var firstNonZeroDistance = 0; + for (it = 0, len = inputs.length; it < len; it++) { + var distance = checkType(type, inputs[it], true); + if (distance > 0) { + firstNonZeroDistance = distance; + break; + } } - in_args = allFound; + in_args = firstNonZeroDistance; } addIntoResults(true, results_in_args, fullId, i, -1, in_args); addIntoResults(true, results_returned, fullId, i, -1, returned); From 0b8bbac3ff38b6f68b4584199f7824ca29264998 Mon Sep 17 00:00:00 2001 From: Esteban Kuber Date: Fri, 17 Dec 2021 02:10:12 +0000 Subject: [PATCH 5/8] Fix typo in "new region bound" suggestion The lifetime name shoud always appear in text surrounded by `. --- compiler/rustc_infer/src/infer/error_reporting/mod.rs | 2 +- .../multiple-lifetimes/ret-impl-trait-one.nll.stderr | 2 +- .../multiple-lifetimes/ret-impl-trait-one.stderr | 2 +- src/test/ui/impl-trait/hidden-lifetimes.stderr | 4 ++-- .../multiple-lifetimes/ordinary-bounds-unrelated.stderr | 2 +- .../multiple-lifetimes/ordinary-bounds-unsuited.stderr | 2 +- .../must_outlive_least_region_or_bound.nll.stderr | 6 +++--- .../impl-trait/must_outlive_least_region_or_bound.stderr | 6 +++--- src/test/ui/impl-trait/region-escape-via-bound.stderr | 2 +- .../ui/impl-trait/static-return-lifetime-infered.stderr | 8 ++++---- src/test/ui/nll/ty-outlives/impl-trait-captures.stderr | 2 +- ...itrary_self_types_pin_lifetime_impl_trait-async.stderr | 2 +- .../arbitrary_self_types_pin_lifetime_impl_trait.stderr | 2 +- 13 files changed, 21 insertions(+), 21 deletions(-) diff --git a/compiler/rustc_infer/src/infer/error_reporting/mod.rs b/compiler/rustc_infer/src/infer/error_reporting/mod.rs index 1e3f9f7464deb..bf867db9ce6ef 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/mod.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/mod.rs @@ -275,7 +275,7 @@ pub fn unexpected_hidden_region_diagnostic( fn_returns, hidden_region.to_string(), None, - format!("captures {}", hidden_region), + format!("captures `{}`", hidden_region), None, ) } diff --git a/src/test/ui/async-await/multiple-lifetimes/ret-impl-trait-one.nll.stderr b/src/test/ui/async-await/multiple-lifetimes/ret-impl-trait-one.nll.stderr index 9b0018d8904ac..2722c72c20a33 100644 --- a/src/test/ui/async-await/multiple-lifetimes/ret-impl-trait-one.nll.stderr +++ b/src/test/ui/async-await/multiple-lifetimes/ret-impl-trait-one.nll.stderr @@ -21,7 +21,7 @@ LL | async fn async_ret_impl_trait1<'a, 'b>(a: &'a u8, b: &'b u8) -> impl Trait< | | | hidden type `(&'a u8, &'b u8)` captures the lifetime `'b` as defined here | -help: to declare that the `impl Trait` captures 'b, you can add an explicit `'b` lifetime bound +help: to declare that the `impl Trait` captures `'b`, you can add an explicit `'b` lifetime bound | LL | async fn async_ret_impl_trait1<'a, 'b>(a: &'a u8, b: &'b u8) -> impl Trait<'a> + 'b { | ++++ diff --git a/src/test/ui/async-await/multiple-lifetimes/ret-impl-trait-one.stderr b/src/test/ui/async-await/multiple-lifetimes/ret-impl-trait-one.stderr index bcd96367e2fae..464f283095dad 100644 --- a/src/test/ui/async-await/multiple-lifetimes/ret-impl-trait-one.stderr +++ b/src/test/ui/async-await/multiple-lifetimes/ret-impl-trait-one.stderr @@ -16,7 +16,7 @@ LL | async fn async_ret_impl_trait1<'a, 'b>(a: &'a u8, b: &'b u8) -> impl Trait< | | | hidden type `(&'a u8, &'b u8)` captures the lifetime `'b` as defined here | -help: to declare that the `impl Trait` captures 'b, you can add an explicit `'b` lifetime bound +help: to declare that the `impl Trait` captures `'b`, you can add an explicit `'b` lifetime bound | LL | async fn async_ret_impl_trait1<'a, 'b>(a: &'a u8, b: &'b u8) -> impl Trait<'a> + 'b { | ++++ diff --git a/src/test/ui/impl-trait/hidden-lifetimes.stderr b/src/test/ui/impl-trait/hidden-lifetimes.stderr index 60d3409a8accf..c6d11293eec53 100644 --- a/src/test/ui/impl-trait/hidden-lifetimes.stderr +++ b/src/test/ui/impl-trait/hidden-lifetimes.stderr @@ -6,7 +6,7 @@ LL | fn hide_ref<'a, 'b, T: 'static>(x: &'a mut &'b T) -> impl Swap + 'a { | | | hidden type `&'a mut &'b T` captures the lifetime `'b` as defined here | -help: to declare that the `impl Trait` captures 'b, you can add an explicit `'b` lifetime bound +help: to declare that the `impl Trait` captures `'b`, you can add an explicit `'b` lifetime bound | LL | fn hide_ref<'a, 'b, T: 'static>(x: &'a mut &'b T) -> impl Swap + 'a + 'b { | ++++ @@ -19,7 +19,7 @@ LL | fn hide_rc_refcell<'a, 'b: 'a, T: 'static>(x: Rc>) -> impl S | | | hidden type `Rc>` captures the lifetime `'b` as defined here | -help: to declare that the `impl Trait` captures 'b, you can add an explicit `'b` lifetime bound +help: to declare that the `impl Trait` captures `'b`, you can add an explicit `'b` lifetime bound | LL | fn hide_rc_refcell<'a, 'b: 'a, T: 'static>(x: Rc>) -> impl Swap + 'a + 'b { | ++++ diff --git a/src/test/ui/impl-trait/multiple-lifetimes/ordinary-bounds-unrelated.stderr b/src/test/ui/impl-trait/multiple-lifetimes/ordinary-bounds-unrelated.stderr index bfe656c7e2b49..32829a0a1b2fa 100644 --- a/src/test/ui/impl-trait/multiple-lifetimes/ordinary-bounds-unrelated.stderr +++ b/src/test/ui/impl-trait/multiple-lifetimes/ordinary-bounds-unrelated.stderr @@ -6,7 +6,7 @@ LL | fn upper_bounds<'a, 'b, 'c, 'd, 'e>(a: Ordinary<'a>, b: Ordinary<'b>) -> im | | | hidden type `Ordinary<'b>` captures the lifetime `'b` as defined here | -help: to declare that the `impl Trait` captures 'b, you can add an explicit `'b` lifetime bound +help: to declare that the `impl Trait` captures `'b`, you can add an explicit `'b` lifetime bound | LL | fn upper_bounds<'a, 'b, 'c, 'd, 'e>(a: Ordinary<'a>, b: Ordinary<'b>) -> impl Trait<'d, 'e> + 'b | ++++ diff --git a/src/test/ui/impl-trait/multiple-lifetimes/ordinary-bounds-unsuited.stderr b/src/test/ui/impl-trait/multiple-lifetimes/ordinary-bounds-unsuited.stderr index 75c2dd8e9d39e..83ad23b253bb3 100644 --- a/src/test/ui/impl-trait/multiple-lifetimes/ordinary-bounds-unsuited.stderr +++ b/src/test/ui/impl-trait/multiple-lifetimes/ordinary-bounds-unsuited.stderr @@ -6,7 +6,7 @@ LL | fn upper_bounds<'a, 'b>(a: Ordinary<'a>, b: Ordinary<'b>) -> impl Trait<'a, | | | hidden type `Ordinary<'b>` captures the lifetime `'b` as defined here | -help: to declare that the `impl Trait` captures 'b, you can add an explicit `'b` lifetime bound +help: to declare that the `impl Trait` captures `'b`, you can add an explicit `'b` lifetime bound | LL | fn upper_bounds<'a, 'b>(a: Ordinary<'a>, b: Ordinary<'b>) -> impl Trait<'a, 'b> + 'b | ++++ diff --git a/src/test/ui/impl-trait/must_outlive_least_region_or_bound.nll.stderr b/src/test/ui/impl-trait/must_outlive_least_region_or_bound.nll.stderr index eaf341248a180..2f6bd8ff377a5 100644 --- a/src/test/ui/impl-trait/must_outlive_least_region_or_bound.nll.stderr +++ b/src/test/ui/impl-trait/must_outlive_least_region_or_bound.nll.stderr @@ -6,7 +6,7 @@ LL | fn elided(x: &i32) -> impl Copy { x } | | | hidden type `&i32` captures the anonymous lifetime defined here | -help: to declare that the `impl Trait` captures '_, you can add an explicit `'_` lifetime bound +help: to declare that the `impl Trait` captures `'_`, you can add an explicit `'_` lifetime bound | LL | fn elided(x: &i32) -> impl Copy + '_ { x } | ++++ @@ -19,7 +19,7 @@ LL | fn explicit<'a>(x: &'a i32) -> impl Copy { x } | | | hidden type `&'a i32` captures the lifetime `'a` as defined here | -help: to declare that the `impl Trait` captures 'a, you can add an explicit `'a` lifetime bound +help: to declare that the `impl Trait` captures `'a`, you can add an explicit `'a` lifetime bound | LL | fn explicit<'a>(x: &'a i32) -> impl Copy + 'a { x } | ++++ @@ -74,7 +74,7 @@ LL | fn move_lifetime_into_fn<'a, 'b>(x: &'a u32, y: &'b u32) -> impl Fn(&'a u32 | | | hidden type `[closure@$DIR/must_outlive_least_region_or_bound.rs:35:5: 35:31]` captures the lifetime `'b` as defined here | -help: to declare that the `impl Trait` captures 'b, you can add an explicit `'b` lifetime bound +help: to declare that the `impl Trait` captures `'b`, you can add an explicit `'b` lifetime bound | LL | fn move_lifetime_into_fn<'a, 'b>(x: &'a u32, y: &'b u32) -> impl Fn(&'a u32) + 'b { | ++++ diff --git a/src/test/ui/impl-trait/must_outlive_least_region_or_bound.stderr b/src/test/ui/impl-trait/must_outlive_least_region_or_bound.stderr index de5d3b612c9c2..07ac0a8db35a9 100644 --- a/src/test/ui/impl-trait/must_outlive_least_region_or_bound.stderr +++ b/src/test/ui/impl-trait/must_outlive_least_region_or_bound.stderr @@ -6,7 +6,7 @@ LL | fn elided(x: &i32) -> impl Copy { x } | | | hidden type `&i32` captures the anonymous lifetime defined here | -help: to declare that the `impl Trait` captures '_, you can add an explicit `'_` lifetime bound +help: to declare that the `impl Trait` captures `'_`, you can add an explicit `'_` lifetime bound | LL | fn elided(x: &i32) -> impl Copy + '_ { x } | ++++ @@ -19,7 +19,7 @@ LL | fn explicit<'a>(x: &'a i32) -> impl Copy { x } | | | hidden type `&'a i32` captures the lifetime `'a` as defined here | -help: to declare that the `impl Trait` captures 'a, you can add an explicit `'a` lifetime bound +help: to declare that the `impl Trait` captures `'a`, you can add an explicit `'a` lifetime bound | LL | fn explicit<'a>(x: &'a i32) -> impl Copy + 'a { x } | ++++ @@ -119,7 +119,7 @@ LL | fn move_lifetime_into_fn<'a, 'b>(x: &'a u32, y: &'b u32) -> impl Fn(&'a u32 | | | hidden type `[closure@$DIR/must_outlive_least_region_or_bound.rs:35:5: 35:31]` captures the lifetime `'b` as defined here | -help: to declare that the `impl Trait` captures 'b, you can add an explicit `'b` lifetime bound +help: to declare that the `impl Trait` captures `'b`, you can add an explicit `'b` lifetime bound | LL | fn move_lifetime_into_fn<'a, 'b>(x: &'a u32, y: &'b u32) -> impl Fn(&'a u32) + 'b { | ++++ diff --git a/src/test/ui/impl-trait/region-escape-via-bound.stderr b/src/test/ui/impl-trait/region-escape-via-bound.stderr index 9dc2ea5bc82a1..cf854f67d0456 100644 --- a/src/test/ui/impl-trait/region-escape-via-bound.stderr +++ b/src/test/ui/impl-trait/region-escape-via-bound.stderr @@ -7,7 +7,7 @@ LL | LL | where 'x: 'y | -- hidden type `Cell<&'x u32>` captures the lifetime `'x` as defined here | -help: to declare that the `impl Trait` captures 'x, you can add an explicit `'x` lifetime bound +help: to declare that the `impl Trait` captures `'x`, you can add an explicit `'x` lifetime bound | LL | fn foo(x: Cell<&'x u32>) -> impl Trait<'y> + 'x | ++++ diff --git a/src/test/ui/impl-trait/static-return-lifetime-infered.stderr b/src/test/ui/impl-trait/static-return-lifetime-infered.stderr index 0d68f8c825f70..7424da76182ab 100644 --- a/src/test/ui/impl-trait/static-return-lifetime-infered.stderr +++ b/src/test/ui/impl-trait/static-return-lifetime-infered.stderr @@ -6,7 +6,7 @@ LL | fn iter_values_anon(&self) -> impl Iterator { | | | hidden type `Map, [closure@$DIR/static-return-lifetime-infered.rs:9:27: 9:34]>` captures the anonymous lifetime defined here | -help: to declare that the `impl Trait` captures '_, you can add an explicit `'_` lifetime bound +help: to declare that the `impl Trait` captures `'_`, you can add an explicit `'_` lifetime bound | LL | fn iter_values_anon(&self) -> impl Iterator + '_ { | ++++ @@ -19,7 +19,7 @@ LL | fn iter_values_anon(&self) -> impl Iterator { | | | hidden type `Map, [closure@$DIR/static-return-lifetime-infered.rs:9:27: 9:34]>` captures the anonymous lifetime defined here | -help: to declare that the `impl Trait` captures '_, you can add an explicit `'_` lifetime bound +help: to declare that the `impl Trait` captures `'_`, you can add an explicit `'_` lifetime bound | LL | fn iter_values_anon(&self) -> impl Iterator + '_ { | ++++ @@ -32,7 +32,7 @@ LL | fn iter_values<'a>(&'a self) -> impl Iterator { | | | hidden type `Map, [closure@$DIR/static-return-lifetime-infered.rs:14:27: 14:34]>` captures the lifetime `'a` as defined here | -help: to declare that the `impl Trait` captures 'a, you can add an explicit `'a` lifetime bound +help: to declare that the `impl Trait` captures `'a`, you can add an explicit `'a` lifetime bound | LL | fn iter_values<'a>(&'a self) -> impl Iterator + 'a { | ++++ @@ -45,7 +45,7 @@ LL | fn iter_values<'a>(&'a self) -> impl Iterator { | | | hidden type `Map, [closure@$DIR/static-return-lifetime-infered.rs:14:27: 14:34]>` captures the lifetime `'a` as defined here | -help: to declare that the `impl Trait` captures 'a, you can add an explicit `'a` lifetime bound +help: to declare that the `impl Trait` captures `'a`, you can add an explicit `'a` lifetime bound | LL | fn iter_values<'a>(&'a self) -> impl Iterator + 'a { | ++++ diff --git a/src/test/ui/nll/ty-outlives/impl-trait-captures.stderr b/src/test/ui/nll/ty-outlives/impl-trait-captures.stderr index bc02eb82dd948..5e56e12eda021 100644 --- a/src/test/ui/nll/ty-outlives/impl-trait-captures.stderr +++ b/src/test/ui/nll/ty-outlives/impl-trait-captures.stderr @@ -6,7 +6,7 @@ LL | fn foo<'a, T>(x: &T) -> impl Foo<'a> { | | | hidden type `&ReFree(DefId(0:8 ~ impl_trait_captures[HASH]::foo), BrAnon(0)) T` captures the anonymous lifetime defined here | -help: to declare that the `impl Trait` captures ReFree(DefId(0:8 ~ impl_trait_captures[HASH]::foo), BrAnon(0)), you can add an explicit `ReFree(DefId(0:8 ~ impl_trait_captures[HASH]::foo), BrAnon(0))` lifetime bound +help: to declare that the `impl Trait` captures `ReFree(DefId(0:8 ~ impl_trait_captures[HASH]::foo), BrAnon(0))`, you can add an explicit `ReFree(DefId(0:8 ~ impl_trait_captures[HASH]::foo), BrAnon(0))` lifetime bound | LL | fn foo<'a, T>(x: &T) -> impl Foo<'a> + ReFree(DefId(0:8 ~ impl_trait_captures[HASH]::foo), BrAnon(0)) { | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ diff --git a/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait-async.stderr b/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait-async.stderr index 953d7cd6a0769..61ac7731777b4 100644 --- a/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait-async.stderr +++ b/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait-async.stderr @@ -6,7 +6,7 @@ LL | async fn f(self: Pin<&Self>) -> impl Clone { self } | | | hidden type `Pin<&Foo>` captures the lifetime `'_` as defined here | -help: to declare that the `impl Trait` captures '_, you can add an explicit `'_` lifetime bound +help: to declare that the `impl Trait` captures `'_`, you can add an explicit `'_` lifetime bound | LL | async fn f(self: Pin<&Self>) -> impl Clone + '_ { self } | ++++ diff --git a/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait.stderr b/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait.stderr index faa1233ffde63..6f8200739b9de 100644 --- a/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait.stderr +++ b/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait.stderr @@ -6,7 +6,7 @@ LL | fn f(self: Pin<&Self>) -> impl Clone { self } | | | hidden type `Pin<&Foo>` captures the anonymous lifetime defined here | -help: to declare that the `impl Trait` captures '_, you can add an explicit `'_` lifetime bound +help: to declare that the `impl Trait` captures `'_`, you can add an explicit `'_` lifetime bound | LL | fn f(self: Pin<&Self>) -> impl Clone + '_ { self } | ++++ From a995462f9a33195caf447f257eb221e2b664bc1b Mon Sep 17 00:00:00 2001 From: lzh Date: Fri, 17 Dec 2021 11:17:43 +0800 Subject: [PATCH 6/8] Eliminate duplicate codes of expected_found_bool --- compiler/rustc_infer/src/infer/combine.rs | 8 ++++---- compiler/rustc_middle/src/ty/relate.rs | 10 +--------- compiler/rustc_typeck/src/check/expr.rs | 4 ++-- 3 files changed, 7 insertions(+), 15 deletions(-) diff --git a/compiler/rustc_infer/src/infer/combine.rs b/compiler/rustc_infer/src/infer/combine.rs index 09bfb3290f4ca..03596f7dfad6d 100644 --- a/compiler/rustc_infer/src/infer/combine.rs +++ b/compiler/rustc_infer/src/infer/combine.rs @@ -37,7 +37,7 @@ use crate::traits::{Obligation, PredicateObligations}; use rustc_data_structures::sso::SsoHashMap; use rustc_hir::def_id::DefId; use rustc_middle::traits::ObligationCause; -use rustc_middle::ty::error::TypeError; +use rustc_middle::ty::error::{ExpectedFound, TypeError}; use rustc_middle::ty::relate::{self, Relate, RelateResult, TypeRelation}; use rustc_middle::ty::subst::SubstsRef; use rustc_middle::ty::{self, InferConst, ToPredicate, Ty, TyCtxt, TypeFoldable}; @@ -790,7 +790,7 @@ pub fn const_unification_error<'tcx>( a_is_expected: bool, (a, b): (&'tcx ty::Const<'tcx>, &'tcx ty::Const<'tcx>), ) -> TypeError<'tcx> { - TypeError::ConstMismatch(ty::relate::expected_found_bool(a_is_expected, a, b)) + TypeError::ConstMismatch(ExpectedFound::new(a_is_expected, a, b)) } fn int_unification_error<'tcx>( @@ -798,7 +798,7 @@ fn int_unification_error<'tcx>( v: (ty::IntVarValue, ty::IntVarValue), ) -> TypeError<'tcx> { let (a, b) = v; - TypeError::IntMismatch(ty::relate::expected_found_bool(a_is_expected, a, b)) + TypeError::IntMismatch(ExpectedFound::new(a_is_expected, a, b)) } fn float_unification_error<'tcx>( @@ -806,7 +806,7 @@ fn float_unification_error<'tcx>( v: (ty::FloatVarValue, ty::FloatVarValue), ) -> TypeError<'tcx> { let (ty::FloatVarValue(a), ty::FloatVarValue(b)) = v; - TypeError::FloatMismatch(ty::relate::expected_found_bool(a_is_expected, a, b)) + TypeError::FloatMismatch(ExpectedFound::new(a_is_expected, a, b)) } struct ConstInferUnifier<'cx, 'tcx> { diff --git a/compiler/rustc_middle/src/ty/relate.rs b/compiler/rustc_middle/src/ty/relate.rs index c7d8bec506f6b..42495f974d0d8 100644 --- a/compiler/rustc_middle/src/ty/relate.rs +++ b/compiler/rustc_middle/src/ty/relate.rs @@ -849,13 +849,5 @@ pub fn expected_found(relation: &mut R, a: T, b: T) -> ExpectedFound where R: TypeRelation<'tcx>, { - expected_found_bool(relation.a_is_expected(), a, b) -} - -pub fn expected_found_bool(a_is_expected: bool, a: T, b: T) -> ExpectedFound { - if a_is_expected { - ExpectedFound { expected: a, found: b } - } else { - ExpectedFound { expected: b, found: a } - } + ExpectedFound::new(relation.a_is_expected(), a, b) } diff --git a/compiler/rustc_typeck/src/check/expr.rs b/compiler/rustc_typeck/src/check/expr.rs index 311106474bea0..60e7dc61a1b9c 100644 --- a/compiler/rustc_typeck/src/check/expr.rs +++ b/compiler/rustc_typeck/src/check/expr.rs @@ -36,8 +36,8 @@ use rustc_infer::infer; use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; use rustc_infer::infer::InferOk; use rustc_middle::ty::adjustment::{Adjust, Adjustment, AllowTwoPhase}; +use rustc_middle::ty::error::ExpectedFound; use rustc_middle::ty::error::TypeError::{FieldMisMatch, Sorts}; -use rustc_middle::ty::relate::expected_found_bool; use rustc_middle::ty::subst::SubstsRef; use rustc_middle::ty::{self, AdtKind, Ty, TypeFoldable}; use rustc_session::parse::feature_err; @@ -1494,7 +1494,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { &self.misc(base_expr.span), adt_ty, base_ty, - Sorts(expected_found_bool(true, adt_ty, base_ty)), + Sorts(ExpectedFound::new(true, adt_ty, base_ty)), ) .emit(); } From c3da28eade867f731d8169a8c143e33353006e29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Marie?= Date: Fri, 17 Dec 2021 11:27:14 +0000 Subject: [PATCH 7/8] pass -Wl,-z,origin to set DF_ORIGIN when using rpath DF_ORIGIN flag signifies that the object being loaded may make reference to the $ORIGIN substitution string. Some implementations are just ignoring DF_ORIGIN and do substitution for $ORIGIN if present (whatever DF_ORIGIN pr Set the flag inconditionally if rpath is wanted. --- compiler/rustc_codegen_ssa/src/back/rpath.rs | 5 ++++- src/bootstrap/builder.rs | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_codegen_ssa/src/back/rpath.rs b/compiler/rustc_codegen_ssa/src/back/rpath.rs index 61c3ef62fb193..0b5656c9ad127 100644 --- a/compiler/rustc_codegen_ssa/src/back/rpath.rs +++ b/compiler/rustc_codegen_ssa/src/back/rpath.rs @@ -23,9 +23,12 @@ pub fn get_rpath_flags(config: &mut RPathConfig<'_>) -> Vec { let rpaths = get_rpaths(config); let mut flags = rpaths_to_flags(&rpaths); - // Use DT_RUNPATH instead of DT_RPATH if available if config.linker_is_gnu { + // Use DT_RUNPATH instead of DT_RPATH if available flags.push("-Wl,--enable-new-dtags".to_owned()); + + // Set DF_ORIGIN for substitute $ORIGIN + flags.push("-Wl,-z,origin".to_owned()); } flags diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs index 952a65a428688..bbd2c087ccabb 100644 --- a/src/bootstrap/builder.rs +++ b/src/bootstrap/builder.rs @@ -1176,6 +1176,7 @@ impl<'a> Builder<'a> { rustflags.arg("-Zosx-rpath-install-name"); Some("-Wl,-rpath,@loader_path/../lib") } else if !target.contains("windows") { + rustflags.arg("-Clink-args=-Wl,-z,origin"); Some("-Wl,-rpath,$ORIGIN/../lib") } else { None From 0d61852cc5e3c9c441e861acd31a1fc72f584c5b Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Fri, 17 Dec 2021 16:45:15 +0800 Subject: [PATCH 8/8] hir: Do not introduce dummy type names for `extern` blocks in def paths Use a separate nameless `DefPathData` variant instead --- compiler/rustc_hir/src/definitions.rs | 7 ++++- compiler/rustc_lint/src/context.rs | 4 +-- compiler/rustc_middle/src/ty/print/pretty.rs | 28 +++++++++----------- compiler/rustc_resolve/src/def_collector.rs | 2 +- compiler/rustc_symbol_mangling/src/legacy.rs | 4 +-- compiler/rustc_symbol_mangling/src/v0.rs | 4 +++ src/librustdoc/clean/inline.rs | 6 ++--- src/librustdoc/visit_ast.rs | 6 ++--- 8 files changed, 33 insertions(+), 28 deletions(-) diff --git a/compiler/rustc_hir/src/definitions.rs b/compiler/rustc_hir/src/definitions.rs index ca29351455e62..40071c6df8cca 100644 --- a/compiler/rustc_hir/src/definitions.rs +++ b/compiler/rustc_hir/src/definitions.rs @@ -267,6 +267,8 @@ pub enum DefPathData { // Different kinds of items and item-like things: /// An impl. Impl, + /// An `extern` block. + ForeignMod, /// Something in the type namespace. TypeNs(Symbol), /// Something in the value namespace. @@ -469,7 +471,9 @@ impl DefPathData { match *self { TypeNs(name) | ValueNs(name) | MacroNs(name) | LifetimeNs(name) => Some(name), - Impl | CrateRoot | Misc | ClosureExpr | Ctor | AnonConst | ImplTrait => None, + Impl | ForeignMod | CrateRoot | Misc | ClosureExpr | Ctor | AnonConst | ImplTrait => { + None + } } } @@ -482,6 +486,7 @@ impl DefPathData { // Note that this does not show up in user print-outs. CrateRoot => DefPathDataName::Anon { namespace: kw::Crate }, Impl => DefPathDataName::Anon { namespace: kw::Impl }, + ForeignMod => DefPathDataName::Anon { namespace: kw::Extern }, Misc => DefPathDataName::Anon { namespace: sym::misc }, ClosureExpr => DefPathDataName::Anon { namespace: sym::closure }, Ctor => DefPathDataName::Anon { namespace: sym::constructor }, diff --git a/compiler/rustc_lint/src/context.rs b/compiler/rustc_lint/src/context.rs index 71db58f2d8bae..313a1cc208633 100644 --- a/compiler/rustc_lint/src/context.rs +++ b/compiler/rustc_lint/src/context.rs @@ -1040,8 +1040,8 @@ impl<'tcx> LateContext<'tcx> { ) -> Result { let mut path = print_prefix(self)?; - // Skip `::{{constructor}}` on tuple/unit structs. - if let DefPathData::Ctor = disambiguated_data.data { + // Skip `::{{extern}}` blocks and `::{{constructor}}` on tuple/unit structs. + if let DefPathData::ForeignMod | DefPathData::Ctor = disambiguated_data.data { return Ok(path); } diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index 175295b3199e8..b3b8183d313f3 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -1740,30 +1740,26 @@ impl Printer<'tcx> for FmtPrinter<'_, 'tcx, F> { ) -> Result { self = print_prefix(self)?; - // Skip `::{{constructor}}` on tuple/unit structs. - if let DefPathData::Ctor = disambiguated_data.data { + // Skip `::{{extern}}` blocks and `::{{constructor}}` on tuple/unit structs. + if let DefPathData::ForeignMod | DefPathData::Ctor = disambiguated_data.data { return Ok(self); } - // FIXME(eddyb) `name` should never be empty, but it - // currently is for `extern { ... }` "foreign modules". let name = disambiguated_data.data.name(); - if name != DefPathDataName::Named(kw::Empty) { - if !self.empty_path { - write!(self, "::")?; - } + if !self.empty_path { + write!(self, "::")?; + } - if let DefPathDataName::Named(name) = name { - if Ident::with_dummy_span(name).is_raw_guess() { - write!(self, "r#")?; - } + if let DefPathDataName::Named(name) = name { + if Ident::with_dummy_span(name).is_raw_guess() { + write!(self, "r#")?; } + } - let verbose = self.tcx.sess.verbose(); - disambiguated_data.fmt_maybe_verbose(&mut self, verbose)?; + let verbose = self.tcx.sess.verbose(); + disambiguated_data.fmt_maybe_verbose(&mut self, verbose)?; - self.empty_path = false; - } + self.empty_path = false; Ok(self) } diff --git a/compiler/rustc_resolve/src/def_collector.rs b/compiler/rustc_resolve/src/def_collector.rs index 391baa85c61db..688b7b1a8c6d2 100644 --- a/compiler/rustc_resolve/src/def_collector.rs +++ b/compiler/rustc_resolve/src/def_collector.rs @@ -92,6 +92,7 @@ impl<'a, 'b> visit::Visitor<'a> for DefCollector<'a, 'b> { // information we encapsulate into, the better let def_data = match &i.kind { ItemKind::Impl { .. } => DefPathData::Impl, + ItemKind::ForeignMod(..) => DefPathData::ForeignMod, ItemKind::Mod(..) | ItemKind::Trait(..) | ItemKind::TraitAlias(..) @@ -99,7 +100,6 @@ impl<'a, 'b> visit::Visitor<'a> for DefCollector<'a, 'b> { | ItemKind::Struct(..) | ItemKind::Union(..) | ItemKind::ExternCrate(..) - | ItemKind::ForeignMod(..) | ItemKind::TyAlias(..) => DefPathData::TypeNs(i.ident.name), ItemKind::Static(..) | ItemKind::Const(..) | ItemKind::Fn(..) => { DefPathData::ValueNs(i.ident.name) diff --git a/compiler/rustc_symbol_mangling/src/legacy.rs b/compiler/rustc_symbol_mangling/src/legacy.rs index cdea84a8d60f7..0232aace6d78c 100644 --- a/compiler/rustc_symbol_mangling/src/legacy.rs +++ b/compiler/rustc_symbol_mangling/src/legacy.rs @@ -311,8 +311,8 @@ impl<'tcx> Printer<'tcx> for &mut SymbolPrinter<'tcx> { ) -> Result { self = print_prefix(self)?; - // Skip `::{{constructor}}` on tuple/unit structs. - if let DefPathData::Ctor = disambiguated_data.data { + // Skip `::{{extern}}` blocks and `::{{constructor}}` on tuple/unit structs. + if let DefPathData::ForeignMod | DefPathData::Ctor = disambiguated_data.data { return Ok(self); } diff --git a/compiler/rustc_symbol_mangling/src/v0.rs b/compiler/rustc_symbol_mangling/src/v0.rs index 167ff758f3480..ea6366c407e21 100644 --- a/compiler/rustc_symbol_mangling/src/v0.rs +++ b/compiler/rustc_symbol_mangling/src/v0.rs @@ -771,6 +771,10 @@ impl<'tcx> Printer<'tcx> for &mut SymbolMangler<'tcx> { disambiguated_data: &DisambiguatedDefPathData, ) -> Result { let ns = match disambiguated_data.data { + // FIXME: It shouldn't be necessary to add anything for extern block segments, + // but we add 't' for backward compatibility. + DefPathData::ForeignMod => 't', + // Uppercase categories are more stable than lowercase ones. DefPathData::TypeNs(_) => 't', DefPathData::ValueNs(_) => 'v', diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index 39544fa843de8..57621f4f18cfe 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -8,6 +8,7 @@ use rustc_data_structures::fx::FxHashSet; use rustc_hir as hir; use rustc_hir::def::{DefKind, Res}; use rustc_hir::def_id::DefId; +use rustc_hir::definitions::DefPathData; use rustc_hir::Mutability; use rustc_metadata::creader::{CStore, LoadedMacro}; use rustc_middle::ty::{self, TyCtxt}; @@ -165,9 +166,8 @@ crate fn record_extern_fqn(cx: &mut DocContext<'_>, did: DefId, kind: ItemType) let crate_name = cx.tcx.crate_name(did.krate).to_string(); let relative = cx.tcx.def_path(did).data.into_iter().filter_map(|elem| { - // extern blocks have an empty name - let s = elem.data.to_string(); - if !s.is_empty() { Some(s) } else { None } + // Filter out extern blocks + (elem.data != DefPathData::ForeignMod).then(|| elem.data.to_string()) }); let fqn = if let ItemType::Macro = kind { // Check to see if it is a macro 2.0 or built-in macro diff --git a/src/librustdoc/visit_ast.rs b/src/librustdoc/visit_ast.rs index a18bd48d72bc4..ea7372761ba31 100644 --- a/src/librustdoc/visit_ast.rs +++ b/src/librustdoc/visit_ast.rs @@ -5,6 +5,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_hir as hir; use rustc_hir::def::{DefKind, Res}; use rustc_hir::def_id::DefId; +use rustc_hir::definitions::DefPathData; use rustc_hir::Node; use rustc_hir::CRATE_HIR_ID; use rustc_middle::middle::privacy::AccessLevel; @@ -45,9 +46,8 @@ impl Module<'hir> { fn def_id_to_path(tcx: TyCtxt<'_>, did: DefId) -> Vec { let crate_name = tcx.crate_name(did.krate).to_string(); let relative = tcx.def_path(did).data.into_iter().filter_map(|elem| { - // extern blocks have an empty name - let s = elem.data.to_string(); - if !s.is_empty() { Some(s) } else { None } + // Filter out extern blocks + (elem.data != DefPathData::ForeignMod).then(|| elem.data.to_string()) }); std::iter::once(crate_name).chain(relative).collect() }