Skip to content

Commit 83f6d74

Browse files
committed
Auto merge of rust-lang#135576 - matthiaskrgr:rollup-e38vft0, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - rust-lang#133720 ([cfg_match] Adjust syntax) - rust-lang#134496 (Update documentation for Arc::from_raw, Arc::increment_strong_count, and Arc::decrement_strong_count to clarify allocator requirement) - rust-lang#134754 (Implement `use` associated items of traits) - rust-lang#135249 (Fix overflows in the implementation of `overflowing_literals` lint's help) - rust-lang#135251 (Only treat plain literal patterns as short) - rust-lang#135556 (Clarify note in `std::sync::LazyLock` example) - rust-lang#135560 (Update `compiler-builtins` to 0.1.144) r? `@ghost` `@rustbot` modify labels: rollup
2 parents d8a6409 + 5d1688d commit 83f6d74

37 files changed

+1009
-88
lines changed

compiler/rustc_codegen_cranelift/patches/0029-stdlib-Disable-f16-and-f128-in-compiler-builtins.patch

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ index 7165c3e48af..968552ad435 100644
1616

1717
[dependencies]
1818
core = { path = "../core" }
19-
-compiler_builtins = { version = "=0.1.143", features = ['rustc-dep-of-std'] }
20-
+compiler_builtins = { version = "=0.1.143", features = ['rustc-dep-of-std', 'no-f16-f128'] }
19+
-compiler_builtins = { version = "=0.1.144", features = ['rustc-dep-of-std'] }
20+
+compiler_builtins = { version = "=0.1.144", features = ['rustc-dep-of-std', 'no-f16-f128'] }
2121

2222
[dev-dependencies]
2323
rand = { version = "0.8.5", default-features = false, features = ["alloc"] }

compiler/rustc_data_structures/src/flock.rs

