From df0df5256b95023e1e5e6bc49ee3857d90d91555 Mon Sep 17 00:00:00 2001 From: Zalathar Date: Thu, 28 Dec 2023 15:08:24 +1100 Subject: coverage: Overhaul how "visible macros" are determined --- tests/coverage/inline-dead.cov-map | 4 ++-- tests/coverage/inline-dead.coverage | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/coverage/inline-dead.cov-map b/tests/coverage/inline-dead.cov-map index 958b423f24c..ab04e746b91 100644 --- a/tests/coverage/inline-dead.cov-map +++ b/tests/coverage/inline-dead.cov-map @@ -31,14 +31,14 @@ Number of file 0 mappings: 2 - Code(Counter(0)) at (prev + 7, 6) to (start + 2, 2) Function name: inline_dead::main::{closure#0} -Raw bytes (23): 0x[01, 01, 02, 00, 06, 01, 00, 03, 01, 07, 17, 00, 18, 00, 02, 0d, 00, 0e, 03, 02, 05, 00, 06] +Raw bytes (23): 0x[01, 01, 02, 00, 06, 01, 00, 03, 01, 07, 17, 01, 16, 00, 02, 0d, 00, 0e, 03, 02, 05, 00, 06] Number of files: 1 - file 0 => global file 1 Number of expressions: 2 - expression 0 operands: lhs = Zero, rhs = Expression(1, Sub) - expression 1 operands: lhs = Counter(0), rhs = Zero Number of file 0 mappings: 3 -- Code(Counter(0)) at (prev + 7, 23) to (start + 0, 24) +- Code(Counter(0)) at (prev + 7, 23) to (start + 1, 22) - Code(Zero) at (prev + 2, 13) to (start + 0, 14) - Code(Expression(0, Add)) at (prev + 2, 5) to (start + 0, 6) = (Zero + (c0 - Zero)) diff --git a/tests/coverage/inline-dead.coverage b/tests/coverage/inline-dead.coverage index de96aa17acd..7c201f482db 100644 --- a/tests/coverage/inline-dead.coverage +++ b/tests/coverage/inline-dead.coverage @@ -5,7 +5,7 @@ LL| 1| println!("{}", live::()); LL| 1| LL| 1| let f = |x: bool| { - LL| | debug_assert!( + LL| 1| debug_assert!( LL| 0| x LL| | ); LL| 1| }; -- cgit 1.4.1-3-g733a5 From d4d2f1428cda381fe0c0d58700ead551fdf96f6b Mon Sep 17 00:00:00 2001 From: Zalathar Date: Fri, 22 Dec 2023 11:21:52 +1100 Subject: coverage: Hoist the splitting of visible macro invocations --- compiler/rustc_mir_transform/src/coverage/spans.rs | 34 ------------------ .../src/coverage/spans/from_mir.rs | 36 +++++++++++++++++++ tests/coverage/closure.cov-map | 42 ++++++++++------------ 3 files changed, 54 insertions(+), 58 deletions(-) (limited to 'tests') diff --git a/compiler/rustc_mir_transform/src/coverage/spans.rs b/compiler/rustc_mir_transform/src/coverage/spans.rs index 576f098e6e4..f346aa1810c 100644 --- a/compiler/rustc_mir_transform/src/coverage/spans.rs +++ b/compiler/rustc_mir_transform/src/coverage/spans.rs @@ -220,7 +220,6 @@ impl<'a> CoverageSpansGenerator<'a> { // span-processing steps don't make sense yet. if self.some_prev.is_none() { debug!(" initial span"); - self.maybe_push_macro_name_span(); continue; } @@ -232,7 +231,6 @@ impl<'a> CoverageSpansGenerator<'a> { debug!(" same bcb (and neither is a closure), merge with prev={prev:?}"); let prev = self.take_prev(); self.curr_mut().merge_from(&prev); - self.maybe_push_macro_name_span(); // Note that curr.span may now differ from curr_original_span } else if prev.span.hi() <= curr.span.lo() { debug!( @@ -240,7 +238,6 @@ impl<'a> CoverageSpansGenerator<'a> { ); let prev = self.take_prev(); self.refined_spans.push(prev); - self.maybe_push_macro_name_span(); } else if prev.is_closure { // drop any equal or overlapping span (`curr`) and keep `prev` to test again in the // next iter @@ -256,7 +253,6 @@ impl<'a> CoverageSpansGenerator<'a> { self.update_pending_dups(); } else { self.cutoff_prev_at_overlapping_curr(); - self.maybe_push_macro_name_span(); } } @@ -291,36 +287,6 @@ impl<'a> CoverageSpansGenerator<'a> { self.refined_spans } - /// If `curr` is part of a new macro expansion, carve out and push a separate - /// span that ends just after the macro name and its subsequent `!`. - fn maybe_push_macro_name_span(&mut self) { - let curr = self.curr(); - - let Some(visible_macro) = curr.visible_macro else { return }; - - // The split point is relative to `curr_original_span`, - // because `curr.span` may have been merged with preceding spans. - let split_point_after_macro_bang = self.curr_original_span.lo() - + BytePos(visible_macro.as_str().len() as u32) - + BytePos(1); // add 1 for the `!` - debug_assert!(split_point_after_macro_bang <= curr.span.hi()); - if split_point_after_macro_bang > curr.span.hi() { - // Something is wrong with the macro name span; - // return now to avoid emitting malformed mappings (e.g. #117788). - return; - } - - let mut macro_name_cov = curr.clone(); - macro_name_cov.span = macro_name_cov.span.with_hi(split_point_after_macro_bang); - self.curr_mut().span = curr.span.with_lo(split_point_after_macro_bang); - - debug!( - " and curr starts a new macro expansion, so add a new span just for \ - the macro `{visible_macro}!`, new span={macro_name_cov:?}", - ); - self.refined_spans.push(macro_name_cov); - } - #[track_caller] fn curr(&self) -> &CoverageSpan { self.some_curr.as_ref().unwrap_or_else(|| bug!("some_curr is None (curr)")) diff --git a/compiler/rustc_mir_transform/src/coverage/spans/from_mir.rs b/compiler/rustc_mir_transform/src/coverage/spans/from_mir.rs index b28abcf71d5..637424753d9 100644 --- a/compiler/rustc_mir_transform/src/coverage/spans/from_mir.rs +++ b/compiler/rustc_mir_transform/src/coverage/spans/from_mir.rs @@ -38,6 +38,7 @@ pub(super) fn mir_to_initial_sorted_coverage_spans( initial_spans.sort_by(|a, b| basic_coverage_blocks.cmp_in_dominator_order(a.bcb, b.bcb)); remove_unwanted_macro_spans(&mut initial_spans); + split_visible_macro_spans(&mut initial_spans); initial_spans.sort_by(|a, b| { // First sort by span start. @@ -79,6 +80,41 @@ fn remove_unwanted_macro_spans(initial_spans: &mut Vec) { }); } +/// When a span corresponds to a macro invocation that is visible from the +/// function body, split it into two parts. The first part covers just the +/// macro name plus `!`, and the second part covers the rest of the macro +/// invocation. This seems to give better results for code that uses macros. +fn split_visible_macro_spans(initial_spans: &mut Vec) { + let mut extra_spans = vec![]; + + initial_spans.retain(|covspan| { + if covspan.is_closure { + return true; + } + + let Some(visible_macro) = covspan.visible_macro else { return true }; + + let split_len = visible_macro.as_str().len() as u32 + 1; + let (before, after) = covspan.span.split_at(split_len); + if !covspan.span.contains(before) || !covspan.span.contains(after) { + // Something is unexpectedly wrong with the split point. + // The debug assertion in `split_at` will have already caught this, + // but in release builds it's safer to do nothing and maybe get a + // bug report for unexpected coverage, rather than risk an ICE. + return true; + } + + assert!(!covspan.is_closure); + extra_spans.push(CoverageSpan::new(before, covspan.visible_macro, covspan.bcb, false)); + extra_spans.push(CoverageSpan::new(after, covspan.visible_macro, covspan.bcb, false)); + false // Discard the original covspan that we just split. + }); + + // The newly-split spans are added at the end, so any previous sorting + // is not preserved. + initial_spans.extend(extra_spans); +} + // Generate a set of `CoverageSpan`s from the filtered set of `Statement`s and `Terminator`s of // the `BasicBlock`(s) in the given `BasicCoverageBlockData`. One `CoverageSpan` is generated // for each `Statement` and `Terminator`. (Note that subsequent stages of coverage analysis will diff --git a/tests/coverage/closure.cov-map b/tests/coverage/closure.cov-map index 522c1e73afe..c5ac17600cd 100644 --- a/tests/coverage/closure.cov-map +++ b/tests/coverage/closure.cov-map @@ -81,21 +81,18 @@ Number of file 0 mappings: 1 - Code(Zero) at (prev + 171, 13) to (start + 2, 14) Function name: closure::main::{closure#14} -Raw bytes (36): 0x[01, 01, 03, 05, 0a, 01, 05, 01, 05, 05, 03, b2, 01, 0d, 00, 15, 01, 01, 11, 01, 1b, 05, 01, 1e, 00, 25, 0a, 00, 2f, 00, 33, 03, 01, 0d, 00, 0e] +Raw bytes (29): 0x[01, 01, 02, 01, 05, 05, 02, 04, 01, b2, 01, 0d, 02, 1b, 05, 02, 1e, 00, 25, 02, 00, 2f, 00, 33, 07, 01, 0d, 00, 0e] Number of files: 1 - file 0 => global file 1 -Number of expressions: 3 -- expression 0 operands: lhs = Counter(1), rhs = Expression(2, Sub) -- expression 1 operands: lhs = Counter(0), rhs = Counter(1) -- expression 2 operands: lhs = Counter(0), rhs = Counter(1) -Number of file 0 mappings: 5 -- Code(Expression(0, Add)) at (prev + 178, 13) to (start + 0, 21) - = (c1 + (c0 - c1)) -- Code(Counter(0)) at (prev + 1, 17) to (start + 1, 27) -- Code(Counter(1)) at (prev + 1, 30) to (start + 0, 37) -- Code(Expression(2, Sub)) at (prev + 0, 47) to (start + 0, 51) +Number of expressions: 2 +- expression 0 operands: lhs = Counter(0), rhs = Counter(1) +- expression 1 operands: lhs = Counter(1), rhs = Expression(0, Sub) +Number of file 0 mappings: 4 +- Code(Counter(0)) at (prev + 178, 13) to (start + 2, 27) +- Code(Counter(1)) at (prev + 2, 30) to (start + 0, 37) +- Code(Expression(0, Sub)) at (prev + 0, 47) to (start + 0, 51) = (c0 - c1) -- Code(Expression(0, Add)) at (prev + 1, 13) to (start + 0, 14) +- Code(Expression(1, Add)) at (prev + 1, 13) to (start + 0, 14) = (c1 + (c0 - c1)) Function name: closure::main::{closure#15} @@ -118,21 +115,18 @@ Number of file 0 mappings: 6 = (c1 + (c0 - c1)) Function name: closure::main::{closure#16} -Raw bytes (36): 0x[01, 01, 03, 05, 0a, 01, 05, 01, 05, 05, 03, c4, 01, 0d, 00, 15, 01, 01, 11, 01, 1b, 05, 01, 1e, 00, 25, 0a, 00, 2f, 00, 33, 03, 01, 0d, 00, 0e] +Raw bytes (29): 0x[01, 01, 02, 01, 05, 05, 02, 04, 01, c4, 01, 0d, 02, 1b, 05, 02, 1e, 00, 25, 02, 00, 2f, 00, 33, 07, 01, 0d, 00, 0e] Number of files: 1 - file 0 => global file 1 -Number of expressions: 3 -- expression 0 operands: lhs = Counter(1), rhs = Expression(2, Sub) -- expression 1 operands: lhs = Counter(0), rhs = Counter(1) -- expression 2 operands: lhs = Counter(0), rhs = Counter(1) -Number of file 0 mappings: 5 -- Code(Expression(0, Add)) at (prev + 196, 13) to (start + 0, 21) - = (c1 + (c0 - c1)) -- Code(Counter(0)) at (prev + 1, 17) to (start + 1, 27) -- Code(Counter(1)) at (prev + 1, 30) to (start + 0, 37) -- Code(Expression(2, Sub)) at (prev + 0, 47) to (start + 0, 51) +Number of expressions: 2 +- expression 0 operands: lhs = Counter(0), rhs = Counter(1) +- expression 1 operands: lhs = Counter(1), rhs = Expression(0, Sub) +Number of file 0 mappings: 4 +- Code(Counter(0)) at (prev + 196, 13) to (start + 2, 27) +- Code(Counter(1)) at (prev + 2, 30) to (start + 0, 37) +- Code(Expression(0, Sub)) at (prev + 0, 47) to (start + 0, 51) = (c0 - c1) -- Code(Expression(0, Add)) at (prev + 1, 13) to (start + 0, 14) +- Code(Expression(1, Add)) at (prev + 1, 13) to (start + 0, 14) = (c1 + (c0 - c1)) Function name: closure::main::{closure#17} -- cgit 1.4.1-3-g733a5 From 2c3aeea1baf4eed29f131f53e852532d8e3833c3 Mon Sep 17 00:00:00 2001 From: Georg Semmler Date: Fri, 22 Dec 2023 14:30:12 +0100 Subject: Replace some usage of `#[rustc_on_unimplemented]` with `#[diagnostic::on_unimplemented]` This commit replaces those `#[rustc_on_unimplemented]` attributes with their equivalent `#[diagnostic::on_unimplemented]` where this is supported (So no filter or any extended option) --- library/core/src/future/future.rs | 2 +- library/core/src/lib.rs | 1 + library/core/src/marker.rs | 16 ++++++++-------- library/core/src/ops/arith.rs | 16 ++++++++-------- library/core/src/ops/bit.rs | 20 ++++++++++---------- library/core/src/ops/index.rs | 2 +- library/core/src/panic/unwind_safe.rs | 4 ++-- tests/ui/proc-macro/meta-macro-hygiene.stdout | 3 +++ tests/ui/proc-macro/nonterminal-token-hygiene.stdout | 3 +++ 9 files changed, 37 insertions(+), 30 deletions(-) (limited to 'tests') diff --git a/library/core/src/future/future.rs b/library/core/src/future/future.rs index 71b9464efd2..af2e422e8a0 100644 --- a/library/core/src/future/future.rs +++ b/library/core/src/future/future.rs @@ -28,7 +28,7 @@ use crate::task::{Context, Poll}; #[must_use = "futures do nothing unless you `.await` or poll them"] #[stable(feature = "futures_api", since = "1.36.0")] #[lang = "future_trait"] -#[rustc_on_unimplemented( +#[diagnostic::on_unimplemented( label = "`{Self}` is not a future", message = "`{Self}` is not a future", note = "{Self} must be a future or must implement `IntoFuture` to be awaited" diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs index 07720f23598..9f8ae7a09f0 100644 --- a/library/core/src/lib.rs +++ b/library/core/src/lib.rs @@ -218,6 +218,7 @@ #![feature(const_trait_impl)] #![feature(decl_macro)] #![feature(deprecated_suggestion)] +#![feature(diagnostic_namespace)] #![feature(doc_cfg)] #![feature(doc_cfg_hide)] #![feature(doc_notable_trait)] diff --git a/library/core/src/marker.rs b/library/core/src/marker.rs index 99762bccd18..69d54f06407 100644 --- a/library/core/src/marker.rs +++ b/library/core/src/marker.rs @@ -75,7 +75,7 @@ macro marker_impls { /// [ub]: ../../reference/behavior-considered-undefined.html #[stable(feature = "rust1", since = "1.0.0")] #[cfg_attr(not(test), rustc_diagnostic_item = "Send")] -#[rustc_on_unimplemented( +#[diagnostic::on_unimplemented( message = "`{Self}` cannot be sent between threads safely", label = "`{Self}` cannot be sent between threads safely" )] @@ -134,7 +134,7 @@ unsafe impl Send for &T {} #[doc(alias = "?", alias = "?Sized")] #[stable(feature = "rust1", since = "1.0.0")] #[lang = "sized"] -#[rustc_on_unimplemented( +#[diagnostic::on_unimplemented( message = "the size for values of type `{Self}` cannot be known at compilation time", label = "doesn't have a size known at compile-time" )] @@ -205,7 +205,7 @@ pub trait Unsize { /// [RFC1445]: https://github.com/rust-lang/rfcs/blob/master/text/1445-restrict-constants-in-patterns.md /// [issue 63438]: https://github.com/rust-lang/rust/issues/63438 #[unstable(feature = "structural_match", issue = "31434")] -#[rustc_on_unimplemented(message = "the type `{Self}` does not `#[derive(PartialEq)]`")] +#[diagnostic::on_unimplemented(message = "the type `{Self}` does not `#[derive(PartialEq)]`")] #[lang = "structural_peq"] pub trait StructuralPartialEq { // Empty. @@ -273,7 +273,7 @@ marker_impls! { /// of the two derives (`#[derive(PartialEq)]` and `#[derive(Eq)]`) and check /// that both of them are present as part of structural-match checking. #[unstable(feature = "structural_match", issue = "31434")] -#[rustc_on_unimplemented(message = "the type `{Self}` does not `#[derive(Eq)]`")] +#[diagnostic::on_unimplemented(message = "the type `{Self}` does not `#[derive(Eq)]`")] #[lang = "structural_teq"] pub trait StructuralEq { // Empty. @@ -941,7 +941,7 @@ marker_impls! { /// [Pin]: crate::pin::Pin /// [`pin` module]: crate::pin #[stable(feature = "pin", since = "1.33.0")] -#[rustc_on_unimplemented( +#[diagnostic::on_unimplemented( note = "consider using the `pin!` macro\nconsider using `Box::pin` if you need to access the pinned value outside of the current scope", message = "`{Self}` cannot be unpinned" )] @@ -989,7 +989,7 @@ pub trait Destruct {} /// for any user type. #[unstable(feature = "tuple_trait", issue = "none")] #[lang = "tuple_trait"] -#[rustc_on_unimplemented(message = "`{Self}` is not a tuple")] +#[diagnostic::on_unimplemented(message = "`{Self}` is not a tuple")] #[rustc_deny_explicit_impl(implement_via_object = false)] pub trait Tuple {} @@ -999,7 +999,7 @@ pub trait Tuple {} /// `*const ()` automatically implement this trait. #[unstable(feature = "pointer_like_trait", issue = "none")] #[lang = "pointer_like"] -#[rustc_on_unimplemented( +#[diagnostic::on_unimplemented( message = "`{Self}` needs to have the same ABI as a pointer", label = "`{Self}` needs to be a pointer-like type" )] @@ -1013,7 +1013,7 @@ pub trait PointerLike {} /// are `StructuralPartialEq`. #[lang = "const_param_ty"] #[unstable(feature = "adt_const_params", issue = "95174")] -#[rustc_on_unimplemented(message = "`{Self}` can't be used as a const parameter type")] +#[diagnostic::on_unimplemented(message = "`{Self}` can't be used as a const parameter type")] #[allow(multiple_supertrait_upcastable)] pub trait ConstParamTy: StructuralEq + StructuralPartialEq + Eq {} diff --git a/library/core/src/ops/arith.rs b/library/core/src/ops/arith.rs index 1773fdbf37c..bb3cdde66d1 100644 --- a/library/core/src/ops/arith.rs +++ b/library/core/src/ops/arith.rs @@ -307,7 +307,7 @@ sub_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f32 f64 } /// ``` #[lang = "mul"] #[stable(feature = "rust1", since = "1.0.0")] -#[rustc_on_unimplemented( +#[diagnostic::on_unimplemented( message = "cannot multiply `{Self}` by `{Rhs}`", label = "no implementation for `{Self} * {Rhs}`" )] @@ -441,7 +441,7 @@ mul_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f32 f64 } /// ``` #[lang = "div"] #[stable(feature = "rust1", since = "1.0.0")] -#[rustc_on_unimplemented( +#[diagnostic::on_unimplemented( message = "cannot divide `{Self}` by `{Rhs}`", label = "no implementation for `{Self} / {Rhs}`" )] @@ -543,7 +543,7 @@ div_impl_float! { f32 f64 } /// ``` #[lang = "rem"] #[stable(feature = "rust1", since = "1.0.0")] -#[rustc_on_unimplemented( +#[diagnostic::on_unimplemented( message = "cannot calculate the remainder of `{Self}` divided by `{Rhs}`", label = "no implementation for `{Self} % {Rhs}`" )] @@ -729,7 +729,7 @@ neg_impl! { isize i8 i16 i32 i64 i128 f32 f64 } /// ``` #[lang = "add_assign"] #[stable(feature = "op_assign_traits", since = "1.8.0")] -#[rustc_on_unimplemented( +#[diagnostic::on_unimplemented( message = "cannot add-assign `{Rhs}` to `{Self}`", label = "no implementation for `{Self} += {Rhs}`" )] @@ -796,7 +796,7 @@ add_assign_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f32 f64 } /// ``` #[lang = "sub_assign"] #[stable(feature = "op_assign_traits", since = "1.8.0")] -#[rustc_on_unimplemented( +#[diagnostic::on_unimplemented( message = "cannot subtract-assign `{Rhs}` from `{Self}`", label = "no implementation for `{Self} -= {Rhs}`" )] @@ -854,7 +854,7 @@ sub_assign_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f32 f64 } /// ``` #[lang = "mul_assign"] #[stable(feature = "op_assign_traits", since = "1.8.0")] -#[rustc_on_unimplemented( +#[diagnostic::on_unimplemented( message = "cannot multiply-assign `{Self}` by `{Rhs}`", label = "no implementation for `{Self} *= {Rhs}`" )] @@ -912,7 +912,7 @@ mul_assign_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f32 f64 } /// ``` #[lang = "div_assign"] #[stable(feature = "op_assign_traits", since = "1.8.0")] -#[rustc_on_unimplemented( +#[diagnostic::on_unimplemented( message = "cannot divide-assign `{Self}` by `{Rhs}`", label = "no implementation for `{Self} /= {Rhs}`" )] @@ -973,7 +973,7 @@ div_assign_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f32 f64 } /// ``` #[lang = "rem_assign"] #[stable(feature = "op_assign_traits", since = "1.8.0")] -#[rustc_on_unimplemented( +#[diagnostic::on_unimplemented( message = "cannot calculate and assign the remainder of `{Self}` divided by `{Rhs}`", label = "no implementation for `{Self} %= {Rhs}`" )] diff --git a/library/core/src/ops/bit.rs b/library/core/src/ops/bit.rs index c70f4a3da2e..6984100e498 100644 --- a/library/core/src/ops/bit.rs +++ b/library/core/src/ops/bit.rs @@ -137,7 +137,7 @@ impl Not for ! { #[lang = "bitand"] #[doc(alias = "&")] #[stable(feature = "rust1", since = "1.0.0")] -#[rustc_on_unimplemented( +#[diagnostic::on_unimplemented( message = "no implementation for `{Self} & {Rhs}`", label = "no implementation for `{Self} & {Rhs}`" )] @@ -237,7 +237,7 @@ bitand_impl! { bool usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 } #[lang = "bitor"] #[doc(alias = "|")] #[stable(feature = "rust1", since = "1.0.0")] -#[rustc_on_unimplemented( +#[diagnostic::on_unimplemented( message = "no implementation for `{Self} | {Rhs}`", label = "no implementation for `{Self} | {Rhs}`" )] @@ -337,7 +337,7 @@ bitor_impl! { bool usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 } #[lang = "bitxor"] #[doc(alias = "^")] #[stable(feature = "rust1", since = "1.0.0")] -#[rustc_on_unimplemented( +#[diagnostic::on_unimplemented( message = "no implementation for `{Self} ^ {Rhs}`", label = "no implementation for `{Self} ^ {Rhs}`" )] @@ -436,7 +436,7 @@ bitxor_impl! { bool usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 } #[lang = "shl"] #[doc(alias = "<<")] #[stable(feature = "rust1", since = "1.0.0")] -#[rustc_on_unimplemented( +#[diagnostic::on_unimplemented( message = "no implementation for `{Self} << {Rhs}`", label = "no implementation for `{Self} << {Rhs}`" )] @@ -554,7 +554,7 @@ shl_impl_all! { u8 u16 u32 u64 u128 usize i8 i16 i32 i64 isize i128 } #[lang = "shr"] #[doc(alias = ">>")] #[stable(feature = "rust1", since = "1.0.0")] -#[rustc_on_unimplemented( +#[diagnostic::on_unimplemented( message = "no implementation for `{Self} >> {Rhs}`", label = "no implementation for `{Self} >> {Rhs}`" )] @@ -681,7 +681,7 @@ shr_impl_all! { u8 u16 u32 u64 u128 usize i8 i16 i32 i64 i128 isize } #[lang = "bitand_assign"] #[doc(alias = "&=")] #[stable(feature = "op_assign_traits", since = "1.8.0")] -#[rustc_on_unimplemented( +#[diagnostic::on_unimplemented( message = "no implementation for `{Self} &= {Rhs}`", label = "no implementation for `{Self} &= {Rhs}`" )] @@ -752,7 +752,7 @@ bitand_assign_impl! { bool usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 } #[lang = "bitor_assign"] #[doc(alias = "|=")] #[stable(feature = "op_assign_traits", since = "1.8.0")] -#[rustc_on_unimplemented( +#[diagnostic::on_unimplemented( message = "no implementation for `{Self} |= {Rhs}`", label = "no implementation for `{Self} |= {Rhs}`" )] @@ -823,7 +823,7 @@ bitor_assign_impl! { bool usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 } #[lang = "bitxor_assign"] #[doc(alias = "^=")] #[stable(feature = "op_assign_traits", since = "1.8.0")] -#[rustc_on_unimplemented( +#[diagnostic::on_unimplemented( message = "no implementation for `{Self} ^= {Rhs}`", label = "no implementation for `{Self} ^= {Rhs}`" )] @@ -892,7 +892,7 @@ bitxor_assign_impl! { bool usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 } #[lang = "shl_assign"] #[doc(alias = "<<=")] #[stable(feature = "op_assign_traits", since = "1.8.0")] -#[rustc_on_unimplemented( +#[diagnostic::on_unimplemented( message = "no implementation for `{Self} <<= {Rhs}`", label = "no implementation for `{Self} <<= {Rhs}`" )] @@ -974,7 +974,7 @@ shl_assign_impl_all! { u8 u16 u32 u64 u128 usize i8 i16 i32 i64 i128 isize } #[lang = "shr_assign"] #[doc(alias = ">>=")] #[stable(feature = "op_assign_traits", since = "1.8.0")] -#[rustc_on_unimplemented( +#[diagnostic::on_unimplemented( message = "no implementation for `{Self} >>= {Rhs}`", label = "no implementation for `{Self} >>= {Rhs}`" )] diff --git a/library/core/src/ops/index.rs b/library/core/src/ops/index.rs index 6ceee463729..37d9a28fb99 100644 --- a/library/core/src/ops/index.rs +++ b/library/core/src/ops/index.rs @@ -47,7 +47,7 @@ /// assert_eq!(nucleotide_count[Nucleotide::T], 12); /// ``` #[lang = "index"] -#[rustc_on_unimplemented( +#[diagnostic::on_unimplemented( message = "the type `{Self}` cannot be indexed by `{Idx}`", label = "`{Self}` cannot be indexed by `{Idx}`" )] diff --git a/library/core/src/panic/unwind_safe.rs b/library/core/src/panic/unwind_safe.rs index 6a53909a8f1..37859212c0e 100644 --- a/library/core/src/panic/unwind_safe.rs +++ b/library/core/src/panic/unwind_safe.rs @@ -83,7 +83,7 @@ use crate::task::{Context, Poll}; /// implemented for any closed over variables passed to `catch_unwind`. #[stable(feature = "catch_unwind", since = "1.9.0")] #[cfg_attr(not(test), rustc_diagnostic_item = "unwind_safe_trait")] -#[rustc_on_unimplemented( +#[diagnostic::on_unimplemented( message = "the type `{Self}` may not be safely transferred across an unwind boundary", label = "`{Self}` may not be safely transferred across an unwind boundary" )] @@ -99,7 +99,7 @@ pub auto trait UnwindSafe {} /// [`UnwindSafe`] trait, for more information see that documentation. #[stable(feature = "catch_unwind", since = "1.9.0")] #[cfg_attr(not(test), rustc_diagnostic_item = "ref_unwind_safe_trait")] -#[rustc_on_unimplemented( +#[diagnostic::on_unimplemented( message = "the type `{Self}` may contain interior mutability and a reference may not be safely \ transferrable across a catch_unwind boundary", label = "`{Self}` may contain interior mutability and a reference may not be safely \ diff --git a/tests/ui/proc-macro/meta-macro-hygiene.stdout b/tests/ui/proc-macro/meta-macro-hygiene.stdout index 6d10cc604c2..3672a3590fd 100644 --- a/tests/ui/proc-macro/meta-macro-hygiene.stdout +++ b/tests/ui/proc-macro/meta-macro-hygiene.stdout @@ -50,6 +50,9 @@ crate0::{{expn1}}: parent: crate0::{{expn0}}, call_site_ctxt: #0, def_site_ctxt: crate0::{{expn2}}: parent: crate0::{{expn0}}, call_site_ctxt: #0, def_site_ctxt: #0, kind: Macro(Bang, "produce_it") crate0::{{expn3}}: parent: crate0::{{expn2}}, call_site_ctxt: #3, def_site_ctxt: #0, kind: Macro(Bang, "meta_macro::print_def_site") crate0::{{expn4}}: parent: crate0::{{expn3}}, call_site_ctxt: #4, def_site_ctxt: #0, kind: Macro(Bang, "$crate::dummy") +crate1::{{expnNNN}}: parent: crate0::{{expn0}}, call_site_ctxt: #0, def_site_ctxt: #0, kind: Macro(Attr, "diagnostic::on_unimplemented") +crate1::{{expnNNN}}: parent: crate0::{{expn0}}, call_site_ctxt: #0, def_site_ctxt: #0, kind: Macro(Attr, "diagnostic::on_unimplemented") +crate1::{{expnNNN}}: parent: crate0::{{expn0}}, call_site_ctxt: #0, def_site_ctxt: #0, kind: Macro(Attr, "diagnostic::on_unimplemented") crate1::{{expnNNN}}: parent: crate0::{{expn0}}, call_site_ctxt: #0, def_site_ctxt: #0, kind: Macro(Attr, "derive") crate1::{{expnNNN}}: parent: crate0::{{expn0}}, call_site_ctxt: #0, def_site_ctxt: #0, kind: Macro(Attr, "derive") crate1::{{expnNNN}}: parent: crate0::{{expn0}}, call_site_ctxt: #0, def_site_ctxt: #0, kind: Macro(Bang, "include") diff --git a/tests/ui/proc-macro/nonterminal-token-hygiene.stdout b/tests/ui/proc-macro/nonterminal-token-hygiene.stdout index 5c70e780f74..d3c2c46ac75 100644 --- a/tests/ui/proc-macro/nonterminal-token-hygiene.stdout +++ b/tests/ui/proc-macro/nonterminal-token-hygiene.stdout @@ -73,6 +73,9 @@ crate0::{{expn1}}: parent: crate0::{{expn0}}, call_site_ctxt: #0, def_site_ctxt: crate0::{{expn2}}: parent: crate0::{{expn0}}, call_site_ctxt: #0, def_site_ctxt: #0, kind: Macro(Bang, "outer") crate0::{{expn3}}: parent: crate0::{{expn2}}, call_site_ctxt: #3, def_site_ctxt: #3, kind: Macro(Bang, "inner") crate0::{{expn4}}: parent: crate0::{{expn3}}, call_site_ctxt: #5, def_site_ctxt: #0, kind: Macro(Bang, "print_bang") +crate1::{{expnNNN}}: parent: crate0::{{expn0}}, call_site_ctxt: #0, def_site_ctxt: #0, kind: Macro(Attr, "diagnostic::on_unimplemented") +crate1::{{expnNNN}}: parent: crate0::{{expn0}}, call_site_ctxt: #0, def_site_ctxt: #0, kind: Macro(Attr, "diagnostic::on_unimplemented") +crate1::{{expnNNN}}: parent: crate0::{{expn0}}, call_site_ctxt: #0, def_site_ctxt: #0, kind: Macro(Attr, "diagnostic::on_unimplemented") crate1::{{expnNNN}}: parent: crate0::{{expn0}}, call_site_ctxt: #0, def_site_ctxt: #0, kind: Macro(Attr, "derive") crate1::{{expnNNN}}: parent: crate0::{{expn0}}, call_site_ctxt: #0, def_site_ctxt: #0, kind: Macro(Attr, "derive") crate1::{{expnNNN}}: parent: crate0::{{expn0}}, call_site_ctxt: #0, def_site_ctxt: #0, kind: Macro(Bang, "include") -- cgit 1.4.1-3-g733a5 From 91e1af38623e05c52591aae2aa4a213553907ea0 Mon Sep 17 00:00:00 2001 From: Georg Semmler Date: Sat, 23 Dec 2023 14:02:01 +0100 Subject: Add a test that emitting diagnostics does not require the crate to use the corresponding feature. --- .../on_unimplemented/auxiliary/other.rs | 8 ++++++++ .../error_is_shown_in_downstream_crates.rs | 12 ++++++++++++ .../error_is_shown_in_downstream_crates.stderr | 19 +++++++++++++++++++ 3 files changed, 39 insertions(+) create mode 100644 tests/ui/diagnostic_namespace/on_unimplemented/auxiliary/other.rs create mode 100644 tests/ui/diagnostic_namespace/on_unimplemented/error_is_shown_in_downstream_crates.rs create mode 100644 tests/ui/diagnostic_namespace/on_unimplemented/error_is_shown_in_downstream_crates.stderr (limited to 'tests') diff --git a/tests/ui/diagnostic_namespace/on_unimplemented/auxiliary/other.rs b/tests/ui/diagnostic_namespace/on_unimplemented/auxiliary/other.rs new file mode 100644 index 00000000000..884bab2800a --- /dev/null +++ b/tests/ui/diagnostic_namespace/on_unimplemented/auxiliary/other.rs @@ -0,0 +1,8 @@ +#![feature(diagnostic_namespace)] + +#[diagnostic::on_unimplemented( + message = "Message", + note = "Note", + label = "label" +)] +pub trait Foo {} diff --git a/tests/ui/diagnostic_namespace/on_unimplemented/error_is_shown_in_downstream_crates.rs b/tests/ui/diagnostic_namespace/on_unimplemented/error_is_shown_in_downstream_crates.rs new file mode 100644 index 00000000000..b39375a09f3 --- /dev/null +++ b/tests/ui/diagnostic_namespace/on_unimplemented/error_is_shown_in_downstream_crates.rs @@ -0,0 +1,12 @@ +// aux-build:other.rs + +extern crate other; + +use other::Foo; + +fn take_foo(_: impl Foo) {} + +fn main() { + take_foo(()); + //~^ERROR Message +} diff --git a/tests/ui/diagnostic_namespace/on_unimplemented/error_is_shown_in_downstream_crates.stderr b/tests/ui/diagnostic_namespace/on_unimplemented/error_is_shown_in_downstream_crates.stderr new file mode 100644 index 00000000000..a9968538d0d --- /dev/null +++ b/tests/ui/diagnostic_namespace/on_unimplemented/error_is_shown_in_downstream_crates.stderr @@ -0,0 +1,19 @@ +error[E0277]: Message + --> $DIR/error_is_shown_in_downstream_crates.rs:10:14 + | +LL | take_foo(()); + | -------- ^^ label + | | + | required by a bound introduced by this call + | + = help: the trait `Foo` is not implemented for `()` + = note: Note +note: required by a bound in `take_foo` + --> $DIR/error_is_shown_in_downstream_crates.rs:7:21 + | +LL | fn take_foo(_: impl Foo) {} + | ^^^ required by this bound in `take_foo` + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0277`. -- cgit 1.4.1-3-g733a5 From 97c82385114dfb8aa30b0fd63aa06c201aeb65d9 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Fri, 5 Jan 2024 18:49:25 +0100 Subject: remove duplicate test --- tests/ui/numbers-arithmetic/overflowing-rsh-6.rs | 9 --------- tests/ui/numbers-arithmetic/overflowing-rsh-6.stderr | 14 -------------- 2 files changed, 23 deletions(-) delete mode 100644 tests/ui/numbers-arithmetic/overflowing-rsh-6.rs delete mode 100644 tests/ui/numbers-arithmetic/overflowing-rsh-6.stderr (limited to 'tests') diff --git a/tests/ui/numbers-arithmetic/overflowing-rsh-6.rs b/tests/ui/numbers-arithmetic/overflowing-rsh-6.rs deleted file mode 100644 index f75e779ed15..00000000000 --- a/tests/ui/numbers-arithmetic/overflowing-rsh-6.rs +++ /dev/null @@ -1,9 +0,0 @@ -// build-fail -// compile-flags: -C debug-assertions - -#![deny(arithmetic_overflow)] - -fn main() { - let _n = 1i64 >> [64][0]; - //~^ ERROR: this arithmetic operation will overflow -} diff --git a/tests/ui/numbers-arithmetic/overflowing-rsh-6.stderr b/tests/ui/numbers-arithmetic/overflowing-rsh-6.stderr deleted file mode 100644 index 005f7378226..00000000000 --- a/tests/ui/numbers-arithmetic/overflowing-rsh-6.stderr +++ /dev/null @@ -1,14 +0,0 @@ -error: this arithmetic operation will overflow - --> $DIR/overflowing-rsh-6.rs:7:14 - | -LL | let _n = 1i64 >> [64][0]; - | ^^^^^^^^^^^^^^^ attempt to shift right by `64_i32`, which would overflow - | -note: the lint level is defined here - --> $DIR/overflowing-rsh-6.rs:4:9 - | -LL | #![deny(arithmetic_overflow)] - | ^^^^^^^^^^^^^^^^^^^ - -error: aborting due to 1 previous error - -- cgit 1.4.1-3-g733a5 From 54967d7a680bc72bea2c1ff6f1edc0d7d2ca6d41 Mon Sep 17 00:00:00 2001 From: León Orell Valerian Liehr Date: Fri, 5 Jan 2024 20:33:16 +0100 Subject: Ignore a rustdoc test --- tests/rustdoc/synthetic_auto/no-redundancy.rs | 3 +++ 1 file changed, 3 insertions(+) (limited to 'tests') diff --git a/tests/rustdoc/synthetic_auto/no-redundancy.rs b/tests/rustdoc/synthetic_auto/no-redundancy.rs index ea57d7388b8..fed9c9c7ba4 100644 --- a/tests/rustdoc/synthetic_auto/no-redundancy.rs +++ b/tests/rustdoc/synthetic_auto/no-redundancy.rs @@ -1,3 +1,6 @@ +// FIXME(fmease, #119216): Reenable this test! +// ignore-test + pub struct Inner { field: T, } -- cgit 1.4.1-3-g733a5 From 274674819c3c37e09f5fe0e3276d3921068dbb95 Mon Sep 17 00:00:00 2001 From: Lukas Markeffsky <@> Date: Fri, 5 Jan 2024 21:50:52 +0100 Subject: fix OOM when `ty::Instance` is used in query description --- compiler/rustc_middle/src/ty/instance.rs | 12 ++++++++---- .../resolve/auxiliary/suggest-constructor-cycle-error.rs | 12 ++++++++++++ tests/ui/resolve/suggest-constructor-cycle-error.rs | 10 ++++++++++ tests/ui/resolve/suggest-constructor-cycle-error.stderr | 15 +++++++++++++++ 4 files changed, 45 insertions(+), 4 deletions(-) create mode 100644 tests/ui/resolve/auxiliary/suggest-constructor-cycle-error.rs create mode 100644 tests/ui/resolve/suggest-constructor-cycle-error.rs create mode 100644 tests/ui/resolve/suggest-constructor-cycle-error.stderr (limited to 'tests') diff --git a/compiler/rustc_middle/src/ty/instance.rs b/compiler/rustc_middle/src/ty/instance.rs index 2ac3cddfa15..dd41cb5a61f 100644 --- a/compiler/rustc_middle/src/ty/instance.rs +++ b/compiler/rustc_middle/src/ty/instance.rs @@ -293,12 +293,16 @@ impl<'tcx> InstanceDef<'tcx> { fn fmt_instance( f: &mut fmt::Formatter<'_>, instance: &Instance<'_>, - type_length: rustc_session::Limit, + type_length: Option, ) -> fmt::Result { ty::tls::with(|tcx| { let args = tcx.lift(instance.args).expect("could not lift for printing"); - let mut cx = FmtPrinter::new_with_limit(tcx, Namespace::ValueNS, type_length); + let mut cx = if let Some(type_length) = type_length { + FmtPrinter::new_with_limit(tcx, Namespace::ValueNS, type_length) + } else { + FmtPrinter::new(tcx, Namespace::ValueNS) + }; cx.print_def_path(instance.def_id(), args)?; let s = cx.into_buffer(); f.write_str(&s) @@ -324,13 +328,13 @@ pub struct ShortInstance<'a, 'tcx>(pub &'a Instance<'tcx>, pub usize); impl<'a, 'tcx> fmt::Display for ShortInstance<'a, 'tcx> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - fmt_instance(f, self.0, rustc_session::Limit(self.1)) + fmt_instance(f, self.0, Some(rustc_session::Limit(self.1))) } } impl<'tcx> fmt::Display for Instance<'tcx> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - ty::tls::with(|tcx| fmt_instance(f, self, tcx.type_length_limit())) + fmt_instance(f, self, None) } } diff --git a/tests/ui/resolve/auxiliary/suggest-constructor-cycle-error.rs b/tests/ui/resolve/auxiliary/suggest-constructor-cycle-error.rs new file mode 100644 index 00000000000..8de68c38bc3 --- /dev/null +++ b/tests/ui/resolve/auxiliary/suggest-constructor-cycle-error.rs @@ -0,0 +1,12 @@ +mod m { + pub struct Uuid(()); + + impl Uuid { + pub fn encode_buffer() -> [u8; LENGTH] { + [] + } + } + const LENGTH: usize = 0; +} + +pub use m::Uuid; diff --git a/tests/ui/resolve/suggest-constructor-cycle-error.rs b/tests/ui/resolve/suggest-constructor-cycle-error.rs new file mode 100644 index 00000000000..2336cd92f4d --- /dev/null +++ b/tests/ui/resolve/suggest-constructor-cycle-error.rs @@ -0,0 +1,10 @@ +// aux-build:suggest-constructor-cycle-error.rs +//~^ cycle detected when getting the resolver for lowering [E0391] + +// Regression test for https://github.com/rust-lang/rust/issues/119625 + +extern crate suggest_constructor_cycle_error as a; + +const CONST_NAME: a::Uuid = a::Uuid(()); + +fn main() {} diff --git a/tests/ui/resolve/suggest-constructor-cycle-error.stderr b/tests/ui/resolve/suggest-constructor-cycle-error.stderr new file mode 100644 index 00000000000..ae139619c69 --- /dev/null +++ b/tests/ui/resolve/suggest-constructor-cycle-error.stderr @@ -0,0 +1,15 @@ +error[E0391]: cycle detected when getting the resolver for lowering + | + = note: ...which requires normalizing `[u8; suggest_constructor_cycle_error::::m::{impl#0}::encode_buffer::{constant#0}]`... +note: ...which requires resolving instance `suggest_constructor_cycle_error::m::Uuid::encode_buffer::{constant#0}`... + --> $DIR/auxiliary/suggest-constructor-cycle-error.rs:5:40 + | +LL | pub fn encode_buffer() -> [u8; LENGTH] { + | ^^^^^^ + = note: ...which requires calculating the lang items map... + = note: ...which again requires getting the resolver for lowering, completing the cycle + = note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0391`. -- cgit 1.4.1-3-g733a5 From 339fa311ad8140cfb98a1c6080ea7e002b9ce3fa Mon Sep 17 00:00:00 2001 From: Lukas Markeffsky <@> Date: Fri, 5 Jan 2024 21:55:09 +0100 Subject: fix cycle error for "use constructor" suggestion --- compiler/rustc_resolve/src/late/diagnostics.rs | 7 ++----- tests/ui/resolve/suggest-constructor-cycle-error.rs | 2 +- .../resolve/suggest-constructor-cycle-error.stderr | 20 ++++++++++---------- 3 files changed, 13 insertions(+), 16 deletions(-) (limited to 'tests') diff --git a/compiler/rustc_resolve/src/late/diagnostics.rs b/compiler/rustc_resolve/src/late/diagnostics.rs index 6c38ed62270..1ccb4820cdd 100644 --- a/compiler/rustc_resolve/src/late/diagnostics.rs +++ b/compiler/rustc_resolve/src/late/diagnostics.rs @@ -1755,11 +1755,8 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> { .filter_map(|item| { // Only assoc fns that return `Self` let fn_sig = self.r.tcx.fn_sig(item.def_id).skip_binder(); - let ret_ty = fn_sig.output(); - let ret_ty = self - .r - .tcx - .normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), ret_ty); + // Don't normalize the return type, because that can cause cycle errors. + let ret_ty = fn_sig.output().skip_binder(); let ty::Adt(def, _args) = ret_ty.kind() else { return None; }; diff --git a/tests/ui/resolve/suggest-constructor-cycle-error.rs b/tests/ui/resolve/suggest-constructor-cycle-error.rs index 2336cd92f4d..e36fffd97d1 100644 --- a/tests/ui/resolve/suggest-constructor-cycle-error.rs +++ b/tests/ui/resolve/suggest-constructor-cycle-error.rs @@ -1,10 +1,10 @@ // aux-build:suggest-constructor-cycle-error.rs -//~^ cycle detected when getting the resolver for lowering [E0391] // Regression test for https://github.com/rust-lang/rust/issues/119625 extern crate suggest_constructor_cycle_error as a; const CONST_NAME: a::Uuid = a::Uuid(()); +//~^ ERROR: cannot initialize a tuple struct which contains private fields [E0423] fn main() {} diff --git a/tests/ui/resolve/suggest-constructor-cycle-error.stderr b/tests/ui/resolve/suggest-constructor-cycle-error.stderr index ae139619c69..c6ec2465a43 100644 --- a/tests/ui/resolve/suggest-constructor-cycle-error.stderr +++ b/tests/ui/resolve/suggest-constructor-cycle-error.stderr @@ -1,15 +1,15 @@ -error[E0391]: cycle detected when getting the resolver for lowering +error[E0423]: cannot initialize a tuple struct which contains private fields + --> $DIR/suggest-constructor-cycle-error.rs:7:29 | - = note: ...which requires normalizing `[u8; suggest_constructor_cycle_error::::m::{impl#0}::encode_buffer::{constant#0}]`... -note: ...which requires resolving instance `suggest_constructor_cycle_error::m::Uuid::encode_buffer::{constant#0}`... - --> $DIR/auxiliary/suggest-constructor-cycle-error.rs:5:40 +LL | const CONST_NAME: a::Uuid = a::Uuid(()); + | ^^^^^^^ | -LL | pub fn encode_buffer() -> [u8; LENGTH] { - | ^^^^^^ - = note: ...which requires calculating the lang items map... - = note: ...which again requires getting the resolver for lowering, completing the cycle - = note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information +note: constructor is not visible here due to private fields + --> $DIR/auxiliary/suggest-constructor-cycle-error.rs:2:21 + | +LL | pub struct Uuid(()); + | ^^ private field error: aborting due to 1 previous error -For more information about this error, try `rustc --explain E0391`. +For more information about this error, try `rustc --explain E0423`. -- cgit 1.4.1-3-g733a5 From 7366bdaea2757b7b45965f4b59a8137adf7d10af Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Fri, 29 Dec 2023 20:04:03 +0000 Subject: Handle ForeignItem as TAIT scope. --- .../src/collect/type_of/opaque.rs | 7 +++++++ .../type-alias-impl-trait/nested-in-anon-const.rs | 21 +++++++++++++++++++++ .../nested-in-anon-const.stderr | 20 ++++++++++++++++++++ 3 files changed, 48 insertions(+) create mode 100644 tests/ui/type-alias-impl-trait/nested-in-anon-const.rs create mode 100644 tests/ui/type-alias-impl-trait/nested-in-anon-const.stderr (limited to 'tests') diff --git a/compiler/rustc_hir_analysis/src/collect/type_of/opaque.rs b/compiler/rustc_hir_analysis/src/collect/type_of/opaque.rs index 5a73097b0f6..04047e56c60 100644 --- a/compiler/rustc_hir_analysis/src/collect/type_of/opaque.rs +++ b/compiler/rustc_hir_analysis/src/collect/type_of/opaque.rs @@ -69,6 +69,7 @@ pub(super) fn find_opaque_ty_constraints_for_tait(tcx: TyCtxt<'_>, def_id: Local Node::Item(it) => locator.visit_item(it), Node::ImplItem(it) => locator.visit_impl_item(it), Node::TraitItem(it) => locator.visit_trait_item(it), + Node::ForeignItem(it) => locator.visit_foreign_item(it), other => bug!("{:?} is not a valid scope for an opaque type item", other), } } @@ -240,6 +241,12 @@ impl<'tcx> intravisit::Visitor<'tcx> for TaitConstraintLocator<'tcx> { self.check(it.owner_id.def_id); intravisit::walk_trait_item(self, it); } + fn visit_foreign_item(&mut self, it: &'tcx hir::ForeignItem<'tcx>) { + trace!(?it.owner_id); + assert_ne!(it.owner_id.def_id, self.def_id); + self.check(it.owner_id.def_id); + intravisit::walk_foreign_item(self, it); + } } pub(super) fn find_opaque_ty_constraints_for_rpit<'tcx>( diff --git a/tests/ui/type-alias-impl-trait/nested-in-anon-const.rs b/tests/ui/type-alias-impl-trait/nested-in-anon-const.rs new file mode 100644 index 00000000000..e9d53c99d04 --- /dev/null +++ b/tests/ui/type-alias-impl-trait/nested-in-anon-const.rs @@ -0,0 +1,21 @@ +// Regression test for issue #119295. + +#![feature(type_alias_impl_trait)] + +type Bar = T; +type S = [i32; A]; + +extern "C" { + pub fn lint_me( + x: Bar< + S< + { //~ ERROR mismatched types + type B = impl Sized; + //~^ ERROR unconstrained opaque type + }, + >, + >, + ); +} + +fn main() {} diff --git a/tests/ui/type-alias-impl-trait/nested-in-anon-const.stderr b/tests/ui/type-alias-impl-trait/nested-in-anon-const.stderr new file mode 100644 index 00000000000..aa0c1076117 --- /dev/null +++ b/tests/ui/type-alias-impl-trait/nested-in-anon-const.stderr @@ -0,0 +1,20 @@ +error[E0308]: mismatched types + --> $DIR/nested-in-anon-const.rs:12:17 + | +LL | / { +LL | | type B = impl Sized; +LL | | +LL | | }, + | |_________________^ expected `usize`, found `()` + +error: unconstrained opaque type + --> $DIR/nested-in-anon-const.rs:13:33 + | +LL | type B = impl Sized; + | ^^^^^^^^^^ + | + = note: `B` must be used in combination with a concrete type within the same item + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0308`. -- cgit 1.4.1-3-g733a5 From eeaea576008f53e259c0f86cdd37f28bed9034a1 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Fri, 5 Jan 2024 21:54:41 +0000 Subject: Rebase fallout. --- .../ui/type-alias-impl-trait/nested-in-anon-const.stderr | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'tests') diff --git a/tests/ui/type-alias-impl-trait/nested-in-anon-const.stderr b/tests/ui/type-alias-impl-trait/nested-in-anon-const.stderr index aa0c1076117..d0fe920b35f 100644 --- a/tests/ui/type-alias-impl-trait/nested-in-anon-const.stderr +++ b/tests/ui/type-alias-impl-trait/nested-in-anon-const.stderr @@ -1,3 +1,11 @@ +error: unconstrained opaque type + --> $DIR/nested-in-anon-const.rs:13:33 + | +LL | type B = impl Sized; + | ^^^^^^^^^^ + | + = note: `B` must be used in combination with a concrete type within the same item + error[E0308]: mismatched types --> $DIR/nested-in-anon-const.rs:12:17 | @@ -7,14 +15,6 @@ LL | | LL | | }, | |_________________^ expected `usize`, found `()` -error: unconstrained opaque type - --> $DIR/nested-in-anon-const.rs:13:33 - | -LL | type B = impl Sized; - | ^^^^^^^^^^ - | - = note: `B` must be used in combination with a concrete type within the same item - error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0308`. -- cgit 1.4.1-3-g733a5