Skip to content

Rollup of 8 pull requests #102627

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Oct 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
9c7c232
Improve `FromStr` example
eduardosm Oct 2, 2022
90a8d67
Avoid ICE in printing RPITIT type
compiler-errors Oct 2, 2022
bc1216e
Document when `slice::from_ptr_range[_mut]` panic
WaffleLapkin Oct 3, 2022
2cd5faf
Sync docs of `slice::{from_ptr_range, from_ptr_range_mut}`
WaffleLapkin Oct 3, 2022
a540234
rustdoc: re-sugar more cross-crate trait bounds
fmease Sep 28, 2022
82510b9
return when obligation has references_error
TaKO8Ki Oct 3, 2022
b8b30ae
add a ui test for #101739
TaKO8Ki Oct 3, 2022
1df0a18
Cleanup some error code explanations
Noratrieb Oct 3, 2022
0e615ca
check if const is ADT or not
TaKO8Ki Oct 3, 2022
550715d
`HirId` for `deferred_transmute_checks`
lcnr Oct 3, 2022
c0c7597
Migrate stab elements style to CSS variables
GuillaumeGomez Oct 3, 2022
2e7e17a
Rollup merge of #102439 - fmease:rustdoc-simplify-cross-crate-trait-b…
matthiaskrgr Oct 3, 2022
cdd0ba8
Rollup merge of #102569 - eduardosm:from_str-example, r=joshtriplett
matthiaskrgr Oct 3, 2022
8ede234
Rollup merge of #102597 - compiler-errors:issue-102571, r=davidtwco
matthiaskrgr Oct 3, 2022
3374a7d
Rollup merge of #102607 - WaffleLapkin:docky_docky_slice_from_ptr_ran…
matthiaskrgr Oct 3, 2022
aa076d6
Rollup merge of #102613 - TaKO8Ki:fix-part-of-101739, r=compiler-errors
matthiaskrgr Oct 3, 2022
e64177c
Rollup merge of #102615 - Nilstrieb:there-are-many-error-codes, r=com…
matthiaskrgr Oct 3, 2022
f50b72f
Rollup merge of #102617 - lcnr:deferred_transmute_checks, r=compiler-…
matthiaskrgr Oct 3, 2022
d329213
Rollup merge of #102620 - GuillaumeGomez:css-stab-migration, r=notriddle
matthiaskrgr Oct 3, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions compiler/rustc_error_codes/src/error_codes/E0045.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ Variadic parameters have been used on a non-C ABI function.
Erroneous code example:

```compile_fail,E0045
#![feature(unboxed_closures)]

extern "rust-call" {
extern "Rust" {
fn foo(x: u8, ...); // error!
}
```
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_error_codes/src/error_codes/E0092.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ functions are defined in `compiler/rustc_codegen_llvm/src/intrinsic.rs` and in
#![feature(intrinsics)]

extern "rust-intrinsic" {
fn atomic_fence(); // ok!
fn atomic_fence_seqcst(); // ok!
}
```
7 changes: 2 additions & 5 deletions compiler/rustc_error_codes/src/error_codes/E0161.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ A value was moved whose size was not known at compile time.
Erroneous code example:

```compile_fail,E0161
#![feature(box_syntax)]
trait Bar {
fn f(self);
}
Expand All @@ -13,7 +12,7 @@ impl Bar for i32 {
}

