Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 7cfd7d3

Browse files
committed
Auto merge of #147003 - matthiaskrgr:rollup-b5z9uiz, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - #146556 (Fix duration_since panic on unix when std is built with integer overflow checks) - #146679 (Clarify Display for error should not include source) - #146753 (Improve the pretty print of UnstableFeature clause) - #146894 (Improve derive suggestion of const param) - #146950 (core: simplify `CStr::default()`) - #146958 (Fix infinite recursion in Path::eq with String) - #146971 (fix ICE in writeback due to bound regions) r? `@ghost` `@rustbot` modify labels: rollup
2 parents bbcbc78 + 57ee169 commit 7cfd7d3

File tree

22 files changed

+108
-86
lines changed

22 files changed

+108
-86
lines changed

‎compiler/rustc_hir_typeck/src/writeback.rs‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,8 +1003,10 @@ impl<'cx, 'tcx> TypeFolder<TyCtxt<'tcx>> for Resolver<'cx, 'tcx> {
10031003
}
10041004

10051005
fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
1006-
debug_assert!(!r.is_bound(), "Should not be resolving bound region.");
1007-
self.fcx.tcx.lifetimes.re_erased
1006+
match r.kind() {
1007+
ty::ReBound(..) => r,
1008+
_ => self.fcx.tcx.lifetimes.re_erased,
1009+
}
10081010
}
10091011

10101012
fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {

‎compiler/rustc_middle/src/ty/print/pretty.rs‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3177,8 +3177,7 @@ define_print! {
31773177
write!(p, "` can be evaluated")?;
31783178
}
31793179
ty::ClauseKind::UnstableFeature(symbol) => {
3180-
write!(p, "unstable feature: ")?;
3181-
write!(p, "`{symbol}`")?;
3180+
write!(p, "feature({symbol}) is enabled")?;
31823181
}
31833182
}
31843183
}

‎compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1305,17 +1305,20 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
13051305
{
13061306
if ty.is_structural_eq_shallow(self.tcx) {
13071307
diag.span_suggestion(
1308-
span,
1309-
"add `#[derive(ConstParamTy)]` to the struct",
1308+
span.shrink_to_lo(),
1309+
format!("add `#[derive(ConstParamTy)]` to the {}", def.descr()),
13101310
"#[derive(ConstParamTy)]\n",
13111311
Applicability::MachineApplicable,
13121312
);
13131313
} else {
13141314
// FIXME(adt_const_params): We should check there's not already an
13151315
// overlapping `Eq`/`PartialEq` impl.
13161316
diag.span_suggestion(
1317-
span,
1318-
"add `#[derive(ConstParamTy, PartialEq, Eq)]` to the struct",
1317+
span.shrink_to_lo(),
1318+
format!(
1319+
"add `#[derive(ConstParamTy, PartialEq, Eq)]` to the {}",
1320+
def.descr()
1321+
),
13191322
"#[derive(ConstParamTy, PartialEq, Eq)]\n",
13201323
Applicability::MachineApplicable,
13211324
);

‎compiler/rustc_trait_selection/src/traits/query/type_op/custom.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,9 @@ where
100100
} else if let Err(guar) = infcx.tcx.check_potentially_region_dependent_goals(root_def_id) {
101101
Err(guar)
102102
} else {
103-
Err(infcx
104-
.dcx()
105-
.delayed_bug(format!("errors selecting obligation during MIR typeck: {errors:?}")))
103+
Err(infcx.dcx().delayed_bug(format!(
104+
"errors selecting obligation during MIR typeck: {name} {root_def_id:?} {errors:?}"
105+
)))
106106
}
107107
})?;
108108

‎library/alloc/src/ffi/c_str.rs‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -970,17 +970,14 @@ impl Default for Rc<CStr> {
970970
/// This may or may not share an allocation with other Rcs on the same thread.
971971
#[inline]
972972
fn default() -> Self {
973-
let rc = Rc::<[u8]>::from(*b"0円");
974-
// `[u8]` has the same layout as `CStr`, and it is `NUL` terminated.
975-
unsafe { Rc::from_raw(Rc::into_raw(rc) as *const CStr) }
973+
Rc::from(c"")
976974
}
977975
}
978976

