Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 6 pull requests #97662

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions compiler/rustc_passes/src/dead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -722,11 +722,7 @@ impl<'tcx> DeadVisitor<'tcx> {
traits_str,
is_are
);
let multispan = ign_traits
.iter()
.map(|(_, impl_id)| self.tcx.def_span(*impl_id))
.collect::<Vec<_>>();
err.span_note(multispan, &msg);
err.note(&msg);
}
err.emit();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ use rustc_hir::lang_items::LangItem;
use rustc_hir::{AsyncGeneratorKind, GeneratorKind, Node};
use rustc_middle::hir::map;
use rustc_middle::ty::{
self, suggest_arbitrary_trait_bound, suggest_constraining_type_param, AdtKind, DefIdTree,
self,
subst::{GenericArgKind, SubstsRef},
suggest_arbitrary_trait_bound, suggest_constraining_type_param, AdtKind, DefIdTree,
GeneratorDiagnosticData, GeneratorInteriorTypeCause, Infer, InferTy, ToPredicate, Ty, TyCtxt,
TypeFoldable,
};
Expand Down Expand Up @@ -458,6 +460,16 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
_ => (false, None),
};

let generic_args_have_impl_trait = |args: SubstsRef<'tcx>| -> bool {
args.iter().any(|arg| match arg.unpack() {
GenericArgKind::Type(ty) => match ty.kind() {
ty::Param(param) => param.name.as_str().starts_with("impl"),
_ => false,
},
_ => false,
})
};

// FIXME: Add check for trait bound that is already present, particularly `?Sized` so we
// don't suggest `T: Sized + ?Sized`.
let mut hir_id = body_id;
Expand Down Expand Up @@ -588,7 +600,9 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
| hir::ItemKind::TraitAlias(generics, _)
| hir::ItemKind::OpaqueTy(hir::OpaqueTy { generics, .. }),
..
}) if !param_ty => {
}) if !param_ty
&& !generic_args_have_impl_trait(trait_pred.skip_binder().trait_ref.substs) =>
{
// Missing generic type parameter bound.
let param_name = self_ty.to_string();
let constraint = trait_pred.print_modifiers_and_trait_path().to_string();
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_typeck/src/coherence/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ fn enforce_trait_manually_implementable(
E0322,
"explicit impls for the `Pointee` trait are not permitted"
)
.span_label(span, "impl of 'Pointee' not allowed")
.span_label(span, "impl of `Pointee` not allowed")
.emit();
return;
}
Expand All @@ -70,7 +70,7 @@ fn enforce_trait_manually_implementable(
E0322,
"explicit impls for the `DiscriminantKind` trait are not permitted"
)
.span_label(span, "impl of 'DiscriminantKind' not allowed")
.span_label(span, "impl of `DiscriminantKind` not allowed")
.emit();
return;
}
Expand All @@ -83,7 +83,7 @@ fn enforce_trait_manually_implementable(
E0322,
"explicit impls for the `Sized` trait are not permitted"
)
.span_label(span, "impl of 'Sized' not allowed")
.span_label(span, "impl of `Sized` not allowed")
.emit();
return;
}
Expand Down
32 changes: 28 additions & 4 deletions library/alloc/src/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,13 @@ impl<T> Box<T> {
Self::new_zeroed_in(Global)
}

/// Constructs a new `Pin<Box<T>>`. If `T` does not implement `Unpin`, then
/// Constructs a new `Pin<Box<T>>`. If `T` does not implement [`Unpin`], then
/// `x` will be pinned in memory and unable to be moved.
///
/// Constructing and pinning of the `Box` can also be done in two steps: `Box::pin(x)`
/// does the same as <code>[Box::into_pin]\([Box::new]\(x))</code>. Consider using
/// [`into_pin`](Box::into_pin) if you already have a `Box<T>`, or if you want to
/// construct a (pinned) `Box` in a different way than with [`Box::new`].
#[cfg(not(no_global_oom_handling))]
#[stable(feature = "pin", since = "1.33.0")]
#[must_use]
Expand Down Expand Up @@ -573,8 +578,13 @@ impl<T, A: Allocator> Box<T, A> {
unsafe { Ok(Box::from_raw_in(ptr.as_ptr(), alloc)) }
}

