diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index 3da133f5e1136..a916ee1f143bd 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -1197,8 +1197,6 @@ impl<'hir> LoweringContext<'_, 'hir> { } } else { self.emit_bad_parenthesized_trait_in_assoc_ty(data); - // FIXME(return_type_notation): we could issue a feature error - // if the parens are empty and there's no return type. self.lower_angle_bracketed_parameter_data( &data.as_angle_bracketed_args(), ParamMode::Explicit, diff --git a/compiler/rustc_borrowck/src/diagnostics/var_name.rs b/compiler/rustc_borrowck/src/diagnostics/var_name.rs index b51604fb2903a..7106bb81da97b 100644 --- a/compiler/rustc_borrowck/src/diagnostics/var_name.rs +++ b/compiler/rustc_borrowck/src/diagnostics/var_name.rs @@ -8,7 +8,7 @@ use tracing::debug; use crate::region_infer::RegionInferenceContext; impl<'tcx> RegionInferenceContext<'tcx> { - /// Find the the name and span of the variable corresponding to the given region. + /// Find the name and span of the variable corresponding to the given region. /// The returned var will also be ensured to actually be used in `body`. pub(crate) fn get_var_name_and_span_for_region( &self, diff --git a/compiler/rustc_codegen_ssa/src/errors.rs b/compiler/rustc_codegen_ssa/src/errors.rs index cceda09c701cc..97884c202d302 100644 --- a/compiler/rustc_codegen_ssa/src/errors.rs +++ b/compiler/rustc_codegen_ssa/src/errors.rs @@ -1220,14 +1220,17 @@ pub(crate) struct UnstableCTargetFeature<'a> { #[derive(Diagnostic)] #[diag("target feature `{$feature}` cannot be {$enabled} with `-Ctarget-feature`: {$reason}")] -#[note( - "this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!" -)] -#[note("for more information, see issue #116344 ")] pub(crate) struct ForbiddenCTargetFeature<'a> { pub feature: &'a str, pub enabled: &'a str, pub reason: &'a str, + #[note( + "this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!" + )] + #[note( + "for more information, see issue #116344 " + )] + pub future_compat_note: bool, } pub(crate) struct TargetFeatureDisableOrEnable<'a> { diff --git a/compiler/rustc_codegen_ssa/src/target_features.rs b/compiler/rustc_codegen_ssa/src/target_features.rs index 2572d21608213..1310005437e77 100644 --- a/compiler/rustc_codegen_ssa/src/target_features.rs +++ b/compiler/rustc_codegen_ssa/src/target_features.rs @@ -308,12 +308,19 @@ pub fn cfg_target_feature<'a, const N: usize>( sess.dcx().emit_warn(unknown_feature); } Some((_, stability, _)) => { - if let Err(reason) = stability.toggle_allowed() { - sess.dcx().emit_warn(errors::ForbiddenCTargetFeature { + if let Stability::Forbidden { reason, hard_error } = stability { + let diag = errors::ForbiddenCTargetFeature { feature: base_feature, enabled: if enable { "enabled" } else { "disabled" }, reason, - }); + future_compat_note: !hard_error, + }; + + if *hard_error { + sess.dcx().emit_err(diag); + } else { + sess.dcx().emit_warn(diag); + } } else if stability.requires_nightly(/* in_cfg */ false).is_some() { // An unstable feature. Warn about using it. It makes little sense // to hard-error here since we just warn about fully unknown diff --git a/compiler/rustc_lint/src/expect.rs b/compiler/rustc_lint/src/expect.rs index 5364a4141805b..2f257bb092ae8 100644 --- a/compiler/rustc_lint/src/expect.rs +++ b/compiler/rustc_lint/src/expect.rs @@ -38,7 +38,7 @@ fn check_expectations(tcx: TyCtxt<'_>, tool_filter: Option) { (tcx.hir_attrs(id.hir_id)[id.attr_index as usize].id(), id.lint_index) } }; - (attr_id, lint_index.expect("fulfilled expectations must have a lint index")) + (attr_id, lint_index) }; let fulfilled_expectations: FxHashSet<_> = diff --git a/compiler/rustc_lint/src/levels.rs b/compiler/rustc_lint/src/levels.rs index b8da46594cfc2..00ae385c57672 100644 --- a/compiler/rustc_lint/src/levels.rs +++ b/compiler/rustc_lint/src/levels.rs @@ -233,7 +233,7 @@ pub trait LintLevelsProvider { &self, attr_id: AttrId, attr_index: usize, - lint_index: Option, + lint_index: u16, ) -> Self::LintExpectationId; } @@ -258,7 +258,7 @@ impl LintLevelsProvider for TopDown { &self, attr_id: AttrId, _attr_index: usize, - lint_index: Option, + lint_index: u16, ) -> Self::LintExpectationId { UnstableLintExpectationId { attr_id, lint_index } } @@ -296,7 +296,7 @@ impl LintLevelsProvider for LintLevelQueryMap<'_> { &self, _attr_id: AttrId, attr_index: usize, - lint_index: Option, + lint_index: u16, ) -> Self::LintExpectationId { let attr_index = attr_index.try_into().unwrap(); StableLintExpectationId { hir_id: self.cur, attr_index, lint_index } @@ -740,11 +740,7 @@ where // `Expect` is the only lint level with a `LintExpectationId` that can be created // from an attribute. let lint_id = (level == Level::Expect).then(|| { - self.provider.mk_lint_expectation_id( - attr.id(), - attr_index, - Some(lint_index as u16), - ) + self.provider.mk_lint_expectation_id(attr.id(), attr_index, lint_index as u16) }); let sp = li.span(); diff --git a/compiler/rustc_lint_defs/src/lib.rs b/compiler/rustc_lint_defs/src/lib.rs index fc8b2b65a8d48..1edc12e1ca7eb 100644 --- a/compiler/rustc_lint_defs/src/lib.rs +++ b/compiler/rustc_lint_defs/src/lib.rs @@ -109,7 +109,7 @@ pub enum LintExpectationId { #[derive(Clone, Copy, PartialEq, Eq, Debug, Hash, Encodable, Decodable)] pub struct UnstableLintExpectationId { pub attr_id: AttrId, - pub lint_index: Option, + pub lint_index: u16, } impl From for LintExpectationId { @@ -125,7 +125,7 @@ impl From for LintExpectationId { pub struct StableLintExpectationId { pub hir_id: HirId, pub attr_index: u16, - pub lint_index: Option, + pub lint_index: u16, } impl StableHash for StableLintExpectationId { @@ -135,7 +135,7 @@ impl StableHash for StableLintExpectationId { hir_id.stable_hash(hcx, hasher); attr_index.stable_hash(hcx, hasher); - lint_index.expect("must be filled to call `stable_hash`").stable_hash(hcx, hasher); + lint_index.stable_hash(hcx, hasher); } } diff --git a/compiler/rustc_mir_build/src/builder/expr/as_place.rs b/compiler/rustc_mir_build/src/builder/expr/as_place.rs index ff7e518f91a81..e92f74722626b 100644 --- a/compiler/rustc_mir_build/src/builder/expr/as_place.rs +++ b/compiler/rustc_mir_build/src/builder/expr/as_place.rs @@ -583,6 +583,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { | ExprKind::ThreadLocalRef(_) | ExprKind::Call { .. } | ExprKind::ByUse { .. } + // A reborrow is an rvalue. If a place is needed for it, materialize + // the rvalue in a temporary instead of treating the reborrow + // expression itself as an assignable place. + | ExprKind::Reborrow { .. } | ExprKind::WrapUnsafeBinder { .. } => { // these are not places, so we need to make a temporary. debug_assert!(!matches!(Category::of(&expr.kind), Some(Category::Place))); @@ -590,12 +594,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { let temp = unpack!(block = this.as_temp(block, temp_lifetime, expr_id, mutability)); block.and(PlaceBuilder::from(temp)) } - ExprKind::Reborrow { .. } => { - // FIXME(reborrow): it should currently be impossible to end up evaluating a - // Reborrow expression as a place. That might not in the future, but what this then - // evaluates to requires further thought. - unreachable!(); - } } } diff --git a/compiler/rustc_mir_build/src/builder/expr/category.rs b/compiler/rustc_mir_build/src/builder/expr/category.rs index eb6a0754358d1..1a2f0a791b697 100644 --- a/compiler/rustc_mir_build/src/builder/expr/category.rs +++ b/compiler/rustc_mir_build/src/builder/expr/category.rs @@ -43,8 +43,7 @@ impl Category { | ExprKind::PlaceTypeAscription { .. } | ExprKind::ValueTypeAscription { .. } | ExprKind::PlaceUnwrapUnsafeBinder { .. } - | ExprKind::ValueUnwrapUnsafeBinder { .. } - | ExprKind::Reborrow { .. } => Some(Category::Place), + | ExprKind::ValueUnwrapUnsafeBinder { .. } => Some(Category::Place), ExprKind::LogicalOp { .. } | ExprKind::Match { .. } @@ -70,6 +69,10 @@ impl Category { | ExprKind::Repeat { .. } | ExprKind::Assign { .. } | ExprKind::AssignOp { .. } + // A reborrow expression produces a value represented in MIR as + // `Rvalue::Reborrow`. Its source may be a place, but the reborrow + // expression itself does not denote an assignable place. + | ExprKind::Reborrow { .. } | ExprKind::ThreadLocalRef(_) | ExprKind::WrapUnsafeBinder { .. } => Some(Category::Rvalue(RvalueFunc::AsRvalue)), diff --git a/compiler/rustc_privacy/src/lib.rs b/compiler/rustc_privacy/src/lib.rs index 23a8ddaa3d6da..de5c00306a736 100644 --- a/compiler/rustc_privacy/src/lib.rs +++ b/compiler/rustc_privacy/src/lib.rs @@ -783,7 +783,7 @@ impl ReachEverythingInTheInterfaceVisitor<'_, '_> { } } - DefKind::TraitAlias | DefKind::Fn => { + DefKind::TraitAlias | DefKind::Fn | DefKind::TyAlias => { self.ev.queue.insert(def_id); } @@ -808,7 +808,6 @@ impl ReachEverythingInTheInterfaceVisitor<'_, '_> { // Can't be reached DefKind::Impl { .. } - | DefKind::TyAlias | DefKind::Field | DefKind::Variant | DefKind::Static { .. } diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index 21b36f1934c3a..f4bd6354972b5 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -3937,7 +3937,9 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { //As we lower target_expr_template body to a body of a function we need a label rib (#148889) this.with_label_rib(RibKind::FnOrCoroutine, |this| { - this.visit_block(body); + this.with_lifetime_rib(LifetimeRibKind::Elided(LifetimeRes::Infer), |this| { + this.visit_block(body); + }); }); }); } diff --git a/compiler/rustc_target/src/target_features.rs b/compiler/rustc_target/src/target_features.rs index e2bf1c48b7b47..b009c42eb2302 100644 --- a/compiler/rustc_target/src/target_features.rs +++ b/compiler/rustc_target/src/target_features.rs @@ -35,7 +35,12 @@ pub enum Stability { /// set in the target spec. It is never set in `cfg(target_feature)`. Used in /// particular for features are actually ABI configuration flags (not all targets are as nice as /// RISC-V and have an explicit way to set the ABI separate from target features). - Forbidden { reason: &'static str }, + Forbidden { + reason: &'static str, + /// True if this is always an error, false if this can be reported as a warning when set via + /// `-Ctarget-feature`. + hard_error: bool, + }, } use Stability::*; @@ -85,14 +90,14 @@ impl Stability { } /// Returns whether the feature may be toggled via `#[target_feature]` or `-Ctarget-feature`. - /// (It might still be nightly-only even if this returns `true`, so make sure to also check + /// (It might still be nightly-only even if this returns `Ok(())`, so make sure to also check /// `requires_nightly`.) pub fn toggle_allowed(&self) -> Result<(), &'static str> { match self { Stability::Unstable(_) | Stability::CfgStableToggleUnstable(_) | Stability::Stable { .. } => Ok(()), - Stability::Forbidden { reason } => Err(reason), + Stability::Forbidden { reason, hard_error: _ } => Err(reason), } } } @@ -149,7 +154,10 @@ static ARM_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[ ("aes", Unstable(sym::arm_target_feature), &["neon"]), ( "atomics-32", - Stability::Forbidden { reason: "unsound because it changes the ABI of atomic operations" }, + Stability::Forbidden { + reason: "unsound because it changes the ABI of atomic operations", + hard_error: false, + }, &[], ), ("crc", Unstable(sym::arm_target_feature), &[]), @@ -225,7 +233,11 @@ static AARCH64_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[ // FEAT_FLAGM2 ("flagm2", Unstable(sym::aarch64_unstable_target_feature), &[]), // We forbid directly toggling just `fp-armv8`; it must be toggled with `neon`. - ("fp-armv8", Stability::Forbidden { reason: "Rust ties `fp-armv8` to `neon`" }, &[]), + ( + "fp-armv8", + Stability::Forbidden { reason: "Rust ties `fp-armv8` to `neon`", hard_error: false }, + &[], + ), // FEAT_FP8 ("fp8", Unstable(sym::aarch64_unstable_target_feature), &["faminmax", "lut", "bf16"]), // FEAT_FP8DOT2 @@ -288,7 +300,11 @@ static AARCH64_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[ ("rcpc3", Unstable(sym::aarch64_unstable_target_feature), &["rcpc2"]), // FEAT_RDM ("rdm", Stable, &["neon"]), - ("reserve-x18", Forbidden { reason: "use `-Zfixed-x18` compiler flag instead" }, &[]), + ( + "reserve-x18", + Forbidden { reason: "use `-Zfixed-x18` compiler flag instead", hard_error: false }, + &[], + ), // FEAT_SB ("sb", Stable, &[]), // FEAT_SHA1 & FEAT_SHA256 @@ -467,17 +483,26 @@ static X86_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[ ("rdseed", Stable, &[]), ( "retpoline-external-thunk", - Stability::Forbidden { reason: "use `-Zretpoline-external-thunk` compiler flag instead" }, + Stability::Forbidden { + reason: "use `-Zretpoline-external-thunk` compiler flag instead", + hard_error: false, + }, &[], ), ( "retpoline-indirect-branches", - Stability::Forbidden { reason: "use `-Zretpoline` compiler flag instead" }, + Stability::Forbidden { + reason: "use `-Zretpoline` compiler flag instead", + hard_error: false, + }, &[], ), ( "retpoline-indirect-calls", - Stability::Forbidden { reason: "use `-Zretpoline` compiler flag instead" }, + Stability::Forbidden { + reason: "use `-Zretpoline` compiler flag instead", + hard_error: false, + }, &[], ), ("rtm", Unstable(sym::rtm_target_feature), &[]), @@ -485,7 +510,11 @@ static X86_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[ ("sha512", Stable, &["avx2"]), ("sm3", Stable, &["avx"]), ("sm4", Stable, &["avx2"]), - ("soft-float", Stability::Forbidden { reason: "use a soft-float target instead" }, &[]), + ( + "soft-float", + Stability::Forbidden { reason: "use a soft-float target instead", hard_error: false }, + &[], + ), ("sse", Stable, &[]), ("sse2", Stable, &["sse"]), ("sse3", Stable, &["sse2"]), @@ -615,7 +644,10 @@ static RISCV_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[ ("f", Unstable(sym::riscv_target_feature), &["zicsr"]), ( "forced-atomics", - Stability::Forbidden { reason: "unsound because it changes the ABI of atomic operations" }, + Stability::Forbidden { + reason: "unsound because it changes the ABI of atomic operations", + hard_error: false, + }, &[], ), ("m", Stable, &[]), @@ -872,7 +904,7 @@ const IBMZ_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[ ("miscellaneous-extensions-3", Stable, &[]), ("miscellaneous-extensions-4", Stable, &[]), ("nnp-assist", Stable, &["vector"]), - ("soft-float", Forbidden { reason: "unsupported ABI-configuration feature" }, &[]), + ("soft-float", Forbidden { reason: "unsupported ABI-configuration feature", hard_error: false }, &[]), ("transactional-execution", Unstable(sym::s390x_target_feature), &[]), ("vector", Stable, &[]), ("vector-enhancements-1", Stable, &["vector"]), @@ -924,7 +956,11 @@ static AVR_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[ ("rmw", Unstable(sym::avr_target_feature), &[]), ("spm", Unstable(sym::avr_target_feature), &[]), ("spmx", Unstable(sym::avr_target_feature), &[]), - ("sram", Forbidden { reason: "devices that have no SRAM are unsupported" }, &[]), + ( + "sram", + Forbidden { reason: "devices that have no SRAM are unsupported", hard_error: false }, + &[], + ), ("tinyencoding", Unstable(sym::avr_target_feature), &[]), // tidy-alphabetical-end ]; diff --git a/compiler/rustc_type_ir/src/solve/mod.rs b/compiler/rustc_type_ir/src/solve/mod.rs index f2ea2e5a729e8..fb61d3a467316 100644 --- a/compiler/rustc_type_ir/src/solve/mod.rs +++ b/compiler/rustc_type_ir/src/solve/mod.rs @@ -145,7 +145,7 @@ impl AsRef<[T]> for SmallCopyList { /// | never | no | no | /// | always | yes | yes | /// | [defid in storage] | no | only if any of the defids in the list is in the opaque type storage OR if TypingMode::PostAnalysis | -/// | opaque with hidden type | no | only if any of the the opaques in the opaque type storage has a hidden type in this list AND if TypingMode::Analysis | +/// | opaque with hidden type | no | only if any of the opaques in the opaque type storage has a hidden type in this list AND if TypingMode::Analysis | /// /// - "bail" is implemented with [`should_bail`](Self::should_bail). /// If true, we're abandoning our attempt to canonicalize in [`TypingMode::ErasedNotCoherence`], diff --git a/src/bootstrap/src/core/build_steps/dist.rs b/src/bootstrap/src/core/build_steps/dist.rs index 360b8418d2194..4bd4fb0834e25 100644 --- a/src/bootstrap/src/core/build_steps/dist.rs +++ b/src/bootstrap/src/core/build_steps/dist.rs @@ -2587,6 +2587,12 @@ pub fn maybe_install_llvm_runtime(builder: &Builder<'_>, target: TargetSelection // statically. if builder.llvm_link_shared() { maybe_install_llvm(builder, target, &dst_libdir, false); + + // To workaround lack of rpath on Windows, we bundle another copy of + // the LLVM DLL to make rust-lld and llvm-tools work when `sysroot/bin` + // is missing from PATH, i.e. when they not launched by rustc. + let dst_libdir = sysroot.join("lib/rustlib").join(target).join("bin"); + maybe_install_llvm(builder, target, &dst_libdir, false); } } diff --git a/src/etc/lldb_providers.py b/src/etc/lldb_providers.py index e299a64f2c9a9..2da6151607e3c 100644 --- a/src/etc/lldb_providers.py +++ b/src/etc/lldb_providers.py @@ -15,7 +15,7 @@ from rust_types import is_tuple_fields if TYPE_CHECKING: - from lldb import SBValue, SBType, SBTypeStaticField, SBTarget + from lldb import SBValue, SBType, SBTypeStaticField, SBTarget, SBProcess # from lldb.formatters import Logger @@ -289,6 +289,28 @@ def vec_to_string(vec: SBValue) -> str: ) +def read_string( + process: SBProcess, address: int, length: int, error: Optional[SBError] = None +) -> str: + """Reads a string from running process's memory. If `error` is passed in, it will be passed + to the `SBProcess.ReadMemory` call, and will reflect any errors after the function is called. + + If any error or exception occurs, a placeholder byte array of the form "" will + be returned instead.""" + + if error is None: + error = SBError() + try: + data = process.ReadMemory(address, length, error) + if error.Success(): + return '"' + data.decode("utf-8", "replace") + '"' + else: + return f"" + except Exception as e: + print(f"Unable to generate String summary: {e.__cause__}") + return "" + + def StdStringSummaryProvider(valobj: SBValue, dict: LLDBOpaque): inner_vec = ( valobj.GetNonSyntheticValue() @@ -305,16 +327,25 @@ def StdStringSummaryProvider(valobj: SBValue, dict: LLDBOpaque): ) length = inner_vec.GetChildMemberWithName("len").GetValueAsUnsigned() + capacity = ( + inner_vec.GetChildMemberWithName("buf") + .GetChildMemberWithName("cap") + .GetValueAsUnsigned() + ) if length <= 0: return '""' - error = SBError() + + no_hi_bit_max: int = 1 << ((pointer.GetByteSize() * 8) - 1) + # technically length isn't a NoHighBit, but length should always be <= capacity + if length >= no_hi_bit_max or capacity >= no_hi_bit_max: + return "" + if pointer.GetValueAsUnsigned() == 0: + return "" + process = pointer.GetProcess() - data = process.ReadMemory(pointer.GetValueAsUnsigned(), length, error) - if error.Success(): - return '"' + data.decode("utf8", "replace") + '"' - else: - raise Exception("ReadMemory error: %s", error.GetCString()) + + return read_string(process, pointer.GetValueAsAddress(), length) def StdOsStringSummaryProvider(valobj: SBValue, _dict: LLDBOpaque) -> str: @@ -363,15 +394,9 @@ def StdPathSummaryProvider(valobj: SBValue, _dict: LLDBOpaque) -> str: data_ptr = valobj.GetChildMemberWithName("data_ptr") start = data_ptr.GetValueAsUnsigned() - error = SBError() process = data_ptr.GetProcess() - data = process.ReadMemory(start, length, error) - if PY3: - try: - data = data.decode(encoding="UTF-8") - except UnicodeDecodeError: - return "%r" % data - return '"%s"' % data + + return read_string(process, start, length) def sequence_formatter(output: str, valobj: SBValue, _dict: LLDBOpaque): @@ -443,6 +468,9 @@ def has_children(self) -> bool: class StdStringSyntheticProvider: def __init__(self, valobj: SBValue, _dict: LLDBOpaque): self.valobj = valobj + ptr_size = valobj.GetTarget().GetAddressByteSize() * 8 + self.no_hi_bit_max = 1 << (ptr_size - 1) + self.update() def update(self): @@ -454,7 +482,25 @@ def update(self): .GetChildMemberWithName("pointer") .GetChildMemberWithName("pointer") ) - self.length = inner_vec.GetChildMemberWithName("len").GetValueAsUnsigned() + + self.capacity = ( + inner_vec.GetChildMemberWithName("buf") + .GetChildMemberWithName("cap") + .GetValueAsUnsigned() + ) + + # As of 4/18/2026, LLDB cannot accurately determine the difference between Some("") and None + # this just makes sure we're not trying to access data when the string is clearly in an + # invalid state. + if ( + self.capacity >= self.no_hi_bit_max + or self.data_ptr.GetValueAsUnsigned() == 0 + ): + self.capacity = 0 + self.length = 0 + else: + self.length = inner_vec.GetChildMemberWithName("len").GetValueAsUnsigned() + self.element_type = self.data_ptr.GetType().GetPointeeType() def has_children(self) -> bool: @@ -928,6 +974,8 @@ def __init__(self, valobj: SBValue, _dict: LLDBOpaque): # logger >> "[StdVecSyntheticProvider] for " + str(valobj.GetName()) self.valobj = valobj self.element_type = None + ptr_size = valobj.GetTarget().GetAddressByteSize() * 8 + self.no_hi_bit_max = 1 << (ptr_size - 1) self.update() def num_children(self) -> int: @@ -949,15 +997,19 @@ def get_child_at_index(self, index: int) -> Optional[SBValue]: return element def update(self): - self.length = self.valobj.GetChildMemberWithName("len").GetValueAsUnsigned() - self.buf = self.valobj.GetChildMemberWithName("buf").GetChildMemberWithName( - "inner" - ) - + buf: SBValue = self.valobj.GetChildMemberWithName("buf") self.data_ptr = unwrap_unique_or_non_null( - self.buf.GetChildMemberWithName("ptr") + buf.GetChildMemberWithName("inner").GetChildMemberWithName("ptr") ) + capacity: int = buf.GetChildMemberWithName("cap").GetValueAsUnsigned() + + if capacity >= self.no_hi_bit_max or self.data_ptr.GetValueAsUnsigned() == 0: + self.capacity = 0 + self.length = 0 + else: + self.length = self.valobj.GetChildMemberWithName("len").GetValueAsUnsigned() + self.element_type = self.valobj.GetType().GetTemplateArgumentType(0) if not self.element_type.IsValid(): diff --git a/src/tools/rustfmt/src/items.rs b/src/tools/rustfmt/src/items.rs index 32f71703e019f..95b13eb4aac99 100644 --- a/src/tools/rustfmt/src/items.rs +++ b/src/tools/rustfmt/src/items.rs @@ -960,6 +960,7 @@ fn format_impl_ref_and_type( if let Some(of_trait) = of_trait.as_deref() { result.push_str(format_defaultness(of_trait.defaultness)); + result.push_str(format_constness(*constness)); result.push_str(format_safety(of_trait.safety)); } else { result.push_str(format_constness(*constness)); @@ -980,7 +981,6 @@ fn format_impl_ref_and_type( let trait_ref_overhead; if let Some(of_trait) = of_trait.as_deref() { - result.push_str(format_constness_right(*constness)); let polarity_str = match of_trait.polarity { ast::ImplPolarity::Negative(_) => "!", ast::ImplPolarity::Positive => "", diff --git a/src/tools/rustfmt/src/utils.rs b/src/tools/rustfmt/src/utils.rs index de72c9ce14bc3..6eb76c935a920 100644 --- a/src/tools/rustfmt/src/utils.rs +++ b/src/tools/rustfmt/src/utils.rs @@ -125,14 +125,6 @@ pub(crate) fn format_constness(constness: ast::Const) -> &'static str { } } -#[inline] -pub(crate) fn format_constness_right(constness: ast::Const) -> &'static str { - match constness { - ast::Const::Yes(..) => " const", - ast::Const::No => "", - } -} - #[inline] pub(crate) fn format_defaultness(defaultness: ast::Defaultness) -> &'static str { match defaultness { diff --git a/src/tools/rustfmt/tests/source/const_trait.rs b/src/tools/rustfmt/tests/source/const_trait.rs deleted file mode 100644 index 99414a74f250c..0000000000000 --- a/src/tools/rustfmt/tests/source/const_trait.rs +++ /dev/null @@ -1,14 +0,0 @@ -#![feature(trait_alias, const_trait_impl)] - -const trait Bar {} - -const trait Foo = Bar; - -impl const Bar for () {} - -// const impl gets reformatted to impl const.. for now -const impl Bar for u8 {} - -struct X; - -const impl X {} diff --git a/src/tools/rustfmt/tests/target/const_trait.rs b/src/tools/rustfmt/tests/target/const_trait.rs index 337a4cf4140e8..bb6ba1cd85b1d 100644 --- a/src/tools/rustfmt/tests/target/const_trait.rs +++ b/src/tools/rustfmt/tests/target/const_trait.rs @@ -4,10 +4,7 @@ const trait Bar {} const trait Foo = Bar; -impl const Bar for () {} - -// const impl gets reformatted to impl const.. for now -impl const Bar for u8 {} +const impl Bar for () {} struct X; diff --git a/src/tools/rustfmt/tests/target/impls.rs b/src/tools/rustfmt/tests/target/impls.rs index 99e02990e4177..71dfb5591e7ce 100644 --- a/src/tools/rustfmt/tests/target/impls.rs +++ b/src/tools/rustfmt/tests/target/impls.rs @@ -244,7 +244,7 @@ where } // #4084 -impl const std::default::Default for Struct { +const impl std::default::Default for Struct { #[inline] fn default() -> Self { Self { f: 12.5 } diff --git a/src/tools/rustfmt/tests/target/type.rs b/src/tools/rustfmt/tests/target/type.rs index 623192b72b8b7..4855f726ea3f9 100644 --- a/src/tools/rustfmt/tests/target/type.rs +++ b/src/tools/rustfmt/tests/target/type.rs @@ -153,7 +153,7 @@ const fn not_quite_const() -> i32 { ::CONST } -impl const T for U {} +const impl T for U {} fn apit(_: impl [const] T) {} diff --git a/tests/ui/delegation/ice-line-bounds-issue-148732.rs b/tests/ui/delegation/ice-line-bounds-issue-148732.rs index 699e7d86f2581..0123f0c8705b0 100644 --- a/tests/ui/delegation/ice-line-bounds-issue-148732.rs +++ b/tests/ui/delegation/ice-line-bounds-issue-148732.rs @@ -2,7 +2,7 @@ reuse a as b { //~^ ERROR cannot find function `a` in this scope //~| ERROR functions delegation is not yet fully implemented dbg!(b); - //~^ ERROR missing lifetime specifier + //~^ ERROR: `fn() {b}` doesn't implement `Debug` } fn main() {} diff --git a/tests/ui/delegation/ice-line-bounds-issue-148732.stderr b/tests/ui/delegation/ice-line-bounds-issue-148732.stderr index c4f261181b109..eb93655beb60d 100644 --- a/tests/ui/delegation/ice-line-bounds-issue-148732.stderr +++ b/tests/ui/delegation/ice-line-bounds-issue-148732.stderr @@ -1,9 +1,3 @@ -error[E0106]: missing lifetime specifier - --> $DIR/ice-line-bounds-issue-148732.rs:4:5 - | -LL | dbg!(b); - | ^^^^^^^ expected named lifetime parameter - error[E0425]: cannot find function `a` in this scope --> $DIR/ice-line-bounds-issue-148732.rs:1:7 | @@ -25,7 +19,18 @@ LL | | } = help: add `#![feature(fn_delegation)]` to the crate attributes to enable = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date +error[E0277]: `fn() {b}` doesn't implement `Debug` + --> $DIR/ice-line-bounds-issue-148732.rs:4:5 + | +LL | reuse a as b { + | - consider calling this function +... +LL | dbg!(b); + | ^^^^^^^ the trait `Debug` is not implemented for fn item `fn() {b}` + | + = help: use parentheses to call this function: `b()` + error: aborting due to 3 previous errors -Some errors have detailed explanations: E0106, E0425, E0658. -For more information about an error, try `rustc --explain E0106`. +Some errors have detailed explanations: E0277, E0425, E0658. +For more information about an error, try `rustc --explain E0277`. diff --git a/tests/ui/delegation/wrong-lifetime-rib.rs b/tests/ui/delegation/wrong-lifetime-rib.rs index 14d62cbaa41fa..825ac6a64008a 100644 --- a/tests/ui/delegation/wrong-lifetime-rib.rs +++ b/tests/ui/delegation/wrong-lifetime-rib.rs @@ -29,4 +29,14 @@ mod ice_156758 { } } +mod ice_156806 { + trait X {} + + impl X { //~ ERROR: expected a type, found a trait + reuse Iterator::fold { //~ ERROR: `()` is not an iterator + let _: &X; //~ ERROR: expected a type, found a trait + } + } +} + fn main() {} diff --git a/tests/ui/delegation/wrong-lifetime-rib.stderr b/tests/ui/delegation/wrong-lifetime-rib.stderr index 2c9594af581ce..07ddc94f7a4ae 100644 --- a/tests/ui/delegation/wrong-lifetime-rib.stderr +++ b/tests/ui/delegation/wrong-lifetime-rib.stderr @@ -19,6 +19,21 @@ help: you might have intended to implement this trait for a given type LL | impl X for /* Type */ { | ++++++++++++++ +error[E0782]: expected a type, found a trait + --> $DIR/wrong-lifetime-rib.rs:35:10 + | +LL | impl X { + | ^ + | +help: you can add the `dyn` keyword if you want a trait object + | +LL | impl dyn X { + | +++ +help: you might have intended to implement this trait for a given type + | +LL | impl X for /* Type */ { + | ++++++++++++++ + error[E0116]: cannot define inherent `impl` for a type outside of the crate where the type is defined --> $DIR/wrong-lifetime-rib.rs:9:5 | @@ -40,7 +55,28 @@ LL - reuse<<<&Project> :: Ty> :: Ty as Iterator>::next; LL + reuse<<<&() as Example>::Ty> :: Ty as Iterator>::next; | -error: aborting due to 4 previous errors +error[E0782]: expected a type, found a trait + --> $DIR/wrong-lifetime-rib.rs:37:21 + | +LL | let _: &X; + | ^ + | +help: you can add the `dyn` keyword if you want a trait object + | +LL | let _: &dyn X; + | +++ + +error[E0599]: `()` is not an iterator + --> $DIR/wrong-lifetime-rib.rs:36:25 + | +LL | reuse Iterator::fold { + | ^^^^ `()` is not an iterator + | + = note: the following trait bounds were not satisfied: + `(): Iterator` + which is required by `&mut (): Iterator` + +error: aborting due to 7 previous errors -Some errors have detailed explanations: E0116, E0223, E0423, E0782. +Some errors have detailed explanations: E0116, E0223, E0423, E0599, E0782. For more information about an error, try `rustc --explain E0116`. diff --git a/tests/ui/privacy/reach-type-alias-issue-156778.rs b/tests/ui/privacy/reach-type-alias-issue-156778.rs new file mode 100644 index 0000000000000..4297a44038cfc --- /dev/null +++ b/tests/ui/privacy/reach-type-alias-issue-156778.rs @@ -0,0 +1,20 @@ +//@ check-pass +#![feature(lazy_type_alias)] + +use src::hidden_core; +mod src { + mod aliases { + use hidden_core::InternalStruct; + pub type ExposedType = InternalStruct; + } + pub mod hidden_core { + use super::aliases::ExposedType; + pub struct InternalStruct { + _x: T, + } + pub fn new() -> ExposedType { + InternalStruct { _x: 1.0 } + } + } +} +fn main() {} diff --git a/tests/ui/reborrow/generic-reborrow-rvalue-contract.rs b/tests/ui/reborrow/generic-reborrow-rvalue-contract.rs new file mode 100644 index 0000000000000..465be1b52fb2c --- /dev/null +++ b/tests/ui/reborrow/generic-reborrow-rvalue-contract.rs @@ -0,0 +1,40 @@ +//@ check-pass +// Regression test for rust-lang/rust#156482. +// This used to ICE in MIR building when a THIR `ExprKind::Reborrow` +// was categorized as a place but `expr_as_place` treated it as unreachable. + +#![feature(reborrow)] + +use std::marker::{CoerceShared, Reborrow}; + +struct Thing<'a>(&'a ()); + +impl<'a> Reborrow for Thing<'a> {} + +fn foo(x: Thing<'_>) { + let _: Thing<'_> = x; +} + +#[allow(unused)] +struct CustomMut<'a, T>(&'a mut T); +impl<'a, T> Reborrow for CustomMut<'a, T> {} +impl<'a, T> CoerceShared> for CustomMut<'a, T> {} + +#[allow(unused)] +struct CustomRef<'a, T>(&'a T); +impl<'a, T> Clone for CustomRef<'a, T> { + fn clone(&self) -> Self { + Self(self.0) + } +} +impl<'a, T> Copy for CustomRef<'a, T> {} + +fn main() { + let a = CustomMut(&mut ()); + + let _: CustomMut<'_, ()> = a; + let _: CustomMut<'_, ()> = a; + + let _: CustomRef<'_, ()> = a; + let _: CustomRef<'_, ()> = a; +}