+25
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
//! green/native threading. This is just a bare-bones enough solution for
55
//! librustdoc, it is not production quality at all.
66
7+
#[cfg(bootstrap)]
78
cfg_match! {
89
cfg(target_os = "linux") => {
910
mod linux;
@@ -27,4 +28,28 @@ cfg_match! {
2728
}
2829
}
2930

31+
#[cfg(not(bootstrap))]
32+
cfg_match! {
33+
target_os = "linux" => {
34+
mod linux;
35+
use linux as imp;
36+
}
37+
target_os = "redox" => {
38+
mod linux;
39+
use linux as imp;
40+
}
41+
unix => {
42+
mod unix;
43+
use unix as imp;
44+
}
45+
windows => {
46+
mod windows;
47+
use self::windows as imp;
48+
}
49+
_ => {
50+
mod unsupported;
51+
use unsupported as imp;
52+
}
53+
}
54+
3055
pub use imp::Lock;

compiler/rustc_data_structures/src/profiling.rs

+63
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,7 @@ fn get_thread_id() -> u32 {
860860
}
861861

862862
// Memory reporting
863+
#[cfg(bootstrap)]
863864
cfg_match! {
864865
cfg(windows) => {
865866
pub fn get_resident_set_size() -> Option<usize> {
@@ -921,5 +922,67 @@ cfg_match! {
921922
}
922923
}
923924

925+
#[cfg(not(bootstrap))]
926+
cfg_match! {
927+
windows => {
928+
pub fn get_resident_set_size() -> Option<usize> {
929+
use std::mem;
930+
931+
use windows::{
932+
Win32::System::ProcessStatus::{K32GetProcessMemoryInfo, PROCESS_MEMORY_COUNTERS},
933+
Win32::System::Threading::GetCurrentProcess,
934+
};
935+
936+
let mut pmc = PROCESS_MEMORY_COUNTERS::default();
937+
let pmc_size = mem::size_of_val(&pmc);
938+
unsafe {
939+
K32GetProcessMemoryInfo(
940+
GetCurrentProcess(),
941+
&mut pmc,
942+
pmc_size as u32,
943+
)
944+
}
945+
.ok()
946+
.ok()?;
947+
948+
Some(pmc.WorkingSetSize)
949+
}
950+
}
951+
target_os = "macos" => {
952+
pub fn get_resident_set_size() -> Option<usize> {
953+
use libc::{c_int, c_void, getpid, proc_pidinfo, proc_taskinfo, PROC_PIDTASKINFO};
954+
use std::mem;
955+
const PROC_TASKINFO_SIZE: c_int = mem::size_of::<proc_taskinfo>() as c_int;
956+
957+
unsafe {
958+
let mut info: proc_taskinfo = mem::zeroed();
959+
let info_ptr = &mut info as *mut proc_taskinfo as *mut c_void;
960+
let pid = getpid() as c_int;
961+
let ret = proc_pidinfo(pid, PROC_PIDTASKINFO, 0, info_ptr, PROC_TASKINFO_SIZE);
962+
if ret == PROC_TASKINFO_SIZE {
963+
Some(info.pti_resident_size as usize)
964+
} else {
965+
None
966+
}
967+
}
968+
}
969+
}
970+
unix => {
971+
pub fn get_resident_set_size() -> Option<usize> {
972+
let field = 1;
973+
let contents = fs::read("/proc/self/statm").ok()?;
974+
let contents = String::from_utf8(contents).ok()?;
975+
let s = contents.split_whitespace().nth(field)?;
976+
let npages = s.parse::<usize>().ok()?;
977+
Some(npages * 4096)
978+
}
979+
}
980+
_ => {
981+
pub fn get_resident_set_size() -> Option<usize> {
982+
None
983+
}
984+
}
985+
}
986+
924987
#[cfg(test)]
925988
mod tests;
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
Attempt was made to import an unimportable value. This can happen when trying
2-
to import a method from a trait.
1+
Attempt was made to import an unimportable type. This can happen when trying
2+
to import a type from a trait.
33

44
Erroneous code example:
55

66
```compile_fail,E0253
77
mod foo {
88
pub trait MyTrait {
9-
fn do_something();
9+
type SomeType;
1010
}
1111
}
1212
13-
use foo::MyTrait::do_something;
14-
// error: `do_something` is not directly importable
13+
use foo::MyTrait::SomeType;
14+
// error: `SomeType` is not directly importable
1515
1616
fn main() {}
1717
```
1818

19-
It's invalid to directly import methods belonging to a trait or concrete type.
19+
It's invalid to directly import types belonging to a trait.

compiler/rustc_feature/src/unstable.rs

+2
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,8 @@ declare_features! (
521521
(unstable, impl_trait_in_bindings, "1.64.0", Some(63065)),
522522
/// Allows `impl Trait` as output type in `Fn` traits in return position of functions.
523523
(unstable, impl_trait_in_fn_trait_return, "1.64.0", Some(99697)),
524+
/// Allows `use` associated functions from traits.
525+
(unstable, import_trait_associated_functions, "CURRENT_RUSTC_VERSION", Some(134691)),
524526
/// Allows associated types in inherent impls.
525527
(incomplete, inherent_associated_types, "1.52.0", Some(8995)),
526528
/// Allow anonymous constants from an inline `const` block in pattern position

compiler/rustc_lint/src/types/literal.rs

+23-8
Original file line numberDiff line numberDiff line change
@@ -204,20 +204,35 @@ fn get_type_suggestion(t: Ty<'_>, val: u128, negative: bool) -> Option<&'static
204204
match t.kind() {
205205
ty::Uint(ty::UintTy::Usize) | ty::Int(ty::IntTy::Isize) => None,
206206
ty::Uint(_) => Some(Integer::fit_unsigned(val).uint_ty_str()),
207-
ty::Int(_) if negative => Some(Integer::fit_signed(-(val as i128)).int_ty_str()),
208-
ty::Int(int) => {
209-
let signed = Integer::fit_signed(val as i128);
210-
let unsigned = Integer::fit_unsigned(val);
211-
Some(if Some(unsigned.size().bits()) == int.bit_width() {
212-
unsigned.uint_ty_str()
207+
ty::Int(_) => {
208+
let signed = literal_to_i128(val, negative).map(Integer::fit_signed);
209+
if negative {
210+
signed.map(Integer::int_ty_str)
213211
} else {
214-
signed.int_ty_str()
215-
})
212+
let unsigned = Integer::fit_unsigned(val);
213+
Some(if let Some(signed) = signed {
214+
if unsigned.size() < signed.size() {
215+
unsigned.uint_ty_str()
216+
} else {
217+
signed.int_ty_str()
218+
}
219+
} else {
220+
unsigned.uint_ty_str()
221+
})
222+
}
216223
}
217224
_ => None,
218225
}
219226
}
220227

228+
fn literal_to_i128(val: u128, negative: bool) -> Option<i128> {
229+
if negative {
230+
(val <= i128::MAX as u128 + 1).then(|| val.wrapping_neg() as i128)
231+
} else {
232+
val.try_into().ok()
233+
}
234+
}
235+
221236
fn lint_int_literal<'tcx>(
222237
cx: &LateContext<'tcx>,
223238
type_limits: &TypeLimits,

compiler/rustc_resolve/src/diagnostics.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -1183,7 +1183,11 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
11831183
let in_module_is_extern = !in_module.def_id().is_local();
11841184
in_module.for_each_child(self, |this, ident, ns, name_binding| {
11851185
// avoid non-importable candidates
1186-
if !name_binding.is_importable() {
1186+
if !name_binding.is_importable()
1187+
// FIXME(import_trait_associated_functions): remove this when `import_trait_associated_functions` is stable
1188+
|| name_binding.is_assoc_const_or_fn()
1189+
&& !this.tcx.features().import_trait_associated_functions()
1190+
{
11871191
return;
11881192
}
11891193

compiler/rustc_resolve/src/imports.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ use rustc_session::lint::builtin::{
1717
AMBIGUOUS_GLOB_REEXPORTS, HIDDEN_GLOB_REEXPORTS, PUB_USE_OF_PRIVATE_EXTERN_CRATE,
1818
REDUNDANT_IMPORTS, UNUSED_IMPORTS,
1919
};
20+
use rustc_session::parse::feature_err;
2021
use rustc_span::edit_distance::find_best_match_for_name;
2122
use rustc_span::hygiene::LocalExpnId;
22-
use rustc_span::{Ident, Span, Symbol, kw};
23+
use rustc_span::{Ident, Span, Symbol, kw, sym};
2324
use smallvec::SmallVec;
2425
use tracing::debug;
2526

@@ -829,6 +830,17 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
829830
// Don't update the resolution, because it was never added.
830831
Err(Determined) if target.name == kw::Underscore => {}
831832
Ok(binding) if binding.is_importable() => {
833+
if binding.is_assoc_const_or_fn()
834+
&& !this.tcx.features().import_trait_associated_functions()
835+
{
836+
feature_err(
837+
this.tcx.sess,
838+
sym::import_trait_associated_functions,
839+
import.span,
840+
"`use` associated items of traits is unstable",
841+
)
842+
.emit();
843+
}
832844
let imported_binding = this.import(binding, import);
833845
target_bindings[ns].set(Some(imported_binding));
834846
this.define(parent, target, ns, imported_binding);

compiler/rustc_resolve/src/lib.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -920,10 +920,13 @@ impl<'ra> NameBindingData<'ra> {
920920
}
921921

922922
fn is_importable(&self) -> bool {
923-
!matches!(
924-
self.res(),
925-
Res::Def(DefKind::AssocConst | DefKind::AssocFn | DefKind::AssocTy, _)
926-
)
923+
!matches!(self.res(), Res::Def(DefKind::AssocTy, _))
924+
}
925+
926+
// FIXME(import_trait_associated_functions): associate `const` or `fn` are not importable unless
927+
// the feature `import_trait_associated_functions` is enable
928+
fn is_assoc_const_or_fn(&self) -> bool {
929+
matches!(self.res(), Res::Def(DefKind::AssocConst | DefKind::AssocFn, _))
927930
}
928931

929932
fn macro_kind(&self) -> Option<MacroKind> {

0 commit comments

Comments
 (0)