Skip to content

Commit 466198c

Browse files
authored
Merge pull request #2519 from rust-lang/rustc-pull
Rustc pull update
2 parents 9c99623 + 645b85e commit 466198c

File tree

848 files changed

+10018
-5141
lines changed

Some content is hidden

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

848 files changed

+10018
-5141
lines changed

Cargo.lock

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4255,6 +4255,7 @@ dependencies = [
42554255
"rustc-literal-escaper",
42564256
"rustc_ast",
42574257
"rustc_ast_pretty",
4258+
"rustc_attr_parsing",
42584259
"rustc_data_structures",
42594260
"rustc_errors",
42604261
"rustc_feature",
@@ -4563,7 +4564,10 @@ dependencies = [
45634564
"rustc_macros",
45644565
"rustc_serialize",
45654566
"rustc_span",
4567+
"serde",
4568+
"serde_derive",
45664569
"serde_json",
4570+
"serde_path_to_error",
45674571
"tracing",
45684572
]
45694573

@@ -4955,6 +4959,16 @@ dependencies = [
49554959
"serde",
49564960
]
49574961

4962+
[[package]]
4963+
name = "serde_path_to_error"
4964+
version = "0.1.17"
4965+
source = "registry+https://github.com/rust-lang/crates.io-index"
4966+
checksum = "59fab13f937fa393d08645bf3a84bdfe86e296747b506ada67bb15f10f218b2a"
4967+
dependencies = [
4968+
"itoa",
4969+
"serde",
4970+
]
4971+
49584972
[[package]]
49594973
name = "serde_spanned"
49604974
version = "0.6.9"

compiler/rustc_abi/src/layout.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,6 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
313313
scalar_valid_range: (Bound<u128>, Bound<u128>),
314314
discr_range_of_repr: impl Fn(i128, i128) -> (Integer, bool),
315315
discriminants: impl Iterator<Item = (VariantIdx, i128)>,
316-
dont_niche_optimize_enum: bool,
317316
always_sized: bool,
318317
) -> LayoutCalculatorResult<FieldIdx, VariantIdx, F> {
319318
let (present_first, present_second) = {
@@ -352,13 +351,7 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
352351
// structs. (We have also handled univariant enums
353352
// that allow representation optimization.)
354353
assert!(is_enum);
355-
self.layout_of_enum(
356-
repr,
357-
variants,
358-
discr_range_of_repr,
359-
discriminants,
360-
dont_niche_optimize_enum,
361-
)
354+
self.layout_of_enum(repr, variants, discr_range_of_repr, discriminants)
362355
}
363356
}
364357

@@ -599,7 +592,6 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
599592
variants: &IndexSlice<VariantIdx, IndexVec<FieldIdx, F>>,
600593
discr_range_of_repr: impl Fn(i128, i128) -> (Integer, bool),
601594
discriminants: impl Iterator<Item = (VariantIdx, i128)>,
602-
dont_niche_optimize_enum: bool,
603595
) -> LayoutCalculatorResult<FieldIdx, VariantIdx, F> {
604596
// Until we've decided whether to use the tagged or
605597
// niche filling LayoutData, we don't want to intern the
@@ -618,7 +610,7 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
618610
}
619611

