Skip to content

Rollup of 5 pull requests #99847

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

Closed
wants to merge 14 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
2 changes: 1 addition & 1 deletion compiler/rustc_expand/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ fn get_features(
.span_suggestion(
mi.span(),
"expected just one word",
format!("{}", ident.name),
ident.name,
Applicability::MaybeIncorrect,
)
.emit();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ pub trait InferCtxtExt<'tcx> {
trait_pred: ty::PolyTraitPredicate<'tcx>,
) -> bool;

fn get_closure_name(&self, def_id: DefId, err: &mut Diagnostic, msg: &str) -> Option<String>;
fn get_closure_name(&self, def_id: DefId, err: &mut Diagnostic, msg: &str) -> Option<Symbol>;

fn suggest_fn_call(
&self,
Expand Down Expand Up @@ -737,13 +737,13 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
/// Given a closure's `DefId`, return the given name of the closure.
///
/// This doesn't account for reassignments, but it's only used for suggestions.
fn get_closure_name(&self, def_id: DefId, err: &mut Diagnostic, msg: &str) -> Option<String> {
let get_name = |err: &mut Diagnostic, kind: &hir::PatKind<'_>| -> Option<String> {
fn get_closure_name(&self, def_id: DefId, err: &mut Diagnostic, msg: &str) -> Option<Symbol> {
let get_name = |err: &mut Diagnostic, kind: &hir::PatKind<'_>| -> Option<Symbol> {
// Get the local name of this closure. This can be inaccurate because
// of the possibility of reassignment, but this should be good enough.
match &kind {
hir::PatKind::Binding(hir::BindingAnnotation::Unannotated, _, name, None) => {
Some(format!("{}", name))
hir::PatKind::Binding(hir::BindingAnnotation::Unannotated, _, ident, None) => {
Some(ident.name)
}
_ => {
err.note(msg);
Expand Down
6 changes: 4 additions & 2 deletions compiler/rustc_traits/src/evaluate_obligation.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use rustc_infer::infer::TyCtxtInferExt;
use rustc_infer::infer::{DefiningAnchor, TyCtxtInferExt};
use rustc_middle::ty::query::Providers;
use rustc_middle::ty::{ParamEnvAnd, TyCtxt};
use rustc_span::source_map::DUMMY_SP;
Expand All @@ -16,7 +16,9 @@ fn evaluate_obligation<'tcx>(
canonical_goal: CanonicalPredicateGoal<'tcx>,
) -> Result<EvaluationResult, OverflowError> {
debug!("evaluate_obligation(canonical_goal={:#?})", canonical_goal);
tcx.infer_ctxt().enter_with_canonical(
// HACK This bubble is required for this tests to pass:
// impl-trait/issue99642.rs
tcx.infer_ctxt().with_opaque_type_inference(DefiningAnchor::Bubble).enter_with_canonical(
DUMMY_SP,
&canonical_goal,
|ref infcx, goal, _canonical_inference_vars| {
Expand Down
15 changes: 10 additions & 5 deletions compiler/rustc_traits/src/type_op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use rustc_hir as hir;
use rustc_hir::def_id::DefId;
use rustc_infer::infer::at::ToTrace;
use rustc_infer::infer::canonical::{Canonical, QueryResponse};
use rustc_infer::infer::{InferCtxt, TyCtxtInferExt};
use rustc_infer::infer::{DefiningAnchor, InferCtxt, TyCtxtInferExt};
use rustc_infer::traits::TraitEngineExt as _;
use rustc_middle::ty::query::Providers;
use rustc_middle::ty::subst::{GenericArg, Subst, UserSelfTy, UserSubsts};
Expand Down Expand Up @@ -258,10 +258,15 @@ fn type_op_prove_predicate<'tcx>(
tcx: TyCtxt<'tcx>,
canonicalized: Canonical<'tcx, ParamEnvAnd<'tcx, ProvePredicate<'tcx>>>,
) -> Result<&'tcx Canonical<'tcx, QueryResponse<'tcx, ()>>, NoSolution> {
tcx.infer_ctxt().enter_canonical_trait_query(&canonicalized, |infcx, fulfill_cx, key| {
type_op_prove_predicate_with_cause(infcx, fulfill_cx, key, ObligationCause::dummy());
Ok(())
})
// HACK This bubble is required for this test to pass:
// impl-trait/issue-99642.rs
tcx.infer_ctxt().with_opaque_type_inference(DefiningAnchor::Bubble).enter_canonical_trait_query(
&canonicalized,
|infcx, fulfill_cx, key| {
type_op_prove_predicate_with_cause(infcx, fulfill_cx, key, ObligationCause::dummy());
Ok(())
},
)
}

/// The core of the `type_op_prove_predicate` query: for diagnostics purposes in NLL HRTB errors,
Expand Down
20 changes: 20 additions & 0 deletions library/std/src/f32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -920,4 +920,24 @@ impl f32 {
pub fn atanh(self) -> f32 {
0.5 * ((2.0 * self) / (1.0 - self)).ln_1p()
}

/// Gamma function.
///
/// # Examples
///
/// ```
/// #![feature(float_gamma)]
/// let x = 5.0f32;
///
/// let abs_difference = (x.gamma() - 24.0).abs();
///
/// assert!(abs_difference <= f32::EPSILON);
/// ```
#[rustc_allow_incoherent_impl]
#[must_use = "method returns a new number and does not mutate the original value"]
#[unstable(feature = "float_gamma", issue = "99842")]
#[inline]
pub fn gamma(self) -> f32 {
unsafe { cmath::tgammaf(self) }
}
}
15 changes: 15 additions & 0 deletions library/std/src/f32/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,21 @@ fn test_atanh() {
assert_approx_eq!((-0.5f32).atanh(), -0.54930614433405484569762261846126285f32);
}

#[test]
fn test_gamma() {
assert_eq!(0.0f32.gamma(), f32::INFINITY);
assert_approx_eq!(1.0f32.gamma(), 1.0f32);
assert_approx_eq!(2.0f32.gamma(), 1.0f32);
assert_approx_eq!(3.0f32.gamma(), 2.0f32);
assert_approx_eq!(4.0f32.gamma(), 6.0f32);
assert_approx_eq!(5.0f32.gamma(), 24.0f32);

assert_approx_eq!(0.5f32.gamma(), consts::PI.sqrt());
assert_approx_eq!((-0.5f32).gamma(), -2.0 * consts::PI.sqrt());

assert!((-1.0f32).gamma().is_nan());
}

#[test]
fn test_real_consts() {
use super::consts;
Expand Down
20 changes: 20 additions & 0 deletions library/std/src/f64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -946,4 +946,24 @@ impl f64 {
Self::NAN // log(-Inf) = NaN
}
}

/// Gamma function.
///
/// # Examples
///
/// ```
/// #![feature(float_gamma)]
/// let x = 5.0f64;
///
/// let abs_difference = (x.gamma() - 24.0).abs();
///
/// assert!(abs_difference <= f64::EPSILON);
/// ```
#[rustc_allow_incoherent_impl]
#[must_use = "method returns a new number and does not mutate the original value"]
#[unstable(feature = "float_gamma", issue = "99842")]
#[inline]
pub fn gamma(self) -> f64 {
unsafe { cmath::tgamma(self) }
}
}
15 changes: 15 additions & 0 deletions library/std/src/f64/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,21 @@ fn test_atanh() {
assert_approx_eq!((-0.5f64).atanh(), -0.54930614433405484569762261846126285f64);
}

#[test]
fn test_gamma() {
assert_eq!(0.0f64.gamma(), f64::INFINITY);
assert_approx_eq!(1.0f64.gamma(), 1.0f64);
assert_approx_eq!(2.0f64.gamma(), 1.0f64);
assert_approx_eq!(3.0f64.gamma(), 2.0f64);
assert_approx_eq!(4.0f64.gamma(), 6.0f64);
assert_approx_eq!(5.0f64.gamma(), 24.0f64);

assert_approx_eq!(0.5f64.gamma(), consts::PI.sqrt());
assert_approx_eq!((-0.5f64).gamma(), -2.0 * consts::PI.sqrt());

assert!((-1.0f64).gamma().is_nan());
}

#[test]
fn test_real_consts() {
use super::consts;
Expand Down
1 change: 1 addition & 0 deletions library/std/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@
#![feature(exact_size_is_empty)]
#![feature(exclusive_wrapper)]
#![feature(extend_one)]
#![feature(float_gamma)]
#![feature(float_minimum_maximum)]
#![feature(hasher_prefixfree_extras)]
#![feature(hashmap_internals)]
Expand Down
4 changes: 4 additions & 0 deletions library/std/src/os/fd/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use crate::os::wasi::io::OwnedFd;
use crate::sys_common::{AsInner, IntoInner};

/// Raw file descriptors.
#[cfg_attr(not(bootstrap), rustc_allowed_through_unstable_modules)]
#[stable(feature = "rust1", since = "1.0.0")]
pub type RawFd = raw::c_int;

Expand All @@ -22,6 +23,7 @@ pub type RawFd = raw::c_int;
/// This is only available on unix and WASI platforms and must be imported in
/// order to call the method. Windows platforms have a corresponding
/// `AsRawHandle` and `AsRawSocket` set of traits.
#[cfg_attr(not(bootstrap), rustc_allowed_through_unstable_modules)]
#[stable(feature = "rust1", since = "1.0.0")]
pub trait AsRawFd {
/// Extracts the raw file descriptor.
Expand Down Expand Up @@ -57,6 +59,7 @@ pub trait AsRawFd {

/// A trait to express the ability to construct an object from a raw file
/// descriptor.
#[cfg_attr(not(bootstrap), rustc_allowed_through_unstable_modules)]
#[stable(feature = "from_raw_os", since = "1.1.0")]
pub trait FromRawFd {
/// Constructs a new instance of `Self` from the given raw file
Expand Down Expand Up @@ -100,6 +103,7 @@ pub trait FromRawFd {

/// A trait to express the ability to consume an object and acquire ownership of
/// its raw file descriptor.
#[cfg_attr(not(bootstrap), rustc_allowed_through_unstable_modules)]
#[stable(feature = "into_raw_os", since = "1.4.0")]
pub trait IntoRawFd {
/// Consumes this object, returning the raw underlying file descriptor.
Expand Down
15 changes: 15 additions & 0 deletions library/std/src/os/wasi/io/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,19 @@

#![unstable(feature = "wasi_ext", issue = "71213")]

// NOTE: despite the fact that this module is unstable,
// stable Rust had the capability to access the stable
// re-exported items from os::fd::raw through this
// unstable module.
// In PR #95956 the stability checker was changed to check
// all path segments of an item rather than just the last,
// which caused the aforementioned stable usage to regress
// (see issue #99502).
// As a result, the items in os::fd::raw were given the
// rustc_allowed_through_unstable_modules attribute.
// No regression tests were added to ensure this property,
// as CI is not configured to test wasm32-wasi.
// If this module is stabilized,
// you may want to remove those attributes
// (assuming no other unstable modules need them).
pub use crate::os::fd::raw::*;
2 changes: 2 additions & 0 deletions library/std/src/sys/unix/cmath.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,6 @@ extern "C" {
pub fn tanf(n: f32) -> f32;
pub fn tanh(n: f64) -> f64;
pub fn tanhf(n: f32) -> f32;
pub fn tgamma(n: f64) -> f64;
pub fn tgammaf(n: f32) -> f32;
}
2 changes: 2 additions & 0 deletions library/std/src/sys/windows/cmath.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ extern "C" {
pub fn sinh(n: c_double) -> c_double;
pub fn tan(n: c_double) -> c_double;
pub fn tanh(n: c_double) -> c_double;
pub fn tgamma(n: c_double) -> c_double;
pub fn tgammaf(n: c_float) -> c_float;
}

pub use self::shims::*;
Expand Down
3 changes: 1 addition & 2 deletions src/librustdoc/html/static/css/settings.css
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@

.toggle {
position: relative;
display: inline-block;
width: 100%;
height: 27px;
margin-right: 20px;
display: flex;
align-items: center;
Expand All @@ -58,6 +56,7 @@
.slider {
position: relative;
width: 45px;
min-width: 45px;
display: block;
height: 28px;
margin-right: 20px;
Expand Down
9 changes: 9 additions & 0 deletions src/test/rustdoc-gui/settings.goml
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,12 @@ assert-false: "noscript section"
javascript: false
reload:
assert-css: ("noscript section", {"display": "block"})
javascript: true

// Check for the display on small screen
show-text: true
reload:
size: (300, 1000)
click: "#settings-menu"
wait-for: "#settings"
assert-css: ("#settings .slider", {"width": "45px"}, ALL)
8 changes: 8 additions & 0 deletions src/test/ui/impl-trait/issue-99642-2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// check-pass

#![feature(type_alias_impl_trait)]
type Opq = impl Sized;
fn test() -> impl Iterator<Item = Opq> {
Box::new(0..) as Box<dyn Iterator<Item = _>>
}
fn main(){}
7 changes: 7 additions & 0 deletions src/test/ui/impl-trait/issue-99642.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// check-pass

fn test() -> impl Iterator<Item = impl Sized> {
Box::new(0..) as Box<dyn Iterator<Item = _>>
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
error[E0275]: overflow evaluating the requirement `<fn() -> Foo {foo} as FnOnce<()>>::Output == fn() -> Foo {foo}`
error[E0275]: overflow evaluating the requirement `fn() -> Foo {foo}: Sized`
--> $DIR/issue-53398-cyclic-types.rs:5:13
|
LL | fn foo() -> Foo {
| ^^^
|
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`issue_53398_cyclic_types`)

error: aborting due to previous error

Expand Down