Skip to content

Commit d5de305

Browse files
committed
Auto merge of #3435 - rust-lang:rustup-2024-03-31, r=saethlin
Automatic Rustup
2 parents 723aced + eb8e8c0 commit d5de305

File tree

84 files changed

+1386
-714
lines changed

Some content is hidden

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

84 files changed

+1386
-714
lines changed

compiler/rustc_codegen_gcc/patches/libgccjit12/0001-core-Disable-portable-simd-test.patch

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ index d0a119c..76fdece 100644
1414
@@ -89,7 +89,6 @@
1515
#![feature(never_type)]
1616
#![feature(unwrap_infallible)]
17-
#![feature(pointer_is_aligned)]
17+
#![feature(pointer_is_aligned_to)]
1818
-#![feature(portable_simd)]
1919
#![feature(ptr_metadata)]
2020
#![feature(lazy_cell)]
@@ -27,6 +27,6 @@ index d0a119c..76fdece 100644
2727
mod slice;
2828
mod str;
2929
mod str_lossy;
30-
--
30+
--
3131
2.42.1
3232

compiler/rustc_data_structures/src/tagged_ptr/copy.rs

+1
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ where
243243
T: Tag,
244244
{
245245
#[inline]
246+
#[allow(ambiguous_wide_pointer_comparisons)]
246247
fn eq(&self, other: &Self) -> bool {
247248
self.packed == other.packed
248249
}

compiler/rustc_hir_analysis/messages.ftl

+2
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,8 @@ hir_analysis_not_supported_delegation =
295295
{$descr} is not supported yet
296296
.label = callee defined here
297297
298+
hir_analysis_only_current_traits_adt = `{$name}` is not defined in the current crate
299+
298300
hir_analysis_only_current_traits_arbitrary = only traits defined in the current crate can be implemented for arbitrary types
299301
300302
hir_analysis_only_current_traits_foreign = this is not defined in the current crate because this is a foreign trait

compiler/rustc_hir_analysis/src/coherence/orphan.rs

+69-91
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
use crate::errors;
55
use rustc_errors::ErrorGuaranteed;
66
use rustc_hir as hir;
7-
use rustc_middle::ty::{self, AliasKind, Ty, TyCtxt, TypeVisitableExt};
7+
use rustc_middle::ty::{self, AliasKind, TyCtxt, TypeVisitableExt};
88
use rustc_span::def_id::LocalDefId;
99
use rustc_span::Span;
1010
use rustc_trait_selection::traits::{self, IsFirstInputType};
@@ -283,9 +283,14 @@ fn emit_orphan_check_error<'tcx>(
283283
let self_ty = trait_ref.self_ty();
284284
Err(match err {
285285
traits::OrphanCheckErr::NonLocalInputType(tys) => {
286-
let (mut opaque, mut foreign, mut name, mut pointer, mut ty_diag) =
287-
(Vec::new(), Vec::new(), Vec::new(), Vec::new(), Vec::new());
288-
let mut sugg = None;
286+
let mut diag = tcx.dcx().create_err(match self_ty.kind() {
287+
ty::Adt(..) => errors::OnlyCurrentTraits::Outside { span: sp, note: () },
288+
_ if self_ty.is_primitive() => {
289+
errors::OnlyCurrentTraits::Primitive { span: sp, note: () }
290+
}
291+
_ => errors::OnlyCurrentTraits::Arbitrary { span: sp, note: () },
292+
});
293+
289294
for &(mut ty, is_target_ty) in &tys {
290295
let span = if matches!(is_target_ty, IsFirstInputType::Yes) {
291296
// Point at `D<A>` in `impl<A, B> for C<B> in D<A>`
@@ -296,113 +301,86 @@ fn emit_orphan_check_error<'tcx>(
296301
};
297302

298303
ty = tcx.erase_regions(ty);
299-
ty = match ty.kind() {
300-
// Remove the type arguments from the output, as they are not relevant.
301-
// You can think of this as the reverse of `resolve_vars_if_possible`.
302-
// That way if we had `Vec<MyType>`, we will properly attribute the
303-
// problem to `Vec<T>` and avoid confusing the user if they were to see
304-
// `MyType` in the error.
305-
ty::Adt(def, _) => Ty::new_adt(tcx, *def, ty::List::empty()),
306-
_ => ty,
307-
};
308-
309-
fn push_to_foreign_or_name<'tcx>(
310-
is_foreign: bool,
311-
foreign: &mut Vec<errors::OnlyCurrentTraitsForeign>,
312-
name: &mut Vec<errors::OnlyCurrentTraitsName<'tcx>>,
313-
span: Span,
314-
sname: &'tcx str,
315-
) {
316-
if is_foreign {
317-
foreign.push(errors::OnlyCurrentTraitsForeign { span })
318-
} else {
319-
name.push(errors::OnlyCurrentTraitsName { span, name: sname });
320-
}
321-
}
322304

323305
let is_foreign =
324306
!trait_ref.def_id.is_local() && matches!(is_target_ty, IsFirstInputType::No);
325307

326308
match *ty.kind() {
327309
ty::Slice(_) => {
328-
push_to_foreign_or_name(
329-
is_foreign,
330-
&mut foreign,
331-
&mut name,
332-
span,
333-
"slices",
334-
);
310+
if is_foreign {
311+
diag.subdiagnostic(
312+
tcx.dcx(),
313+
errors::OnlyCurrentTraitsForeign { span },
314+
);
315+
} else {
316+
diag.subdiagnostic(
317+
tcx.dcx(),
318+
errors::OnlyCurrentTraitsName { span, name: "slices" },
319+
);
320+
}
335321
}
336322
ty::Array(..) => {
337-
push_to_foreign_or_name(
338-
is_foreign,
339-
&mut foreign,
340-
&mut name,
341-
span,
342-
"arrays",
343-
);
323+
if is_foreign {
324+
diag.subdiagnostic(
325+
tcx.dcx(),
326+
errors::OnlyCurrentTraitsForeign { span },
327+
);
328+
} else {
329+
diag.subdiagnostic(
330+
tcx.dcx(),
331+
errors::OnlyCurrentTraitsName { span, name: "arrays" },
332+
);
333+
}
344334
}
345335
ty::Tuple(..) => {
346-
push_to_foreign_or_name(
347-
is_foreign,
348-
&mut foreign,
349-
&mut name,
350-
span,
351-
"tuples",
352-
);
336+
if is_foreign {
337+
diag.subdiagnostic(
338+
tcx.dcx(),
339+
errors::OnlyCurrentTraitsForeign { span },
340+
);
341+
} else {
342+
diag.subdiagnostic(
343+
tcx.dcx(),
344+
errors::OnlyCurrentTraitsName { span, name: "tuples" },
345+
);
346+
}
353347
}
354348
ty::Alias(ty::Opaque, ..) => {
355-
opaque.push(errors::OnlyCurrentTraitsOpaque { span })
349+
diag.subdiagnostic(tcx.dcx(), errors::OnlyCurrentTraitsOpaque { span });
356350
}
357351
ty::RawPtr(ptr_ty, mutbl) => {
358352
if !self_ty.has_param() {
359-
let mut_key = mutbl.prefix_str();
360-
sugg = Some(errors::OnlyCurrentTraitsPointerSugg {
361-
wrapper_span: self_ty_span,
362-
struct_span: full_impl_span.shrink_to_lo(),
363-
mut_key,
364-
ptr_ty,
365-
});
353+
diag.subdiagnostic(
354+
tcx.dcx(),
355+
errors::OnlyCurrentTraitsPointerSugg {
356+
wrapper_span: self_ty_span,
357+
struct_span: full_impl_span.shrink_to_lo(),
358+
mut_key: mutbl.prefix_str(),
359+
ptr_ty,
360+
},
361+
);
366362
}
367-
pointer.push(errors::OnlyCurrentTraitsPointer { span, pointer: ty });
363+
diag.subdiagnostic(
364+
tcx.dcx(),
365+
errors::OnlyCurrentTraitsPointer { span, pointer: ty },
366+
);
367+
}
368+
ty::Adt(adt_def, _) => {
369+
diag.subdiagnostic(
370+
tcx.dcx(),
371+
errors::OnlyCurrentTraitsAdt {
372+
span,
373+
name: tcx.def_path_str(adt_def.did()),
374+
},
375+
);
376+
}
377+
_ => {
378+
diag.subdiagnostic(tcx.dcx(), errors::OnlyCurrentTraitsTy { span, ty });
368379
}
369-
_ => ty_diag.push(errors::OnlyCurrentTraitsTy { span, ty }),
370380
}
371381
}
372382

373-
let err_struct = match self_ty.kind() {
374-
ty::Adt(..) => errors::OnlyCurrentTraits::Outside {
375-
span: sp,
376-
note: (),
377-
opaque,
378-
foreign,
379-
name,
380-
pointer,
381-
ty: ty_diag,
382-
sugg,
383-
},
384-
_ if self_ty.is_primitive() => errors::OnlyCurrentTraits::Primitive {
385-
span: sp,
386-
note: (),
387-
opaque,
388-
foreign,
389-
name,
390-
pointer,
391-
ty: ty_diag,
392-
sugg,
393-
},
394-
_ => errors::OnlyCurrentTraits::Arbitrary {
395-
span: sp,
396-
note: (),
397-
opaque,
398-
foreign,
399-
name,
400-
pointer,
401-
ty: ty_diag,
402-
sugg,
403-
},
404-
};
405-
tcx.dcx().emit_err(err_struct)
383+
diag.emit()
406384
}
407385
traits::OrphanCheckErr::UncoveredTy(param_ty, local_type) => {
408386
let mut sp = sp;

compiler/rustc_hir_analysis/src/errors.rs

+9-38
Original file line numberDiff line numberDiff line change
@@ -1376,26 +1376,14 @@ pub struct TyParamSome<'a> {
13761376
}
13771377

13781378
#[derive(Diagnostic)]
1379-
pub enum OnlyCurrentTraits<'a> {
1379+
pub enum OnlyCurrentTraits {
13801380
#[diag(hir_analysis_only_current_traits_outside, code = E0117)]
13811381
Outside {
13821382
#[primary_span]
13831383
#[label(hir_analysis_only_current_traits_label)]
13841384
span: Span,
13851385
#[note(hir_analysis_only_current_traits_note)]
13861386
note: (),
1387-
#[subdiagnostic]
1388-
opaque: Vec<OnlyCurrentTraitsOpaque>,
1389-
#[subdiagnostic]
1390-
foreign: Vec<OnlyCurrentTraitsForeign>,
1391-
#[subdiagnostic]
1392-
name: Vec<OnlyCurrentTraitsName<'a>>,
1393-
#[subdiagnostic]
1394-
pointer: Vec<OnlyCurrentTraitsPointer<'a>>,
1395-
#[subdiagnostic]
1396-
ty: Vec<OnlyCurrentTraitsTy<'a>>,
1397-
#[subdiagnostic]
1398-
sugg: Option<OnlyCurrentTraitsPointerSugg<'a>>,
13991387
},
14001388
#[diag(hir_analysis_only_current_traits_primitive, code = E0117)]
14011389
Primitive {
@@ -1404,18 +1392,6 @@ pub enum OnlyCurrentTraits<'a> {
14041392
span: Span,
14051393
#[note(hir_analysis_only_current_traits_note)]
14061394
note: (),
1407-
#[subdiagnostic]
1408-
opaque: Vec<OnlyCurrentTraitsOpaque>,
1409-
#[subdiagnostic]
1410-
foreign: Vec<OnlyCurrentTraitsForeign>,
1411-
#[subdiagnostic]
1412-
name: Vec<OnlyCurrentTraitsName<'a>>,
1413-
#[subdiagnostic]
1414-
pointer: Vec<OnlyCurrentTraitsPointer<'a>>,
1415-
#[subdiagnostic]
1416-
ty: Vec<OnlyCurrentTraitsTy<'a>>,
1417-
#[subdiagnostic]
1418-
sugg: Option<OnlyCurrentTraitsPointerSugg<'a>>,
14191395
},
14201396
#[diag(hir_analysis_only_current_traits_arbitrary, code = E0117)]
14211397
Arbitrary {
@@ -1424,18 +1400,6 @@ pub enum OnlyCurrentTraits<'a> {
14241400
span: Span,
14251401
#[note(hir_analysis_only_current_traits_note)]
14261402
note: (),
1427-
#[subdiagnostic]
1428-
opaque: Vec<OnlyCurrentTraitsOpaque>,
1429-
#[subdiagnostic]
1430-
foreign: Vec<OnlyCurrentTraitsForeign>,
1431-
#[subdiagnostic]
1432-
name: Vec<OnlyCurrentTraitsName<'a>>,
1433-
#[subdiagnostic]
1434-
pointer: Vec<OnlyCurrentTraitsPointer<'a>>,
1435-
#[subdiagnostic]
1436-
ty: Vec<OnlyCurrentTraitsTy<'a>>,
1437-
#[subdiagnostic]
1438-
sugg: Option<OnlyCurrentTraitsPointerSugg<'a>>,
14391403
},
14401404
}
14411405

@@ -1445,7 +1409,6 @@ pub struct OnlyCurrentTraitsOpaque {
14451409
#[primary_span]
14461410
pub span: Span,
14471411
}
1448-
14491412
#[derive(Subdiagnostic)]
14501413
#[label(hir_analysis_only_current_traits_foreign)]
14511414
pub struct OnlyCurrentTraitsForeign {
@@ -1477,6 +1440,14 @@ pub struct OnlyCurrentTraitsTy<'a> {
14771440
pub ty: Ty<'a>,
14781441
}
14791442

1443+
#[derive(Subdiagnostic)]
1444+
#[label(hir_analysis_only_current_traits_adt)]
1445+
pub struct OnlyCurrentTraitsAdt {
1446+
#[primary_span]
1447+
pub span: Span,
1448+
pub name: String,
1449+
}
1450+
14801451
#[derive(Subdiagnostic)]
14811452
#[multipart_suggestion(
14821453
hir_analysis_only_current_traits_pointer_sugg,

compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

+3-10
Original file line numberDiff line numberDiff line change
@@ -1916,18 +1916,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
19161916
pat: &'tcx hir::Pat<'tcx>,
19171917
ty: Ty<'tcx>,
19181918
) {
1919-
struct V<'tcx> {
1920-
tcx: TyCtxt<'tcx>,
1919+
struct V {
19211920
pat_hir_ids: Vec<hir::HirId>,
19221921
}
19231922

1924-
impl<'tcx> Visitor<'tcx> for V<'tcx> {
1925-
type NestedFilter = rustc_middle::hir::nested_filter::All;
1926-
1927-
fn nested_visit_map(&mut self) -> Self::Map {
1928-
self.tcx.hir()
1929-
}
1930-
1923+
impl<'tcx> Visitor<'tcx> for V {
19311924
fn visit_pat(&mut self, p: &'tcx hir::Pat<'tcx>) {
19321925
self.pat_hir_ids.push(p.hir_id);
19331926
hir::intravisit::walk_pat(self, p);
@@ -1938,7 +1931,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
19381931
let err = Ty::new_error(self.tcx, guar);
19391932
self.write_ty(hir_id, err);
19401933
self.write_ty(pat.hir_id, err);
1941-
let mut visitor = V { tcx: self.tcx, pat_hir_ids: vec![] };
1934+
let mut visitor = V { pat_hir_ids: vec![] };
19421935
hir::intravisit::walk_pat(&mut visitor, pat);
19431936
// Mark all the subpatterns as `{type error}` as well. This allows errors for specific
19441937
// subpatterns to be silenced.

0 commit comments

Comments
 (0)