/// Constructs a new `Pin<Box<T, A>>`. If `T` does not implement `Unpin`, then
/// Constructs a new `Pin<Box<T, A>>`. If `T` does not implement [`Unpin`], then
/// `x` will be pinned in memory and unable to be moved.
///
/// Constructing and pinning of the `Box` can also be done in two steps: `Box::pin_in(x, alloc)`
/// does the same as <code>[Box::into_pin]\([Box::new_in]\(x, alloc))</code>. Consider using
/// [`into_pin`](Box::into_pin) if you already have a `Box<T, A>`, or if you want to
/// construct a (pinned) `Box` in a different way than with [`Box::new_in`].
#[cfg(not(no_global_oom_handling))]
#[unstable(feature = "allocator_api", issue = "32838")]
#[rustc_const_unstable(feature = "const_box", issue = "92521")]
Expand Down Expand Up @@ -1190,12 +1200,18 @@ impl<T: ?Sized, A: Allocator> Box<T, A> {
unsafe { &mut *mem::ManuallyDrop::new(b).0.as_ptr() }
}

/// Converts a `Box<T>` into a `Pin<Box<T>>`
/// Converts a `Box<T>` into a `Pin<Box<T>>`. If `T` does not implement [`Unpin`], then
/// `*boxed` will be pinned in memory and unable to be moved.
///
/// This conversion does not allocate on the heap and happens in place.
///
/// This is also available via [`From`].
///
/// Constructing and pinning a `Box` with <code>Box::into_pin([Box::new]\(x))</code>
/// can also be written more concisely using <code>[Box::pin]\(x)</code>.
/// This `into_pin` method is useful if you already have a `Box<T>`, or you are
/// constructing a (pinned) `Box` in a different way than with [`Box::new`].
///
/// # Notes
///
/// It's not recommended that crates add an impl like `From<Box<T>> for Pin<T>`,
Expand Down Expand Up @@ -1458,9 +1474,17 @@ impl<T: ?Sized, A: Allocator> const From<Box<T, A>> for Pin<Box<T, A>>
where
A: 'static,
{
/// Converts a `Box<T>` into a `Pin<Box<T>>`
/// Converts a `Box<T>` into a `Pin<Box<T>>`. If `T` does not implement [`Unpin`], then
/// `*boxed` will be pinned in memory and unable to be moved.
///
/// This conversion does not allocate on the heap and happens in place.
///
/// This is also available via [`Box::into_pin`].
///
/// Constructing and pinning a `Box` with <code><Pin<Box\<T>>>::from([Box::new]\(x))</code>
/// can also be written more concisely using <code>[Box::pin]\(x)</code>.
/// This `From` implementation is useful if you already have a `Box<T>`, or you are
/// constructing a (pinned) `Box` in a different way than with [`Box::new`].
fn from(boxed: Box<T, A>) -> Self {
Box::into_pin(boxed)
}
Expand Down
73 changes: 70 additions & 3 deletions library/std/src/sys/unix/process/process_unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -695,18 +695,85 @@ impl From<c_int> for ExitStatus {
}
}

/// Convert a signal number to a readable, searchable name.
///
/// This string should be displayed right after the signal number.
/// If a signal is unrecognized, it returns the empty string, so that
/// you just get the number like "0". If it is recognized, you'll get
/// something like "9 (SIGKILL)".
fn signal_string(signal: i32) -> &'static str {
match signal {
libc::SIGHUP => " (SIGHUP)",
libc::SIGINT => " (SIGINT)",
libc::SIGQUIT => " (SIGQUIT)",
libc::SIGILL => " (SIGILL)",
libc::SIGTRAP => " (SIGTRAP)",
libc::SIGABRT => " (SIGABRT)",
libc::SIGBUS => " (SIGBUS)",
libc::SIGFPE => " (SIGFPE)",
libc::SIGKILL => " (SIGKILL)",
libc::SIGUSR1 => " (SIGUSR1)",
libc::SIGSEGV => " (SIGSEGV)",
libc::SIGUSR2 => " (SIGUSR2)",
libc::SIGPIPE => " (SIGPIPE)",
libc::SIGALRM => " (SIGALRM)",
libc::SIGTERM => " (SIGTERM)",
libc::SIGCHLD => " (SIGCHLD)",
libc::SIGCONT => " (SIGCONT)",
libc::SIGSTOP => " (SIGSTOP)",
libc::SIGTSTP => " (SIGTSTP)",
libc::SIGTTIN => " (SIGTTIN)",
libc::SIGTTOU => " (SIGTTOU)",
libc::SIGURG => " (SIGURG)",
libc::SIGXCPU => " (SIGXCPU)",
libc::SIGXFSZ => " (SIGXFSZ)",
libc::SIGVTALRM => " (SIGVTALRM)",
libc::SIGPROF => " (SIGPROF)",
libc::SIGWINCH => " (SIGWINCH)",
libc::SIGIO => " (SIGIO)",
libc::SIGSYS => " (SIGSYS)",
#[cfg(target_os = "linux")]
libc::SIGSTKFLT => " (SIGSTKFLT)",
#[cfg(target_os = "linux")]
libc::SIGPWR => " (SIGPWR)",
#[cfg(any(
target_os = "macos",
target_os = "ios",
target_os = "tvos",
target_os = "freebsd",
target_os = "netbsd",
target_os = "openbsd",
target_os = "dragonfly"
))]
libc::SIGEMT => " (SIGEMT)",
#[cfg(any(
target_os = "macos",
target_os = "ios",
target_os = "tvos",
target_os = "freebsd",
target_os = "netbsd",
target_os = "openbsd",
target_os = "dragonfly"
))]
libc::SIGINFO => " (SIGINFO)",
_ => "",
}
}

