Skip to content

Commit

Permalink
Auto merge of rust-lang#136041 - matthiaskrgr:rollup-5r1k45x, r=matth…
Browse files Browse the repository at this point in the history
…iaskrgr

Rollup of 9 pull requests

Successful merges:

 - rust-lang#135971 (Properly report error when object type param default references self)
 - rust-lang#135977 (Fix `FormattingOptions` instantiation with `Default`)
 - rust-lang#135985 (Rename test to `unresolvable-upvar-issue-87987.rs` and add some notes)
 - rust-lang#135991 (Fix set_name in thread mod for NuttX)
 - rust-lang#136009 (bootstrap: Handle bootstrap lockfile race condition better)
 - rust-lang#136018 (Use short ty string for move errors)
 - rust-lang#136027 (Skip suggestions in `derive`d code)
 - rust-lang#136029 (Bootstrap: Don't move ownership of job object)
 - rust-lang#136034 (fix(bootstrap): deserialize null as `f64::NAN`)

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Jan 25, 2025
2 parents 6365178 + a330c7e commit f940188
Show file tree
Hide file tree
Showing 34 changed files with 274 additions and 126 deletions.
3 changes: 3 additions & 0 deletions compiler/rustc_borrowck/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ borrowck_lifetime_constraints_error =
borrowck_limitations_implies_static =
due to current limitations in the borrow checker, this implies a `'static` lifetime
borrowck_long_type_consider_verbose = consider using `--verbose` to print the full type name to the console
borrowck_long_type_full_path = the full type name has been written to '{$path}'
borrowck_move_closure_suggestion =
consider adding 'move' keyword before the nested closure
Expand Down
7 changes: 7 additions & 0 deletions compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,8 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
None => "value".to_owned(),
};
if needs_note {
let mut path = None;
let ty = self.infcx.tcx.short_ty_string(ty, &mut path);
if let Some(local) = place.as_local() {
let span = self.body.local_decls[local].source_info.span;
err.subdiagnostic(crate::session_diagnostics::TypeNoCopy::Label {
Expand All @@ -304,6 +306,11 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
place: &note_msg,
});
};
if let Some(path) = path {
err.subdiagnostic(crate::session_diagnostics::LongTypePath {
path: path.display().to_string(),
});
}
}

if let UseSpans::FnSelfUse {
Expand Down
27 changes: 24 additions & 3 deletions compiler/rustc_borrowck/src/diagnostics/move_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -596,12 +596,19 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
self.suggest_cloning(err, place_ty, expr, None);
}

let mut path = None;
let ty = self.infcx.tcx.short_ty_string(place_ty, &mut path);
err.subdiagnostic(crate::session_diagnostics::TypeNoCopy::Label {
is_partial_move: false,
ty: place_ty,
ty,
place: &place_desc,
span,
});
if let Some(path) = path {
err.subdiagnostic(crate::session_diagnostics::LongTypePath {
path: path.display().to_string(),
});
}
} else {
binds_to.sort();
binds_to.dedup();
Expand All @@ -628,12 +635,19 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
self.suggest_cloning(err, place_ty, expr, Some(use_spans));
}

let mut path = None;
let ty = self.infcx.tcx.short_ty_string(place_ty, &mut path);
err.subdiagnostic(crate::session_diagnostics::TypeNoCopy::Label {
is_partial_move: false,
ty: place_ty,
ty,
place: &place_desc,
span: use_span,
});
if let Some(path) = path {
err.subdiagnostic(crate::session_diagnostics::LongTypePath {
path: path.display().to_string(),
});
}

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

let mut path = None;
let ty = self.infcx.tcx.short_ty_string(bind_to.ty, &mut path);
err.subdiagnostic(crate::session_diagnostics::TypeNoCopy::Label {
is_partial_move: false,
ty: bind_to.ty,
ty,
place: place_desc,
span: binding_span,
});
if let Some(path) = path {
err.subdiagnostic(crate::session_diagnostics::LongTypePath {
path: path.display().to_string(),
});
}
}
}

Expand Down
13 changes: 10 additions & 3 deletions compiler/rustc_borrowck/src/session_diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,17 +459,24 @@ pub(crate) enum OnClosureNote<'a> {
}

