Skip to content

Commit 574c9dd

Browse files
committed
Auto merge of rust-lang#86559 - Dylan-DPC:rollup-aixg3q5, r=Dylan-DPC
Rollup of 6 pull requests Successful merges: - rust-lang#86223 (Specify the kind of the item for E0121) - rust-lang#86521 (Add comments around code where ordering is important due for panic-safety) - rust-lang#86523 (Improvements to intra-doc link macro disambiguators) - rust-lang#86542 (Line numbers aligned with content) - rust-lang#86549 (Add destructuring example of E0508) - rust-lang#86557 (Update books) Failed merges: - rust-lang#86548 (Fix crate filter search reset) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 6a758ea + bd04f4c commit 574c9dd

Some content is hidden

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

55 files changed

+569
-460
lines changed

compiler/rustc_error_codes/src/error_codes/E0508.md

+13
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,16 @@ fn main() {
3939
let _value = array[0].clone();
4040
}
4141
```
42+
43+
If you really want to move the value out, you can use a destructuring array
44+
pattern to move it:
45+
46+
```
47+
struct NonCopy;
48+
49+
fn main() {
50+
let array = [NonCopy; 1];
51+
// Destructuring the array
52+
let [_value] = array;
53+
}
54+
```

compiler/rustc_hir/src/hir.rs

+21
Original file line numberDiff line numberDiff line change
@@ -2815,6 +2815,27 @@ impl ItemKind<'_> {
28152815
_ => return None,
28162816
})
28172817
}
2818+
2819+
pub fn descr(&self) -> &'static str {
2820+
match self {
2821+
ItemKind::ExternCrate(..) => "extern crate",
2822+
ItemKind::Use(..) => "`use` import",
2823+
ItemKind::Static(..) => "static item",
2824+
ItemKind::Const(..) => "constant item",
2825+
ItemKind::Fn(..) => "function",
2826+
ItemKind::Mod(..) => "module",
2827+
ItemKind::ForeignMod { .. } => "extern block",
2828+
ItemKind::GlobalAsm(..) => "global asm item",
2829+
ItemKind::TyAlias(..) => "type alias",
2830+
ItemKind::OpaqueTy(..) => "opaque type",
2831+
ItemKind::Enum(..) => "enum",
2832+
ItemKind::Struct(..) => "struct",
2833+
ItemKind::Union(..) => "union",
2834+
ItemKind::Trait(..) => "trait",
2835+
ItemKind::TraitAlias(..) => "trait alias",
2836+
ItemKind::Impl(..) => "implementation",
2837+
}
2838+
}
28182839
}
28192840

28202841
/// A reference from an trait to one of its associated items. This

compiler/rustc_typeck/src/astconv/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2418,6 +2418,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
24182418
visitor.0,
24192419
true,
24202420
hir_ty,
2421+
"function",
24212422
);
24222423
}
24232424

compiler/rustc_typeck/src/collect.rs

+40-11
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ crate fn placeholder_type_error(
145145
placeholder_types: Vec<Span>,
146146
suggest: bool,
147147
hir_ty: Option<&hir::Ty<'_>>,
148+
kind: &'static str,
148149
) {
149150
if placeholder_types.is_empty() {
150151
return;
@@ -174,7 +175,7 @@ crate fn placeholder_type_error(
174175
));
175176
}
176177

177-
let mut err = bad_placeholder_type(tcx, placeholder_types);
178+
let mut err = bad_placeholder_type(tcx, placeholder_types, kind);
178179

179180
// Suggest, but only if it is not a function in const or static
180181
if suggest {
@@ -236,7 +237,15 @@ fn reject_placeholder_type_signatures_in_item(tcx: TyCtxt<'tcx>, item: &'tcx hir
236237
let mut visitor = PlaceholderHirTyCollector::default();
237238
visitor.visit_item(item);
238239

239-
placeholder_type_error(tcx, Some(generics.span), generics.params, visitor.0, suggest, None);
240+
placeholder_type_error(
241+
tcx,
242+
Some(generics.span),
243+
generics.params,
244+
visitor.0,
245+
suggest,
246+
None,
247+
item.kind.descr(),
248+
);
240249
}
241250

242251
impl Visitor<'tcx> for CollectItemTypesVisitor<'tcx> {
@@ -302,13 +311,17 @@ impl Visitor<'tcx> for CollectItemTypesVisitor<'tcx> {
302311
fn bad_placeholder_type(
303312
tcx: TyCtxt<'tcx>,
304313
mut spans: Vec<Span>,
314+
kind: &'static str,
305315
) -> rustc_errors::DiagnosticBuilder<'tcx> {
316+
let kind = if kind.ends_with('s') { format!("{}es", kind) } else { format!("{}s", kind) };
317+
306318
spans.sort();
307319
let mut err = struct_span_err!(
308320
tcx.sess,
309321
spans.clone(),
310322
E0121,
311-
"the type placeholder `_` is not allowed within types on item signatures",
323+
"the type placeholder `_` is not allowed within types on item signatures for {}",
324+
kind
312325
);
313326
for span in spans {
314327
err.span_label(span, "not allowed in type signatures");
@@ -382,7 +395,7 @@ impl AstConv<'tcx> for ItemCtxt<'tcx> {
382395
_: Option<&ty::GenericParamDef>,
383396
span: Span,
384397
) -> &'tcx Const<'tcx> {
385-
bad_placeholder_type(self.tcx(), vec![span]).emit();
398+
bad_placeholder_type(self.tcx(), vec![span], "generic").emit();
386399
// Typeck doesn't expect erased regions to be returned from `type_of`.
387400
let ty = self.tcx.fold_regions(ty, &mut false, |r, _| match r {
388401
ty::ReErased => self.tcx.lifetimes.re_static,
@@ -746,7 +759,15 @@ fn convert_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) {
746759
hir::ForeignItemKind::Static(..) => {
747760
let mut visitor = PlaceholderHirTyCollector::default();
748761
visitor.visit_foreign_item(item);
749-
placeholder_type_error(tcx, None, &[], visitor.0, false, None);
762+
placeholder_type_error(
763+
tcx,
764+
None,
765+
&[],
766+
visitor.0,
767+
false,
768+
None,
769+
"static variable",
770+
);
750771
}
751772
_ => (),
752773
}
@@ -818,7 +839,15 @@ fn convert_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) {
818839
if let hir::TyKind::TraitObject(..) = ty.kind {
819840
let mut visitor = PlaceholderHirTyCollector::default();
820841
visitor.visit_item(it);
821-
placeholder_type_error(tcx, None, &[], visitor.0, false, None);
842+
placeholder_type_error(
843+
tcx,
844+
None,
845+
&[],
846+
visitor.0,
847+
false,
848+
None,
849+
it.kind.descr(),
850+
);
822851
}
823852
}
824853
_ => (),
@@ -846,7 +875,7 @@ fn convert_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::TraitItemId) {
846875
// Account for `const C: _;`.
847876
let mut visitor = PlaceholderHirTyCollector::default();
848877
visitor.visit_trait_item(trait_item);
849-
placeholder_type_error(tcx, None, &[], visitor.0, false, None);
878+
placeholder_type_error(tcx, None, &[], visitor.0, false, None, "constant");
850879
}
851880

852881
hir::TraitItemKind::Type(_, Some(_)) => {
@@ -855,7 +884,7 @@ fn convert_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::TraitItemId) {
855884
// Account for `type T = _;`.
856885
let mut visitor = PlaceholderHirTyCollector::default();
857886
visitor.visit_trait_item(trait_item);
858-
placeholder_type_error(tcx, None, &[], visitor.0, false, None);
887+
placeholder_type_error(tcx, None, &[], visitor.0, false, None, "associated type");
859888
}
860889

861890
hir::TraitItemKind::Type(_, None) => {
@@ -865,7 +894,7 @@ fn convert_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::TraitItemId) {
865894
let mut visitor = PlaceholderHirTyCollector::default();
866895
visitor.visit_trait_item(trait_item);
867896

868-
placeholder_type_error(tcx, None, &[], visitor.0, false, None);
897+
placeholder_type_error(tcx, None, &[], visitor.0, false, None, "associated type");
869898
}
870899
};
871900

@@ -887,7 +916,7 @@ fn convert_impl_item(tcx: TyCtxt<'_>, impl_item_id: hir::ImplItemId) {
887916
let mut visitor = PlaceholderHirTyCollector::default();
888917
visitor.visit_impl_item(impl_item);
889918

890-
placeholder_type_error(tcx, None, &[], visitor.0, false, None);
919+
placeholder_type_error(tcx, None, &[], visitor.0, false, None, "associated type");
891920
}
892921
hir::ImplItemKind::Const(..) => {}
893922
}
@@ -1711,7 +1740,7 @@ fn fn_sig(tcx: TyCtxt<'_>, def_id: DefId) -> ty::PolyFnSig<'_> {
17111740

17121741
let mut visitor = PlaceholderHirTyCollector::default();
17131742
visitor.visit_ty(ty);
1714-
let mut diag = bad_placeholder_type(tcx, visitor.0);
1743+
let mut diag = bad_placeholder_type(tcx, visitor.0, "return type");
17151744
let ret_ty = fn_sig.output();
17161745
if ret_ty != tcx.ty_error() {
17171746
if !ret_ty.is_closure() {

compiler/rustc_typeck/src/collect/type_of.rs

+28-9
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,9 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
285285
TraitItemKind::Const(ref ty, body_id) => body_id
286286
.and_then(|body_id| {
287287
if is_suggestable_infer_ty(ty) {
288-
Some(infer_placeholder_type(tcx, def_id, body_id, ty.span, item.ident))
288+
Some(infer_placeholder_type(
289+
tcx, def_id, body_id, ty.span, item.ident, "constant",
290+
))
289291
} else {
290292
None
291293
}
@@ -304,7 +306,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
304306
}
305307
ImplItemKind::Const(ref ty, body_id) => {
306308
if is_suggestable_infer_ty(ty) {
307-
infer_placeholder_type(tcx, def_id, body_id, ty.span, item.ident)
309+
infer_placeholder_type(tcx, def_id, body_id, ty.span, item.ident, "constant")
308310
} else {
309311
icx.to_ty(ty)
310312
}
@@ -320,9 +322,25 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
320322

321323
Node::Item(item) => {
322324
match item.kind {
323-
ItemKind::Static(ref ty, .., body_id) | ItemKind::Const(ref ty, body_id) => {
325+
ItemKind::Static(ref ty, .., body_id) => {
324326
if is_suggestable_infer_ty(ty) {
325-
infer_placeholder_type(tcx, def_id, body_id, ty.span, item.ident)
327+
infer_placeholder_type(
328+
tcx,
329+
def_id,
330+
body_id,
331+
ty.span,
332+
item.ident,
333+
"static variable",
334+
)
335+
} else {
336+
icx.to_ty(ty)
337+
}
338+
}
339+
ItemKind::Const(ref ty, body_id) => {
340+
if is_suggestable_infer_ty(ty) {
341+
infer_placeholder_type(
342+
tcx, def_id, body_id, ty.span, item.ident, "constant",
343+
)
326344
} else {
327345
icx.to_ty(ty)
328346
}
@@ -742,13 +760,14 @@ fn let_position_impl_trait_type(tcx: TyCtxt<'_>, opaque_ty_id: LocalDefId) -> Ty
742760
concrete_ty
743761
}
744762

745-
fn infer_placeholder_type(
746-
tcx: TyCtxt<'_>,
763+
fn infer_placeholder_type<'a>(
764+
tcx: TyCtxt<'a>,
747765
def_id: LocalDefId,
748766
body_id: hir::BodyId,
749767
span: Span,
750768
item_ident: Ident,
751-
) -> Ty<'_> {
769+
kind: &'static str,
770+
) -> Ty<'a> {
752771
// Attempts to make the type nameable by turning FnDefs into FnPtrs.
753772
struct MakeNameable<'tcx> {
754773
success: bool,
@@ -802,7 +821,7 @@ fn infer_placeholder_type(
802821
if let Some(sugg_ty) = sugg_ty {
803822
err.span_suggestion(
804823
span,
805-
"provide a type for the item",
824+
&format!("provide a type for the {item}", item = kind),
806825
format!("{}: {}", item_ident, sugg_ty),
807826
Applicability::MachineApplicable,
808827
);
@@ -816,7 +835,7 @@ fn infer_placeholder_type(
816835
err.emit_unless(ty.references_error());
817836
}
818837
None => {
819-
let mut diag = bad_placeholder_type(tcx, vec![span]);
838+
let mut diag = bad_placeholder_type(tcx, vec![span], kind);
820839

821840
if !ty.references_error() {
822841
let mut mk_nameable = MakeNameable::new(tcx);

library/alloc/src/vec/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -2568,6 +2568,8 @@ impl<T, A: Allocator> Vec<T, A> {
25682568
}
25692569
unsafe {
25702570
ptr::write(self.as_mut_ptr().add(len), element);
2571+
// Since next() executes user code which can panic we have to bump the length
2572+
// after each step.
25712573
// NB can't overflow since we would have had to alloc the address space
25722574
self.set_len(len + 1);
25732575
}

library/alloc/src/vec/source_iter_marker.rs

+4
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ fn write_in_place_with_drop<T>(
8989
// all we can do is check if it's still in range
9090
debug_assert!(sink.dst as *const _ <= src_end, "InPlaceIterable contract violation");
9191
ptr::write(sink.dst, item);
92+
// Since this executes user code which can panic we have to bump the pointer
93+
// after each step.
9294
sink.dst = sink.dst.add(1);
9395
}
9496
Ok(sink)
@@ -136,6 +138,8 @@ where
136138
let dst = dst_buf.offset(i as isize);
137139
debug_assert!(dst as *const _ <= end, "InPlaceIterable contract violation");
138140
ptr::write(dst, self.__iterator_get_unchecked(i));
141+
// Since this executes user code which can panic we have to bump the pointer
142+
// after each step.
139143
drop_guard.dst = dst.add(1);
140144
}
141145
}

library/alloc/src/vec/spec_extend.rs

+2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ where
4040
iterator.for_each(move |element| {
4141
ptr::write(ptr, element);
4242
ptr = ptr.offset(1);
43+
// Since the loop executes user code which can panic we have to bump the pointer
44+
// after each step.
4345
// NB can't overflow since we would have had to alloc the address space
4446
local_len.increment_len(1);
4547
});

library/core/src/iter/adapters/zip.rs

+9
Original file line numberDiff line numberDiff line change
@@ -227,13 +227,16 @@ where
227227
fn next(&mut self) -> Option<(A::Item, B::Item)> {
228228
if self.index < self.len {
229229
let i = self.index;
230+
// since get_unchecked executes code which can panic we increment the counters beforehand
231+
// so that the same index won't be accessed twice, as required by TrustedRandomAccess
230232
self.index += 1;
231233
// SAFETY: `i` is smaller than `self.len`, thus smaller than `self.a.len()` and `self.b.len()`
232234
unsafe {
233235
Some((self.a.__iterator_get_unchecked(i), self.b.__iterator_get_unchecked(i)))
234236
}
235237
} else if A::MAY_HAVE_SIDE_EFFECT && self.index < self.a_len {
236238
let i = self.index;
239+
// as above, increment before executing code that may panic
237240
self.index += 1;
238241
self.len += 1;
239242
// match the base implementation's potential side effects
@@ -259,6 +262,8 @@ where
259262
let end = self.index + delta;
260263
while self.index < end {
261264
let i = self.index;
265+
// since get_unchecked executes code which can panic we increment the counters beforehand
266+
// so that the same index won't be accessed twice, as required by TrustedRandomAccess
262267
self.index += 1;
263268
if A::MAY_HAVE_SIDE_EFFECT {
264269
// SAFETY: the usage of `cmp::min` to calculate `delta`
@@ -295,6 +300,8 @@ where
295300
let sz_a = self.a.size();
296301
if A::MAY_HAVE_SIDE_EFFECT && sz_a > self.len {
297302
for _ in 0..sz_a - self.len {
303+
// since next_back() may panic we increment the counters beforehand
304+
// to keep Zip's state in sync with the underlying iterator source
298305
self.a_len -= 1;
299306
self.a.next_back();
300307
}
@@ -309,6 +316,8 @@ where
309316
}
310317
}
311318
if self.index < self.len {
319+
// since get_unchecked executes code which can panic we increment the counters beforehand
320+
// so that the same index won't be accessed twice, as required by TrustedRandomAccess
312321
self.len -= 1;
313322
self.a_len -= 1;
314323
let i = self.len;

src/ci/docker/host-x86_64/x86_64-gnu-tools/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ ENV PATH="/node-v14.4.0-linux-x64/bin:${PATH}"
7171
# https://github.com/puppeteer/puppeteer/issues/375
7272
#
7373
# We also specify the version in case we need to update it to go around cache limitations.
74-
RUN npm install -g browser-ui-test@0.3.0 --unsafe-perm=true
74+
RUN npm install -g browser-ui-test@0.4.0 --unsafe-perm=true
7575

7676
ENV RUST_CONFIGURE_ARGS \
7777
--build=x86_64-unknown-linux-gnu \

0 commit comments

Comments
 (0)