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 f940188

Browse files
committedJan 25, 2025
Auto merge of #136041 - matthiaskrgr:rollup-5r1k45x, r=matthiaskrgr
Rollup of 9 pull requests Successful merges: - #135971 (Properly report error when object type param default references self) - #135977 (Fix `FormattingOptions` instantiation with `Default`) - #135985 (Rename test to `unresolvable-upvar-issue-87987.rs` and add some notes) - #135991 (Fix set_name in thread mod for NuttX) - #136009 (bootstrap: Handle bootstrap lockfile race condition better) - #136018 (Use short ty string for move errors) - #136027 (Skip suggestions in `derive`d code) - #136029 (Bootstrap: Don't move ownership of job object) - #136034 (fix(bootstrap): deserialize null as `f64::NAN`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 6365178 + a330c7e commit f940188

File tree

34 files changed

+274
-126
lines changed

34 files changed

+274
-126
lines changed
 

‎compiler/rustc_borrowck/messages.ftl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ borrowck_lifetime_constraints_error =
9292
borrowck_limitations_implies_static =
9393
due to current limitations in the borrow checker, this implies a `'static` lifetime
9494
95+
borrowck_long_type_consider_verbose = consider using `--verbose` to print the full type name to the console
96+
borrowck_long_type_full_path = the full type name has been written to '{$path}'
97+
9598
borrowck_move_closure_suggestion =
9699
consider adding 'move' keyword before the nested closure
97100

‎compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,8 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
289289
None => "value".to_owned(),
290290
};
291291
if needs_note {
292+
let mut path = None;
293+
let ty = self.infcx.tcx.short_ty_string(ty, &mut path);
292294
if let Some(local) = place.as_local() {
293295
let span = self.body.local_decls[local].source_info.span;
294296
err.subdiagnostic(crate::session_diagnostics::TypeNoCopy::Label {
@@ -304,6 +306,11 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
304306
place: &note_msg,
305307
});
306308
};
309+
if let Some(path) = path {
310+
err.subdiagnostic(crate::session_diagnostics::LongTypePath {
311+
path: path.display().to_string(),
312+
});
313+
}
307314
}
308315

309316
if let UseSpans::FnSelfUse {

‎compiler/rustc_borrowck/src/diagnostics/move_errors.rs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -596,12 +596,19 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
596596
self.suggest_cloning(err, place_ty, expr, None);
597597
}
598598

599+
let mut path = None;
600+
let ty = self.infcx.tcx.short_ty_string(place_ty, &mut path);
599601
err.subdiagnostic(crate::session_diagnostics::TypeNoCopy::Label {
600602
is_partial_move: false,
601-
ty: place_ty,
603+
ty,
602604
place: &place_desc,
603605
span,
604606
});
607+
if let Some(path) = path {
608+
err.subdiagnostic(crate::session_diagnostics::LongTypePath {
609+
path: path.display().to_string(),
610+
});
611+
}
605612
} else {
606613
binds_to.sort();
607614
binds_to.dedup();
@@ -628,12 +635,19 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
628635
self.suggest_cloning(err, place_ty, expr, Some(use_spans));
629636
}
630637

638+
let mut path = None;
639+
let ty = self.infcx.tcx.short_ty_string(place_ty, &mut path);
631640
err.subdiagnostic(crate::session_diagnostics::TypeNoCopy::Label {
632641
is_partial_move: false,
633-
ty: place_ty,
642+
ty,
634643
place: &place_desc,
635644
span: use_span,
636645
});
646+
if let Some(path) = path {
647+
err.subdiagnostic(crate::session_diagnostics::LongTypePath {
648+
path: path.display().to_string(),
649+
});
650+
}
637651

638652
use_spans.args_subdiag(err, |args_span| {
639653
crate::session_diagnostics::CaptureArgLabel::MoveOutPlace {
@@ -831,12 +845,19 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
831845
self.suggest_cloning(err, bind_to.ty, expr, None);
832846
}
833847

848+
let mut path = None;
849+
let ty = self.infcx.tcx.short_ty_string(bind_to.ty, &mut path);
834850
err.subdiagnostic(crate::session_diagnostics::TypeNoCopy::Label {
835851
is_partial_move: false,
836-
ty: bind_to.ty,
852+
ty,
837853
place: place_desc,
838854
span: binding_span,
839855
});
856+
if let Some(path) = path {
857+
err.subdiagnostic(crate::session_diagnostics::LongTypePath {
858+
path: path.display().to_string(),
859+
});
860+
}
840861
}
841862
}
842863

