Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit e571544

Browse files
committedJul 11, 2023
Auto merge of rust-lang#113577 - matthiaskrgr:rollup-vaa83ip, r=matthiaskrgr
Rollup of 4 pull requests Successful merges: - rust-lang#112717 (Implement a few more rvalue translation to smir) - rust-lang#113310 (Don't suggest `impl Trait` in path position) - rust-lang#113497 (Support explicit 32-bit MIPS ABI for the synthetic object) - rust-lang#113560 (Lint against misplaced where-clauses on associated types in traits) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 0a2681c + 4f5ef52 commit e571544

21 files changed

+498
-66
lines changed
 

‎Cargo.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4233,6 +4233,7 @@ dependencies = [
42334233
"rustc_hir",
42344234
"rustc_middle",
42354235
"rustc_span",
4236+
"rustc_target",
42364237
"scoped-tls",
42374238
"tracing",
42384239
]

‎compiler/rustc_ast_passes/src/ast_validation.rs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,33 +1300,34 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
13001300
});
13011301
}
13021302
}
1303-
AssocItemKind::Type(box TyAlias {
1304-
generics,
1305-
where_clauses,
1306-
where_predicates_split,
1307-
bounds,
1308-
ty,
1309-
..
1310-
}) => {
1303+
AssocItemKind::Type(box TyAlias { bounds, ty, .. }) => {
13111304
if ty.is_none() {
13121305
self.session.emit_err(errors::AssocTypeWithoutBody {
13131306
span: item.span,
13141307
replace_span: self.ending_semi_or_hi(item.span),
13151308
});
13161309
}
13171310
self.check_type_no_bounds(bounds, "`impl`s");
1318-
if ty.is_some() {
1319-
self.check_gat_where(
1320-
item.id,
1321-
generics.where_clause.predicates.split_at(*where_predicates_split).0,
1322-
*where_clauses,
1323-
);
1324-
}
13251311
}
13261312
_ => {}
13271313
}
13281314
}
13291315

