Skip to content

Commit 542c040

Browse files
committed
Auto merge of #150228 - matthiaskrgr:rollup-ymp54q0, r=matthiaskrgr
Rollup of 11 pull requests Successful merges: - #146377 (Don't strip shebang in expr-ctxt `include!(…)`) - #149812 (Add const default for OnceCell and OnceLock) - #149882 (miri: add -Zbinary-dep-depinfo to dependency builds) - #150009 (Enable llvm-libunwind by default for Hexagon targets) - #150035 (fix docustring on fetch_or) - #150082 (tests/ui/traits/fmt-pointer-trait.rs: Add HRTB fn pointer case) - #150160 (Fix ICE (#149980) for invalid EII in statement position) - #150184 (mir_build: Use the same length type for `TestableCase::Slice` and `TestKind::Len`) - #150185 ([rustdoc] Add missing close tags in extern crate reexports) - #150191 (change non-canonical clone impl to {*self}, fix some doc comments) - #150203 (Drop the From derive macro from the v1 prelude) r? `@ghost` `@rustbot` modify labels: rollup
2 parents a6525d5 + c91cbcd commit 542c040

File tree

32 files changed

+175
-64
lines changed

32 files changed

+175
-64
lines changed

compiler/rustc_builtin_macros/src/eii.rs

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,18 @@ fn eii_(
6060
) -> Vec<Annotatable> {
6161
let eii_attr_span = ecx.with_def_site_ctxt(eii_attr_span);
6262

63-
let (item, stmt) = if let Annotatable::Item(item) = item {
64-
(item, false)
63+
let (item, wrap_item): (_, &dyn Fn(_) -> _) = if let Annotatable::Item(item) = item {
64+
(item, &Annotatable::Item)
6565
} else if let Annotatable::Stmt(ref stmt) = item
6666
&& let StmtKind::Item(ref item) = stmt.kind
6767
{
68-
(item.clone(), true)
68+
(item.clone(), &|item| {
69+
Annotatable::Stmt(Box::new(Stmt {
70+
id: DUMMY_NODE_ID,
71+
kind: StmtKind::Item(item),
72+
span: eii_attr_span,
73+
}))
74+
})
6975
} else {
7076
ecx.dcx().emit_err(EiiSharedMacroExpectedFunction {
7177
span: eii_attr_span,
@@ -74,23 +80,25 @@ fn eii_(
7480
return vec![item];
7581
};
7682

77-
let orig_item = item.clone();
78-
79-
let item = *item;
80-
81-
let ast::Item { attrs, id: _, span: _, vis, kind: ItemKind::Fn(func), tokens: _ } = item else {
83+
let ast::Item { attrs, id: _, span: _, vis, kind: ItemKind::Fn(func), tokens: _ } =
84+
item.as_ref()
85+
else {
8286
ecx.dcx().emit_err(EiiSharedMacroExpectedFunction {
8387
span: eii_attr_span,
8488
name: path_to_string(&meta_item.path),
8589
});
86-
return vec![Annotatable::Item(Box::new(item))];
90+
return vec![wrap_item(item)];
8791
};
92+
// only clone what we need
93+
let attrs = attrs.clone();
94+
let func = (**func).clone();
95+
let vis = vis.clone();
8896

8997
let attrs_from_decl =
9098
filter_attrs_for_multiple_eii_attr(ecx, attrs, eii_attr_span, &meta_item.path);
9199

92100
let Ok(macro_name) = name_for_impl_macro(ecx, &func, &meta_item) else {
93-
return vec![Annotatable::Item(orig_item)];
101+
return vec![wrap_item(item)];
94102
};
95103

96104
// span of the declaring item without attributes
@@ -115,7 +123,7 @@ fn eii_(
115123
ecx,
116124
eii_attr_span,
117125
item_span,
118-
*func,
126+
func,
119127
vis,
120128
&attrs_from_decl,
121129
)));
@@ -128,20 +136,7 @@ fn eii_(
128136
decl_span,
129137
)));
130138

131-
if stmt {
132-
return_items
133-
.into_iter()
134-
.map(|i| {
135-
Annotatable::Stmt(Box::new(Stmt {
136-
id: DUMMY_NODE_ID,
137-
kind: StmtKind::Item(i),
138-
span: eii_attr_span,
139-
}))
140-
})
141-
.collect()
142-
} else {
143-
return_items.into_iter().map(|i| Annotatable::Item(i)).collect()
144-
}
139+
return_items.into_iter().map(wrap_item).collect()
145140
}
146141

147142
/// Decide on the name of the macro that can be used to implement the EII.

compiler/rustc_builtin_macros/src/source_util.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,7 @@ pub(crate) fn expand_include<'cx>(
144144
let mut p = unwrap_or_emit_fatal(new_parser_from_file(
145145
self.psess,
146146
&self.path,
147-
// Don't strip frontmatter for backward compatibility, `---` may be the start of a
148-
// manifold negation. FIXME: Ideally, we wouldn't strip shebangs here either.
149-
StripTokens::Shebang,
147+
StripTokens::Nothing,
150148
Some(self.span),
151149
));
152150
let expr = parse_expr(&mut p).ok()?;

compiler/rustc_graphviz/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ impl<'a> Id<'a> {
416416
/// it in the generated .dot file. They can also provide more
417417
/// elaborate (and non-unique) label text that is used in the graphviz
418418
/// rendered output.
419-
419+
///
420420
/// The graph instance is responsible for providing the DOT compatible
421421
/// identifiers for the nodes and (optionally) rendered labels for the nodes and
422422
/// edges, as well as an identifier for the graph itself.

compiler/rustc_middle/src/ty/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2654,7 +2654,7 @@ struct InternedInSet<'tcx, T: ?Sized + PointeeSized>(&'tcx T);
26542654

26552655
impl<'tcx, T: 'tcx + ?Sized + PointeeSized> Clone for InternedInSet<'tcx, T> {
26562656
fn clone(&self) -> Self {
2657-
InternedInSet(self.0)
2657+
*self
26582658
}
26592659
}
26602660