620612
let calculate_niche_filling_layout = || -> Option<TmpLayout<FieldIdx, VariantIdx>> {
621-
if dont_niche_optimize_enum {
613+
if repr.inhibit_enum_layout_opt() {
622614
return None;
623615
}
624616

compiler/rustc_abi/src/lib.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,6 +1376,28 @@ impl WrappingRange {
13761376
}
13771377
}
13781378

1379+
/// Returns `true` if all the values in `other` are contained in this range,
1380+
/// when the values are considered as having width `size`.
1381+
#[inline(always)]
1382+
pub fn contains_range(&self, other: Self, size: Size) -> bool {
1383+
if self.is_full_for(size) {
1384+
true
1385+
} else {
1386+
let trunc = |x| size.truncate(x);
1387+
1388+
let delta = self.start;
1389+
let max = trunc(self.end.wrapping_sub(delta));
1390+
1391+
let other_start = trunc(other.start.wrapping_sub(delta));
1392+
let other_end = trunc(other.end.wrapping_sub(delta));
1393+
1394+
// Having shifted both input ranges by `delta`, now we only need to check
1395+
// whether `0..=max` contains `other_start..=other_end`, which can only
1396+
// happen if the other doesn't wrap since `self` isn't everything.
1397+
(other_start <= other_end) && (other_end <= max)
1398+
}
1399+
}
1400+
13791401
/// Returns `self` with replaced `start`
13801402
#[inline(always)]
13811403
fn with_start(mut self, start: u128) -> Self {

compiler/rustc_abi/src/tests.rs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,66 @@ fn align_constants() {
55
assert_eq!(Align::ONE, Align::from_bytes(1).unwrap());
66
assert_eq!(Align::EIGHT, Align::from_bytes(8).unwrap());
77
}
8+
9+
#[test]
10+
fn wrapping_range_contains_range() {
11+
let size16 = Size::from_bytes(16);
12+
13+
let a = WrappingRange { start: 10, end: 20 };
14+
assert!(a.contains_range(a, size16));
15+
assert!(a.contains_range(WrappingRange { start: 11, end: 19 }, size16));
16+
assert!(a.contains_range(WrappingRange { start: 10, end: 10 }, size16));
17+
assert!(a.contains_range(WrappingRange { start: 20, end: 20 }, size16));
18+
assert!(!a.contains_range(WrappingRange { start: 10, end: 21 }, size16));
19+
assert!(!a.contains_range(WrappingRange { start: 9, end: 20 }, size16));
20+
assert!(!a.contains_range(WrappingRange { start: 4, end: 6 }, size16));
21+
assert!(!a.contains_range(WrappingRange { start: 24, end: 26 }, size16));
22+
23+
assert!(!a.contains_range(WrappingRange { start: 16, end: 14 }, size16));
24+
25+
let b = WrappingRange { start: 20, end: 10 };
26+
assert!(b.contains_range(b, size16));
27+
assert!(b.contains_range(WrappingRange { start: 20, end: 20 }, size16));
28+
assert!(b.contains_range(WrappingRange { start: 10, end: 10 }, size16));
29+
assert!(b.contains_range(WrappingRange { start: 0, end: 10 }, size16));
30+
assert!(b.contains_range(WrappingRange { start: 20, end: 30 }, size16));
31+
assert!(b.contains_range(WrappingRange { start: 20, end: 9 }, size16));
32+
assert!(b.contains_range(WrappingRange { start: 21, end: 10 }, size16));
33+
assert!(b.contains_range(WrappingRange { start: 999, end: 9999 }, size16));
34+
assert!(b.contains_range(WrappingRange { start: 999, end: 9 }, size16));
35+
assert!(!b.contains_range(WrappingRange { start: 19, end: 19 }, size16));
36+
assert!(!b.contains_range(WrappingRange { start: 11, end: 11 }, size16));
37+
assert!(!b.contains_range(WrappingRange { start: 19, end: 11 }, size16));
38+
assert!(!b.contains_range(WrappingRange { start: 11, end: 19 }, size16));
39+
40+
let f = WrappingRange { start: 0, end: u128::MAX };
41+
assert!(f.contains_range(WrappingRange { start: 10, end: 20 }, size16));
42+
assert!(f.contains_range(WrappingRange { start: 20, end: 10 }, size16));
43+
44+
let g = WrappingRange { start: 2, end: 1 };
45+
assert!(g.contains_range(WrappingRange { start: 10, end: 20 }, size16));
46+
assert!(g.contains_range(WrappingRange { start: 20, end: 10 }, size16));
47+
48+
let size1 = Size::from_bytes(1);
49+
let u8r = WrappingRange { start: 0, end: 255 };
50+
let i8r = WrappingRange { start: 128, end: 127 };
51+
assert!(u8r.contains_range(i8r, size1));
52+
assert!(i8r.contains_range(u8r, size1));
53+
assert!(!u8r.contains_range(i8r, size16));
54+
assert!(i8r.contains_range(u8r, size16));
55+
56+
let boolr = WrappingRange { start: 0, end: 1 };
57+
assert!(u8r.contains_range(boolr, size1));
58+
assert!(i8r.contains_range(boolr, size1));
59+
assert!(!boolr.contains_range(u8r, size1));
60+
assert!(!boolr.contains_range(i8r, size1));
61+
62+
let cmpr = WrappingRange { start: 255, end: 1 };
63+
assert!(u8r.contains_range(cmpr, size1));
64+
assert!(i8r.contains_range(cmpr, size1));
65+
assert!(!cmpr.contains_range(u8r, size1));
66+
assert!(!cmpr.contains_range(i8r, size1));
67+
68+
assert!(!boolr.contains_range(cmpr, size1));
69+
assert!(cmpr.contains_range(boolr, size1));
70+
}

compiler/rustc_ast/src/ast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2849,7 +2849,7 @@ impl InlineAsmOperand {
28492849
}
28502850
}
28512851

2852-
#[derive(Clone, Copy, Encodable, Decodable, Debug, HashStable_Generic, Walkable)]
2852+
#[derive(Clone, Copy, Encodable, Decodable, Debug, HashStable_Generic, Walkable, PartialEq, Eq)]
28532853
pub enum AsmMacro {
28542854
/// The `asm!` macro
28552855
Asm,

compiler/rustc_attr_parsing/src/attributes/stability.rs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,15 @@ impl<S: Stage> AttributeParser<S> for StabilityParser {
7474
template!(NameValueStr: "deprecation message"),
7575
|this, cx, args| {
7676
reject_outside_std!(cx);
77-
this.allowed_through_unstable_modules =
78-
args.name_value().and_then(|i| i.value_as_str())
77+
let Some(nv) = args.name_value() else {
78+
cx.expected_name_value(cx.attr_span, None);
79+
return;
80+
};
81+
let Some(value_str) = nv.value_as_str() else {
82+
cx.expected_string_literal(nv.value_span, Some(nv.value_as_lit()));
83+
return;
84+
};
85+
this.allowed_through_unstable_modules = Some(value_str);
7986
},
8087
),
8188
];
@@ -247,7 +254,12 @@ pub(crate) fn parse_stability<S: Stage>(
247254
let mut feature = None;
248255
let mut since = None;
249256

250-
for param in args.list()?.mixed() {
257+
let ArgParser::List(list) = args else {
258+
cx.expected_list(cx.attr_span);
259+
return None;
260+
};
261+
262+
for param in list.mixed() {
251263
let param_span = param.span();
252264
let Some(param) = param.meta_item() else {
253265
cx.emit_err(session_diagnostics::UnsupportedLiteral {
@@ -322,7 +334,13 @@ pub(crate) fn parse_unstability<S: Stage>(
322334
let mut is_soft = false;
323335
let mut implied_by = None;
324336
let mut old_name = None;
325-
for param in args.list()?.mixed() {
337+
338+
let ArgParser::List(list) = args else {
339+
cx.expected_list(cx.attr_span);
340+
return None;
341+
};
342+
343+
for param in list.mixed() {
326344
let Some(param) = param.meta_item() else {
327345
cx.emit_err(session_diagnostics::UnsupportedLiteral {
328346
span: param.span(),

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,6 +1290,58 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
12901290
span,
12911291
format!("if `{ty}` implemented `Clone`, you could clone the value"),
12921292
);
1293+
} else if let ty::Adt(_, _) = ty.kind()
1294+
&& let Some(clone_trait) = self.infcx.tcx.lang_items().clone_trait()
1295+
{
1296+
// For cases like `Option<NonClone>`, where `Option<T>: Clone` if `T: Clone`, we point
1297+
// at the types that should be `Clone`.
1298+
let ocx = ObligationCtxt::new_with_diagnostics(self.infcx);
1299+
let cause = ObligationCause::misc(expr.span, self.mir_def_id());
1300+
ocx.register_bound(cause, self.infcx.param_env, ty, clone_trait);
1301+
let errors = ocx.select_all_or_error();
1302+
if errors.iter().all(|error| {
1303+
match error.obligation.predicate.as_clause().and_then(|c| c.as_trait_clause()) {
1304+
Some(clause) => match clause.self_ty().skip_binder().kind() {
1305+
ty::Adt(def, _) => def.did().is_local() && clause.def_id() == clone_trait,
1306+
_ => false,
1307+
},
1308+
None => false,
1309+
}
1310+
}) {
1311+
let mut type_spans = vec![];
1312+
let mut types = FxIndexSet::default();
1313+
for clause in errors
1314+
.iter()
1315+
.filter_map(|e| e.obligation.predicate.as_clause())
1316+
.filter_map(|c| c.as_trait_clause())
1317+
{
1318+
let ty::Adt(def, _) = clause.self_ty().skip_binder().kind() else { continue };
1319+
type_spans.push(self.infcx.tcx.def_span(def.did()));
1320+
types.insert(
1321+
self.infcx
1322+
.tcx
1323+
.short_string(clause.self_ty().skip_binder(), &mut err.long_ty_path()),
1324+
);
1325+
}
1326+
let mut span: MultiSpan = type_spans.clone().into();
1327+
for sp in type_spans {
1328+
span.push_span_label(sp, "consider implementing `Clone` for this type");
1329+
}
1330+
span.push_span_label(expr.span, "you could clone this value");
1331+
let types: Vec<_> = types.into_iter().collect();
1332+
let msg = match &types[..] {
1333+
[only] => format!("`{only}`"),
1334+
[head @ .., last] => format!(
1335+
"{} and `{last}`",
1336+
head.iter().map(|t| format!("`{t}`")).collect::<Vec<_>>().join(", ")
1337+
),
1338+
[] => unreachable!(),
1339+
};
1340+
err.span_note(
1341+
span,
1342+
format!("if {msg} implemented `Clone`, you could clone the value"),
1343+
);
1344+
}
12931345
}
12941346
}
12951347

0 commit comments

Comments
 (0)