Skip to content

Commit 56a35bc

Browse files
committed
Auto merge of #102545 - matthiaskrgr:rollup-13i3tc3, r=matthiaskrgr
Rollup of 3 pull requests Successful merges: - #101675 (Improve `File::set_times` error handling) - #102500 (Remove `expr_parentheses_needed` from `ParseSess`) - #102533 (rustdoc: remove unused CSS selector `a.source`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents edadc7c + 51e2f03 commit 56a35bc

File tree

13 files changed

+59
-67
lines changed

13 files changed

+59
-67
lines changed

compiler/rustc_hir_analysis/src/check/expr.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ use rustc_middle::ty::adjustment::{Adjust, Adjustment, AllowTwoPhase};
4141
use rustc_middle::ty::error::TypeError::FieldMisMatch;
4242
use rustc_middle::ty::subst::SubstsRef;
4343
use rustc_middle::ty::{self, AdtKind, Ty, TypeVisitable};
44+
use rustc_session::errors::ExprParenthesesNeeded;
4445
use rustc_session::parse::feature_err;
4546
use rustc_span::hygiene::DesugaringKind;
4647
use rustc_span::lev_distance::find_best_match_for_name;
@@ -394,7 +395,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
394395
if let Some(sp) =
395396
tcx.sess.parse_sess.ambiguous_block_expr_parse.borrow().get(&sp)
396397
{
397-
tcx.sess.parse_sess.expr_parentheses_needed(&mut err, *sp);
398+
err.subdiagnostic(ExprParenthesesNeeded::surrounding(*sp));
398399
}
399400
err.emit();
400401
oprnd_t = tcx.ty_error();

compiler/rustc_hir_analysis/src/check/fn_ctxt/suggestions.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use rustc_infer::infer::{self, TyCtxtInferExt};
1515
use rustc_infer::traits::{self, StatementAsExpression};
1616
use rustc_middle::lint::in_external_macro;
1717
use rustc_middle::ty::{self, Binder, IsSuggestable, ToPredicate, Ty};
18+
use rustc_session::errors::ExprParenthesesNeeded;
1819
use rustc_span::symbol::sym;
1920
use rustc_span::Span;
2021
use rustc_trait_selection::infer::InferCtxtExt;
@@ -895,7 +896,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
895896
let sp = self.tcx.sess.source_map().start_point(expr.span);
896897
if let Some(sp) = self.tcx.sess.parse_sess.ambiguous_block_expr_parse.borrow().get(&sp) {
897898
// `{ 42 } &&x` (#61475) or `{ 42 } && if x { 1 } else { 0 }`
898-
self.tcx.sess.parse_sess.expr_parentheses_needed(err, *sp);
899+
err.subdiagnostic(ExprParenthesesNeeded::surrounding(*sp));
899900
}
900901
}
901902