1316+
if let AssocItemKind::Type(box TyAlias {
1317+
generics,
1318+
where_clauses,
1319+
where_predicates_split,
1320+
ty: Some(_),
1321+
..
1322+
}) = &item.kind
1323+
{
1324+
self.check_gat_where(
1325+
item.id,
1326+
generics.where_clause.predicates.split_at(*where_predicates_split).0,
1327+
*where_clauses,
1328+
);
1329+
}
1330+
13301331
if ctxt == AssocCtxt::Trait || self.in_trait_impl {
13311332
self.visibility_not_permitted(&item.vis, errors::VisibilityNotPermittedNote::TraitImpl);
13321333
if let AssocItemKind::Fn(box Fn { sig, .. }) = &item.kind {

‎compiler/rustc_codegen_ssa/src/back/metadata.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,16 @@ pub(crate) fn create_object_file(sess: &Session) -> Option<write::Object<'static
243243
s if s.contains("r6") => elf::EF_MIPS_ARCH_32R6,
244244
_ => elf::EF_MIPS_ARCH_32R2,
245245
};
246-
// The only ABI LLVM supports for 32-bit MIPS CPUs is o32.
247-
let mut e_flags = elf::EF_MIPS_CPIC | elf::EF_MIPS_ABI_O32 | arch;
246+
247+
let mut e_flags = elf::EF_MIPS_CPIC | arch;
248+
249+
// If the ABI is explicitly given, use it or default to O32.
250+
match sess.target.options.llvm_abiname.to_lowercase().as_str() {
251+
"n32" => e_flags |= elf::EF_MIPS_ABI2,
252+
"o32" => e_flags |= elf::EF_MIPS_ABI_O32,
253+
_ => e_flags |= elf::EF_MIPS_ABI_O32,
254+
};
255+
248256
if sess.target.options.relocation_model != RelocModel::Static {
249257
e_flags |= elf::EF_MIPS_PIC;
250258
}

‎compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,18 @@ fn fmt_printer<'a, 'tcx>(infcx: &'a InferCtxt<'tcx>, ns: Namespace) -> FmtPrinte
162162
let mut infcx_inner = infcx.inner.borrow_mut();
163163
let ty_vars = infcx_inner.type_variables();
164164
let var_origin = ty_vars.var_origin(ty_vid);
165-
if let TypeVariableOriginKind::TypeParameterDefinition(name, _) = var_origin.kind
165+
if let TypeVariableOriginKind::TypeParameterDefinition(name, def_id) = var_origin.kind
166166
&& !var_origin.span.from_expansion()
167167
{
168-
Some(name)
168+
let generics = infcx.tcx.generics_of(infcx.tcx.parent(def_id));
169+
let idx = generics.param_def_id_to_index(infcx.tcx, def_id).unwrap();
170+
let generic_param_def = generics.param_at(idx as usize, infcx.tcx);
171+
if let ty::GenericParamDefKind::Type { synthetic: true, .. } = generic_param_def.kind
172+
{
173+
None
174+
} else {
175+
Some(name)
176+
}
169177
} else {
170178
None
171179
}

‎compiler/rustc_lint_defs/src/builtin.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4084,7 +4084,7 @@ declare_lint! {
40844084
///
40854085
/// ### Explanation
40864086
///
4087-
/// The preferred location for where clauses on associated types in impls
4087+
/// The preferred location for where clauses on associated types
40884088
/// is after the type. However, for most of generic associated types development,
40894089
/// it was only accepted before the equals. To provide a transition period and
40904090
/// further evaluate this change, both are currently accepted. At some point in

‎compiler/rustc_smir/Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,18 @@ version = "0.0.0"
44
edition = "2021"
55

66
[dependencies]
7-
rustc_hir = { path = "../rustc_hir" }
7+
# Use optional dependencies for rustc_* in order to support building this crate separately.
8+
rustc_hir = { path = "../rustc_hir", optional = true }
89
rustc_middle = { path = "../rustc_middle", optional = true }
910
rustc_span = { path = "../rustc_span", optional = true }
11+
rustc_target = { path = "../rustc_target", optional = true }
1012
tracing = "0.1"
1113
scoped-tls = "1.0"
1214

1315
[features]
1416
default = [
17+
"rustc_hir",
1518
"rustc_middle",
1619
"rustc_span",
20+
"rustc_target",
1721
]
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[toolchain]
2-
channel = "nightly-2023-02-28"
2+
channel = "nightly-2023-06-14"
33
components = [ "rustfmt", "rustc-dev" ]

‎compiler/rustc_smir/src/lib.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,17 @@
1313
#![cfg_attr(not(feature = "default"), feature(rustc_private))]
1414
#![feature(local_key_cell_methods)]
1515
#![feature(ptr_metadata)]
16+
#![feature(type_alias_impl_trait)] // Used to define opaque types.
17+
18+
// Declare extern rustc_* crates to enable building this crate separately from the compiler.
19+
#[cfg(not(feature = "default"))]
20+
extern crate rustc_hir;
21+
#[cfg(not(feature = "default"))]
22+
extern crate rustc_middle;
23+
#[cfg(not(feature = "default"))]
24+
extern crate rustc_span;
25+
#[cfg(not(feature = "default"))]
26+
extern crate rustc_target;
1627

1728
pub mod rustc_internal;
1829
pub mod stable_mir;

‎compiler/rustc_smir/src/rustc_internal/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
//! For that, we define APIs that will temporarily be public to 3P that exposes rustc internal APIs
44
//! until stable MIR is complete.
55
6+
use std::fmt::Debug;
7+
use std::string::ToString;
8+
69
use crate::{
710
rustc_smir::Tables,
811
stable_mir::{self, with},
@@ -49,3 +52,10 @@ pub fn crate_num(item: &stable_mir::Crate) -> CrateNum {
4952
pub fn run(tcx: TyCtxt<'_>, f: impl FnOnce()) {
5053
crate::stable_mir::run(Tables { tcx, def_ids: vec![], types: vec![] }, f);
5154
}
55+
56+
/// A type that provides internal information but that can still be used for debug purpose.
57+
pub type Opaque = impl Debug + ToString + Clone;
58+
59+
pub(crate) fn opaque<T: Debug>(value: &T) -> Opaque {
60+
format!("{value:?}")
61+
}

‎compiler/rustc_smir/src/rustc_smir/mod.rs

Lines changed: 164 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77
//!
88
//! For now, we are developing everything inside `rustc`, thus, we keep this module private.
99
10+
use crate::rustc_internal::{self, opaque};
1011
use crate::stable_mir::ty::{FloatTy, IntTy, RigidTy, TyKind, UintTy};
1112
use crate::stable_mir::{self, Context};
1213
use rustc_middle::mir;
1314
use rustc_middle::ty::{self, Ty, TyCtxt};
1415
use rustc_span::def_id::{CrateNum, DefId, LOCAL_CRATE};
16+
use rustc_target::abi::FieldIdx;
1517
use tracing::debug;
1618

1719
impl<'tcx> Context for Tables<'tcx> {
@@ -137,11 +139,21 @@ fn smir_crate(tcx: TyCtxt<'_>, crate_num: CrateNum) -> stable_mir::Crate {
137139
stable_mir::Crate { id: crate_num.into(), name: crate_name, is_local }
138140
}
139141

140-
pub trait Stable {
142+
/// Trait used to convert between an internal MIR type to a Stable MIR type.
143+
pub(crate) trait Stable {
144+
/// The stable representation of the type implementing Stable.
141145
type T;
146+
/// Converts an object to the equivalent Stable MIR representation.
142147
fn stable(&self) -> Self::T;
143148
}
144149

150+
impl Stable for DefId {
151+
type T = stable_mir::CrateItem;
152+
fn stable(&self) -> Self::T {
153+
rustc_internal::crate_item(*self)
154+
}
155+
}
156+
145157
impl<'tcx> Stable for mir::Statement<'tcx> {
146158
type T = stable_mir::mir::Statement;
147159
fn stable(&self) -> Self::T {
@@ -173,27 +185,138 @@ impl<'tcx> Stable for mir::Rvalue<'tcx> {
173185
match self {
174186
Use(op) => stable_mir::mir::Rvalue::Use(op.stable()),
175187
Repeat(_, _) => todo!(),
176-
Ref(_, _, _) => todo!(),
177-
ThreadLocalRef(_) => todo!(),
178-
AddressOf(_, _) => todo!(),
179-
Len(_) => todo!(),
188+
Ref(region, kind, place) => {
189+
stable_mir::mir::Rvalue::Ref(opaque(region), kind.stable(), place.stable())
190+
}
191+
ThreadLocalRef(def_id) => stable_mir::mir::Rvalue::ThreadLocalRef(def_id.stable()),
192+
AddressOf(mutability, place) => {
193+
stable_mir::mir::Rvalue::AddressOf(mutability.stable(), place.stable())
194+
}
195+
Len(place) => stable_mir::mir::Rvalue::Len(place.stable()),
180196
Cast(_, _, _) => todo!(),
181-
BinaryOp(_, _) => todo!(),
197+
BinaryOp(bin_op, ops) => {
198+
stable_mir::mir::Rvalue::BinaryOp(bin_op.stable(), ops.0.stable(), ops.1.stable())
199+
}
182200
CheckedBinaryOp(bin_op, ops) => stable_mir::mir::Rvalue::CheckedBinaryOp(
183201
bin_op.stable(),
184202
ops.0.stable(),
185203
ops.1.stable(),
186204
),
187205
NullaryOp(_, _) => todo!(),
188206
UnaryOp(un_op, op) => stable_mir::mir::Rvalue::UnaryOp(un_op.stable(), op.stable()),
189-
Discriminant(_) => todo!(),
207+
Discriminant(place) => stable_mir::mir::Rvalue::Discriminant(place.stable()),
190208
Aggregate(_, _) => todo!(),
191209
ShallowInitBox(_, _) => todo!(),
192-
CopyForDeref(_) => todo!(),
210+
CopyForDeref(place) => stable_mir::mir::Rvalue::CopyForDeref(place.stable()),
211+
}
212+
}
213+
}
214+
215+
impl Stable for mir::Mutability {
216+
type T = stable_mir::mir::Mutability;
217+
fn stable(&self) -> Self::T {
218+
use mir::Mutability::*;
219+
match *self {
220+
Not => stable_mir::mir::Mutability::Not,
221+
Mut => stable_mir::mir::Mutability::Mut,
222+
}
223+
}
224+
}
225+
226+
impl Stable for mir::BorrowKind {
227+
type T = stable_mir::mir::BorrowKind;
228+
fn stable(&self) -> Self::T {
229+
use mir::BorrowKind::*;
230+
match *self {
231+
Shared => stable_mir::mir::BorrowKind::Shared,
232+
Shallow => stable_mir::mir::BorrowKind::Shallow,
233+
Mut { kind } => stable_mir::mir::BorrowKind::Mut { kind: kind.stable() },
234+
}
235+
}
236+
}
237+
238+
impl Stable for mir::MutBorrowKind {
239+
type T = stable_mir::mir::MutBorrowKind;
240+
fn stable(&self) -> Self::T {
241+
use mir::MutBorrowKind::*;
242+
match *self {
243+
Default => stable_mir::mir::MutBorrowKind::Default,
244+
TwoPhaseBorrow => stable_mir::mir::MutBorrowKind::TwoPhaseBorrow,
245+
ClosureCapture => stable_mir::mir::MutBorrowKind::ClosureCapture,
246+
}
247+
}
248+
}
249+
250+
impl<'tcx> Stable for mir::NullOp<'tcx> {
251+
type T = stable_mir::mir::NullOp;
252+
fn stable(&self) -> Self::T {
253+
use mir::NullOp::*;
254+
match self {
255+
SizeOf => stable_mir::mir::NullOp::SizeOf,
256+
AlignOf => stable_mir::mir::NullOp::AlignOf,
257+
OffsetOf(indices) => {
258+
stable_mir::mir::NullOp::OffsetOf(indices.iter().map(|idx| idx.stable()).collect())
259+
}
260+
}
261+
}
262+
}
263+
264+
impl Stable for mir::CastKind {
265+
type T = stable_mir::mir::CastKind;
266+
fn stable(&self) -> Self::T {
267+
use mir::CastKind::*;
268+
match self {
269+
PointerExposeAddress => stable_mir::mir::CastKind::PointerExposeAddress,
270+
PointerFromExposedAddress => stable_mir::mir::CastKind::PointerFromExposedAddress,
271+
PointerCoercion(c) => stable_mir::mir::CastKind::PointerCoercion(c.stable()),
272+
DynStar => stable_mir::mir::CastKind::DynStar,
273+
IntToInt => stable_mir::mir::CastKind::IntToInt,
274+
FloatToInt => stable_mir::mir::CastKind::FloatToInt,
275+
FloatToFloat => stable_mir::mir::CastKind::FloatToFloat,
276+
IntToFloat => stable_mir::mir::CastKind::IntToFloat,
277+
PtrToPtr => stable_mir::mir::CastKind::PtrToPtr,
278+
FnPtrToPtr => stable_mir::mir::CastKind::FnPtrToPtr,
279+
Transmute => stable_mir::mir::CastKind::Transmute,
193280
}
194281
}
195282
}
196283

284+
impl Stable for ty::adjustment::PointerCoercion {
285+
type T = stable_mir::mir::PointerCoercion;
286+
fn stable(&self) -> Self::T {
287+
use ty::adjustment::PointerCoercion;
288+
match self {
289+
PointerCoercion::ReifyFnPointer => stable_mir::mir::PointerCoercion::ReifyFnPointer,
290+
PointerCoercion::UnsafeFnPointer => stable_mir::mir::PointerCoercion::UnsafeFnPointer,
291+
PointerCoercion::ClosureFnPointer(unsafety) => {
292+
stable_mir::mir::PointerCoercion::ClosureFnPointer(unsafety.stable())
293+
}
294+
PointerCoercion::MutToConstPointer => {
295+
stable_mir::mir::PointerCoercion::MutToConstPointer
296+
}
297+
PointerCoercion::ArrayToPointer => stable_mir::mir::PointerCoercion::ArrayToPointer,
298+
PointerCoercion::Unsize => stable_mir::mir::PointerCoercion::Unsize,
299+
}
300+
}
301+
}
302+
303+
impl Stable for rustc_hir::Unsafety {
304+
type T = stable_mir::mir::Safety;
305+
fn stable(&self) -> Self::T {
306+
match self {
307+
rustc_hir::Unsafety::Unsafe => stable_mir::mir::Safety::Unsafe,
308+
rustc_hir::Unsafety::Normal => stable_mir::mir::Safety::Normal,
309+
}
310+
}
311+
}
312+
313+
impl Stable for FieldIdx {
314+
type T = usize;
315+
fn stable(&self) -> Self::T {
316+
self.as_usize()
317+
}
318+
}
319+
197320
impl<'tcx> Stable for mir::Operand<'tcx> {
198321
type T = stable_mir::mir::Operand;
199322
fn stable(&self) -> Self::T {
@@ -229,34 +352,38 @@ impl Stable for mir::UnwindAction {
229352
}
230353
}
231354

232-
fn rustc_assert_msg_to_msg<'tcx>(
233-
assert_message: &rustc_middle::mir::AssertMessage<'tcx>,
234-
) -> stable_mir::mir::AssertMessage {
235-
use rustc_middle::mir::AssertKind;
236-
match assert_message {
237-
AssertKind::BoundsCheck { len, index } => {
238-
stable_mir::mir::AssertMessage::BoundsCheck { len: len.stable(), index: index.stable() }
239-
}
240-
AssertKind::Overflow(bin_op, op1, op2) => {
241-
stable_mir::mir::AssertMessage::Overflow(bin_op.stable(), op1.stable(), op2.stable())
242-
}
243-
AssertKind::OverflowNeg(op) => stable_mir::mir::AssertMessage::OverflowNeg(op.stable()),
244-
AssertKind::DivisionByZero(op) => {
245-
stable_mir::mir::AssertMessage::DivisionByZero(op.stable())
246-
}
247-
AssertKind::RemainderByZero(op) => {
248-
stable_mir::mir::AssertMessage::RemainderByZero(op.stable())
249-
}
250-
AssertKind::ResumedAfterReturn(generator) => {
251-
stable_mir::mir::AssertMessage::ResumedAfterReturn(generator.stable())
252-
}
253-
AssertKind::ResumedAfterPanic(generator) => {
254-
stable_mir::mir::AssertMessage::ResumedAfterPanic(generator.stable())
255-
}
256-
AssertKind::MisalignedPointerDereference { required, found } => {
257-
stable_mir::mir::AssertMessage::MisalignedPointerDereference {
258-
required: required.stable(),
259-
found: found.stable(),
355+
impl<'tcx> Stable for mir::AssertMessage<'tcx> {
356+
type T = stable_mir::mir::AssertMessage;
357+
fn stable(&self) -> Self::T {
358+
use rustc_middle::mir::AssertKind;
359+
match self {
360+
AssertKind::BoundsCheck { len, index } => stable_mir::mir::AssertMessage::BoundsCheck {
361+
len: len.stable(),
362+
index: index.stable(),
363+
},
364+
AssertKind::Overflow(bin_op, op1, op2) => stable_mir::mir::AssertMessage::Overflow(
365+
bin_op.stable(),
366+
op1.stable(),
367+
op2.stable(),
368+
),
369+
AssertKind::OverflowNeg(op) => stable_mir::mir::AssertMessage::OverflowNeg(op.stable()),
370+
AssertKind::DivisionByZero(op) => {
371+
stable_mir::mir::AssertMessage::DivisionByZero(op.stable())
372+
}
373+
AssertKind::RemainderByZero(op) => {
374+
stable_mir::mir::AssertMessage::RemainderByZero(op.stable())
375+
}
376+
AssertKind::ResumedAfterReturn(generator) => {
377+
stable_mir::mir::AssertMessage::ResumedAfterReturn(generator.stable())
378+
}
379+
AssertKind::ResumedAfterPanic(generator) => {
380+
stable_mir::mir::AssertMessage::ResumedAfterPanic(generator.stable())
381+
}
382+
AssertKind::MisalignedPointerDereference { required, found } => {
383+
stable_mir::mir::AssertMessage::MisalignedPointerDereference {
384+
required: required.stable(),
385+
found: found.stable(),
386+
}
260387
}
261388
}
262389
}
@@ -381,7 +508,7 @@ impl<'tcx> Stable for mir::Terminator<'tcx> {
381508
Assert { cond, expected, msg, target, unwind } => Terminator::Assert {
382509
cond: cond.stable(),
383510
expected: *expected,
384-
msg: rustc_assert_msg_to_msg(msg),
511+
msg: msg.stable(),
385512
target: target.as_usize(),
386513
unwind: unwind.stable(),
387514
},

‎compiler/rustc_smir/src/stable_mir/mir/body.rs

Lines changed: 179 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
use crate::stable_mir::ty::Ty;
1+
use crate::rustc_internal::Opaque;
2+
use crate::stable_mir::{self, ty::Ty};
23

34
#[derive(Clone, Debug)]
45
pub struct Body {
@@ -136,12 +137,98 @@ pub enum Statement {
136137
Nop,
137138
}
138139

140+
type Region = Opaque;
141+
139142
// FIXME this is incomplete
140143
#[derive(Clone, Debug)]
141144
pub enum Rvalue {
142-
Use(Operand),
145+
/// Creates a pointer with the indicated mutability to the place.
146+
///
147+
/// This is generated by pointer casts like `&v as *const _` or raw address of expressions like
148+
/// `&raw v` or `addr_of!(v)`.
149+
AddressOf(Mutability, Place),
150+
151+
/// * `Offset` has the same semantics as [`offset`](pointer::offset), except that the second
152+
/// parameter may be a `usize` as well.
153+
/// * The comparison operations accept `bool`s, `char`s, signed or unsigned integers, floats,
154+
/// raw pointers, or function pointers and return a `bool`. The types of the operands must be
155+
/// matching, up to the usual caveat of the lifetimes in function pointers.
156+
/// * Left and right shift operations accept signed or unsigned integers not necessarily of the
157+
/// same type and return a value of the same type as their LHS. Like in Rust, the RHS is
158+
/// truncated as needed.
159+
/// * The `Bit*` operations accept signed integers, unsigned integers, or bools with matching
160+
/// types and return a value of that type.
161+
/// * The remaining operations accept signed integers, unsigned integers, or floats with
162+
/// matching types and return a value of that type.
163+
BinaryOp(BinOp, Operand, Operand),
164+
165+
/// Performs essentially all of the casts that can be performed via `as`.
166+
///
167+
/// This allows for casts from/to a variety of types.
168+
Cast(CastKind, Operand, Ty),
169+
170+
/// Same as `BinaryOp`, but yields `(T, bool)` with a `bool` indicating an error condition.
171+
///
172+
/// For addition, subtraction, and multiplication on integers the error condition is set when
173+
/// the infinite precision result would not be equal to the actual result.
143174
CheckedBinaryOp(BinOp, Operand, Operand),
175+
176+
/// A CopyForDeref is equivalent to a read from a place.
177+
/// When such a read happens, it is guaranteed that the only use of the returned value is a
178+
/// deref operation, immediately followed by one or more projections.
179+
CopyForDeref(Place),
180+
181+
/// Computes the discriminant of the place, returning it as an integer of type
182+
/// [`discriminant_ty`]. Returns zero for types without discriminant.
183+
///
184+
/// The validity requirements for the underlying value are undecided for this rvalue, see
185+
/// [#91095]. Note too that the value of the discriminant is not the same thing as the
186+
/// variant index; use [`discriminant_for_variant`] to convert.
187+
///
188+
/// [`discriminant_ty`]: crate::ty::Ty::discriminant_ty
189+
/// [#91095]: https://github.com/rust-lang/rust/issues/91095
190+
/// [`discriminant_for_variant`]: crate::ty::Ty::discriminant_for_variant
191+
Discriminant(Place),
192+
193+
/// Yields the length of the place, as a `usize`.
194+
///
195+
/// If the type of the place is an array, this is the array length. For slices (`[T]`, not
196+
/// `&[T]`) this accesses the place's metadata to determine the length. This rvalue is
197+
/// ill-formed for places of other types.
198+
Len(Place),
199+
200+
/// Creates a reference to the place.
201+
Ref(Region, BorrowKind, Place),
202+
203+
/// Transmutes a `*mut u8` into shallow-initialized `Box<T>`.
204+
///
205+
/// This is different from a normal transmute because dataflow analysis will treat the box as
206+
/// initialized but its content as uninitialized. Like other pointer casts, this in general
207+
/// affects alias analysis.
208+
ShallowInitBox(Operand, Ty),
209+
210+
/// Creates a pointer/reference to the given thread local.
211+
///
212+
/// The yielded type is a `*mut T` if the static is mutable, otherwise if the static is extern a
213+
/// `*const T`, and if neither of those apply a `&T`.
214+
///
215+
/// **Note:** This is a runtime operation that actually executes code and is in this sense more
216+
/// like a function call. Also, eliminating dead stores of this rvalue causes `fn main() {}` to
217+
/// SIGILL for some reason that I (JakobDegen) never got a chance to look into.
218+
///
219+
/// **Needs clarification**: Are there weird additional semantics here related to the runtime
220+
/// nature of this operation?
221+
ThreadLocalRef(stable_mir::CrateItem),
222+
223+
/// Exactly like `BinaryOp`, but less operands.
224+
///
225+
/// Also does two's-complement arithmetic. Negation requires a signed integer or a float;
226+
/// bitwise not requires a signed integer, unsigned integer, or bool. Both operation kinds
227+
/// return a value with the same type as their operand.
144228
UnaryOp(UnOp, Operand),
229+
230+
/// Yields the operand unchanged
231+
Use(Operand),
145232
}
146233

147234
#[derive(Clone, Debug)]
@@ -157,8 +244,98 @@ pub struct Place {
157244
pub projection: String,
158245
}
159246

247+
type FieldIdx = usize;
248+
160249
#[derive(Clone, Debug)]
161250
pub struct SwitchTarget {
162251
pub value: u128,
163252
pub target: usize,
164253
}
254+
255+
#[derive(Clone, Debug)]
256+
pub enum BorrowKind {
257+
/// Data must be immutable and is aliasable.
258+
Shared,
259+
260+
/// The immediately borrowed place must be immutable, but projections from
261+
/// it don't need to be. For example, a shallow borrow of `a.b` doesn't
262+
/// conflict with a mutable borrow of `a.b.c`.
263+
Shallow,
264+
265+
/// Data is mutable and not aliasable.
266+
Mut {
267+
/// `true` if this borrow arose from method-call auto-ref
268+
kind: MutBorrowKind,
269+
},
270+
}
271+
272+
#[derive(Clone, Debug)]
273+
pub enum MutBorrowKind {
274+
Default,
275+
TwoPhaseBorrow,
276+
ClosureCapture,
277+
}
278+
279+
#[derive(Clone, Debug)]
280+
pub enum Mutability {
281+
Not,
282+
Mut,
283+
}
284+
285+
#[derive(Clone, Debug)]
286+
pub enum Safety {
287+
Unsafe,
288+
Normal,
289+
}
290+
291+
#[derive(Clone, Debug)]
292+
pub enum PointerCoercion {
293+
/// Go from a fn-item type to a fn-pointer type.
294+
ReifyFnPointer,
295+
296+
/// Go from a safe fn pointer to an unsafe fn pointer.
297+
UnsafeFnPointer,
298+
299+
/// Go from a non-capturing closure to an fn pointer or an unsafe fn pointer.
300+
/// It cannot convert a closure that requires unsafe.
301+
ClosureFnPointer(Safety),
302+
303+
/// Go from a mut raw pointer to a const raw pointer.
304+
MutToConstPointer,
305+
306+
/// Go from `*const [T; N]` to `*const T`
307+
ArrayToPointer,
308+
309+
/// Unsize a pointer/reference value, e.g., `&[T; n]` to
310+
/// `&[T]`. Note that the source could be a thin or fat pointer.
311+
/// This will do things like convert thin pointers to fat
312+
/// pointers, or convert structs containing thin pointers to
313+
/// structs containing fat pointers, or convert between fat
314+
/// pointers.
315+
Unsize,
316+
}
317+
318+
#[derive(Clone, Debug)]
319+
pub enum CastKind {
320+
PointerExposeAddress,
321+
PointerFromExposedAddress,
322+
PointerCoercion(PointerCoercion),
323+
DynStar,
324+
IntToInt,
325+
FloatToInt,
326+
FloatToFloat,
327+
IntToFloat,
328+
PtrToPtr,
329+
FnPtrToPtr,
330+
Transmute,
331+
}
332+
333+
#[derive(Clone, Debug)]
334+
pub enum NullOp {
335+
/// Returns the size of a value of that type.
336+
SizeOf,
337+
/// Returns the minimum alignment of a type.
338+
AlignOf,
339+
/// Returns the offset of a field.
340+
OffsetOf(Vec<FieldIdx>),
341+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
trait T {}
2+
3+
struct S {}
4+
5+
impl S {
6+
fn owo(&self, _: Option<&impl T>) {}
7+
}
8+
9+
fn main() {
10+
(S {}).owo(None)
11+
//~^ ERROR type annotations needed
12+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error[E0282]: type annotations needed
2+
--> $DIR/issue-113264-incorrect-impl-trait-in-path-suggestion.rs:10:16
3+
|
4+
LL | (S {}).owo(None)
5+
| ^^^^ cannot infer type of the type parameter `T` declared on the enum `Option`
6+
|
7+
help: consider specifying the generic argument
8+
|
9+
LL | (S {}).owo(None::<&_>)
10+
| ++++++
11+
12+
error: aborting due to previous error
13+
14+
For more information about this error, try `rustc --explain E0282`.

‎tests/ui/parser/type-alias-where-fixable.stderr renamed to ‎tests/ui/where-clauses/where-clause-placement-assoc-type-in-impl.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
warning: where clause not allowed here
2-
--> $DIR/type-alias-where-fixable.rs:13:16
2+
--> $DIR/where-clause-placement-assoc-type-in-impl.rs:13:16
33
|
44
LL | type Assoc where u32: Copy = ();
55
| ^^^^^^^^^^^^^^^
@@ -13,7 +13,7 @@ LL + type Assoc = () where u32: Copy;
1313
|
1414

1515
warning: where clause not allowed here
16-
--> $DIR/type-alias-where-fixable.rs:16:17
16+
--> $DIR/where-clause-placement-assoc-type-in-impl.rs:16:17
1717
|
1818
LL | type Assoc2 where u32: Copy = () where i32: Copy;
1919
| ^^^^^^^^^^^^^^^
@@ -26,7 +26,7 @@ LL + type Assoc2 = () where i32: Copy, u32: Copy;
2626
|
2727

2828
warning: where clause not allowed here
29-
--> $DIR/type-alias-where-fixable.rs:24:17
29+
--> $DIR/where-clause-placement-assoc-type-in-impl.rs:24:17
3030
|
3131
LL | type Assoc2 where u32: Copy, i32: Copy = ();
3232
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// check-pass
2+
// run-rustfix
3+
4+
#![feature(associated_type_defaults)]
5+
6+
trait Trait {
7+
// Not fine, suggests moving.
8+
type Assoc = () where u32: Copy;
9+
//~^ WARNING where clause not allowed here
10+
// Not fine, suggests moving `u32: Copy`
11+
type Assoc2 = () where i32: Copy, u32: Copy;
12+
//~^ WARNING where clause not allowed here
13+
}
14+
15+
fn main() {}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// check-pass
2+
// run-rustfix
3+
4+
#![feature(associated_type_defaults)]
5+
6+
trait Trait {
7+
// Not fine, suggests moving.
8+
type Assoc where u32: Copy = ();
9+
//~^ WARNING where clause not allowed here
10+
// Not fine, suggests moving `u32: Copy`
11+
type Assoc2 where u32: Copy = () where i32: Copy;
12+
//~^ WARNING where clause not allowed here
13+
}
14+
15+
fn main() {}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
warning: where clause not allowed here
2+
--> $DIR/where-clause-placement-assoc-type-in-trait.rs:8:16
3+
|
4+
LL | type Assoc where u32: Copy = ();
5+
| ^^^^^^^^^^^^^^^
6+
|
7+
= note: see issue #89122 <https://github.com/rust-lang/rust/issues/89122> for more information
8+
= note: `#[warn(deprecated_where_clause_location)]` on by default
9+
help: move it to the end of the type declaration
10+
|
11+
LL - type Assoc where u32: Copy = ();
12+
LL + type Assoc = () where u32: Copy;
13+
|
14+
15+
warning: where clause not allowed here
16+
--> $DIR/where-clause-placement-assoc-type-in-trait.rs:11:17
17+
|
18+
LL | type Assoc2 where u32: Copy = () where i32: Copy;
19+
| ^^^^^^^^^^^^^^^
20+
|
21+
= note: see issue #89122 <https://github.com/rust-lang/rust/issues/89122> for more information
22+
help: move it to the end of the type declaration
23+
|
24+
LL - type Assoc2 where u32: Copy = () where i32: Copy;
25+
LL + type Assoc2 = () where i32: Copy, u32: Copy;
26+
|
27+
28+
warning: 2 warnings emitted
29+

‎tests/ui/parser/type-alias-where.stderr renamed to ‎tests/ui/where-clauses/where-clause-placement-type-alias.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
error: where clauses are not allowed after the type for type aliases
2-
--> $DIR/type-alias-where.rs:6:15
2+
--> $DIR/where-clause-placement-type-alias.rs:6:15
33
|
44
LL | type Bar = () where u32: Copy;
55
| ^^^^^^^^^^^^^^^
66
|
77
= note: see issue #89122 <https://github.com/rust-lang/rust/issues/89122> for more information
88

99
error: where clauses are not allowed after the type for type aliases
10-
--> $DIR/type-alias-where.rs:8:15
10+
--> $DIR/where-clause-placement-type-alias.rs:8:15
1111
|
1212
LL | type Baz = () where;
1313
| ^^^^^

0 commit comments

Comments
 (0)
This repository has been archived.