Skip to content

Commit 1b5e121

Browse files
committed
Auto merge of #97401 - Dylan-DPC:rollup-fh9e61o, r=Dylan-DPC
Rollup of 5 pull requests Successful merges: - #97302 (Do writeback of Closure params before visiting the parent expression) - #97328 (rustc: Fix ICE in native library error reporting) - #97351 (Output correct type responsible for structural match violation) - #97398 (Add regression test for #82830) - #97400 (Fix a typo on Struct `Substructure`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 9fed130 + e98f8f8 commit 1b5e121

File tree

16 files changed

+164
-42
lines changed

16 files changed

+164
-42
lines changed

Diff for: compiler/rustc_builtin_macros/src/deriving/generic/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ pub struct Substructure<'a> {
257257
pub type_ident: Ident,
258258
/// ident of the method
259259
pub method_ident: Ident,
260-
/// dereferenced access to any [`Self_`] or [`Ptr(Self_, _)][ptr]` arguments
260+
/// dereferenced access to any [`Self_`] or [`Ptr(Self_, _)`][ptr] arguments
261261
///
262262
/// [`Self_`]: ty::Ty::Self_
263263
/// [ptr]: ty::Ty::Ptr

Diff for: compiler/rustc_metadata/src/native_libs.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -418,10 +418,11 @@ impl<'tcx> Collector<'tcx> {
418418
// involved or not, library reordering and kind overriding without
419419
// explicit `:rename` in particular.
420420
if lib.has_modifiers() || passed_lib.has_modifiers() {
421-
self.tcx.sess.span_err(
422-
self.tcx.def_span(lib.foreign_module.unwrap()),
423-
"overriding linking modifiers from command line is not supported"
424-
);
421+
let msg = "overriding linking modifiers from command line is not supported";
422+
match lib.foreign_module {
423+
Some(def_id) => self.tcx.sess.span_err(self.tcx.def_span(def_id), msg),
424+
None => self.tcx.sess.err(msg),
425+
};
425426
}
426427
if passed_lib.kind != NativeLibKind::Unspecified {
427428
lib.kind = passed_lib.kind;

Diff for: compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -121,27 +121,27 @@ impl<'a, 'tcx> ConstToPat<'a, 'tcx> {
121121

122122
fn search_for_structural_match_violation(&self, ty: Ty<'tcx>) -> Option<String> {
123123
traits::search_for_structural_match_violation(self.span, self.tcx(), ty).map(|non_sm_ty| {
124-
with_no_trimmed_paths!(match non_sm_ty {
125-
traits::NonStructuralMatchTy::Adt(adt) => self.adt_derive_msg(adt),
126-
traits::NonStructuralMatchTy::Dynamic => {
124+
with_no_trimmed_paths!(match non_sm_ty.kind {
125+
traits::NonStructuralMatchTyKind::Adt(adt) => self.adt_derive_msg(adt),
126+
traits::NonStructuralMatchTyKind::Dynamic => {
127127
"trait objects cannot be used in patterns".to_string()
128128
}
129-
traits::NonStructuralMatchTy::Opaque => {
129+
traits::NonStructuralMatchTyKind::Opaque => {
130130
"opaque types cannot be used in patterns".to_string()
131131
}
132-
traits::NonStructuralMatchTy::Closure => {
132+
traits::NonStructuralMatchTyKind::Closure => {
133133
"closures cannot be used in patterns".to_string()
134134
}
135-
traits::NonStructuralMatchTy::Generator => {
135+
traits::NonStructuralMatchTyKind::Generator => {
136136
"generators cannot be used in patterns".to_string()
137137
}
138-
traits::NonStructuralMatchTy::Param => {
138+
traits::NonStructuralMatchTyKind::Param => {
139139
bug!("use of a constant whose type is a parameter inside a pattern")
140140
}
141-
traits::NonStructuralMatchTy::Projection => {
141+
traits::NonStructuralMatchTyKind::Projection => {
142142
bug!("use of a constant whose type is a projection inside a pattern")
143143
}
144-
traits::NonStructuralMatchTy::Foreign => {
144+
traits::NonStructuralMatchTyKind::Foreign => {
145145
bug!("use of a value of a foreign type inside a pattern")
146146
}
147147
})

Diff for: compiler/rustc_trait_selection/src/traits/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ pub use self::specialize::specialization_graph::FutureCompatOverlapError;
6262
pub use self::specialize::specialization_graph::FutureCompatOverlapErrorKind;
6363
pub use self::specialize::{specialization_graph, translate_substs, OverlapError};
6464
pub use self::structural_match::search_for_structural_match_violation;
65-
pub use self::structural_match::NonStructuralMatchTy;
65+
pub use self::structural_match::{NonStructuralMatchTy, NonStructuralMatchTyKind};
6666
pub use self::util::{
6767
elaborate_obligations, elaborate_predicates, elaborate_predicates_with_span,
6868
elaborate_trait_ref, elaborate_trait_refs,

Diff for: compiler/rustc_trait_selection/src/traits/structural_match.rs

+23-9
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,13 @@ use rustc_span::Span;
1111
use std::ops::ControlFlow;
1212

1313
#[derive(Debug)]
14-
pub enum NonStructuralMatchTy<'tcx> {
14+
pub struct NonStructuralMatchTy<'tcx> {
15+
pub ty: Ty<'tcx>,
16+
pub kind: NonStructuralMatchTyKind<'tcx>,
17+
}
18+
19+
#[derive(Debug)]
20+
pub enum NonStructuralMatchTyKind<'tcx> {
1521
Adt(AdtDef<'tcx>),
1622
Param,
1723
Dynamic,
@@ -137,25 +143,32 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for Search<'a, 'tcx> {
137143
let (adt_def, substs) = match *ty.kind() {
138144
ty::Adt(adt_def, substs) => (adt_def, substs),
139145
ty::Param(_) => {
140-
return ControlFlow::Break(NonStructuralMatchTy::Param);
146+
let kind = NonStructuralMatchTyKind::Param;
147+
return ControlFlow::Break(NonStructuralMatchTy { ty, kind });
141148
}
142149
ty::Dynamic(..) => {
143-
return ControlFlow::Break(NonStructuralMatchTy::Dynamic);
150+
let kind = NonStructuralMatchTyKind::Dynamic;
151+
return ControlFlow::Break(NonStructuralMatchTy { ty, kind });
144152
}
145153
ty::Foreign(_) => {
146-
return ControlFlow::Break(NonStructuralMatchTy::Foreign);
154+
let kind = NonStructuralMatchTyKind::Foreign;
155+
return ControlFlow::Break(NonStructuralMatchTy { ty, kind });
147156
}
148157
ty::Opaque(..) => {
149-
return ControlFlow::Break(NonStructuralMatchTy::Opaque);
158+
let kind = NonStructuralMatchTyKind::Opaque;
159+
return ControlFlow::Break(NonStructuralMatchTy { ty, kind });
150160
}
151161
ty::Projection(..) => {
152-
return ControlFlow::Break(NonStructuralMatchTy::Projection);
162+
let kind = NonStructuralMatchTyKind::Projection;
163+
return ControlFlow::Break(NonStructuralMatchTy { ty, kind });
153164
}
154165
ty::Closure(..) => {
155-
return ControlFlow::Break(NonStructuralMatchTy::Closure);
166+
let kind = NonStructuralMatchTyKind::Closure;
167+
return ControlFlow::Break(NonStructuralMatchTy { ty, kind });
156168
}
157169
ty::Generator(..) | ty::GeneratorWitness(..) => {
158-
return ControlFlow::Break(NonStructuralMatchTy::Generator);
170+
let kind = NonStructuralMatchTyKind::Generator;
171+
return ControlFlow::Break(NonStructuralMatchTy { ty, kind });
159172
}
160173
ty::RawPtr(..) => {
161174
// structural-match ignores substructure of
@@ -215,7 +228,8 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for Search<'a, 'tcx> {
215228

216229
if !self.type_marked_structural(ty) {
217230
debug!("Search found ty: {:?}", ty);
218-
return ControlFlow::Break(NonStructuralMatchTy::Adt(adt_def));
231+
let kind = NonStructuralMatchTyKind::Adt(adt_def);
232+
return ControlFlow::Break(NonStructuralMatchTy { ty, kind });
219233
}
220234

221235
// structural-match does not care about the

Diff for: compiler/rustc_typeck/src/check/wfcheck.rs

+15-9
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,9 @@ fn check_param_wf(tcx: TyCtxt<'_>, param: &hir::GenericParam<'_>) {
827827
);
828828
}
829829

830-
if traits::search_for_structural_match_violation(param.span, tcx, ty).is_some() {
830+
if let Some(non_structural_match_ty) =
831+
traits::search_for_structural_match_violation(param.span, tcx, ty)
832+
{
831833
// We use the same error code in both branches, because this is really the same
832834
// issue: we just special-case the message for type parameters to make it
833835
// clearer.
@@ -853,19 +855,23 @@ fn check_param_wf(tcx: TyCtxt<'_>, param: &hir::GenericParam<'_>) {
853855
)
854856
.emit();
855857
} else {
856-
struct_span_err!(
858+
let mut diag = struct_span_err!(
857859
tcx.sess,
858860
hir_ty.span,
859861
E0741,
860862
"`{}` must be annotated with `#[derive(PartialEq, Eq)]` to be used as \
861863
the type of a const parameter",
862-
ty,
863-
)
864-
.span_label(
865-
hir_ty.span,
866-
format!("`{ty}` doesn't derive both `PartialEq` and `Eq`"),
867-
)
868-
.emit();
864+
non_structural_match_ty.ty,
865+
);
866+
867+
if ty == non_structural_match_ty.ty {
868+
diag.span_label(
869+
hir_ty.span,
870+
format!("`{ty}` doesn't derive both `PartialEq` and `Eq`"),
871+
);
872+
}
873+
874+
diag.emit();
869875
}
870876
}
871877
} else {

Diff for: compiler/rustc_typeck/src/check/writeback.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,6 @@ impl<'cx, 'tcx> Visitor<'tcx> for WritebackCx<'cx, 'tcx> {
263263
self.fix_scalar_builtin_expr(e);
264264
self.fix_index_builtin_expr(e);
265265

266-
self.visit_node_id(e.span, e.hir_id);
267-
268266
match e.kind {
269267
hir::ExprKind::Closure(_, _, body, _, _) => {
270268
let body = self.fcx.tcx.hir().body(body);
@@ -291,6 +289,7 @@ impl<'cx, 'tcx> Visitor<'tcx> for WritebackCx<'cx, 'tcx> {
291289
_ => {}
292290
}
293291

292+
self.visit_node_id(e.span, e.hir_id);
294293
intravisit::walk_expr(self, e);
295294
}
296295

Diff for: src/test/ui/const-generics/issues/issue-63322-forbid-dyn.full.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error[E0741]: `&'static (dyn A + 'static)` must be annotated with `#[derive(PartialEq, Eq)]` to be used as the type of a const parameter
1+
error[E0741]: `(dyn A + 'static)` must be annotated with `#[derive(PartialEq, Eq)]` to be used as the type of a const parameter
22
--> $DIR/issue-63322-forbid-dyn.rs:9:18
33
|
44
LL | fn test<const T: &'static dyn A>() {
5-
| ^^^^^^^^^^^^^^ `&'static (dyn A + 'static)` doesn't derive both `PartialEq` and `Eq`
5+
| ^^^^^^^^^^^^^^
66

77
error: aborting due to previous error
88

Diff for: src/test/ui/const-generics/issues/issue-97278.rs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#![feature(adt_const_params)]
2+
#![allow(incomplete_features)]
3+
4+
use std::sync::Arc;
5+
6+
#[derive(PartialEq, Eq)]
7+
enum Bar {
8+
Bar(Arc<i32>)
9+
}
10+
11+
fn test<const BAR: Bar>() {}
12+
//~^ ERROR `Arc<i32>` must be annotated with `#[derive(PartialEq, Eq)]`
13+
14+
fn main() {}

Diff for: src/test/ui/const-generics/issues/issue-97278.stderr

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0741]: `Arc<i32>` must be annotated with `#[derive(PartialEq, Eq)]` to be used as the type of a const parameter
2+
--> $DIR/issue-97278.rs:11:20
3+
|
4+
LL | fn test<const BAR: Bar>() {}
5+
| ^^^
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0741`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Regression test for issue #97299, one command line library with modifiers
2+
// overrides another command line library with modifiers.
3+
4+
// compile-flags:-lstatic:+whole-archive=foo -lstatic:+whole-archive=foo
5+
// error-pattern: overriding linking modifiers from command line is not supported
6+
7+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
error: overriding linking modifiers from command line is not supported
2+
3+
error: aborting due to previous error
4+

Diff for: src/test/ui/traits/issue-82830.rs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
trait A<Y, N> {
2+
type B;
3+
}
4+
5+
type MaybeBox<T> = <T as A<T, Box<T>>>::B;
6+
struct P {
7+
t: MaybeBox<P>, //~ ERROR: overflow evaluating the requirement `P: Sized`
8+
}
9+
10+
impl<Y, N> A<Y, N> for P {
11+
type B = N;
12+
}
13+
14+
fn main() {
15+
let t: MaybeBox<P>;
16+
}

Diff for: src/test/ui/traits/issue-82830.stderr

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0275]: overflow evaluating the requirement `P: Sized`
2+
--> $DIR/issue-82830.rs:7:8
3+
|
4+
LL | t: MaybeBox<P>,
5+
| ^^^^^^^^^^^
6+
|
7+
note: required because of the requirements on the impl of `A<P, Box<P>>` for `P`
8+
--> $DIR/issue-82830.rs:10:12
9+
|
10+
LL | impl<Y, N> A<Y, N> for P {
11+
| ^^^^^^^ ^
12+
13+
error: aborting due to previous error
14+
15+
For more information about this error, try `rustc --explain E0275`.
+16-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1-
fn main() {
2-
let x = |_| { }; //~ ERROR type annotations needed
1+
fn infer_in_arg() {
2+
let x = |b: Vec<_>| {}; //~ ERROR E0282
33
}
4+
5+
fn empty_pattern() {
6+
let x = |_| {}; //~ ERROR type annotations needed
7+
}
8+
9+
fn infer_ty() {
10+
let x = |k: _| {}; //~ ERROR type annotations needed
11+
}
12+
13+
fn ambig_return() {
14+
let x = || -> Vec<_> { Vec::new() }; //~ ERROR type annotations needed for the closure `fn() -> Vec<_>`
15+
}
16+
17+
fn main() {}
+26-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,32 @@
1-
error[E0282]: type annotations needed
1+
error[E0282]: type annotations needed for `Vec<_>`
22
--> $DIR/unknown_type_for_closure.rs:2:14
33
|
4-
LL | let x = |_| { };
4+
LL | let x = |b: Vec<_>| {};
55
| ^ consider giving this closure parameter a type
66

7-
error: aborting due to previous error
7+
error[E0282]: type annotations needed
8+
--> $DIR/unknown_type_for_closure.rs:6:14
9+
|
10+
LL | let x = |_| {};
11+
| ^ consider giving this closure parameter a type
12+
13+
error[E0282]: type annotations needed
14+
--> $DIR/unknown_type_for_closure.rs:10:14
15+
|
16+
LL | let x = |k: _| {};
17+
| ^ consider giving this closure parameter a type
18+
19+
error[E0282]: type annotations needed for the closure `fn() -> Vec<_>`
20+
--> $DIR/unknown_type_for_closure.rs:14:28
21+
|
22+
LL | let x = || -> Vec<_> { Vec::new() };
23+
| ^^^^^^^^ cannot infer type for type parameter `T`
24+
|
25+
help: give this closure an explicit return type without `_` placeholders
26+
|
27+
LL | let x = || -> Vec<_> { Vec::new() };
28+
| ~~~~~~
29+
30+
error: aborting due to 4 previous errors
831

932
For more information about this error, try `rustc --explain E0282`.

0 commit comments

Comments
 (0)