Skip to content

Commit 0922559

Browse files
committed
Auto merge of rust-lang#102627 - matthiaskrgr:rollup-2xtrqkw, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - rust-lang#102439 (rustdoc: re-sugar more cross-crate trait bounds) - rust-lang#102569 (Improve `FromStr` example) - rust-lang#102597 (Avoid ICE in printing RPITIT type) - rust-lang#102607 (Improve documentation of `slice::{from_ptr_range, from_ptr_range_mut}`) - rust-lang#102613 (Fix ICE rust-lang#101739) - rust-lang#102615 (Cleanup some error code explanations) - rust-lang#102617 (`HirId` for `deferred_transmute_checks`) - rust-lang#102620 (Migrate `.stab` elements style to CSS variables) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 33d3519 + d329213 commit 0922559

File tree

31 files changed

+325
-86
lines changed

31 files changed

+325
-86
lines changed

compiler/rustc_error_codes/src/error_codes/E0045.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ Variadic parameters have been used on a non-C ABI function.
33
Erroneous code example:
44

55
```compile_fail,E0045
6-
#![feature(unboxed_closures)]
7-
8-
extern "rust-call" {
6+
extern "Rust" {
97
fn foo(x: u8, ...); // error!
108
}
119
```

compiler/rustc_error_codes/src/error_codes/E0092.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ functions are defined in `compiler/rustc_codegen_llvm/src/intrinsic.rs` and in
1919
#![feature(intrinsics)]
2020
2121
extern "rust-intrinsic" {
22-
fn atomic_fence(); // ok!
22+
fn atomic_fence_seqcst(); // ok!
2323
}
2424
```

compiler/rustc_error_codes/src/error_codes/E0161.md

+2-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ A value was moved whose size was not known at compile time.
33
Erroneous code example:
44

55
```compile_fail,E0161
6-
#![feature(box_syntax)]
76
trait Bar {
87
fn f(self);
98
}
@@ -13,7 +12,7 @@ impl Bar for i32 {
1312
}
1413
1514
fn main() {
16-
let b: Box<dyn Bar> = box (0 as i32);
15+
let b: Box<dyn Bar> = Box::new(0i32);
1716
b.f();
1817
// error: cannot move a value of type dyn Bar: the size of dyn Bar cannot
1918
// be statically determined
@@ -27,8 +26,6 @@ either `&x` or `&mut x`. Since a reference has a fixed size, this lets you move
2726
it around as usual. Example:
2827

2928
```
30-
#![feature(box_syntax)]
31-
3229
trait Bar {
3330
fn f(&self);
3431
}
@@ -38,7 +35,7 @@ impl Bar for i32 {
3835
}
3936
4037
fn main() {
41-
let b: Box<dyn Bar> = box (0 as i32);
38+
let b: Box<dyn Bar> = Box::new(0i32);
4239
b.f();
4340
// ok!
4441
}

compiler/rustc_error_codes/src/error_codes/E0579.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ Erroneous code example:
88
fn main() {
99
match 5u32 {
1010
// This range is ok, albeit pointless.
11-
1 .. 2 => {}
11+
1..2 => {}
1212
// This range is empty, and the compiler can tell.
13-
5 .. 5 => {} // error!
13+
5..5 => {} // error!
1414
}
1515
}
1616
```

compiler/rustc_error_codes/src/error_codes/E0622.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Erroneous code example:
55
```compile_fail,E0622
66
#![feature(intrinsics)]
77
extern "rust-intrinsic" {
8-
pub static breakpoint : fn(); // error: intrinsic must be a function
8+
pub static breakpoint: fn(); // error: intrinsic must be a function
99
}
1010
1111
fn main() { unsafe { breakpoint(); } }

compiler/rustc_error_codes/src/error_codes/E0743.md

-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ The C-variadic type `...` has been nested inside another type.
33
Erroneous code example:
44

55
```compile_fail,E0743
6-
#![feature(c_variadic)]
7-
86
fn foo2(x: u8, y: &...) {} // error!
97
```
108

compiler/rustc_hir_analysis/src/check/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
542542
// been resolved or we errored. This is important as we can only check transmute
543543
// on concrete types, but the output type may not be known yet (it would only
544544
// be known if explicitly specified via turbofish).
545-
self.deferred_transmute_checks.borrow_mut().push((from, to, expr.span));
545+
self.deferred_transmute_checks.borrow_mut().push((from, to, expr.hir_id));
546546
}
547547
if !tcx.features().unsized_fn_params {
548548
// We want to remove some Sized bounds from std functions,

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
5050
pub(in super::super) fn check_transmutes(&self) {
5151
let mut deferred_transmute_checks = self.deferred_transmute_checks.borrow_mut();
5252
debug!("FnCtxt::check_transmutes: {} deferred checks", deferred_transmute_checks.len());
53-
for (from, to, span) in deferred_transmute_checks.drain(..) {
54-
self.check_transmute(span, from, to);
53+
for (from, to, hir_id) in deferred_transmute_checks.drain(..) {
54+
self.check_transmute(from, to, hir_id);
5555
}
5656
}
5757

compiler/rustc_hir_analysis/src/check/inherited.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ pub struct Inherited<'a, 'tcx> {
5555

5656
pub(super) deferred_cast_checks: RefCell<Vec<super::cast::CastCheck<'tcx>>>,
5757

58-
pub(super) deferred_transmute_checks: RefCell<Vec<(Ty<'tcx>, Ty<'tcx>, Span)>>,
58+
pub(super) deferred_transmute_checks: RefCell<Vec<(Ty<'tcx>, Ty<'tcx>, hir::HirId)>>,
5959

6060
pub(super) deferred_asm_checks: RefCell<Vec<(&'tcx hir::InlineAsm<'tcx>, hir::HirId)>>,
6161

compiler/rustc_hir_analysis/src/check/intrinsicck.rs

+11-8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use hir::HirId;
12
use rustc_ast::InlineAsmTemplatePiece;
23
use rustc_data_structures::fx::FxHashSet;
34
use rustc_errors::struct_span_err;
@@ -6,7 +7,7 @@ use rustc_index::vec::Idx;
67
use rustc_middle::ty::layout::{LayoutError, SizeSkeleton};
78
use rustc_middle::ty::{self, Article, FloatTy, IntTy, Ty, TyCtxt, TypeVisitable, UintTy};
89
use rustc_session::lint;
9-
use rustc_span::{Span, Symbol, DUMMY_SP};
10+
use rustc_span::{Symbol, DUMMY_SP};
1011
use rustc_target::abi::{Pointer, VariantIdx};
1112
use rustc_target::asm::{InlineAsmReg, InlineAsmRegClass, InlineAsmRegOrRegClass, InlineAsmType};
1213

@@ -40,11 +41,13 @@ fn unpack_option_like<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Ty<'tcx> {
4041
}
4142

4243
impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
43-
pub fn check_transmute(&self, span: Span, from: Ty<'tcx>, to: Ty<'tcx>) {
44+
pub fn check_transmute(&self, from: Ty<'tcx>, to: Ty<'tcx>, hir_id: HirId) {
45+
let tcx = self.tcx;
46+
let span = tcx.hir().span(hir_id);
4447
let convert = |ty: Ty<'tcx>| {
4548
let ty = self.resolve_vars_if_possible(ty);
46-
let ty = self.tcx.normalize_erasing_regions(self.param_env, ty);
47-
(SizeSkeleton::compute(ty, self.tcx, self.param_env), ty)
49+
let ty = tcx.normalize_erasing_regions(self.param_env, ty);
50+
(SizeSkeleton::compute(ty, tcx, self.param_env), ty)
4851
};
4952
let (sk_from, from) = convert(from);
5053
let (sk_to, to) = convert(to);
@@ -57,9 +60,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
5760

5861
// Special-case transmuting from `typeof(function)` and
5962
// `Option<typeof(function)>` to present a clearer error.
60-
let from = unpack_option_like(self.tcx, from);
61-
if let (&ty::FnDef(..), SizeSkeleton::Known(size_to)) = (from.kind(), sk_to) && size_to == Pointer.size(&self.tcx) {
62-
struct_span_err!(self.tcx.sess, span, E0591, "can't transmute zero-sized type")
63+
let from = unpack_option_like(tcx, from);
64+
if let (&ty::FnDef(..), SizeSkeleton::Known(size_to)) = (from.kind(), sk_to) && size_to == Pointer.size(&tcx) {
65+
struct_span_err!(tcx.sess, span, E0591, "can't transmute zero-sized type")
6366
.note(&format!("source type: {from}"))
6467
.note(&format!("target type: {to}"))
6568
.help("cast with `as` to a pointer instead")
@@ -83,7 +86,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
8386
};
8487

8588
let mut err = struct_span_err!(
86-
self.tcx.sess,
89+
tcx.sess,
8790
span,
8891
E0512,
8992
"cannot transmute between types of different sizes, \

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -927,7 +927,7 @@ pub trait PrettyPrinter<'tcx>:
927927
// unless we can find out what generator return type it comes from.
928928
let term = if let Some(ty) = term.skip_binder().ty()
929929
&& let ty::Projection(proj) = ty.kind()
930-
&& let assoc = tcx.associated_item(proj.item_def_id)
930+
&& let Some(assoc) = tcx.opt_associated_item(proj.item_def_id)
931931
&& assoc.trait_container(tcx) == tcx.lang_items().gen_trait()
932932
&& assoc.name == rustc_span::sym::Return
933933
{

compiler/rustc_trait_selection/src/traits/select/confirmation.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ use rustc_hir::lang_items::LangItem;
1111
use rustc_index::bit_set::GrowableBitSet;
1212
use rustc_infer::infer::InferOk;
1313
use rustc_infer::infer::LateBoundRegionConversionTime::HigherRankedType;
14-
use rustc_middle::ty::{self, GenericParamDefKind, Ty, TyCtxt};
15-
use rustc_middle::ty::{GenericArg, GenericArgKind, InternalSubsts, SubstsRef};
16-
use rustc_middle::ty::{ToPolyTraitRef, ToPredicate};
14+
use rustc_middle::ty::{
15+
self, GenericArg, GenericArgKind, GenericParamDefKind, InternalSubsts, SubstsRef,
16+
ToPolyTraitRef, ToPredicate, Ty, TyCtxt,
17+
};
1718
use rustc_span::def_id::DefId;
1819

1920
use crate::traits::project::{normalize_with_depth, normalize_with_depth_to};
@@ -289,8 +290,10 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
289290

290291
let scope = type_at(2).skip_binder();
291292

292-
let assume =
293-
rustc_transmute::Assume::from_const(self.infcx.tcx, obligation.param_env, const_at(3));
293+
let Some(assume) =
294+
rustc_transmute::Assume::from_const(self.infcx.tcx, obligation.param_env, const_at(3)) else {
295+
return Err(Unimplemented);
296+
};
294297

295298
let cause = obligation.cause.clone();
296299

compiler/rustc_transmute/src/lib.rs

+10-5
Original file line numberDiff line numberDiff line change
@@ -115,18 +115,23 @@ mod rustc {
115115
tcx: TyCtxt<'tcx>,
116116
param_env: ParamEnv<'tcx>,
117117
c: Const<'tcx>,
118-
) -> Self {
118+
) -> Option<Self> {
119119
use rustc_middle::ty::ScalarInt;
120120
use rustc_middle::ty::TypeVisitable;
121121
use rustc_span::symbol::sym;
122122

123123
let c = c.eval(tcx, param_env);
124124

125125
if let Some(err) = c.error_reported() {
126-
return Self { alignment: true, lifetimes: true, safety: true, validity: true };
126+
return Some(Self {
127+
alignment: true,
128+
lifetimes: true,
129+
safety: true,
130+
validity: true,
131+
});
127132
}
128133

129-
let adt_def = c.ty().ty_adt_def().expect("The given `Const` must be an ADT.");
134+
let adt_def = c.ty().ty_adt_def()?;
130135

131136
assert_eq!(
132137
tcx.require_lang_item(LangItem::TransmuteOpts, None),
@@ -148,12 +153,12 @@ mod rustc {
148153
fields[field_idx].unwrap_leaf() == ScalarInt::TRUE
149154
};
150155

151-
Self {
156+
Some(Self {
152157
alignment: get_field(sym::alignment),
153158
lifetimes: get_field(sym::lifetimes),
154159
safety: get_field(sym::safety),
155160
validity: get_field(sym::validity),
156-
}
161+
})
157162
}
158163
}
159164
}

library/core/src/slice/raw.rs

+23-1
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,10 @@ pub const fn from_mut<T>(s: &mut T) -> &mut [T] {
188188
///
189189
/// Note that a range created from [`slice::as_ptr_range`] fulfills these requirements.
190190
///
191+
/// # Panics
192+
///
193+
/// This function panics if `T` is a Zero-Sized Type (“ZST”).
194+
///
191195
/// # Caveat
192196
///
193197
/// The lifetime for the returned slice is inferred from its usage. To
@@ -219,9 +223,15 @@ pub const unsafe fn from_ptr_range<'a, T>(range: Range<*const T>) -> &'a [T] {
219223
unsafe { from_raw_parts(range.start, range.end.sub_ptr(range.start)) }
220224
}
221225

222-
/// Performs the same functionality as [`from_ptr_range`], except that a
226+
/// Forms a mutable slice from a pointer range.
227+
///
228+
/// This is the same functionality as [`from_ptr_range`], except that a
223229
/// mutable slice is returned.
224230
///
231+
/// This function is useful for interacting with foreign interfaces which
232+
/// use two pointers to refer to a range of elements in memory, as is
233+
/// common in C++.
234+
///
225235
/// # Safety
226236
///
227237
/// Behavior is undefined if any of the following conditions are violated:
@@ -247,6 +257,18 @@ pub const unsafe fn from_ptr_range<'a, T>(range: Range<*const T>) -> &'a [T] {
247257
///
248258
/// Note that a range created from [`slice::as_mut_ptr_range`] fulfills these requirements.
249259
///
260+
/// # Panics
261+
///
262+
/// This function panics if `T` is a Zero-Sized Type (“ZST”).
263+
///
264+
/// # Caveat
265+
///
266+
/// The lifetime for the returned slice is inferred from its usage. To
267+
/// prevent accidental misuse, it's suggested to tie the lifetime to whichever
268+
/// source lifetime is safe in the context, such as by providing a helper
269+
/// function taking the lifetime of a host value for the slice, or by explicit
270+
/// annotation.
271+
///
250272
/// # Examples
251273
///
252274
/// ```

library/core/src/str/traits.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -507,26 +507,28 @@ unsafe impl const SliceIndex<str> for ops::RangeToInclusive<usize> {
507507
///
508508
/// ```
509509
/// use std::str::FromStr;
510-
/// use std::num::ParseIntError;
511510
///
512511
/// #[derive(Debug, PartialEq)]
513512
/// struct Point {
514513
/// x: i32,
515514
/// y: i32
516515
/// }
517516
///
517+
/// #[derive(Debug, PartialEq, Eq)]
518+
/// struct ParsePointError;
519+
///
518520
/// impl FromStr for Point {
519-
/// type Err = ParseIntError;
521+
/// type Err = ParsePointError;
520522
///
521523
/// fn from_str(s: &str) -> Result<Self, Self::Err> {
522524
/// let (x, y) = s
523525
/// .strip_prefix('(')
524526
/// .and_then(|s| s.strip_suffix(')'))
525527
/// .and_then(|s| s.split_once(','))
526-
/// .unwrap();
528+
/// .ok_or(ParsePointError)?;
527529
///
528-
/// let x_fromstr = x.parse::<i32>()?;
529-
/// let y_fromstr = y.parse::<i32>()?;
530+
/// let x_fromstr = x.parse::<i32>().map_err(|_| ParsePointError)?;
531+
/// let y_fromstr = y.parse::<i32>().map_err(|_| ParsePointError)?;
530532
///
531533
/// Ok(Point { x: x_fromstr, y: y_fromstr })
532534
/// }
@@ -538,6 +540,8 @@ unsafe impl const SliceIndex<str> for ops::RangeToInclusive<usize> {
538540
/// // Implicit calls, through parse
539541
/// assert_eq!("(1,2)".parse(), expected);
540542
/// assert_eq!("(1,2)".parse::<Point>(), expected);
543+
/// // Invalid input string
544+
/// assert!(Point::from_str("(1 2)").is_err());
541545
/// ```
542546
#[stable(feature = "rust1", since = "1.0.0")]
543547
pub trait FromStr: Sized {

src/librustdoc/clean/mod.rs

+9
Original file line numberDiff line numberDiff line change
@@ -1176,6 +1176,15 @@ pub(crate) fn clean_middle_assoc_item<'tcx>(
11761176
}
11771177

11781178
if let ty::TraitContainer = assoc_item.container {
1179+
// FIXME(fmease): `tcx.explicit_item_bounds` does not contain the bounds of GATs,
1180+
// e.g. the bounds `Copy`, `Display` & (implicitly) `Sized` in
1181+
// `type Assoc<T: Copy> where T: Display`. This also means that we
1182+
// later incorrectly render `where T: ?Sized`.
1183+
//
1184+
// The result of `tcx.explicit_predicates_of` *does* contain them but
1185+
// it does not contain the other bounds / predicates we need.
1186+
// Either merge those two interned lists somehow or refactor
1187+
// `clean_ty_generics` to call `explicit_item_bounds` by itself.
11791188
let bounds = tcx.explicit_item_bounds(assoc_item.def_id);
11801189
let predicates = ty::GenericPredicates { parent: None, predicates: bounds };
11811190
let mut generics =

0 commit comments

Comments
 (0)