Skip to content

Commit 13e0fbc

Browse files
committed
Auto merge of #69360 - Mark-Simulacrum:beta-next, r=Mark-Simulacrum
[beta] beta backports This backports the following PRs: * Revert "Remove `checked_add` in `Layout::repeat`" #69241 * Do not ICE when encountering `yield` inside `async` block #69175 * Fix MIR typeck soundness holes #69145 * Fix extra subslice lowering #69128 * Correct ICE caused by macros generating invalid spans. #68611 * Make conflicting_repr_hints a deny-by-default c-future-compat lint #68586
2 parents 86f329b + e553243 commit 13e0fbc

27 files changed

+344
-64
lines changed

src/ci/azure-pipelines/steps/run.yml

+3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ steps:
3131
- bash: src/ci/scripts/setup-environment.sh
3232
displayName: Setup environment
3333

34+
- bash: src/ci/scripts/clean-disk.sh
35+
displayName: Clean disk
36+
3437
- bash: src/ci/scripts/should-skip-this.sh
3538
displayName: Decide whether to run this job
3639

src/ci/scripts/clean-disk.sh

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
# This script deletes some of the Azure-provided artifacts. We don't use these,
3+
# and disk space is at a premium on our builders.
4+
5+
set -euo pipefail
6+
IFS=$'\n\t'
7+
8+
source "$(cd "$(dirname "$0")" && pwd)/../shared.sh"
9+
10+
# All the Linux builds happen inside Docker.
11+
if isLinux; then
12+
# 6.7GB
13+
sudo rm -rf /opt/ghc
14+
# 16GB
15+
sudo rm -rf /usr/share/dotnet
16+
fi

src/libcore/alloc.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -241,11 +241,13 @@ impl Layout {
241241
#[unstable(feature = "alloc_layout_extra", issue = "55724")]
242242
#[inline]
243243
pub fn repeat(&self, n: usize) -> Result<(Self, usize), LayoutErr> {
244-
// This cannot overflow. Quoting from the invariant of Layout:
245-
// > `size`, when rounded up to the nearest multiple of `align`,
246-
// > must not overflow (i.e., the rounded value must be less than
247-
// > `usize::MAX`)
248-
let padded_size = self.size() + self.padding_needed_for(self.align());
244+
// Warning, removing the checked_add here led to segfaults in #67174. Further
245+
// analysis in #69225 seems to indicate that this is an LTO-related
246+
// miscompilation, so #67174 might be able to be reapplied in the future.
247+
let padded_size = self
248+
.size()
249+
.checked_add(self.padding_needed_for(self.align()))
250+
.ok_or(LayoutErr { private: () })?;
249251
let alloc_size = padded_size.checked_mul(n).ok_or(LayoutErr { private: () })?;
250252

251253
unsafe {

src/librustc/hir/check_attr.rs

+12-9
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use rustc_hir::def_id::DefId;
1414
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
1515
use rustc_hir::DUMMY_HIR_ID;
1616
use rustc_hir::{self, HirId, Item, ItemKind, TraitItem, TraitItemKind};
17-
use rustc_session::lint::builtin::UNUSED_ATTRIBUTES;
17+
use rustc_session::lint::builtin::{CONFLICTING_REPR_HINTS, UNUSED_ATTRIBUTES};
1818
use rustc_span::symbol::sym;
1919
use rustc_span::Span;
2020
use syntax::ast::Attribute;
@@ -196,7 +196,7 @@ impl CheckAttrVisitor<'tcx> {
196196
self.tcx.codegen_fn_attrs(self.tcx.hir().local_def_id(hir_id));
197197
}
198198

199-
self.check_repr(attrs, span, target, item);
199+
self.check_repr(attrs, span, target, item, hir_id);
200200
self.check_used(attrs, target);
201201
}
202202

@@ -357,6 +357,7 @@ impl CheckAttrVisitor<'tcx> {
357357
span: &Span,
358358
target: Target,
359359
item: Option<&Item<'_>>,
360+
hir_id: HirId,
360361
) {
361362
// Extract the names of all repr hints, e.g., [foo, bar, align] for:
362363
// ```
@@ -446,13 +447,15 @@ impl CheckAttrVisitor<'tcx> {
446447
|| (is_simd && is_c)
447448
|| (int_reprs == 1 && is_c && item.map_or(false, |item| is_c_like_enum(item)))
448449
{
449-
struct_span_err!(
450-
self.tcx.sess,
451-
hint_spans.collect::<Vec<Span>>(),
452-
E0566,
453-
"conflicting representation hints",
454-
)
455-
.emit();
450+
self.tcx
451+
.struct_span_lint_hir(
452+
CONFLICTING_REPR_HINTS,
453+
hir_id,
454+
hint_spans.collect::<Vec<Span>>(),
455+
"conflicting representation hints",
456+
)
457+
.code(rustc_errors::error_code!(E0566))
458+
.emit();
456459
}
457460
}
458461

