Skip to content
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

Rollup of 8 pull requests #102627

Merged
merged 19 commits into from
Oct 3, 2022
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
HirId for deferred_transmute_checks
lcnr committed Oct 3, 2022
commit 550715d74da9de33dfb29a02148750fff9b46f49
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/check/expr.rs
Original file line number Diff line number Diff line change
@@ -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,
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
@@ -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);
}
}

2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/check/inherited.rs
Original file line number Diff line number Diff line change
@@ -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)>>,

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;
@@ -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};

@@ -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);
@@ -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")
@@ -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, \