979977
#[stable(feature = "default_box_extra", since = "1.17.0")]
980978
impl Default for Box<CStr> {
981979
fn default() -> Box<CStr> {
982-
let boxed: Box<[u8]> = Box::from([0]);
983-
unsafe { Box::from_raw(Box::into_raw(boxed) as *mut CStr) }
980+
Box::from(c"")
984981
}
985982
}
986983

‎library/core/src/error.rs‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,19 @@ use crate::fmt::{self, Debug, Display, Formatter};
1616
/// assert_eq!(err.to_string(), "invalid digit found in string");
1717
/// ```
1818
///
19+
/// # Error source
20+
///
1921
/// Errors may provide cause information. [`Error::source()`] is generally
2022
/// used when errors cross "abstraction boundaries". If one module must report
2123
/// an error that is caused by an error from a lower-level module, it can allow
22-
/// accessing that error via [`Error::source()`]. This makes it possible for the
24+
/// accessing that error via `Error::source()`. This makes it possible for the
2325
/// high-level module to provide its own errors while also revealing some of the
2426
/// implementation for debugging.
2527
///
28+
/// In error types that wrap an underlying error, the underlying error
29+
/// should be either returned by the outer error's `Error::source()`, or rendered
30+
/// by the outer error's `Display` implementation, but not both.
31+
///
2632
/// # Example
2733
///
2834
/// Implementing the `Error` trait only requires that `Debug` and `Display` are implemented too.

