Skip to content

Commit 4b9063c

Browse files
committed
Auto merge of #145831 - jhpratt:rollup-32kaj7j, r=jhpratt
Rollup of 6 pull requests Successful merges: - #135761 (Dial down detail of B-tree description) - #144373 (remove deprecated Error::description in impls) - #145620 (Account for impossible bounds making seemingly unsatisfyable dyn-to-dyn casts) - #145783 (add span to struct pattern rest (..)) - #145817 (cg_llvm: Replace the `llvm::Bool` typedef with a proper newtype) - #145820 (raw-dylib-elf: set correct `DT_VERDEFNUM`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 809200e + 92bf516 commit 4b9063c

File tree

76 files changed

+371
-571
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+371
-571
lines changed

compiler/rustc_ast/src/ast.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -937,7 +937,7 @@ pub enum PatKind {
937937
#[derive(Clone, Copy, Encodable, Decodable, Debug, PartialEq, Walkable)]
938938
pub enum PatFieldsRest {
939939
/// `module::StructName { field, ..}`
940-
Rest,
940+
Rest(Span),
941941
/// `module::StructName { field, syntax error }`
942942
Recovered(ErrorGuaranteed),
943943
/// `module::StructName { field }`
@@ -4051,8 +4051,8 @@ mod size_asserts {
40514051
static_assert_size!(Local, 96);
40524052
static_assert_size!(MetaItemLit, 40);
40534053
static_assert_size!(Param, 40);
4054-
static_assert_size!(Pat, 72);
4055-
static_assert_size!(PatKind, 48);
4054+
static_assert_size!(Pat, 80);
4055+
static_assert_size!(PatKind, 56);
40564056
static_assert_size!(Path, 24);
40574057
static_assert_size!(PathSegment, 24);
40584058
static_assert_size!(Stmt, 32);

compiler/rustc_ast_lowering/src/expr.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1434,10 +1434,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
14341434
self.dcx().emit_err(FunctionalRecordUpdateDestructuringAssignment {
14351435
span: e.span,
14361436
});
1437-
true
1437+
Some(self.lower_span(e.span))
14381438
}
1439-
StructRest::Rest(_) => true,
1440-
StructRest::None => false,
1439+
StructRest::Rest(span) => Some(self.lower_span(*span)),
1440+
StructRest::None => None,
14411441
};
14421442
let struct_pat = hir::PatKind::Struct(qpath, field_pats, fields_omitted);
14431443
return self.pat_without_dbm(lhs.span, struct_pat);

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2508,7 +2508,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
25082508
fields: &'hir [hir::PatField<'hir>],
25092509
) -> &'hir hir::Pat<'hir> {
25102510
let qpath = hir::QPath::LangItem(lang_item, self.lower_span(span));
2511-
self.pat(span, hir::PatKind::Struct(qpath, fields, false))
2511+
self.pat(span, hir::PatKind::Struct(qpath, fields, None))
25122512
}
25132513