‎compiler/rustc_borrowck/src/session_diagnostics.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -459,17 +459,24 @@ pub(crate) enum OnClosureNote<'a> {
459459
}
460460

461461
#[derive(Subdiagnostic)]
462-
pub(crate) enum TypeNoCopy<'a, 'tcx> {
462+
#[note(borrowck_long_type_full_path)]
463+
#[note(borrowck_long_type_consider_verbose)]
464+
pub(crate) struct LongTypePath {
465+
pub(crate) path: String,
466+
}
467+
468+
#[derive(Subdiagnostic)]
469+
pub(crate) enum TypeNoCopy<'a> {
463470
#[label(borrowck_ty_no_impl_copy)]
464471
Label {
465472
is_partial_move: bool,
466-
ty: Ty<'tcx>,
473+
ty: String,
467474
place: &'a str,
468475
#[primary_span]
469476
span: Span,
470477
},
471478
#[note(borrowck_ty_no_impl_copy)]
472-
Note { is_partial_move: bool, ty: Ty<'tcx>, place: &'a str },
479+
Note { is_partial_move: bool, ty: String, place: &'a str },
473480
}
474481

475482
#[derive(Diagnostic)]

‎compiler/rustc_error_codes/src/error_codes/E0393.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@ A type parameter which references `Self` in its default value was not specified.
33
Erroneous code example:
44

55
```compile_fail,E0393
6-
trait A<T=Self> {}
6+
trait A<T = Self> {}
77
8-
fn together_we_will_rule_the_galaxy(son: &A) {}
9-
// error: the type parameter `T` must be explicitly specified in an
10-
// object type because its default value `Self` references the
11-
// type `Self`
8+
fn together_we_will_rule_the_galaxy(son: &dyn A) {}
9+
// error: the type parameter `T` must be explicitly specified
1210
```
1311

1412
A trait object is defined over a single, fully-defined trait. With a regular
@@ -23,7 +21,7 @@ disallowed. Making the trait concrete by explicitly specifying the value of the
2321
defaulted parameter will fix this issue. Fixed example:
2422

2523
```
26-
trait A<T=Self> {}
24+
trait A<T = Self> {}
2725
28-
fn together_we_will_rule_the_galaxy(son: &A<i32>) {} // Ok!
26+
fn together_we_will_rule_the_galaxy(son: &dyn A<i32>) {} // Ok!
2927
```

‎compiler/rustc_hir_analysis/messages.ftl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,13 @@ hir_analysis_missing_type_params =
353353
[one] reference
354354
*[other] references
355355
} to {$parameters}
356-
.note = because of the default `Self` reference, type parameters must be specified on object types
356+
.note = because the parameter {$parameterCount ->
357+
[one] default references
358+
*[other] defaults reference
359+
} `Self`, the {$parameterCount ->
360+
[one] parameter
361+
*[other] parameters
362+
} must be specified on the object type
357363
358364
hir_analysis_multiple_relaxed_default_bounds =
359365
type parameter has more than one relaxed default bound, only one is supported