‎library/core/src/ffi/c_str.rs‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,7 @@ impl fmt::Debug for CStr {
179179
impl Default for &CStr {
180180
#[inline]
181181
fn default() -> Self {
182-
const SLICE: &[c_char] = &[0];
183-
// SAFETY: `SLICE` is indeed pointing to a valid nul-terminated string.
184-
unsafe { CStr::from_ptr(SLICE.as_ptr()) }
182+
c""
185183
}
186184
}
187185

‎library/std/src/path.rs‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2107,31 +2107,31 @@ impl PartialEq for PathBuf {
21072107
impl cmp::PartialEq<str> for PathBuf {
21082108
#[inline]
21092109
fn eq(&self, other: &str) -> bool {
2110-
Path::eq(self,other)
2110+
self.as_path() == other
21112111
}
21122112
}
21132113

21142114
#[stable(feature = "eq_str_for_path", since = "CURRENT_RUSTC_VERSION")]
21152115
impl cmp::PartialEq<PathBuf> for str {
21162116
#[inline]
21172117
fn eq(&self, other: &PathBuf) -> bool {
2118-
other == self
2118+
self == other.as_path()
21192119
}
21202120
}
21212121

21222122
#[stable(feature = "eq_str_for_path", since = "CURRENT_RUSTC_VERSION")]
21232123
impl cmp::PartialEq<String> for PathBuf {
21242124
#[inline]
21252125
fn eq(&self, other: &String) -> bool {
2126-
**self == **other
2126+
self.as_path() == other.as_str()
21272127
}
21282128
}
21292129

21302130
#[stable(feature = "eq_str_for_path", since = "CURRENT_RUSTC_VERSION")]
21312131
impl cmp::PartialEq<PathBuf> for String {
21322132
#[inline]
21332133
fn eq(&self, other: &PathBuf) -> bool {
2134-
other == self
2134+
self.as_str() == other.as_path()
21352135
}
21362136
}
21372137

@@ -3426,15 +3426,15 @@ impl cmp::PartialEq<Path> for str {
34263426
impl cmp::PartialEq<String> for Path {
34273427
#[inline]
34283428
fn eq(&self, other: &String) -> bool {
3429-
self == &*other
3429+
self == other.as_str()
34303430
}
34313431
}
34323432

34333433
#[stable(feature = "eq_str_for_path", since = "CURRENT_RUSTC_VERSION")]
34343434
impl cmp::PartialEq<Path> for String {
34353435
#[inline]
34363436
fn eq(&self, other: &Path) -> bool {
3437-
other == self
3437+
self.as_str() == other
34383438
}
34393439
}
34403440

‎library/std/src/sys/pal/hermit/time.rs‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,22 @@ impl Timespec {
2626
}
2727

2828
fn sub_timespec(&self, other: &Timespec) -> Result<Duration, Duration> {
29+
fn sub_ge_to_unsigned(a: i64, b: i64) -> u64 {
30+
debug_assert!(a >= b);
31+
a.wrapping_sub(b).cast_unsigned()
32+
}
33+
2934
if self >= other {
35+
// Logic here is identical to Unix version of `Timestamp::sub_timespec`,
36+
// check comments there why operations do not overflow.
3037
Ok(if self.t.tv_nsec >= other.t.tv_nsec {
3138
Duration::new(
32-
(self.t.tv_sec - other.t.tv_sec)asu64,
39+
sub_ge_to_unsigned(self.t.tv_sec,other.t.tv_sec),
3340
(self.t.tv_nsec - other.t.tv_nsec) as u32,
3441
)
3542
} else {
3643
Duration::new(
37-
(self.t.tv_sec - 1 - other.t.tv_sec)asu64,
44+
sub_ge_to_unsigned(self.t.tv_sec - 1,other.t.tv_sec),
3845
(self.t.tv_nsec + NSEC_PER_SEC - other.t.tv_nsec) as u32,
3946
)
4047
})

‎library/std/src/sys/pal/unix/time.rs‎

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -134,28 +134,25 @@ impl Timespec {
134134
}
135135

136136
pub fn sub_timespec(&self, other: &Timespec) -> Result<Duration, Duration> {
137+
// When a >= b, the difference fits in u64.
138+
fn sub_ge_to_unsigned(a: i64, b: i64) -> u64 {
139+
debug_assert!(a >= b);
140+
a.wrapping_sub(b).cast_unsigned()
141+
}
142+
137143
if self >= other {
138-
// NOTE(eddyb) two aspects of this `if`-`else` are required for LLVM
139-
// to optimize it into a branchless form (see also #75545):
140-
//
141-
// 1. `self.tv_sec - other.tv_sec` shows up as a common expression
142-
// in both branches, i.e. the `else` must have its `- 1`
143-
// subtraction after the common one, not interleaved with it
144-
// (it used to be `self.tv_sec - 1 - other.tv_sec`)
145-
//
146-
// 2. the `Duration::new` call (or any other additional complexity)
147-
// is outside of the `if`-`else`, not duplicated in both branches
148-
//
149-
// Ideally this code could be rearranged such that it more
150-
// directly expresses the lower-cost behavior we want from it.
151144
let (secs, nsec) = if self.tv_nsec.as_inner() >= other.tv_nsec.as_inner() {
152145
(
153-
(self.tv_sec - other.tv_sec)asu64,
146+
sub_ge_to_unsigned(self.tv_sec,other.tv_sec),
154147
self.tv_nsec.as_inner() - other.tv_nsec.as_inner(),
155148
)
156149
} else {
150+
// Following sequence of assertions explain why `self.tv_sec - 1` does not underflow.
151+
debug_assert!(self.tv_nsec < other.tv_nsec);
152+
debug_assert!(self.tv_sec > other.tv_sec);
153+
debug_assert!(self.tv_sec > i64::MIN);
157154
(
158-
(self.tv_sec - other.tv_sec - 1)asu64,
155+
sub_ge_to_unsigned(self.tv_sec - 1,other.tv_sec),
159156
self.tv_nsec.as_inner() + (NSEC_PER_SEC as u32) - other.tv_nsec.as_inner(),
160157
)
161158
};

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /