Skip to content

Commit ad39372

Browse files
committed
Auto merge of #141707 - tgross35:rollup-aoygluy, r=tgross35
Rollup of 7 pull requests Successful merges: - #125087 (Optimize `Seek::stream_len` impl for `File`) - #133823 (Use `cfg_attr_trace` in AST with a placeholder attribute for accurate suggestion) - #138285 (Stabilize `repr128`) - #139994 (add `CStr::display`) - #141477 (Path::with_extension: show that it adds an extension where one did no…) - #141533 (clean up old rintf leftovers) - #141693 (Subtree update of `rust-analyzer`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 6f69710 + 9cd4054 commit ad39372

File tree

139 files changed

+2064
-1332
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

139 files changed

+2064
-1332
lines changed

compiler/rustc_error_codes/src/error_codes/E0658.md

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@ An unstable feature was used.
33
Erroneous code example:
44

55
```compile_fail,E0658
6-
#[repr(u128)] // error: use of unstable library feature 'repr128'
7-
enum Foo {
8-
Bar(u64),
9-
}
6+
use std::intrinsics; // error: use of unstable library feature `core_intrinsics`
107
```
118

129
If you're using a stable or a beta version of rustc, you won't be able to use
@@ -17,12 +14,9 @@ If you're using a nightly version of rustc, just add the corresponding feature
1714
to be able to use it:
1815

1916
```
20-
#![feature(repr128)]
17+
#![feature(core_intrinsics)]
2118
22-
#[repr(u128)] // ok!
23-
enum Foo {
24-
Bar(u64),
25-
}
19+
use std::intrinsics; // ok!
2620
```
2721

2822
[rustup]: https://rust-lang.github.io/rustup/concepts/channels.html