compiler/rustc_hir_analysis/src/check/op.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use rustc_middle::ty::adjustment::{
1313
};
1414
use rustc_middle::ty::print::with_no_trimmed_paths;
1515
use rustc_middle::ty::{self, DefIdTree, Ty, TyCtxt, TypeFolder, TypeSuperFoldable, TypeVisitable};
16+
use rustc_session::errors::ExprParenthesesNeeded;
1617
use rustc_span::source_map::Spanned;
1718
use rustc_span::symbol::{sym, Ident};
1819
use rustc_span::Span;
@@ -677,7 +678,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
677678
// If the previous expression was a block expression, suggest parentheses
678679
// (turning this into a binary subtraction operation instead.)
679680
// for example, `{2} - 2` -> `({2}) - 2` (see src\test\ui\parser\expr-as-stmt.rs)
680-
self.tcx.sess.parse_sess.expr_parentheses_needed(&mut err, *sp);
681+
err.subdiagnostic(ExprParenthesesNeeded::surrounding(*sp));
681682
} else {
682683
match actual.kind() {
683684
Uint(_) if op == hir::UnOp::Neg => {

compiler/rustc_parse/src/parser/diagnostics.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ use rustc_errors::{
3333
fluent, Applicability, DiagnosticBuilder, DiagnosticMessage, Handler, MultiSpan, PResult,
3434
};
3535
use rustc_errors::{pluralize, Diagnostic, ErrorGuaranteed, IntoDiagnostic};
36+
use rustc_session::errors::ExprParenthesesNeeded;
3637
use rustc_span::source_map::Spanned;
3738
use rustc_span::symbol::{kw, sym, Ident};
3839
use rustc_span::{Span, SpanSnippetError, DUMMY_SP};
@@ -2049,7 +2050,7 @@ impl<'a> Parser<'a> {
20492050
let mut err = self.struct_span_err(span, &msg);
20502051
let sp = self.sess.source_map().start_point(self.token.span);
20512052
if let Some(sp) = self.sess.ambiguous_block_expr_parse.borrow().get(&sp) {
2052-
self.sess.expr_parentheses_needed(&mut err, *sp);
2053+
err.subdiagnostic(ExprParenthesesNeeded::surrounding(*sp));
20532054
}
20542055
err.span_label(span, "expected expression");
20552056
err

compiler/rustc_parse/src/parser/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1310,7 +1310,7 @@ impl<'a> Parser<'a> {
13101310
// If the input is something like `if a { 1 } else { 2 } | if a { 3 } else { 4 }`
13111311
// then suggest parens around the lhs.
13121312
if let Some(sp) = self.sess.ambiguous_block_expr_parse.borrow().get(&lo) {
1313-
self.sess.expr_parentheses_needed(&mut err, *sp);
1313+
err.subdiagnostic(ExprParenthesesNeeded::surrounding(*sp));
13141314
}
13151315
err
13161316
})

compiler/rustc_parse/src/parser/pat.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use rustc_ast::{
1010
};
1111
use rustc_ast_pretty::pprust;
1212
use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder, ErrorGuaranteed, PResult};
13+
use rustc_session::errors::ExprParenthesesNeeded;
1314
use rustc_span::source_map::{respan, Span, Spanned};
1415
use rustc_span::symbol::{kw, sym, Ident};
1516

@@ -693,7 +694,7 @@ impl<'a> Parser<'a> {
693694

694695
let sp = self.sess.source_map().start_point(self.token.span);
695696
if let Some(sp) = self.sess.ambiguous_block_expr_parse.borrow().get(&sp) {
696-
self.sess.expr_parentheses_needed(&mut err, *sp);
697+
err.subdiagnostic(ExprParenthesesNeeded::surrounding(*sp));
697698
}
698699

699700
Err(err)

compiler/rustc_session/src/parse.rs

+3-11
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
//! It also serves as an input to the parser itself.
33
44
use crate::config::CheckCfg;
5-
use crate::errors::{
6-
ExprParenthesesNeeded, FeatureDiagnosticForIssue, FeatureDiagnosticHelp, FeatureGateError,
7-
};
5+
use crate::errors::{FeatureDiagnosticForIssue, FeatureDiagnosticHelp, FeatureGateError};
86
use crate::lint::{
97
builtin::UNSTABLE_SYNTAX_PRE_EXPANSION, BufferedEarlyLint, BuiltinLintDiagnostics, Lint, LintId,
108
};
@@ -13,8 +11,8 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexSet};
1311
use rustc_data_structures::sync::{Lock, Lrc};
1412
use rustc_errors::{emitter::SilentEmitter, ColorConfig, Handler};
1513
use rustc_errors::{
16-
fallback_fluent_bundle, AddToDiagnostic, Diagnostic, DiagnosticBuilder, DiagnosticId,
17-
DiagnosticMessage, EmissionGuarantee, ErrorGuaranteed, IntoDiagnostic, MultiSpan, StashKey,
14+
fallback_fluent_bundle, Diagnostic, DiagnosticBuilder, DiagnosticId, DiagnosticMessage,
15+
EmissionGuarantee, ErrorGuaranteed, IntoDiagnostic, MultiSpan, StashKey,
1816
};
1917
use rustc_feature::{find_feature_issue, GateIssue, UnstableFeatures};
2018
use rustc_span::edition::Edition;
@@ -324,12 +322,6 @@ impl ParseSess {
324322
});
325323
}
326324

327-
/// Extend an error with a suggestion to wrap an expression with parentheses to allow the
328-
/// parser to continue parsing the following operation as part of the same expression.
329-
pub fn expr_parentheses_needed(&self, err: &mut Diagnostic, span: Span) {
330-
ExprParenthesesNeeded::surrounding(span).add_to_diagnostic(err);
331-
}
332-
333325
pub fn save_proc_macro_span(&self, span: Span) -> usize {
334326
let mut spans = self.proc_macro_quoted_spans.lock();
335327
spans.push(span);

library/std/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@
251251
#![feature(doc_notable_trait)]
252252
#![feature(dropck_eyepatch)]
253253
#![feature(exhaustive_patterns)]
254+
#![feature(if_let_guard)]
254255
#![feature(intra_doc_pointers)]
255256
#![feature(lang_items)]
256257
#![feature(let_chains)]

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

+21-41
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,11 @@ pub struct FilePermissions {
313313
mode: mode_t,
314314
}
315315

316-
#[derive(Copy, Clone)]
317-
pub struct FileTimes([libc::timespec; 2]);
316+
#[derive(Copy, Clone, Debug, Default)]
317+
pub struct FileTimes {
318+
accessed: Option<SystemTime>,
319+
modified: Option<SystemTime>,
320+
}
318321

319322
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
320323
pub struct FileType {
@@ -512,45 +515,11 @@ impl FilePermissions {
512515

513516
impl FileTimes {
514517
pub fn set_accessed(&mut self, t: SystemTime) {
515-
self.0[0] = t.t.to_timespec().expect("Invalid system time");
518+
self.accessed = Some(t);
516519
}
517520

518521
pub fn set_modified(&mut self, t: SystemTime) {
519-
self.0[1] = t.t.to_timespec().expect("Invalid system time");
520-
}
521-
}
522-
523-
struct TimespecDebugAdapter<'a>(&'a libc::timespec);
524-
525-
impl fmt::Debug for TimespecDebugAdapter<'_> {
526-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
527-
f.debug_struct("timespec")
528-
.field("tv_sec", &self.0.tv_sec)
529-
.field("tv_nsec", &self.0.tv_nsec)
530-
.finish()
531-
}
532-
}
533-
534-
impl fmt::Debug for FileTimes {
535-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
536-
f.debug_struct("FileTimes")
537-
.field("accessed", &TimespecDebugAdapter(&self.0[0]))
538-
.field("modified", &TimespecDebugAdapter(&self.0[1]))
539-
.finish()
540-
}
541-
}
542-
543-
impl Default for FileTimes {
544-
fn default() -> Self {
545-
// Redox doesn't appear to support `UTIME_OMIT`, so we stub it out here, and always return
546-
// an error in `set_times`.
547-
// ESP-IDF and HorizonOS do not support `futimens` at all and the behavior for those OS is therefore
548-
// the same as for Redox.
549-
#[cfg(any(target_os = "redox", target_os = "espidf", target_os = "horizon"))]
550-
let omit = libc::timespec { tv_sec: 0, tv_nsec: 0 };
551-
#[cfg(not(any(target_os = "redox", target_os = "espidf", target_os = "horizon")))]
552-
let omit = libc::timespec { tv_sec: 0, tv_nsec: libc::UTIME_OMIT as _ };
553-
Self([omit; 2])
522+
self.modified = Some(t);
554523
}
555524
}
556525

@@ -1084,6 +1053,17 @@ impl File {
10841053
}
10851054

