Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit fda509e

Browse files
committedJun 25, 2024·
Auto merge of rust-lang#126965 - matthiaskrgr:rollup-x3kamn8, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - rust-lang#126302 (Detect unused structs which derived Default) - rust-lang#126885 (Remove internal `PathBuf::as_mut_vec`) - rust-lang#126916 (Specify target specific linker for `riscv64gc-gnu` job) - rust-lang#126926 (Tweak a confusing comment in `create_match_candidates`) - rust-lang#126927 (core: VaArgSafe is an unsafe trait) - rust-lang#126932 (Tweak `FlatPat::new` to avoid a temporarily-invalid state) - rust-lang#126946 (Add missing slash in `const_eval_select` doc comment) - rust-lang#126947 (Delegation: ast lowering refactor) r? `@ghost` `@rustbot` modify labels: rollup
2 parents c290e9d + 4ebd69c commit fda509e

File tree

19 files changed

+227
-116
lines changed

19 files changed

+227
-116
lines changed
 

‎compiler/rustc_ast_lowering/src/delegation.rs

+49-58
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,18 @@ impl<'hir> LoweringContext<'_, 'hir> {
6666
let Ok(sig_id) = sig_id else {
6767
return false;
6868
};
69-
if let Some(local_sig_id) = sig_id.as_local() {
69+
self.has_self(sig_id, span)
70+
}
71+
72+
fn has_self(&self, def_id: DefId, span: Span) -> bool {
73+
if let Some(local_sig_id) = def_id.as_local() {
7074
// The value may be missing due to recursive delegation.
7175
// Error will be emmited later during HIR ty lowering.
7276
self.resolver.delegation_fn_sigs.get(&local_sig_id).map_or(false, |sig| sig.has_self)
7377
} else {
74-
match self.tcx.def_kind(sig_id) {
78+
match self.tcx.def_kind(def_id) {
7579
DefKind::Fn => false,
76-
DefKind::AssocFn => self.tcx.associated_item(sig_id).fn_has_self_parameter,
80+
DefKind::AssocFn => self.tcx.associated_item(def_id).fn_has_self_parameter,
7781
_ => span_bug!(span, "unexpected DefKind for delegation item"),
7882
}
7983
}
@@ -107,12 +111,17 @@ impl<'hir> LoweringContext<'_, 'hir> {
107111
span: Span,
108112
) -> Result<DefId, ErrorGuaranteed> {
109113
let sig_id = if self.is_in_trait_impl { item_id } else { path_id };
110-
let sig_id =
111-
self.resolver.get_partial_res(sig_id).and_then(|r| r.expect_full_res().opt_def_id());
112-
sig_id.ok_or_else(|| {
113-
self.tcx
114-
.dcx()
115-
.span_delayed_bug(span, "LoweringContext: couldn't resolve delegation item")
114+
self.get_resolution_id(sig_id, span)
115+
}
116+
117+
fn get_resolution_id(&self, node_id: NodeId, span: Span) -> Result<DefId, ErrorGuaranteed> {
118+
let def_id =
119+
self.resolver.get_partial_res(node_id).and_then(|r| r.expect_full_res().opt_def_id());
120+
def_id.ok_or_else(|| {
121+
self.tcx.dcx().span_delayed_bug(
122+
span,
123+
format!("LoweringContext: couldn't resolve node {:?} in delegation item", node_id),
124+
)
116125
})
117126
}
118127

@@ -122,7 +131,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
122131
predicates: &[],
123132
has_where_clause_predicates: false,
124133
where_clause_span: span,
125-
span: span,
134+
span,
126135
})
127136
}
128137

@@ -222,12 +231,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
222231
}));
223232

224233
let path = self.arena.alloc(hir::Path { span, res: Res::Local(param_id), segments });
225-
226-
hir::Expr {
227-
hir_id: self.next_id(),
228-
kind: hir::ExprKind::Path(hir::QPath::Resolved(None, path)),
229-
span,
230-
}
234+
self.mk_expr(hir::ExprKind::Path(hir::QPath::Resolved(None, path)), span)
231235
}
232236