#[derive(Subdiagnostic)]
pub(crate) enum TypeNoCopy<'a, 'tcx> {
#[note(borrowck_long_type_full_path)]
#[note(borrowck_long_type_consider_verbose)]
pub(crate) struct LongTypePath {
pub(crate) path: String,
}

#[derive(Subdiagnostic)]
pub(crate) enum TypeNoCopy<'a> {
#[label(borrowck_ty_no_impl_copy)]
Label {
is_partial_move: bool,
ty: Ty<'tcx>,
ty: String,
place: &'a str,
#[primary_span]
span: Span,
},
#[note(borrowck_ty_no_impl_copy)]
Note { is_partial_move: bool, ty: Ty<'tcx>, place: &'a str },
Note { is_partial_move: bool, ty: String, place: &'a str },
}

#[derive(Diagnostic)]
Expand Down
12 changes: 5 additions & 7 deletions compiler/rustc_error_codes/src/error_codes/E0393.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ A type parameter which references `Self` in its default value was not specified.
Erroneous code example:

```compile_fail,E0393
trait A<T=Self> {}
trait A<T = Self> {}
fn together_we_will_rule_the_galaxy(son: &A) {}
// error: the type parameter `T` must be explicitly specified in an
// object type because its default value `Self` references the
// type `Self`
fn together_we_will_rule_the_galaxy(son: &dyn A) {}
// error: the type parameter `T` must be explicitly specified
```

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

```
trait A<T=Self> {}
trait A<T = Self> {}
fn together_we_will_rule_the_galaxy(son: &A<i32>) {} // Ok!
fn together_we_will_rule_the_galaxy(son: &dyn A<i32>) {} // Ok!
```
8 changes: 7 additions & 1 deletion compiler/rustc_hir_analysis/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,13 @@ hir_analysis_missing_type_params =
[one] reference
*[other] references
} to {$parameters}
.note = because of the default `Self` reference, type parameters must be specified on object types
.note = because the parameter {$parameterCount ->
[one] default references
*[other] defaults reference
} `Self`, the {$parameterCount ->
[one] parameter
*[other] parameters
} must be specified on the object type
hir_analysis_multiple_relaxed_default_bounds =
type parameter has more than one relaxed default bound, only one is supported
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,16 +237,10 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
// Skip `Self`
.skip(1)
.map(|(index, arg)| {
if arg == dummy_self.into() {
if arg.walk().any(|arg| arg == dummy_self.into()) {
let param = &generics.own_params[index];
missing_type_params.push(param.name);
Ty::new_misc_error(tcx).into()
} else if arg.walk().any(|arg| arg == dummy_self.into()) {
let guar = self.dcx().span_delayed_bug(
span,
"trait object trait bounds reference `Self`",
);
replace_dummy_self_with_error(tcx, arg, guar)
} else {
arg
}
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
rhs_ty: Ty<'tcx>,
can_satisfy: impl FnOnce(Ty<'tcx>, Ty<'tcx>) -> bool,
) -> bool {
if lhs_expr.span.in_derive_expansion() || rhs_expr.span.in_derive_expansion() {
return false;
}
let Some((_, lhs_output_ty, lhs_inputs)) = self.extract_callable_info(lhs_ty) else {
return false;
};
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_mir_build/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ mir_build_borrow_of_moved_value = borrow of moved value
.occurs_because_label = move occurs because `{$name}` has type `{$ty}`, which does not implement the `Copy` trait
.value_borrowed_label = value borrowed here after move
.suggestion = borrow this binding in the pattern to avoid moving the value
.full_type_name = the full type name has been written to '{$path}'
.consider_verbose = consider using `--verbose` to print the full type name to the console
mir_build_call_to_deprecated_safe_fn_requires_unsafe =
call to deprecated safe function `{$function}` is unsafe and requires unsafe block
Expand Down
8 changes: 6 additions & 2 deletions compiler/rustc_mir_build/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -790,17 +790,21 @@ pub(crate) struct IrrefutableLetPatternsWhileLet {

#[derive(Diagnostic)]
#[diag(mir_build_borrow_of_moved_value)]
pub(crate) struct BorrowOfMovedValue<'tcx> {
pub(crate) struct BorrowOfMovedValue {
#[primary_span]
#[label]
#[label(mir_build_occurs_because_label)]
pub(crate) binding_span: Span,
#[label(mir_build_value_borrowed_label)]
pub(crate) conflicts_ref: Vec<Span>,
pub(crate) name: Symbol,
pub(crate) ty: Ty<'tcx>,
pub(crate) ty: String,
#[suggestion(code = "ref ", applicability = "machine-applicable")]
pub(crate) suggest_borrowing: Option<Span>,
#[note(mir_build_full_type_name)]
#[note(mir_build_consider_verbose)]
pub(crate) has_path: bool,
pub(crate) path: String,
}

#[derive(Diagnostic)]
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_mir_build/src/thir/pattern/check_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -795,12 +795,16 @@ fn check_borrow_conflicts_in_at_patterns<'tcx>(cx: &MatchVisitor<'_, 'tcx>, pat:
}
});
if !conflicts_ref.is_empty() {
let mut path = None;
let ty = cx.tcx.short_ty_string(ty, &mut path);
sess.dcx().emit_err(BorrowOfMovedValue {
binding_span: pat.span,
conflicts_ref,
name,
ty,
suggest_borrowing: Some(pat.span.shrink_to_lo()),
has_path: path.is_some(),
path: path.map(|p| p.display().to_string()).unwrap_or_default(),
});
}
return;
Expand Down
11 changes: 10 additions & 1 deletion library/core/src/fmt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ pub enum DebugAsHex {
///
/// `FormattingOptions` is a [`Formatter`] without an attached [`Write`] trait.
/// It is mainly used to construct `Formatter` instances.
#[derive(Copy, Clone, Debug, PartialEq, Eq, Default)]
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[unstable(feature = "formatting_options", issue = "118117")]
pub struct FormattingOptions {
flags: u32,
Expand Down Expand Up @@ -508,6 +508,15 @@ impl FormattingOptions {
}
}

#[unstable(feature = "formatting_options", issue = "118117")]
impl Default for FormattingOptions {
/// Same as [`FormattingOptions::new()`].
fn default() -> Self {
// The `#[derive(Default)]` implementation would set `fill` to `\0` instead of space.
Self::new()
}
}

/// Configuration for formatting.
///
/// A `Formatter` represents various options related to formatting. Users do not
Expand Down
6 changes: 6 additions & 0 deletions library/core/tests/fmt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ fn test_maybe_uninit_short() {
assert_eq!(format!("{x:?}"), "MaybeUninit<u32>");
}

#[test]
fn formatting_options_ctor() {
use core::fmt::FormattingOptions;
assert_eq!(FormattingOptions::new(), FormattingOptions::default());
}

#[test]
fn formatting_options_flags() {
use core::fmt::*;
Expand Down
11 changes: 8 additions & 3 deletions library/std/src/sys/pal/unix/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,12 @@ impl Thread {
}
}

#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "dragonfly"))]
#[cfg(any(
target_os = "linux",
target_os = "freebsd",
target_os = "dragonfly",
target_os = "nuttx"
))]
pub fn set_name(name: &CStr) {
unsafe {
cfg_if::cfg_if! {
Expand All @@ -139,7 +144,7 @@ impl Thread {
const TASK_COMM_LEN: usize = 16;
let name = truncate_cstr::<{ TASK_COMM_LEN }>(name);
} else {
// FreeBSD and DragonFly BSD do not enforce length limits.
// FreeBSD, DragonFly, FreeBSD and NuttX do not enforce length limits.
}
};
// Available since glibc 2.12, musl 1.1.16, and uClibc 1.0.20 for Linux,
Expand All @@ -150,7 +155,7 @@ impl Thread {
}
}

#[cfg(any(target_os = "openbsd", target_os = "nuttx"))]
#[cfg(target_os = "openbsd")]
pub fn set_name(name: &CStr) {
unsafe {
libc::pthread_set_name_np(libc::pthread_self(), name.as_ptr());
Expand Down
3 changes: 0 additions & 3 deletions src/bootstrap/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -1310,9 +1310,6 @@ def bootstrap(args):
args = [build.bootstrap_binary()]
args.extend(sys.argv[1:])
env = os.environ.copy()
# The Python process ID is used when creating a Windows job object
# (see src\bootstrap\src\utils\job.rs)
env["BOOTSTRAP_PARENT_ID"] = str(os.getpid())
env["BOOTSTRAP_PYTHON"] = sys.executable
run(args, env=env, verbose=build.verbose, is_bootstrap=True)

Expand Down
4 changes: 3 additions & 1 deletion src/bootstrap/src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ fn main() {
}
err => {
drop(err);
if let Ok(pid) = pid {
// #135972: We can reach this point when the lock has been taken,
// but the locker has not yet written its PID to the file
if let Some(pid) = pid.ok().filter(|pid| !pid.is_empty()) {
println!("WARNING: build directory locked by process {pid}, waiting for lock");
} else {
println!("WARNING: build directory locked, waiting for lock");
Expand Down
Loading

0 comments on commit f940188

Please sign in to comment.