10861055
pub fn set_times(&self, times: FileTimes) -> io::Result<()> {
1056+
#[cfg(not(any(target_os = "redox", target_os = "espidf", target_os = "horizon")))]
1057+
let to_timespec = |time: Option<SystemTime>| {
1058+
match time {
1059+
Some(time) if let Some(ts) = time.t.to_timespec() => Ok(ts),
1060+
Some(time) if time > crate::sys::time::UNIX_EPOCH => Err(io::const_io_error!(io::ErrorKind::InvalidInput, "timestamp is too large to set as a file time")),
1061+
Some(_) => Err(io::const_io_error!(io::ErrorKind::InvalidInput, "timestamp is too small to set as a file time")),
1062+
None => Ok(libc::timespec { tv_sec: 0, tv_nsec: libc::UTIME_OMIT as _ }),
1063+
}
1064+
};
1065+
#[cfg(not(any(target_os = "redox", target_os = "espidf", target_os = "horizon")))]
1066+
let times = [to_timespec(times.accessed)?, to_timespec(times.modified)?];
10871067
cfg_if::cfg_if! {
10881068
if #[cfg(any(target_os = "redox", target_os = "espidf", target_os = "horizon"))] {
10891069
// Redox doesn't appear to support `UTIME_OMIT`.
@@ -1099,7 +1079,7 @@ impl File {
10991079
cvt(unsafe {
11001080
weak!(fn futimens(c_int, *const libc::timespec) -> c_int);
11011081
match futimens.get() {
1102-
Some(futimens) => futimens(self.as_raw_fd(), times.0.as_ptr()),
1082+
Some(futimens) => futimens(self.as_raw_fd(), times.as_ptr()),
11031083
#[cfg(target_os = "macos")]
11041084
None => {
11051085
fn ts_to_tv(ts: &libc::timespec) -> libc::timeval {
@@ -1108,7 +1088,7 @@ impl File {
11081088
tv_usec: (ts.tv_nsec / 1000) as _
11091089
}
11101090
}
1111-
let timevals = [ts_to_tv(&times.0[0]), ts_to_tv(&times.0[1])];
1091+
let timevals = [ts_to_tv(&times[0]), ts_to_tv(&times[1])];
11121092
libc::futimes(self.as_raw_fd(), timevals.as_ptr())
11131093
}
11141094
// futimes requires even newer Android.
@@ -1121,7 +1101,7 @@ impl File {
11211101
})?;
11221102
Ok(())
11231103
} else {
1124-
cvt(unsafe { libc::futimens(self.as_raw_fd(), times.0.as_ptr()) })?;
1104+
cvt(unsafe { libc::futimens(self.as_raw_fd(), times.as_ptr()) })?;
11251105
Ok(())
11261106
}
11271107
}

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

+13-6
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ pub struct FilePermissions {
6565

6666
#[derive(Copy, Clone, Debug, Default)]
6767
pub struct FileTimes {
68-
accessed: Option<wasi::Timestamp>,
69-
modified: Option<wasi::Timestamp>,
68+
accessed: Option<SystemTime>,
69+
modified: Option<SystemTime>,
7070
}
7171

7272
#[derive(PartialEq, Eq, Hash, Debug, Copy, Clone)]
@@ -120,11 +120,11 @@ impl FilePermissions {
120120

121121
impl FileTimes {
122122
pub fn set_accessed(&mut self, t: SystemTime) {
123-
self.accessed = Some(t.to_wasi_timestamp_or_panic());
123+
self.accessed = Some(t);
124124
}
125125

126126
pub fn set_modified(&mut self, t: SystemTime) {
127-
self.modified = Some(t.to_wasi_timestamp_or_panic());
127+
self.modified = Some(t);
128128
}
129129
}
130130

@@ -476,9 +476,16 @@ impl File {
476476
}
477477

478478
pub fn set_times(&self, times: FileTimes) -> io::Result<()> {
479+
let to_timestamp = |time: Option<SystemTime>| {
480+
match time {
481+
Some(time) if let Some(ts) = time.to_wasi_timestamp() => Ok(ts),
482+
Some(_) => Err(io::const_io_error!(io::ErrorKind::InvalidInput, "timestamp is too large to set as a file time")),
483+
None => Ok(0),
484+
}
485+
};
479486
self.fd.filestat_set_times(
480-
times.accessed.unwrap_or(0),
481-
times.modified.unwrap_or(0),
487+
to_timestamp(times.accessed)?,
488+
to_timestamp(times.modified)?,
482489
times.accessed.map_or(0, |_| wasi::FSTFLAGS_ATIM)
483490
| times.modified.map_or(0, |_| wasi::FSTFLAGS_MTIM),
484491
)

library/std/src/sys/wasi/time.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ impl SystemTime {
4747
SystemTime(Duration::from_nanos(ts))
4848
}
4949

50-
pub fn to_wasi_timestamp_or_panic(&self) -> wasi::Timestamp {
51-
self.0.as_nanos().try_into().expect("time does not fit in WASI timestamp")
50+
pub fn to_wasi_timestamp(&self) -> Option<wasi::Timestamp> {
51+
self.0.as_nanos().try_into().ok()
5252
}
5353

5454
pub fn sub_time(&self, other: &SystemTime) -> Result<Duration, Duration> {

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

+8
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,14 @@ impl File {
572572
"Cannot set file timestamp to 0",
573573
));
574574
}
575+
let is_max =
576+
|t: c::FILETIME| t.dwLowDateTime == c::DWORD::MAX && t.dwHighDateTime == c::DWORD::MAX;
577+
if times.accessed.map_or(false, is_max) || times.modified.map_or(false, is_max) {
578+
return Err(io::const_io_error!(
579+
io::ErrorKind::InvalidInput,
580+
"Cannot set file timestamp to 0xFFFF_FFFF_FFFF_FFFF",
581+
));
582+
}
575583
cvt(unsafe {
576584
c::SetFileTime(self.as_handle(), None, times.accessed.as_ref(), times.modified.as_ref())
577585
})?;

src/librustdoc/html/static/css/rustdoc.css

-1
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,6 @@ h4.code-header {
201201
h1, h2, h3, h4, h5, h6,
202202
.sidebar,
203203
.mobile-topbar,
204-
a.source,
205204
.search-input,
206205
.search-results .result-name,
207206
.item-left > a,

0 commit comments

Comments
 (0)