From 14e6f3f5625fb719cb337b21722c88cbbc85f884 Mon Sep 17 00:00:00 2001 From: Kai Luo Date: Wed, 13 Dec 2023 13:28:00 +0800 Subject: [PATCH 1/9] Fix XCOFF metadata --- .../rustc_codegen_ssa/src/back/metadata.rs | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/compiler/rustc_codegen_ssa/src/back/metadata.rs b/compiler/rustc_codegen_ssa/src/back/metadata.rs index bc0e3a82806..d8550428984 100644 --- a/compiler/rustc_codegen_ssa/src/back/metadata.rs +++ b/compiler/rustc_codegen_ssa/src/back/metadata.rs @@ -158,12 +158,13 @@ pub(super) fn get_metadata_xcoff<'a>(path: &Path, data: &'a [u8]) -> Result<&'a file.symbols().find(|sym| sym.name() == Ok(AIX_METADATA_SYMBOL_NAME)) { let offset = metadata_symbol.address() as usize; - if offset < 8 { + // The offset specifies the location of rustc metadata in the .info section of XCOFF. + // Each string stored in .info section of XCOFF is preceded by a 4-byte lenght field. + if offset < 4 { return Err(format!("Invalid metadata symbol offset: {offset}")); } - // The offset specifies the location of rustc metadata in the comment section. - // The metadata is preceded by a 8-byte length field. - let len = u64::from_le_bytes(info_data[(offset - 8)..offset].try_into().unwrap()) as usize; + // XCOFF format uses big-endian byte order. + let len = u32::from_be_bytes(info_data[(offset - 4)..offset].try_into().unwrap()) as usize; if offset + len > (info_data.len() as usize) { return Err(format!( "Metadata at offset {offset} with size {len} is beyond .info section" @@ -478,9 +479,9 @@ pub fn create_wrapper_file( file.add_section(Vec::new(), b".text".to_vec(), SectionKind::Text); file.section_mut(section).flags = SectionFlags::Xcoff { s_flags: xcoff::STYP_INFO as u32 }; - - let len = data.len() as u64; - let offset = file.append_section_data(section, &len.to_le_bytes(), 1); + // Encode string stored in .info section of XCOFF. + let len = data.len() as u32; + let offset = file.append_section_data(section, &len.to_be_bytes(), 1); // Add a symbol referring to the data in .info section. file.add_symbol(Symbol { name: AIX_METADATA_SYMBOL_NAME.into(), @@ -599,12 +600,12 @@ pub fn create_compressed_metadata_file_for_xcoff( section: SymbolSection::Section(data_section), flags: SymbolFlags::None, }); - let len = data.len() as u64; - let offset = file.append_section_data(section, &len.to_le_bytes(), 1); + let len = data.len() as u32; + let offset = file.append_section_data(section, &len.to_be_bytes(), 1); // Add a symbol referring to the rustc metadata. file.add_symbol(Symbol { name: AIX_METADATA_SYMBOL_NAME.into(), - value: offset + 8, // The metadata is preceded by a 8-byte length field. + value: offset + 4, // The metadata is preceded by a 4-byte length field. size: 0, kind: SymbolKind::Unknown, scope: SymbolScope::Dynamic, From ce9a02eaac80ad5f4843dd93228e72f04ec1cb4c Mon Sep 17 00:00:00 2001 From: Kai Luo Date: Thu, 14 Dec 2023 10:31:07 +0800 Subject: [PATCH 2/9] Address comment --- compiler/rustc_codegen_ssa/src/back/metadata.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_codegen_ssa/src/back/metadata.rs b/compiler/rustc_codegen_ssa/src/back/metadata.rs index d8550428984..06ef0be4615 100644 --- a/compiler/rustc_codegen_ssa/src/back/metadata.rs +++ b/compiler/rustc_codegen_ssa/src/back/metadata.rs @@ -159,7 +159,7 @@ pub(super) fn get_metadata_xcoff<'a>(path: &Path, data: &'a [u8]) -> Result<&'a { let offset = metadata_symbol.address() as usize; // The offset specifies the location of rustc metadata in the .info section of XCOFF. - // Each string stored in .info section of XCOFF is preceded by a 4-byte lenght field. + // Each string stored in .info section of XCOFF is preceded by a 4-byte length field. if offset < 4 { return Err(format!("Invalid metadata symbol offset: {offset}")); } @@ -480,7 +480,10 @@ pub fn create_wrapper_file( file.section_mut(section).flags = SectionFlags::Xcoff { s_flags: xcoff::STYP_INFO as u32 }; // Encode string stored in .info section of XCOFF. - let len = data.len() as u32; + // FIXME: The length of data here is not guaranteed to fit in a u32. + // We may have to split the data into multiple pieces in order to + // store in .info section. + let len: u32 = data.len().try_into().unwrap(); let offset = file.append_section_data(section, &len.to_be_bytes(), 1); // Add a symbol referring to the data in .info section. file.add_symbol(Symbol { From 663bea5a96e5284bf03b61c784030a9be700ffbc Mon Sep 17 00:00:00 2001 From: Ross Smyth Date: Thu, 14 Dec 2023 23:31:36 -0500 Subject: [PATCH 3/9] Add better ICE messages for some undescriptive panics --- compiler/rustc_ast_lowering/src/path.rs | 5 ++++- compiler/rustc_ast_pretty/src/pprust/state.rs | 4 +++- compiler/rustc_span/src/caching_source_map_view.rs | 6 ++++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/compiler/rustc_ast_lowering/src/path.rs b/compiler/rustc_ast_lowering/src/path.rs index efd80af5ef4..cdedae6cff8 100644 --- a/compiler/rustc_ast_lowering/src/path.rs +++ b/compiler/rustc_ast_lowering/src/path.rs @@ -9,6 +9,7 @@ use rustc_ast::{self as ast, *}; use rustc_hir as hir; use rustc_hir::def::{DefKind, PartialRes, Res}; use rustc_hir::GenericArg; +use rustc_middle::span_bug; use rustc_span::symbol::{kw, sym, Ident}; use rustc_span::{BytePos, Span, DUMMY_SP}; @@ -285,7 +286,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { let (start, end) = match self.resolver.get_lifetime_res(segment_id) { Some(LifetimeRes::ElidedAnchor { start, end }) => (start, end), None => return, - Some(_) => panic!(), + Some(res) => { + span_bug!(path_span, "expected an elided lifetime to insert. found {res:?}") + } }; let expected_lifetimes = end.as_usize() - start.as_usize(); debug!(expected_lifetimes); diff --git a/compiler/rustc_ast_pretty/src/pprust/state.rs b/compiler/rustc_ast_pretty/src/pprust/state.rs index 4a2a693862b..d6c15ec35b6 100644 --- a/compiler/rustc_ast_pretty/src/pprust/state.rs +++ b/compiler/rustc_ast_pretty/src/pprust/state.rs @@ -1597,7 +1597,9 @@ impl<'a> State<'a> { } match bound { ast::GenericBound::Outlives(lt) => self.print_lifetime(*lt), - _ => panic!(), + _ => { + panic!("expected a lifetime bound, found a trait bound") + } } } } diff --git a/compiler/rustc_span/src/caching_source_map_view.rs b/compiler/rustc_span/src/caching_source_map_view.rs index fbfc5c22fcb..4c7029c4e52 100644 --- a/compiler/rustc_span/src/caching_source_map_view.rs +++ b/compiler/rustc_span/src/caching_source_map_view.rs @@ -117,7 +117,7 @@ impl<'sm> CachingSourceMapView<'sm> { self.time_stamp += 1; // Check if lo and hi are in the cached lines. - let lo_cache_idx = self.cache_entry_index(span_data.lo); + let lo_cache_idx: isize = self.cache_entry_index(span_data.lo); let hi_cache_idx = self.cache_entry_index(span_data.hi); if lo_cache_idx != -1 && hi_cache_idx != -1 { @@ -205,7 +205,9 @@ impl<'sm> CachingSourceMapView<'sm> { (lo_cache_idx as usize, oldest) } _ => { - panic!(); + panic!( + "the case of neither value being equal to -1 was handled above and the function returns." + ); } }; From dfa6441354181ad829baca363b619d0aeb295798 Mon Sep 17 00:00:00 2001 From: Zalathar Date: Tue, 12 Dec 2023 13:18:15 +1100 Subject: [PATCH 4/9] coverage: Skip instrumenting a function if no spans were extracted --- compiler/rustc_mir_transform/src/coverage/mod.rs | 7 +++++-- compiler/rustc_mir_transform/src/coverage/spans.rs | 12 ++++++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/compiler/rustc_mir_transform/src/coverage/mod.rs b/compiler/rustc_mir_transform/src/coverage/mod.rs index 65a0924f1c9..709d1fdc21a 100644 --- a/compiler/rustc_mir_transform/src/coverage/mod.rs +++ b/compiler/rustc_mir_transform/src/coverage/mod.rs @@ -99,12 +99,15 @@ impl<'a, 'tcx> Instrumentor<'a, 'tcx> { fn inject_counters(&'a mut self) { //////////////////////////////////////////////////// // Compute coverage spans from the `CoverageGraph`. - let coverage_spans = CoverageSpans::generate_coverage_spans( + let Some(coverage_spans) = CoverageSpans::generate_coverage_spans( self.mir_body, self.fn_sig_span, self.body_span, &self.basic_coverage_blocks, - ); + ) else { + // No relevant spans were found in MIR, so skip instrumenting this function. + return; + }; //////////////////////////////////////////////////// // Create an optimized mix of `Counter`s and `Expression`s for the `CoverageGraph`. Ensure diff --git a/compiler/rustc_mir_transform/src/coverage/spans.rs b/compiler/rustc_mir_transform/src/coverage/spans.rs index 05ad14f1525..462e54c386c 100644 --- a/compiler/rustc_mir_transform/src/coverage/spans.rs +++ b/compiler/rustc_mir_transform/src/coverage/spans.rs @@ -15,12 +15,16 @@ pub(super) struct CoverageSpans { } impl CoverageSpans { + /// Extracts coverage-relevant spans from MIR, and associates them with + /// their corresponding BCBs. + /// + /// Returns `None` if no coverage-relevant spans could be extracted. pub(super) fn generate_coverage_spans( mir_body: &mir::Body<'_>, fn_sig_span: Span, body_span: Span, basic_coverage_blocks: &CoverageGraph, - ) -> Self { + ) -> Option { let coverage_spans = CoverageSpansGenerator::generate_coverage_spans( mir_body, fn_sig_span, @@ -28,13 +32,17 @@ impl CoverageSpans { basic_coverage_blocks, ); + if coverage_spans.is_empty() { + return None; + } + // Group the coverage spans by BCB, with the BCBs in sorted order. let mut bcb_to_spans = IndexVec::from_elem_n(Vec::new(), basic_coverage_blocks.num_nodes()); for CoverageSpan { bcb, span, .. } in coverage_spans { bcb_to_spans[bcb].push(span); } - Self { bcb_to_spans } + Some(Self { bcb_to_spans }) } pub(super) fn bcb_has_coverage_spans(&self, bcb: BasicCoverageBlock) -> bool { From c57f28bbf75572e10c6165c33a2aef922315fdb4 Mon Sep 17 00:00:00 2001 From: Zalathar Date: Tue, 12 Dec 2023 13:49:19 +1100 Subject: [PATCH 5/9] coverage: Avoid creating `func_coverage` for marker statements Coverage marker statements should have no effect on codegen, but in some cases they could have the side-effect of creating a `func_coverage` entry for their enclosing function. That can lead to an ICE for functions that don't actually have any coverage spans. --- .../rustc_codegen_llvm/src/coverageinfo/mod.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs b/compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs index 8386f067baf..0befbb5a39b 100644 --- a/compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs +++ b/compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs @@ -85,6 +85,14 @@ impl<'tcx> CoverageInfoBuilderMethods<'tcx> for Builder<'_, '_, 'tcx> { let bx = self; + match coverage.kind { + // Marker statements have no effect during codegen, + // so return early and don't create `func_coverage`. + CoverageKind::SpanMarker => return, + // Match exhaustively to ensure that newly-added kinds are classified correctly. + CoverageKind::CounterIncrement { .. } | CoverageKind::ExpressionUsed { .. } => {} + } + let Some(function_coverage_info) = bx.tcx.instance_mir(instance.def).function_coverage_info.as_deref() else { @@ -100,9 +108,9 @@ impl<'tcx> CoverageInfoBuilderMethods<'tcx> for Builder<'_, '_, 'tcx> { let Coverage { kind } = coverage; match *kind { - // Span markers are only meaningful during MIR instrumentation, - // and have no effect during codegen. - CoverageKind::SpanMarker => {} + CoverageKind::SpanMarker => unreachable!( + "unexpected marker statement {kind:?} should have caused an early return" + ), CoverageKind::CounterIncrement { id } => { func_coverage.mark_counter_id_seen(id); // We need to explicitly drop the `RefMut` before calling into `instrprof_increment`, From e0de1439708d72a319ca334ef1d3237a7a4a6800 Mon Sep 17 00:00:00 2001 From: Zalathar Date: Tue, 12 Dec 2023 12:55:40 +1100 Subject: [PATCH 6/9] coverage: Regression test for markers in a function with no spans --- tests/coverage/no_spans_if_not.cov-map | 8 +++++++ tests/coverage/no_spans_if_not.coverage | 30 +++++++++++++++++++++++++ tests/coverage/no_spans_if_not.rs | 29 ++++++++++++++++++++++++ 3 files changed, 67 insertions(+) create mode 100644 tests/coverage/no_spans_if_not.cov-map create mode 100644 tests/coverage/no_spans_if_not.coverage create mode 100644 tests/coverage/no_spans_if_not.rs diff --git a/tests/coverage/no_spans_if_not.cov-map b/tests/coverage/no_spans_if_not.cov-map new file mode 100644 index 00000000000..5277267ec1b --- /dev/null +++ b/tests/coverage/no_spans_if_not.cov-map @@ -0,0 +1,8 @@ +Function name: no_spans_if_not::main +Raw bytes (9): 0x[01, 01, 00, 01, 01, 0b, 01, 02, 02] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 0 +Number of file 0 mappings: 1 +- Code(Counter(0)) at (prev + 11, 1) to (start + 2, 2) + diff --git a/tests/coverage/no_spans_if_not.coverage b/tests/coverage/no_spans_if_not.coverage new file mode 100644 index 00000000000..1b6bbc75a04 --- /dev/null +++ b/tests/coverage/no_spans_if_not.coverage @@ -0,0 +1,30 @@ + LL| |// edition: 2021 + LL| | + LL| |// If the span extractor can't find any relevant spans for a function, + LL| |// but the function contains coverage span-marker statements (e.g. inserted + LL| |// for `if !`), coverage codegen may think that it is instrumented and + LL| |// consequently complain that it has no spans. + LL| |// + LL| |// Regression test for , + LL| |// "A used function should have had coverage mapping data but did not". + LL| | + LL| 1|fn main() { + LL| 1| affected_function(); + LL| 1|} + LL| | + LL| |macro_rules! macro_that_defines_a_function { + LL| | (fn $name:ident () $body:tt) => { + LL| | fn $name () $body + LL| | } + LL| |} + LL| | + LL| |macro_that_defines_a_function! { + LL| | fn affected_function() { + LL| | if !false { + LL| | () + LL| | } else { + LL| | () + LL| | } + LL| | } + LL| |} + diff --git a/tests/coverage/no_spans_if_not.rs b/tests/coverage/no_spans_if_not.rs new file mode 100644 index 00000000000..2bbdc11cd5e --- /dev/null +++ b/tests/coverage/no_spans_if_not.rs @@ -0,0 +1,29 @@ +// edition: 2021 + +// If the span extractor can't find any relevant spans for a function, +// but the function contains coverage span-marker statements (e.g. inserted +// for `if !`), coverage codegen may think that it is instrumented and +// consequently complain that it has no spans. +// +// Regression test for , +// "A used function should have had coverage mapping data but did not". + +fn main() { + affected_function(); +} + +macro_rules! macro_that_defines_a_function { + (fn $name:ident () $body:tt) => { + fn $name () $body + } +} + +macro_that_defines_a_function! { + fn affected_function() { + if !false { + () + } else { + () + } + } +} From e585b0ed58b8b5bd3dd3b549be7e7313bbd7ce25 Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Sun, 17 Dec 2023 17:54:20 +0000 Subject: [PATCH 7/9] Use FileEndOfFileInfo, not FileAllocationInfo This fixes WINE support --- library/std/src/sys/windows/fs.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/library/std/src/sys/windows/fs.rs b/library/std/src/sys/windows/fs.rs index 09dfb0caeec..42484543686 100644 --- a/library/std/src/sys/windows/fs.rs +++ b/library/std/src/sys/windows/fs.rs @@ -309,14 +309,16 @@ impl File { && unsafe { c::GetLastError() } == c::ERROR_ALREADY_EXISTS { unsafe { - // Setting the allocation size to zero also sets the - // EOF position to zero. - let alloc = c::FILE_ALLOCATION_INFO { AllocationSize: 0 }; + // This originally used `FileAllocationInfo` instead of + // `FileEndOfFileInfo` but that wasn't supported by WINE. + // It's arguable which fits the semantics of `OpenOptions` + // better so let's just use the more widely supported method. + let eof = c::FILE_END_OF_FILE_INFO { EndOfFile: 0 }; let result = c::SetFileInformationByHandle( handle.as_raw_handle(), - c::FileAllocationInfo, - ptr::addr_of!(alloc).cast::(), - mem::size_of::() as u32, + c::FileEndOfFileInfo, + ptr::addr_of!(eof).cast::(), + mem::size_of::() as u32, ); if result == 0 { return Err(io::Error::last_os_error()); From 4a5dd169f73d77429c592f96977ae5484f2cfad8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Le=C3=B3n=20Orell=20Valerian=20Liehr?= Date: Mon, 18 Dec 2023 01:10:16 +0100 Subject: [PATCH 8/9] Deny ~const trait bounds in inherent impl headers --- compiler/rustc_ast_passes/messages.ftl | 3 ++- compiler/rustc_ast_passes/src/ast_validation.rs | 12 ++++++++++-- compiler/rustc_ast_passes/src/errors.rs | 5 +++++ .../tilde-const-invalid-places.rs | 3 +++ .../tilde-const-invalid-places.stderr | 14 +++++++++++++- .../tilde_const_on_impl_bound.rs | 7 +++---- .../tilde_const_on_impl_bound.stderr | 12 ------------ 7 files changed, 36 insertions(+), 20 deletions(-) delete mode 100644 tests/ui/rfcs/rfc-2632-const-trait-impl/tilde_const_on_impl_bound.stderr diff --git a/compiler/rustc_ast_passes/messages.ftl b/compiler/rustc_ast_passes/messages.ftl index 28bd6c2111b..790b583134c 100644 --- a/compiler/rustc_ast_passes/messages.ftl +++ b/compiler/rustc_ast_passes/messages.ftl @@ -225,7 +225,8 @@ ast_passes_tilde_const_disallowed = `~const` is not allowed here .closure = closures cannot have `~const` trait bounds .function = this function is not `const`, so it cannot have `~const` trait bounds .trait = this trait is not a `#[const_trait]`, so it cannot have `~const` trait bounds - .impl = this impl is not `const`, so it cannot have `~const` trait bounds + .trait_impl = this impl is not `const`, so it cannot have `~const` trait bounds + .impl = inherent impls cannot have `~const` trait bounds .object = trait objects cannot have `~const` trait bounds .item = this item cannot have `~const` trait bounds diff --git a/compiler/rustc_ast_passes/src/ast_validation.rs b/compiler/rustc_ast_passes/src/ast_validation.rs index 59cf18c2459..326ac459c37 100644 --- a/compiler/rustc_ast_passes/src/ast_validation.rs +++ b/compiler/rustc_ast_passes/src/ast_validation.rs @@ -41,6 +41,7 @@ enum DisallowTildeConstContext<'a> { TraitObject, Fn(FnKind<'a>), Trait(Span), + TraitImpl(Span), Impl(Span), Item, } @@ -837,7 +838,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> { this.visit_vis(&item.vis); this.visit_ident(item.ident); let disallowed = matches!(constness, Const::No) - .then(|| DisallowTildeConstContext::Impl(item.span)); + .then(|| DisallowTildeConstContext::TraitImpl(item.span)); this.with_tilde_const(disallowed, |this| this.visit_generics(generics)); this.visit_trait_ref(t); this.visit_ty(self_ty); @@ -890,7 +891,9 @@ impl<'a> Visitor<'a> for AstValidator<'a> { self.visit_vis(&item.vis); self.visit_ident(item.ident); - self.with_tilde_const(None, |this| this.visit_generics(generics)); + self.with_tilde_const(Some(DisallowTildeConstContext::Impl(item.span)), |this| { + this.visit_generics(generics) + }); self.visit_ty(self_ty); walk_list!(self, visit_assoc_item, items, AssocCtxt::Impl); walk_list!(self, visit_attribute, &item.attrs); @@ -1216,7 +1219,12 @@ impl<'a> Visitor<'a> for AstValidator<'a> { &DisallowTildeConstContext::Trait(span) => { errors::TildeConstReason::Trait { span } } + &DisallowTildeConstContext::TraitImpl(span) => { + errors::TildeConstReason::TraitImpl { span } + } &DisallowTildeConstContext::Impl(span) => { + // FIXME(effects): Consider providing a help message or even a structured + // suggestion for moving such bounds to the assoc const fns if available. errors::TildeConstReason::Impl { span } } DisallowTildeConstContext::TraitObject => { diff --git a/compiler/rustc_ast_passes/src/errors.rs b/compiler/rustc_ast_passes/src/errors.rs index 928bf19759a..4283fc7c07d 100644 --- a/compiler/rustc_ast_passes/src/errors.rs +++ b/compiler/rustc_ast_passes/src/errors.rs @@ -563,6 +563,11 @@ pub enum TildeConstReason { #[primary_span] span: Span, }, + #[note(ast_passes_trait_impl)] + TraitImpl { + #[primary_span] + span: Span, + }, #[note(ast_passes_impl)] Impl { #[primary_span] diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/tilde-const-invalid-places.rs b/tests/ui/rfcs/rfc-2632-const-trait-impl/tilde-const-invalid-places.rs index bbe1194f7a3..5ecb75094f0 100644 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/tilde-const-invalid-places.rs +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/tilde-const-invalid-places.rs @@ -52,4 +52,7 @@ trait Child1 where Self: ~const Trait {} //~ ERROR `~const` is not allowed // non-const impl impl Trait for T {} //~ ERROR `~const` is not allowed +// inherent impl (regression test for issue #117004) +impl Struct {} //~ ERROR `~const` is not allowed + fn main() {} diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/tilde-const-invalid-places.stderr b/tests/ui/rfcs/rfc-2632-const-trait-impl/tilde-const-invalid-places.stderr index c6e18924fd8..497ec5bcf84 100644 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/tilde-const-invalid-places.stderr +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/tilde-const-invalid-places.stderr @@ -194,6 +194,18 @@ note: this impl is not `const`, so it cannot have `~const` trait bounds LL | impl Trait for T {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +error: `~const` is not allowed here + --> $DIR/tilde-const-invalid-places.rs:56:9 + | +LL | impl Struct {} + | ^^^^^^ + | +note: inherent impls cannot have `~const` trait bounds + --> $DIR/tilde-const-invalid-places.rs:56:1 + | +LL | impl Struct {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + error[E0658]: generic const items are experimental --> $DIR/tilde-const-invalid-places.rs:19:15 | @@ -239,6 +251,6 @@ LL | type Type = (); = note: see issue #8995 for more information = help: add `#![feature(inherent_associated_types)]` to the crate attributes to enable -error: aborting due to 26 previous errors +error: aborting due to 27 previous errors For more information about this error, try `rustc --explain E0658`. diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/tilde_const_on_impl_bound.rs b/tests/ui/rfcs/rfc-2632-const-trait-impl/tilde_const_on_impl_bound.rs index fbdc3a4f370..bfd9fe42e67 100644 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/tilde_const_on_impl_bound.rs +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/tilde_const_on_impl_bound.rs @@ -1,5 +1,4 @@ -// known-bug: #110395 -// FIXME check-pass +// check-pass #![feature(const_trait_impl, effects)] #[const_trait] @@ -9,8 +8,8 @@ trait Foo { struct Bar(T); -impl Bar { - const fn foo(&self) { +impl Bar { + const fn foo(&self) where T: ~const Foo { self.0.foo() } } diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/tilde_const_on_impl_bound.stderr b/tests/ui/rfcs/rfc-2632-const-trait-impl/tilde_const_on_impl_bound.stderr deleted file mode 100644 index 0925bfa7e57..00000000000 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/tilde_const_on_impl_bound.stderr +++ /dev/null @@ -1,12 +0,0 @@ -error[E0308]: mismatched types - --> $DIR/tilde_const_on_impl_bound.rs:14:9 - | -LL | self.0.foo() - | ^^^^^^^^^^^^ expected `host`, found `true` - | - = note: expected constant `host` - found constant `true` - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0308`. From a8e1da317104cf33b9485be29c10da57c648b873 Mon Sep 17 00:00:00 2001 From: Kai Luo Date: Mon, 18 Dec 2023 09:41:36 +0800 Subject: [PATCH 9/9] Address comment --- compiler/rustc_codegen_ssa/src/back/metadata.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_codegen_ssa/src/back/metadata.rs b/compiler/rustc_codegen_ssa/src/back/metadata.rs index 06ef0be4615..b683e1b45a8 100644 --- a/compiler/rustc_codegen_ssa/src/back/metadata.rs +++ b/compiler/rustc_codegen_ssa/src/back/metadata.rs @@ -603,7 +603,7 @@ pub fn create_compressed_metadata_file_for_xcoff( section: SymbolSection::Section(data_section), flags: SymbolFlags::None, }); - let len = data.len() as u32; + let len: u32 = data.len().try_into().unwrap(); let offset = file.append_section_data(section, &len.to_be_bytes(), 1); // Add a symbol referring to the rustc metadata. file.add_symbol(Symbol {