impl fmt::Display for ExitStatus {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if let Some(code) = self.code() {
write!(f, "exit status: {code}")
} else if let Some(signal) = self.signal() {
let signal_string = signal_string(signal);
if self.core_dumped() {
write!(f, "signal: {signal} (core dumped)")
write!(f, "signal: {signal}{signal_string} (core dumped)")
} else {
write!(f, "signal: {signal}")
write!(f, "signal: {signal}{signal_string}")
}
} else if let Some(signal) = self.stopped_signal() {
write!(f, "stopped (not terminated) by signal: {signal}")
let signal_string = signal_string(signal);
write!(f, "stopped (not terminated) by signal: {signal}{signal_string}")
} else if self.continued() {
write!(f, "continued (WIFCONTINUED)")
} else {
Expand Down
6 changes: 3 additions & 3 deletions library/std/src/sys/unix/process/process_unix/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ fn exitstatus_display_tests() {

let t = |v, s| assert_eq!(s, format!("{}", <ExitStatus as ExitStatusExt>::from_raw(v)));

t(0x0000f, "signal: 15");
t(0x0008b, "signal: 11 (core dumped)");
t(0x0000f, "signal: 15 (SIGTERM)");
t(0x0008b, "signal: 11 (SIGSEGV) (core dumped)");
t(0x00000, "exit status: 0");
t(0x0ff00, "exit status: 255");

Expand All @@ -24,7 +24,7 @@ fn exitstatus_display_tests() {
// The purpose of this test is to test our string formatting, not our understanding of the wait
// status magic numbers. So restrict these to Linux.
if cfg!(target_os = "linux") {
t(0x0137f, "stopped (not terminated) by signal: 19");
t(0x0137f, "stopped (not terminated) by signal: 19 (SIGSTOP)");
t(0x0ffff, "continued (WIFCONTINUED)");
}

Expand Down
42 changes: 42 additions & 0 deletions src/test/rustdoc/nested-modules.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#![crate_name = "aCrate"]

mod a_module {
pub fn private_function() {}

pub use a_module::private_function as other_private_function;

pub mod a_nested_module {
// @has aCrate/a_nested_module/index.html '//a[@href="fn.a_nested_public_function.html"]' 'a_nested_public_function'
// @has aCrate/a_nested_module/fn.a_nested_public_function.html 'pub fn a_nested_public_function()'
pub fn a_nested_public_function() {}

// @has aCrate/a_nested_module/index.html '//a[@href="fn.another_nested_public_function.html"]' 'another_nested_public_function'
// @has aCrate/a_nested_module/fn.another_nested_public_function.html 'pub fn another_nested_public_function()'
pub use a_nested_module::a_nested_public_function as another_nested_public_function;
}

// @!has aCrate/a_nested_module/index.html 'yet_another_nested_public_function'
pub use a_nested_module::a_nested_public_function as yet_another_nested_public_function;

// @!has aCrate/a_nested_module/index.html 'one_last_nested_public_function'
pub use a_nested_module::another_nested_public_function as one_last_nested_public_function;
}

// @!has aCrate/index.html 'a_module'
// @has aCrate/index.html '//a[@href="a_nested_module/index.html"]' 'a_nested_module'
pub use a_module::a_nested_module;

// @has aCrate/index.html '//a[@href="fn.a_nested_public_function.html"]' 'a_nested_public_function'
// @has aCrate/index.html '//a[@href="fn.another_nested_public_function.html"]' 'another_nested_public_function'
// @has aCrate/index.html '//a[@href="fn.yet_another_nested_public_function.html"]' 'yet_another_nested_public_function'
// @has aCrate/index.html '//a[@href="fn.one_last_nested_public_function.html"]' 'one_last_nested_public_function'
pub use a_module::{
a_nested_module::{a_nested_public_function, another_nested_public_function},
one_last_nested_public_function, yet_another_nested_public_function,
};

// @has aCrate/index.html '//a[@href="fn.private_function.html"]' 'private_function'
// @!has aCrate/fn.private_function.html 'a_module'
// @has aCrate/index.html '//a[@href="fn.other_private_function.html"]' 'other_private_function'
// @!has aCrate/fn.other_private_function.html 'a_module'
pub use a_module::{other_private_function, private_function};
12 changes: 6 additions & 6 deletions src/test/ui/coherence/coherence-impls-sized.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -35,37 +35,37 @@ error[E0322]: explicit impls for the `Sized` trait are not permitted
--> $DIR/coherence-impls-sized.rs:14:1
|
LL | impl Sized for TestE {}
| ^^^^^^^^^^^^^^^^^^^^ impl of 'Sized' not allowed
| ^^^^^^^^^^^^^^^^^^^^ impl of `Sized` not allowed

error[E0322]: explicit impls for the `Sized` trait are not permitted
--> $DIR/coherence-impls-sized.rs:17:1
|
LL | impl Sized for MyType {}
| ^^^^^^^^^^^^^^^^^^^^^ impl of 'Sized' not allowed
| ^^^^^^^^^^^^^^^^^^^^^ impl of `Sized` not allowed

error[E0322]: explicit impls for the `Sized` trait are not permitted
--> $DIR/coherence-impls-sized.rs:20:1
|
LL | impl Sized for (MyType, MyType) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl of 'Sized' not allowed
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl of `Sized` not allowed

error[E0322]: explicit impls for the `Sized` trait are not permitted
--> $DIR/coherence-impls-sized.rs:24:1
|
LL | impl Sized for &'static NotSync {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl of 'Sized' not allowed
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl of `Sized` not allowed

error[E0322]: explicit impls for the `Sized` trait are not permitted
--> $DIR/coherence-impls-sized.rs:27:1
|
LL | impl Sized for [MyType] {}
| ^^^^^^^^^^^^^^^^^^^^^^^ impl of 'Sized' not allowed
| ^^^^^^^^^^^^^^^^^^^^^^^ impl of `Sized` not allowed

error[E0322]: explicit impls for the `Sized` trait are not permitted
--> $DIR/coherence-impls-sized.rs:31:1
|
LL | impl Sized for &'static [NotSync] {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl of 'Sized' not allowed
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl of `Sized` not allowed

error: aborting due to 9 previous errors

Expand Down
7 changes: 1 addition & 6 deletions src/test/ui/derive-uninhabited-enum-38885.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,7 @@ LL | Void(Void),
| ^^^^^^^^^^
|
= note: `-W dead-code` implied by `-W unused`
note: `Foo` has a derived impl for the trait `Debug`, but this is intentionally ignored during dead code analysis
--> $DIR/derive-uninhabited-enum-38885.rs:10:10
|
LL | #[derive(Debug)]
| ^^^^^
= note: this warning originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info)
= note: `Foo` has a derived impl for the trait `Debug`, but this is intentionally ignored during dead code analysis

warning: 1 warning emitted

21 changes: 3 additions & 18 deletions src/test/ui/derives/clone-debug-dead-code.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -16,38 +16,23 @@ error: field is never read: `f`
LL | struct B { f: () }
| ^^^^^
|
note: `B` has a derived impl for the trait `Clone`, but this is intentionally ignored during dead code analysis
--> $DIR/clone-debug-dead-code.rs:9:10
|
LL | #[derive(Clone)]
| ^^^^^
= note: this error originates in the derive macro `Clone` (in Nightly builds, run with -Z macro-backtrace for more info)
= note: `B` has a derived impl for the trait `Clone`, but this is intentionally ignored during dead code analysis

error: field is never read: `f`
--> $DIR/clone-debug-dead-code.rs:14:12
|
LL | struct C { f: () }
| ^^^^^
|
note: `C` has a derived impl for the trait `Debug`, but this is intentionally ignored during dead code analysis
--> $DIR/clone-debug-dead-code.rs:13:10
|
LL | #[derive(Debug)]
| ^^^^^
= note: this error originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info)
= note: `C` has a derived impl for the trait `Debug`, but this is intentionally ignored during dead code analysis

error: field is never read: `f`
--> $DIR/clone-debug-dead-code.rs:18:12
|
LL | struct D { f: () }
| ^^^^^
|
note: `D` has derived impls for the traits `Clone` and `Debug`, but these are intentionally ignored during dead code analysis
--> $DIR/clone-debug-dead-code.rs:17:10
|
LL | #[derive(Debug,Clone)]
| ^^^^^ ^^^^^
= note: this error originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info)
= note: `D` has derived impls for the traits `Clone` and `Debug`, but these are intentionally ignored during dead code analysis

error: field is never read: `f`
--> $DIR/clone-debug-dead-code.rs:21:12
Expand Down
Loading