compiler/rustc_mir_build/src/builder/matches/buckets.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
218218
&TestKind::Len { len: test_len, op: BinOp::Eq },
219219
&TestableCase::Slice { len, variable_length },
220220
) => {
221-
match (test_len.cmp(&(len as u64)), variable_length) {
221+
match (test_len.cmp(&len), variable_length) {
222222
(Ordering::Equal, false) => {
223223
// on true, min_len = len = $actual_length,
224224
// on false, len != $actual_length
@@ -251,7 +251,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
251251
&TestableCase::Slice { len, variable_length },
252252
) => {
253253
// the test is `$actual_len >= test_len`
254-
match (test_len.cmp(&(len as u64)), variable_length) {
254+
match (test_len.cmp(&len), variable_length) {
255255
(Ordering::Equal, true) => {
256256
// $actual_len >= test_len = pat_len,
257257
// so we can match.

compiler/rustc_mir_build/src/builder/matches/match_pair.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ impl<'tcx> MatchPairTree<'tcx> {
256256
None
257257
} else {
258258
Some(TestableCase::Slice {
259-
len: prefix.len() + suffix.len(),
259+
len: u64::try_from(prefix.len() + suffix.len()).unwrap(),
260260
variable_length: slice.is_some(),
261261
})
262262
}

compiler/rustc_mir_build/src/builder/matches/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1264,7 +1264,7 @@ enum TestableCase<'tcx> {
12641264
Variant { adt_def: ty::AdtDef<'tcx>, variant_index: VariantIdx },
12651265
Constant { value: ty::Value<'tcx> },
12661266
Range(Arc<PatRange<'tcx>>),
1267-
Slice { len: usize, variable_length: bool },
1267+
Slice { len: u64, variable_length: bool },
12681268
Deref { temp: Place<'tcx>, mutability: Mutability },
12691269
Never,
12701270
Or { pats: Box<[FlatPat<'tcx>]> },

compiler/rustc_mir_build/src/builder/matches/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
4747

4848
TestableCase::Slice { len, variable_length } => {
4949
let op = if variable_length { BinOp::Ge } else { BinOp::Eq };
50-
TestKind::Len { len: len as u64, op }
50+
TestKind::Len { len, op }
5151
}
5252

5353
TestableCase::Deref { temp, mutability } => TestKind::Deref { temp, mutability },

compiler/rustc_pattern_analysis/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ pub struct MatchArm<'p, Cx: PatCx> {
141141

142142
impl<'p, Cx: PatCx> Clone for MatchArm<'p, Cx> {
143143
fn clone(&self) -> Self {
144-
Self { pat: self.pat, has_guard: self.has_guard, arm_data: self.arm_data }
144+
*self
145145
}
146146
}
147147

compiler/rustc_pattern_analysis/src/pat.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,7 @@ pub(crate) enum PatOrWild<'p, Cx: PatCx> {
174174

175175
impl<'p, Cx: PatCx> Clone for PatOrWild<'p, Cx> {
176176
fn clone(&self) -> Self {
177-
match self {
178-
PatOrWild::Wild => PatOrWild::Wild,
179-
PatOrWild::Pat(pat) => PatOrWild::Pat(pat),
180-
}
177+
*self
181178
}
182179
}
183180

0 commit comments

Comments
 (0)