‎compiler/rustc_hir_analysis/src/hir_ty_lowering/dyn_compatibility.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -237,16 +237,10 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
237237
// Skip `Self`
238238
.skip(1)
239239
.map(|(index, arg)| {
240-
if arg == dummy_self.into() {
240+
if arg.walk().any(|arg| arg == dummy_self.into()) {
241241
let param = &generics.own_params[index];
242242
missing_type_params.push(param.name);
243243
Ty::new_misc_error(tcx).into()
244-
} else if arg.walk().any(|arg| arg == dummy_self.into()) {
245-
let guar = self.dcx().span_delayed_bug(
246-
span,
247-
"trait object trait bounds reference `Self`",
248-
);
249-
replace_dummy_self_with_error(tcx, arg, guar)
250244
} else {
251245
arg
252246
}

‎compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
185185
rhs_ty: Ty<'tcx>,
186186
can_satisfy: impl FnOnce(Ty<'tcx>, Ty<'tcx>) -> bool,
187187
) -> bool {
188+
if lhs_expr.span.in_derive_expansion() || rhs_expr.span.in_derive_expansion() {
189+
return false;
190+
}
188191
let Some((_, lhs_output_ty, lhs_inputs)) = self.extract_callable_info(lhs_ty) else {
189192
return false;
190193
};

‎compiler/rustc_mir_build/messages.ftl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ mir_build_borrow_of_moved_value = borrow of moved value
2525
.occurs_because_label = move occurs because `{$name}` has type `{$ty}`, which does not implement the `Copy` trait
2626
.value_borrowed_label = value borrowed here after move
2727
.suggestion = borrow this binding in the pattern to avoid moving the value
28+
.full_type_name = the full type name has been written to '{$path}'
29+
.consider_verbose = consider using `--verbose` to print the full type name to the console
2830
2931
mir_build_call_to_deprecated_safe_fn_requires_unsafe =
3032
call to deprecated safe function `{$function}` is unsafe and requires unsafe block

‎compiler/rustc_mir_build/src/errors.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -790,17 +790,21 @@ pub(crate) struct IrrefutableLetPatternsWhileLet {
790790

791791
#[derive(Diagnostic)]
792792
#[diag(mir_build_borrow_of_moved_value)]
793-
pub(crate) struct BorrowOfMovedValue<'tcx> {
793+
pub(crate) struct BorrowOfMovedValue {
794794
#[primary_span]
795795
#[label]
796796
#[label(mir_build_occurs_because_label)]
797797
pub(crate) binding_span: Span,
798798
#[label(mir_build_value_borrowed_label)]
799799
pub(crate) conflicts_ref: Vec<Span>,
800800
pub(crate) name: Symbol,
801-
pub(crate) ty: Ty<'tcx>,
801+
pub(crate) ty: String,
802802
#[suggestion(code = "ref ", applicability = "machine-applicable")]
803803
pub(crate) suggest_borrowing: Option<Span>,
804+
#[note(mir_build_full_type_name)]
805+
#[note(mir_build_consider_verbose)]
806+
pub(crate) has_path: bool,
807+
pub(crate) path: String,
804808
}
805809

806810
#[derive(Diagnostic)]

‎compiler/rustc_mir_build/src/thir/pattern/check_match.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -795,12 +795,16 @@ fn check_borrow_conflicts_in_at_patterns<'tcx>(cx: &MatchVisitor<'_, 'tcx>, pat:
795795
}
796796
});
797797
if !conflicts_ref.is_empty() {
798+
let mut path = None;
799+
let ty = cx.tcx.short_ty_string(ty, &mut path);
798800
sess.dcx().emit_err(BorrowOfMovedValue {
799801
binding_span: pat.span,
800802
conflicts_ref,
801803
name,
802804
ty,
803805
suggest_borrowing: Some(pat.span.shrink_to_lo()),
806+
has_path: path.is_some(),
807+
path: path.map(|p| p.display().to_string()).unwrap_or_default(),
804808
});
805809
}
806810
return;

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ pub enum DebugAsHex {
288288
///
289289
/// `FormattingOptions` is a [`Formatter`] without an attached [`Write`] trait.
290290
/// It is mainly used to construct `Formatter` instances.
291-
#[derive(Copy, Clone, Debug, PartialEq, Eq, Default)]
291+
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
292292
#[unstable(feature = "formatting_options", issue = "118117")]
293293
pub struct FormattingOptions {
294294
flags: u32,
@@ -508,6 +508,15 @@ impl FormattingOptions {
508508
}
509509
}
510510

511+
#[unstable(feature = "formatting_options", issue = "118117")]
512+
impl Default for FormattingOptions {
513+
/// Same as [`FormattingOptions::new()`].
514+
fn default() -> Self {
515+
// The `#[derive(Default)]` implementation would set `fill` to `\0` instead of space.
516+
Self::new()
517+
}
518+
}
519+
511520
/// Configuration for formatting.
512521
///
513522
/// A `Formatter` represents various options related to formatting. Users do not

‎library/core/tests/fmt/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ fn test_maybe_uninit_short() {
5151
assert_eq!(format!("{x:?}"), "MaybeUninit<u32>");
5252
}
5353

54+
#[test]
55+
fn formatting_options_ctor() {
56+
use core::fmt::FormattingOptions;
57+
assert_eq!(FormattingOptions::new(), FormattingOptions::default());
58+
}
59+
5460
#[test]
5561
fn formatting_options_flags() {
5662
use core::fmt::*;

‎library/std/src/sys/pal/unix/thread.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,12 @@ impl Thread {
130130
}
131131
}
132132

133-
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "dragonfly"))]
133+
#[cfg(any(
134+
target_os = "linux",
135+
target_os = "freebsd",
136+
target_os = "dragonfly",
137+
target_os = "nuttx"
138+
))]
134139
pub fn set_name(name: &CStr) {
135140
unsafe {
136141
cfg_if::cfg_if! {
@@ -139,7 +144,7 @@ impl Thread {
139144
const TASK_COMM_LEN: usize = 16;
140145
let name = truncate_cstr::<{ TASK_COMM_LEN }>(name);
141146
} else {
142-
// FreeBSD and DragonFly BSD do not enforce length limits.
147+
// FreeBSD, DragonFly, FreeBSD and NuttX do not enforce length limits.
143148
}
144149
};
145150
// Available since glibc 2.12, musl 1.1.16, and uClibc 1.0.20 for Linux,
@@ -150,7 +155,7 @@ impl Thread {
150155
}
151156
}
152157

153-
#[cfg(any(target_os = "openbsd", target_os = "nuttx"))]
158+
#[cfg(target_os = "openbsd")]
154159
pub fn set_name(name: &CStr) {
155160
unsafe {
156161
libc::pthread_set_name_np(libc::pthread_self(), name.as_ptr());

‎src/bootstrap/bootstrap.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1310,9 +1310,6 @@ def bootstrap(args):
13101310
args = [build.bootstrap_binary()]
13111311
args.extend(sys.argv[1:])
13121312
env = os.environ.copy()
1313-
# The Python process ID is used when creating a Windows job object
1314-
# (see src\bootstrap\src\utils\job.rs)
1315-
env["BOOTSTRAP_PARENT_ID"] = str(os.getpid())
13161313
env["BOOTSTRAP_PYTHON"] = sys.executable
13171314
run(args, env=env, verbose=build.verbose, is_bootstrap=True)
13181315

‎src/bootstrap/src/bin/main.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ fn main() {
5757
}
5858
err => {
5959
drop(err);
60-
if let Ok(pid) = pid {
60+
// #135972: We can reach this point when the lock has been taken,
61+
// but the locker has not yet written its PID to the file
62+
if let Some(pid) = pid.ok().filter(|pid| !pid.is_empty()) {
6163
println!("WARNING: build directory locked by process {pid}, waiting for lock");
6264
} else {
6365
println!("WARNING: build directory locked, waiting for lock");

‎src/bootstrap/src/utils/job.rs

Lines changed: 4 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ pub unsafe fn setup(build: &mut crate::Build) {
4242
#[cfg(windows)]
4343
mod for_windows {
4444
use std::ffi::c_void;
45-
use std::{env, io, mem};
45+
use std::{io, mem};
4646

47-
use windows::Win32::Foundation::{CloseHandle, DUPLICATE_SAME_ACCESS, DuplicateHandle, HANDLE};
47+
use windows::Win32::Foundation::CloseHandle;
4848
use windows::Win32::System::Diagnostics::Debug::{
4949
SEM_NOGPFAULTERRORBOX, SetErrorMode, THREAD_ERROR_MODE,
5050
};
@@ -53,9 +53,7 @@ mod for_windows {
5353
JOB_OBJECT_LIMIT_PRIORITY_CLASS, JOBOBJECT_EXTENDED_LIMIT_INFORMATION,
5454
JobObjectExtendedLimitInformation, SetInformationJobObject,
5555
};
56-
use windows::Win32::System::Threading::{
57-
BELOW_NORMAL_PRIORITY_CLASS, GetCurrentProcess, OpenProcess, PROCESS_DUP_HANDLE,
58-
};
56+
use windows::Win32::System::Threading::{BELOW_NORMAL_PRIORITY_CLASS, GetCurrentProcess};
5957
use windows::core::PCWSTR;
6058

6159
use crate::Build;
@@ -95,49 +93,8 @@ mod for_windows {
9593
return;
9694
}
9795

98-
// If we've got a parent process (e.g., the python script that called us)
99-
// then move ownership of this job object up to them. That way if the python
100-
// script is killed (e.g., via ctrl-c) then we'll all be torn down.
101-
//
102-
// If we don't have a parent (e.g., this was run directly) then we
103-
// intentionally leak the job object handle. When our process exits
96+
// Note: we intentionally leak the job object handle. When our process exits
10497
// (normally or abnormally) it will close the handle implicitly, causing all
10598
// processes in the job to be cleaned up.
106-
let pid = match env::var("BOOTSTRAP_PARENT_ID") {
107-
Ok(s) => s,
108-
Err(..) => return,
109-
};
110-
111-
let parent = match OpenProcess(PROCESS_DUP_HANDLE, false, pid.parse().unwrap()).ok() {
112-
Some(parent) => parent,
113-
_ => {
114-
// If we get a null parent pointer here, it is possible that either
115-
// we have an invalid pid or the parent process has been closed.
116-
// Since the first case rarely happens
117-
// (only when wrongly setting the environmental variable),
118-
// it might be better to improve the experience of the second case
119-
// when users have interrupted the parent process and we haven't finish
120-
// duplicating the handle yet.
121-
return;
122-
}
123-
};
124-
125-
let mut parent_handle = HANDLE::default();
126-
// If this fails, well at least we tried! An example of DuplicateHandle
127-
// failing in the past has been when the wrong python2 package spawned this
128-
// build system (e.g., the `python2` package in MSYS instead of
129-
// `mingw-w64-x86_64-python2`). Not sure why it failed, but the "failure
130-
// mode" here is that we only clean everything up when the build system
131-
// dies, not when the python parent does, so not too bad.
132-
let _ = DuplicateHandle(
133-
GetCurrentProcess(),
134-
job,
135-
parent,
136-
&mut parent_handle,
137-
0,
138-
false,
139-
DUPLICATE_SAME_ACCESS,
140-
);
141-
CloseHandle(parent).ok();
14299
}
143100
}

‎src/build_helper/src/metrics.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ pub struct JsonInvocation {
1616
//
1717
// This is necessary to easily correlate this invocation with logs or other data.
1818
pub start_time: u64,
19+
#[serde(deserialize_with = "null_as_f64_nan")]
1920
pub duration_including_children_sec: f64,
2021
pub children: Vec<JsonNode>,
2122
}
@@ -28,6 +29,7 @@ pub enum JsonNode {
2829
type_: String,
2930
debug_repr: String,
3031

32+
#[serde(deserialize_with = "null_as_f64_nan")]
3133
duration_excluding_children_sec: f64,
3234
system_stats: JsonStepSystemStats,
3335

@@ -88,5 +90,11 @@ pub struct JsonInvocationSystemStats {
8890
#[derive(Serialize, Deserialize)]
8991
#[serde(rename_all = "snake_case")]
9092
pub struct JsonStepSystemStats {
93+
#[serde(deserialize_with = "null_as_f64_nan")]
9194
pub cpu_utilization_percent: f64,
9295
}
96+
97+
fn null_as_f64_nan<'de, D: serde::Deserializer<'de>>(d: D) -> Result<f64, D::Error> {
98+
use serde::Deserialize as _;
99+
Option::<f64>::deserialize(d).map(|f| f.unwrap_or(f64::NAN))
100+
}

‎src/tools/tidy/src/issues.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,6 @@ ui/closure_context/issue-26046-fn-once.rs
409409
ui/closure_context/issue-42065.rs
410410
ui/closures/2229_closure_analysis/issue-118144.rs
411411
ui/closures/2229_closure_analysis/issue-87378.rs
412-
ui/closures/2229_closure_analysis/issue-87987.rs
413412
ui/closures/2229_closure_analysis/issue-88118-2.rs
414413
ui/closures/2229_closure_analysis/issue-88476.rs
415414
ui/closures/2229_closure_analysis/issue-89606.rs

‎tests/ui/closures/2229_closure_analysis/issue-87987.rs

Lines changed: 0 additions & 27 deletions
This file was deleted.

‎tests/ui/closures/2229_closure_analysis/issue-87987.stderr

Lines changed: 0 additions & 14 deletions
This file was deleted.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
//! When a closure syntactically captures a place, but doesn't actually capture
2+
//! it, make sure MIR building doesn't ICE when handling that place.
3+
//!
4+
//! Under the Rust 2021 disjoint capture rules, this sort of non-capture can
5+
//! occur when a place is only inspected by infallible non-binding patterns.
6+
7+
// FIXME(#135985): On its own, this test should probably just be check-pass.
8+
// But there are few/no other tests that use non-binding array patterns and
9+
// invoke the later parts of the compiler, so building/running has some value.
10+
11+
//@ run-pass
12+
//@ edition:2021
13+
14+
#[expect(dead_code)]
15+
struct Props {
16+
field_1: u32,
17+
field_2: u32,
18+
}
19+
20+
fn main() {
21+
// Test 1
22+
let props_2 = Props { field_1: 1, field_2: 1 };
23+
24+
let _ = || {
25+
let _: Props = props_2;
26+
};
27+
28+
// Test 2
29+
let mut arr = [1, 3, 4, 5];
30+
31+
let mref = &mut arr;
32+
33+
// These array patterns don't need to inspect the array, so the array
34+
// isn't captured.
35+
let _c = || match arr {
36+
[_, _, _, _] => println!("C"),
37+
};
38+
let _d = || match arr {
39+
[_, .., _] => println!("D"),
40+
};
41+
let _e = || match arr {
42+
[_, ..] => println!("E"),
43+
};
44+
45+
println!("{:#?}", mref);
46+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
use std::rc::Rc;
2+
3+
#[derive(PartialEq)] //~ NOTE in this expansion
4+
pub struct Function {
5+
callback: Rc<dyn Fn()>, //~ ERROR binary operation `==` cannot be applied to type `Rc<dyn Fn()>`
6+
}
7+
8+
fn main() {}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error[E0369]: binary operation `==` cannot be applied to type `Rc<dyn Fn()>`
2+
--> $DIR/do-not-suggest-calling-fn-in-derive-macro.rs:5:5
3+
|
4+
LL | #[derive(PartialEq)]
5+
| --------- in this derive macro expansion
6+
LL | pub struct Function {
7+
LL | callback: Rc<dyn Fn()>,
8+
| ^^^^^^^^^^^^^^^^^^^^^^
9+
|
10+
= note: this error originates in the derive macro `PartialEq` (in Nightly builds, run with -Z macro-backtrace for more info)
11+
12+
error: aborting due to 1 previous error
13+
14+
For more information about this error, try `rustc --explain E0369`.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//@ compile-flags: --diagnostic-width=60 -Zwrite-long-types-to-disk=yes
2+
//@ normalize-stderr: "long-type-\d+" -> "long-type-hash"
3+
type A = (String, String, String, String);
4+
type B = (A, A, A, A);
5+
type C = (B, B, B, B);
6+
type D = (C, C, C, C);
7+
8+
trait Trait {}
9+
10+
fn require_trait<T: Trait>() {}
11+
12+
fn foo(x: D) {
13+
let _a = x;
14+
let _b = x; //~ ERROR use of moved value
15+
}
16+
17+
fn main() {}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
error[E0382]: use of moved value: `x`
2+
--> $DIR/non-copy-type-moved.rs:14:14
3+
|
4+
LL | fn foo(x: D) {
5+
| - move occurs because `x` has type `((..., ..., ..., ...), ..., ..., ...)`, which does not implement the `Copy` trait
6+
LL | let _a = x;
7+
| - value moved here
8+
LL | let _b = x;
9+
| ^ value used here after move
10+
|
11+
= note: the full type name has been written to '$TEST_BUILD_DIR/diagnostic-width/non-copy-type-moved/non-copy-type-moved.long-type-hash.txt'
12+
= note: consider using `--verbose` to print the full type name to the console
13+
help: consider cloning the value if the performance cost is acceptable
14+
|
15+
LL | let _a = x.clone();
16+
| ++++++++
17+
18+
error: aborting due to 1 previous error
19+
20+
For more information about this error, try `rustc --explain E0382`.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
trait A<C = <Self as D>::E> {}
2+
3+
trait D {
4+
type E;
5+
}
6+
7+
impl A<()> for () {}
8+
impl D for () {
9+
type E = ();
10+
}
11+
12+
fn f() {
13+
let B: &dyn A = &();
14+
//~^ ERROR the type parameter `C` must be explicitly specified
15+
}
16+
17+
fn main() {}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
error[E0393]: the type parameter `C` must be explicitly specified
2+
--> $DIR/default-param-self-projection.rs:13:17
3+
|
4+
LL | trait A<C = <Self as D>::E> {}
5+
| --------------------------- type parameter `C` must be specified for this
6+
...
7+
LL | let B: &dyn A = &();
8+
| ^
9+
|
10+
= note: because the parameter default references `Self`, the parameter must be specified on the object type
11+
help: set the type parameter to the desired type
12+
|
13+
LL | let B: &dyn A<C> = &();
14+
| +++
15+
16+
error: aborting due to 1 previous error
17+
18+
For more information about this error, try `rustc --explain E0393`.

‎tests/ui/error-codes/E0393.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL |
77
LL | fn together_we_will_rule_the_galaxy(son: &dyn A) {}
88
| ^
99
|
10-
= note: because of the default `Self` reference, type parameters must be specified on object types
10+
= note: because the parameter default references `Self`, the parameter must be specified on the object type
1111
help: set the type parameter to the desired type
1212
|
1313
LL | fn together_we_will_rule_the_galaxy(son: &dyn A<T>) {}

‎tests/ui/issues/issue-22370.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL |
77
LL | fn f(a: &dyn A) {}
88
| ^
99
|
10-
= note: because of the default `Self` reference, type parameters must be specified on object types
10+
= note: because the parameter default references `Self`, the parameter must be specified on the object type
1111
help: set the type parameter to the desired type
1212
|
1313
LL | fn f(a: &dyn A<T>) {}

‎tests/ui/traits/object/canonicalize-fresh-infer-vars-issue-103626.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ fn w<'a, T: 'a, F: Fn(&'a T)>() {
1010
let b: &dyn FromResidual = &();
1111
//~^ ERROR: the trait `FromResidual` is not dyn compatible
1212
//~| ERROR: the trait `FromResidual` is not dyn compatible
13+
//~| ERROR the type parameter `R` must be explicitly specified
1314
}
1415

1516
fn main() {}

‎tests/ui/traits/object/canonicalize-fresh-infer-vars-issue-103626.stderr

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
error[E0393]: the type parameter `R` must be explicitly specified
2+
--> $DIR/canonicalize-fresh-infer-vars-issue-103626.rs:10:17
3+
|
4+
LL | trait FromResidual<R = <Self as Try>::Residual> {
5+
| ----------------------------------------------- type parameter `R` must be specified for this
6+
...
7+
LL | let b: &dyn FromResidual = &();
8+
| ^^^^^^^^^^^^
9+
|
10+
= note: because the parameter default references `Self`, the parameter must be specified on the object type
11+
help: set the type parameter to the desired type
12+
|
13+
LL | let b: &dyn FromResidual<R> = &();
14+
| +++
15+
116
error[E0038]: the trait `FromResidual` is not dyn compatible
217
--> $DIR/canonicalize-fresh-infer-vars-issue-103626.rs:10:32
318
|
@@ -45,6 +60,7 @@ help: alternatively, consider constraining `from_residual` so it does not apply
4560
LL | fn from_residual(residual: R) -> Self where Self: Sized;
4661
| +++++++++++++++++
4762

48-
error: aborting due to 2 previous errors
63+
error: aborting due to 3 previous errors
4964

50-
For more information about this error, try `rustc --explain E0038`.
65+
Some errors have detailed explanations: E0038, E0393.
66+
For more information about an error, try `rustc --explain E0038`.

‎tests/ui/traits/unspecified-self-in-trait-ref.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ LL | pub trait Bar<X=usize, A=Self> {
9797
LL | let e = Bar::<usize>::lol();
9898
| ^^^^^^^^^^^^ missing reference to `A`
9999
|
100-
= note: because of the default `Self` reference, type parameters must be specified on object types
100+
= note: because the parameter default references `Self`, the parameter must be specified on the object type
101101

102102
error: aborting due to 5 previous errors; 5 warnings emitted
103103

‎tests/ui/type/type-parameter-defaults-referencing-Self.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | trait Foo<T=Self> {
77
LL | fn foo(x: &dyn Foo) { }
88
| ^^^
99
|
10-
= note: because of the default `Self` reference, type parameters must be specified on object types
10+
= note: because the parameter default references `Self`, the parameter must be specified on the object type
1111
help: set the type parameter to the desired type
1212
|
1313
LL | fn foo(x: &dyn Foo<T>) { }

0 commit comments

Comments
 (0)
Please sign in to comment.