233237
fn lower_delegation_body(
@@ -236,19 +240,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
236240
param_count: usize,
237241
span: Span,
238242
) -> BodyId {
239-
let path = self.lower_qpath(
240-
delegation.id,
241-
&delegation.qself,
242-
&delegation.path,
243-
ParamMode::Optional,
244-
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
245-
None,
246-
);
247243
let block = delegation.body.as_deref();
248244

249245
self.lower_body(|this| {
250-
let mut parameters: Vec<hir::Param<'_>> = Vec::new();
251-
let mut args: Vec<hir::Expr<'hir>> = Vec::new();
246+
let mut parameters: Vec<hir::Param<'_>> = Vec::with_capacity(param_count);
247+
let mut args: Vec<hir::Expr<'_>> = Vec::with_capacity(param_count);
252248

253249
for idx in 0..param_count {
254250
let (param, pat_node_id) = this.generate_param(span);
@@ -264,55 +260,49 @@ impl<'hir> LoweringContext<'_, 'hir> {
264260
};
265261
self_resolver.visit_block(block);
266262
let block = this.lower_block(block, false);
267-
hir::Expr {
268-
hir_id: this.next_id(),
269-
kind: hir::ExprKind::Block(block, None),
270-
span: block.span,
271-
}
263+
this.mk_expr(hir::ExprKind::Block(block, None), block.span)
272264
} else {
273265
let pat_hir_id = this.lower_node_id(pat_node_id);
274266
this.generate_arg(pat_hir_id, span)
275267
};
276268
args.push(arg);
277269
}
278270

279-
let args = self.arena.alloc_from_iter(args);
280-
let final_expr = this.generate_call(path, args);
271+
let final_expr = this.finalize_body_lowering(delegation, args, span);
281272
(this.arena.alloc_from_iter(parameters), final_expr)
282273
})
283274
}
284275

285-
fn generate_call(
276+
// Generates fully qualified call for the resulting body.
277+
fn finalize_body_lowering(
286278
&mut self,
287-
path: hir::QPath<'hir>,
288-
args: &'hir [hir::Expr<'hir>],
279+
delegation: &Delegation,
280+
args: Vec<hir::Expr<'hir>>,
281+
span: Span,
289282
) -> hir::Expr<'hir> {
290-
let callee = self.arena.alloc(hir::Expr {
291-
hir_id: self.next_id(),
292-
kind: hir::ExprKind::Path(path),
293-
span: path.span(),
294-
});
283+
let path = self.lower_qpath(
284+
delegation.id,
285+
&delegation.qself,
286+
&delegation.path,
287+
ParamMode::Optional,
288+
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
289+
None,
290+
);
295291

296-
let expr = self.arena.alloc(hir::Expr {
297-
hir_id: self.next_id(),
298-
kind: hir::ExprKind::Call(callee, args),
299-
span: path.span(),
300-
});
292+
let args = self.arena.alloc_from_iter(args);
293+
let path_expr = self.arena.alloc(self.mk_expr(hir::ExprKind::Path(path), span));
294+
let call = self.arena.alloc(self.mk_expr(hir::ExprKind::Call(path_expr, args), span));
301295

302296
let block = self.arena.alloc(hir::Block {
303297
stmts: &[],
304-
expr: Some(expr),
298+
expr: Some(call),
305299
hir_id: self.next_id(),
306300
rules: hir::BlockCheckMode::DefaultBlock,
307-
span: path.span(),
301+
span,
308302
targeted_by_break: false,
309303
});
310304

311-
hir::Expr {
312-
hir_id: self.next_id(),
313-
kind: hir::ExprKind::Block(block, None),
314-
span: path.span(),
315-
}
305+
self.mk_expr(hir::ExprKind::Block(block, None), span)
316306
}
317307

318308
fn generate_delegation_error(
@@ -333,11 +323,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
333323
let header = self.generate_header_error();
334324
let sig = hir::FnSig { decl, header, span };
335325

336-
let body_id = self.lower_body(|this| {
337-
let expr =
338-
hir::Expr { hir_id: this.next_id(), kind: hir::ExprKind::Err(err), span: span };
339-
(&[], expr)
340-
});
326+
let body_id = self.lower_body(|this| (&[], this.mk_expr(hir::ExprKind::Err(err), span)));
341327
DelegationResults { generics, body_id, sig }
342328
}
343329

