diff --git a/compiler/rustc_borrowck/src/def_use.rs b/compiler/rustc_borrowck/src/def_use.rs index 74e6ce37e971a..b775739fed2ae 100644 --- a/compiler/rustc_borrowck/src/def_use.rs +++ b/compiler/rustc_borrowck/src/def_use.rs @@ -55,7 +55,7 @@ pub fn categorize(context: PlaceContext) -> Option { // `PlaceMention` and `AscribeUserType` both evaluate the place, which must not // contain dangling references. PlaceContext::NonMutatingUse(NonMutatingUseContext::PlaceMention) | - PlaceContext::NonUse(NonUseContext::AscribeUserTy) | + PlaceContext::NonUse(NonUseContext::AscribeUserTy(_)) | PlaceContext::MutatingUse(MutatingUseContext::AddressOf) | PlaceContext::NonMutatingUse(NonMutatingUseContext::AddressOf) | diff --git a/compiler/rustc_borrowck/src/type_check/mod.rs b/compiler/rustc_borrowck/src/type_check/mod.rs index dcabeb792be3e..33b24b68f7cfc 100644 --- a/compiler/rustc_borrowck/src/type_check/mod.rs +++ b/compiler/rustc_borrowck/src/type_check/mod.rs @@ -777,7 +777,7 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> { Inspect | Copy | Move | PlaceMention | SharedBorrow | ShallowBorrow | UniqueBorrow | AddressOf | Projection, ) => ty::Covariant, - PlaceContext::NonUse(AscribeUserTy) => ty::Covariant, + PlaceContext::NonUse(AscribeUserTy(variance)) => variance, } } diff --git a/compiler/rustc_middle/src/mir/visit.rs b/compiler/rustc_middle/src/mir/visit.rs index 6718605ed0bc4..4b7014e31090b 100644 --- a/compiler/rustc_middle/src/mir/visit.rs +++ b/compiler/rustc_middle/src/mir/visit.rs @@ -64,7 +64,7 @@ use crate::mir::*; use crate::ty::subst::SubstsRef; -use crate::ty::{CanonicalUserTypeAnnotation, Ty}; +use crate::ty::{self, CanonicalUserTypeAnnotation, Ty}; use rustc_span::Span; macro_rules! make_mir_visitor { @@ -782,12 +782,12 @@ macro_rules! make_mir_visitor { fn super_ascribe_user_ty(&mut self, place: & $($mutability)? Place<'tcx>, - _variance: $(& $mutability)? ty::Variance, + variance: $(& $mutability)? ty::Variance, user_ty: & $($mutability)? UserTypeProjection, location: Location) { self.visit_place( place, - PlaceContext::NonUse(NonUseContext::AscribeUserTy), + PlaceContext::NonUse(NonUseContext::AscribeUserTy($(* &$mutability *)? variance)), location ); self.visit_user_type_projection(user_ty); @@ -1320,7 +1320,7 @@ pub enum NonUseContext { /// Ending a storage live range. StorageDead, /// User type annotation assertions for NLL. - AscribeUserTy, + AscribeUserTy(ty::Variance), /// The data of a user variable, for debug info. VarDebugInfo, } diff --git a/compiler/rustc_middle/src/traits/mod.rs b/compiler/rustc_middle/src/traits/mod.rs index 449c453555e9e..2f0b07d4c71b4 100644 --- a/compiler/rustc_middle/src/traits/mod.rs +++ b/compiler/rustc_middle/src/traits/mod.rs @@ -281,9 +281,6 @@ pub enum ObligationCauseCode<'tcx> { /// A type like `Box + 'b>` is WF only if `'b: 'a`. ObjectTypeBound(Ty<'tcx>, ty::Region<'tcx>), - /// Obligation incurred due to an object cast. - ObjectCastObligation(/* Concrete type */ Ty<'tcx>, /* Object type */ Ty<'tcx>), - /// Obligation incurred due to a coercion. Coercion { source: Ty<'tcx>, diff --git a/compiler/rustc_mir_transform/src/ref_prop.rs b/compiler/rustc_mir_transform/src/ref_prop.rs index dafd2ae23a635..d1bc9ee91538e 100644 --- a/compiler/rustc_mir_transform/src/ref_prop.rs +++ b/compiler/rustc_mir_transform/src/ref_prop.rs @@ -85,7 +85,9 @@ fn propagate_ssa<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { let ssa = SsaLocals::new(body); let mut replacer = compute_replacement(tcx, body, &ssa); - debug!(?replacer.targets, ?replacer.allowed_replacements, ?replacer.storage_to_remove); + debug!(?replacer.targets); + debug!(?replacer.allowed_replacements); + debug!(?replacer.storage_to_remove); replacer.visit_body_preserves_cfg(body); @@ -190,8 +192,11 @@ fn compute_replacement<'tcx>( continue; } + // Whether the current local is subject to the uniqueness rule. + let needs_unique = ty.is_mutable_ptr(); + // If this a mutable reference that we cannot fully replace, mark it as unknown. - if ty.is_mutable_ptr() && !fully_replacable_locals.contains(local) { + if needs_unique && !fully_replacable_locals.contains(local) { debug!("not fully replaceable"); continue; } @@ -203,13 +208,14 @@ fn compute_replacement<'tcx>( // have been visited before. Rvalue::Use(Operand::Copy(place) | Operand::Move(place)) | Rvalue::CopyForDeref(place) => { - if let Some(rhs) = place.as_local() { + if let Some(rhs) = place.as_local() && ssa.is_ssa(rhs) { let target = targets[rhs]; - if matches!(target, Value::Pointer(..)) { + // Only see through immutable reference and pointers, as we do not know yet if + // mutable references are fully replaced. + if !needs_unique && matches!(target, Value::Pointer(..)) { targets[local] = target; - } else if ssa.is_ssa(rhs) { - let refmut = body.local_decls[rhs].ty.is_mutable_ptr(); - targets[local] = Value::Pointer(tcx.mk_place_deref(rhs.into()), refmut); + } else { + targets[local] = Value::Pointer(tcx.mk_place_deref(rhs.into()), needs_unique); } } } @@ -217,10 +223,10 @@ fn compute_replacement<'tcx>( let mut place = *place; // Try to see through `place` in order to collapse reborrow chains. if place.projection.first() == Some(&PlaceElem::Deref) - && let Value::Pointer(target, refmut) = targets[place.local] + && let Value::Pointer(target, inner_needs_unique) = targets[place.local] // Only see through immutable reference and pointers, as we do not know yet if // mutable references are fully replaced. - && !refmut + && !inner_needs_unique // Only collapse chain if the pointee is definitely live. && can_perform_opt(target, location) { @@ -228,7 +234,7 @@ fn compute_replacement<'tcx>( } assert_ne!(place.local, local); if is_constant_place(place) { - targets[local] = Value::Pointer(place, ty.is_mutable_ptr()); + targets[local] = Value::Pointer(place, needs_unique); } } // We do not know what to do, so keep as not-a-pointer. @@ -276,16 +282,35 @@ fn compute_replacement<'tcx>( return; } - if let Value::Pointer(target, refmut) = self.targets[place.local] - && place.projection.first() == Some(&PlaceElem::Deref) - { - let perform_opt = (self.can_perform_opt)(target, loc); - if perform_opt { - self.allowed_replacements.insert((target.local, loc)); - } else if refmut { - // This mutable reference is not fully replacable, so drop it. - self.targets[place.local] = Value::Unknown; + if place.projection.first() != Some(&PlaceElem::Deref) { + // This is not a dereference, nothing to do. + return; + } + + let mut place = place.as_ref(); + loop { + if let Value::Pointer(target, needs_unique) = self.targets[place.local] { + let perform_opt = (self.can_perform_opt)(target, loc); + debug!(?place, ?target, ?needs_unique, ?perform_opt); + + // This a reborrow chain, recursively allow the replacement. + // + // This also allows to detect cases where `target.local` is not replacable, + // and mark it as such. + if let &[PlaceElem::Deref] = &target.projection[..] { + assert!(perform_opt); + self.allowed_replacements.insert((target.local, loc)); + place.local = target.local; + continue; + } else if perform_opt { + self.allowed_replacements.insert((target.local, loc)); + } else if needs_unique { + // This mutable reference is not fully replacable, so drop it. + self.targets[place.local] = Value::Unknown; + } } + + break; } } } @@ -326,18 +351,23 @@ impl<'tcx> MutVisitor<'tcx> for Replacer<'tcx> { } fn visit_place(&mut self, place: &mut Place<'tcx>, ctxt: PlaceContext, loc: Location) { - if let Value::Pointer(target, _) = self.targets[place.local] - && place.projection.first() == Some(&PlaceElem::Deref) - { - let perform_opt = matches!(ctxt, PlaceContext::NonUse(_)) - || self.allowed_replacements.contains(&(target.local, loc)); - - if perform_opt { - *place = target.project_deeper(&place.projection[1..], self.tcx); - self.any_replacement = true; + if place.projection.first() != Some(&PlaceElem::Deref) { + return; + } + + loop { + if let Value::Pointer(target, _) = self.targets[place.local] { + let perform_opt = matches!(ctxt, PlaceContext::NonUse(_)) + || self.allowed_replacements.contains(&(target.local, loc)); + + if perform_opt { + *place = target.project_deeper(&place.projection[1..], self.tcx); + self.any_replacement = true; + continue; + } } - } else { - self.super_place(place, ctxt, loc); + + break; } } diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index 2a8287d5554f8..d7509cbf10e33 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -1482,7 +1482,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> { if let Some(&(_, res)) = rib.bindings.get(&normalized_ident) { self.record_lifetime_res(lifetime.id, res, LifetimeElisionCandidate::Named); - if let LifetimeRes::Param { param, .. } = res { + if let LifetimeRes::Param { param, binder } = res { match self.lifetime_uses.entry(param) { Entry::Vacant(v) => { debug!("First use of {:?} at {:?}", res, ident.span); @@ -1496,10 +1496,16 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> { LifetimeRibKind::Item | LifetimeRibKind::AnonymousReportError | LifetimeRibKind::ElisionFailure => Some(LifetimeUseSet::Many), - // An anonymous lifetime is legal here, go ahead. - LifetimeRibKind::AnonymousCreateParameter { .. } => { - Some(LifetimeUseSet::One { use_span: ident.span, use_ctxt }) - } + // An anonymous lifetime is legal here, and bound to the right + // place, go ahead. + LifetimeRibKind::AnonymousCreateParameter { + binder: anon_binder, + .. + } => Some(if binder == anon_binder { + LifetimeUseSet::One { use_span: ident.span, use_ctxt } + } else { + LifetimeUseSet::Many + }), // Only report if eliding the lifetime would have the same // semantics. LifetimeRibKind::Elided(r) => Some(if res == r { diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs index 9836522392373..f5f2fe5421788 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs @@ -797,9 +797,17 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { err.span_label(span, explanation); } - if let ObligationCauseCode::ObjectCastObligation(concrete_ty, obj_ty) = obligation.cause.code().peel_derives() && - Some(trait_ref.def_id()) == self.tcx.lang_items().sized_trait() { - self.suggest_borrowing_for_object_cast(&mut err, &root_obligation, *concrete_ty, *obj_ty); + if let ObligationCauseCode::Coercion { source, target } = + *obligation.cause.code().peel_derives() + { + if Some(trait_ref.def_id()) == self.tcx.lang_items().sized_trait() { + self.suggest_borrowing_for_object_cast( + &mut err, + &root_obligation, + source, + target, + ); + } } let UnsatisfiedConst(unsatisfied_const) = self @@ -1510,7 +1518,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> { | ObligationCauseCode::BindingObligation(_, _) | ObligationCauseCode::ExprItemObligation(..) | ObligationCauseCode::ExprBindingObligation(..) - | ObligationCauseCode::ObjectCastObligation(..) + | ObligationCauseCode::Coercion { .. } | ObligationCauseCode::OpaqueType ); diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs index 53bf38c0a340f..49b309abcda3a 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -1442,8 +1442,9 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { err: &mut Diagnostic, obligation: &PredicateObligation<'tcx>, self_ty: Ty<'tcx>, - object_ty: Ty<'tcx>, + target_ty: Ty<'tcx>, ) { + let ty::Ref(_, object_ty, hir::Mutability::Not) = target_ty.kind() else { return; }; let ty::Dynamic(predicates, _, ty::Dyn) = object_ty.kind() else { return; }; let self_ref_ty = self.tcx.mk_imm_ref(self.tcx.lifetimes.re_erased, self_ty); @@ -1458,7 +1459,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { err.span_suggestion( obligation.cause.span.shrink_to_lo(), format!( - "consider borrowing the value, since `&{self_ty}` can be coerced into `{object_ty}`" + "consider borrowing the value, since `&{self_ty}` can be coerced into `{target_ty}`" ), "&", Applicability::MaybeIncorrect, @@ -2851,30 +2852,27 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { err.span_note(tcx.def_span(item_def_id), descr); } } - ObligationCauseCode::ObjectCastObligation(concrete_ty, object_ty) => { - let (concrete_ty, concrete_file) = - self.tcx.short_ty_string(self.resolve_vars_if_possible(concrete_ty)); - let (object_ty, object_file) = - self.tcx.short_ty_string(self.resolve_vars_if_possible(object_ty)); + ObligationCauseCode::Coercion { source, target } => { + let (source, source_file) = + self.tcx.short_ty_string(self.resolve_vars_if_possible(source)); + let (target, target_file) = + self.tcx.short_ty_string(self.resolve_vars_if_possible(target)); err.note(with_forced_trimmed_paths!(format!( - "required for the cast from `{concrete_ty}` to the object type `{object_ty}`", + "required for the cast from `{source}` to `{target}`", ))); - if let Some(file) = concrete_file { + if let Some(file) = source_file { err.note(format!( - "the full name for the casted type has been written to '{}'", + "the full name for the source type has been written to '{}'", file.display(), )); } - if let Some(file) = object_file { + if let Some(file) = target_file { err.note(format!( - "the full name for the object type has been written to '{}'", + "the full name for the target type has been written to '{}'", file.display(), )); } } - ObligationCauseCode::Coercion { source: _, target } => { - err.note(format!("required by cast to type `{}`", self.ty_to_string(target))); - } ObligationCauseCode::RepeatElementCopy { is_const_fn } => { err.note( "the `Copy` trait is required because this value will be copied for each element of the array", diff --git a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs index 4dc84e0ad10b1..6a648294efd98 100644 --- a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs +++ b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs @@ -29,9 +29,9 @@ use crate::traits::{ ImplSourceAutoImplData, ImplSourceBuiltinData, ImplSourceClosureData, ImplSourceConstDestructData, ImplSourceFnPointerData, ImplSourceFutureData, ImplSourceGeneratorData, ImplSourceObjectData, ImplSourceTraitAliasData, - ImplSourceTraitUpcastingData, ImplSourceUserDefinedData, Normalized, ObjectCastObligation, - Obligation, ObligationCause, OutputTypeParameterMismatch, PredicateObligation, Selection, - SelectionError, TraitNotObjectSafe, TraitObligation, Unimplemented, + ImplSourceTraitUpcastingData, ImplSourceUserDefinedData, Normalized, Obligation, + ObligationCause, OutputTypeParameterMismatch, PredicateObligation, Selection, SelectionError, + TraitNotObjectSafe, TraitObligation, Unimplemented, }; use super::BuiltinImplConditions; @@ -905,16 +905,10 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { .map_err(|_| Unimplemented)?; nested.extend(obligations); - // Register one obligation for 'a: 'b. - let cause = ObligationCause::new( - obligation.cause.span, - obligation.cause.body_id, - ObjectCastObligation(source, target), - ); let outlives = ty::OutlivesPredicate(r_a, r_b); nested.push(Obligation::with_depth( tcx, - cause, + obligation.cause.clone(), obligation.recursion_depth + 1, obligation.param_env, obligation.predicate.rebind(outlives), @@ -1005,15 +999,10 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { nested.extend(obligations); // Register one obligation for 'a: 'b. - let cause = ObligationCause::new( - obligation.cause.span, - obligation.cause.body_id, - ObjectCastObligation(source, target), - ); let outlives = ty::OutlivesPredicate(r_a, r_b); nested.push(Obligation::with_depth( tcx, - cause, + obligation.cause.clone(), obligation.recursion_depth + 1, obligation.param_env, obligation.predicate.rebind(outlives), @@ -1027,16 +1016,10 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { return Err(TraitNotObjectSafe(did)); } - let cause = ObligationCause::new( - obligation.cause.span, - obligation.cause.body_id, - ObjectCastObligation(source, target), - ); - let predicate_to_obligation = |predicate| { Obligation::with_depth( tcx, - cause.clone(), + obligation.cause.clone(), obligation.recursion_depth + 1, obligation.param_env, predicate, @@ -1056,7 +1039,12 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { ); // We can only make objects from sized types. - let tr = ty::TraitRef::from_lang_item(tcx, LangItem::Sized, cause.span, [source]); + let tr = ty::TraitRef::from_lang_item( + tcx, + LangItem::Sized, + obligation.cause.span, + [source], + ); nested.push(predicate_to_obligation(tr.without_const().to_predicate(tcx))); // If the type is `Foo + 'a`, ensure that the type diff --git a/compiler/rustc_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs index e4f5a84f4244e..b72ff5b78e418 100644 --- a/compiler/rustc_trait_selection/src/traits/select/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs @@ -2647,14 +2647,19 @@ impl<'tcx> SelectionContext<'_, 'tcx> { let predicates = predicates.instantiate_own(tcx, substs); let mut obligations = Vec::with_capacity(predicates.len()); for (index, (predicate, span)) in predicates.into_iter().enumerate() { - let cause = cause.clone().derived_cause(parent_trait_pred, |derived| { - ImplDerivedObligation(Box::new(ImplDerivedObligationCause { - derived, - impl_or_alias_def_id: def_id, - impl_def_predicate_index: Some(index), - span, - })) - }); + let cause = + if Some(parent_trait_pred.def_id()) == tcx.lang_items().coerce_unsized_trait() { + cause.clone() + } else { + cause.clone().derived_cause(parent_trait_pred, |derived| { + ImplDerivedObligation(Box::new(ImplDerivedObligationCause { + derived, + impl_or_alias_def_id: def_id, + impl_def_predicate_index: Some(index), + span, + })) + }) + }; let predicate = normalize_with_depth_to( self, param_env, diff --git a/compiler/rustc_type_ir/src/lib.rs b/compiler/rustc_type_ir/src/lib.rs index 7e5a4d1c73532..f6b44bdf27ef9 100644 --- a/compiler/rustc_type_ir/src/lib.rs +++ b/compiler/rustc_type_ir/src/lib.rs @@ -643,7 +643,7 @@ impl UnifyKey for FloatVid { } } -#[derive(Copy, Clone, PartialEq, Decodable, Encodable, Hash, HashStable_Generic)] +#[derive(Copy, Clone, PartialEq, Eq, Decodable, Encodable, Hash, HashStable_Generic)] #[rustc_pass_by_value] pub enum Variance { Covariant, // T <: T iff A <: B -- e.g., function return type diff --git a/src/ci/docker/host-x86_64/x86_64-gnu-tools/browser-ui-test.version b/src/ci/docker/host-x86_64/x86_64-gnu-tools/browser-ui-test.version index 7092c7c46f861..d183d4ace05b9 100644 --- a/src/ci/docker/host-x86_64/x86_64-gnu-tools/browser-ui-test.version +++ b/src/ci/docker/host-x86_64/x86_64-gnu-tools/browser-ui-test.version @@ -1 +1 @@ -0.15.0 \ No newline at end of file +0.16.0 \ No newline at end of file diff --git a/src/tools/cargo b/src/tools/cargo index 26b73d15a68fb..13413c64ff88d 160000 --- a/src/tools/cargo +++ b/src/tools/cargo @@ -1 +1 @@ -Subproject commit 26b73d15a68fb94579f6d3590585ec0e9d81d3d5 +Subproject commit 13413c64ff88dd6c2824e9eb9374fc5f10895d28 diff --git a/src/tools/rustdoc-gui/tester.js b/src/tools/rustdoc-gui/tester.js index 692d5e3fcef90..b26480f668b37 100644 --- a/src/tools/rustdoc-gui/tester.js +++ b/src/tools/rustdoc-gui/tester.js @@ -143,7 +143,7 @@ async function runTests(opts, framework_options, files, results, status_bar, sho const tests_queue = []; for (const testPath of files) { - const callback = runTest(testPath, framework_options) + const callback = runTest(testPath, {"options": framework_options}) .then(out => { const [output, nb_failures] = out; results[nb_failures === 0 ? "successful" : "failed"].push({ @@ -323,6 +323,7 @@ async function main(argv) { if (results.failed.length > 0 || results.errored.length > 0) { process.exit(1); } + process.exit(0); } main(process.argv); diff --git a/tests/mir-opt/reference_prop.mut_raw_then_mut_shr.ReferencePropagation.diff b/tests/mir-opt/reference_prop.mut_raw_then_mut_shr.ReferencePropagation.diff new file mode 100644 index 0000000000000..af8ee2411d36d --- /dev/null +++ b/tests/mir-opt/reference_prop.mut_raw_then_mut_shr.ReferencePropagation.diff @@ -0,0 +1,74 @@ +- // MIR for `mut_raw_then_mut_shr` before ReferencePropagation ++ // MIR for `mut_raw_then_mut_shr` after ReferencePropagation + + fn mut_raw_then_mut_shr() -> (i32, i32) { + let mut _0: (i32, i32); // return place in scope 0 at $DIR/reference_prop.rs:+0:30: +0:40 + let mut _1: i32; // in scope 0 at $DIR/reference_prop.rs:+1:9: +1:14 + let mut _4: *mut i32; // in scope 0 at $DIR/reference_prop.rs:+3:16: +3:36 + let mut _5: &mut i32; // in scope 0 at $DIR/reference_prop.rs:+3:16: +3:26 + let _8: (); // in scope 0 at $DIR/reference_prop.rs:+7:5: +7:26 + let mut _9: i32; // in scope 0 at $DIR/reference_prop.rs:+8:6: +8:7 + let mut _10: i32; // in scope 0 at $DIR/reference_prop.rs:+8:9: +8:10 + scope 1 { + debug x => _1; // in scope 1 at $DIR/reference_prop.rs:+1:9: +1:14 + let _2: &mut i32; // in scope 1 at $DIR/reference_prop.rs:+2:9: +2:13 + scope 2 { + debug xref => _2; // in scope 2 at $DIR/reference_prop.rs:+2:9: +2:13 + let _3: *mut i32; // in scope 2 at $DIR/reference_prop.rs:+3:9: +3:13 + scope 3 { + debug xraw => _3; // in scope 3 at $DIR/reference_prop.rs:+3:9: +3:13 + let _6: &i32; // in scope 3 at $DIR/reference_prop.rs:+4:9: +4:13 + scope 4 { + debug xshr => _6; // in scope 4 at $DIR/reference_prop.rs:+4:9: +4:13 + let _7: i32; // in scope 4 at $DIR/reference_prop.rs:+6:9: +6:10 + scope 5 { + debug a => _7; // in scope 5 at $DIR/reference_prop.rs:+6:9: +6:10 + scope 6 { + } + } + } + } + } + } + + bb0: { + StorageLive(_1); // scope 0 at $DIR/reference_prop.rs:+1:9: +1:14 + _1 = const 2_i32; // scope 0 at $DIR/reference_prop.rs:+1:17: +1:18 +- StorageLive(_2); // scope 1 at $DIR/reference_prop.rs:+2:9: +2:13 + _2 = &mut _1; // scope 1 at $DIR/reference_prop.rs:+2:16: +2:22 + StorageLive(_3); // scope 2 at $DIR/reference_prop.rs:+3:9: +3:13 +- StorageLive(_4); // scope 2 at $DIR/reference_prop.rs:+3:16: +3:36 +- StorageLive(_5); // scope 2 at $DIR/reference_prop.rs:+3:16: +3:26 +- _5 = &mut (*_2); // scope 2 at $DIR/reference_prop.rs:+3:16: +3:26 +- _4 = &raw mut (*_5); // scope 2 at $DIR/reference_prop.rs:+3:16: +3:26 ++ _4 = &raw mut _1; // scope 2 at $DIR/reference_prop.rs:+3:16: +3:26 + _3 = _4; // scope 2 at $DIR/reference_prop.rs:+3:16: +3:36 +- StorageDead(_5); // scope 2 at $DIR/reference_prop.rs:+3:36: +3:37 +- StorageDead(_4); // scope 2 at $DIR/reference_prop.rs:+3:36: +3:37 + StorageLive(_6); // scope 3 at $DIR/reference_prop.rs:+4:9: +4:13 +- _6 = &(*_2); // scope 3 at $DIR/reference_prop.rs:+4:16: +4:22 ++ _6 = &_1; // scope 3 at $DIR/reference_prop.rs:+4:16: +4:22 + StorageLive(_7); // scope 4 at $DIR/reference_prop.rs:+6:9: +6:10 +- _7 = (*_6); // scope 4 at $DIR/reference_prop.rs:+6:13: +6:18 +- StorageLive(_8); // scope 5 at $DIR/reference_prop.rs:+7:5: +7:26 +- (*_3) = const 4_i32; // scope 6 at $DIR/reference_prop.rs:+7:14: +7:23 +- _8 = const (); // scope 6 at $DIR/reference_prop.rs:+7:5: +7:26 +- StorageDead(_8); // scope 5 at $DIR/reference_prop.rs:+7:25: +7:26 ++ _7 = _1; // scope 4 at $DIR/reference_prop.rs:+6:13: +6:18 ++ _1 = const 4_i32; // scope 6 at $DIR/reference_prop.rs:+7:14: +7:23 + StorageLive(_9); // scope 5 at $DIR/reference_prop.rs:+8:6: +8:7 + _9 = _7; // scope 5 at $DIR/reference_prop.rs:+8:6: +8:7 + StorageLive(_10); // scope 5 at $DIR/reference_prop.rs:+8:9: +8:10 + _10 = _1; // scope 5 at $DIR/reference_prop.rs:+8:9: +8:10 + _0 = (move _9, move _10); // scope 5 at $DIR/reference_prop.rs:+8:5: +8:11 + StorageDead(_10); // scope 5 at $DIR/reference_prop.rs:+8:10: +8:11 + StorageDead(_9); // scope 5 at $DIR/reference_prop.rs:+8:10: +8:11 + StorageDead(_7); // scope 4 at $DIR/reference_prop.rs:+9:1: +9:2 + StorageDead(_6); // scope 3 at $DIR/reference_prop.rs:+9:1: +9:2 + StorageDead(_3); // scope 2 at $DIR/reference_prop.rs:+9:1: +9:2 +- StorageDead(_2); // scope 1 at $DIR/reference_prop.rs:+9:1: +9:2 + StorageDead(_1); // scope 0 at $DIR/reference_prop.rs:+9:1: +9:2 + return; // scope 0 at $DIR/reference_prop.rs:+9:2: +9:2 + } + } + diff --git a/tests/mir-opt/reference_prop.read_through_raw.ReferencePropagation.diff b/tests/mir-opt/reference_prop.read_through_raw.ReferencePropagation.diff index a7d505c69066b..75c1f8f57ccae 100644 --- a/tests/mir-opt/reference_prop.read_through_raw.ReferencePropagation.diff +++ b/tests/mir-opt/reference_prop.read_through_raw.ReferencePropagation.diff @@ -9,15 +9,14 @@ let mut _5: *mut usize; // in scope 0 at $SRC_DIR/core/src/intrinsics/mir.rs:LL:COL bb0: { - _2 = &mut (*_1); // scope 0 at $DIR/reference_prop.rs:+10:13: +10:25 +- _2 = &mut (*_1); // scope 0 at $DIR/reference_prop.rs:+10:13: +10:25 - _3 = &mut (*_2); // scope 0 at $DIR/reference_prop.rs:+11:13: +11:26 - _4 = &raw mut (*_2); // scope 0 at $DIR/reference_prop.rs:+12:13: +12:30 - _5 = &raw mut (*_3); // scope 0 at $DIR/reference_prop.rs:+13:13: +13:30 - _0 = (*_4); // scope 0 at $DIR/reference_prop.rs:+15:13: +15:22 - _0 = (*_5); // scope 0 at $DIR/reference_prop.rs:+16:13: +16:22 -+ _3 = &mut (*_1); // scope 0 at $DIR/reference_prop.rs:+11:13: +11:26 -+ _0 = (*_2); // scope 0 at $DIR/reference_prop.rs:+15:13: +15:22 -+ _0 = (*_3); // scope 0 at $DIR/reference_prop.rs:+16:13: +16:22 ++ _0 = (*_1); // scope 0 at $DIR/reference_prop.rs:+15:13: +15:22 ++ _0 = (*_1); // scope 0 at $DIR/reference_prop.rs:+16:13: +16:22 return; // scope 0 at $DIR/reference_prop.rs:+17:13: +17:21 } } diff --git a/tests/mir-opt/reference_prop.rs b/tests/mir-opt/reference_prop.rs index e3e5d791464eb..93f8d1df8e85a 100644 --- a/tests/mir-opt/reference_prop.rs +++ b/tests/mir-opt/reference_prop.rs @@ -433,6 +433,29 @@ fn maybe_dead(m: bool) { ) } +fn mut_raw_then_mut_shr() -> (i32, i32) { + let mut x = 2; + let xref = &mut x; + let xraw = &mut *xref as *mut _; + let xshr = &*xref; + // Verify that we completely replace with `x` in both cases. + let a = *xshr; + unsafe { *xraw = 4; } + (a, x) +} + +fn unique_with_copies() { + let y = { + let mut a = 0; + let x = &raw mut a; + // `*y` is not replacable below, so we must not replace `*x`. + unsafe { opaque(*x) }; + x + }; + // But rewriting as `*x` is ok. + unsafe { opaque(*y) }; +} + fn main() { let mut x = 5_usize; let mut y = 7_usize; @@ -444,6 +467,8 @@ fn main() { multiple_storage(); dominate_storage(); maybe_dead(true); + mut_raw_then_mut_shr(); + unique_with_copies(); } // EMIT_MIR reference_prop.reference_propagation.ReferencePropagation.diff @@ -454,3 +479,5 @@ fn main() { // EMIT_MIR reference_prop.multiple_storage.ReferencePropagation.diff // EMIT_MIR reference_prop.dominate_storage.ReferencePropagation.diff // EMIT_MIR reference_prop.maybe_dead.ReferencePropagation.diff +// EMIT_MIR reference_prop.mut_raw_then_mut_shr.ReferencePropagation.diff +// EMIT_MIR reference_prop.unique_with_copies.ReferencePropagation.diff diff --git a/tests/mir-opt/reference_prop.unique_with_copies.ReferencePropagation.diff b/tests/mir-opt/reference_prop.unique_with_copies.ReferencePropagation.diff new file mode 100644 index 0000000000000..2cda2409e8093 --- /dev/null +++ b/tests/mir-opt/reference_prop.unique_with_copies.ReferencePropagation.diff @@ -0,0 +1,66 @@ +- // MIR for `unique_with_copies` before ReferencePropagation ++ // MIR for `unique_with_copies` after ReferencePropagation + + fn unique_with_copies() -> () { + let mut _0: (); // return place in scope 0 at $DIR/reference_prop.rs:+0:25: +0:25 + let _1: *mut i32; // in scope 0 at $DIR/reference_prop.rs:+1:9: +1:10 + let mut _2: i32; // in scope 0 at $DIR/reference_prop.rs:+2:13: +2:18 + let _4: (); // in scope 0 at $DIR/reference_prop.rs:+5:18: +5:28 + let mut _5: i32; // in scope 0 at $DIR/reference_prop.rs:+5:25: +5:27 + let _6: (); // in scope 0 at $DIR/reference_prop.rs:+9:14: +9:24 + let mut _7: i32; // in scope 0 at $DIR/reference_prop.rs:+9:21: +9:23 + scope 1 { + debug y => _1; // in scope 1 at $DIR/reference_prop.rs:+1:9: +1:10 + scope 5 { + } + } + scope 2 { + debug a => _2; // in scope 2 at $DIR/reference_prop.rs:+2:13: +2:18 + let _3: *mut i32; // in scope 2 at $DIR/reference_prop.rs:+3:13: +3:14 + scope 3 { + debug x => _3; // in scope 3 at $DIR/reference_prop.rs:+3:13: +3:14 + scope 4 { + } + } + } + + bb0: { + StorageLive(_1); // scope 0 at $DIR/reference_prop.rs:+1:9: +1:10 + StorageLive(_2); // scope 0 at $DIR/reference_prop.rs:+2:13: +2:18 + _2 = const 0_i32; // scope 0 at $DIR/reference_prop.rs:+2:21: +2:22 +- StorageLive(_3); // scope 2 at $DIR/reference_prop.rs:+3:13: +3:14 + _3 = &raw mut _2; // scope 2 at $DIR/reference_prop.rs:+3:17: +3:27 + StorageLive(_4); // scope 3 at $DIR/reference_prop.rs:+5:9: +5:30 + StorageLive(_5); // scope 4 at $DIR/reference_prop.rs:+5:25: +5:27 + _5 = (*_3); // scope 4 at $DIR/reference_prop.rs:+5:25: +5:27 + _4 = opaque::(move _5) -> bb1; // scope 4 at $DIR/reference_prop.rs:+5:18: +5:28 + // mir::Constant + // + span: $DIR/reference_prop.rs:452:18: 452:24 + // + literal: Const { ty: fn(i32) {opaque::}, val: Value() } + } + + bb1: { + StorageDead(_5); // scope 4 at $DIR/reference_prop.rs:+5:27: +5:28 + StorageDead(_4); // scope 3 at $DIR/reference_prop.rs:+5:30: +5:31 + _1 = _3; // scope 3 at $DIR/reference_prop.rs:+6:9: +6:10 +- StorageDead(_3); // scope 2 at $DIR/reference_prop.rs:+7:5: +7:6 + StorageDead(_2); // scope 0 at $DIR/reference_prop.rs:+7:5: +7:6 + StorageLive(_6); // scope 1 at $DIR/reference_prop.rs:+9:5: +9:26 + StorageLive(_7); // scope 5 at $DIR/reference_prop.rs:+9:21: +9:23 +- _7 = (*_1); // scope 5 at $DIR/reference_prop.rs:+9:21: +9:23 ++ _7 = (*_3); // scope 5 at $DIR/reference_prop.rs:+9:21: +9:23 + _6 = opaque::(move _7) -> bb2; // scope 5 at $DIR/reference_prop.rs:+9:14: +9:24 + // mir::Constant + // + span: $DIR/reference_prop.rs:456:14: 456:20 + // + literal: Const { ty: fn(i32) {opaque::}, val: Value() } + } + + bb2: { + StorageDead(_7); // scope 5 at $DIR/reference_prop.rs:+9:23: +9:24 + StorageDead(_6); // scope 1 at $DIR/reference_prop.rs:+9:26: +9:27 + _0 = const (); // scope 0 at $DIR/reference_prop.rs:+0:25: +10:2 + StorageDead(_1); // scope 0 at $DIR/reference_prop.rs:+10:1: +10:2 + return; // scope 0 at $DIR/reference_prop.rs:+10:2: +10:2 + } + } + diff --git a/tests/rustdoc-gui/check-stab-in-docblock.goml b/tests/rustdoc-gui/check-stab-in-docblock.goml index 2f62636211b82..f25c88690e551 100644 --- a/tests/rustdoc-gui/check-stab-in-docblock.goml +++ b/tests/rustdoc-gui/check-stab-in-docblock.goml @@ -7,20 +7,26 @@ set-window-size: (786, 600) // Confirms that there 3 paragraphs. assert-count: (".top-doc .docblock p", 3) // Checking that there is no scrollable content. -store-property: (clientHeight, ".top-doc .docblock p:nth-of-type(1)", "clientHeight") -store-property: (clientWidth, ".top-doc .docblock p:nth-of-type(1)", "clientWidth") +store-property: (".top-doc .docblock p:nth-of-type(1)", { + "clientHeight": clientHeight, + "clientWidth": clientWidth, +}) assert-property: ( ".top-doc .docblock p:nth-of-type(1)", {"scrollHeight": |clientHeight|, "scrollWidth": |clientWidth|}, ) -store-property: (clientHeight, ".top-doc .docblock p:nth-of-type(2)", "clientHeight") -store-property: (clientWidth, ".top-doc .docblock p:nth-of-type(2)", "clientWidth") +store-property: (".top-doc .docblock p:nth-of-type(2)", { + "clientHeight": clientHeight, + "clientWidth": clientWidth, +}) assert-property: ( ".top-doc .docblock p:nth-of-type(2)", {"scrollHeight": |clientHeight|, "scrollWidth": |clientWidth|}, ) -store-property: (clientHeight, ".top-doc .docblock p:nth-of-type(3)", "clientHeight") -store-property: (clientWidth, ".top-doc .docblock p:nth-of-type(3)", "clientWidth") +store-property: (".top-doc .docblock p:nth-of-type(3)", { + "clientHeight": clientHeight, + "clientWidth": clientWidth, +}) assert-property: ( ".top-doc .docblock p:nth-of-type(3)", {"scrollHeight": |clientHeight|, "scrollWidth": |clientWidth|}, diff --git a/tests/rustdoc-gui/codeblock-sub.goml b/tests/rustdoc-gui/codeblock-sub.goml index 03575cc6aaa93..a4b0558765abe 100644 --- a/tests/rustdoc-gui/codeblock-sub.goml +++ b/tests/rustdoc-gui/codeblock-sub.goml @@ -1,5 +1,5 @@ // Test that code blocks nested within do not have a line height of 0. go-to: "file://" + |DOC_PATH| + "/test_docs/codeblock_sub/index.html" -store-property: (codeblock_sub_1, "#codeblock-sub-1", "offsetHeight") +store-property: ("#codeblock-sub-1", {"offsetHeight": codeblock_sub_1}) assert-property-false: ("#codeblock-sub-3", { "offsetHeight": |codeblock_sub_1| }) diff --git a/tests/rustdoc-gui/docblock-details.goml b/tests/rustdoc-gui/docblock-details.goml index 58ff17619f63f..8e6d2ba824f73 100644 --- a/tests/rustdoc-gui/docblock-details.goml +++ b/tests/rustdoc-gui/docblock-details.goml @@ -9,7 +9,7 @@ reload: assert-text: (".top-doc .docblock > h3", "Hello") assert-css: ( ".top-doc .docblock > h3", - {"border-bottom": "1px solid rgb(210, 210, 210)"}, + {"border-bottom": "1px solid #d2d2d2"}, ) // We now check that the `` doesn't have a bottom border and has the correct display. assert-css: ( diff --git a/tests/rustdoc-gui/item-info.goml b/tests/rustdoc-gui/item-info.goml index 60fd7c4e19817..030ff8f8a3e70 100644 --- a/tests/rustdoc-gui/item-info.goml +++ b/tests/rustdoc-gui/item-info.goml @@ -4,8 +4,8 @@ go-to: "file://" + |DOC_PATH| + "/lib2/struct.Foo.html" // We set a fixed size so there is no chance of "random" resize. set-window-size: (1100, 800) // We check that ".item-info" is bigger than its content. -assert-css: (".item-info", {"width": "840px"}) -assert-css: (".item-info .stab", {"width": "289px"}) +assert-size: (".item-info", {"width": 840}) +assert-size: (".item-info .stab", {"width": 289}) assert-position: (".item-info .stab", {"x": 245}) // Now we ensure that they're not rendered on the same line. diff --git a/tests/rustdoc-gui/notable-trait.goml b/tests/rustdoc-gui/notable-trait.goml index f65da57747872..ecb57c274a5d3 100644 --- a/tests/rustdoc-gui/notable-trait.goml +++ b/tests/rustdoc-gui/notable-trait.goml @@ -225,12 +225,12 @@ assert: "#method\.create_an_iterator_from_read .tooltip:focus" // Now we check that the focus isn't given back to the wrong item when opening // another popover. -store-window-property: (scroll, "scrollY") +store-window-property: {"scrollY": scroll} click: "#method\.create_an_iterator_from_read .fn" // We ensure that the scroll position changed. assert-window-property-false: {"scrollY": |scroll|} // Store the new position. -store-window-property: (scroll, "scrollY") +store-window-property: {"scrollY": scroll} click: "//*[@id='method.create_an_iterator_from_read']//*[@class='tooltip']" wait-for: "//*[@class='tooltip popover']" click: "#settings-menu a" @@ -239,12 +239,12 @@ click: ".search-input" assert-window-property-false: {"scrollY": |scroll|} // Same but with Escape handling. -store-window-property: (scroll, "scrollY") +store-window-property: {"scrollY": scroll} click: "#method\.create_an_iterator_from_read .fn" // We ensure that the scroll position changed. assert-window-property-false: {"scrollY": |scroll|} // Store the new position. -store-window-property: (scroll, "scrollY") +store-window-property: {"scrollY": scroll} click: "//*[@id='method.create_an_iterator_from_read']//*[@class='tooltip']" wait-for: "//*[@class='tooltip popover']" click: "#settings-menu a" diff --git a/tests/rustdoc-gui/scrape-examples-button-focus.goml b/tests/rustdoc-gui/scrape-examples-button-focus.goml index 77061ea2a3f3f..af4293dfc0057 100644 --- a/tests/rustdoc-gui/scrape-examples-button-focus.goml +++ b/tests/rustdoc-gui/scrape-examples-button-focus.goml @@ -3,7 +3,7 @@ go-to: "file://" + |DOC_PATH| + "/scrape_examples/fn.test.html" // The next/prev buttons vertically scroll the code viewport between examples -store-property: (initialScrollTop, ".scraped-example-list > .scraped-example pre", "scrollTop") +store-property: (".scraped-example-list > .scraped-example pre", {"scrollTop": initialScrollTop}) focus: ".scraped-example-list > .scraped-example .next" press-key: "Enter" assert-property-false: (".scraped-example-list > .scraped-example pre", { @@ -16,7 +16,7 @@ assert-property: (".scraped-example-list > .scraped-example pre", { }, NEAR) // The expand button increases the scrollHeight of the minimized code viewport -store-property: (smallOffsetHeight, ".scraped-example-list > .scraped-example pre", "offsetHeight") +store-property: (".scraped-example-list > .scraped-example pre", {"offsetHeight": smallOffsetHeight}) assert-property-false: (".scraped-example-list > .scraped-example pre", { "scrollHeight": |smallOffsetHeight| }, NEAR) @@ -25,7 +25,7 @@ press-key: "Enter" assert-property-false: (".scraped-example-list > .scraped-example pre", { "offsetHeight": |smallOffsetHeight| }, NEAR) -store-property: (fullOffsetHeight, ".scraped-example-list > .scraped-example pre", "offsetHeight") +store-property: (".scraped-example-list > .scraped-example pre", {"offsetHeight": fullOffsetHeight}) assert-property: (".scraped-example-list > .scraped-example pre", { "scrollHeight": |fullOffsetHeight| }, NEAR) diff --git a/tests/rustdoc-gui/scrape-examples-layout.goml b/tests/rustdoc-gui/scrape-examples-layout.goml index 160056d6d0598..4fc1c1ac065f4 100644 --- a/tests/rustdoc-gui/scrape-examples-layout.goml +++ b/tests/rustdoc-gui/scrape-examples-layout.goml @@ -9,9 +9,8 @@ assert-property-false: ( // Check that examples with very long lines have the same width as ones that don't. store-property: ( - clientWidth, ".more-scraped-examples .scraped-example:nth-child(2) .code-wrapper .src-line-numbers", - "clientWidth" + {"clientWidth": clientWidth}, ) assert-property: ( @@ -40,8 +39,8 @@ assert-property: ( store-value: (offset_y, 4) // First with desktop -assert-position: (".scraped-example .code-wrapper", {"y": 253}) -assert-position: (".scraped-example .code-wrapper .prev", {"y": 253 + |offset_y|}) +assert-position: (".scraped-example .code-wrapper", {"y": 226}) +assert-position: (".scraped-example .code-wrapper .prev", {"y": 226 + |offset_y|}) // Then with mobile set-window-size: (600, 600) diff --git a/tests/rustdoc-gui/search-result-display.goml b/tests/rustdoc-gui/search-result-display.goml index 93c71f23f24e0..ee5598e4b21d0 100644 --- a/tests/rustdoc-gui/search-result-display.goml +++ b/tests/rustdoc-gui/search-result-display.goml @@ -32,8 +32,8 @@ set-text: ( ) // Then we compare again to confirm the height didn't change. -assert-css: ("#crate-search", {"width": "527px"}) -assert-css: (".search-results-title", {"height": "50px", "width": "640px"}) +assert-size: ("#crate-search", {"width": 527}) +assert-size: (".search-results-title", {"height": 50, "width": 640}) // And we check that the `