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 7 pull requests #111611

Closed
wants to merge 28 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
af5de85
Remove unnecessary Send bound
GilShoshan94 May 3, 2023
2664660
bootstrap: enable Cargo `public-dependency` feature for `libstd`
notriddle May 1, 2023
28b7747
rustc_metadata: inherit dependency privacy flag
notriddle May 1, 2023
7c673c6
diagnostics: exclude indirect private deps from trait impl suggest
notriddle May 1, 2023
1f8e8fe
Update compiler/rustc_metadata/src/creader.rs
notriddle May 1, 2023
8b06850
rust-installer: include `RUSTC_BOOTSTRAP` when generating installer
notriddle May 1, 2023
64c11bc
Improve comments
notriddle May 8, 2023
d7041de
rustc_metadata: fix private_dep logic in `register_crate`
notriddle May 8, 2023
827a181
diagnostics: don't crash if an injected crate shows up in suggestions
notriddle May 8, 2023
1d3799e
rustc_metadata: use AtomicBool for privateness instead of Lock
notriddle May 8, 2023
3d3bd20
remove outdated comment from `is_user_visible_dep` docs
notriddle May 8, 2023
fcee118
std: mark common functions in test crate `pub(crate)`
notriddle May 8, 2023
190047f
rustc_metadata: use configurable AtomicBool for privateness flag
notriddle May 8, 2023
1b1c787
Use De Morgan's law to simplify logic
notriddle May 9, 2023
bbc9674
rustc_metadata: specialize private_dep flag with `fetch_and`
notriddle May 9, 2023
9dffb52
Get current target config from` --print=cfg`
May 11, 2023
cf7131e
Rework handling of recursive panics
Amanieu Apr 28, 2023
9c58f91
Add support for nested panics to miri
Amanieu Apr 29, 2023
980b392
Document that `missing_copy_implementations` and `missing_debug_imple…
kpreid May 14, 2023
9799fb1
fixup version placeholder for cfi_encoding feature
klensy May 15, 2023
29a81f5
Add clubby789 to the bootstrap review rotation
jyn514 May 15, 2023
23f7f7e
Rollup merge of #110975 - Amanieu:panic_count, r=joshtriplett
matthiaskrgr May 15, 2023
e1b6294
Rollup merge of #111076 - notriddle:notriddle/silence-private-dep-tra…
matthiaskrgr May 15, 2023
206c7a5
Rollup merge of #111134 - GilShoshan94:remove-send-bound-on-error, r=…
matthiaskrgr May 15, 2023
32e2883
Rollup merge of #111472 - djkoloski:compiletest_cfg_current_target, r…
matthiaskrgr May 15, 2023
8cfd0ff
Rollup merge of #111572 - kpreid:mdi, r=compiler-errors
matthiaskrgr May 15, 2023
a91f879
Rollup merge of #111605 - klensy:fixup_version, r=compiler-errors
matthiaskrgr May 15, 2023
63315ca
Rollup merge of #111607 - jyn514:clubby-reviews, r=clubby789
matthiaskrgr May 15, 2023
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
5 changes: 5 additions & 0 deletions compiler/rustc_data_structures/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ cfg_if! {
self.0.set(val);
result
}
pub fn fetch_and(&self, val: bool, _: Ordering) -> bool {
let result = self.0.get() & val;
self.0.set(val);
result
}
}

impl<T: Copy + PartialEq> Atomic<T> {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_feature/src/active.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ declare_features! (
/// Allow conditional compilation depending on rust version
(active, cfg_version, "1.45.0", Some(64796), None),
/// Allows to use the `#[cfi_encoding = ""]` attribute.
(active, cfi_encoding, "1.69.0", Some(89653), None),
(active, cfi_encoding, "CURRENT_RUSTC_VERSION", Some(89653), None),
/// Allows `for<...>` on closures and generators.
(active, closure_lifetime_binder, "1.64.0", Some(97362), None),
/// Allows `#[track_caller]` on closures and generators.
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_lint/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {

declare_lint! {
/// The `missing_copy_implementations` lint detects potentially-forgotten
/// implementations of [`Copy`].
/// implementations of [`Copy`] for public types.
///
/// [`Copy`]: https://doc.rust-lang.org/std/marker/trait.Copy.html
///
Expand Down Expand Up @@ -729,7 +729,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingCopyImplementations {

declare_lint! {
/// The `missing_debug_implementations` lint detects missing
/// implementations of [`fmt::Debug`].
/// implementations of [`fmt::Debug`] for public types.
///
/// [`fmt::Debug`]: https://doc.rust-lang.org/std/fmt/trait.Debug.html
///
Expand Down
20 changes: 15 additions & 5 deletions compiler/rustc_metadata/src/creader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,15 +361,21 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
lib: Library,
dep_kind: CrateDepKind,
name: Symbol,
private_dep: Option<bool>,
) -> Result<CrateNum, CrateError> {
let _prof_timer = self.sess.prof.generic_activity("metadata_register_crate");

let Library { source, metadata } = lib;
let crate_root = metadata.get_root();
let host_hash = host_lib.as_ref().map(|lib| lib.metadata.get_root().hash());

let private_dep =
self.sess.opts.externs.get(name.as_str()).map_or(false, |e| e.is_private_dep);
let private_dep = self
.sess
.opts
.externs
.get(name.as_str())
.map_or(private_dep.unwrap_or(false), |e| e.is_private_dep)
&& private_dep.unwrap_or(true);

// Claim this crate number and cache it
let cnum = self.cstore.intern_stable_crate_id(&crate_root)?;
Expand Down Expand Up @@ -514,15 +520,16 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
if !name.as_str().is_ascii() {
return Err(CrateError::NonAsciiName(name));
}
let (root, hash, host_hash, extra_filename, path_kind) = match dep {
let (root, hash, host_hash, extra_filename, path_kind, private_dep) = match dep {
Some((root, dep)) => (
Some(root),
Some(dep.hash),
dep.host_hash,
Some(&dep.extra_filename[..]),
PathKind::Dependency,
Some(dep.is_private),
),
None => (None, None, None, None, PathKind::Crate),
None => (None, None, None, None, PathKind::Crate, None),
};
let result = if let Some(cnum) = self.existing_match(name, hash, path_kind) {
(LoadResult::Previous(cnum), None)
Expand Down Expand Up @@ -558,10 +565,13 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
dep_kind = CrateDepKind::MacrosOnly;
}
data.update_dep_kind(|data_dep_kind| cmp::max(data_dep_kind, dep_kind));
if let Some(private_dep) = private_dep {
data.update_and_private_dep(private_dep);
}
Ok(cnum)
}
(LoadResult::Loaded(library), host_library) => {
self.register_crate(host_library, root, library, dep_kind, name)
self.register_crate(host_library, root, library, dep_kind, name, private_dep)
}
_ => panic!(),
}
Expand Down
21 changes: 14 additions & 7 deletions compiler/rustc_metadata/src/rmeta/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use rustc_ast as ast;
use rustc_data_structures::captures::Captures;
use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::svh::Svh;
use rustc_data_structures::sync::{AppendOnlyVec, Lock, Lrc, OnceCell};
use rustc_data_structures::sync::{AppendOnlyVec, AtomicBool, Lock, Lrc, OnceCell};
use rustc_data_structures::unhash::UnhashMap;
use rustc_expand::base::{SyntaxExtension, SyntaxExtensionKind};
use rustc_expand::proc_macro::{AttrProcMacro, BangProcMacro, DeriveProcMacro};
Expand Down Expand Up @@ -38,6 +38,7 @@ use proc_macro::bridge::client::ProcMacro;
use std::iter::TrustedLen;
use std::num::NonZeroUsize;
use std::path::Path;
use std::sync::atomic::Ordering;
use std::{io, iter, mem};

pub(super) use cstore_impl::provide;
Expand Down Expand Up @@ -109,9 +110,10 @@ pub(crate) struct CrateMetadata {
dep_kind: Lock<CrateDepKind>,
/// Filesystem location of this crate.
source: Lrc<CrateSource>,
/// Whether or not this crate should be consider a private dependency
/// for purposes of the 'exported_private_dependencies' lint
private_dep: bool,
/// Whether or not this crate should be consider a private dependency.
/// Used by the 'exported_private_dependencies' lint, and for determining
/// whether to emit suggestions that reference this crate.
private_dep: AtomicBool,
/// The hash for the host proc macro. Used to support `-Z dual-proc-macro`.
host_hash: Option<Svh>,

Expand Down Expand Up @@ -692,12 +694,13 @@ impl MetadataBlob {
writeln!(out, "=External Dependencies=")?;

for (i, dep) in root.crate_deps.decode(self).enumerate() {
let CrateDep { name, extra_filename, hash, host_hash, kind } = dep;
let CrateDep { name, extra_filename, hash, host_hash, kind, is_private } = dep;
let number = i + 1;

writeln!(
out,
"{number} {name}{extra_filename} hash {hash} host_hash {host_hash:?} kind {kind:?}"
"{number} {name}{extra_filename} hash {hash} host_hash {host_hash:?} kind {kind:?} {privacy}",
privacy = if is_private { "private" } else { "public" }
)?;
}
write!(out, "\n")?;
Expand Down Expand Up @@ -1627,7 +1630,7 @@ impl CrateMetadata {
dependencies,
dep_kind: Lock::new(dep_kind),
source: Lrc::new(source),
private_dep,
private_dep: AtomicBool::new(private_dep),
host_hash,
extern_crate: Lock::new(None),
hygiene_context: Default::default(),
Expand Down Expand Up @@ -1675,6 +1678,10 @@ impl CrateMetadata {
self.dep_kind.with_lock(|dep_kind| *dep_kind = f(*dep_kind))
}

pub(crate) fn update_and_private_dep(&self, private_dep: bool) {
self.private_dep.fetch_and(private_dep, Ordering::SeqCst);
}

pub(crate) fn required_panic_strategy(&self) -> Option<PanicStrategy> {
self.root.required_panic_strategy
}
Expand Down
8 changes: 7 additions & 1 deletion compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,13 @@ provide! { tcx, def_id, other, cdata,
is_ctfe_mir_available => { cdata.is_ctfe_mir_available(def_id.index) }

dylib_dependency_formats => { cdata.get_dylib_dependency_formats(tcx) }
is_private_dep => { cdata.private_dep }
is_private_dep => {
// Parallel compiler needs to synchronize type checking and linting (which use this flag)
// so that they happen strictly crate loading. Otherwise, the full list of available
// impls aren't loaded yet.
use std::sync::atomic::Ordering;
cdata.private_dep.load(Ordering::Acquire)
}
is_panic_runtime => { cdata.root.panic_runtime }
is_compiler_builtins => { cdata.root.compiler_builtins }
has_global_allocator => { cdata.root.has_global_allocator }
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_metadata/src/rmeta/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1869,6 +1869,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
host_hash: self.tcx.crate_host_hash(cnum),
kind: self.tcx.dep_kind(cnum),
extra_filename: self.tcx.extra_filename(cnum).clone(),
is_private: self.tcx.is_private_dep(cnum),
};
(cnum, dep)
})
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_metadata/src/rmeta/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ pub(crate) struct CrateDep {
pub host_hash: Option<Svh>,
pub kind: CrateDepKind,
pub extra_filename: String,
pub is_private: bool,
}

#[derive(MetadataEncodable, MetadataDecodable)]
Expand Down
22 changes: 21 additions & 1 deletion compiler/rustc_middle/src/ty/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use rustc_data_structures::stable_hasher::{Hash64, HashStable, StableHasher};
use rustc_errors::ErrorGuaranteed;
use rustc_hir as hir;
use rustc_hir::def::{CtorOf, DefKind, Res};
use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId};
use rustc_index::bit_set::GrowableBitSet;
use rustc_index::{Idx, IndexVec};
use rustc_macros::HashStable;
Expand Down Expand Up @@ -820,6 +820,26 @@ impl<'tcx> TyCtxt<'tcx> {
_ => def_kind.article(),
}
}

/// Return `true` if the supplied `CrateNum` is "user-visible," meaning either a [public]
/// dependency, or a [direct] private dependency. This is used to decide whether the crate can
/// be shown in `impl` suggestions.
///
/// [public]: TyCtxt::is_private_dep
/// [direct]: rustc_session::cstore::ExternCrate::is_direct
pub fn is_user_visible_dep(self, key: CrateNum) -> bool {
// | Private | Direct | Visible | |
// |---------|--------|---------|--------------------|
// | Yes | Yes | Yes | !true || true |
// | No | Yes | Yes | !false || true |
// | Yes | No | No | !true || false |
// | No | No | Yes | !false || false |
!self.is_private_dep(key)
// If `extern_crate` is `None`, then the crate was injected (e.g., by the allocator).
// Treat that kind of crate as "indirect", since it's an implementation detail of
// the language.
|| self.extern_crate(key.as_def_id()).map_or(false, |e| e.is_direct())
}
}

struct OpaqueTypeExpander<'tcx> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1775,6 +1775,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|| !trait_pred
.skip_binder()
.is_constness_satisfied_by(self.tcx.constness(def_id))
|| !self.tcx.is_user_visible_dep(def_id.krate)
{
return None;
}
Expand Down
10 changes: 6 additions & 4 deletions library/std/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
cargo-features = ["public-dependency"]

[package]
name = "std"
version = "0.0.0"
Expand All @@ -10,12 +12,12 @@ edition = "2021"
crate-type = ["dylib", "rlib"]

[dependencies]
alloc = { path = "../alloc" }
alloc = { path = "../alloc", public = true }
cfg-if = { version = "1.0", features = ['rustc-dep-of-std'] }
panic_unwind = { path = "../panic_unwind", optional = true }
panic_abort = { path = "../panic_abort" }
core = { path = "../core" }
libc = { version = "0.2.143", default-features = false, features = ['rustc-dep-of-std'] }
core = { path = "../core", public = true }
libc = { version = "0.2.143", default-features = false, features = ['rustc-dep-of-std'], public = true }
compiler_builtins = { version = "0.1.91" }
profiler_builtins = { path = "../profiler_builtins", optional = true }
unwind = { path = "../unwind" }
Expand All @@ -25,7 +27,7 @@ std_detect = { path = "../stdarch/crates/std_detect", default-features = false,
# Dependencies of the `backtrace` crate
addr2line = { version = "0.19.0", optional = true, default-features = false }
rustc-demangle = { version = "0.1.21", features = ['rustc-dep-of-std'] }
miniz_oxide = { version = "0.6.0", optional = true, default-features = false }
miniz_oxide = { version = "0.6.0", optional = true, default-features = false, public = false }
[dependencies.object]
version = "0.30.0"
optional = true
Expand Down
Loading