compiler/rustc_feature/src/accepted.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,8 @@ declare_features! (
360360
(accepted, relaxed_adts, "1.19.0", Some(35626)),
361361
/// Lessens the requirements for structs to implement `Unsize`.
362362
(accepted, relaxed_struct_unsize, "1.58.0", Some(81793)),
363+
/// Allows the `#[repr(i128)]` attribute for enums.
364+
(accepted, repr128, "CURRENT_RUSTC_VERSION", Some(56071)),
363365
/// Allows `repr(align(16))` struct attribute (RFC 1358).
364366
(accepted, repr_align, "1.25.0", Some(33626)),
365367
/// Allows using `#[repr(align(X))]` on enums with equivalent semantics

compiler/rustc_feature/src/unstable.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -621,8 +621,6 @@ declare_features! (
621621
(incomplete, ref_pat_eat_one_layer_2024_structural, "1.81.0", Some(123076)),
622622
/// Allows using the `#[register_tool]` attribute.
623623
(unstable, register_tool, "1.41.0", Some(66079)),
624-
/// Allows the `#[repr(i128)]` attribute for enums.
625-
(incomplete, repr128, "1.16.0", Some(56071)),
626624
/// Allows `repr(simd)` and importing the various simd intrinsics.
627625
(unstable, repr_simd, "1.4.0", Some(27731)),
628626
/// Allows bounding the return type of AFIT/RPITIT.

compiler/rustc_hir_analysis/src/check/check.rs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use rustc_middle::middle::resolve_bound_vars::ResolvedArg;
1818
use rustc_middle::middle::stability::EvalResult;
1919
use rustc_middle::ty::error::TypeErrorToStringExt;
2020
use rustc_middle::ty::layout::{LayoutError, MAX_SIMD_LANES};
21-
use rustc_middle::ty::util::{Discr, IntTypeExt};
21+
use rustc_middle::ty::util::Discr;
2222
use rustc_middle::ty::{
2323
AdtDef, BottomUpFolder, GenericArgKind, RegionKind, TypeFoldable, TypeSuperVisitable,
2424
TypeVisitable, TypeVisitableExt, fold_regions,
@@ -1385,19 +1385,6 @@ fn check_enum(tcx: TyCtxt<'_>, def_id: LocalDefId) {
13851385
);
13861386
}
13871387

1388-
let repr_type_ty = def.repr().discr_type().to_ty(tcx);
1389-
if repr_type_ty == tcx.types.i128 || repr_type_ty == tcx.types.u128 {
1390-
if !tcx.features().repr128() {
1391-
feature_err(
1392-
&tcx.sess,
1393-
sym::repr128,
1394-
tcx.def_span(def_id),
1395-
"repr with 128-bit type is unstable",
1396-
)
1397-
.emit();
1398-
}
1399-
}
1400-
14011388
for v in def.variants() {
14021389
if let ty::VariantDiscr::Explicit(discr_def_id) = v.discr {
14031390
tcx.ensure_ok().typeck(discr_def_id.expect_local());

compiler/rustc_lint/messages.ftl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -959,8 +959,9 @@ lint_unused_doc_comment = unused doc comment
959959
.label = rustdoc does not generate documentation for macro invocations
960960
.help = to document an item produced by a macro, the macro must produce the documentation as part of its expansion
961961
962-
lint_unused_extern_crate = unused extern crate
963-
.suggestion = remove it
962+
lint_unused_extern_crate = unused `extern crate`
963+
.label = unused
964+
.suggestion = remove the unused `extern crate`
964965
965966
lint_unused_import_braces = braces around {$node} is unnecessary
966967

compiler/rustc_lint/src/early/diagnostics.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,8 @@ pub fn decorate_builtin_lint(
292292
BuiltinLintDiag::ByteSliceInPackedStructWithDerive { ty } => {
293293
lints::ByteSliceInPackedStructWithDerive { ty }.decorate_lint(diag);
294294
}
295-
BuiltinLintDiag::UnusedExternCrate { removal_span } => {
296-
lints::UnusedExternCrate { removal_span }.decorate_lint(diag);
295+
BuiltinLintDiag::UnusedExternCrate { span, removal_span } => {
296+
lints::UnusedExternCrate { span, removal_span }.decorate_lint(diag);
297297
}
298298
BuiltinLintDiag::ExternCrateNotIdiomatic { vis_span, ident_span } => {
299299
let suggestion_span = vis_span.between(ident_span);

compiler/rustc_lint/src/lints.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3077,7 +3077,9 @@ pub(crate) struct ByteSliceInPackedStructWithDerive {
30773077
#[derive(LintDiagnostic)]
30783078
#[diag(lint_unused_extern_crate)]
30793079
pub(crate) struct UnusedExternCrate {
3080-
#[suggestion(code = "", applicability = "machine-applicable")]
3080+
#[label]
3081+
pub span: Span,
3082+
#[suggestion(code = "", applicability = "machine-applicable", style = "verbose")]
30813083
pub removal_span: Span,
30823084
}
30833085

compiler/rustc_lint_defs/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,7 @@ pub enum BuiltinLintDiag {
736736
ty: String,
737737
},
738738
UnusedExternCrate {
739+
span: Span,
739740
removal_span: Span,
740741
},
741742
ExternCrateNotIdiomatic {

compiler/rustc_resolve/src/check_unused.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ impl<'a, 'ra, 'tcx> UnusedImportCheckVisitor<'a, 'ra, 'tcx> {
154154
extern_crate.id,
155155
span,
156156
BuiltinLintDiag::UnusedExternCrate {
157+
span: extern_crate.span,
157158
removal_span: extern_crate.span_with_attributes,
158159
},
159160
);

library/core/src/ffi/c_str.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,30 @@ impl CStr {
632632
// instead of doing it afterwards.
633633
str::from_utf8(self.to_bytes())
634634
}
635+
636+
/// Returns an object that implements [`Display`] for safely printing a [`CStr`] that may
637+
/// contain non-Unicode data.
638+
///
639+
/// Behaves as if `self` were first lossily converted to a `str`, with invalid UTF-8 presented
640+
/// as the Unicode replacement character: �.
641+
///
642+
/// [`Display`]: fmt::Display
643+
///
644+
/// # Examples
645+
///
646+
/// ```
647+
/// #![feature(cstr_display)]
648+
///
649+
/// let cstr = c"Hello, world!";
650+
/// println!("{}", cstr.display());
651+
/// ```
652+
#[unstable(feature = "cstr_display", issue = "139984")]
653+
#[must_use = "this does not display the `CStr`; \
654+
it returns an object that can be displayed"]
655+
#[inline]
656+
pub fn display(&self) -> impl fmt::Display {
657+
crate::bstr::ByteStr::from_bytes(self.to_bytes())
658+
}
635659
}
636660

637661
// `.to_bytes()` representations are compared instead of the inner `[c_char]`s,

library/core/src/intrinsics/mod.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2285,12 +2285,6 @@ pub fn round_ties_even_f16(x: f16) -> f16;
22852285
#[rustc_nounwind]
22862286
pub fn round_ties_even_f32(x: f32) -> f32;
22872287

2288-
/// Provided for compatibility with stdarch. DO NOT USE.
2289-
#[inline(always)]
2290-
pub unsafe fn rintf32(x: f32) -> f32 {
2291-
round_ties_even_f32(x)
2292-
}
2293-
22942288
/// Returns the nearest integer to an `f64`. Rounds half-way cases to the number with an even
22952289
/// least significant digit.
22962290
///
@@ -2300,12 +2294,6 @@ pub unsafe fn rintf32(x: f32) -> f32 {
23002294
#[rustc_nounwind]
23012295
pub fn round_ties_even_f64(x: f64) -> f64;
23022296

2303-
/// Provided for compatibility with stdarch. DO NOT USE.
2304-
#[inline(always)]
2305-
pub unsafe fn rintf64(x: f64) -> f64 {
2306-
round_ties_even_f64(x)
2307-
}
2308-
23092297
/// Returns the nearest integer to an `f128`. Rounds half-way cases to the number with an even
23102298
/// least significant digit.
23112299
///

library/coretests/tests/ffi/cstr.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,9 @@ fn debug() {
1919
let s = c"abc\x01\x02\n\xE2\x80\xA6\xFF";
2020
assert_eq!(format!("{s:?}"), r#""abc\x01\x02\n\xe2\x80\xa6\xff""#);
2121
}
22+
23+
#[test]
24+
fn display() {
25+
let s = c"\xf0\x28\x8c\xbc";
26+
assert_eq!(format!("{}", s.display()), "�(��");
27+
}

library/coretests/tests/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#![feature(core_io_borrowed_buf)]
2424
#![feature(core_private_bignum)]
2525
#![feature(core_private_diy_float)]
26+
#![feature(cstr_display)]
2627
#![feature(dec2flt)]
2728
#![feature(duration_constants)]
2829
#![feature(duration_constructors)]

library/std/src/fs.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1311,9 +1311,39 @@ impl Write for &File {
13111311
}
13121312
#[stable(feature = "rust1", since = "1.0.0")]
13131313
impl Seek for &File {
1314+
/// Seek to an offset, in bytes in a file.
1315+
///
1316+
/// See [`Seek::seek`] docs for more info.
1317+
///
1318+
/// # Platform-specific behavior
1319+
///
1320+
/// This function currently corresponds to the `lseek64` function on Unix
1321+
/// and the `SetFilePointerEx` function on Windows. Note that this [may
1322+
/// change in the future][changes].
1323+
///
1324+
/// [changes]: io#platform-specific-behavior
13141325
fn seek(&mut self, pos: SeekFrom) -> io::Result<u64> {
13151326
self.inner.seek(pos)
13161327
}
1328+
1329+
/// Returns the length of this file (in bytes).
1330+
///
1331+
/// See [`Seek::stream_len`] docs for more info.
1332+
///
1333+
/// # Platform-specific behavior
1334+
///
1335+
/// This function currently corresponds to the `statx` function on Linux
1336+
/// (with fallbacks) and the `GetFileSizeEx` function on Windows. Note that
1337+
/// this [may change in the future][changes].
1338+
///
1339+
/// [changes]: io#platform-specific-behavior
1340+
fn stream_len(&mut self) -> io::Result<u64> {
1341+
if let Some(result) = self.inner.size() {
1342+
return result;
1343+
}
1344+
io::stream_len_default(self)
1345+
}
1346+
13171347
fn stream_position(&mut self) -> io::Result<u64> {
13181348
self.inner.tell()
13191349
}
@@ -1363,6 +1393,9 @@ impl Seek for File {
13631393
fn seek(&mut self, pos: SeekFrom) -> io::Result<u64> {
13641394
(&*self).seek(pos)
13651395
}
1396+
fn stream_len(&mut self) -> io::Result<u64> {
1397+
(&*self).stream_len()
1398+
}
13661399
fn stream_position(&mut self) -> io::Result<u64> {
13671400
(&*self).stream_position()
13681401
}
@@ -1412,6 +1445,9 @@ impl Seek for Arc<File> {
14121445
fn seek(&mut self, pos: SeekFrom) -> io::Result<u64> {
14131446
(&**self).seek(pos)
14141447
}
1448+
fn stream_len(&mut self) -> io::Result<u64> {
1449+
(&**self).stream_len()
1450+
}
14151451
fn stream_position(&mut self) -> io::Result<u64> {
14161452
(&**self).stream_position()
14171453
}

library/std/src/io/mod.rs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2028,7 +2028,7 @@ pub trait Seek {
20282028

20292029
/// Returns the length of this stream (in bytes).
20302030
///
2031-
/// This method is implemented using up to three seek operations. If this
2031+
/// The default implementation uses up to three seek operations. If this
20322032
/// method returns successfully, the seek position is unchanged (i.e. the
20332033
/// position before calling this method is the same as afterwards).
20342034
/// However, if this method returns an error, the seek position is
@@ -2062,16 +2062,7 @@ pub trait Seek {
20622062
/// ```
20632063
#[unstable(feature = "seek_stream_len", issue = "59359")]
20642064
fn stream_len(&mut self) -> Result<u64> {
2065-
let old_pos = self.stream_position()?;
2066-
let len = self.seek(SeekFrom::End(0))?;
2067-
2068-
// Avoid seeking a third time when we were already at the end of the
2069-
// stream. The branch is usually way cheaper than a seek operation.
2070-
if old_pos != len {
2071-
self.seek(SeekFrom::Start(old_pos))?;
2072-
}
2073-
2074-
Ok(len)
2065+
stream_len_default(self)
20752066
}
20762067

20772068
/// Returns the current seek position from the start of the stream.
@@ -2132,6 +2123,19 @@ pub trait Seek {
21322123
}
21332124
}
21342125

2126+
pub(crate) fn stream_len_default<T: Seek + ?Sized>(self_: &mut T) -> Result<u64> {
2127+
let old_pos = self_.stream_position()?;
2128+
let len = self_.seek(SeekFrom::End(0))?;
2129+
2130+
// Avoid seeking a third time when we were already at the end of the
2131+
// stream. The branch is usually way cheaper than a seek operation.
2132+
if old_pos != len {
2133+
self_.seek(SeekFrom::Start(old_pos))?;
2134+
}
2135+
2136+
Ok(len)
2137+
}
2138+
21352139
/// Enumeration of possible methods to seek within an I/O object.
21362140
///
21372141
/// It is used by the [`Seek`] trait.

library/std/src/path.rs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2746,15 +2746,30 @@ impl Path {
27462746
/// # Examples
27472747
///
27482748
/// ```
2749-
/// use std::path::{Path, PathBuf};
2749+
/// use std::path::Path;
27502750
///
27512751
/// let path = Path::new("foo.rs");
2752-
/// assert_eq!(path.with_extension("txt"), PathBuf::from("foo.txt"));
2752+
/// assert_eq!(path.with_extension("txt"), Path::new("foo.txt"));
2753+
/// assert_eq!(path.with_extension(""), Path::new("foo"));
2754+
/// ```
2755+
///
2756+
/// Handling multiple extensions:
2757+
///
2758+
/// ```
2759+
/// use std::path::Path;
27532760
///
27542761
/// let path = Path::new("foo.tar.gz");
2755-
/// assert_eq!(path.with_extension(""), PathBuf::from("foo.tar"));
2756-
/// assert_eq!(path.with_extension("xz"), PathBuf::from("foo.tar.xz"));
2757-
/// assert_eq!(path.with_extension("").with_extension("txt"), PathBuf::from("foo.txt"));
2762+
/// assert_eq!(path.with_extension("xz"), Path::new("foo.tar.xz"));
2763+
/// assert_eq!(path.with_extension("").with_extension("txt"), Path::new("foo.txt"));
2764+
/// ```
2765+
///
2766+
/// Adding an extension where one did not exist:
2767+
///
2768+
/// ```
2769+
/// use std::path::Path;
2770+
///
2771+
/// let path = Path::new("foo");
2772+
/// assert_eq!(path.with_extension("rs"), Path::new("foo.rs"));
27582773
/// ```
27592774
#[stable(feature = "rust1", since = "1.0.0")]
27602775
pub fn with_extension<S: AsRef<OsStr>>(&self, extension: S) -> PathBuf {

library/std/src/sys/fs/hermit.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,10 @@ impl File {
422422
self.0.seek(pos)
423423
}
424424

425+
pub fn size(&self) -> Option<io::Result<u64>> {
426+
None
427+
}
428+
425429
pub fn tell(&self) -> io::Result<u64> {
426430
self.0.tell()
427431
}

library/std/src/sys/fs/solid.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,10 @@ impl File {
459459
self.tell()
460460
}
461461

462+
pub fn size(&self) -> Option<io::Result<u64>> {
463+
None
464+
}
465+
462466
pub fn tell(&self) -> io::Result<u64> {
463467
unsafe {
464468
let mut out_offset = MaybeUninit::uninit();

library/std/src/sys/fs/unix.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1464,6 +1464,15 @@ impl File {
14641464
Ok(n as u64)
14651465
}
14661466

1467+
pub fn size(&self) -> Option<io::Result<u64>> {
1468+
match self.file_attr().map(|attr| attr.size()) {
1469+
// Fall back to default implementation if the returned size is 0,
1470+
// we might be in a proc mount.
1471+
Ok(0) => None,
1472+
result => Some(result),
1473+
}
1474+
}
1475+
14671476
pub fn tell(&self) -> io::Result<u64> {
14681477
self.seek(SeekFrom::Current(0))
14691478
}

library/std/src/sys/fs/unsupported.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,10 @@ impl File {
259259
self.0
260260
}
261261

262+
pub fn size(&self) -> Option<io::Result<u64>> {
263+
self.0
264+
}
265+
262266
pub fn tell(&self) -> io::Result<u64> {
263267
self.0
264268
}

0 commit comments

Comments
 (0)