@@ -349,6 +335,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
349335
abi: abi::Abi::Rust,
350336
}
351337
}
338+
339+
#[inline]
340+
fn mk_expr(&mut self, kind: hir::ExprKind<'hir>, span: Span) -> hir::Expr<'hir> {
341+
hir::Expr { hir_id: self.next_id(), kind, span }
342+
}
352343
}
353344

354345
struct SelfResolver<'a> {

‎compiler/rustc_mir_build/src/build/matches/mod.rs

+27-13
Original file line numberDiff line numberDiff line change
@@ -358,8 +358,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
358358
where
359359
'a: 'pat,
360360
{
361-
// Assemble a list of candidates: there is one candidate per pattern,
362-
// which means there may be more than one candidate *per arm*.
361+
// Assemble the initial list of candidates. These top-level candidates
362+
// are 1:1 with the original match arms, but other parts of match
363+
// lowering also introduce subcandidates (for subpatterns), and will
364+
// also flatten candidates in some cases. So in general a list of
365+
// candidates does _not_ necessarily correspond to a list of arms.
363366
arms.iter()
364367
.copied()
365368
.map(|arm| {
@@ -1031,6 +1034,12 @@ impl<'tcx> PatternExtraData<'tcx> {
10311034
}
10321035

10331036
/// A pattern in a form suitable for generating code.
1037+
///
1038+
/// Here, "flat" indicates that the pattern's match pairs have been recursively
1039+
/// simplified by [`Builder::simplify_match_pairs`]. They are not necessarily
1040+
/// flat in an absolute sense.
1041+
///
1042+
/// Will typically be incorporated into a [`Candidate`].
10341043
#[derive(Debug, Clone)]
10351044
struct FlatPat<'pat, 'tcx> {
10361045
/// To match the pattern, all of these must be satisfied...
@@ -1042,23 +1051,25 @@ struct FlatPat<'pat, 'tcx> {
10421051
}
10431052

10441053
impl<'tcx, 'pat> FlatPat<'pat, 'tcx> {
1054+
/// Creates a `FlatPat` containing a simplified [`MatchPair`] list/forest
1055+
/// for the given pattern.
10451056
fn new(
10461057
place: PlaceBuilder<'tcx>,
10471058
pattern: &'pat Pat<'tcx>,
10481059
cx: &mut Builder<'_, 'tcx>,
10491060
) -> Self {
1050-
let is_never = pattern.is_never_pattern();
1051-
let mut flat_pat = FlatPat {
1052-
match_pairs: vec![MatchPair::new(place, pattern, cx)],
1053-
extra_data: PatternExtraData {
1054-
span: pattern.span,
1055-
bindings: Vec::new(),
1056-
ascriptions: Vec::new(),
1057-
is_never,
1058-
},
1061+
// First, recursively build a tree of match pairs for the given pattern.
1062+
let mut match_pairs = vec![MatchPair::new(place, pattern, cx)];
1063+
let mut extra_data = PatternExtraData {
1064+
span: pattern.span,
1065+
bindings: Vec::new(),
1066+
ascriptions: Vec::new(),
1067+
is_never: pattern.is_never_pattern(),
10591068
};
1060-
cx.simplify_match_pairs(&mut flat_pat.match_pairs, &mut flat_pat.extra_data);
1061-
flat_pat
1069+
// Partly-flatten and sort the match pairs, while recording extra data.
1070+
cx.simplify_match_pairs(&mut match_pairs, &mut extra_data);
1071+
1072+
Self { match_pairs, extra_data }
10621073
}
10631074
}
10641075

@@ -1104,9 +1115,12 @@ impl<'tcx, 'pat> Candidate<'pat, 'tcx> {
11041115
has_guard: bool,
11051116
cx: &mut Builder<'_, 'tcx>,
11061117
) -> Self {
1118+
// Use `FlatPat` to build simplified match pairs, then immediately
1119+
// incorporate them into a new candidate.
11071120
Self::from_flat_pat(FlatPat::new(place, pattern, cx), has_guard)
11081121
}
11091122

1123+
/// Incorporates an already-simplified [`FlatPat`] into a new candidate.
11101124
fn from_flat_pat(flat_pat: FlatPat<'pat, 'tcx>, has_guard: bool) -> Self {
11111125
Candidate {
11121126
match_pairs: flat_pat.match_pairs,

‎compiler/rustc_mir_build/src/build/matches/util.rs

+2
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
9595
}
9696

9797
impl<'pat, 'tcx> MatchPair<'pat, 'tcx> {
98+
/// Recursively builds a `MatchPair` tree for the given pattern and its
99+
/// subpatterns.
98100
pub(in crate::build) fn new(
99101
mut place_builder: PlaceBuilder<'tcx>,
100102
pattern: &'pat Pat<'tcx>,

‎compiler/rustc_passes/src/dead.rs

+25
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,31 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
399399
return false;
400400
}
401401

402+
// don't ignore impls for Enums and pub Structs whose methods don't have self receiver,
403+
// cause external crate may call such methods to construct values of these types
404+
if let Some(local_impl_of) = impl_of.as_local()
405+
&& let Some(local_def_id) = def_id.as_local()
406+
&& let Some(fn_sig) =
407+
self.tcx.hir().fn_sig_by_hir_id(self.tcx.local_def_id_to_hir_id(local_def_id))
408+
&& matches!(fn_sig.decl.implicit_self, hir::ImplicitSelfKind::None)
409+
&& let TyKind::Path(hir::QPath::Resolved(_, path)) =
410+
self.tcx.hir().expect_item(local_impl_of).expect_impl().self_ty.kind
411+
&& let Res::Def(def_kind, did) = path.res
412+
{
413+
match def_kind {
414+
// for example, #[derive(Default)] pub struct T(i32);
415+
// external crate can call T::default() to construct T,
416+
// so that don't ignore impl Default for pub Enum and Structs
417+
DefKind::Struct | DefKind::Union if self.tcx.visibility(did).is_public() => {
418+
return false;
419+
}
420+
// don't ignore impl Default for Enums,
421+
// cause we don't know which variant is constructed
422+
DefKind::Enum => return false,
423+
_ => (),
424+
};
425+
}
426+
402427
if let Some(trait_of) = self.tcx.trait_id_of_impl(impl_of)
403428
&& self.tcx.has_attr(trait_of, sym::rustc_trivial_field_reads)
404429
{

‎library/alloc/src/sync/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ fn show_arc() {
396396

397397
// Make sure deriving works with Arc<T>
398398
#[derive(Eq, Ord, PartialEq, PartialOrd, Clone, Debug, Default)]
399-
struct Foo {
399+
struct _Foo {
400400
inner: Arc<i32>,
401401
}
402402

‎library/core/src/default.rs

+1
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ use crate::ascii::Char as AsciiChar;
103103
/// ```
104104
#[cfg_attr(not(test), rustc_diagnostic_item = "Default")]
105105
#[stable(feature = "rust1", since = "1.0.0")]
106+
#[cfg_attr(not(bootstrap), rustc_trivial_field_reads)]
106107
pub trait Default: Sized {
107108
/// Returns the "default value" for a type.
108109
///

‎library/core/src/ffi/mod.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ mod sealed_trait {
484484
all supported platforms",
485485
issue = "44930"
486486
)]
487-
pub trait VaArgSafe {}
487+
pub unsafe trait VaArgSafe {}
488488
}
489489

490490
macro_rules! impl_va_arg_safe {
@@ -494,7 +494,7 @@ macro_rules! impl_va_arg_safe {
494494
reason = "the `c_variadic` feature has not been properly tested on \
495495
all supported platforms",
496496
issue = "44930")]
497-
impl sealed_trait::VaArgSafe for $t {}
497+
unsafe impl sealed_trait::VaArgSafe for $t {}
498498
)+
499499
}
500500
}
@@ -509,14 +509,15 @@ impl_va_arg_safe! {f64}
509509
all supported platforms",
510510
issue = "44930"
511511
)]
512-
impl<T> sealed_trait::VaArgSafe for *mut T {}
512+
unsafe impl<T> sealed_trait::VaArgSafe for *mut T {}
513+
513514
#[unstable(
514515
feature = "c_variadic",
515516
reason = "the `c_variadic` feature has not been properly tested on \
516517
all supported platforms",
517518
issue = "44930"
518519
)]
519-
impl<T> sealed_trait::VaArgSafe for *const T {}
520+
unsafe impl<T> sealed_trait::VaArgSafe for *const T {}
520521

521522
#[unstable(
522523
feature = "c_variadic",

‎library/core/src/intrinsics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2579,7 +2579,7 @@ extern "rust-intrinsic" {
25792579
/// fn runtime() -> i32 { 1 }
25802580
/// const fn compiletime() -> i32 { 2 }
25812581
///
2582-
// // ⚠ This code violates the required equivalence of `compiletime`
2582+
/// // ⚠ This code violates the required equivalence of `compiletime`
25832583
/// // and `runtime`.
25842584
/// const_eval_select((), compiletime, runtime)
25852585
/// }

‎library/std/src/ffi/os_str.rs

+13-3
Original file line numberDiff line numberDiff line change
@@ -552,10 +552,20 @@ impl OsString {
552552
OsStr::from_inner_mut(self.inner.leak())
553553
}
554554

555-
/// Part of a hack to make PathBuf::push/pop more efficient.
555+
/// Provides plumbing to core `Vec::truncate`.
556+
/// More well behaving alternative to allowing outer types
557+
/// full mutable access to the core `Vec`.
556558
#[inline]
557-
pub(crate) fn as_mut_vec_for_path_buf(&mut self) -> &mut Vec<u8> {
558-
self.inner.as_mut_vec_for_path_buf()
559+
pub(crate) fn truncate(&mut self, len: usize) {
560+
self.inner.truncate(len);
561+
}
562+
563+
/// Provides plumbing to core `Vec::extend_from_slice`.
564+
/// More well behaving alternative to allowing outer types
565+
/// full mutable access to the core `Vec`.
566+
#[inline]
567+
pub(crate) fn extend_from_slice(&mut self, other: &[u8]) {
568+
self.inner.extend_from_slice(other);
559569
}
560570
}
561571

‎library/std/src/path.rs

+13-18
Original file line numberDiff line numberDiff line change
@@ -1163,11 +1163,6 @@ pub struct PathBuf {
11631163
}
11641164

11651165
impl PathBuf {
1166-
#[inline]
1167-
fn as_mut_vec(&mut self) -> &mut Vec<u8> {
1168-
self.inner.as_mut_vec_for_path_buf()
1169-
}
1170-
11711166
/// Allocates an empty `PathBuf`.
11721167
///
11731168
/// # Examples
@@ -1290,7 +1285,8 @@ impl PathBuf {
12901285

12911286
fn _push(&mut self, path: &Path) {
12921287
// in general, a separator is needed if the rightmost byte is not a separator
1293-
let mut need_sep = self.as_mut_vec().last().map(|c| !is_sep_byte(*c)).unwrap_or(false);
1288+
let buf = self.inner.as_encoded_bytes();
1289+
let mut need_sep = buf.last().map(|c| !is_sep_byte(*c)).unwrap_or(false);
12941290

12951291
// in the special case of `C:` on Windows, do *not* add a separator
12961292
let comps = self.components();
@@ -1304,7 +1300,7 @@ impl PathBuf {
13041300

13051301
// absolute `path` replaces `self`
13061302
if path.is_absolute() || path.prefix().is_some() {
1307-
self.as_mut_vec().truncate(0);
1303+
self.inner.truncate(0);
13081304

13091305
// verbatim paths need . and .. removed
13101306
} else if comps.prefix_verbatim() && !path.inner.is_empty() {
@@ -1349,7 +1345,7 @@ impl PathBuf {
13491345
// `path` has a root but no prefix, e.g., `\windows` (Windows only)
13501346
} else if path.has_root() {
13511347
let prefix_len = self.components().prefix_remaining();
1352-
self.as_mut_vec().truncate(prefix_len);
1348+
self.inner.truncate(prefix_len);
13531349

13541350
// `path` is a pure relative path
13551351
} else if need_sep {
@@ -1382,7 +1378,7 @@ impl PathBuf {
13821378
pub fn pop(&mut self) -> bool {
13831379
match self.parent().map(|p| p.as_u8_slice().len()) {
13841380
Some(len) => {
1385-
self.as_mut_vec().truncate(len);
1381+
self.inner.truncate(len);
13861382
true
13871383
}
13881384
None => false,
@@ -1510,15 +1506,14 @@ impl PathBuf {
15101506
// truncate until right after the file stem
15111507
let end_file_stem = file_stem[file_stem.len()..].as_ptr().addr();
15121508
let start = self.inner.as_encoded_bytes().as_ptr().addr();
1513-
let v = self.as_mut_vec();
1514-
v.truncate(end_file_stem.wrapping_sub(start));
1509+
self.inner.truncate(end_file_stem.wrapping_sub(start));
15151510

15161511
// add the new extension, if any
1517-
let new = extension.as_encoded_bytes();
1512+
let new = extension;
15181513
if !new.is_empty() {
1519-
v.reserve_exact(new.len() + 1);
1520-
v.push(b'.');
1521-
v.extend_from_slice(new);
1514+
self.inner.reserve_exact(new.len() + 1);
1515+
self.inner.push(OsStr::new("."));
1516+
self.inner.push(new);
15221517
}
15231518

15241519
true
@@ -2645,18 +2640,18 @@ impl Path {
26452640
None => {
26462641
// Enough capacity for the extension and the dot
26472642
let capacity = self_len + extension.len() + 1;
2648-
let whole_path = self_bytes.iter();
2643+
let whole_path = self_bytes;
26492644
(capacity, whole_path)
26502645
}
26512646
Some(previous_extension) => {
26522647
let capacity = self_len + extension.len() - previous_extension.len();
2653-
let path_till_dot = self_bytes[..self_len - previous_extension.len()].iter();
2648+
let path_till_dot = &self_bytes[..self_len - previous_extension.len()];
26542649
(capacity, path_till_dot)
26552650
}
26562651
};
26572652

26582653
let mut new_path = PathBuf::with_capacity(new_capacity);
2659-
new_path.as_mut_vec().extend(slice_to_copy);
2654+
new_path.inner.extend_from_slice(slice_to_copy);
26602655
new_path.set_extension(extension);
26612656
new_path
26622657
}

‎library/std/src/sys/os_str/bytes.rs

+13-3
Original file line numberDiff line numberDiff line change
@@ -202,10 +202,20 @@ impl Buf {
202202
self.as_slice().into_rc()
203203
}
204204

205-
/// Part of a hack to make PathBuf::push/pop more efficient.
205+
/// Provides plumbing to core `Vec::truncate`.
206+
/// More well behaving alternative to allowing outer types
207+
/// full mutable access to the core `Vec`.
206208
#[inline]
207-
pub(crate) fn as_mut_vec_for_path_buf(&mut self) -> &mut Vec<u8> {
208-
&mut self.inner
209+
pub(crate) fn truncate(&mut self, len: usize) {
210+
self.inner.truncate(len);
211+
}
212+
213+
/// Provides plumbing to core `Vec::extend_from_slice`.
214+
/// More well behaving alternative to allowing outer types
215+
/// full mutable access to the core `Vec`.
216+
#[inline]
217+
pub(crate) fn extend_from_slice(&mut self, other: &[u8]) {
218+
self.inner.extend_from_slice(other);
209219
}
210220
}
211221

‎library/std/src/sys/os_str/wtf8.rs

+13-3
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,20 @@ impl Buf {
165165
self.as_slice().into_rc()
166166
}
167167

168-
/// Part of a hack to make PathBuf::push/pop more efficient.
168+
/// Provides plumbing to core `Vec::truncate`.
169+
/// More well behaving alternative to allowing outer types
170+
/// full mutable access to the core `Vec`.
169171
#[inline]
170-
pub(crate) fn as_mut_vec_for_path_buf(&mut self) -> &mut Vec<u8> {
171-
self.inner.as_mut_vec_for_path_buf()
172+
pub(crate) fn truncate(&mut self, len: usize) {
173+
self.inner.truncate(len);
174+
}
175+
176+
/// Provides plumbing to core `Vec::extend_from_slice`.
177+
/// More well behaving alternative to allowing outer types
178+
/// full mutable access to the core `Vec`.
179+
#[inline]
180+
pub(crate) fn extend_from_slice(&mut self, other: &[u8]) {
181+
self.inner.extend_from_slice(other);
172182
}
173183
}
174184

‎library/std/src/sys_common/wtf8.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -474,13 +474,13 @@ impl Wtf8Buf {
474474
Wtf8Buf { bytes: bytes.into_vec(), is_known_utf8: false }
475475
}
476476

477-
/// Part of a hack to make PathBuf::push/pop more efficient.
477+
/// Provides plumbing to core `Vec::extend_from_slice`.
478+
/// More well behaving alternative to allowing outer types
479+
/// full mutable access to the core `Vec`.
478480
#[inline]
479-
pub(crate) fn as_mut_vec_for_path_buf(&mut self) -> &mut Vec<u8> {
480-
// FIXME: this function should not even exist, as it implies violating Wtf8Buf invariants
481-
// For now, simply assume that is about to happen.
482-
self.is_known_utf8 = false;
483-
&mut self.bytes
481+
pub(crate) fn extend_from_slice(&mut self, other: &[u8]) {
482+
self.bytes.extend_from_slice(other);
483+
self.is_known_utf8 = self.is_known_utf8 || self.next_surrogate(0).is_none();
484484
}
485485
}
486486

‎src/ci/docker/host-x86_64/disabled/riscv64gc-gnu/Dockerfile

+3-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ RUN sh /scripts/sccache.sh
9191
# Avoid "fatal: detected dubious ownership in repository at '/checkout'" error
9292
RUN git config --global --add safe.directory /checkout
9393

94-
ENV RUST_CONFIGURE_ARGS --qemu-riscv64-rootfs=/tmp/rootfs
94+
ENV RUST_CONFIGURE_ARGS \
95+
--qemu-riscv64-rootfs=/tmp/rootfs \
96+
--set target.riscv64gc-unknown-linux-gnu.linker=riscv64-linux-gnu-gcc
9597
ENV SCRIPT python3 ../x.py --stage 2 test --host='' --target riscv64gc-unknown-linux-gnu
9698

9799
ENV NO_CHANGE_USER=1

‎tests/ui/delegation/explicit-paths.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,10 @@ error[E0308]: mismatched types
110110
--> $DIR/explicit-paths.rs:78:30
111111
|
112112
LL | reuse <S2 as Trait>::foo1;
113-
| ---------------^^^^
114-
| | |
115-
| | expected `&S2`, found `&S`
116-
| arguments to this function are incorrect
113+
| ^^^^
114+
| |
115+
| expected `&S2`, found `&S`
116+
| arguments to this function are incorrect
117117
|
118118
= note: expected reference `&S2`
119119
found reference `&S`

‎tests/ui/deriving/deriving-default-enum.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ enum MyOption<T> {
2222
}
2323

2424
fn main() {
25-
assert_eq!(Foo::default(), Foo::Alpha);
25+
assert!(matches!(Foo::default(), Foo::Alpha));
2626
assert!(matches!(MyOption::<NotDefault>::default(), MyOption::None));
2727
}

‎tests/ui/issues/issue-68696-catch-during-unwind.rs

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
use std::panic::catch_unwind;
99

10+
#[allow(dead_code)]
1011
#[derive(Default)]
1112
struct Guard;
1213

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#![deny(dead_code)]
2+
3+
#[derive(Default)]
4+
struct T; //~ ERROR struct `T` is never constructed
5+
6+
#[derive(Default)]
7+
struct Used;
8+
9+
#[derive(Default)]
10+
enum E {
11+
#[default]
12+
A,
13+
B, //~ ERROR variant `B` is never constructed
14+
}
15+
16+
// external crate can call T2::default() to construct T2,
17+
// so that no warnings for pub adts
18+
#[derive(Default)]
19+
pub struct T2 {
20+
_unread: i32,
21+
}
22+
23+
fn main() {
24+
let _x: Used = Default::default();
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
error: struct `T` is never constructed
2+
--> $DIR/unused-struct-derive-default.rs:4:8
3+
|
4+
LL | struct T;
5+
| ^
6+
|
7+
= note: `T` has a derived impl for the trait `Default`, but this is intentionally ignored during dead code analysis
8+
note: the lint level is defined here
9+
--> $DIR/unused-struct-derive-default.rs:1:9
10+
|
11+
LL | #![deny(dead_code)]
12+
| ^^^^^^^^^
13+
14+
error: variant `B` is never constructed
15+
--> $DIR/unused-struct-derive-default.rs:13:5
16+
|
17+
LL | enum E {
18+
| - variant in this enum
19+
...
20+
LL | B,
21+
| ^
22+
23+
error: aborting due to 2 previous errors
24+

0 commit comments

Comments
 (0)
Please sign in to comment.