Skip to content

Rollup of 8 pull requests #106667

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 16 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_borrowck/src/region_infer/opaque_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
}

let definition_ty = instantiated_ty
.remap_generic_params_to_declaration_params(opaque_type_key, self.tcx, false, origin)
.remap_generic_params_to_declaration_params(opaque_type_key, self.tcx, false)
.ty;

if !check_opaque_type_parameter_valid(
Expand Down
4 changes: 1 addition & 3 deletions compiler/rustc_codegen_ssa/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,7 @@ pub fn unsized_info<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
(
&ty::Dynamic(ref data_a, _, src_dyn_kind),
&ty::Dynamic(ref data_b, _, target_dyn_kind),
) => {
assert_eq!(src_dyn_kind, target_dyn_kind);

) if src_dyn_kind == target_dyn_kind => {
let old_info =
old_info.expect("unsized_info: missing old info for trait upcasting coercion");
if data_a.principal_def_id() == data_b.principal_def_id() {
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_hir_typeck/src/writeback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,6 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
opaque_type_key,
self.fcx.infcx.tcx,
true,
decl.origin,
);

self.typeck_results.concrete_opaque_types.insert(opaque_type_key.def_id, hidden_type);
Expand Down
24 changes: 20 additions & 4 deletions compiler/rustc_macros/src/diagnostics/diagnostic_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,10 +382,26 @@ impl<'a> DiagnosticDeriveVariantBuilder<'a> {
return Ok(quote! { #diag.subdiagnostic(#binding); });
}
}
(Meta::List(_), "subdiagnostic") => {
throw_invalid_attr!(attr, &meta, |diag| {
diag.help("`subdiagnostic` does not support nested attributes")
})
(Meta::List(MetaList { ref nested, .. }), "subdiagnostic") => {
if nested.len() == 1
&& let Some(NestedMeta::Meta(Meta::Path(path))) = nested.first()
&& path.is_ident("eager") {
let handler = match &self.parent.kind {
DiagnosticDeriveKind::Diagnostic { handler } => handler,
DiagnosticDeriveKind::LintDiagnostic => {
throw_invalid_attr!(attr, &meta, |diag| {
diag.help("eager subdiagnostics are not supported on lints")
})
}
};
return Ok(quote! { #diag.eager_subdiagnostic(#handler, #binding); });
} else {
throw_invalid_attr!(attr, &meta, |diag| {
diag.help(
"`eager` is the only supported nested attribute for `subdiagnostic`",
)
})
}
}
_ => (),
}
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_macros/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![feature(allow_internal_unstable)]
#![feature(if_let_guard)]
#![feature(let_chains)]
#![feature(never_type)]
#![feature(proc_macro_diagnostic)]
#![feature(proc_macro_span)]
Expand Down
27 changes: 1 addition & 26 deletions compiler/rustc_middle/src/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ use crate::ty::util::Discr;
pub use adt::*;
pub use assoc::*;
pub use generics::*;
use hir::OpaqueTyOrigin;
use rustc_ast as ast;
use rustc_ast::node_id::NodeMap;
use rustc_attr as attr;
Expand Down Expand Up @@ -1316,7 +1315,6 @@ impl<'tcx> OpaqueHiddenType<'tcx> {
tcx: TyCtxt<'tcx>,
// typeck errors have subpar spans for opaque types, so delay error reporting until borrowck.
ignore_errors: bool,
origin: OpaqueTyOrigin,
) -> Self {
let OpaqueTypeKey { def_id, substs } = opaque_type_key;

Expand All @@ -1332,30 +1330,7 @@ impl<'tcx> OpaqueHiddenType<'tcx> {
// This zip may have several times the same lifetime in `substs` paired with a different
// lifetime from `id_substs`. Simply `collect`ing the iterator is the correct behaviour:
// it will pick the last one, which is the one we introduced in the impl-trait desugaring.
let map = substs.iter().zip(id_substs);

let map: FxHashMap<GenericArg<'tcx>, GenericArg<'tcx>> = match origin {
// HACK: The HIR lowering for async fn does not generate
// any `+ Captures<'x>` bounds for the `impl Future<...>`, so all async fns with lifetimes
// would now fail to compile. We should probably just make hir lowering fill this in properly.
OpaqueTyOrigin::AsyncFn(_) => map.collect(),
OpaqueTyOrigin::FnReturn(_) | OpaqueTyOrigin::TyAlias => {
// Opaque types may only use regions that are bound. So for
// ```rust
// type Foo<'a, 'b, 'c> = impl Trait<'a> + 'b;
// ```
// we may not use `'c` in the hidden type.
let variances = tcx.variances_of(def_id);
debug!(?variances);

map.filter(|(_, v)| {
let ty::GenericArgKind::Lifetime(lt) = v.unpack() else { return true };
let ty::ReEarlyBound(ebr) = lt.kind() else { bug!() };
variances[ebr.index as usize] == ty::Variance::Invariant
})
.collect()
}
};
let map = substs.iter().zip(id_substs).collect();
debug!("map = {:#?}", map);

// Convert the type from the function into a type valid outside
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_session/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1241,7 +1241,7 @@ options! {

// tidy-alphabetical-start
allow_features: Option<Vec<String>> = (None, parse_opt_comma_list, [TRACKED],
"only allow the listed language features to be enabled in code (space separated)"),
"only allow the listed language features to be enabled in code (comma separated)"),
always_encode_mir: bool = (false, parse_bool, [TRACKED],
"encode MIR of all functions into the crate metadata (default: no)"),
asm_comments: bool = (false, parse_bool, [TRACKED],
Expand Down
10 changes: 8 additions & 2 deletions compiler/rustc_trait_selection/src/solve/project_goals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,14 @@ impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> {
else {
return
};

let nested_goals = obligations.into_iter().map(|o| o.into()).collect();
let where_clause_bounds = tcx
.predicates_of(impl_def_id)
.instantiate(tcx, impl_substs)
.predicates
.into_iter()
.map(|pred| goal.with(tcx, pred));

let nested_goals = obligations.into_iter().map(|o| o.into()).chain(where_clause_bounds).collect();
let Ok(trait_ref_certainty) = acx.cx.evaluate_all(acx.infcx, nested_goals) else { return };

let Some(assoc_def) = fetch_eligible_assoc_item_def(
Expand Down
17 changes: 13 additions & 4 deletions compiler/rustc_trait_selection/src/solve/trait_goals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
goal: Goal<'tcx, TraitPredicate<'tcx>>,
impl_def_id: DefId,
) {
let impl_trait_ref = acx.cx.tcx.bound_impl_trait_ref(impl_def_id).unwrap();
let tcx = acx.cx.tcx;

let impl_trait_ref = tcx.bound_impl_trait_ref(impl_def_id).unwrap();
let drcx = DeepRejectCtxt { treat_obligation_params: TreatParams::AsPlaceholder };
if iter::zip(goal.predicate.trait_ref.substs, impl_trait_ref.skip_binder().substs)
.any(|(goal, imp)| !drcx.generic_args_may_unify(goal, imp))
Expand All @@ -81,7 +83,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {

acx.infcx.probe(|_| {
let impl_substs = acx.infcx.fresh_substs_for_item(DUMMY_SP, impl_def_id);
let impl_trait_ref = impl_trait_ref.subst(acx.cx.tcx, impl_substs);
let impl_trait_ref = impl_trait_ref.subst(tcx, impl_substs);

let Ok(InferOk { obligations, .. }) = acx
.infcx
Expand All @@ -92,8 +94,15 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
else {
return
};

let nested_goals = obligations.into_iter().map(|o| o.into()).collect();
let where_clause_bounds = tcx
.predicates_of(impl_def_id)
.instantiate(tcx, impl_substs)
.predicates
.into_iter()
.map(|pred| goal.with(tcx, pred));

let nested_goals =
obligations.into_iter().map(|o| o.into()).chain(where_clause_bounds).collect();

let Ok(certainty) = acx.cx.evaluate_all(acx.infcx, nested_goals) else { return };
acx.try_insert_candidate(CandidateSource::Impl(impl_def_id), certainty);
Expand Down
26 changes: 26 additions & 0 deletions library/core/tests/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,32 @@ fn div() {
assert_eq!(Duration::new(99, 999_999_000) / 100, Duration::new(0, 999_999_990));
}

#[test]
fn div_duration_f32() {
assert_eq!(Duration::ZERO.div_duration_f32(Duration::MAX), 0.0);
assert_eq!(Duration::MAX.div_duration_f32(Duration::ZERO), f32::INFINITY);
assert_eq!((Duration::SECOND * 2).div_duration_f32(Duration::SECOND), 2.0);
assert!(Duration::ZERO.div_duration_f32(Duration::ZERO).is_nan());
// These tests demonstrate it doesn't panic with extreme values.
// Accuracy of the computed value is not a huge concern, we know floats don't work well
// at these extremes.
assert!((Duration::MAX).div_duration_f32(Duration::NANOSECOND) > 10.0f32.powf(28.0));
assert!((Duration::NANOSECOND).div_duration_f32(Duration::MAX) < 0.1);
}

#[test]
fn div_duration_f64() {
assert_eq!(Duration::ZERO.div_duration_f64(Duration::MAX), 0.0);
assert_eq!(Duration::MAX.div_duration_f64(Duration::ZERO), f64::INFINITY);
assert_eq!((Duration::SECOND * 2).div_duration_f64(Duration::SECOND), 2.0);
assert!(Duration::ZERO.div_duration_f64(Duration::ZERO).is_nan());
// These tests demonstrate it doesn't panic with extreme values.
// Accuracy of the computed value is not a huge concern, we know floats don't work well
// at these extremes.
assert!((Duration::MAX).div_duration_f64(Duration::NANOSECOND) > 10.0f64.powf(28.0));
assert!((Duration::NANOSECOND).div_duration_f64(Duration::MAX) < 0.1);
}

#[test]
fn checked_div() {
assert_eq!(Duration::new(2, 0).checked_div(2), Some(Duration::new(1, 0)));
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/sync/mutex/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ fn test_mutex_arc_poison() {
let arc2 = arc.clone();
let _ = thread::spawn(move || {
let lock = arc2.lock().unwrap();
assert_eq!(*lock, 2);
assert_eq!(*lock, 2); // deliberate assertion failure to poison the mutex
})
.join();
assert!(arc.lock().is_err());
Expand Down
22 changes: 11 additions & 11 deletions library/std/src/thread/local/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ impl Signal {
}
}

struct Foo(Signal);
struct NotifyOnDrop(Signal);

impl Drop for Foo {
impl Drop for NotifyOnDrop {
fn drop(&mut self) {
let Foo(ref f) = *self;
let NotifyOnDrop(ref f) = *self;
f.notify();
}
}
Expand Down Expand Up @@ -82,18 +82,18 @@ fn states() {

#[test]
fn smoke_dtor() {
thread_local!(static FOO: UnsafeCell<Option<Foo>> = UnsafeCell::new(None));
thread_local!(static FOO: UnsafeCell<Option<NotifyOnDrop>> = UnsafeCell::new(None));
run(&FOO);
thread_local!(static FOO2: UnsafeCell<Option<Foo>> = const { UnsafeCell::new(None) });
thread_local!(static FOO2: UnsafeCell<Option<NotifyOnDrop>> = const { UnsafeCell::new(None) });
run(&FOO2);

fn run(key: &'static LocalKey<UnsafeCell<Option<Foo>>>) {
fn run(key: &'static LocalKey<UnsafeCell<Option<NotifyOnDrop>>>) {
let signal = Signal::default();
let signal2 = signal.clone();
let t = thread::spawn(move || unsafe {
let mut signal = Some(signal2);
key.with(|f| {
*f.get() = Some(Foo(signal.take().unwrap()));
*f.get() = Some(NotifyOnDrop(signal.take().unwrap()));
});
});
signal.wait();
Expand Down Expand Up @@ -187,13 +187,13 @@ fn self_referential() {
fn dtors_in_dtors_in_dtors() {
struct S1(Signal);
thread_local!(static K1: UnsafeCell<Option<S1>> = UnsafeCell::new(None));
thread_local!(static K2: UnsafeCell<Option<Foo>> = UnsafeCell::new(None));
thread_local!(static K2: UnsafeCell<Option<NotifyOnDrop>> = UnsafeCell::new(None));

impl Drop for S1 {
fn drop(&mut self) {
let S1(ref signal) = *self;
unsafe {
let _ = K2.try_with(|s| *s.get() = Some(Foo(signal.clone())));
let _ = K2.try_with(|s| *s.get() = Some(NotifyOnDrop(signal.clone())));
}
}
}
Expand All @@ -211,13 +211,13 @@ fn dtors_in_dtors_in_dtors() {
fn dtors_in_dtors_in_dtors_const_init() {
struct S1(Signal);
thread_local!(static K1: UnsafeCell<Option<S1>> = const { UnsafeCell::new(None) });
thread_local!(static K2: UnsafeCell<Option<Foo>> = const { UnsafeCell::new(None) });
thread_local!(static K2: UnsafeCell<Option<NotifyOnDrop>> = const { UnsafeCell::new(None) });

impl Drop for S1 {
fn drop(&mut self) {
let S1(ref signal) = *self;
unsafe {
let _ = K2.try_with(|s| *s.get() = Some(Foo(signal.clone())));
let _ = K2.try_with(|s| *s.get() = Some(NotifyOnDrop(signal.clone())));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/rustdoc-ui/z-help.stdout
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-Z allow-features=val -- only allow the listed language features to be enabled in code (space separated)
-Z allow-features=val -- only allow the listed language features to be enabled in code (comma separated)
-Z always-encode-mir=val -- encode MIR of all functions into the crate metadata (default: no)
-Z asm-comments=val -- generate comments into the assembly (may change behavior) (default: no)
-Z assert-incr-state=val -- assert that the incremental cache is in given state: either `loaded` or `not-loaded`.
Expand Down
2 changes: 0 additions & 2 deletions src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,6 @@ struct SubdiagnosticEagerLint {
#[diag(compiletest_example)]
struct SubdiagnosticEagerCorrect {
#[subdiagnostic(eager)]
//~^ ERROR `#[subdiagnostic(...)]` is not a valid attribute
note: Note,
}

Expand All @@ -744,7 +743,6 @@ pub(crate) struct SubdiagnosticWithSuggestion {
#[diag(compiletest_example)]
struct SubdiagnosticEagerSuggestion {
#[subdiagnostic(eager)]
//~^ ERROR `#[subdiagnostic(...)]` is not a valid attribute
sub: SubdiagnosticWithSuggestion,
}

Expand Down
32 changes: 8 additions & 24 deletions src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ error: `#[subdiagnostic(...)]` is not a valid attribute
LL | #[subdiagnostic(bad)]
| ^^^^^^^^^^^^^^^^^^^^^
|
= help: `subdiagnostic` does not support nested attributes
= help: `eager` is the only supported nested attribute for `subdiagnostic`

error: `#[subdiagnostic = ...]` is not a valid attribute
--> $DIR/diagnostic-derive.rs:693:5
Expand All @@ -553,54 +553,38 @@ error: `#[subdiagnostic(...)]` is not a valid attribute
LL | #[subdiagnostic(bad, bad)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: `subdiagnostic` does not support nested attributes
= help: `eager` is the only supported nested attribute for `subdiagnostic`

error: `#[subdiagnostic(...)]` is not a valid attribute
--> $DIR/diagnostic-derive.rs:709:5
|
LL | #[subdiagnostic("bad")]
| ^^^^^^^^^^^^^^^^^^^^^^^
|
= help: `subdiagnostic` does not support nested attributes
= help: `eager` is the only supported nested attribute for `subdiagnostic`

error: `#[subdiagnostic(...)]` is not a valid attribute
--> $DIR/diagnostic-derive.rs:717:5
|
LL | #[subdiagnostic(eager)]
| ^^^^^^^^^^^^^^^^^^^^^^^
|
= help: `subdiagnostic` does not support nested attributes

error: `#[subdiagnostic(...)]` is not a valid attribute
--> $DIR/diagnostic-derive.rs:725:5
|
LL | #[subdiagnostic(eager)]
| ^^^^^^^^^^^^^^^^^^^^^^^
|
= help: `subdiagnostic` does not support nested attributes

error: `#[subdiagnostic(...)]` is not a valid attribute
--> $DIR/diagnostic-derive.rs:746:5
|
LL | #[subdiagnostic(eager)]
| ^^^^^^^^^^^^^^^^^^^^^^^
|
= help: `subdiagnostic` does not support nested attributes
= help: eager subdiagnostics are not supported on lints

error: expected at least one string literal for `code(...)`
--> $DIR/diagnostic-derive.rs:777:18
--> $DIR/diagnostic-derive.rs:775:18
|
LL | #[suggestion(code())]
| ^^^^^^

error: `code(...)` must contain only string literals
--> $DIR/diagnostic-derive.rs:785:23
--> $DIR/diagnostic-derive.rs:783:23
|
LL | #[suggestion(code(foo))]
| ^^^

error: `code = "..."`/`code(...)` must contain only string literals
--> $DIR/diagnostic-derive.rs:793:18
--> $DIR/diagnostic-derive.rs:791:18
|
LL | #[suggestion(code = 3)]
| ^^^^^^^^
Expand Down Expand Up @@ -676,7 +660,7 @@ note: required by a bound in `DiagnosticBuilder::<'a, G>::set_arg`
--> $COMPILER_DIR/rustc_errors/src/diagnostic_builder.rs:LL:CC
= note: this error originates in the derive macro `Diagnostic` which comes from the expansion of the macro `forward` (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to 85 previous errors
error: aborting due to 83 previous errors

Some errors have detailed explanations: E0277, E0425.
For more information about an error, try `rustc --explain E0277`.
Loading