fn main() {
let b: Box<dyn Bar> = box (0 as i32);
let b: Box<dyn Bar> = Box::new(0i32);
b.f();
// error: cannot move a value of type dyn Bar: the size of dyn Bar cannot
// be statically determined
Expand All @@ -27,8 +26,6 @@ either `&x` or `&mut x`. Since a reference has a fixed size, this lets you move
it around as usual. Example:

```
#![feature(box_syntax)]

trait Bar {
fn f(&self);
}
Expand All @@ -38,7 +35,7 @@ impl Bar for i32 {
}

fn main() {
let b: Box<dyn Bar> = box (0 as i32);
let b: Box<dyn Bar> = Box::new(0i32);
b.f();
// ok!
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_error_codes/src/error_codes/E0579.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ Erroneous code example:
fn main() {
match 5u32 {
// This range is ok, albeit pointless.
1 .. 2 => {}
1..2 => {}
// This range is empty, and the compiler can tell.
5 .. 5 => {} // error!
5..5 => {} // error!
}
}
```
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_error_codes/src/error_codes/E0622.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Erroneous code example:
```compile_fail,E0622
#![feature(intrinsics)]
extern "rust-intrinsic" {
pub static breakpoint : fn(); // error: intrinsic must be a function
pub static breakpoint: fn(); // error: intrinsic must be a function
}

fn main() { unsafe { breakpoint(); } }
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_error_codes/src/error_codes/E0743.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ The C-variadic type `...` has been nested inside another type.
Erroneous code example:

```compile_fail,E0743
#![feature(c_variadic)]

fn foo2(x: u8, y: &...) {} // error!
```

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/check/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// been resolved or we errored. This is important as we can only check transmute
// on concrete types, but the output type may not be known yet (it would only
// be known if explicitly specified via turbofish).
self.deferred_transmute_checks.borrow_mut().push((from, to, expr.span));
self.deferred_transmute_checks.borrow_mut().push((from, to, expr.hir_id));
}
if !tcx.features().unsized_fn_params {
// We want to remove some Sized bounds from std functions,
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir_analysis/src/check/fn_ctxt/checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
pub(in super::super) fn check_transmutes(&self) {
let mut deferred_transmute_checks = self.deferred_transmute_checks.borrow_mut();
debug!("FnCtxt::check_transmutes: {} deferred checks", deferred_transmute_checks.len());
for (from, to, span) in deferred_transmute_checks.drain(..) {
self.check_transmute(span, from, to);
for (from, to, hir_id) in deferred_transmute_checks.drain(..) {
self.check_transmute(from, to, hir_id);
}
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/check/inherited.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub struct Inherited<'a, 'tcx> {

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

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

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

Expand Down
19 changes: 11 additions & 8 deletions compiler/rustc_hir_analysis/src/check/intrinsicck.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use hir::HirId;
use rustc_ast::InlineAsmTemplatePiece;
use rustc_data_structures::fx::FxHashSet;
use rustc_errors::struct_span_err;
Expand All @@ -6,7 +7,7 @@ use rustc_index::vec::Idx;
use rustc_middle::ty::layout::{LayoutError, SizeSkeleton};
use rustc_middle::ty::{self, Article, FloatTy, IntTy, Ty, TyCtxt, TypeVisitable, UintTy};
use rustc_session::lint;
use rustc_span::{Span, Symbol, DUMMY_SP};
use rustc_span::{Symbol, DUMMY_SP};
use rustc_target::abi::{Pointer, VariantIdx};
use rustc_target::asm::{InlineAsmReg, InlineAsmRegClass, InlineAsmRegOrRegClass, InlineAsmType};

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

impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
pub fn check_transmute(&self, span: Span, from: Ty<'tcx>, to: Ty<'tcx>) {
pub fn check_transmute(&self, from: Ty<'tcx>, to: Ty<'tcx>, hir_id: HirId) {
let tcx = self.tcx;
let span = tcx.hir().span(hir_id);
let convert = |ty: Ty<'tcx>| {
let ty = self.resolve_vars_if_possible(ty);
let ty = self.tcx.normalize_erasing_regions(self.param_env, ty);
(SizeSkeleton::compute(ty, self.tcx, self.param_env), ty)
let ty = tcx.normalize_erasing_regions(self.param_env, ty);
(SizeSkeleton::compute(ty, tcx, self.param_env), ty)
};
let (sk_from, from) = convert(from);
let (sk_to, to) = convert(to);
Expand All @@ -57,9 +60,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

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

let mut err = struct_span_err!(
self.tcx.sess,
tcx.sess,
span,
E0512,
"cannot transmute between types of different sizes, \
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/print/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -927,7 +927,7 @@ pub trait PrettyPrinter<'tcx>:
// unless we can find out what generator return type it comes from.
let term = if let Some(ty) = term.skip_binder().ty()
&& let ty::Projection(proj) = ty.kind()
&& let assoc = tcx.associated_item(proj.item_def_id)
&& let Some(assoc) = tcx.opt_associated_item(proj.item_def_id)
&& assoc.trait_container(tcx) == tcx.lang_items().gen_trait()
&& assoc.name == rustc_span::sym::Return
{
Expand Down
13 changes: 8 additions & 5 deletions compiler/rustc_trait_selection/src/traits/select/confirmation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ use rustc_hir::lang_items::LangItem;
use rustc_index::bit_set::GrowableBitSet;
use rustc_infer::infer::InferOk;
use rustc_infer::infer::LateBoundRegionConversionTime::HigherRankedType;
use rustc_middle::ty::{self, GenericParamDefKind, Ty, TyCtxt};
use rustc_middle::ty::{GenericArg, GenericArgKind, InternalSubsts, SubstsRef};
use rustc_middle::ty::{ToPolyTraitRef, ToPredicate};
use rustc_middle::ty::{
self, GenericArg, GenericArgKind, GenericParamDefKind, InternalSubsts, SubstsRef,
ToPolyTraitRef, ToPredicate, Ty, TyCtxt,
};
use rustc_span::def_id::DefId;

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

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

let assume =
rustc_transmute::Assume::from_const(self.infcx.tcx, obligation.param_env, const_at(3));
let Some(assume) =
rustc_transmute::Assume::from_const(self.infcx.tcx, obligation.param_env, const_at(3)) else {
return Err(Unimplemented);
};

let cause = obligation.cause.clone();

Expand Down
15 changes: 10 additions & 5 deletions compiler/rustc_transmute/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,18 +115,23 @@ mod rustc {
tcx: TyCtxt<'tcx>,
param_env: ParamEnv<'tcx>,
c: Const<'tcx>,
) -> Self {
) -> Option<Self> {
use rustc_middle::ty::ScalarInt;
use rustc_middle::ty::TypeVisitable;
use rustc_span::symbol::sym;

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

if let Some(err) = c.error_reported() {
return Self { alignment: true, lifetimes: true, safety: true, validity: true };
return Some(Self {
alignment: true,
lifetimes: true,
safety: true,
validity: true,
});
}

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

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

Self {
Some(Self {
alignment: get_field(sym::alignment),
lifetimes: get_field(sym::lifetimes),
safety: get_field(sym::safety),
validity: get_field(sym::validity),
}
})
}
}
}
Expand Down
24 changes: 23 additions & 1 deletion library/core/src/slice/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,10 @@ pub const fn from_mut<T>(s: &mut T) -> &mut [T] {
///
/// Note that a range created from [`slice::as_ptr_range`] fulfills these requirements.
///
/// # Panics
///
/// This function panics if `T` is a Zero-Sized Type (“ZST”).
///
/// # Caveat
///
/// The lifetime for the returned slice is inferred from its usage. To
Expand Down Expand Up @@ -219,9 +223,15 @@ pub const unsafe fn from_ptr_range<'a, T>(range: Range<*const T>) -> &'a [T] {
unsafe { from_raw_parts(range.start, range.end.sub_ptr(range.start)) }
}

/// Performs the same functionality as [`from_ptr_range`], except that a
/// Forms a mutable slice from a pointer range.
///
/// This is the same functionality as [`from_ptr_range`], except that a
/// mutable slice is returned.
///
/// This function is useful for interacting with foreign interfaces which
/// use two pointers to refer to a range of elements in memory, as is
/// common in C++.
///
/// # Safety
///
/// Behavior is undefined if any of the following conditions are violated:
Expand All @@ -247,6 +257,18 @@ pub const unsafe fn from_ptr_range<'a, T>(range: Range<*const T>) -> &'a [T] {
///
/// Note that a range created from [`slice::as_mut_ptr_range`] fulfills these requirements.
///
/// # Panics
///
/// This function panics if `T` is a Zero-Sized Type (“ZST”).
///
/// # Caveat
///
/// The lifetime for the returned slice is inferred from its usage. To
/// prevent accidental misuse, it's suggested to tie the lifetime to whichever
/// source lifetime is safe in the context, such as by providing a helper
/// function taking the lifetime of a host value for the slice, or by explicit
/// annotation.
///
/// # Examples
///
/// ```
Expand Down
14 changes: 9 additions & 5 deletions library/core/src/str/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -507,26 +507,28 @@ unsafe impl const SliceIndex<str> for ops::RangeToInclusive<usize> {
///
/// ```
/// use std::str::FromStr;
/// use std::num::ParseIntError;
///
/// #[derive(Debug, PartialEq)]
/// struct Point {
/// x: i32,
/// y: i32
/// }
///
/// #[derive(Debug, PartialEq, Eq)]
/// struct ParsePointError;
///
/// impl FromStr for Point {
/// type Err = ParseIntError;
/// type Err = ParsePointError;
///
/// fn from_str(s: &str) -> Result<Self, Self::Err> {
/// let (x, y) = s
/// .strip_prefix('(')
/// .and_then(|s| s.strip_suffix(')'))
/// .and_then(|s| s.split_once(','))
/// .unwrap();
/// .ok_or(ParsePointError)?;
///
/// let x_fromstr = x.parse::<i32>()?;
/// let y_fromstr = y.parse::<i32>()?;
/// let x_fromstr = x.parse::<i32>().map_err(|_| ParsePointError)?;
/// let y_fromstr = y.parse::<i32>().map_err(|_| ParsePointError)?;
///
/// Ok(Point { x: x_fromstr, y: y_fromstr })
/// }
Expand All @@ -538,6 +540,8 @@ unsafe impl const SliceIndex<str> for ops::RangeToInclusive<usize> {
/// // Implicit calls, through parse
/// assert_eq!("(1,2)".parse(), expected);
/// assert_eq!("(1,2)".parse::<Point>(), expected);
/// // Invalid input string
/// assert!(Point::from_str("(1 2)").is_err());
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub trait FromStr: Sized {
Expand Down
9 changes: 9 additions & 0 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1176,6 +1176,15 @@ pub(crate) fn clean_middle_assoc_item<'tcx>(
}

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