25142514
fn pat_ident(&mut self, span: Span, ident: Ident) -> (&'hir hir::Pat<'hir>, HirId) {

compiler/rustc_ast_lowering/src/pat.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
106106
break hir::PatKind::Struct(
107107
qpath,
108108
fs,
109-
matches!(
110-
etc,
111-
ast::PatFieldsRest::Rest | ast::PatFieldsRest::Recovered(_)
112-
),
109+
match etc {
110+
ast::PatFieldsRest::Rest(sp) => Some(self.lower_span(*sp)),
111+
ast::PatFieldsRest::Recovered(_) => Some(Span::default()),
112+
_ => None,
113+
},
113114
);
114115
}
115116
PatKind::Tuple(pats) => {

compiler/rustc_ast_pretty/src/pprust/state.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1769,7 +1769,7 @@ impl<'a> State<'a> {
17691769
},
17701770
|f| f.pat.span,
17711771
);
1772-
if let ast::PatFieldsRest::Rest | ast::PatFieldsRest::Recovered(_) = etc {
1772+
if let ast::PatFieldsRest::Rest(_) | ast::PatFieldsRest::Recovered(_) = etc {
17731773
if !fields.is_empty() {
17741774
self.word_space(",");
17751775
}

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 74 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ use rustc_mir_dataflow::points::DenseLocationMap;
3434
use rustc_span::def_id::CRATE_DEF_ID;
3535
use rustc_span::source_map::Spanned;
3636
use rustc_span::{Span, sym};
37+
use rustc_trait_selection::infer::InferCtxtExt;
3738
use rustc_trait_selection::traits::query::type_op::custom::scrape_region_constraints;
3839
use rustc_trait_selection::traits::query::type_op::{TypeOp, TypeOpOutput};
3940
use tracing::{debug, instrument, trace};
@@ -1454,68 +1455,79 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
14541455
}
14551456
CastKind::PtrToPtr => {
14561457
let ty_from = op.ty(self.body, tcx);
1457-
let cast_ty_from = CastTy::from_ty(ty_from);
1458-
let cast_ty_to = CastTy::from_ty(*ty);
1459-
match (cast_ty_from, cast_ty_to) {
1460-
(Some(CastTy::Ptr(src)), Some(CastTy::Ptr(dst))) => {
1461-
let src_tail = self.struct_tail(src.ty, location);
1462-
let dst_tail = self.struct_tail(dst.ty, location);
1463-
1464-
// This checks (lifetime part of) vtable validity for pointer casts,
1465-
// which is irrelevant when there are aren't principal traits on
1466-
// both sides (aka only auto traits).
1467-
//
1468-
// Note that other checks (such as denying `dyn Send` -> `dyn
1469-
// Debug`) are in `rustc_hir_typeck`.
1470-
if let ty::Dynamic(src_tty, _src_lt, ty::Dyn) = *src_tail.kind()
1471-
&& let ty::Dynamic(dst_tty, dst_lt, ty::Dyn) = *dst_tail.kind()
1472-
&& src_tty.principal().is_some()
1473-
&& dst_tty.principal().is_some()
1474-
{
1475-
// Remove auto traits.
1476-
// Auto trait checks are handled in `rustc_hir_typeck` as FCW.
1477-
let src_obj = Ty::new_dynamic(
1478-
tcx,
1479-
tcx.mk_poly_existential_predicates(
1480-
&src_tty.without_auto_traits().collect::<Vec<_>>(),
1481-
),
1482-
// FIXME: Once we disallow casting `*const dyn Trait + 'short`
1483-
// to `*const dyn Trait + 'long`, then this can just be `src_lt`.
1484-
dst_lt,
1485-
ty::Dyn,
1486-
);
1487-
let dst_obj = Ty::new_dynamic(
1488-
tcx,
1489-
tcx.mk_poly_existential_predicates(
1490-
&dst_tty.without_auto_traits().collect::<Vec<_>>(),
1491-
),
1492-
dst_lt,
1493-
ty::Dyn,
1494-
);
1495-
1496-
debug!(?src_tty, ?dst_tty, ?src_obj, ?dst_obj);
1497-
1498-
self.sub_types(
1499-
src_obj,
1500-
dst_obj,
1501-
location.to_locations(),
1502-
ConstraintCategory::Cast {
1503-
is_implicit_coercion: false,
1504-
unsize_to: None,
1505-
},
1506-
)
1507-
.unwrap();
1508-
}
1509-
}
1510-
_ => {
1511-
span_mirbug!(
1512-
self,
1513-
rvalue,
1514-
"Invalid PtrToPtr cast {:?} -> {:?}",
1515-
ty_from,
1516-
ty
1517-
)
1518-
}
1458+
let Some(CastTy::Ptr(src)) = CastTy::from_ty(ty_from) else {
1459+
unreachable!();
1460+
};
1461+
let Some(CastTy::Ptr(dst)) = CastTy::from_ty(*ty) else {
1462+
unreachable!();
1463+
};
1464+
1465+
if self.infcx.type_is_sized_modulo_regions(self.infcx.param_env, dst.ty) {
1466+
// Wide to thin ptr cast. This may even occur in an env with
1467+
// impossible predicates, such as `where dyn Trait: Sized`.
1468+
// In this case, we don't want to fall into the case below,
1469+
// since the types may not actually be equatable, but it's
1470+
// fine to perform this operation in an impossible env.
1471+
let trait_ref = ty::TraitRef::new(
1472+
tcx,
1473+
tcx.require_lang_item(LangItem::Sized, self.last_span),
1474+
[dst.ty],
1475+
);
1476+
self.prove_trait_ref(
1477+
trait_ref,
1478+
location.to_locations(),
1479+
ConstraintCategory::Cast {
1480+
is_implicit_coercion: true,
1481+
unsize_to: None,
1482+
},
1483+
);
1484+
} else if let ty::Dynamic(src_tty, _src_lt, ty::Dyn) =
1485+
*self.struct_tail(src.ty, location).kind()
1486+
&& let ty::Dynamic(dst_tty, dst_lt, ty::Dyn) =
1487+
*self.struct_tail(dst.ty, location).kind()
1488+
&& src_tty.principal().is_some()
1489+
&& dst_tty.principal().is_some()
1490+
{
1491+
// This checks (lifetime part of) vtable validity for pointer casts,
1492+
// which is irrelevant when there are aren't principal traits on
1493+
// both sides (aka only auto traits).
1494+
//
1495+
// Note that other checks (such as denying `dyn Send` -> `dyn
1496+
// Debug`) are in `rustc_hir_typeck`.
1497+
1498+
// Remove auto traits.
1499+
// Auto trait checks are handled in `rustc_hir_typeck` as FCW.
1500+
let src_obj = Ty::new_dynamic(
1501+
tcx,
1502+
tcx.mk_poly_existential_predicates(
1503+
&src_tty.without_auto_traits().collect::<Vec<_>>(),
1504+
),
1505+
// FIXME: Once we disallow casting `*const dyn Trait + 'short`
1506+
// to `*const dyn Trait + 'long`, then this can just be `src_lt`.
1507+
dst_lt,
1508+
ty::Dyn,
1509+
);
1510+
let dst_obj = Ty::new_dynamic(
1511+
tcx,
1512+
tcx.mk_poly_existential_predicates(
1513+
&dst_tty.without_auto_traits().collect::<Vec<_>>(),
1514+
),
1515+
dst_lt,
1516+
ty::Dyn,
1517+
);
1518+
1519+
debug!(?src_tty, ?dst_tty, ?src_obj, ?dst_obj);
1520+
1521+
self.sub_types(
1522+
src_obj,
1523+
dst_obj,
1524+
location.to_locations(),
1525+
ConstraintCategory::Cast {
1526+
is_implicit_coercion: false,
1527+
unsize_to: None,
1528+
},
1529+
)
1530+
.unwrap();
15191531
}
15201532
}
15211533
CastKind::Transmute => {

compiler/rustc_codegen_llvm/src/allocator.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use smallvec::SmallVec;
1212

1313
use crate::builder::SBuilder;
1414
use crate::declare::declare_simple_fn;
15-
use crate::llvm::{self, False, True, Type, Value};
15+
use crate::llvm::{self, FALSE, TRUE, Type, Value};
1616
use crate::{SimpleCx, attributes, debuginfo, llvm_util};
1717

1818
pub(crate) unsafe fn codegen(
@@ -80,7 +80,7 @@ pub(crate) unsafe fn codegen(
8080
&cx,
8181
&mangle_internal_symbol(tcx, OomStrategy::SYMBOL),
8282
&i8,
83-
&llvm::LLVMConstInt(i8, tcx.sess.opts.unstable_opts.oom.should_panic() as u64, False),
83+
&llvm::LLVMConstInt(i8, tcx.sess.opts.unstable_opts.oom.should_panic() as u64, FALSE),
8484
);
8585

8686
// __rust_no_alloc_shim_is_unstable_v2
@@ -201,7 +201,7 @@ fn create_wrapper_function(
201201
.map(|(i, _)| llvm::get_param(llfn, i as c_uint))
202202
.collect::<Vec<_>>();
203203
let ret = bx.call(ty, callee, &args, None);
204-
llvm::LLVMSetTailCall(ret, True);
204+
llvm::LLVMSetTailCall(ret, TRUE);
205205
if output.is_some() {
206206
bx.ret(ret);
207207
} else {

compiler/rustc_codegen_llvm/src/asm.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use tracing::debug;
1616
use crate::builder::Builder;
1717
use crate::common::Funclet;
1818
use crate::context::CodegenCx;
19+
use crate::llvm::ToLlvmBool;
1920
use crate::type_::Type;
2021
use crate::type_of::LayoutLlvmExt;
2122
use crate::value::Value;
@@ -470,10 +471,6 @@ pub(crate) fn inline_asm_call<'ll>(
470471
dest: Option<&'ll llvm::BasicBlock>,
471472
catch_funclet: Option<(&'ll llvm::BasicBlock, Option<&Funclet<'ll>>)>,
472473
) -> Option<&'ll Value> {
473-
let volatile = if volatile { llvm::True } else { llvm::False };
474-
let alignstack = if alignstack { llvm::True } else { llvm::False };
475-
let can_throw = if unwind { llvm::True } else { llvm::False };
476-
477474
let argtys = inputs
478475
.iter()
479476
.map(|v| {
@@ -500,10 +497,10 @@ pub(crate) fn inline_asm_call<'ll>(
500497
asm.len(),
501498
cons.as_ptr(),
502499
cons.len(),
503-
volatile,
504-
alignstack,
500+
volatile.to_llvm_bool(),
501+
alignstack.to_llvm_bool(),
505502
dia,
506-
can_throw,
503+
unwind.to_llvm_bool(),
507504
)
508505
};
509506

compiler/rustc_codegen_llvm/src/back/write.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1110,7 +1110,7 @@ fn embed_bitcode(
11101110

11111111
llvm::set_section(llglobal, bitcode_section_name(cgcx));
11121112
llvm::set_linkage(llglobal, llvm::Linkage::PrivateLinkage);
1113-
llvm::LLVMSetGlobalConstant(llglobal, llvm::True);
1113+
llvm::LLVMSetGlobalConstant(llglobal, llvm::TRUE);
11141114

11151115
let llconst = common::bytes_in_context(llcx, &[]);
11161116
let llglobal = llvm::add_global(llmod, common::val_ty(llconst), c"rustc.embedded.cmdline");

0 commit comments

Comments
 (0)