diff --git a/RELEASES.md b/RELEASES.md index f2d74f2e7f1f0..34984a29eff51 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -1,3 +1,10 @@ +Version 1.98.1 (2026-09-03) +=========================== + + + +* [rustc: fix miscompilation in generating vtables](https://github.com/rust-lang/rust/issues/161441) + Version 1.98.0 (2026-08-20) ========================== diff --git a/compiler/rustc_attr_ir/src/attribute_docs.rs b/compiler/rustc_attr_ir/src/attribute_docs.rs new file mode 100644 index 0000000000000..4d40cd6d52f16 --- /dev/null +++ b/compiler/rustc_attr_ir/src/attribute_docs.rs @@ -0,0 +1,225 @@ +macro_rules! include_example { + ($name:literal) => { + concat!( + "```rust,compile_fail\n", + include_str!(concat!("../../../tests/ui/attributes/doc_examples/", $name, ".rs")), + "```\n", + "produces:\n", + " ```text\n", + include_str!(concat!("../../../tests/ui/attributes/doc_examples/", $name, ".stderr")), + "```\n", + ) + }; +} + +#[cfg_attr(not(bootstrap), doc(attribute = "rustc_dump_clauses"))] +/// Dumps the list of [`ty::Clause`]s as computed by the [`clauses_of`] query. +/// +/// See [`AttributeKind::RustcDumpClauses`] for the internal representation of this attribute. +/// +/// # Example +/// +#[doc = include_example!("rustc_dump_clauses")] +/// +/// # Example: super trait bounds are not elaborated +/// +#[doc = include_example!("rustc_dump_clauses_super_trait")] +/// +/// [`clauses_of`]: ../rustc_middle/ty/struct.TyCtxt.html#method.clauses_of +/// [`ty::Clause`]: ../rustc_middle/ty/struct.Clause.html +const _: () = (); + +#[doc(attribute = "rustc_dump_def_parents")] +/// Dumps the parents of the annotated item and of any anonymous constants contained within it. +/// +/// See also [`opt_parent`](../rustc_middle/ty/struct.TyCtxt.html#method.opt_parent). +/// +/// See [`AttributeKind::RustcDumpDefParents`] for the internal representation of this attribute. +/// +/// # Example +/// +#[doc = include_example!("rustc_dump_def_parents")] +const _: () = (); + +#[doc(attribute = "rustc_dump_def_path")] +/// Dumps the def path of the annotated item. +/// +/// See also [`def_path_str`] and [`def_path_str_with_args`]. +/// +/// See [`AttributeKind::RustcDumpDefPath`] for the internal representation of this attribute. +/// +/// # Example +/// +#[doc = include_example!("rustc_dump_def_path")] +/// +/// [`def_path_str`]: ../rustc_middle/ty/struct.TyCtxt.html#method.def_path_str +/// [`def_path_str_with_args`]: ../rustc_middle/ty/struct.TyCtxt.html#method.def_path_str_with_args +const _: () = (); + +#[doc(attribute = "rustc_dump_generics")] +/// Dumps the generics of the annotated item. +/// +/// See [`generics_of`] and [`ty::Generics`] for what "generics" means here. +/// +/// See [`AttributeKind::RustcDumpGenerics`] for the internal representation of this attribute. +/// +/// # Example +/// +#[doc = include_example!("rustc_dump_generics")] +/// +/// [`generics_of`]: ../rustc_middle/ty/struct.TyCtxt.html#method.generics_of +/// [`ty::Generics`]: ../rustc_middle/ty/struct.Generics.html +const _: () = (); + +#[doc(attribute = "rustc_dump_hidden_type_of_opaques")] +/// Dumps the hidden types of the opaque items in this crate. +/// +/// This ends up calling the [`type_of`] query, which, for opaque types, reveals their hidden types. +/// +/// See [`AttributeKind::RustcDumpHiddenTypeOfOpaques`] for the internal representation of this attribute. +/// +/// # Example +/// +#[doc = include_example!("rustc_dump_hidden_type_of_opaques")] +/// +/// [`type_of`]: ../rustc_middle/ty/struct.TyCtxt.html#method.type_of +const _: () = (); + +#[doc(attribute = "rustc_dump_inferred_outlives")] +/// Dumps the inferred outlives-clauses of the annotated item. +/// +/// See also the [`inferred_outlives_of`] query. +/// +/// See [`AttributeKind::RustcDumpInferredOutlives`] for the internal representation of this attribute. +/// +/// # Example +/// +#[doc = include_example!("rustc_dump_inferred_outlives")] +/// +/// [`inferred_outlives_of`]: ../rustc_middle/ty/struct.TyCtxt.html#method.inferred_outlives_of +const _: () = (); + +#[doc(attribute = "rustc_dump_item_bounds")] +/// Dumps the item bounds of the annotated item. +/// +/// This ends up calling the [`item_bounds`] query and prints the [`ty::Clause`] of the item. +/// +/// See [`AttributeKind::RustcDumpItemBounds`] for the internal representation of this attribute. +/// +/// # Example +/// +#[doc = include_example!("rustc_dump_item_bounds")] +/// +/// [`item_bounds`]: ../rustc_middle/ty/struct.TyCtxt.html#method.item_bounds +/// [`ty::Clause`]: ../rustc_middle/ty/struct.Clause.html +const _: () = (); + +#[doc(attribute = "rustc_dump_layout")] +/// Dumps the layout of the annotated item. +/// +/// This ends up calling the [`layout_of`] query to get the [`Layout`] of the annotated item. If used +/// with the `debug` modifier, it will print the entirety of `Layout`. Other modifiers will print +/// only parts of it. +/// +/// See [`AttributeKind::RustcDumpLayout`] for the internal representation of this attribute. +/// +/// # Example: `debug` +/// +#[doc = include_example!("rustc_dump_layout_debug")] +/// +/// # Example: `largest_niche` +/// +#[doc = include_example!("rustc_dump_layout_largest_niche")] +/// +/// # Example: `size` +/// +#[doc = include_example!("rustc_dump_layout_size")] +/// +/// # Example: `align` +/// +#[doc = include_example!("rustc_dump_layout_align")] +/// +/// # Example: `backend_repr` +/// +#[doc = include_example!("rustc_dump_layout_backend_repr")] +/// +/// # Example: `homogeneous_aggregate` +/// +#[doc = include_example!("rustc_dump_layout_homogeneous_aggregate")] +/// +/// [`layout_of`]: ../rustc_middle/ty/struct.TyCtxt.html#method.layout_of +/// [`Layout`]: rustc_abi::Layout +const _: () = (); + +#[doc(attribute = "rustc_dump_object_lifetime_defaults")] +/// Dumps the trait object lifetime defaults induced by the type parameters of the annotated item. +/// +/// It will dump this information separately for each type parameter of the annotated item. +/// +/// See also the [`object_lifetime_default`] query. +/// +/// See [`AttributeKind::RustcDumpObjectLifetimeDefaults`] for the internal representation of this attribute. +/// +/// # Example +/// +#[doc = include_example!("rustc_dump_object_lifetime_defaults")] +/// +/// [`object_lifetime_default`]: ../rustc_middle/ty/struct.TyCtxt.html#method.object_lifetime_default +const _: () = (); + +#[doc(attribute = "rustc_dump_symbol_name")] +/// Dumps the symbol name of the annotated item, also demangling it if necessary. +/// +/// See also the [`symbol_name`] query. +/// +/// See [`AttributeKind::RustcDumpSymbolName`] for the internal representation of this attribute. +/// +/// # Example +/// +#[doc = include_example!("rustc_dump_symbol_name")] +/// +/// [`symbol_name`]: ../rustc_middle/ty/struct.TyCtxt.html#method.symbol_name +const _: () = (); + +#[doc(attribute = "rustc_dump_variances")] +/// Dumps the variances of the annotated item. +/// +/// See also the [`variances_of`] query and [`ty::Variance`]. +/// +/// See [`AttributeKind::RustcDumpVariances`] for the internal representation of this attribute. +/// +/// # Example +/// +#[doc = include_example!("rustc_dump_variances")] +/// +/// [`variances_of`]: ../rustc_middle/ty/struct.TyCtxt.html#method.variances_of +/// [`ty::Variance`]: ../rustc_middle/ty/enum.Variance.html +const _: () = (); + +#[doc(attribute = "rustc_dump_variances_of_opaques")] +/// Dumps the variances of opaque types in this crate. +/// +/// See also the [`variances_of`] query. +/// +/// See [`AttributeKind::RustcDumpVariancesOfOpaques`] for the internal representation of this attribute. +/// +/// # Example +/// +#[doc = include_example!("rustc_dump_variances_of_opaques")] +/// +/// [`variances_of`]: ../rustc_middle/ty/struct.TyCtxt.html#method.variances_of +const _: () = (); + +#[doc(attribute = "rustc_dump_vtable")] +/// Dumps the virtual method table ("vtable") of the annotated item. +/// +/// See also the [`vtable_entries`] query. +/// +/// See [`AttributeKind::RustcDumpVtable`] for the internal representation of this attribute. +/// +/// # Example +/// +#[doc = include_example!("rustc_dump_vtable")] +/// +/// [`vtable_entries`]: ../rustc_middle/ty/struct.TyCtxt.html#method.vtable_entries +const _: () = (); diff --git a/compiler/rustc_attr_ir/src/data_structures.rs b/compiler/rustc_attr_ir/src/data_structures.rs index 164efb04e1fe3..beb4ba8fabef7 100644 --- a/compiler/rustc_attr_ir/src/data_structures.rs +++ b/compiler/rustc_attr_ir/src/data_structures.rs @@ -1219,46 +1219,46 @@ pub enum AttributeKind { /// Represents `#[rustc_dummy]`. RustcDummy, - /// Represents `#[rustc_dump_clauses]` + /// Represents the [`rustc_dump_clauses`](./attribute.rustc_dump_clauses.html) attribute. RustcDumpClauses, - /// Represents `#[rustc_dump_def_parents]` + /// Represents the [`rustc_dump_def_parents`](./attribute.rustc_dump_def_parents.html) attribute. RustcDumpDefParents, - /// Represents `#[rustc_dump_def_path]` + /// Represents the [`rustc_dump_def_path`](./attribute.rustc_dump_def_path.html) attribute. RustcDumpDefPath(Span), - /// Represents `#[rustc_dump_generics]` + /// Represents the [`rustc_dump_generics`](./attribute.rustc_dump_generics.html) attribute. RustcDumpGenerics, - /// Represents `#[rustc_dump_hidden_type_of_opaques]` + /// Represents the [`rustc_dump_hidden_type_of_opaques`](./attribute.rustc_dump_hidden_type_of_opaques.html) attribute. RustcDumpHiddenTypeOfOpaques, - /// Represents `#[rustc_dump_inferred_outlives]` + /// Represents the [`rustc_dump_inferred_outlives`](./attribute.rustc_dump_inferred_outlives.html) attribute. RustcDumpInferredOutlives, - /// Represents `#[rustc_dump_item_bounds]` + /// Represents the [`rustc_dump_item_bounds`](./attribute.rustc_dump_item_bounds.html) attribute. RustcDumpItemBounds, - /// Represents `#[rustc_dump_layout]` + /// Represents the [`rustc_dump_layout`](./attribute.rustc_dump_layout.html) attribute. RustcDumpLayout(ThinVec), - /// Represents `#[rustc_dump_object_lifetime_defaults]`. + /// Represents the [`rustc_dump_object_lifetime_defaults`](./attribute.rustc_dump_object_lifetime_defaults.html) attribute. RustcDumpObjectLifetimeDefaults, - /// Represents `#[rustc_dump_symbol_name]` + /// Represents the [`rustc_dump_symbol_name`](./attribute.rustc_dump_symbol_name.html) attribute. RustcDumpSymbolName(Span), /// Represents `#[rustc_dump_user_args]` RustcDumpUserArgs, - /// Represents `#[rustc_dump_variances]` + /// Represents the [`rustc_dump_variances`](./attribute.rustc_dump_variances.html) attribute. RustcDumpVariances, - /// Represents `#[rustc_dump_variances_of_opaques]` + /// Represents the [`rustc_dump_variances_of_opaques`](./attribute.rustc_dump_variances_of_opaques.html) attribute. RustcDumpVariancesOfOpaques, - /// Represents `#[rustc_dump_vtable]` + /// Represents the [`rustc_dump_vtable`](./attribute.rustc_dump_vtable.html) attribute. RustcDumpVtable(Span), /// Represents `#[rustc_dyn_incompatible_trait]`. diff --git a/compiler/rustc_attr_ir/src/lib.rs b/compiler/rustc_attr_ir/src/lib.rs index 0b142ca92df6b..f835e257762a9 100644 --- a/compiler/rustc_attr_ir/src/lib.rs +++ b/compiler/rustc_attr_ir/src/lib.rs @@ -4,11 +4,13 @@ //! see [rustc_attr_parsing](../rustc_attr_parsing/index.html). // tidy-alphabetical-start +#![expect(internal_features, reason = "rustdoc_internals, for documenting attributes")] #![feature(const_default)] #![feature(const_trait_impl)] #![feature(default_field_values)] #![feature(derive_const)] #![feature(exhaustive_patterns)] +#![feature(rustdoc_internals)] #![feature(variant_count)] #![recursion_limit = "256"] // tidy-alphabetical-end @@ -143,3 +145,5 @@ macro_rules! find_attr { } }}; } + +include!("attribute_docs.rs"); diff --git a/compiler/rustc_borrowck/src/region_infer/mod.rs b/compiler/rustc_borrowck/src/region_infer/mod.rs index d86ba5d462de1..19aa4081bfc88 100644 --- a/compiler/rustc_borrowck/src/region_infer/mod.rs +++ b/compiler/rustc_borrowck/src/region_infer/mod.rs @@ -347,7 +347,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { outlives_constraints, scc_annotations, type_tests, - mut liveness_constraints, + liveness_constraints, universe_causes, placeholder_indices, } = lowered_constraints; @@ -376,9 +376,6 @@ impl<'tcx> RegionInferenceContext<'tcx> { match definition.origin { // For each free, universally quantified region X: NllRegionVariableOrigin::FreeRegion => { - // Add all nodes in the CFG to liveness constraints - liveness_constraints.add_all_points(region); - // Add `end(X)` into the set for X. scc_values.add_free_region(scc, region); } @@ -396,8 +393,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { // has them, setting `scc_values[scc(region)] |= liveness_constraints[region]`. // // These values will later be propagated during [`Self::propagate_constraints()`]. - // The values include any live-at-all-points constraints added above - // for free regions. + // The values include any live-at-all-points constraints added previously in `liveness::generate`. if let Some(liveness) = liveness_constraints.point_liveness(region) { scc_values.merge_liveness(scc, liveness) } diff --git a/compiler/rustc_borrowck/src/type_check/liveness/mod.rs b/compiler/rustc_borrowck/src/type_check/liveness/mod.rs index 22d8ababcdfd5..fd8502773c51e 100644 --- a/compiler/rustc_borrowck/src/type_check/liveness/mod.rs +++ b/compiler/rustc_borrowck/src/type_check/liveness/mod.rs @@ -34,6 +34,11 @@ pub(super) fn generate<'tcx>( debug!("liveness::generate"); let _timer = typeck.tcx().prof.generic_activity("borrowck_liveness"); + // Universal regions are live at every point. + for region in typeck.universal_regions.universal_regions_iter() { + typeck.constraints.liveness_constraints.add_all_points(region); + } + let mut free_regions = regions_that_outlive_free_regions( typeck.infcx.num_region_vars(), &typeck.universal_regions, diff --git a/compiler/rustc_infer/src/infer/mod.rs b/compiler/rustc_infer/src/infer/mod.rs index a49a4355b66b1..6f5d3bb75ebe4 100644 --- a/compiler/rustc_infer/src/infer/mod.rs +++ b/compiler/rustc_infer/src/infer/mod.rs @@ -89,10 +89,11 @@ pub(crate) type UnificationTable<'a, 'tcx, T> = ut::UnificationTable< ut::InPlace, &'a mut InferCtxtUndoLogs<'tcx>>, >; -/// This type contains all the things within `InferCtxt` that sit within a -/// `RefCell` and are involved with taking/rolling back snapshots. Snapshot -/// operations are hot enough that we want only one call to `borrow_mut` per -/// call to `start_snapshot` and `rollback_to`. +/// This type contains all the things within [`InferCtxt`] that sit within a +/// [`RefCell`] and are involved with taking/rolling back snapshots. Snapshot +/// operations are hot enough that we want only one call to +/// [`RefCell::borrow_mut`] per call to [`InferCtxt::start_snapshot`] and +/// [`InferCtxt::rollback_to`]. #[derive(Clone)] pub struct InferCtxtInner<'tcx> { undo_log: InferCtxtUndoLogs<'tcx>, @@ -102,7 +103,10 @@ pub struct InferCtxtInner<'tcx> { /// This cache is snapshotted along with the infcx. projection_cache: traits::ProjectionCacheStorage<'tcx>, - /// We instantiate `UnificationTable` with `bounds` because the types + /// Primary map of inference variables to the types that they currently + /// represent. + /// + /// We instantiate [`UnificationTable`] with `bounds` because the types /// that might instantiate a general type variable have an order, /// represented by its upper and lower bounds. type_variable_storage: type_variable::TypeVariableStorage<'tcx>, diff --git a/library/std/src/sys/thread/unix.rs b/library/std/src/sys/thread/unix.rs index 1d87e2095f134..b7908dea2b5de 100644 --- a/library/std/src/sys/thread/unix.rs +++ b/library/std/src/sys/thread/unix.rs @@ -67,7 +67,7 @@ impl Thread { assert_eq!( libc::pthread_attr_setstacksize( attr.get(), - cmp::max(stack, min_stack_size(attr.as_ptr())) + cmp::max(stack, min_stack_size(attr.get())) ), 0 ); diff --git a/src/bootstrap/src/bin/rustdoc.rs b/src/bootstrap/src/bin/rustdoc.rs index da80d7cd8c599..d18ca77fc7e14 100644 --- a/src/bootstrap/src/bin/rustdoc.rs +++ b/src/bootstrap/src/bin/rustdoc.rs @@ -72,11 +72,9 @@ fn main() { .arg("-Zcrate-attr=doc(rust_logo)") .arg("-Zcrate-attr=doc(html_root_url = \"https://doc.rust-lang.org/nightly/nightly-rustc/\")"); - // rustc_proc_macro is another build of library/proc_macro which already enables this - // feature - if crate_name != "rustc_proc_macro" { - cmd.arg("-Zcrate-attr=feature(rustdoc_internals)"); - } + // Some crates already have this feature enabled + cmd.arg("-Zcrate-attr=feature(rustdoc_internals)"); + cmd.arg("-Aduplicate-features"); } } diff --git a/src/etc/lldb_batchmode/common.py b/src/etc/lldb_batchmode/common.py index 56933b4de87b3..b85ef47ba3ced 100644 --- a/src/etc/lldb_batchmode/common.py +++ b/src/etc/lldb_batchmode/common.py @@ -572,6 +572,12 @@ def save_blessing(self, metadata: BlessMetadata): f.write(x) f.write("\n") + def print_json(self, metadata: BlessMetadata): + """Prints `self` to `stdout` in json format with no formatting. This output is identicall to + what would be saved via `TargetData.save_blessing`""" + self.bless_metadata = metadata + print(json.dumps(clean_nones(asdict(self)))) + def clean_nones(value): """ diff --git a/src/etc/lldb_batchmode/runner.py b/src/etc/lldb_batchmode/runner.py index a396f7c1f504b..2db1f6793d4f3 100644 --- a/src/etc/lldb_batchmode/runner.py +++ b/src/etc/lldb_batchmode/runner.py @@ -301,14 +301,35 @@ def main(): # this point are either from the `bless` not working properly, or some other issue with # the test itself. In either case, we probably don't want to update the test data until # those are resolved. - # Only runs if the test contains a repr command, as we don't want to create an input - # file for a test that won't ever use it. + + # If we're running CI though, the runner may be on a target that the PR author doesn't + # have access to. In such cases, we want to dump the json output so they can "manually + # bless" when necessary. + if ( + not all_ok + and (is_ci := os.environ.get("CI")) is not None + and is_ci == "true" + ): + from lldb_providers import FEATURE_FLAGS + + path = os.path.relpath(os.environ["LLDB_BATCHMODE_INPUT_DATA_PATH"]) + + print(f"[repr] If you do not have access to this target, you can manually update \ +the test data by overwriting the data in {path} with the following:") + + INPUT_DATA.print_json( + BlessMetadata( + sys.version, debugger.GetVersionString(), str(FEATURE_FLAGS) + ) + ) if not tested_all_types() or not tested_all_variables(): debugger.HandleCommand("quit 1") elif BLESS: from lldb_providers import FEATURE_FLAGS + # Only runs if the test contains a repr command, as we don't want to create an input + # file for a test that won't ever use it. INPUT_DATA.save_blessing( BlessMetadata( sys.version, debugger.GetVersionString(), str(FEATURE_FLAGS) diff --git a/tests/ui/attributes/doc_examples/README.md b/tests/ui/attributes/doc_examples/README.md new file mode 100644 index 0000000000000..38a76752d91a7 --- /dev/null +++ b/tests/ui/attributes/doc_examples/README.md @@ -0,0 +1 @@ +These UI tests and their stderr are `include_str`'d into compiler/rustc_attr_ir/src/attribute_docs.rs. diff --git a/tests/ui/attributes/doc_examples/rustc_dump_clauses.rs b/tests/ui/attributes/doc_examples/rustc_dump_clauses.rs new file mode 100644 index 0000000000000..fb4a2ceb8bbd7 --- /dev/null +++ b/tests/ui/attributes/doc_examples/rustc_dump_clauses.rs @@ -0,0 +1,25 @@ +//@ dont-require-annotations: ERROR +//@ compile-flags: --crate-type lib -Z ui-testing=no +//@ normalize-stderr: "DefId\((\d+):(\d+)" -> "DefId(..:.." +//@ normalize-stderr: "\[[A-Fa-f0-9]{4}\]" -> "[....]" + +#![feature(negative_impls)] +#![feature(rustc_attrs)] + +#[rustc_dump_clauses] +fn function(_t: T) {} + +#[rustc_dump_clauses] +trait Trait: Sync { + #[rustc_dump_clauses] + type Assoc; +} + +#[rustc_dump_clauses] +struct X<'a, T: ?Sized, I: Iterator> { + x: &'a T, + y: &'a I::Item, +} + +#[rustc_dump_clauses] +impl !Sync for X<'_, T, I> {} diff --git a/tests/ui/attributes/doc_examples/rustc_dump_clauses.stderr b/tests/ui/attributes/doc_examples/rustc_dump_clauses.stderr new file mode 100644 index 0000000000000..d381e6ebd745f --- /dev/null +++ b/tests/ui/attributes/doc_examples/rustc_dump_clauses.stderr @@ -0,0 +1,52 @@ +error: rustc_dump_clauses + --> $DIR/rustc_dump_clauses.rs:10:1 + | +10 | fn function(_t: T) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: Binder { value: TraitClause(, polarity:Positive), bound_vars: [] } + = note: Binder { value: TraitClause(, polarity:Positive), bound_vars: [] } + +error: rustc_dump_clauses + --> $DIR/rustc_dump_clauses.rs:13:1 + | +13 | trait Trait: Sync { + | ^^^^^^^^^^^^^^^^^ + | + = note: Binder { value: TraitClause(, polarity:Positive), bound_vars: [] } + = note: Binder { value: TraitClause(, polarity:Positive), bound_vars: [] } + = note: Binder { value: TraitClause(, polarity:Positive), bound_vars: [] } + +error: rustc_dump_clauses + --> $DIR/rustc_dump_clauses.rs:19:1 + | +19 | struct X<'a, T: ?Sized, I: Iterator> { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: Binder { value: TraitClause(, polarity:Positive), bound_vars: [] } + = note: Binder { value: TraitClause(, polarity:Positive), bound_vars: [] } + = note: Binder { value: TraitClause(, polarity:Positive), bound_vars: [] } + = note: Binder { value: OutlivesClause(T/#1, 'a/#0), bound_vars: [] } + = note: Binder { value: OutlivesClause(Alias(No, Alias { kind: Projection { def_id: DefId(..:.. ~ core[....]::iter::traits::iterator::Iterator::Item) }, args: [I/#2], .. }), 'a/#0), bound_vars: [] } + +error: rustc_dump_clauses + --> $DIR/rustc_dump_clauses.rs:25:1 + | +25 | impl !Sync for X<'_, T, I> {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: Binder { value: TraitClause(, polarity:Positive), bound_vars: [] } + = note: Binder { value: TraitClause(, polarity:Positive), bound_vars: [] } + +error: rustc_dump_clauses + --> $DIR/rustc_dump_clauses.rs:15:5 + | +15 | type Assoc; + | ^^^^^^^^^^ + | + = note: Binder { value: TraitClause(, polarity:Positive), bound_vars: [] } + = note: Binder { value: TraitClause(, polarity:Positive), bound_vars: [] } + = note: Binder { value: TraitClause(, polarity:Positive), bound_vars: [] } + +error: aborting due to 5 previous errors + diff --git a/tests/ui/attributes/doc_examples/rustc_dump_clauses_super_trait.rs b/tests/ui/attributes/doc_examples/rustc_dump_clauses_super_trait.rs new file mode 100644 index 0000000000000..d9f4b94f8d5de --- /dev/null +++ b/tests/ui/attributes/doc_examples/rustc_dump_clauses_super_trait.rs @@ -0,0 +1,9 @@ +//@ dont-require-annotations: ERROR +//@ compile-flags: --crate-type lib -Z ui-testing=no + +#![feature(rustc_attrs)] + +#[rustc_dump_clauses] +fn foo(t: &T) -> T { + *t +} diff --git a/tests/ui/attributes/doc_examples/rustc_dump_clauses_super_trait.stderr b/tests/ui/attributes/doc_examples/rustc_dump_clauses_super_trait.stderr new file mode 100644 index 0000000000000..d110ea484a6f8 --- /dev/null +++ b/tests/ui/attributes/doc_examples/rustc_dump_clauses_super_trait.stderr @@ -0,0 +1,11 @@ +error: rustc_dump_clauses + --> $DIR/rustc_dump_clauses_super_trait.rs:7:1 + | +7 | fn foo(t: &T) -> T { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: Binder { value: TraitClause(, polarity:Positive), bound_vars: [] } + = note: Binder { value: TraitClause(, polarity:Positive), bound_vars: [] } + +error: aborting due to 1 previous error + diff --git a/tests/ui/attributes/doc_examples/rustc_dump_def_parents.rs b/tests/ui/attributes/doc_examples/rustc_dump_def_parents.rs new file mode 100644 index 0000000000000..92bd53c473da9 --- /dev/null +++ b/tests/ui/attributes/doc_examples/rustc_dump_def_parents.rs @@ -0,0 +1,20 @@ +//@ dont-require-annotations: ERROR +//@ compile-flags: --crate-type lib -Z ui-testing=no + +#![feature(rustc_attrs)] + +fn parent() { + #[rustc_dump_def_parents] + fn child() {} +} + +struct Struct; + +const CONST: Struct<42> = Struct::< + { + #[rustc_dump_def_parents] + fn baby() {} + + 42 + }, +>; diff --git a/tests/ui/attributes/doc_examples/rustc_dump_def_parents.stderr b/tests/ui/attributes/doc_examples/rustc_dump_def_parents.stderr new file mode 100644 index 0000000000000..ffeb711998631 --- /dev/null +++ b/tests/ui/attributes/doc_examples/rustc_dump_def_parents.stderr @@ -0,0 +1,57 @@ +error: rustc_dump_def_parents: DefId(0:4 ~ rustc_dump_def_parents[9c2e]::parent::child) + --> $DIR/rustc_dump_def_parents.rs:8:5 + | + 8 | fn child() {} + | ^^^^^^^^^^ + | +note: DefId(0:3 ~ rustc_dump_def_parents[9c2e]::parent) + --> $DIR/rustc_dump_def_parents.rs:6:1 + | + 6 | fn parent() { + | ^^^^^^^^^^^ +note: DefId(0:0 ~ rustc_dump_def_parents[9c2e]) + --> $DIR/rustc_dump_def_parents.rs:4:1 + | + 4 | / #![feature(rustc_attrs)] + 5 | | + 6 | | fn parent() { + 7 | | #[rustc_dump_def_parents] +... | +19 | | }, +20 | | >; + | |__^ + +error: rustc_dump_def_parents: DefId(0:11 ~ rustc_dump_def_parents[9c2e]::CONST::{constant#1}::baby) + --> $DIR/rustc_dump_def_parents.rs:16:9 + | +16 | fn baby() {} + | ^^^^^^^^^ + | +note: DefId(0:10 ~ rustc_dump_def_parents[9c2e]::CONST::{constant#1}) + --> $DIR/rustc_dump_def_parents.rs:14:5 + | +14 | / { +15 | | #[rustc_dump_def_parents] +16 | | fn baby() {} +... | +19 | | }, + | |_____^ +note: DefId(0:8 ~ rustc_dump_def_parents[9c2e]::CONST) + --> $DIR/rustc_dump_def_parents.rs:13:1 + | +13 | const CONST: Struct<42> = Struct::< + | ^^^^^^^^^^^^^^^^^^^^^^^ +note: DefId(0:0 ~ rustc_dump_def_parents[9c2e]) + --> $DIR/rustc_dump_def_parents.rs:4:1 + | + 4 | / #![feature(rustc_attrs)] + 5 | | + 6 | | fn parent() { + 7 | | #[rustc_dump_def_parents] +... | +19 | | }, +20 | | >; + | |__^ + +error: aborting due to 2 previous errors + diff --git a/tests/ui/attributes/doc_examples/rustc_dump_def_path.rs b/tests/ui/attributes/doc_examples/rustc_dump_def_path.rs new file mode 100644 index 0000000000000..00181bce7d445 --- /dev/null +++ b/tests/ui/attributes/doc_examples/rustc_dump_def_path.rs @@ -0,0 +1,24 @@ +//@ dont-require-annotations: ERROR +//@ compile-flags: --crate-type lib -Z ui-testing=no +//@ build-fail + +#![feature(rustc_attrs)] + +#[rustc_dump_def_path] +fn main() { + || { + unsafe extern "C" { + #[rustc_dump_def_path] + static Foo: u8; + } + }; +} + +mod a { + mod b { + mod c { + #[rustc_dump_def_path] + fn d() {} + } + } +} diff --git a/tests/ui/attributes/doc_examples/rustc_dump_def_path.stderr b/tests/ui/attributes/doc_examples/rustc_dump_def_path.stderr new file mode 100644 index 0000000000000..f7cd75eecd927 --- /dev/null +++ b/tests/ui/attributes/doc_examples/rustc_dump_def_path.stderr @@ -0,0 +1,20 @@ +error: def-path(main) + --> $DIR/rustc_dump_def_path.rs:7:1 + | +7 | #[rustc_dump_def_path] + | ^^^^^^^^^^^^^^^^^^^^^^ + +error: def-path(a::b::c::d) + --> $DIR/rustc_dump_def_path.rs:20:13 + | +20 | #[rustc_dump_def_path] + | ^^^^^^^^^^^^^^^^^^^^^^ + +error: def-path(main::{closure#0}::Foo) + --> $DIR/rustc_dump_def_path.rs:11:13 + | +11 | #[rustc_dump_def_path] + | ^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 3 previous errors + diff --git a/tests/ui/attributes/doc_examples/rustc_dump_generics.rs b/tests/ui/attributes/doc_examples/rustc_dump_generics.rs new file mode 100644 index 0000000000000..9b95354309d00 --- /dev/null +++ b/tests/ui/attributes/doc_examples/rustc_dump_generics.rs @@ -0,0 +1,11 @@ +//@ dont-require-annotations: ERROR +//@ compile-flags: --crate-type lib -Z ui-testing=no +//@ normalize-stderr: "DefId\((\d+):(\d+)" -> "DefId(..:.." +//@ normalize-stderr: "\[[A-Fa-f0-9]{4}\]" -> "[....]" + +#![feature(rustc_attrs)] + +#[rustc_dump_generics] +struct Struct<'lifetime, const CONST: usize, GENERIC> { + stuff: &'lifetime [GENERIC; CONST], +} diff --git a/tests/ui/attributes/doc_examples/rustc_dump_generics.stderr b/tests/ui/attributes/doc_examples/rustc_dump_generics.stderr new file mode 100644 index 0000000000000..b6b2eacb2c137 --- /dev/null +++ b/tests/ui/attributes/doc_examples/rustc_dump_generics.stderr @@ -0,0 +1,61 @@ +error: rustc_dump_generics: DefId(..:.. ~ rustc_dump_generics[....]::Struct) + --> $DIR/rustc_dump_generics.rs:9:1 + | +9 | struct Struct<'lifetime, const CONST: usize, GENERIC> { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +note: Generics { + parent: None, + parent_count: 0, + own_params: [ + GenericParamDef { + name: "'lifetime", + def_id: DefId(..:.. ~ rustc_dump_generics[....]::Struct::'lifetime), + index: 0, + pure_wrt_drop: false, + kind: Lifetime, + }, + GenericParamDef { + name: "CONST", + def_id: DefId(..:.. ~ rustc_dump_generics[....]::Struct::CONST), + index: 1, + pure_wrt_drop: false, + kind: Const { + has_default: false, + }, + }, + GenericParamDef { + name: "GENERIC", + def_id: DefId(..:.. ~ rustc_dump_generics[....]::Struct::GENERIC), + index: 2, + pure_wrt_drop: false, + kind: Type { + has_default: false, + synthetic: false, + }, + }, + ], + param_def_id_to_index: [ + ( + DefId(..:.. ~ rustc_dump_generics[....]::Struct::'lifetime), + 0, + ), + ( + DefId(..:.. ~ rustc_dump_generics[....]::Struct::CONST), + 1, + ), + ( + DefId(..:.. ~ rustc_dump_generics[....]::Struct::GENERIC), + 2, + ), + ], + has_self: false, + has_late_bound_regions: None, + } + --> $DIR/rustc_dump_generics.rs:9:1 + | +9 | struct Struct<'lifetime, const CONST: usize, GENERIC> { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 1 previous error + diff --git a/tests/ui/attributes/doc_examples/rustc_dump_hidden_type_of_opaques.rs b/tests/ui/attributes/doc_examples/rustc_dump_hidden_type_of_opaques.rs new file mode 100644 index 0000000000000..fbd21351f5379 --- /dev/null +++ b/tests/ui/attributes/doc_examples/rustc_dump_hidden_type_of_opaques.rs @@ -0,0 +1,13 @@ +//@ dont-require-annotations: ERROR +//@ compile-flags: --crate-type lib -Z ui-testing=no -Z verbose-internals + +#![feature(rustc_attrs)] +#![rustc_dump_hidden_type_of_opaques] + +trait Foo { + fn hello(&self) -> impl Sized; +} + +fn hello<'s, T: Foo>(x: &'s T) -> impl Sized + use<'s, T> { + x.hello() +} diff --git a/tests/ui/attributes/doc_examples/rustc_dump_hidden_type_of_opaques.stderr b/tests/ui/attributes/doc_examples/rustc_dump_hidden_type_of_opaques.stderr new file mode 100644 index 0000000000000..a92efaf30859a --- /dev/null +++ b/tests/ui/attributes/doc_examples/rustc_dump_hidden_type_of_opaques.stderr @@ -0,0 +1,8 @@ +error: ::hello::{anon_assoc#0}<'s/#1> + --> $DIR/rustc_dump_hidden_type_of_opaques.rs:11:35 + | +11 | fn hello<'s, T: Foo>(x: &'s T) -> impl Sized + use<'s, T> { + | ^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 1 previous error + diff --git a/tests/ui/attributes/doc_examples/rustc_dump_inferred_outlives.rs b/tests/ui/attributes/doc_examples/rustc_dump_inferred_outlives.rs new file mode 100644 index 0000000000000..7d5e51f65ab38 --- /dev/null +++ b/tests/ui/attributes/doc_examples/rustc_dump_inferred_outlives.rs @@ -0,0 +1,19 @@ +//@ dont-require-annotations: ERROR +//@ compile-flags: --crate-type lib -Z ui-testing=no + +#![feature(rustc_attrs)] + +trait Trait<'x, T> +where + T: 'x, +{ + type Type; +} + +#[rustc_dump_inferred_outlives] +struct Foo<'a, A, B> +where + A: Trait<'a, B>, +{ + foo: >::Type, +} diff --git a/tests/ui/attributes/doc_examples/rustc_dump_inferred_outlives.stderr b/tests/ui/attributes/doc_examples/rustc_dump_inferred_outlives.stderr new file mode 100644 index 0000000000000..6c07c38d0384a --- /dev/null +++ b/tests/ui/attributes/doc_examples/rustc_dump_inferred_outlives.stderr @@ -0,0 +1,10 @@ +error: rustc_dump_inferred_outlives + --> $DIR/rustc_dump_inferred_outlives.rs:14:1 + | +14 | struct Foo<'a, A, B> + | ^^^^^^^^^^^^^^^^^^^^ + | + = note: B: 'a + +error: aborting due to 1 previous error + diff --git a/tests/ui/attributes/doc_examples/rustc_dump_item_bounds.rs b/tests/ui/attributes/doc_examples/rustc_dump_item_bounds.rs new file mode 100644 index 0000000000000..8eb5fd003c3e2 --- /dev/null +++ b/tests/ui/attributes/doc_examples/rustc_dump_item_bounds.rs @@ -0,0 +1,9 @@ +//@ dont-require-annotations: ERROR +//@ compile-flags: --crate-type lib -Z ui-testing=no + +#![feature(rustc_attrs)] + +trait Trait { + #[rustc_dump_item_bounds] + type Assoc: PartialEq; +} diff --git a/tests/ui/attributes/doc_examples/rustc_dump_item_bounds.stderr b/tests/ui/attributes/doc_examples/rustc_dump_item_bounds.stderr new file mode 100644 index 0000000000000..be7850111c429 --- /dev/null +++ b/tests/ui/attributes/doc_examples/rustc_dump_item_bounds.stderr @@ -0,0 +1,11 @@ +error: rustc_dump_item_bounds + --> $DIR/rustc_dump_item_bounds.rs:8:5 + | +8 | type Assoc: PartialEq; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: Binder { value: TraitClause(<>::Assoc as std::cmp::PartialEq>, polarity:Positive), bound_vars: [] } + = note: Binder { value: TraitClause(<>::Assoc as std::marker::Sized>, polarity:Positive), bound_vars: [] } + +error: aborting due to 1 previous error + diff --git a/tests/ui/attributes/doc_examples/rustc_dump_layout_align.rs b/tests/ui/attributes/doc_examples/rustc_dump_layout_align.rs new file mode 100644 index 0000000000000..103a8924cba4e --- /dev/null +++ b/tests/ui/attributes/doc_examples/rustc_dump_layout_align.rs @@ -0,0 +1,10 @@ +//@ dont-require-annotations: ERROR +//@ compile-flags: --crate-type lib -Z ui-testing=no + +#![feature(rustc_attrs)] + +#[rustc_dump_layout(align)] +enum Enum { + Bytes([u8; 4]), + Int(u32), +} diff --git a/tests/ui/attributes/doc_examples/rustc_dump_layout_align.stderr b/tests/ui/attributes/doc_examples/rustc_dump_layout_align.stderr new file mode 100644 index 0000000000000..d7fb8b5c96919 --- /dev/null +++ b/tests/ui/attributes/doc_examples/rustc_dump_layout_align.stderr @@ -0,0 +1,8 @@ +error: align: Align(4 bytes) + --> $DIR/rustc_dump_layout_align.rs:7:1 + | +7 | enum Enum { + | ^^^^^^^^^ + +error: aborting due to 1 previous error + diff --git a/tests/ui/attributes/doc_examples/rustc_dump_layout_backend_repr.rs b/tests/ui/attributes/doc_examples/rustc_dump_layout_backend_repr.rs new file mode 100644 index 0000000000000..844a7bc072ff9 --- /dev/null +++ b/tests/ui/attributes/doc_examples/rustc_dump_layout_backend_repr.rs @@ -0,0 +1,8 @@ +//@ dont-require-annotations: ERROR +//@ compile-flags: --crate-type lib -Z ui-testing=no + +#![feature(rustc_attrs)] +#![feature(portable_simd)] + +#[rustc_dump_layout(backend_repr)] +type Simd = std::simd::u32x4; diff --git a/tests/ui/attributes/doc_examples/rustc_dump_layout_backend_repr.stderr b/tests/ui/attributes/doc_examples/rustc_dump_layout_backend_repr.stderr new file mode 100644 index 0000000000000..5afc9709cb24e --- /dev/null +++ b/tests/ui/attributes/doc_examples/rustc_dump_layout_backend_repr.stderr @@ -0,0 +1,8 @@ +error: backend_repr: SimdVector { element: u32 is .., count: BackendLaneCount(4) } + --> $DIR/rustc_dump_layout_backend_repr.rs:8:1 + | +8 | type Simd = std::simd::u32x4; + | ^^^^^^^^^ + +error: aborting due to 1 previous error + diff --git a/tests/ui/attributes/doc_examples/rustc_dump_layout_debug.rs b/tests/ui/attributes/doc_examples/rustc_dump_layout_debug.rs new file mode 100644 index 0000000000000..41544d99cf10d --- /dev/null +++ b/tests/ui/attributes/doc_examples/rustc_dump_layout_debug.rs @@ -0,0 +1,11 @@ +//@ dont-require-annotations: ERROR +//@ compile-flags: --crate-type lib -Z ui-testing=no +//@ normalize-stderr: "randomization_seed: \d+" -> "randomization_seed: $$SEED" + +#![feature(rustc_attrs)] + +#[rustc_dump_layout(debug)] +pub union Union { + Float: f32, + Int: u32, +} diff --git a/tests/ui/attributes/doc_examples/rustc_dump_layout_debug.stderr b/tests/ui/attributes/doc_examples/rustc_dump_layout_debug.stderr new file mode 100644 index 0000000000000..1918a3696a4e1 --- /dev/null +++ b/tests/ui/attributes/doc_examples/rustc_dump_layout_debug.stderr @@ -0,0 +1,27 @@ +error: layout_of(Union) = Layout { + size: Size(4 bytes), + align: AbiAlign { + abi: Align(4 bytes), + }, + backend_repr: Memory { + sized: true, + }, + fields: Union( + 2, + ), + largest_niche: None, + uninhabited: false, + variants: Single { + index: 0, + }, + max_repr_align: None, + unadjusted_abi_align: Align(4 bytes), + randomization_seed: $SEED, + } + --> $DIR/rustc_dump_layout_debug.rs:8:1 + | +8 | pub union Union { + | ^^^^^^^^^^^^^^^ + +error: aborting due to 1 previous error + diff --git a/tests/ui/attributes/doc_examples/rustc_dump_layout_homogeneous_aggregate.rs b/tests/ui/attributes/doc_examples/rustc_dump_layout_homogeneous_aggregate.rs new file mode 100644 index 0000000000000..4888f1896f79e --- /dev/null +++ b/tests/ui/attributes/doc_examples/rustc_dump_layout_homogeneous_aggregate.rs @@ -0,0 +1,11 @@ +//@ dont-require-annotations: ERROR +//@ compile-flags: --crate-type lib -Z ui-testing=no + +#![feature(rustc_attrs)] + +#[rustc_dump_layout(homogeneous_aggregate)] +#[repr(C)] +struct Struct { + field: [u8; 32], + unit: (), +} diff --git a/tests/ui/attributes/doc_examples/rustc_dump_layout_homogeneous_aggregate.stderr b/tests/ui/attributes/doc_examples/rustc_dump_layout_homogeneous_aggregate.stderr new file mode 100644 index 0000000000000..2241adaef2343 --- /dev/null +++ b/tests/ui/attributes/doc_examples/rustc_dump_layout_homogeneous_aggregate.stderr @@ -0,0 +1,8 @@ +error: homogeneous_aggregate: Ok(Homogeneous(Reg { kind: Integer, size: Size(1 bytes) })) + --> $DIR/rustc_dump_layout_homogeneous_aggregate.rs:8:1 + | +8 | struct Struct { + | ^^^^^^^^^^^^^ + +error: aborting due to 1 previous error + diff --git a/tests/ui/attributes/doc_examples/rustc_dump_layout_largest_niche.rs b/tests/ui/attributes/doc_examples/rustc_dump_layout_largest_niche.rs new file mode 100644 index 0000000000000..3a8f93fb76347 --- /dev/null +++ b/tests/ui/attributes/doc_examples/rustc_dump_layout_largest_niche.rs @@ -0,0 +1,7 @@ +//@ dont-require-annotations: ERROR +//@ compile-flags: --crate-type lib -Z ui-testing=no + +#![feature(rustc_attrs)] + +#[rustc_dump_layout(largest_niche)] +type Alias = Option; diff --git a/tests/ui/attributes/doc_examples/rustc_dump_layout_largest_niche.stderr b/tests/ui/attributes/doc_examples/rustc_dump_layout_largest_niche.stderr new file mode 100644 index 0000000000000..f0be65ffe82d7 --- /dev/null +++ b/tests/ui/attributes/doc_examples/rustc_dump_layout_largest_niche.stderr @@ -0,0 +1,8 @@ +error: largest_niche: Some(Niche { offset: Size(0 bytes), value: u32, valid_range: (..=1114111) | (4294967295..) }) + --> $DIR/rustc_dump_layout_largest_niche.rs:7:1 + | +7 | type Alias = Option; + | ^^^^^^^^^^ + +error: aborting due to 1 previous error + diff --git a/tests/ui/attributes/doc_examples/rustc_dump_layout_size.rs b/tests/ui/attributes/doc_examples/rustc_dump_layout_size.rs new file mode 100644 index 0000000000000..ad0ef8a668ca3 --- /dev/null +++ b/tests/ui/attributes/doc_examples/rustc_dump_layout_size.rs @@ -0,0 +1,7 @@ +//@ dont-require-annotations: ERROR +//@ compile-flags: --crate-type lib -Z ui-testing=no + +#![feature(rustc_attrs)] + +#[rustc_dump_layout(size)] +type ID = std::any::TypeId; diff --git a/tests/ui/attributes/doc_examples/rustc_dump_layout_size.stderr b/tests/ui/attributes/doc_examples/rustc_dump_layout_size.stderr new file mode 100644 index 0000000000000..065fcb833280f --- /dev/null +++ b/tests/ui/attributes/doc_examples/rustc_dump_layout_size.stderr @@ -0,0 +1,8 @@ +error: size: Size(16 bytes) + --> $DIR/rustc_dump_layout_size.rs:7:1 + | +7 | type ID = std::any::TypeId; + | ^^^^^^^ + +error: aborting due to 1 previous error + diff --git a/tests/ui/attributes/doc_examples/rustc_dump_object_lifetime_defaults.rs b/tests/ui/attributes/doc_examples/rustc_dump_object_lifetime_defaults.rs new file mode 100644 index 0000000000000..720e8076e6a4c --- /dev/null +++ b/tests/ui/attributes/doc_examples/rustc_dump_object_lifetime_defaults.rs @@ -0,0 +1,7 @@ +//@ dont-require-annotations: ERROR +//@ compile-flags: --crate-type lib -Z ui-testing=no + +#![feature(rustc_attrs)] + +#[rustc_dump_object_lifetime_defaults] +struct Ref<'a, T: 'a>(&'a T); diff --git a/tests/ui/attributes/doc_examples/rustc_dump_object_lifetime_defaults.stderr b/tests/ui/attributes/doc_examples/rustc_dump_object_lifetime_defaults.stderr new file mode 100644 index 0000000000000..5aea8daba3f08 --- /dev/null +++ b/tests/ui/attributes/doc_examples/rustc_dump_object_lifetime_defaults.stderr @@ -0,0 +1,8 @@ +error: 'a + --> $DIR/rustc_dump_object_lifetime_defaults.rs:7:16 + | +7 | struct Ref<'a, T: 'a>(&'a T); + | ^ + +error: aborting due to 1 previous error + diff --git a/tests/ui/attributes/doc_examples/rustc_dump_symbol_name.rs b/tests/ui/attributes/doc_examples/rustc_dump_symbol_name.rs new file mode 100644 index 0000000000000..7c5750d1936db --- /dev/null +++ b/tests/ui/attributes/doc_examples/rustc_dump_symbol_name.rs @@ -0,0 +1,17 @@ +//@ dont-require-annotations: ERROR +//@ compile-flags: --crate-type lib -Z ui-testing=no +//@ build-fail + +#![feature(rustc_attrs)] + +#[rustc_dump_symbol_name] +fn mangled() {} + +#[rustc_dump_symbol_name] +#[unsafe(no_mangle)] +fn no_mangle() {} + +unsafe extern "C" { + #[rustc_dump_symbol_name] + fn abort(); +} diff --git a/tests/ui/attributes/doc_examples/rustc_dump_symbol_name.stderr b/tests/ui/attributes/doc_examples/rustc_dump_symbol_name.stderr new file mode 100644 index 0000000000000..a1d298909fae6 --- /dev/null +++ b/tests/ui/attributes/doc_examples/rustc_dump_symbol_name.stderr @@ -0,0 +1,32 @@ +error: symbol-name(_RNvCsCRATE_HASH_22rustc_dump_symbol_name7mangled) + --> $DIR/rustc_dump_symbol_name.rs:7:1 + | +7 | #[rustc_dump_symbol_name] + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: demangling(rustc_dump_symbol_name[6981ee133444a33d]::mangled) + --> $DIR/rustc_dump_symbol_name.rs:7:1 + | +7 | #[rustc_dump_symbol_name] + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: demangling-alt(rustc_dump_symbol_name::mangled) + --> $DIR/rustc_dump_symbol_name.rs:7:1 + | +7 | #[rustc_dump_symbol_name] + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: symbol-name(no_mangle) + --> $DIR/rustc_dump_symbol_name.rs:10:1 + | +10 | #[rustc_dump_symbol_name] + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: symbol-name(abort) + --> $DIR/rustc_dump_symbol_name.rs:15:5 + | +15 | #[rustc_dump_symbol_name] + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 5 previous errors + diff --git a/tests/ui/attributes/doc_examples/rustc_dump_variances.rs b/tests/ui/attributes/doc_examples/rustc_dump_variances.rs new file mode 100644 index 0000000000000..37a4c9a789435 --- /dev/null +++ b/tests/ui/attributes/doc_examples/rustc_dump_variances.rs @@ -0,0 +1,24 @@ +//@ dont-require-annotations: ERROR +//@ compile-flags: --crate-type lib -Z ui-testing=no + +#![feature(rustc_attrs)] + +#[rustc_dump_variances] +struct Ref<'a, T> { + r: &'a T, +} + +#[rustc_dump_variances] +struct RefMut<'a, T> { + r: &'a mut T, +} + +#[rustc_dump_variances] +struct CellRef<'a, T> { + r: &'a core::cell::UnsafeCell, +} + +#[rustc_dump_variances] +fn x(_t: T) -> U { + todo!() +} diff --git a/tests/ui/attributes/doc_examples/rustc_dump_variances.stderr b/tests/ui/attributes/doc_examples/rustc_dump_variances.stderr new file mode 100644 index 0000000000000..4680ca94b5ec8 --- /dev/null +++ b/tests/ui/attributes/doc_examples/rustc_dump_variances.stderr @@ -0,0 +1,26 @@ +error: ['a: +, T: +] + --> $DIR/rustc_dump_variances.rs:7:1 + | +7 | struct Ref<'a, T> { + | ^^^^^^^^^^^^^^^^^ + +error: ['a: +, T: o] + --> $DIR/rustc_dump_variances.rs:12:1 + | +12 | struct RefMut<'a, T> { + | ^^^^^^^^^^^^^^^^^^^^ + +error: ['a: +, T: o] + --> $DIR/rustc_dump_variances.rs:17:1 + | +17 | struct CellRef<'a, T> { + | ^^^^^^^^^^^^^^^^^^^^^ + +error: [T: -, U: +] + --> $DIR/rustc_dump_variances.rs:22:1 + | +22 | fn x(_t: T) -> U { + | ^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 4 previous errors + diff --git a/tests/ui/attributes/doc_examples/rustc_dump_variances_of_opaques.rs b/tests/ui/attributes/doc_examples/rustc_dump_variances_of_opaques.rs new file mode 100644 index 0000000000000..924cd923733de --- /dev/null +++ b/tests/ui/attributes/doc_examples/rustc_dump_variances_of_opaques.rs @@ -0,0 +1,16 @@ +//@ dont-require-annotations: ERROR +//@ compile-flags: --crate-type lib -Z ui-testing=no + +#![feature(rustc_attrs)] +#![rustc_dump_variances_of_opaques] + +trait Captures<'a> {} +impl Captures<'_> for T {} + +fn not_captured_early<'a: 'a>() -> impl Sized {} + +fn captured_early<'a: 'a>() -> impl Sized + Captures<'a> {} + +fn not_captured_late<'a>(_: &'a ()) -> impl Sized {} + +fn captured_late<'a>(_: &'a ()) -> impl Sized + Captures<'a> {} diff --git a/tests/ui/attributes/doc_examples/rustc_dump_variances_of_opaques.stderr b/tests/ui/attributes/doc_examples/rustc_dump_variances_of_opaques.stderr new file mode 100644 index 0000000000000..2c89b9473bd29 --- /dev/null +++ b/tests/ui/attributes/doc_examples/rustc_dump_variances_of_opaques.stderr @@ -0,0 +1,26 @@ +error: ['a: *] + --> $DIR/rustc_dump_variances_of_opaques.rs:10:36 + | +10 | fn not_captured_early<'a: 'a>() -> impl Sized {} + | ^^^^^^^^^^ + +error: ['a: *, 'a: o] + --> $DIR/rustc_dump_variances_of_opaques.rs:12:32 + | +12 | fn captured_early<'a: 'a>() -> impl Sized + Captures<'a> {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: [] + --> $DIR/rustc_dump_variances_of_opaques.rs:14:40 + | +14 | fn not_captured_late<'a>(_: &'a ()) -> impl Sized {} + | ^^^^^^^^^^ + +error: ['a: o] + --> $DIR/rustc_dump_variances_of_opaques.rs:16:36 + | +16 | fn captured_late<'a>(_: &'a ()) -> impl Sized + Captures<'a> {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 4 previous errors + diff --git a/tests/ui/attributes/doc_examples/rustc_dump_vtable.rs b/tests/ui/attributes/doc_examples/rustc_dump_vtable.rs new file mode 100644 index 0000000000000..e061406858d23 --- /dev/null +++ b/tests/ui/attributes/doc_examples/rustc_dump_vtable.rs @@ -0,0 +1,20 @@ +//@ dont-require-annotations: ERROR +//@ compile-flags: --crate-type lib -Z ui-testing=no + +#![feature(rustc_attrs)] + +#[rustc_dump_vtable] +type X = dyn Send; + +#[rustc_dump_vtable] +type Y = dyn core::any::Any; + +struct C; + +#[rustc_dump_vtable] +impl Iterator for C { + type Item = (); + fn next(&mut self) -> Option { + Some(()) + } +} diff --git a/tests/ui/attributes/doc_examples/rustc_dump_vtable.stderr b/tests/ui/attributes/doc_examples/rustc_dump_vtable.stderr new file mode 100644 index 0000000000000..32c43b71b9aad --- /dev/null +++ b/tests/ui/attributes/doc_examples/rustc_dump_vtable.stderr @@ -0,0 +1,37 @@ +error: vtable entries: [ + MetadataDropInPlace, + MetadataSize, + MetadataAlign, + ] + --> $DIR/rustc_dump_vtable.rs:7:1 + | +7 | type X = dyn Send; + | ^^^^^^ + +error: vtable entries: [ + MetadataDropInPlace, + MetadataSize, + MetadataAlign, + Method(::type_id - shim(reify)), + ] + --> $DIR/rustc_dump_vtable.rs:10:1 + | +10 | type Y = dyn core::any::Any; + | ^^^^^^ + +error: vtable entries: [ + MetadataDropInPlace, + MetadataSize, + MetadataAlign, + Method(::next), + Method(::size_hint), + Method(::advance_by), + Method(::nth), + ] + --> $DIR/rustc_dump_vtable.rs:15:1 + | +15 | impl Iterator for C { + | ^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 3 previous errors + diff --git a/tests/ui/attributes/dump-clauses.rs b/tests/ui/attributes/dump-clauses.rs deleted file mode 100644 index 7191fe3f57acf..0000000000000 --- a/tests/ui/attributes/dump-clauses.rs +++ /dev/null @@ -1,20 +0,0 @@ -//@ normalize-stderr: "DefId\(.+?\)" -> "DefId(..)" - -#![feature(rustc_attrs)] - -#[rustc_dump_clauses] -trait Trait: Iterator -//~^ ERROR rustc_dump_clauses -where - String: From -{ - #[rustc_dump_clauses] - #[rustc_dump_item_bounds] - type Assoc: std::ops::Deref - //~^ ERROR rustc_dump_clauses - //~| ERROR rustc_dump_item_bounds - where - Self::Assoc<()>: Copy; -} - -fn main() {} diff --git a/tests/ui/attributes/dump-clauses.stderr b/tests/ui/attributes/dump-clauses.stderr deleted file mode 100644 index 93d2057d88cd5..0000000000000 --- a/tests/ui/attributes/dump-clauses.stderr +++ /dev/null @@ -1,41 +0,0 @@ -error: rustc_dump_clauses - --> $DIR/dump-clauses.rs:6:1 - | -LL | trait Trait: Iterator - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: Binder { value: TraitClause(, polarity:Positive), bound_vars: [] } - = note: Binder { value: TraitClause(, polarity:Positive), bound_vars: [] } - = note: Binder { value: TraitClause(<::Item as std::marker::Copy>, polarity:Positive), bound_vars: [] } - = note: Binder { value: TraitClause(, polarity:Positive), bound_vars: [] } - = note: Binder { value: TraitClause(>, polarity:Positive), bound_vars: [] } - = note: Binder { value: TraitClause(>, polarity:Positive), bound_vars: [] } - -error: rustc_dump_clauses - --> $DIR/dump-clauses.rs:13:5 - | -LL | type Assoc: std::ops::Deref - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: Binder { value: TraitClause(, polarity:Positive), bound_vars: [] } - = note: Binder { value: TraitClause(, polarity:Positive), bound_vars: [] } - = note: Binder { value: TraitClause(<::Item as std::marker::Copy>, polarity:Positive), bound_vars: [] } - = note: Binder { value: TraitClause(, polarity:Positive), bound_vars: [] } - = note: Binder { value: TraitClause(>, polarity:Positive), bound_vars: [] } - = note: Binder { value: TraitClause(>, polarity:Positive), bound_vars: [] } - = note: Binder { value: TraitClause(

, polarity:Positive), bound_vars: [] } - = note: Binder { value: TraitClause(

, polarity:Positive), bound_vars: [] } - = note: Binder { value: TraitClause(<>::Assoc<()> as std::marker::Copy>, polarity:Positive), bound_vars: [] } - -error: rustc_dump_item_bounds - --> $DIR/dump-clauses.rs:13:5 - | -LL | type Assoc: std::ops::Deref - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: Binder { value: ProjectionClause(Alias { kind: ProjectionTy { def_id: DefId(..) }, args: [Alias(No, Alias { kind: Projection { def_id: DefId(..) }, args: [Self/#0, T/#1, P/#2], .. })], .. }, Term::Ty(())), bound_vars: [] } - = note: Binder { value: TraitClause(<>::Assoc

as std::ops::Deref>, polarity:Positive), bound_vars: [] } - = note: Binder { value: TraitClause(<>::Assoc

as std::marker::Sized>, polarity:Positive), bound_vars: [] } - -error: aborting due to 3 previous errors - diff --git a/tests/ui/nll/polonius/boring-local-drop-liveness.nll.stderr b/tests/ui/nll/polonius/boring-local-drop-liveness.nll.stderr new file mode 100644 index 0000000000000..1618679c8b2d4 --- /dev/null +++ b/tests/ui/nll/polonius/boring-local-drop-liveness.nll.stderr @@ -0,0 +1,32 @@ +error[E0506]: cannot assign to `*x` because it is borrowed + --> $DIR/boring-local-drop-liveness.rs:28:5 + | +LL | fn assigning_under_a_live_destructor<'a>( + | -- lifetime `'a` defined here +... +LL | *slot = Some(d.0); + | ----------------- assignment requires that `*x` is borrowed for `'a` +LL | d = D(&*x); + | --- `*x` is borrowed here +LL | *x = String::new(); + | ^^ `*x` is assigned to here but it was already borrowed + +error[E0597]: `local` does not live long enough + --> $DIR/boring-local-drop-liveness.rs:35:11 + | +LL | fn dropping_under_a_live_destructor<'a>(x: &'a String, slot: &mut Option<&'a String>) { + | -- lifetime `'a` defined here +LL | let mut d = D(x); +LL | *slot = Some(d.0); + | ----------------- assignment requires that `local` is borrowed for `'a` +LL | let local = String::from("gone"); + | ----- binding `local` declared here +LL | d = D(&local); + | ^^^^^^ borrowed value does not live long enough +LL | } + | - `local` dropped here while still borrowed + +error: aborting due to 2 previous errors + +Some errors have detailed explanations: E0506, E0597. +For more information about an error, try `rustc --explain E0506`. diff --git a/tests/ui/nll/polonius/boring-local-drop-liveness.polonius_next.stderr b/tests/ui/nll/polonius/boring-local-drop-liveness.polonius_next.stderr new file mode 100644 index 0000000000000..1618679c8b2d4 --- /dev/null +++ b/tests/ui/nll/polonius/boring-local-drop-liveness.polonius_next.stderr @@ -0,0 +1,32 @@ +error[E0506]: cannot assign to `*x` because it is borrowed + --> $DIR/boring-local-drop-liveness.rs:28:5 + | +LL | fn assigning_under_a_live_destructor<'a>( + | -- lifetime `'a` defined here +... +LL | *slot = Some(d.0); + | ----------------- assignment requires that `*x` is borrowed for `'a` +LL | d = D(&*x); + | --- `*x` is borrowed here +LL | *x = String::new(); + | ^^ `*x` is assigned to here but it was already borrowed + +error[E0597]: `local` does not live long enough + --> $DIR/boring-local-drop-liveness.rs:35:11 + | +LL | fn dropping_under_a_live_destructor<'a>(x: &'a String, slot: &mut Option<&'a String>) { + | -- lifetime `'a` defined here +LL | let mut d = D(x); +LL | *slot = Some(d.0); + | ----------------- assignment requires that `local` is borrowed for `'a` +LL | let local = String::from("gone"); + | ----- binding `local` declared here +LL | d = D(&local); + | ^^^^^^ borrowed value does not live long enough +LL | } + | - `local` dropped here while still borrowed + +error: aborting due to 2 previous errors + +Some errors have detailed explanations: E0506, E0597. +For more information about an error, try `rustc --explain E0506`. diff --git a/tests/ui/nll/polonius/boring-local-drop-liveness.rs b/tests/ui/nll/polonius/boring-local-drop-liveness.rs new file mode 100644 index 0000000000000..d473a2faeb5c5 --- /dev/null +++ b/tests/ui/nll/polonius/boring-local-drop-liveness.rs @@ -0,0 +1,38 @@ +// Polonius requires liveness for some locals that NLL leaves "boring": locals +// containing some region that outlives a universal region but is not universal itself. +// +// This test checks that we correctly compute liveness for NLL-boring locals that +// are live only because of their drop. + +//@ ignore-compare-mode-polonius (explicit revisions) +//@ revisions: nll polonius_next +//@ [nll] compile-flags: -Zpolonius=off +//@ [polonius_next] compile-flags: -Zpolonius=next + +struct D<'a>(&'a String); + +impl<'a> Drop for D<'a> { + fn drop(&mut self) { + println!("{}", self.0); + } +} + +fn assigning_under_a_live_destructor<'a>( + x: &'a mut String, + slot: &mut Option<&'a String>, + y: &'a String, +) { + let mut d = D(y); + *slot = Some(d.0); + d = D(&*x); + *x = String::new(); //~ ERROR cannot assign to `*x` because it is borrowed +} + +fn dropping_under_a_live_destructor<'a>(x: &'a String, slot: &mut Option<&'a String>) { + let mut d = D(x); + *slot = Some(d.0); + let local = String::from("gone"); + d = D(&local); //~ ERROR `local` does not live long enough +} + +fn main() {} diff --git a/tests/ui/nll/polonius/boring-local-liveness.nll.stderr b/tests/ui/nll/polonius/boring-local-liveness.nll.stderr new file mode 100644 index 0000000000000..5d5c46a97e946 --- /dev/null +++ b/tests/ui/nll/polonius/boring-local-liveness.nll.stderr @@ -0,0 +1,30 @@ +error[E0506]: cannot assign to `*x` because it is borrowed + --> $DIR/boring-local-liveness.rs:22:5 + | +LL | fn assigning_into_a_slot<'a>(x: &'a mut u32, slot: &mut Option>) { + | -- lifetime `'a` defined here +LL | let r: &'a u32 = &*x; + | ------- --- `*x` is borrowed here + | | + | type annotation requires that `*x` is borrowed for `'a` +LL | *slot = Some(D(r)); +LL | *x = 1; + | ^^^^^^ `*x` is assigned to here but it was already borrowed + +error[E0506]: cannot assign to `*x` because it is borrowed + --> $DIR/boring-local-liveness.rs:32:5 + | +LL | fn clearing_the_slot_does_not_release_it<'a>(x: &'a mut u32, slot: &mut Option>) { + | -- lifetime `'a` defined here +LL | { +LL | let r: &'a u32 = &*x; + | ------- --- `*x` is borrowed here + | | + | type annotation requires that `*x` is borrowed for `'a` +... +LL | *x = 1; + | ^^^^^^ `*x` is assigned to here but it was already borrowed + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0506`. diff --git a/tests/ui/nll/polonius/boring-local-liveness.polonius_next.stderr b/tests/ui/nll/polonius/boring-local-liveness.polonius_next.stderr new file mode 100644 index 0000000000000..5d5c46a97e946 --- /dev/null +++ b/tests/ui/nll/polonius/boring-local-liveness.polonius_next.stderr @@ -0,0 +1,30 @@ +error[E0506]: cannot assign to `*x` because it is borrowed + --> $DIR/boring-local-liveness.rs:22:5 + | +LL | fn assigning_into_a_slot<'a>(x: &'a mut u32, slot: &mut Option>) { + | -- lifetime `'a` defined here +LL | let r: &'a u32 = &*x; + | ------- --- `*x` is borrowed here + | | + | type annotation requires that `*x` is borrowed for `'a` +LL | *slot = Some(D(r)); +LL | *x = 1; + | ^^^^^^ `*x` is assigned to here but it was already borrowed + +error[E0506]: cannot assign to `*x` because it is borrowed + --> $DIR/boring-local-liveness.rs:32:5 + | +LL | fn clearing_the_slot_does_not_release_it<'a>(x: &'a mut u32, slot: &mut Option>) { + | -- lifetime `'a` defined here +LL | { +LL | let r: &'a u32 = &*x; + | ------- --- `*x` is borrowed here + | | + | type annotation requires that `*x` is borrowed for `'a` +... +LL | *x = 1; + | ^^^^^^ `*x` is assigned to here but it was already borrowed + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0506`. diff --git a/tests/ui/nll/polonius/boring-local-liveness.rs b/tests/ui/nll/polonius/boring-local-liveness.rs new file mode 100644 index 0000000000000..86ddcfc6b0119 --- /dev/null +++ b/tests/ui/nll/polonius/boring-local-liveness.rs @@ -0,0 +1,35 @@ +// Polonius requires liveness for some locals that NLL leaves "boring": locals +// containing some region that outlives a universal region but is not universal itself. +// +// This test checks that we correctly compute liveness for NLL-boring locals that +// are live because of a use. + +//@ ignore-compare-mode-polonius (explicit revisions) +//@ revisions: nll polonius_next +//@ [nll] compile-flags: -Zpolonius=off +//@ [polonius_next] compile-flags: -Zpolonius=next + +struct D<'a>(&'a u32); + +impl<'a> Drop for D<'a> { + fn drop(&mut self) {} +} + +// The loan of `*x` flows into `slot`'s region, which outlives `'a` and so is boring to NLLs. +fn assigning_into_a_slot<'a>(x: &'a mut u32, slot: &mut Option>) { + let r: &'a u32 = &*x; + *slot = Some(D(r)); + *x = 1; //~ ERROR cannot assign to `*x` because it is borrowed +} + +// The same, with the borrow confined to an inner scope and the slot cleared afterwards. +fn clearing_the_slot_does_not_release_it<'a>(x: &'a mut u32, slot: &mut Option>) { + { + let r: &'a u32 = &*x; + *slot = Some(D(r)); + } + *slot = None; + *x = 1; //~ ERROR cannot assign to `*x` because it is borrowed +} + +fn main() {}