src/librustc/hir/map/hir_id_validator.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_hir::intravisit;
77
use rustc_hir::itemlikevisit::ItemLikeVisitor;
88
use rustc_hir::{HirId, ItemLocalId};
99

10-
pub fn check_crate(hir_map: &Map<'_>) {
10+
pub fn check_crate(hir_map: &Map<'_>, sess: &rustc_session::Session) {
1111
hir_map.dep_graph.assert_ignored();
1212

1313
let errors = Lock::new(Vec::new());
@@ -24,7 +24,7 @@ pub fn check_crate(hir_map: &Map<'_>) {
2424

2525
if !errors.is_empty() {
2626
let message = errors.iter().fold(String::new(), |s1, s2| s1 + "\n" + s2);
27-
bug!("{}", message);
27+
sess.delay_span_bug(rustc_span::DUMMY_SP, &message);
2828
}
2929
}
3030

src/librustc/hir/map/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1271,7 +1271,7 @@ pub fn map_crate<'hir>(
12711271
};
12721272

12731273
sess.time("validate_HIR_map", || {
1274-
hir_id_validator::check_crate(&map);
1274+
hir_id_validator::check_crate(&map, sess);
12751275
});
12761276

12771277
map

src/librustc_ast_lowering/pat.rs

+11-6
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,13 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
128128
let mut slice = None;
129129
let mut prev_rest_span = None;
130130

131+
// Lowers `$bm $ident @ ..` to `$bm $ident @ _`.
132+
let lower_rest_sub = |this: &mut Self, pat, bm, ident, sub| {
133+
let lower_sub = |this: &mut Self| Some(this.pat_wild_with_node_id_of(sub));
134+
let node = this.lower_pat_ident(pat, bm, ident, lower_sub);
135+
this.pat_with_node_id_of(pat, node)
136+
};
137+
131138
let mut iter = pats.iter();
132139
// Lower all the patterns until the first occurrence of a sub-slice pattern.
133140
for pat in iter.by_ref() {
@@ -142,9 +149,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
142149
// Record, lower it to `$binding_mode $ident @ _`, and stop here.
143150
PatKind::Ident(ref bm, ident, Some(ref sub)) if sub.is_rest() => {
144151
prev_rest_span = Some(sub.span);
145-
let lower_sub = |this: &mut Self| Some(this.pat_wild_with_node_id_of(sub));
146-
let node = self.lower_pat_ident(pat, bm, ident, lower_sub);
147-
slice = Some(self.pat_with_node_id_of(pat, node));
152+
slice = Some(lower_rest_sub(self, pat, bm, ident, sub));
148153
break;
149154
}
150155
// It was not a subslice pattern so lower it normally.
@@ -157,9 +162,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
157162
// There was a previous subslice pattern; make sure we don't allow more.
158163
let rest_span = match pat.kind {
159164
PatKind::Rest => Some(pat.span),
160-
PatKind::Ident(.., Some(ref sub)) if sub.is_rest() => {
161-
// The `HirValidator` is merciless; add a `_` pattern to avoid ICEs.
162-
after.push(self.pat_wild_with_node_id_of(pat));
165+
PatKind::Ident(ref bm, ident, Some(ref sub)) if sub.is_rest() => {
166+
// #69103: Lower into `binding @ _` as above to avoid ICEs.
167+
after.push(lower_rest_sub(self, pat, bm, ident, sub));
163168
Some(sub.span)
164169
}
165170
_ => None,

src/librustc_errors/emitter.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use crate::{
1919
pluralize, CodeSuggestion, Diagnostic, DiagnosticId, Level, SubDiagnostic, SuggestionStyle,
2020
};
2121

22+
use log::*;
2223
use rustc_data_structures::fx::FxHashMap;
2324
use rustc_data_structures::sync::Lrc;
2425
use rustc_span::hygiene::{ExpnKind, MacroKind};
@@ -2108,7 +2109,13 @@ impl<'a> Drop for WritableDst<'a> {
21082109
/// Whether the original and suggested code are visually similar enough to warrant extra wording.
21092110
pub fn is_case_difference(sm: &SourceMap, suggested: &str, sp: Span) -> bool {
21102111
// FIXME: this should probably be extended to also account for `FO0` → `FOO` and unicode.
2111-
let found = sm.span_to_snippet(sp).unwrap();
2112+
let found = match sm.span_to_snippet(sp) {
2113+
Ok(snippet) => snippet,
2114+
Err(e) => {
2115+
warn!("Invalid span {:?}. Err={:?}", sp, e);
2116+
return false;
2117+
}
2118+
};
21122119
let ascii_confusables = &['c', 'f', 'i', 'k', 'o', 's', 'u', 'v', 'w', 'x', 'y', 'z'];
21132120
// All the chars that differ in capitalization are confusable (above):
21142121
let confusable = found

src/librustc_mir/borrow_check/type_check/mod.rs

+41-29
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> {
310310
);
311311
}
312312
} else {
313+
let tcx = self.tcx();
313314
if let ty::ConstKind::Unevaluated(def_id, substs, promoted) = constant.literal.val {
314315
if let Some(promoted) = promoted {
315316
let check_err = |verifier: &mut TypeVerifier<'a, 'b, 'tcx>,
@@ -359,10 +360,23 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> {
359360
);
360361
}
361362
}
363+
} else if let Some(static_def_id) = constant.check_static_ptr(tcx) {
364+
let unnormalized_ty = tcx.type_of(static_def_id);
365+
let locations = location.to_locations();
366+
let normalized_ty = self.cx.normalize(unnormalized_ty, locations);
367+
let literal_ty = constant.literal.ty.builtin_deref(true).unwrap().ty;
368+
369+
if let Err(terr) = self.cx.eq_types(
370+
normalized_ty,
371+
literal_ty,
372+
locations,
373+
ConstraintCategory::Boring,
374+
) {
375+
span_mirbug!(self, constant, "bad static type {:?} ({:?})", constant, terr);
376+
}
362377
}
363-
if let ty::FnDef(def_id, substs) = constant.literal.ty.kind {
364-
let tcx = self.tcx();
365378

379+
if let ty::FnDef(def_id, substs) = constant.literal.ty.kind {
366380
let instantiated_predicates = tcx.predicates_of(def_id).instantiate(tcx, substs);
367381
self.cx.normalize_and_prove_instantiated_predicates(
368382
instantiated_predicates,
@@ -467,33 +481,6 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
467481

468482
let mut place_ty = PlaceTy::from_ty(self.body.local_decls[place.local].ty);
469483

470-
if place.projection.is_empty() {
471-
if let PlaceContext::NonMutatingUse(NonMutatingUseContext::Copy) = context {
472-
let tcx = self.tcx();
473-
let trait_ref = ty::TraitRef {
474-
def_id: tcx.lang_items().copy_trait().unwrap(),
475-
substs: tcx.mk_substs_trait(place_ty.ty, &[]),
476-
};
477-
478-
// To have a `Copy` operand, the type `T` of the
479-
// value must be `Copy`. Note that we prove that `T: Copy`,
480-
// rather than using the `is_copy_modulo_regions`
481-
// test. This is important because
482-
// `is_copy_modulo_regions` ignores the resulting region
483-
// obligations and assumes they pass. This can result in
484-
// bounds from `Copy` impls being unsoundly ignored (e.g.,
485-
// #29149). Note that we decide to use `Copy` before knowing
486-
// whether the bounds fully apply: in effect, the rule is
487-
// that if a value of some type could implement `Copy`, then
488-
// it must.
489-
self.cx.prove_trait_ref(
490-
trait_ref,
491-
location.to_locations(),
492-
ConstraintCategory::CopyBound,
493-
);
494-
}
495-
}
496-
497484
for elem in place.projection.iter() {
498485
if place_ty.variant_index.is_none() {
499486
if place_ty.ty.references_error() {
@@ -504,6 +491,31 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
504491
place_ty = self.sanitize_projection(place_ty, elem, place, location)
505492
}
506493

494+
if let PlaceContext::NonMutatingUse(NonMutatingUseContext::Copy) = context {
495+
let tcx = self.tcx();
496+
let trait_ref = ty::TraitRef {
497+
def_id: tcx.lang_items().copy_trait().unwrap(),
498+
substs: tcx.mk_substs_trait(place_ty.ty, &[]),
499+
};
500+
501+
// To have a `Copy` operand, the type `T` of the
502+
// value must be `Copy`. Note that we prove that `T: Copy`,
503+
// rather than using the `is_copy_modulo_regions`
504+
// test. This is important because
505+
// `is_copy_modulo_regions` ignores the resulting region
506+
// obligations and assumes they pass. This can result in
507+
// bounds from `Copy` impls being unsoundly ignored (e.g.,
508+
// #29149). Note that we decide to use `Copy` before knowing
509+
// whether the bounds fully apply: in effect, the rule is
510+
// that if a value of some type could implement `Copy`, then
511+
// it must.
512+
self.cx.prove_trait_ref(
513+
trait_ref,
514+
location.to_locations(),
515+
ConstraintCategory::CopyBound,
516+
);
517+
}
518+
507519
place_ty
508520
}
509521

src/librustc_session/lint/builtin.rs

+11
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@ declare_lint! {
1818
};
1919
}
2020

21+
declare_lint! {
22+
pub CONFLICTING_REPR_HINTS,
23+
Deny,
24+
"conflicts between `#[repr(..)]` hints that were previously accepted and used in practice",
25+
@future_incompatible = FutureIncompatibleInfo {
26+
reference: "issue #68585 <https://github.com/rust-lang/rust/issues/68585>",
27+
edition: None,
28+
};
29+
}
30+
2131
declare_lint! {
2232
pub META_VARIABLE_MISUSE,
2333
Allow,
@@ -520,6 +530,7 @@ declare_lint_pass! {
520530
MACRO_USE_EXTERN_CRATE,
521531
MACRO_EXPANDED_MACRO_EXPORTS_ACCESSED_BY_ABSOLUTE_PATHS,
522532
ILL_FORMED_ATTRIBUTE_INPUT,
533+
CONFLICTING_REPR_HINTS,
523534
META_VARIABLE_MISUSE,
524535
DEPRECATED_IN_FUTURE,
525536
AMBIGUOUS_ASSOCIATED_ITEMS,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// We used to not lower the extra `b @ ..` into `b @ _` which meant that no type
2+
// was registered for the binding `b` although it passed through resolve.
3+
// This resulted in an ICE (#69103).
4+
5+
fn main() {
6+
let [a @ .., b @ ..] = &mut [1, 2];
7+
//~^ ERROR `..` can only be used once per slice pattern
8+
b;
9+
10+
let [.., c @ ..] = [1, 2];
11+
//~^ ERROR `..` can only be used once per slice pattern
12+
c;
13+
14+
// This never ICEd, but let's make sure it won't regress either.
15+
let (.., d @ ..) = (1, 2);
16+
//~^ ERROR `..` patterns are not allowed here
17+
d;
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
error: `..` can only be used once per slice pattern
2+
--> $DIR/issue-69103-extra-binding-subslice.rs:6:22
3+
|
4+
LL | let [a @ .., b @ ..] = &mut [1, 2];
5+
| -- ^^ can only be used once per slice pattern
6+
| |
7+
| previously used here
8+
9+
error: `..` can only be used once per slice pattern
10+
--> $DIR/issue-69103-extra-binding-subslice.rs:10:18
11+
|
12+
LL | let [.., c @ ..] = [1, 2];
13+
| -- ^^ can only be used once per slice pattern
14+
| |
15+
| previously used here
16+
17+
error: `..` patterns are not allowed here
18+
--> $DIR/issue-69103-extra-binding-subslice.rs:15:18
19+
|
20+
LL | let (.., d @ ..) = (1, 2);
21+
| ^^
22+
|
23+
= note: only allowed in tuple, tuple struct, and slice patterns
24+
25+
error: aborting due to 3 previous errors
26+

src/test/ui/conflicting-repr-hints.rs

+2
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ enum B {
1111
}
1212

1313
#[repr(C, u64)] //~ ERROR conflicting representation hints
14+
//~^ WARN this was previously accepted
1415
enum C {
1516
C,
1617
}
1718

1819
#[repr(u32, u64)] //~ ERROR conflicting representation hints
20+
//~^ WARN this was previously accepted
1921
enum D {
2022
D,
2123
}

0 commit comments

Comments
 (0)