Skip to content

Commit 38528d4

Browse files
committed
Auto merge of rust-lang#100904 - matthiaskrgr:rollup-z3yzivj, r=matthiaskrgr
Rollup of 9 pull requests Successful merges: - rust-lang#100382 (Make the GATS self outlives error take into GATs in the inputs) - rust-lang#100565 (Suggest adding a missing semicolon before an item) - rust-lang#100641 (Add the armv4t-none-eabi target to the supported_targets) - rust-lang#100789 (Use separate infcx to solve obligations during negative coherence) - rust-lang#100832 (Some small bootstrap cleanup) - rust-lang#100861 (fix ICE with extra-const-ub-checks) - rust-lang#100862 (tidy: remove crossbeam-utils) - rust-lang#100887 (Refactor part of codegen_call_terminator) - rust-lang#100893 (Remove out-of-context comment in `mem::MaybeUninit` documentation) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 7e3e8a8 + 683a08a commit 38528d4

File tree

26 files changed

+403
-111
lines changed

26 files changed

+403
-111
lines changed

Cargo.lock

-1
Original file line numberDiff line numberDiff line change
@@ -5295,7 +5295,6 @@ name = "tidy"
52955295
version = "0.1.0"
52965296
dependencies = [
52975297
"cargo_metadata 0.14.0",
5298-
"crossbeam-utils",
52995298
"lazy_static",
53005299
"regex",
53015300
"walkdir",

compiler/rustc_ast/src/token.rs

+24
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,30 @@ impl Token {
436436
|| self == &OpenDelim(Delimiter::Parenthesis)
437437
}
438438

439+
/// Returns `true` if the token can appear at the start of an item.
440+
pub fn can_begin_item(&self) -> bool {
441+
match self.kind {
442+
Ident(name, _) => [
443+
kw::Fn,
444+
kw::Use,
445+
kw::Struct,
446+
kw::Enum,
447+
kw::Pub,
448+
kw::Trait,
449+
kw::Extern,
450+
kw::Impl,
451+
kw::Unsafe,
452+
kw::Static,
453+
kw::Union,
454+
kw::Macro,
455+
kw::Mod,
456+
kw::Type,
457+
]
458+
.contains(&name),
459+
_ => false,
460+
}
461+
}
462+
439463
/// Returns `true` if the token is any literal.
440464
pub fn is_lit(&self) -> bool {
441465
matches!(self.kind, Literal(..))

compiler/rustc_codegen_ssa/src/mir/block.rs

+44-47
Original file line numberDiff line numberDiff line change
@@ -798,58 +798,55 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
798798
let mut op = self.codegen_operand(&mut bx, arg);
799799

800800
if let (0, Some(ty::InstanceDef::Virtual(_, idx))) = (i, def) {
801-
if let Pair(..) = op.val {
802-
// In the case of Rc<Self>, we need to explicitly pass a
803-
// *mut RcBox<Self> with a Scalar (not ScalarPair) ABI. This is a hack
804-
// that is understood elsewhere in the compiler as a method on
805-
// `dyn Trait`.
806-
// To get a `*mut RcBox<Self>`, we just keep unwrapping newtypes until
807-
// we get a value of a built-in pointer type
808-
'descend_newtypes: while !op.layout.ty.is_unsafe_ptr()
809-
&& !op.layout.ty.is_region_ptr()
810-
{
811-
for i in 0..op.layout.fields.count() {
812-
let field = op.extract_field(&mut bx, i);
813-
if !field.layout.is_zst() {
814-
// we found the one non-zero-sized field that is allowed
815-
// now find *its* non-zero-sized field, or stop if it's a
816-
// pointer
817-
op = field;
818-
continue 'descend_newtypes;
801+
match op.val {
802+
Pair(data_ptr, meta) => {
803+
// In the case of Rc<Self>, we need to explicitly pass a
804+
// *mut RcBox<Self> with a Scalar (not ScalarPair) ABI. This is a hack
805+
// that is understood elsewhere in the compiler as a method on
806+
// `dyn Trait`.
807+
// To get a `*mut RcBox<Self>`, we just keep unwrapping newtypes until
808+
// we get a value of a built-in pointer type
809+
'descend_newtypes: while !op.layout.ty.is_unsafe_ptr()
810+
&& !op.layout.ty.is_region_ptr()
811+
{
812+
for i in 0..op.layout.fields.count() {
813+
let field = op.extract_field(&mut bx, i);
814+
if !field.layout.is_zst() {
815+
// we found the one non-zero-sized field that is allowed
816+
// now find *its* non-zero-sized field, or stop if it's a
817+
// pointer
818+
op = field;
819+
continue 'descend_newtypes;
820+
}
819821
}
822+
823+
span_bug!(span, "receiver has no non-zero-sized fields {:?}", op);
820824
}
821825

822-
span_bug!(span, "receiver has no non-zero-sized fields {:?}", op);
826+
// now that we have `*dyn Trait` or `&dyn Trait`, split it up into its
827+
// data pointer and vtable. Look up the method in the vtable, and pass
828+
// the data pointer as the first argument
829+
llfn = Some(meth::VirtualIndex::from_index(idx).get_fn(
830+
&mut bx,
831+
meta,
832+
op.layout.ty,
833+
&fn_abi,
834+
));
835+
llargs.push(data_ptr);
836+
continue 'make_args;
823837
}
824-
825-
// now that we have `*dyn Trait` or `&dyn Trait`, split it up into its
826-
// data pointer and vtable. Look up the method in the vtable, and pass
827-
// the data pointer as the first argument
828-
match op.val {
829-
Pair(data_ptr, meta) => {
830-
llfn = Some(meth::VirtualIndex::from_index(idx).get_fn(
831-
&mut bx,
832-
meta,
833-
op.layout.ty,
834-
&fn_abi,
835-
));
836-
llargs.push(data_ptr);
837-
continue 'make_args;
838-
}
839-
other => bug!("expected a Pair, got {:?}", other),
838+
Ref(data_ptr, Some(meta), _) => {
839+
// by-value dynamic dispatch
840+
llfn = Some(meth::VirtualIndex::from_index(idx).get_fn(
841+
&mut bx,
842+
meta,
843+
op.layout.ty,
844+
&fn_abi,
845+
));
846+
llargs.push(data_ptr);
847+
continue;
840848
}
841-
} else if let Ref(data_ptr, Some(meta), _) = op.val {
842-
// by-value dynamic dispatch
843-
llfn = Some(meth::VirtualIndex::from_index(idx).get_fn(
844-
&mut bx,
845-
meta,
846-
op.layout.ty,
847-
&fn_abi,
848-
));
849-
llargs.push(data_ptr);
850-
continue;
851-
} else {
852-
span_bug!(span, "can't codegen a virtual call on {:?}", op);
849+
_ => span_bug!(span, "can't codegen a virtual call on {:?}", op),
853850
}
854851
}
855852

compiler/rustc_const_eval/src/const_eval/eval_queries.rs

+18-4
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ fn eval_body_using_ecx<'mir, 'tcx>(
8181
}
8282

8383
/// The `InterpCx` is only meant to be used to do field and index projections into constants for
84-
/// `simd_shuffle` and const patterns in match arms.
84+
/// `simd_shuffle` and const patterns in match arms. It never performs alignment checks.
8585
///
8686
/// The function containing the `match` that is currently being analyzed may have generic bounds
8787
/// that inform us about the generic bounds of the constant. E.g., using an associated constant
@@ -98,7 +98,11 @@ pub(super) fn mk_eval_cx<'mir, 'tcx>(
9898
tcx,
9999
root_span,
100100
param_env,
101-
CompileTimeInterpreter::new(tcx.const_eval_limit(), can_access_statics),
101+
CompileTimeInterpreter::new(
102+
tcx.const_eval_limit(),
103+
can_access_statics,
104+
/*check_alignment:*/ false,
105+
),
102106
)
103107
}
104108

@@ -203,7 +207,13 @@ pub(crate) fn turn_into_const_value<'tcx>(
203207
let cid = key.value;
204208
let def_id = cid.instance.def.def_id();
205209
let is_static = tcx.is_static(def_id);
206-
let ecx = mk_eval_cx(tcx, tcx.def_span(key.value.instance.def_id()), key.param_env, is_static);
210+
// This is just accessing an already computed constant, so no need to check alginment here.
211+
let ecx = mk_eval_cx(
212+
tcx,
213+
tcx.def_span(key.value.instance.def_id()),
214+
key.param_env,
215+
/*can_access_statics:*/ is_static,
216+
);
207217

208218
let mplace = ecx.raw_const_to_mplace(constant).expect(
209219
"can only fail if layout computation failed, \
@@ -300,7 +310,11 @@ pub fn eval_to_allocation_raw_provider<'tcx>(
300310
key.param_env,
301311
// Statics (and promoteds inside statics) may access other statics, because unlike consts
302312
// they do not have to behave "as if" they were evaluated at runtime.
303-
CompileTimeInterpreter::new(tcx.const_eval_limit(), /*can_access_statics:*/ is_static),
313+
CompileTimeInterpreter::new(
314+
tcx.const_eval_limit(),
315+
/*can_access_statics:*/ is_static,
316+
/*check_alignment:*/ tcx.sess.opts.unstable_opts.extra_const_ub_checks,
317+
),
304318
);
305319

306320
let res = ecx.load_mir(cid.instance.def, cid.promoted);

compiler/rustc_const_eval/src/const_eval/machine.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,22 @@ pub struct CompileTimeInterpreter<'mir, 'tcx> {
101101
/// * Pointers to allocations inside of statics can never leak outside, to a non-static global.
102102
/// This boolean here controls the second part.
103103
pub(super) can_access_statics: bool,
104+
105+
/// Whether to check alignment during evaluation.
106+
check_alignment: bool,
104107
}
105108

106109
impl<'mir, 'tcx> CompileTimeInterpreter<'mir, 'tcx> {
107-
pub(crate) fn new(const_eval_limit: Limit, can_access_statics: bool) -> Self {
110+
pub(crate) fn new(
111+
const_eval_limit: Limit,
112+
can_access_statics: bool,
113+
check_alignment: bool,
114+
) -> Self {
108115
CompileTimeInterpreter {
109116
steps_remaining: const_eval_limit.0,
110117
stack: Vec::new(),
111118
can_access_statics,
119+
check_alignment,
112120
}
113121
}
114122
}
@@ -238,7 +246,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
238246

239247
#[inline(always)]
240248
fn enforce_alignment(ecx: &InterpCx<'mir, 'tcx, Self>) -> bool {
241-
ecx.tcx.sess.opts.unstable_opts.extra_const_ub_checks
249+
ecx.machine.check_alignment
242250
}
243251

244252
#[inline(always)]

compiler/rustc_const_eval/src/might_permit_raw_init.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ pub fn might_permit_raw_init<'tcx>(
1313
let strict = tcx.sess.opts.unstable_opts.strict_init_checks;
1414

1515
if strict {
16-
let machine = CompileTimeInterpreter::new(Limit::new(0), false);
16+
let machine = CompileTimeInterpreter::new(
17+
Limit::new(0),
18+
/*can_access_statics:*/ false,
19+
/*check_alignment:*/ true,
20+
);
1721

1822
let mut cx = InterpCx::new(tcx, rustc_span::DUMMY_SP, ParamEnv::reveal_all(), machine);
1923

compiler/rustc_parse/src/parser/diagnostics.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -927,10 +927,12 @@ impl<'a> Parser<'a> {
927927
return Ok(true);
928928
} else if self.look_ahead(0, |t| {
929929
t == &token::CloseDelim(Delimiter::Brace)
930-
|| (t.can_begin_expr() && t != &token::Semi && t != &token::Pound)
930+
|| ((t.can_begin_expr() || t.can_begin_item())
931+
&& t != &token::Semi
932+
&& t != &token::Pound)
931933
// Avoid triggering with too many trailing `#` in raw string.
932934
|| (sm.is_multiline(
933-
self.prev_token.span.shrink_to_hi().until(self.token.span.shrink_to_lo())
935+
self.prev_token.span.shrink_to_hi().until(self.token.span.shrink_to_lo()),
934936
) && t == &token::Pound)
935937
}) && !expected.contains(&TokenType::Token(token::Comma))
936938
{

compiler/rustc_target/src/spec/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1028,6 +1028,7 @@ supported_targets! {
10281028
("mipsel-sony-psp", mipsel_sony_psp),
10291029
("mipsel-unknown-none", mipsel_unknown_none),
10301030
("thumbv4t-none-eabi", thumbv4t_none_eabi),
1031+
("armv4t-none-eabi", armv4t_none_eabi),
10311032

10321033
("aarch64_be-unknown-linux-gnu", aarch64_be_unknown_linux_gnu),
10331034
("aarch64-unknown-linux-gnu_ilp32", aarch64_unknown_linux_gnu_ilp32),

compiler/rustc_trait_selection/src/traits/coherence.rs

+8-13
Original file line numberDiff line numberDiff line change
@@ -342,10 +342,8 @@ fn equate<'cx, 'tcx>(
342342
};
343343

344344
let selcx = &mut SelectionContext::new(&infcx);
345-
let opt_failing_obligation = obligations
346-
.into_iter()
347-
.chain(more_obligations)
348-
.find(|o| negative_impl_exists(selcx, impl_env, o));
345+
let opt_failing_obligation =
346+
obligations.into_iter().chain(more_obligations).find(|o| negative_impl_exists(selcx, o));
349347

350348
if let Some(failing_obligation) = opt_failing_obligation {
351349
debug!("overlap: obligation unsatisfiable {:?}", failing_obligation);
@@ -359,18 +357,15 @@ fn equate<'cx, 'tcx>(
359357
#[instrument(level = "debug", skip(selcx))]
360358
fn negative_impl_exists<'cx, 'tcx>(
361359
selcx: &SelectionContext<'cx, 'tcx>,
362-
param_env: ty::ParamEnv<'tcx>,
363360
o: &PredicateObligation<'tcx>,
364361
) -> bool {
365-
let infcx = &selcx.infcx().fork();
366-
367-
if resolve_negative_obligation(infcx, param_env, o) {
362+
if resolve_negative_obligation(selcx.infcx().fork(), o) {
368363
return true;
369364
}
370365

371366
// Try to prove a negative obligation exists for super predicates
372-
for o in util::elaborate_predicates(infcx.tcx, iter::once(o.predicate)) {
373-
if resolve_negative_obligation(infcx, param_env, &o) {
367+
for o in util::elaborate_predicates(selcx.tcx(), iter::once(o.predicate)) {
368+
if resolve_negative_obligation(selcx.infcx().fork(), &o) {
374369
return true;
375370
}
376371
}
@@ -380,8 +375,7 @@ fn negative_impl_exists<'cx, 'tcx>(
380375

381376
#[instrument(level = "debug", skip(infcx))]
382377
fn resolve_negative_obligation<'cx, 'tcx>(
383-
infcx: &InferCtxt<'cx, 'tcx>,
384-
param_env: ty::ParamEnv<'tcx>,
378+
infcx: InferCtxt<'cx, 'tcx>,
385379
o: &PredicateObligation<'tcx>,
386380
) -> bool {
387381
let tcx = infcx.tcx;
@@ -390,7 +384,8 @@ fn resolve_negative_obligation<'cx, 'tcx>(
390384
return false;
391385
};
392386

393-
let errors = super::fully_solve_obligation(infcx, o);
387+
let param_env = o.param_env;
388+
let errors = super::fully_solve_obligation(&infcx, o);
394389
if !errors.is_empty() {
395390
return false;
396391
}

compiler/rustc_typeck/src/check/wfcheck.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ fn check_gat_where_clauses(tcx: TyCtxt<'_>, associated_items: &[hir::TraitItemRe
387387
tcx,
388388
param_env,
389389
item_hir_id,
390-
sig.output(),
390+
sig.inputs_and_output,
391391
// We also assume that all of the function signature's parameter types
392392
// are well formed.
393393
&sig.inputs().iter().copied().collect(),

library/core/src/mem/maybe_uninit.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,8 @@ use crate::slice;
130130
/// MaybeUninit::uninit().assume_init()
131131
/// };
132132
///
133-
/// // Dropping a `MaybeUninit` does nothing. Thus using raw pointer
134-
/// // assignment instead of `ptr::write` does not cause the old
135-
/// // uninitialized value to be dropped. Also if there is a panic during
136-
/// // this loop, we have a memory leak, but there is no memory safety
137-
/// // issue.
133+
/// // Dropping a `MaybeUninit` does nothing, so if there is a panic during this loop,
134+
/// // we have a memory leak, but there is no memory safety issue.
138135
/// for elem in &mut data[..] {
139136
/// elem.write(vec![42]);
140137
/// }

src/bootstrap/dist.rs

+2-9
Original file line numberDiff line numberDiff line change
@@ -1226,17 +1226,10 @@ impl Step for Rustfmt {
12261226

12271227
let rustfmt = builder
12281228
.ensure(tool::Rustfmt { compiler, target, extra_features: Vec::new() })
1229-
.or_else(|| {
1230-
missing_tool("Rustfmt", builder.build.config.missing_tools);
1231-
None
1232-
})?;
1229+
.expect("rustfmt expected to build - essential tool");
12331230
let cargofmt = builder
12341231
.ensure(tool::Cargofmt { compiler, target, extra_features: Vec::new() })
1235-
.or_else(|| {
1236-
missing_tool("Cargofmt", builder.build.config.missing_tools);
1237-
None
1238-
})?;
1239-
1232+
.expect("cargo fmt expected to build - essential tool");
12401233
let mut tarball = Tarball::new(builder, "rustfmt", &target.triple);
12411234
tarball.set_overlay(OverlayKind::Rustfmt);
12421235
tarball.is_preview(true);

0 commit comments

Comments
 (0)