Skip to content

Commit 37a4971

Browse files
committed
Auto merge of rust-lang#91221 - matthiaskrgr:rollup-iuz3gxq, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - rust-lang#89359 (Various fixes for const_trait_impl) - rust-lang#90499 (Link with default MACOSX_DEPLOYMENT_TARGET if not otherwise specified.) - rust-lang#91096 (Print associated types on opaque `impl Trait` types) - rust-lang#91111 (Do not visit attributes in `ItemLowerer`.) - rust-lang#91162 (explain why CTFE/Miri perform truncation on shift offset) - rust-lang#91185 (Remove `-Z force-overflow-checks`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 862962b + 984e644 commit 37a4971

File tree

59 files changed

+578
-198
lines changed

Some content is hidden

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

59 files changed

+578
-198
lines changed

compiler/rustc_ast_lowering/src/item.rs

+5
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ impl ItemLowerer<'_, '_, '_> {
4040
}
4141

4242
impl<'a> Visitor<'a> for ItemLowerer<'a, '_, '_> {
43+
fn visit_attribute(&mut self, _: &'a Attribute) {
44+
// We do not want to lower expressions that appear in attributes,
45+
// as they are not accessible to the rest of the HIR.
46+
}
47+
4348
fn visit_item(&mut self, item: &'a Item) {
4449
let hir_id = self.lctx.with_hir_id_owner(item.id, |lctx| {
4550
let node = lctx.without_in_scope_lifetime_defs(|lctx| lctx.lower_item(item));

compiler/rustc_const_eval/src/interpret/operator.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,12 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
130130
let signed = left_layout.abi.is_signed();
131131
let size = u128::from(left_layout.size.bits());
132132
let overflow = r >= size;
133-
let r = r % size; // mask to type size
133+
// The shift offset is implicitly masked to the type size, to make sure this operation
134+
// is always defined. This is the one MIR operator that does *not* directly map to a
135+
// single LLVM operation. See
136+
// <https://github.com/rust-lang/rust/blob/a3b9405ae7bb6ab4e8103b414e75c44598a10fd2/compiler/rustc_codegen_ssa/src/common.rs#L131-L158>
137+
// for the corresponding truncation in our codegen backends.
138+
let r = r % size;
134139
let r = u32::try_from(r).unwrap(); // we masked so this will always fit
135140
let result = if signed {
136141
let l = self.sign_extend(l, left_layout) as i128;

compiler/rustc_const_eval/src/transform/check_consts/check.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -1004,11 +1004,12 @@ impl Visitor<'tcx> for Checker<'mir, 'tcx> {
10041004
}
10051005

10061006
let mut err_span = self.span;
1007+
let ty_of_dropped_place = dropped_place.ty(self.body, self.tcx).ty;
10071008

1008-
let ty_needs_non_const_drop = qualifs::NeedsNonConstDrop::in_any_value_of_ty(
1009-
self.ccx,
1010-
dropped_place.ty(self.body, self.tcx).ty,
1011-
);
1009+
let ty_needs_non_const_drop =
1010+
qualifs::NeedsNonConstDrop::in_any_value_of_ty(self.ccx, ty_of_dropped_place);
1011+
1012+
debug!(?ty_of_dropped_place, ?ty_needs_non_const_drop);
10121013

10131014
if !ty_needs_non_const_drop {
10141015
return;

compiler/rustc_hir/src/lang_items.rs

+1
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ language_item_table! {
268268
Future, sym::future_trait, future_trait, Target::Trait, GenericRequirement::Exact(0);
269269
GeneratorState, sym::generator_state, gen_state, Target::Enum, GenericRequirement::None;
270270
Generator, sym::generator, gen_trait, Target::Trait, GenericRequirement::Minimum(1);
271+
GeneratorReturn, sym::generator_return, generator_return, Target::AssocTy, GenericRequirement::None;
271272
Unpin, sym::unpin, unpin_trait, Target::Trait, GenericRequirement::None;
272273
Pin, sym::pin, pin_type, Target::Struct, GenericRequirement::None;
273274

compiler/rustc_interface/src/tests.rs

-1
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,6 @@ fn test_debugging_options_tracking_hash() {
726726
tracked!(dep_info_omit_d_target, true);
727727
tracked!(dual_proc_macros, true);
728728
tracked!(fewer_names, Some(true));
729-
tracked!(force_overflow_checks, Some(true));
730729
tracked!(force_unstable_if_unmarked, true);
731730
tracked!(fuel, Some(("abc".to_string(), 99)));
732731
tracked!(function_sections, Some(false));

compiler/rustc_middle/src/mir/mod.rs

+8
Original file line numberDiff line numberDiff line change
@@ -2246,8 +2246,12 @@ pub enum BinOp {
22462246
/// The `*` operator (multiplication)
22472247
Mul,
22482248
/// The `/` operator (division)
2249+
///
2250+
/// Division by zero is UB.
22492251
Div,
22502252
/// The `%` operator (modulus)
2253+
///
2254+
/// Using zero as the modulus (second operand) is UB.
22512255
Rem,
22522256
/// The `^` operator (bitwise xor)
22532257
BitXor,
@@ -2256,8 +2260,12 @@ pub enum BinOp {
22562260
/// The `|` operator (bitwise or)
22572261
BitOr,
22582262
/// The `<<` operator (shift left)
2263+
///
2264+
/// The offset is truncated to the size of the first operand before shifting.
22592265
Shl,
22602266
/// The `>>` operator (shift right)
2267+
///
2268+
/// The offset is truncated to the size of the first operand before shifting.
22612269
Shr,
22622270
/// The `==` operator (equality)
22632271
Eq,

compiler/rustc_middle/src/traits/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ pub mod query;
77
pub mod select;
88
pub mod specialization_graph;
99
mod structural_impls;
10+
pub mod util;
1011

1112
use crate::infer::canonical::Canonical;
1213
use crate::thir::abstract_const::NotConstEvaluatable;
+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
use rustc_data_structures::stable_set::FxHashSet;
2+
3+
use crate::ty::{PolyTraitRef, TyCtxt};
4+
5+
/// Given a PolyTraitRef, get the PolyTraitRefs of the trait's (transitive) supertraits.
6+
///
7+
/// A simplfied version of the same function at `rustc_infer::traits::util::supertraits`.
8+
pub fn supertraits<'tcx>(
9+
tcx: TyCtxt<'tcx>,
10+
trait_ref: PolyTraitRef<'tcx>,
11+
) -> impl Iterator<Item = PolyTraitRef<'tcx>> {
12+
Elaborator { tcx, visited: FxHashSet::from_iter([trait_ref]), stack: vec![trait_ref] }
13+
}
14+
15+
struct Elaborator<'tcx> {
16+
tcx: TyCtxt<'tcx>,
17+
visited: FxHashSet<PolyTraitRef<'tcx>>,
18+
stack: Vec<PolyTraitRef<'tcx>>,
19+
}
20+
21+
impl<'tcx> Elaborator<'tcx> {
22+
fn elaborate(&mut self, trait_ref: PolyTraitRef<'tcx>) {
23+
let supertrait_refs = self
24+
.tcx
25+
.super_predicates_of(trait_ref.def_id())
26+
.predicates
27+
.into_iter()
28+
.flat_map(|(pred, _)| {
29+
pred.subst_supertrait(self.tcx, &trait_ref).to_opt_poly_trait_ref()
30+
})
31+
.map(|t| t.value)
32+
.filter(|supertrait_ref| self.visited.insert(*supertrait_ref));
33+
34+
self.stack.extend(supertrait_refs);
35+
}
36+
}
37+
38+
impl<'tcx> Iterator for Elaborator<'tcx> {
39+
type Item = PolyTraitRef<'tcx>;
40+
41+
fn next(&mut self) -> Option<PolyTraitRef<'tcx>> {
42+
if let Some(trait_ref) = self.stack.pop() {
43+
self.elaborate(trait_ref);
44+
Some(trait_ref)
45+
} else {
46+
None
47+
}
48+
}
49+
}

0 commit comments

Comments
 (0)