authorbors <bors@rust-lang.org> 2026-05-05 07:17:39 UTC
committerbors <bors@rust-lang.org> 2026-05-05 07:17:39 UTC
log4feb7221f4d445120a5061b16ce7222adbfdf6f6
tree1fb71b8922fb6c1cf4939199997fb707c7a20262
parent83adf7e080d0fe4f0970c00eac2976a767dbd042
parentba38fa014737aed9ec416f9a10432d64da7e1524

Auto merge of #156166 - GuillaumeGomez:rollup-nfRhhYb, r=GuillaumeGomez

Rollup of 16 pull requests Successful merges: - rust-lang/rust#155848 ([doc]: Revert `core::io::ErrorKind` doc changes) - rust-lang/rust#155855 (Remove unnecessary `get_unchecked`) - rust-lang/rust#155543 (docs(unstable-book): Document const generics features) - rust-lang/rust#155962 (`rustc`: `target_features`: allow for `cfg`-only stable `target_features`) - rust-lang/rust#156043 (c-variadic: gate `va_arg` on `c_variadic_experimental_arch`) - rust-lang/rust#156082 (Move tests associated types) - rust-lang/rust#156087 (Improve `&pin` reference-pattern suggestions) - rust-lang/rust#156092 (Clean up `TyCtxt::needs_crate_hash` usage and rename it to `needs_hir_hash`.) - rust-lang/rust#156103 (Fix E0040 suggestion for explicit `Drop::drop` UFCS calls) - rust-lang/rust#156104 (Relax `T: Sized` bound on `try_as_dyn` / `try_as_dyn_mut`) - rust-lang/rust#156122 (Add a `doc_cfg` regression test to ensure foreign types impls are working as expected) - rust-lang/rust#156128 (.mailmap: prefer matching just based on commit emails) - rust-lang/rust#156135 (Remove most uses of def_id_to_node_id) - rust-lang/rust#156152 (Update books) - rust-lang/rust#156154 (tests: mark import UI tests as check-pass) - rust-lang/rust#156162 (Update `browser-ui-test` version to `0.23.5`)

110 files changed, 1496 insertions(+), 686 deletions(-)

.mailmap+3-5
......@@ -259,11 +259,9 @@ Gregor Peach <gregorpeach@gmail.com>
259259Grzegorz Bartoszek <grzegorz.bartoszek@thaumatec.com>
260260Guanqun Lu <guanqun.lu@gmail.com>
261261Guillaume Gomez <contact@guillaume-gomez.fr>
262Guillaume Gomez <contact@guillaume-gomez.fr> Guillaume Gomez <guillaume1.gomez@gmail.com>
263Guillaume Gomez <contact@guillaume-gomez.fr> ggomez <guillaume1.gomez@gmail.com>
264Guillaume Gomez <contact@guillaume-gomez.fr> ggomez <ggomez@ggo.ifr.lan>
265Guillaume Gomez <contact@guillaume-gomez.fr> Guillaume Gomez <ggomez@ggo.ifr.lan>
266Guillaume Gomez <contact@guillaume-gomez.fr> Guillaume Gomez <guillaume.gomez@huawei.com>
262Guillaume Gomez <contact@guillaume-gomez.fr> <guillaume1.gomez@gmail.com>
263Guillaume Gomez <contact@guillaume-gomez.fr> <ggomez@ggo.ifr.lan>
264Guillaume Gomez <contact@guillaume-gomez.fr> <guillaume.gomez@huawei.com>
267265gnzlbg <gonzalobg88@gmail.com> <gnzlbg@users.noreply.github.com>
268266hamidreza kalbasi <hamidrezakalbasi@protonmail.com>
269267Hanna Kruppe <hanna.kruppe@gmail.com> <robin.kruppe@gmail.com>
compiler/rustc_ast_lowering/src/lib.rs+1-1
......@@ -562,7 +562,7 @@ pub fn lower_to_hir(tcx: TyCtxt<'_>, (): ()) -> mid_hir::Crate<'_> {
562562
563563 // Don't hash unless necessary, because it's expensive.
564564 let opt_hir_hash =
565 if tcx.needs_crate_hash() { Some(compute_hir_hash(tcx, &owners)) } else { None };
565 if tcx.needs_hir_hash() { Some(compute_hir_hash(tcx, &owners)) } else { None };
566566
567567 let delayed_resolver = Steal::new((resolver, krate));
568568 mid_hir::Crate::new(owners, delayed_ids, delayed_resolver, opt_hir_hash)
compiler/rustc_codegen_llvm/src/intrinsic.rs+13-2
......@@ -3,8 +3,8 @@ use std::ffi::c_uint;
33use std::{assert_matches, iter, ptr};
44
55use rustc_abi::{
6 AddressSpace, Align, BackendRepr, Float, HasDataLayout, Integer, NumScalableVectors, Primitive,
7 Size, WrappingRange,
6 AddressSpace, Align, BackendRepr, CVariadicStatus, Float, HasDataLayout, Integer,
7 NumScalableVectors, Primitive, Size, WrappingRange,
88};
99use rustc_codegen_ssa::base::{compare_simd_types, wants_msvc_seh, wants_wasm_eh};
1010use rustc_codegen_ssa::common::{IntPredicate, TypeKind};
......@@ -23,6 +23,7 @@ use rustc_middle::ty::{
2323};
2424use rustc_middle::{bug, span_bug};
2525use rustc_session::config::CrateType;
26use rustc_session::errors::feature_err;
2627use rustc_session::lint::builtin::DEPRECATED_LLVM_INTRINSIC;
2728use rustc_span::{Span, Symbol, sym};
2829use rustc_symbol_mangling::{mangle_internal_symbol, symbol_name_for_instance_in_crate};
......@@ -288,6 +289,16 @@ impl<'ll, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
288289 }
289290 sym::breakpoint => self.call_intrinsic("llvm.debugtrap", &[], &[]),
290291 sym::va_arg => {
292 let target = &self.cx.tcx.sess.target;
293 let stability = target.supports_c_variadic_definitions();
294 if let CVariadicStatus::Unstable { feature } = stability
295 && !self.tcx.features().enabled(feature)
296 {
297 let msg =
298 format!("C-variadic function definitions on this target are unstable");
299 feature_err(&*self.sess(), feature, span, msg).emit();
300 }
301
291302 let BackendRepr::Scalar(scalar) = result.layout.backend_repr else {
292303 bug!("the va_arg intrinsic does not support non-scalar types")
293304 };
compiler/rustc_codegen_ssa/src/errors.rs+2-1
......@@ -1212,9 +1212,10 @@ pub(crate) struct UnknownCTargetFeature<'a> {
12121212
12131213#[derive(Diagnostic)]
12141214#[diag("unstable feature specified for `-Ctarget-feature`: `{$feature}`")]
1215#[note("this feature is not stably supported; its behavior can change in the future")]
1215#[note("{$note}; its behavior can change in the future")]
12161216pub(crate) struct UnstableCTargetFeature<'a> {
12171217 pub feature: &'a str,
1218 pub note: &'a str,
12181219}
12191220
12201221#[derive(Diagnostic)]
compiler/rustc_codegen_ssa/src/target_features.rs+19-12
......@@ -62,16 +62,15 @@ pub(crate) fn from_target_feature_attr(
6262 feature: feature_str,
6363 reason,
6464 });
65 } else if let Some(nightly_feature) = stability.requires_nightly()
65 } else if let Some(nightly_feature) = stability.requires_nightly(/* in_cfg */ false)
6666 && !rust_features.enabled(nightly_feature)
6767 {
68 feature_err(
69 &tcx.sess,
70 nightly_feature,
71 feature_span,
72 format!("the target feature `{feature}` is currently unstable"),
73 )
74 .emit();
68 let explain = if stability.is_cfg_stable_toggle_unstable() {
69 format!("the target feature `{feature}` is allowed in cfg but unstable otherwise")
70 } else {
71 format!("the target feature `{feature}` is currently unstable")
72 };
73 feature_err(&tcx.sess, nightly_feature, feature_span, explain).emit();
7574 } else {
7675 // Add this and the implied features.
7776 for &name in tcx.implied_target_features(feature) {
......@@ -315,12 +314,19 @@ pub fn cfg_target_feature<'a, const N: usize>(
315314 enabled: if enable { "enabled" } else { "disabled" },
316315 reason,
317316 });
318 } else if stability.requires_nightly().is_some() {
317 } else if stability.requires_nightly(/* in_cfg */ false).is_some() {
319318 // An unstable feature. Warn about using it. It makes little sense
320319 // to hard-error here since we just warn about fully unknown
321320 // features above.
322 sess.dcx()
323 .emit_warn(errors::UnstableCTargetFeature { feature: base_feature });
321 let note = if stability.is_cfg_stable_toggle_unstable() {
322 "this feature is allowed in cfg but unstable otherwise"
323 } else {
324 "this feature is not stably supported"
325 };
326 sess.dcx().emit_warn(errors::UnstableCTargetFeature {
327 feature: base_feature,
328 note,
329 });
324330 }
325331 }
326332 }
......@@ -346,7 +352,8 @@ pub fn cfg_target_feature<'a, const N: usize>(
346352 // "forbidden" features.
347353 if allow_unstable
348354 || (gate.in_cfg()
349 && (sess.is_nightly_build() || gate.requires_nightly().is_none()))
355 && (sess.is_nightly_build()
356 || gate.requires_nightly(/* in_cfg */ true).is_none()))
350357 {
351358 Some(Symbol::intern(feature))
352359 } else {
compiler/rustc_feature/src/unstable.rs+5-3
......@@ -563,8 +563,9 @@ declare_features! (
563563 /// Allows defining gen blocks and `gen fn`.
564564 (unstable, gen_blocks, "1.75.0", Some(117078)),
565565 /// Allows using generics in more complex const expressions, based on definitional equality.
566 (unstable, generic_const_args, "1.95.0", Some(151972)),
567 /// Allows non-trivial generic constants which have to have wfness manually propagated to callers
566 (incomplete, generic_const_args, "1.95.0", Some(151972)),
567 /// Allows non-trivial generic constants which have to be shown to successfully evaluate
568 /// to a value by being part of an item signature.
568569 (incomplete, generic_const_exprs, "1.56.0", Some(76560)),
569570 /// Allows generic parameters and where-clauses on free & associated const items.
570571 (incomplete, generic_const_items, "1.73.0", Some(113521)),
......@@ -626,7 +627,8 @@ declare_features! (
626627 /// Allows additional const parameter types, such as [u8; 10] or user defined types.
627628 /// User defined types must not have fields more private than the type itself.
628629 (unstable, min_adt_const_params, "1.96.0", Some(154042)),
629 /// Enables the generic const args MVP (only bare paths, not arbitrary computation).
630 /// Enables the generic const args MVP (paths to type const items and constructors
631 /// for ADTs and primitives).
630632 (incomplete, min_generic_const_args, "1.84.0", Some(132980)),
631633 /// A minimal, sound subset of specialization intended to be used by the
632634 /// standard library until the soundness issues with specialization
compiler/rustc_hir_typeck/src/callee.rs+1-1
......@@ -42,7 +42,7 @@ pub(crate) fn check_legal_trait_for_method_call(
4242 if tcx.is_lang_item(trait_id, LangItem::Drop) {
4343 let sugg = if let Some(receiver) = receiver.filter(|s| !s.is_empty()) {
4444 errors::ExplicitDestructorCallSugg::Snippet {
45 lo: expr_span.shrink_to_lo(),
45 lo: expr_span.shrink_to_lo().to(receiver.shrink_to_lo()),
4646 hi: receiver.shrink_to_hi().to(expr_span.shrink_to_hi()),
4747 }
4848 } else {
compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs+15-1
......@@ -1007,10 +1007,24 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10071007 debug!(?def_id, ?container, ?container_id);
10081008 match container {
10091009 ty::AssocContainer::Trait => {
1010 let arg_span = if let hir::Node::Expr(call_expr) =
1011 self.tcx.parent_hir_node(hir_id)
1012 && let hir::ExprKind::Call(_, args) = call_expr.kind
1013 && let Some(first_arg) = args.first()
1014 {
1015 let mut arg = first_arg;
1016 while let hir::ExprKind::AddrOf(_, _, inner) = arg.kind {
1017 arg = inner;
1018 }
1019 Some(arg.span)
1020 } else {
1021 None
1022 };
1023
10101024 if let Err(e) = callee::check_legal_trait_for_method_call(
10111025 tcx,
10121026 path_span,
1013 None,
1027 arg_span,
10141028 span,
10151029 container_id,
10161030 self.body_id.to_def_id(),
compiler/rustc_hir_typeck/src/pat.rs+9-2
......@@ -1352,7 +1352,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
13521352 }
13531353
13541354 /// Precondition: pat is a `Ref(_)` pattern
1355 // FIXME(pin_ergonomics): add suggestions for `&pin mut` or `&pin const` patterns
13561355 fn borrow_pat_suggestion(&self, err: &mut Diag<'_>, pat: &Pat<'_>) {
13571356 let tcx = self.tcx;
13581357 if let PatKind::Ref(inner, pinned, mutbl) = pat.kind
......@@ -1407,6 +1406,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14071406 };
14081407
14091408 match binding_parent {
1409 hir::Node::Param(hir::Param { ty_span, pat, .. })
1410 if pat.span != *ty_span
1411 && pinned.is_pinned()
1412 && !tcx.features().pin_ergonomics() =>
1413 {
1414 // FIXME(pin_ergonomics): Once `pin_ergonomics` is stabilized, remove this
1415 // gate and allow the pinned reference type-position suggestion unconditionally.
1416 }
14101417 // Check that there is explicit type (ie this is not a closure param with inferred type)
14111418 // so we don't suggest moving something to the type that does not exist
14121419 hir::Node::Param(hir::Param { ty_span, pat, .. }) if pat.span != *ty_span => {
......@@ -1414,7 +1421,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14141421 format!("to take parameter `{binding}` by reference, move `&{pin_and_mut}` to the type"),
14151422 vec![
14161423 (pat.span.until(inner.span), "".to_owned()),
1417 (ty_span.shrink_to_lo(), mutbl.ref_prefix_str().to_owned()),
1424 (ty_span.shrink_to_lo(), format!("&{}", pinned.prefix_str(mutbl))),
14181425 ],
14191426 Applicability::MachineApplicable
14201427 );
compiler/rustc_interface/src/queries.rs+1-1
......@@ -36,7 +36,7 @@ impl Linker {
3636 Linker {
3737 dep_graph: tcx.dep_graph.clone(),
3838 output_filenames: Arc::clone(tcx.output_filenames(())),
39 crate_hash: if tcx.needs_crate_hash() {
39 crate_hash: if tcx.sess.opts.incremental.is_some() {
4040 Some(tcx.crate_hash(LOCAL_CRATE))
4141 } else {
4242 None
compiler/rustc_middle/src/hir/mod.rs+1-1
......@@ -237,7 +237,7 @@ impl<'tcx> TyCtxt<'tcx> {
237237 attrs: &SortedMap<ItemLocalId, &[Attribute]>,
238238 define_opaque: Option<&[(Span, LocalDefId)]>,
239239 ) -> Hashes {
240 if !self.needs_crate_hash() {
240 if !self.needs_hir_hash() {
241241 return Hashes { opt_hash_including_bodies: None, attrs_hash: None };
242242 }
243243
compiler/rustc_middle/src/ty/context.rs+3-3
......@@ -1127,12 +1127,12 @@ impl<'tcx> TyCtxt<'tcx> {
11271127 })
11281128 }
11291129
1130 pub fn needs_crate_hash(self) -> bool {
1131 // Why is the crate hash needed for these configurations?
1130 pub fn needs_hir_hash(self) -> bool {
1131 // Why is the hir hash needed for these configurations?
11321132 // - debug_assertions: for the "fingerprint the result" check in
11331133 // `rustc_query_impl::execution::execute_job`.
11341134 // - incremental: for query lookups.
1135 // - needs_metadata: for putting into crate metadata.
1135 // - needs_metadata: it is included in the crate metadata through the crate_hash query
11361136 // - instrument_coverage: for putting into coverage data (see
11371137 // `hash_mir_source`).
11381138 // - metrics_dir: metrics use the strict version hash in the filenames
compiler/rustc_resolve/src/build_reduced_graph.rs+12-6
......@@ -9,8 +9,9 @@ use std::sync::Arc;
99
1010use rustc_ast::visit::{self, AssocCtxt, Visitor, WalkItemKind};
1111use rustc_ast::{
12 self as ast, AssocItem, AssocItemKind, Block, ConstItem, Delegation, Fn, ForeignItem,
13 ForeignItemKind, Inline, Item, ItemKind, NodeId, StaticItem, StmtKind, TraitAlias, TyAlias,
12 self as ast, AssocItem, AssocItemKind, Block, ConstItem, DUMMY_NODE_ID, Delegation, Fn,
13 ForeignItem, ForeignItemKind, Inline, Item, ItemKind, NodeId, StaticItem, StmtKind, TraitAlias,
14 TyAlias,
1415};
1516use rustc_attr_parsing::AttributeParser;
1617use rustc_expand::base::ResolverExpand;
......@@ -168,7 +169,12 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
168169 let expn_id = self.cstore().expn_that_defined_untracked(self.tcx, def_id);
169170 let module = self.new_extern_module(
170171 parent,
171 ModuleKind::Def(def_kind, def_id, Some(self.tcx.item_name(def_id))),
172 ModuleKind::Def(
173 def_kind,
174 def_id,
175 DUMMY_NODE_ID,
176 Some(self.tcx.item_name(def_id)),
177 ),
172178 expn_id,
173179 self.def_span(def_id),
174180 // FIXME: Account for `#[no_implicit_prelude]` attributes.
......@@ -251,7 +257,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
251257 // Any inherited visibility resolved directly inside an enum or trait
252258 // (i.e. variants, fields, and trait items) inherits from the visibility
253259 // of the enum or trait.
254 ModuleKind::Def(DefKind::Enum | DefKind::Trait, def_id, _) => {
260 ModuleKind::Def(DefKind::Enum | DefKind::Trait, def_id, _, _) => {
255261 self.tcx.visibility(def_id).expect_local()
256262 }
257263 // Otherwise, the visibility is restricted to the nearest parent `mod` item.
......@@ -848,7 +854,7 @@ impl<'a, 'ra, 'tcx> DefCollector<'a, 'ra, 'tcx> {
848854 }
849855 let module = self.r.new_local_module(
850856 Some(parent),
851 ModuleKind::Def(def_kind, def_id, Some(ident.name)),
857 ModuleKind::Def(def_kind, def_id, item.id, Some(ident.name)),
852858 expansion.to_expn_id(),
853859 item.span,
854860 parent.no_implicit_prelude
......@@ -882,7 +888,7 @@ impl<'a, 'ra, 'tcx> DefCollector<'a, 'ra, 'tcx> {
882888
883889 let module = self.r.new_local_module(
884890 Some(parent),
885 ModuleKind::Def(def_kind, def_id, Some(ident.name)),
891 ModuleKind::Def(def_kind, def_id, item.id, Some(ident.name)),
886892 expansion.to_expn_id(),
887893 item.span,
888894 parent.no_implicit_prelude,
compiler/rustc_resolve/src/diagnostics.rs+22-21
......@@ -5,7 +5,8 @@ use std::ops::ControlFlow;
55use itertools::Itertools as _;
66use rustc_ast::visit::{self, Visitor};
77use rustc_ast::{
8 self as ast, CRATE_NODE_ID, Crate, ItemKind, ModKind, NodeId, Path, join_path_idents,
8 self as ast, CRATE_NODE_ID, Crate, DUMMY_NODE_ID, ItemKind, ModKind, NodeId, Path,
9 join_path_idents,
910};
1011use rustc_ast_pretty::pprust;
1112use rustc_data_structures::fx::{FxHashMap, FxHashSet};
......@@ -192,11 +193,11 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
192193 }
193194
194195 fn report_with_use_injections(&mut self, krate: &Crate) {
195 for UseError { mut err, candidates, def_id, instead, suggestion, path, is_call } in
196 for UseError { mut err, candidates, node_id, instead, suggestion, path, is_call } in
196197 mem::take(&mut self.use_injections)
197198 {
198 let (span, found_use) = if let Some(def_id) = def_id.as_local() {
199 UsePlacementFinder::check(krate, self.def_id_to_node_id(def_id))
199 let (span, found_use) = if node_id != DUMMY_NODE_ID {
200 UsePlacementFinder::check(krate, node_id)
200201 } else {
201202 (None, FoundUse::No)
202203 };
......@@ -242,7 +243,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
242243 let container = match old_binding.parent_module.unwrap().kind {
243244 // Avoid using TyCtxt::def_kind_descr in the resolver, because it
244245 // indirectly *calls* the resolver, and would cause a query cycle.
245 ModuleKind::Def(kind, def_id, _) => kind.descr(def_id),
246 ModuleKind::Def(kind, def_id, _, _) => kind.descr(def_id),
246247 ModuleKind::Block => "block",
247248 };
248249
......@@ -1705,9 +1706,9 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
17051706
17061707 let import_suggestions =
17071708 self.lookup_import_candidates(ident, Namespace::MacroNS, parent_scope, is_expected);
1708 let (span, found_use) = match parent_scope.module.nearest_parent_mod().as_local() {
1709 Some(def_id) => UsePlacementFinder::check(krate, self.def_id_to_node_id(def_id)),
1710 None => (None, FoundUse::No),
1709 let (span, found_use) = match parent_scope.module.nearest_parent_mod_node_id() {
1710 DUMMY_NODE_ID => (None, FoundUse::No),
1711 node_id => UsePlacementFinder::check(krate, node_id),
17111712 };
17121713 show_candidates(
17131714 self.tcx,
......@@ -1764,7 +1765,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
17641765 }
17651766
17661767 if ident.name == kw::Default
1767 && let ModuleKind::Def(DefKind::Enum, def_id, _) = parent_scope.module.kind
1768 && let ModuleKind::Def(DefKind::Enum, def_id, _, _) = parent_scope.module.kind
17681769 {
17691770 let span = self.def_span(def_id);
17701771 let source_map = self.tcx.sess.source_map();
......@@ -1892,19 +1893,19 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
18921893 missing a `derive` attribute",
18931894 ident.name,
18941895 );
1895 let sugg_span = if let ModuleKind::Def(DefKind::Enum, id, _) = parent_scope.module.kind
1896 {
1897 let span = self.def_span(id);
1898 if span.from_expansion() {
1899 None
1896 let sugg_span =
1897 if let ModuleKind::Def(DefKind::Enum, id, _, _) = parent_scope.module.kind {
1898 let span = self.def_span(id);
1899 if span.from_expansion() {
1900 None
1901 } else {
1902 // For enum variants sugg_span is empty but we can get the enum's Span.
1903 Some(span.shrink_to_lo())
1904 }
19001905 } else {
1901 // For enum variants sugg_span is empty but we can get the enum's Span.
1902 Some(span.shrink_to_lo())
1903 }
1904 } else {
1905 // For items this `Span` will be populated, everything else it'll be None.
1906 sugg_span
1907 };
1906 // For items this `Span` will be populated, everything else it'll be None.
1907 sugg_span
1908 };
19081909 match sugg_span {
19091910 Some(span) => {
19101911 err.span_suggestion_verbose(
compiler/rustc_resolve/src/ident.rs+1-1
......@@ -644,7 +644,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
644644 }
645645 }
646646 Scope::ModuleGlobs(module, _)
647 if let ModuleKind::Def(_, def_id, _) = module.kind
647 if let ModuleKind::Def(_, def_id, _, _) = module.kind
648648 && !def_id.is_local() =>
649649 {
650650 // Fast path: external module decoding only creates non-glob declarations.
compiler/rustc_resolve/src/late.rs+6-5
......@@ -1941,7 +1941,8 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
19411941 && let Some((module, _)) = &self.current_trait_ref
19421942 && let Some(ty) = &self.diag_metadata.current_self_type
19431943 && Some(true) == self.diag_metadata.in_non_gat_assoc_type
1944 && let crate::ModuleKind::Def(DefKind::Trait, trait_id, _) = module.kind
1944 && let crate::ModuleKind::Def(DefKind::Trait, trait_id, _, _) =
1945 module.kind
19451946 {
19461947 if def_id_matches_path(
19471948 self.r.tcx,
......@@ -4514,7 +4515,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
45144515 parent_qself,
45154516 );
45164517
4517 let def_id = this.parent_scope.module.nearest_parent_mod();
4518 let node_id = this.parent_scope.module.nearest_parent_mod_node_id();
45184519 let instead = res.is_some();
45194520 let (suggestion, const_err) = if let Some((start, end)) =
45204521 this.diag_metadata.in_range
......@@ -4556,7 +4557,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
45564557 let ue = UseError {
45574558 err,
45584559 candidates,
4559 def_id,
4560 node_id,
45604561 instead,
45614562 suggestion,
45624563 path: path.into(),
......@@ -4645,7 +4646,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
46454646
46464647 parent_err.cancel();
46474648
4648 let def_id = this.parent_scope.module.nearest_parent_mod();
4649 let node_id = this.parent_scope.module.nearest_parent_mod_node_id();
46494650
46504651 if this.should_report_errs() {
46514652 if candidates.is_empty() {
......@@ -4670,7 +4671,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
46704671 this.r.use_injections.push(UseError {
46714672 err,
46724673 candidates,
4673 def_id,
4674 node_id,
46744675 instead: false,
46754676 suggestion: None,
46764677 path: prefix_path.into(),
compiler/rustc_resolve/src/lib.rs+23-14
......@@ -543,7 +543,7 @@ enum ModuleKind {
543543 /// The crate root will have `None` for the symbol.
544544 /// * A trait or an enum (it implicitly contains associated types, methods and variant
545545 /// constructors).
546 Def(DefKind, DefId, Option<Symbol>),
546 Def(DefKind, DefId, NodeId, Option<Symbol>),
547547}
548548
549549impl ModuleKind {
......@@ -557,7 +557,7 @@ impl ModuleKind {
557557
558558 fn opt_def_id(&self) -> Option<DefId> {
559559 match self {
560 ModuleKind::Def(_, def_id, _) => Some(*def_id),
560 ModuleKind::Def(_, def_id, _, _) => Some(*def_id),
561561 _ => None,
562562 }
563563 }
......@@ -726,7 +726,7 @@ impl<'ra> ModuleData<'ra> {
726726 self_decl: Option<Decl<'ra>>,
727727 ) -> Self {
728728 let is_foreign = match kind {
729 ModuleKind::Def(_, def_id, _) => !def_id.is_local(),
729 ModuleKind::Def(_, def_id, _, _) => !def_id.is_local(),
730730 ModuleKind::Block => false,
731731 };
732732 ModuleData {
......@@ -756,7 +756,7 @@ impl<'ra> ModuleData<'ra> {
756756
757757 fn res(&self) -> Option<Res> {
758758 match self.kind {
759 ModuleKind::Def(kind, def_id, _) => Some(Res::Def(kind, def_id)),
759 ModuleKind::Def(kind, def_id, _, _) => Some(Res::Def(kind, def_id)),
760760 _ => None,
761761 }
762762 }
......@@ -813,11 +813,11 @@ impl<'ra> Module<'ra> {
813813
814814 // `self` resolves to the first module ancestor that `is_normal`.
815815 fn is_normal(self) -> bool {
816 matches!(self.kind, ModuleKind::Def(DefKind::Mod, _, _))
816 matches!(self.kind, ModuleKind::Def(DefKind::Mod, _, _, _))
817817 }
818818
819819 fn is_trait(self) -> bool {
820 matches!(self.kind, ModuleKind::Def(DefKind::Trait, _, _))
820 matches!(self.kind, ModuleKind::Def(DefKind::Trait, _, _, _))
821821 }
822822
823823 fn nearest_item_scope(self) -> Module<'ra> {
......@@ -833,11 +833,20 @@ impl<'ra> Module<'ra> {
833833 /// This may be the crate root.
834834 fn nearest_parent_mod(self) -> DefId {
835835 match self.kind {
836 ModuleKind::Def(DefKind::Mod, def_id, _) => def_id,
836 ModuleKind::Def(DefKind::Mod, def_id, _, _) => def_id,
837837 _ => self.parent.expect("non-root module without parent").nearest_parent_mod(),
838838 }
839839 }
840840
841 /// The [`NodeId`] of the nearest `mod` item ancestor (which may be this module).
842 /// This may be the crate root.
843 fn nearest_parent_mod_node_id(self) -> NodeId {
844 match self.kind {
845 ModuleKind::Def(DefKind::Mod, _, node_id, _) => node_id,
846 _ => self.parent.expect("non-root module without parent").nearest_parent_mod_node_id(),
847 }
848 }
849
841850 fn is_ancestor_of(self, mut other: Self) -> bool {
842851 while self != other {
843852 if let Some(parent) = other.parent {
......@@ -852,7 +861,7 @@ impl<'ra> Module<'ra> {
852861 #[track_caller]
853862 fn expect_local(self) -> LocalModule<'ra> {
854863 match self.kind {
855 ModuleKind::Def(_, def_id, _) if !def_id.is_local() => {
864 ModuleKind::Def(_, def_id, _, _) if !def_id.is_local() => {
856865 panic!("`Module::expect_local` is called on a non-local module: {self:?}")
857866 }
858867 ModuleKind::Def(..) | ModuleKind::Block => LocalModule(self.0),
......@@ -862,7 +871,7 @@ impl<'ra> Module<'ra> {
862871 #[track_caller]
863872 fn expect_extern(self) -> ExternModule<'ra> {
864873 match self.kind {
865 ModuleKind::Def(_, def_id, _) if !def_id.is_local() => ExternModule(self.0),
874 ModuleKind::Def(_, def_id, _, _) if !def_id.is_local() => ExternModule(self.0),
866875 ModuleKind::Def(..) | ModuleKind::Block => {
867876 panic!("`Module::expect_extern` is called on a local module: {self:?}")
868877 }
......@@ -992,8 +1001,8 @@ struct UseError<'a> {
9921001 err: Diag<'a>,
9931002 /// Candidates which user could `use` to access the missing type.
9941003 candidates: Vec<ImportSuggestion>,
995 /// The `DefId` of the module to place the use-statements in.
996 def_id: DefId,
1004 /// The `NodeId` of the module to place the use-statements in.
1005 node_id: NodeId,
9971006 /// Whether the diagnostic should say "instead" (as in `consider importing ... instead`).
9981007 instead: bool,
9991008 /// Extra free-form suggestion.
......@@ -1551,7 +1560,7 @@ impl<'ra> ResolverArenas<'ra> {
15511560 no_implicit_prelude: bool,
15521561 ) -> Module<'ra> {
15531562 let self_decl = match kind {
1554 ModuleKind::Def(def_kind, def_id, _) => Some(self.new_def_decl(
1563 ModuleKind::Def(def_kind, def_id, _, _) => Some(self.new_def_decl(
15551564 Res::Def(def_kind, def_id),
15561565 vis,
15571566 span,
......@@ -1732,7 +1741,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
17321741 let root_def_id = CRATE_DEF_ID.to_def_id();
17331742 let graph_root = arenas.new_module(
17341743 None,
1735 ModuleKind::Def(DefKind::Mod, root_def_id, None),
1744 ModuleKind::Def(DefKind::Mod, root_def_id, CRATE_NODE_ID, None),
17361745 Visibility::Public,
17371746 ExpnId::root(),
17381747 crate_span,
......@@ -1743,7 +1752,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
17431752 let local_module_map = FxIndexMap::from_iter([(CRATE_DEF_ID, graph_root)]);
17441753 let empty_module = arenas.new_module(
17451754 None,
1746 ModuleKind::Def(DefKind::Mod, root_def_id, None),
1755 ModuleKind::Def(DefKind::Mod, root_def_id, CRATE_NODE_ID, None),
17471756 Visibility::Public,
17481757 ExpnId::root(),
17491758 DUMMY_SP,
compiler/rustc_resolve/src/macros.rs+1-1
......@@ -1185,7 +1185,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
11851185 self.get_mut().record_use(ident, fallback_binding, Used::Other);
11861186 } else {
11871187 let location = match parent_scope.module.kind {
1188 ModuleKind::Def(kind, def_id, name) => {
1188 ModuleKind::Def(kind, def_id, _, name) => {
11891189 if let Some(name) = name {
11901190 format!("{} `{name}`", kind.descr(def_id))
11911191 } else {
compiler/rustc_target/src/target_features.rs+33-3
......@@ -17,6 +17,13 @@ pub enum Stability {
1717 /// This target feature is stable, it can be used in `#[target_feature]` and
1818 /// `#[cfg(target_feature)]`.
1919 Stable,
20 /// This target feature is cfg-stable. It can be used for `#[cfg(target_feature)]` on stable,
21 /// but using it in `#[target_feature]` requires the given nightly feature.
22 CfgStableToggleUnstable(
23 /// This must be a *language* feature, or else rustc will ICE when reporting a missing
24 /// feature gate!
25 Symbol,
26 ),
2027 /// This target feature is unstable. It is only present in `#[cfg(target_feature)]` on
2128 /// nightly and using it in `#[target_feature]` requires enabling the given nightly feature.
2229 Unstable(
......@@ -37,7 +44,12 @@ impl Stability {
3744 /// (It might still be nightly-only even if this returns `true`, so make sure to also check
3845 /// `requires_nightly`.)
3946 pub fn in_cfg(&self) -> bool {
40 matches!(self, Stability::Stable | Stability::Unstable { .. })
47 matches!(
48 self,
49 Stability::Stable
50 | Stability::CfgStableToggleUnstable { .. }
51 | Stability::Unstable { .. }
52 )
4153 }
4254
4355 /// Returns the nightly feature that is required to toggle this target feature via
......@@ -48,20 +60,38 @@ impl Stability {
4860 /// Before calling this, ensure the feature is even permitted for this use:
4961 /// - for `#[target_feature]`/`-Ctarget-feature`, check `toggle_allowed()`
5062 /// - for `cfg(target_feature)`, check `in_cfg()`
51 pub fn requires_nightly(&self) -> Option<Symbol> {
63 ///
64 /// The `in_cfg` parameter is used to determine whether it will be used in
65 /// `cfg(target_feature)` (true) or `#[target_feature]`/`-Ctarget-feature` (false)
66 pub fn requires_nightly(&self, in_cfg: bool) -> Option<Symbol> {
5267 match *self {
5368 Stability::Unstable(nightly_feature) => Some(nightly_feature),
69 Stability::CfgStableToggleUnstable(nightly_feature) => {
70 if in_cfg {
71 None
72 } else {
73 Some(nightly_feature)
74 }
75 }
5476 Stability::Stable { .. } => None,
5577 Stability::Forbidden { .. } => panic!("forbidden features should not reach this far"),
5678 }
5779 }
5880
81 /// Returns whether the feature is cfg-stable but still requires a nightly feature gate to
82 /// be used in `#[target_feature]`/`-Ctarget-feature`.
83 pub fn is_cfg_stable_toggle_unstable(&self) -> bool {
84 matches!(self, Stability::CfgStableToggleUnstable { .. })
85 }
86
5987 /// Returns whether the feature may be toggled via `#[target_feature]` or `-Ctarget-feature`.
6088 /// (It might still be nightly-only even if this returns `true`, so make sure to also check
6189 /// `requires_nightly`.)
6290 pub fn toggle_allowed(&self) -> Result<(), &'static str> {
6391 match self {
64 Stability::Unstable(_) | Stability::Stable { .. } => Ok(()),
92 Stability::Unstable(_)
93 | Stability::CfgStableToggleUnstable(_)
94 | Stability::Stable { .. } => Ok(()),
6595 Stability::Forbidden { reason } => Err(reason),
6696 }
6797 }
library/core/src/any.rs+14-4
......@@ -1007,18 +1007,23 @@ pub const fn type_name_of_val<T: ?Sized>(_val: &T) -> &'static str {
10071007#[must_use]
10081008#[unstable(feature = "try_as_dyn", issue = "144361")]
10091009pub const fn try_as_dyn<
1010 T: Any + 'static,
1010 T: Any + ?Sized + 'static,
10111011 U: ptr::Pointee<Metadata = ptr::DynMetadata<U>> + ?Sized + 'static,
10121012>(
10131013 t: &T,
10141014) -> Option<&U> {
1015 // For unsized `T`, `trait_info_of` always returns `None` (vtable lookup is
1016 // only supported for sized types). The function therefore unconditionally
1017 // returns `None` in that case.
10151018 let vtable: Option<ptr::DynMetadata<U>> =
10161019 const { TypeId::of::<T>().trait_info_of::<U>().as_ref().map(TraitImpl::get_vtable) };
10171020 match vtable {
10181021 Some(dyn_metadata) => {
1019 let pointer = ptr::from_raw_parts(t, dyn_metadata);
1022 let pointer = ptr::from_raw_parts(t as *const T as *const (), dyn_metadata);
10201023 // SAFETY: `t` is a reference to a type, so we know it is valid.
10211024 // `dyn_metadata` is a vtable for T, implementing the trait of `U`.
1025 // `T` is sized here because `trait_info_of` only returns `Some` for sized types,
1026 // so the thin data pointer fully describes the value.
10221027 Some(unsafe { &*pointer })
10231028 }
10241029 None => None,
......@@ -1061,18 +1066,23 @@ pub const fn try_as_dyn<
10611066#[must_use]
10621067#[unstable(feature = "try_as_dyn", issue = "144361")]
10631068pub const fn try_as_dyn_mut<
1064 T: Any + 'static,
1069 T: Any + ?Sized + 'static,
10651070 U: ptr::Pointee<Metadata = ptr::DynMetadata<U>> + ?Sized + 'static,
10661071>(
10671072 t: &mut T,
10681073) -> Option<&mut U> {
1074 // For unsized `T`, `trait_info_of` always returns `None` (vtable lookup is
1075 // only supported for sized types). The function therefore unconditionally
1076 // returns `None` in that case.
10691077 let vtable: Option<ptr::DynMetadata<U>> =
10701078 const { TypeId::of::<T>().trait_info_of::<U>().as_ref().map(TraitImpl::get_vtable) };
10711079 match vtable {
10721080 Some(dyn_metadata) => {
1073 let pointer = ptr::from_raw_parts_mut(t, dyn_metadata);
1081 let pointer = ptr::from_raw_parts_mut(t as *mut T as *mut (), dyn_metadata);
10741082 // SAFETY: `t` is a reference to a type, so we know it is valid.
10751083 // `dyn_metadata` is a vtable for T, implementing the trait of `U`.
1084 // `T` is sized here because `trait_info_of` only returns `Some` for sized types,
1085 // so the thin data pointer fully describes the value.
10761086 Some(unsafe { &mut *pointer })
10771087 }
10781088 None => None,
library/core/src/io/error.rs+18-3
......@@ -21,6 +21,10 @@ pub type RawOsError = cfg_select! {
2121/// This list is intended to grow over time and it is not recommended to
2222/// exhaustively match against it.
2323///
24/// It is used with the [`io::Error`][error] type.
25///
26/// [error]: ../../std/io/struct.Error.html
27///
2428/// # Handling errors and matching on `ErrorKind`
2529///
2630/// In application code, use `match` for the `ErrorKind` values you are
......@@ -135,12 +139,13 @@ pub enum ErrorKind {
135139 #[stable(feature = "rust1", since = "1.0.0")]
136140 TimedOut,
137141 /// An error returned when an operation could not be completed because a
138 /// call to an underlying writer returned [`Ok(0)`].
142 /// call to [`write`][write] returned [`Ok(0)`].
139143 ///
140144 /// This typically means that an operation could only succeed if it wrote a
141145 /// particular number of bytes but only a smaller number of bytes could be
142146 /// written.
143147 ///
148 /// [write]: ../../std/io/trait.Write.html#tymethod.write
144149 /// [`Ok(0)`]: Ok
145150 #[stable(feature = "rust1", since = "1.0.0")]
146151 WriteZero,
......@@ -239,7 +244,7 @@ pub enum ErrorKind {
239244 //
240245 /// A custom error that does not fall under any other I/O error kind.
241246 ///
242 /// This can be used to construct your own errors that do not match any
247 /// This can be used to construct your own [`Error`][error]s that do not match any
243248 /// [`ErrorKind`].
244249 ///
245250 /// This [`ErrorKind`] is not used by the standard library.
......@@ -247,6 +252,8 @@ pub enum ErrorKind {
247252 /// Errors from the standard library that do not fall under any of the I/O
248253 /// error kinds cannot be `match`ed on, and will only match a wildcard (`_`) pattern.
249254 /// New [`ErrorKind`]s might be added in the future for some of those.
255 ///
256 /// [error]: ../../std/io/struct.Error.html
250257 #[stable(feature = "rust1", since = "1.0.0")]
251258 Other,
252259
......@@ -379,7 +386,15 @@ impl ErrorKind {
379386
380387#[stable(feature = "io_errorkind_display", since = "1.60.0")]
381388impl fmt::Display for ErrorKind {
382 /// Shows a human-readable description of the `ErrorKind`.
389 /// Shows a human-readable description of the [`ErrorKind`].
390 ///
391 /// This is similar to `impl Display for Error`, but doesn't require first converting to Error.
392 ///
393 /// # Examples
394 /// ```
395 /// use core::io::ErrorKind;
396 /// assert_eq!("entity not found", ErrorKind::NotFound.to_string());
397 /// ```
383398 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
384399 fmt.write_str(self.as_str())
385400 }
library/core/src/str/lossy.rs+1-6
......@@ -211,12 +211,7 @@ impl<'a> Iterator for Utf8Chunks<'a> {
211211
212212 let mut i = 0;
213213 let mut valid_up_to = 0;
214 while i < self.source.len() {
215 // SAFETY: `i < self.source.len()` per previous line.
216 // For some reason the following are both significantly slower:
217 // while let Some(&byte) = self.source.get(i) {
218 // while let Some(byte) = self.source.get(i).copied() {
219 let byte = unsafe { *self.source.get_unchecked(i) };
214 while let Some(byte) = self.source.get(i).copied() {
220215 i += 1;
221216
222217 if byte < 128 {
package.json+1-1
......@@ -1,6 +1,6 @@
11{
22 "dependencies": {
3 "browser-ui-test": "^0.23.3",
3 "browser-ui-test": "^0.23.5",
44 "es-check": "^9.4.4",
55 "eslint": "^8.57.1",
66 "typescript": "^5.8.3"
src/doc/reference+1-1
......@@ -1 +1 @@
1Subproject commit 8c88f9d0bdd75ffdc0691676d83212ae22a18cee
1Subproject commit 581920f9109f141b88b860b3e1e8359e3896a150
src/doc/unstable-book/src/language-features/generic-const-args.md created+37
......@@ -0,0 +1,37 @@
1# generic_const_args
2
3Allows using generics in more complex const expressions, based on definitional equality.
4
5The tracking issue for this feature is: [#151972]
6
7[#151972]: https://github.com/rust-lang/rust/issues/151972
8
9------------------------
10
11Warning: This feature is incomplete; its design and syntax may change.
12
13This feature enables many of the same use cases supported by [generic_const_exprs],
14but based on the machinery developed for [min_generic_const_args]. In a way, it is
15meant to be an interim successor for GCE (though it might not currently support all
16the valid cases that supported by GCE).
17
18See also: [generic_const_items]
19
20[min_generic_const_args]: min-generic-const-args.md
21[generic_const_exprs]: generic-const-exprs.md
22[generic_const_items]: generic-const-items.md
23
24## Examples
25
26```rust
27#![feature(generic_const_items)]
28#![feature(min_generic_const_args)]
29#![feature(generic_const_args)]
30#![expect(incomplete_features)]
31
32type const ADD1<const N: usize>: usize = const { N + 1 };
33
34type const INC<const N: usize>: usize = ADD1::<N>;
35
36const ARR: [(); ADD1::<0>] = [(); INC::<0>];
37```
src/doc/unstable-book/src/language-features/generic-const-exprs.md created+73
......@@ -0,0 +1,73 @@
1# generic_const_exprs
2
3Allows non-trivial generic constants which have to be shown to successfully evaluate
4to a value by being part of an item signature.
5
6The tracking issue for this feature is: [#76560]
7
8
9[#76560]: https://github.com/rust-lang/rust/issues/76560
10
11------------------------
12
13Warning: This feature is incomplete; its design and syntax may change.
14
15See also: [min_generic_const_args], [generic_const_args]
16
17[min_generic_const_args]: min-generic-const-args.md
18[generic_const_args]: generic-const-args.md
19
20## Examples
21
22```rust
23#![allow(incomplete_features)]
24#![feature(generic_const_exprs)]
25
26// Use parameters that depend on a generic argument.
27struct Foo<const N: usize>
28where
29 [(); N + 1]:,
30{
31 array: [usize; N + 1],
32}
33
34// Use generic parameters in const operations.
35trait Bar {
36 const X: usize;
37 const Y: usize;
38}
39
40// Note `B::X * B::Y`.
41const fn baz<B: Bar>(x: [usize; B::X], y: [usize; B::Y]) -> [usize; B::X * B::Y] {
42 let mut out = [0; B::X * B::Y];
43 let mut i = 0;
44 while i < B::Y {
45 let mut j = 0;
46 while j < B::X {
47 out[i * B::X + j] = y[i].saturating_mul(x[j]);
48 j += 1;
49 }
50 i += 1;
51 }
52 out
53}
54
55
56// Create a new type based on a generic argument.
57pub struct Grow<const N: usize> {
58 arr: [usize; N],
59}
60
61impl<const N: usize> Grow<N> {
62 pub const fn grow(self, val: usize) -> Grow<{ N + 1 }> {
63 let mut new_arr = [0; { N + 1 }];
64 let mut idx = 0;
65 while idx < N {
66 new_arr[idx] = self.arr[idx];
67 idx += 1;
68 }
69 new_arr[N] = val;
70 Grow { arr: new_arr }
71 }
72}
73```
src/doc/unstable-book/src/language-features/generic-const-items.md created+53
......@@ -0,0 +1,53 @@
1# generic_const_items
2
3Allows generic parameters and where-clauses on free & associated const items.
4
5The tracking issue for this feature is: [#113521]
6
7[#113521]: https://github.com/rust-lang/rust/issues/113521
8
9------------------------
10
11Warning: This feature is an [experiment] and lacks an RFC.
12There are no guarantees that it will ever be stabilized.
13
14See also: [generic_const_exprs], [min_generic_const_args].
15
16[experiment]: https://lang-team.rust-lang.org/how_to/experiment.html
17[generic_const_exprs]: generic-const-exprs.md
18[min_generic_const_args]: min-generic-const-args.md
19
20## Examples
21
22### Generic constant values
23
24```rust
25#![allow(incomplete_features)]
26#![feature(generic_const_items)]
27
28const GENERIC_VAL<const ARG: usize>: usize = ARG + 1;
29
30#[test]
31fn generic_const_arg() {
32 assert_eq!(GENERIC_VAL::<1>, 2);
33 assert_eq!(GENERIC_VAL::<2>, 3);
34}
35```
36
37### Conditional constants
38
39```rust
40#![allow(incomplete_features)]
41#![feature(generic_const_items)]
42
43// `GENERIC_VAL::<0>` will fail to compile
44const GENERIC_VAL<const ARG: usize>: usize = if ARG > 0 { ARG + 1 } else { panic!("0 value") };
45
46// Will fail to compile if the `Copy` derive is removed.
47const COPY_MARKER<C: Copy>: () = ();
48
49#[derive(Clone, Copy)]
50struct Foo;
51
52const FOO_IS_COPY: () = COPY_MARKER::<Foo>;
53```
src/doc/unstable-book/src/language-features/min-generic-const-args.md created+110
......@@ -0,0 +1,110 @@
1# min_generic_const_args
2
3Enables the generic const args MVP (paths to type const items and constructors for ADTs and primitives).
4
5The tracking issue for this feature is: [#132980]
6
7[#132980]: https://github.com/rust-lang/rust/issues/132980
8
9------------------------
10
11Warning: This feature is incomplete; its design and syntax may change.
12
13This feature acts as a minimal alternative to [generic_const_exprs] that allows a smaller subset of functionality,
14and uses a different approach for implementation. It is intentionally more restrictive, which helps with avoiding edge
15cases that make the `generic_const_exprs` hard to implement properly. See [Feature background][feature_background]
16for more details.
17
18Related features: [generic_const_args], [generic_const_items].
19
20[feature_background]: https://github.com/rust-lang/project-const-generics/blob/main/documents/min_const_generics_plan.md
21[generic_const_exprs]: generic-const-exprs.md
22[generic_const_args]: generic-const-args.md
23[generic_const_items]: generic-const-items.md
24
25## `type const` syntax
26
27This feature introduces new syntax: `type const`.
28Constants marked as `type const` are allowed to be used in type contexts, e.g.:
29
30```compile_fail
31#![allow(incomplete_features)]
32#![feature(min_generic_const_args)]
33
34type const X: usize = 1;
35const Y: usize = 1;
36
37struct Foo {
38 good_arr: [(); X], // Allowed
39 bad_arr: [(); Y], // Will not compile, `Y` must be `type const`.
40}
41```
42
43## Examples
44
45```rust
46#![allow(incomplete_features)]
47#![feature(min_generic_const_args)]
48
49trait Bar {
50 type const VAL: usize;
51 type const VAL2: usize;
52}
53
54struct Baz;
55
56impl Bar for Baz {
57 type const VAL: usize = 2;
58 type const VAL2: usize = const { Self::VAL * 2 };
59}
60
61struct Foo<B: Bar> {
62 arr1: [usize; B::VAL],
63 arr2: [usize; B::VAL2],
64}
65```
66
67Note that with [generic_const_exprs] the same example would look as follows:
68
69```rust
70#![allow(incomplete_features)]
71#![feature(generic_const_exprs)]
72
73trait Bar {
74 const VAL: usize;
75 const VAL2: usize;
76}
77
78struct Baz;
79
80impl Bar for Baz {
81 const VAL: usize = 2;
82 const VAL2: usize = const { Self::VAL * 2 };
83}
84
85struct Foo<B: Bar>
86where
87 [(); B::VAL]:,
88 [(); B::VAL2]:,
89{
90 arr1: [usize; B::VAL],
91 arr2: [usize; B::VAL2],
92}
93```
94
95Use of const functions is allowed:
96
97```rust
98#![allow(incomplete_features)]
99#![feature(min_generic_const_args)]
100
101const VAL: usize = 1;
102
103const fn inc(val: usize) -> usize {
104 val + 1
105}
106
107type const INC: usize = const { inc(VAL) };
108
109const ARR: [usize; INC] = [0; INC];
110```
tests/assembly-llvm/c-variadic/avr.rs created+220
......@@ -0,0 +1,220 @@
1//@ add-minicore
2//@ assembly-output: emit-asm
3//
4//@ revisions: AVR
5//@ [AVR] compile-flags: -Copt-level=3 --target=avr-none -Ctarget-cpu=atmega328p
6//@ [AVR] needs-llvm-components: avr
7#![feature(c_variadic, c_variadic_experimental_arch, no_core, lang_items, intrinsics, rustc_attrs)]
8#![no_core]
9#![crate_type = "lib"]
10
11// Check that rustc and clang output match, see https://godbolt.org/z/1MvxoceeT.
12
13extern crate minicore;
14use minicore::*;
15
16#[lang = "va_arg_safe"]
17pub unsafe trait VaArgSafe {}
18
19unsafe impl VaArgSafe for i16 {}
20unsafe impl VaArgSafe for i32 {}
21unsafe impl VaArgSafe for i64 {}
22unsafe impl VaArgSafe for f32 {}
23unsafe impl VaArgSafe for f64 {}
24unsafe impl<T> VaArgSafe for *const T {}
25
26#[repr(transparent)]
27struct VaListInner {
28 ptr: *const c_void,
29}
30
31#[repr(transparent)]
32#[lang = "va_list"]
33pub struct VaList<'a> {
34 inner: VaListInner,
35 _marker: PhantomData<&'a mut ()>,
36}
37
38#[rustc_intrinsic]
39#[rustc_nounwind]
40pub const unsafe fn va_arg<T: VaArgSafe>(ap: &mut VaList<'_>) -> T;
41
42#[unsafe(no_mangle)]
43unsafe extern "C" fn read_f32(ap: &mut VaList<'_>) -> f32 {
44 // CHECK-LABEL: read_f32
45 //
46 // AVR: movw r30, r24
47 // AVR-NEXT: ld r24, Z
48 // AVR-NEXT: ldd r25, Z+1
49 // AVR-NEXT: movw r26, r24
50 // AVR-NEXT: adiw r26, 2
51 // AVR-NEXT: std Z+1, r27
52 // AVR-NEXT: st Z, r26
53 // AVR-NEXT: movw r20, r30
54 // AVR-NEXT: movw r18, r24
55 // AVR-NEXT: movw r30, r18
56 // AVR-NEXT: ld r22, Z
57 // AVR-NEXT: ldd r23, Z+1
58 // AVR-NEXT: adiw r24, 4
59 // AVR-NEXT: movw r30, r20
60 // AVR-NEXT: std Z+1, r25
61 // AVR-NEXT: st Z, r24
62 // AVR-NEXT: movw r30, r18
63 // AVR-NEXT: ldd r24, Z+2
64 // AVR-NEXT: ldd r25, Z+3
65 // AVR-NEXT: ret
66 va_arg(ap)
67}
68
69#[unsafe(no_mangle)]
70unsafe extern "C" fn read_f64(ap: &mut VaList<'_>) -> f64 {
71 // CHECK-LABEL: read_f64
72 //
73 // AVR: push r14
74 // AVR-NEXT: push r15
75 // AVR-NEXT: push r16
76 // AVR-NEXT: push r17
77 // AVR-NEXT: movw r30, r24
78 // AVR-NEXT: ld r24, Z
79 // AVR-NEXT: ldd r25, Z+1
80 // AVR-NEXT: movw r26, r24
81 // AVR-NEXT: adiw r26, 2
82 // AVR-NEXT: std Z+1, r27
83 // AVR-NEXT: st Z, r26
84 // AVR-NEXT: movw r14, r30
85 // AVR-NEXT: movw r16, r24
86 // AVR-NEXT: movw r30, r16
87 // AVR-NEXT: ld r18, Z
88 // AVR-NEXT: ldd r19, Z+1
89 // AVR-NEXT: movw r26, r24
90 // AVR-NEXT: adiw r26, 4
91 // AVR-NEXT: movw r30, r14
92 // AVR-NEXT: std Z+1, r27
93 // AVR-NEXT: st Z, r26
94 // AVR-NEXT: movw r30, r16
95 // AVR-NEXT: ldd r20, Z+2
96 // AVR-NEXT: ldd r21, Z+3
97 // AVR-NEXT: movw r26, r24
98 // AVR-NEXT: adiw r26, 6
99 // AVR-NEXT: movw r30, r14
100 // AVR-NEXT: std Z+1, r27
101 // AVR-NEXT: st Z, r26
102 // AVR-NEXT: movw r30, r16
103 // AVR-NEXT: ldd r22, Z+4
104 // AVR-NEXT: ldd r23, Z+5
105 // AVR-NEXT: adiw r24, 8
106 // AVR-NEXT: movw r30, r14
107 // AVR-NEXT: std Z+1, r25
108 // AVR-NEXT: st Z, r24
109 // AVR-NEXT: movw r30, r16
110 // AVR-NEXT: ldd r24, Z+6
111 // AVR-NEXT: ldd r25, Z+7
112 // AVR-NEXT: pop r17
113 // AVR-NEXT: pop r16
114 // AVR-NEXT: pop r15
115 // AVR-NEXT: pop r14
116 // AVR-NEXT: ret
117 va_arg(ap)
118}
119
120#[unsafe(no_mangle)]
121unsafe extern "C" fn read_i16(ap: &mut VaList<'_>) -> i16 {
122 // CHECK-LABEL: read_i16
123 //
124 // AVR: movw r30, r24
125 // AVR-NEXT: ld r24, Z
126 // AVR-NEXT: ldd r25, Z+1
127 // AVR-NEXT: movw r26, r24
128 // AVR-NEXT: adiw r26, 2
129 // AVR-NEXT: std Z+1, r27
130 // AVR-NEXT: st Z, r26
131 // AVR-NEXT: movw r30, r24
132 // AVR-NEXT: ld r24, Z
133 // AVR-NEXT: ldd r25, Z+1
134 // AVR-NEXT: ret
135 va_arg(ap)
136}
137
138#[unsafe(no_mangle)]
139unsafe extern "C" fn read_i32(ap: &mut VaList<'_>) -> i32 {
140 // CHECK-LABEL: read_i32
141 //
142 // AVR: movw r30, r24
143 // AVR-NEXT: ld r24, Z
144 // AVR-NEXT: ldd r25, Z+1
145 // AVR-NEXT: movw r26, r24
146 // AVR-NEXT: adiw r26, 2
147 // AVR-NEXT: std Z+1, r27
148 // AVR-NEXT: st Z, r26
149 // AVR-NEXT: movw r20, r30
150 // AVR-NEXT: movw r18, r24
151 // AVR-NEXT: movw r30, r18
152 // AVR-NEXT: ld r22, Z
153 // AVR-NEXT: ldd r23, Z+1
154 // AVR-NEXT: adiw r24, 4
155 // AVR-NEXT: movw r30, r20
156 // AVR-NEXT: std Z+1, r25
157 // AVR-NEXT: st Z, r24
158 // AVR-NEXT: movw r30, r18
159 // AVR-NEXT: ldd r24, Z+2
160 // AVR-NEXT: ldd r25, Z+3
161 // AVR-NEXT: ret
162 va_arg(ap)
163}
164
165#[unsafe(no_mangle)]
166unsafe extern "C" fn read_i64(ap: &mut VaList<'_>) -> i64 {
167 // CHECK-LABEL: read_i64
168 //
169 // AVR: push r14
170 // AVR-NEXT: push r15
171 // AVR-NEXT: push r16
172 // AVR-NEXT: push r17
173 // AVR-NEXT: movw r30, r24
174 // AVR-NEXT: ld r24, Z
175 // AVR-NEXT: ldd r25, Z+1
176 // AVR-NEXT: movw r26, r24
177 // AVR-NEXT: adiw r26, 2
178 // AVR-NEXT: std Z+1, r27
179 // AVR-NEXT: st Z, r26
180 // AVR-NEXT: movw r14, r30
181 // AVR-NEXT: movw r16, r24
182 // AVR-NEXT: movw r30, r16
183 // AVR-NEXT: ld r18, Z
184 // AVR-NEXT: ldd r19, Z+1
185 // AVR-NEXT: movw r26, r24
186 // AVR-NEXT: adiw r26, 4
187 // AVR-NEXT: movw r30, r14
188 // AVR-NEXT: std Z+1, r27
189 // AVR-NEXT: st Z, r26
190 // AVR-NEXT: movw r30, r16
191 // AVR-NEXT: ldd r20, Z+2
192 // AVR-NEXT: ldd r21, Z+3
193 // AVR-NEXT: movw r26, r24
194 // AVR-NEXT: adiw r26, 6
195 // AVR-NEXT: movw r30, r14
196 // AVR-NEXT: std Z+1, r27
197 // AVR-NEXT: st Z, r26
198 // AVR-NEXT: movw r30, r16
199 // AVR-NEXT: ldd r22, Z+4
200 // AVR-NEXT: ldd r23, Z+5
201 // AVR-NEXT: adiw r24, 8
202 // AVR-NEXT: movw r30, r14
203 // AVR-NEXT: std Z+1, r25
204 // AVR-NEXT: st Z, r24
205 // AVR-NEXT: movw r30, r16
206 // AVR-NEXT: ldd r24, Z+6
207 // AVR-NEXT: ldd r25, Z+7
208 // AVR-NEXT: pop r17
209 // AVR-NEXT: pop r16
210 // AVR-NEXT: pop r15
211 // AVR-NEXT: pop r14
212 // AVR-NEXT: ret
213 va_arg(ap)
214}
215
216#[unsafe(no_mangle)]
217unsafe extern "C" fn read_ptr(ap: &mut VaList<'_>) -> *const u8 {
218 // AVR: read_ptr = pm(read_i16)
219 va_arg(ap)
220}
tests/assembly-llvm/c-variadic/sparc.rs+1
......@@ -7,6 +7,7 @@
77//@ [SPARC64] compile-flags: -Copt-level=3 --target sparc64-unknown-linux-gnu
88//@ [SPARC64] needs-llvm-components: sparc
99#![feature(c_variadic, no_core, lang_items, intrinsics, rustc_attrs, asm_experimental_arch)]
10#![cfg_attr(target_arch = "sparc", feature(c_variadic_experimental_arch))]
1011#![no_core]
1112#![crate_type = "lib"]
1213
tests/rustdoc-html/doc-cfg/impl-foreign-type.rs created+15
......@@ -0,0 +1,15 @@
1// This test ensures that the `doc_cfg` feature works on foreign types impl.
2// Regression test for <https://github.com/rust-lang/rust/issues/150268>.
3
4// ignore-tidy-linelength
5
6#![feature(doc_cfg)]
7#![crate_name = "foo"]
8
9//@has 'foo/trait.Blob.html'
10//@has - '//*[@id="impl-Blob-for-Box%3CR%3E"]//*[@class="stab portability"]' 'Available on non-crate feature alloc only.'
11
12pub trait Blob {}
13
14#[cfg(not(feature = "alloc"))]
15impl<R: ?Sized> Blob for std::boxed::Box<R> {}
tests/ui/any/try_as_dyn_unsized.rs created+34
......@@ -0,0 +1,34 @@
1//@ run-pass
2#![feature(try_as_dyn)]
3
4use std::fmt::Debug;
5
6// Generic over `?Sized` T: relies on the relaxed bound on `try_as_dyn`.
7fn try_debug<T: ?Sized + 'static>(t: &T) -> Option<String> {
8 std::any::try_as_dyn::<T, dyn Debug>(t).map(|d| format!("{d:?}"))
9}
10
11fn try_debug_mut<T: ?Sized + 'static>(t: &mut T) -> Option<String> {
12 std::any::try_as_dyn_mut::<T, dyn Debug>(t).map(|d| format!("{d:?}"))
13}
14
15fn main() {
16 // Sized case still works through a `?Sized` generic context.
17 let x: i32 = 7;
18 assert_eq!(try_debug(&x).as_deref(), Some("7"));
19
20 let mut y: i32 = 8;
21 assert_eq!(try_debug_mut(&mut y).as_deref(), Some("8"));
22
23 // Unsized `T` always returns `None`, even though `str: Debug` and
24 // `[T]: Debug` hold — vtable lookup for unsized impl types is not
25 // currently supported by `TypeId::trait_info_of`.
26 let s: &str = "hello";
27 assert!(try_debug::<str>(s).is_none());
28
29 let slice: &[i32] = &[1, 2, 3];
30 assert!(try_debug::<[i32]>(slice).is_none());
31
32 let dyn_any: &dyn std::any::Any = &0i32;
33 assert!(try_debug::<dyn std::any::Any>(dyn_any).is_none());
34}
tests/ui/associated-types/ambiguous-associated-type-default.rs created+11
......@@ -0,0 +1,11 @@
1//! Regression test for https://github.com/rust-lang/rust/issues/23073
2
3#![feature(associated_type_defaults)]
4
5trait Foo { type T; }
6trait Bar {
7 type Foo: Foo;
8 type FooT = <<Self as Bar>::Foo>::T; //~ ERROR ambiguous associated type
9}
10
11fn main() {}
tests/ui/associated-types/ambiguous-associated-type-default.stderr created+14
......@@ -0,0 +1,14 @@
1error[E0223]: ambiguous associated type
2 --> $DIR/ambiguous-associated-type-default.rs:8:17
3 |
4LL | type FooT = <<Self as Bar>::Foo>::T;
5 | ^^^^^^^^^^^^^^^^^^^^^^^
6 |
7help: if there were a trait named `Example` with associated type `T` implemented for `<Self as Bar>::Foo`, you could use the fully-qualified path
8 |
9LL | type FooT = <<Self as Bar>::Foo as Example>::T;
10 | ++++++++++
11
12error: aborting due to 1 previous error
13
14For more information about this error, try `rustc --explain E0223`.
tests/ui/associated-types/assoc-type-add-output-via-operator-syntax.rs created+12
......@@ -0,0 +1,12 @@
1//! Regression test for https://github.com/rust-lang/rust/issues/20803
2
3//@ run-pass
4use std::ops::Add;
5
6fn foo<T>(x: T) -> <i32 as Add<T>>::Output where i32: Add<T> {
7 42i32 + x
8}
9
10fn main() {
11 println!("{}", foo(0i32));
12}
tests/ui/associated-types/assoc-type-default-without-override-in-impl.rs created+20
......@@ -0,0 +1,20 @@
1//! Regression test for https://github.com/rust-lang/rust/issues/37051
2
3//@ check-pass
4
5#![feature(associated_type_defaults)]
6
7trait State: Sized {
8 type NextState: State = StateMachineEnded;
9 fn execute(self) -> Option<Self::NextState>;
10}
11
12struct StateMachineEnded;
13
14impl State for StateMachineEnded {
15 fn execute(self) -> Option<Self::NextState> {
16 None
17 }
18}
19
20fn main() {}
tests/ui/associated-types/assoc-type-element-mismatch-in-hrtb.rs created+23
......@@ -0,0 +1,23 @@
1//! Regression test for https://github.com/rust-lang/rust/issues/39970
2
3trait Array<'a> {
4 type Element: 'a;
5}
6
7trait Visit {
8 fn visit() {}
9}
10
11impl<'a> Array<'a> for () {
12 type Element = &'a ();
13}
14
15impl Visit for () where
16 //(): for<'a> Array<'a, Element=&'a ()>, // No ICE
17 (): for<'a> Array<'a, Element=()>, // ICE
18{}
19
20fn main() {
21 <() as Visit>::visit();
22 //~^ ERROR type mismatch resolving `<() as Array<'a>>::Element == ()`
23}
tests/ui/associated-types/assoc-type-element-mismatch-in-hrtb.stderr created+23
......@@ -0,0 +1,23 @@
1error[E0271]: type mismatch resolving `<() as Array<'a>>::Element == ()`
2 --> $DIR/assoc-type-element-mismatch-in-hrtb.rs:21:6
3 |
4LL | <() as Visit>::visit();
5 | ^^ type mismatch resolving `<() as Array<'a>>::Element == ()`
6 |
7note: expected this to be `()`
8 --> $DIR/assoc-type-element-mismatch-in-hrtb.rs:12:20
9 |
10LL | type Element = &'a ();
11 | ^^^^^^
12note: required for `()` to implement `Visit`
13 --> $DIR/assoc-type-element-mismatch-in-hrtb.rs:15:6
14 |
15LL | impl Visit for () where
16 | ^^^^^ ^^
17LL | //(): for<'a> Array<'a, Element=&'a ()>, // No ICE
18LL | (): for<'a> Array<'a, Element=()>, // ICE
19 | ---------- unsatisfied trait bound introduced here
20
21error: aborting due to 1 previous error
22
23For more information about this error, try `rustc --explain E0271`.
tests/ui/associated-types/assoc-type-in-extern-fn-signature.rs created+24
......@@ -0,0 +1,24 @@
1//! Regression test for https://github.com/rust-lang/rust/issues/28983
2
3//@ run-pass
4pub trait Test { type T; }
5
6impl Test for u32 {
7 type T = i32;
8}
9
10pub mod export {
11 #[no_mangle]
12 pub extern "C" fn issue_28983(t: <u32 as crate::Test>::T) -> i32 { t*3 }
13}
14
15// to test both exporting and importing functions, import
16// a function from ourselves.
17extern "C" {
18 fn issue_28983(t: <u32 as Test>::T) -> i32;
19}
20
21fn main() {
22 assert_eq!(export::issue_28983(2), 6);
23 assert_eq!(unsafe { issue_28983(3) }, 9);
24}
tests/ui/associated-types/assoc-type-in-generic-struct-bound.rs created+15
......@@ -0,0 +1,15 @@
1//! Regression test for https://github.com/rust-lang/rust/issues/19632
2
3//@ check-pass
4#![allow(dead_code)]
5
6trait PoolManager {
7 type C;
8 fn dummy(&self) { }
9}
10
11struct InnerPool<M: PoolManager> {
12 manager: M,
13}
14
15fn main() {}
tests/ui/associated-types/assoc-type-in-strategy-pattern-iterator.rs created+93
......@@ -0,0 +1,93 @@
1//@ build-pass
2
3// Regression test for https://github.com/rust-lang/rust/issues/20797
4
5use std::default::Default;
6use std::io;
7use std::fs;
8use std::path::PathBuf;
9
10pub trait PathExtensions {
11 fn is_dir(&self) -> bool { false }
12}
13
14impl PathExtensions for PathBuf {}
15
16/// A strategy for acquiring more subpaths to walk.
17pub trait Strategy {
18 type P: PathExtensions;
19 /// Gets additional subpaths from a given path.
20 fn get_more(&self, item: &Self::P) -> io::Result<Vec<Self::P>>;
21 /// Determine whether a path should be walked further.
22 /// This is run against each item from `get_more()`.
23 fn prune(&self, p: &Self::P) -> bool;
24}
25
26/// The basic fully-recursive strategy. Nothing is pruned.
27#[derive(Copy, Clone, Default)]
28pub struct Recursive;
29
30impl Strategy for Recursive {
31 type P = PathBuf;
32 fn get_more(&self, p: &PathBuf) -> io::Result<Vec<PathBuf>> {
33 Ok(fs::read_dir(p).unwrap().map(|s| s.unwrap().path()).collect())
34 }
35
36 fn prune(&self, _: &PathBuf) -> bool { false }
37}
38
39/// A directory walker of `P` using strategy `S`.
40pub struct Subpaths<S: Strategy> {
41 stack: Vec<S::P>,
42 strategy: S,
43}
44
45impl<S: Strategy> Subpaths<S> {
46 /// Creates a directory walker with a root path and strategy.
47 pub fn new(p: &S::P, strategy: S) -> io::Result<Subpaths<S>> {
48 let stack = strategy.get_more(p)?;
49 Ok(Subpaths { stack: stack, strategy: strategy })
50 }
51}
52
53impl<S: Default + Strategy> Subpaths<S> {
54 /// Creates a directory walker with a root path and a default strategy.
55 pub fn walk(p: &S::P) -> io::Result<Subpaths<S>> {
56 Subpaths::new(p, Default::default())
57 }
58}
59
60impl<S: Default + Strategy> Default for Subpaths<S> {
61 fn default() -> Subpaths<S> {
62 Subpaths { stack: Vec::new(), strategy: Default::default() }
63 }
64}
65
66impl<S: Strategy> Iterator for Subpaths<S> {
67 type Item = S::P;
68 fn next (&mut self) -> Option<S::P> {
69 let mut opt_path = self.stack.pop();
70 while opt_path.is_some() && self.strategy.prune(opt_path.as_ref().unwrap()) {
71 opt_path = self.stack.pop();
72 }
73 match opt_path {
74 Some(path) => {
75 if path.is_dir() {
76 let result = self.strategy.get_more(&path);
77 match result {
78 Ok(dirs) => { self.stack.extend(dirs); },
79 Err(..) => { }
80 }
81 }
82 Some(path)
83 }
84 None => None,
85 }
86 }
87}
88
89fn _foo() {
90 let _walker: Subpaths<Recursive> = Subpaths::walk(&PathBuf::from("/home")).unwrap();
91}
92
93fn main() {}
tests/ui/associated-types/assoc-type-in-struct-constructor.rs created+14
......@@ -0,0 +1,14 @@
1//! Regression test for https://github.com/rust-lang/rust/issues/26127
2
3//@ run-pass
4trait Tr { type T; }
5impl Tr for u8 { type T=(); }
6struct S<I: Tr>(#[allow(dead_code)] I::T);
7
8fn foo<I: Tr>(i: I::T) {
9 S::<I>(i);
10}
11
12fn main() {
13 foo::<u8>(());
14}
tests/ui/associated-types/assoc-type-in-unused-where-clause.rs created+17
......@@ -0,0 +1,17 @@
1//! Regression test for https://github.com/rust-lang/rust/issues/19631
2
3//@ check-pass
4#![allow(dead_code)]
5
6trait PoolManager {
7 type C;
8 fn dummy(&self) { }
9}
10
11struct InnerPool<M> {
12 manager: M,
13}
14
15impl<M> InnerPool<M> where M: PoolManager {}
16
17fn main() {}
tests/ui/associated-types/assoc-type-layout-unsized-allowed-sized-used.rs created+28
......@@ -0,0 +1,28 @@
1//@ run-pass
2// Regression test for https://github.com/rust-lang/rust/issues/36036
3// computing the layout of a type composed from another
4// trait's associated type caused compiler to ICE when the associated
5// type was allowed to be unsized, even though the known instantiated
6// type is itself sized.
7
8#![allow(dead_code)]
9
10trait Context {
11 type Container: ?Sized;
12}
13
14impl Context for u16 {
15 type Container = u8;
16}
17
18struct Wrapper<C: Context+'static> {
19 container: &'static C::Container
20}
21
22fn foobar(_: Wrapper<u16>) {}
23
24static VALUE: u8 = 0;
25
26fn main() {
27 foobar(Wrapper { container: &VALUE });
28}
tests/ui/associated-types/assoc-type-method-call-via-blanket-impl.rs created+13
......@@ -0,0 +1,13 @@
1//! Regression test for https://github.com/rust-lang/rust/issues/23336
2
3//@ run-pass
4pub trait Data { fn doit(&self) {} }
5impl<T> Data for T {}
6pub trait UnaryLogic { type D: Data; }
7impl UnaryLogic for () { type D = i32; }
8
9pub fn crashes<T: UnaryLogic>(t: T::D) {
10 t.doit();
11}
12
13fn main() { crashes::<()>(0); }
tests/ui/associated-types/assoc-type-named-string.rs created+14
......@@ -0,0 +1,14 @@
1//! Regression test for https://github.com/rust-lang/rust/issues/17732
2
3//@ check-pass
4#![allow(dead_code)]
5#![allow(non_camel_case_types)]
6
7trait Person {
8 type string;
9 fn dummy(&self) { }
10}
11
12struct Someone<P: Person>(std::marker::PhantomData<P>);
13
14fn main() {}
tests/ui/associated-types/assoc-type-output-is-sized.rs created+14
......@@ -0,0 +1,14 @@
1//! Regression test for https://github.com/rust-lang/rust/issues/20009
2
3//@ check-pass
4// Check that associated types are `Sized`
5
6
7trait Trait {
8 type Output;
9
10 fn is_sized(&self) -> Self::Output;
11 fn wasnt_sized(&self) -> Self::Output { loop {} }
12}
13
14fn main() {}
tests/ui/associated-types/assoc-type-projection-in-box-return.rs created+23
......@@ -0,0 +1,23 @@
1// Regression test for Issue https://github.com/rust-lang/rust/issues/20971
2
3//@ run-fail
4//@ error-pattern:Hello, world!
5//@ needs-subprocess
6
7pub trait Parser {
8 type Input;
9 fn parse(&mut self, input: <Self as Parser>::Input);
10}
11
12impl Parser for () {
13 type Input = ();
14 fn parse(&mut self, input: ()) {}
15}
16
17pub fn many() -> Box<dyn Parser<Input = <() as Parser>::Input> + 'static> {
18 panic!("Hello, world!")
19}
20
21fn main() {
22 many().parse(());
23}
tests/ui/associated-types/assoc-type-projection-in-let-binding.rs created+23
......@@ -0,0 +1,23 @@
1//! Regression test for https://github.com/rust-lang/rust/issues/19850
2
3//@ check-pass
4#![allow(unused_variables)]
5// Test that `<Type as Trait>::Output` and `Self::Output` are accepted as type annotations in let
6// bindings
7
8
9trait Int {
10 fn one() -> Self;
11 fn leading_zeros(self) -> usize;
12}
13
14trait Foo {
15 type T : Int;
16
17 fn test(&self) {
18 let r: <Self as Foo>::T = Int::one();
19 let r: Self::T = Int::one();
20 }
21}
22
23fn main() {}
tests/ui/associated-types/assoc-type-projection-on-ref-lifetime.rs created+17
......@@ -0,0 +1,17 @@
1//! Regression test for https://github.com/rust-lang/rust/issues/23406
2
3//@ build-pass
4#![allow(dead_code)]
5trait Inner {
6 type T;
7}
8
9impl<'a> Inner for &'a i32 {
10 type T = i32;
11}
12
13fn f<'a>(x: &'a i32) -> <&'a i32 as Inner>::T {
14 *x
15}
16
17fn main() {}
tests/ui/associated-types/assoc-type-ref-in-tuple-return.rs created+18
......@@ -0,0 +1,18 @@
1//! Regression test for https://github.com/rust-lang/rust/issues/37109
2
3//@ run-pass
4trait ToRef<'a> {
5 type Ref: 'a;
6}
7
8impl<'a, U: 'a> ToRef<'a> for U {
9 type Ref = &'a U;
10}
11
12fn example<'a, T>(value: &'a T) -> (<T as ToRef<'a>>::Ref, u32) {
13 (value, 0)
14}
15
16fn main() {
17 example(&0);
18}
tests/ui/associated-types/assoc-type-returns-outer-wrapping-self.rs created+21
......@@ -0,0 +1,21 @@
1//! Regression test for https://github.com/rust-lang/rust/issues/23992
2
3//@ run-pass
4pub struct Outer<T: Trait>(T);
5pub struct Inner<'a> { value: &'a bool }
6
7pub trait Trait {
8 type Error;
9 fn ready(self) -> Self::Error;
10}
11
12impl<'a> Trait for Inner<'a> {
13 type Error = Outer<Inner<'a>>;
14 fn ready(self) -> Outer<Inner<'a>> { Outer(self) }
15}
16
17fn main() {
18 let value = true;
19 let inner = Inner { value: &value };
20 assert_eq!(inner.ready().0.value, &value);
21}
tests/ui/associated-types/bound-references-sibling-assoc-type.rs created+16
......@@ -0,0 +1,16 @@
1//! Regression test for https://github.com/rust-lang/rust/issues/21909
2
3//@ check-pass
4
5trait A<X> {
6 fn dummy(&self, arg: X);
7}
8
9trait B {
10 type X;
11 type Y: A<Self::X>;
12
13 fn dummy(&self);
14}
15
16fn main () { }
tests/ui/associated-types/enum-variant-with-assoc-type-and-lifetimes.rs created+21
......@@ -0,0 +1,21 @@
1//! Regression test for https://github.com/rust-lang/rust/issues/34839
2
3//@ check-pass
4
5trait RegularExpression: Sized {
6 type Text;
7}
8
9struct ExecNoSyncStr<'a>(&'a u8);
10
11impl<'c> RegularExpression for ExecNoSyncStr<'c> {
12 type Text = u8;
13}
14
15struct FindCaptures<'t, R>(&'t R::Text) where R: RegularExpression, R::Text: 't;
16
17enum FindCapturesInner<'r, 't> {
18 Dynamic(FindCaptures<'t, ExecNoSyncStr<'r>>),
19}
20
21fn main() {}
tests/ui/associated-types/method-on-impl-with-assoc-type-projection.rs created+20
......@@ -0,0 +1,20 @@
1//@ run-pass
2trait Device {
3 type Resources;
4}
5#[allow(dead_code)]
6struct Foo<D, R>(D, R);
7
8impl<D: Device> Foo<D, D::Resources> {
9 fn present(&self) {}
10}
11
12struct Res;
13struct Dev;
14
15impl Device for Dev { type Resources = Res; }
16
17fn main() {
18 let foo = Foo(Dev, Res);
19 foo.present();
20}
tests/ui/associated-types/recursive-enum-with-assoc-type-selfref.rs created+22
......@@ -0,0 +1,22 @@
1//@ run-pass
2#![allow(unused_variables)]
3pub trait Parameters { type SelfRef; }
4
5struct RP<'a> { _marker: std::marker::PhantomData<&'a ()> }
6struct BP;
7
8impl<'a> Parameters for RP<'a> { type SelfRef = &'a X<RP<'a>>; }
9impl Parameters for BP { type SelfRef = Box<X<BP>>; }
10
11pub struct Y;
12pub enum X<P: Parameters> {
13 Nothing,
14 SameAgain(P::SelfRef, Y)
15}
16
17fn main() {
18 let bnil: Box<X<BP>> = Box::new(X::Nothing);
19 let bx: Box<X<BP>> = Box::new(X::SameAgain(bnil, Y));
20 let rnil: X<RP> = X::Nothing;
21 let rx: X<RP> = X::SameAgain(&rnil, Y);
22}
tests/ui/associated-types/same-name-assoc-type-and-method.rs created+20
......@@ -0,0 +1,20 @@
1//! Regression test for https://github.com/rust-lang/rust/issues/35600
2
3//@ run-pass
4#![allow(non_camel_case_types)]
5#![allow(unused_variables)]
6
7trait Foo {
8 type bar;
9 fn bar();
10}
11
12impl Foo for () {
13 type bar = ();
14 fn bar() {}
15}
16
17fn main() {
18 let x: <() as Foo>::bar = ();
19 <()>::bar();
20}
tests/ui/associated-types/self-type-alias-for-assoc-type.rs created+19
......@@ -0,0 +1,19 @@
1//! Regression test for https://github.com/rust-lang/rust/issues/27281
2
3//@ check-pass
4pub trait Trait<'a> {
5 type T;
6 type U;
7 fn foo(&self, s: &'a ()) -> &'a ();
8}
9
10impl<'a> Trait<'a> for () {
11 type T = &'a ();
12 type U = Self::T;
13
14 fn foo(&self, s: &'a ()) -> &'a () {
15 let t: Self::T = s; t
16 }
17}
18
19fn main() {}
tests/ui/associated-types/simple-associated-type-impl.rs created+14
......@@ -0,0 +1,14 @@
1//! Regression test for https://github.com/rust-lang/rust/issues/18809
2
3//@ check-pass
4trait Tup {
5 type T0;
6 type T1;
7}
8
9impl Tup for isize {
10 type T0 = f32;
11 type T1 = ();
12}
13
14fn main() {}
tests/ui/associated-types/size-of-assoc-type-output.rs created+13
......@@ -0,0 +1,13 @@
1//! Regression test for https://github.com/rust-lang/rust/issues/43357
2
3//@ check-pass
4#![allow(dead_code)]
5trait Trait {
6 type Output;
7}
8
9fn f<T: Trait>() {
10 std::mem::size_of::<T::Output>();
11}
12
13fn main() {}
tests/ui/associated-types/unspecified-assoc-type-in-trait-object.rs created+14
......@@ -0,0 +1,14 @@
1// Regression test for https://github.com/rust-lang/rust/issues/19842
2// Test that a partially specified trait object with unspecified associated
3// type does not type-check.
4
5trait Foo {
6 type A;
7
8 fn dummy(&self) { }
9}
10
11fn bar(x: &dyn Foo) {}
12//~^ ERROR the associated type `A` in `Foo` must be specified
13
14pub fn main() {}
tests/ui/associated-types/unspecified-assoc-type-in-trait-object.stderr created+17
......@@ -0,0 +1,17 @@
1error[E0191]: the value of the associated type `A` in `Foo` must be specified
2 --> $DIR/unspecified-assoc-type-in-trait-object.rs:11:16
3 |
4LL | type A;
5 | ------ `A` defined here
6...
7LL | fn bar(x: &dyn Foo) {}
8 | ^^^
9 |
10help: specify the associated type
11 |
12LL | fn bar(x: &dyn Foo<A = /* Type */>) {}
13 | ++++++++++++++++
14
15error: aborting due to 1 previous error
16
17For more information about this error, try `rustc --explain E0191`.
tests/ui/drop/explicit-drop-call-error.fixed+1-1
......@@ -11,5 +11,5 @@ impl Drop for Foo {
1111}
1212
1313fn main() {
14 drop(&mut Foo) //~ ERROR explicit use of destructor method
14 drop(Foo) //~ ERROR explicit use of destructor method
1515}
tests/ui/drop/explicit-drop-call-error.stderr+7-4
......@@ -2,10 +2,13 @@ error[E0040]: explicit use of destructor method
22 --> $DIR/explicit-drop-call-error.rs:14:5
33 |
44LL | Drop::drop(&mut Foo)
5 | ^^^^^^^^^^
6 | |
7 | explicit destructor calls not allowed
8 | help: consider using `drop` function: `drop`
5 | ^^^^^^^^^^ explicit destructor calls not allowed
6 |
7help: consider using `drop` function
8 |
9LL - Drop::drop(&mut Foo)
10LL + drop(Foo)
11 |
912
1013error: aborting due to 1 previous error
1114
tests/ui/drop/explicit-drop-call-named-ref.fixed created+17
......@@ -0,0 +1,17 @@
1//@ run-rustfix
2
3struct Foo;
4
5impl Drop for Foo {
6 fn drop(&mut self) {}
7}
8
9fn foo(f: Foo) {
10 drop(f); //~ ERROR explicit use of destructor method
11 //~| HELP: consider using `drop` function
12}
13
14fn main() {
15 let f = Foo;
16 foo(f);
17}
tests/ui/drop/explicit-drop-call-named-ref.rs created+17
......@@ -0,0 +1,17 @@
1//@ run-rustfix
2
3struct Foo;
4
5impl Drop for Foo {
6 fn drop(&mut self) {}
7}
8
9fn foo(f: Foo) {
10 Drop::drop(&mut f); //~ ERROR explicit use of destructor method
11 //~| HELP: consider using `drop` function
12}
13
14fn main() {
15 let f = Foo;
16 foo(f);
17}
tests/ui/drop/explicit-drop-call-named-ref.stderr created+15
......@@ -0,0 +1,15 @@
1error[E0040]: explicit use of destructor method
2 --> $DIR/explicit-drop-call-named-ref.rs:10:5
3 |
4LL | Drop::drop(&mut f);
5 | ^^^^^^^^^^ explicit destructor calls not allowed
6 |
7help: consider using `drop` function
8 |
9LL - Drop::drop(&mut f);
10LL + drop(f);
11 |
12
13error: aborting due to 1 previous error
14
15For more information about this error, try `rustc --explain E0040`.
tests/ui/imports/extern-crate-self/extern-crate-self-macro-item.rs+1-1
......@@ -1,4 +1,4 @@
1//@ build-pass (FIXME(62277): could be check-pass?)
1//@ check-pass
22
33// Test that `extern crate self;` is accepted
44// syntactically as an item for use in a macro.
tests/ui/imports/extern-crate-self/extern-crate-self-pass.rs+1-1
......@@ -1,4 +1,4 @@
1//@ build-pass (FIXME(62277): could be check-pass?)
1//@ check-pass
22
33extern crate self as foo;
44
tests/ui/imports/extern-prelude-extern-crate-absolute-expanded.rs+1-1
......@@ -1,4 +1,4 @@
1//@ build-pass (FIXME(62277): could be check-pass?)
1//@ check-pass
22//@ edition:2018
33
44macro_rules! define_iso { () => {
tests/ui/imports/extern-prelude-extern-crate-cfg.rs+1-1
......@@ -1,4 +1,4 @@
1//@ build-pass (FIXME(62277): could be check-pass?)
1//@ check-pass
22//@ compile-flags:--cfg my_feature --check-cfg=cfg(my_feature)
33
44#![no_std]
tests/ui/imports/extern-prelude-extern-crate-pass.rs+1-1
......@@ -1,4 +1,4 @@
1//@ build-pass (FIXME(62277): could be check-pass?)
1//@ check-pass
22//@ aux-build:two_macros.rs
33
44extern crate two_macros;
tests/ui/imports/extern-prelude-extern-crate-shadowing.rs+1-1
......@@ -1,4 +1,4 @@
1//@ build-pass (FIXME(62277): could be check-pass?)
1//@ check-pass
22//@ aux-build:two_macros.rs
33
44extern crate two_macros as core;
tests/ui/imports/local-modularized-tricky-pass-1.rs+1-1
......@@ -1,4 +1,4 @@
1//@ build-pass (FIXME(62277): could be check-pass?)
1//@ check-pass
22
33macro_rules! define_exported { () => {
44 #[macro_export]
tests/ui/imports/local-modularized.rs+1-1
......@@ -1,5 +1,5 @@
11//@ edition:2015
2//@ build-pass (FIXME(62277): could be check-pass?)
2//@ check-pass
33
44#[macro_export(local_inner_macros)]
55macro_rules! dollar_crate_exported {
tests/ui/issues/issue-17732.rs deleted-12
......@@ -1,12 +0,0 @@
1//@ check-pass
2#![allow(dead_code)]
3#![allow(non_camel_case_types)]
4
5trait Person {
6 type string;
7 fn dummy(&self) { }
8}
9
10struct Someone<P: Person>(std::marker::PhantomData<P>);
11
12fn main() {}
tests/ui/issues/issue-18809.rs deleted-12
......@@ -1,12 +0,0 @@
1//@ check-pass
2trait Tup {
3 type T0;
4 type T1;
5}
6
7impl Tup for isize {
8 type T0 = f32;
9 type T1 = ();
10}
11
12fn main() {}
tests/ui/issues/issue-19482.rs deleted-13
......@@ -1,13 +0,0 @@
1// Test that a partially specified trait object with unspecified associated
2// type does not type-check.
3
4trait Foo {
5 type A;
6
7 fn dummy(&self) { }
8}
9
10fn bar(x: &dyn Foo) {}
11//~^ ERROR the associated type `A` in `Foo` must be specified
12
13pub fn main() {}
tests/ui/issues/issue-19482.stderr deleted-17
......@@ -1,17 +0,0 @@
1error[E0191]: the value of the associated type `A` in `Foo` must be specified
2 --> $DIR/issue-19482.rs:10:16
3 |
4LL | type A;
5 | ------ `A` defined here
6...
7LL | fn bar(x: &dyn Foo) {}
8 | ^^^
9 |
10help: specify the associated type
11 |
12LL | fn bar(x: &dyn Foo<A = /* Type */>) {}
13 | ++++++++++++++++
14
15error: aborting due to 1 previous error
16
17For more information about this error, try `rustc --explain E0191`.
tests/ui/issues/issue-19631.rs deleted-15
......@@ -1,15 +0,0 @@
1//@ check-pass
2#![allow(dead_code)]
3
4trait PoolManager {
5 type C;
6 fn dummy(&self) { }
7}
8
9struct InnerPool<M> {
10 manager: M,
11}
12
13impl<M> InnerPool<M> where M: PoolManager {}
14
15fn main() {}
tests/ui/issues/issue-19632.rs deleted-13
......@@ -1,13 +0,0 @@
1//@ check-pass
2#![allow(dead_code)]
3
4trait PoolManager {
5 type C;
6 fn dummy(&self) { }
7}
8
9struct InnerPool<M: PoolManager> {
10 manager: M,
11}
12
13fn main() {}
tests/ui/issues/issue-19850.rs deleted-21
......@@ -1,21 +0,0 @@
1//@ check-pass
2#![allow(unused_variables)]
3// Test that `<Type as Trait>::Output` and `Self::Output` are accepted as type annotations in let
4// bindings
5
6
7trait Int {
8 fn one() -> Self;
9 fn leading_zeros(self) -> usize;
10}
11
12trait Foo {
13 type T : Int;
14
15 fn test(&self) {
16 let r: <Self as Foo>::T = Int::one();
17 let r: Self::T = Int::one();
18 }
19}
20
21fn main() {}
tests/ui/issues/issue-20009.rs deleted-12
......@@ -1,12 +0,0 @@
1//@ check-pass
2// Check that associated types are `Sized`
3
4
5trait Trait {
6 type Output;
7
8 fn is_sized(&self) -> Self::Output;
9 fn wasnt_sized(&self) -> Self::Output { loop {} }
10}
11
12fn main() {}
tests/ui/issues/issue-20797.rs deleted-93
......@@ -1,93 +0,0 @@
1//@ build-pass
2
3// Regression test for #20797.
4
5use std::default::Default;
6use std::io;
7use std::fs;
8use std::path::PathBuf;
9
10pub trait PathExtensions {
11 fn is_dir(&self) -> bool { false }
12}
13
14impl PathExtensions for PathBuf {}
15
16/// A strategy for acquiring more subpaths to walk.
17pub trait Strategy {
18 type P: PathExtensions;
19 /// Gets additional subpaths from a given path.
20 fn get_more(&self, item: &Self::P) -> io::Result<Vec<Self::P>>;
21 /// Determine whether a path should be walked further.
22 /// This is run against each item from `get_more()`.
23 fn prune(&self, p: &Self::P) -> bool;
24}
25
26/// The basic fully-recursive strategy. Nothing is pruned.
27#[derive(Copy, Clone, Default)]
28pub struct Recursive;
29
30impl Strategy for Recursive {
31 type P = PathBuf;
32 fn get_more(&self, p: &PathBuf) -> io::Result<Vec<PathBuf>> {
33 Ok(fs::read_dir(p).unwrap().map(|s| s.unwrap().path()).collect())
34 }
35
36 fn prune(&self, _: &PathBuf) -> bool { false }
37}
38
39/// A directory walker of `P` using strategy `S`.
40pub struct Subpaths<S: Strategy> {
41 stack: Vec<S::P>,
42 strategy: S,
43}
44
45impl<S: Strategy> Subpaths<S> {
46 /// Creates a directory walker with a root path and strategy.
47 pub fn new(p: &S::P, strategy: S) -> io::Result<Subpaths<S>> {
48 let stack = strategy.get_more(p)?;
49 Ok(Subpaths { stack: stack, strategy: strategy })
50 }
51}
52
53impl<S: Default + Strategy> Subpaths<S> {
54 /// Creates a directory walker with a root path and a default strategy.
55 pub fn walk(p: &S::P) -> io::Result<Subpaths<S>> {
56 Subpaths::new(p, Default::default())
57 }
58}
59
60impl<S: Default + Strategy> Default for Subpaths<S> {
61 fn default() -> Subpaths<S> {
62 Subpaths { stack: Vec::new(), strategy: Default::default() }
63 }
64}
65
66impl<S: Strategy> Iterator for Subpaths<S> {
67 type Item = S::P;
68 fn next (&mut self) -> Option<S::P> {
69 let mut opt_path = self.stack.pop();
70 while opt_path.is_some() && self.strategy.prune(opt_path.as_ref().unwrap()) {
71 opt_path = self.stack.pop();
72 }
73 match opt_path {
74 Some(path) => {
75 if path.is_dir() {
76 let result = self.strategy.get_more(&path);
77 match result {
78 Ok(dirs) => { self.stack.extend(dirs); },
79 Err(..) => { }
80 }
81 }
82 Some(path)
83 }
84 None => None,
85 }
86 }
87}
88
89fn _foo() {
90 let _walker: Subpaths<Recursive> = Subpaths::walk(&PathBuf::from("/home")).unwrap();
91}
92
93fn main() {}
tests/ui/issues/issue-20803.rs deleted-10
......@@ -1,10 +0,0 @@
1//@ run-pass
2use std::ops::Add;
3
4fn foo<T>(x: T) -> <i32 as Add<T>>::Output where i32: Add<T> {
5 42i32 + x
6}
7
8fn main() {
9 println!("{}", foo(0i32));
10}
tests/ui/issues/issue-20971.rs deleted-23
......@@ -1,23 +0,0 @@
1// Regression test for Issue #20971.
2
3//@ run-fail
4//@ error-pattern:Hello, world!
5//@ needs-subprocess
6
7pub trait Parser {
8 type Input;
9 fn parse(&mut self, input: <Self as Parser>::Input);
10}
11
12impl Parser for () {
13 type Input = ();
14 fn parse(&mut self, input: ()) {}
15}
16
17pub fn many() -> Box<dyn Parser<Input = <() as Parser>::Input> + 'static> {
18 panic!("Hello, world!")
19}
20
21fn main() {
22 many().parse(());
23}
tests/ui/issues/issue-21909.rs deleted-14
......@@ -1,14 +0,0 @@
1//@ check-pass
2
3trait A<X> {
4 fn dummy(&self, arg: X);
5}
6
7trait B {
8 type X;
9 type Y: A<Self::X>;
10
11 fn dummy(&self);
12}
13
14fn main () { }
tests/ui/issues/issue-23073.rs deleted-9
......@@ -1,9 +0,0 @@
1#![feature(associated_type_defaults)]
2
3trait Foo { type T; }
4trait Bar {
5 type Foo: Foo;
6 type FooT = <<Self as Bar>::Foo>::T; //~ ERROR ambiguous associated type
7}
8
9fn main() {}
tests/ui/issues/issue-23073.stderr deleted-14
......@@ -1,14 +0,0 @@
1error[E0223]: ambiguous associated type
2 --> $DIR/issue-23073.rs:6:17
3 |
4LL | type FooT = <<Self as Bar>::Foo>::T;
5 | ^^^^^^^^^^^^^^^^^^^^^^^
6 |
7help: if there were a trait named `Example` with associated type `T` implemented for `<Self as Bar>::Foo`, you could use the fully-qualified path
8 |
9LL | type FooT = <<Self as Bar>::Foo as Example>::T;
10 | ++++++++++
11
12error: aborting due to 1 previous error
13
14For more information about this error, try `rustc --explain E0223`.
tests/ui/issues/issue-23336.rs deleted-11
......@@ -1,11 +0,0 @@
1//@ run-pass
2pub trait Data { fn doit(&self) {} }
3impl<T> Data for T {}
4pub trait UnaryLogic { type D: Data; }
5impl UnaryLogic for () { type D = i32; }
6
7pub fn crashes<T: UnaryLogic>(t: T::D) {
8 t.doit();
9}
10
11fn main() { crashes::<()>(0); }
tests/ui/issues/issue-23406.rs deleted-15
......@@ -1,15 +0,0 @@
1//@ build-pass
2#![allow(dead_code)]
3trait Inner {
4 type T;
5}
6
7impl<'a> Inner for &'a i32 {
8 type T = i32;
9}
10
11fn f<'a>(x: &'a i32) -> <&'a i32 as Inner>::T {
12 *x
13}
14
15fn main() {}
tests/ui/issues/issue-23992.rs deleted-19
......@@ -1,19 +0,0 @@
1//@ run-pass
2pub struct Outer<T: Trait>(T);
3pub struct Inner<'a> { value: &'a bool }
4
5pub trait Trait {
6 type Error;
7 fn ready(self) -> Self::Error;
8}
9
10impl<'a> Trait for Inner<'a> {
11 type Error = Outer<Inner<'a>>;
12 fn ready(self) -> Outer<Inner<'a>> { Outer(self) }
13}
14
15fn main() {
16 let value = true;
17 let inner = Inner { value: &value };
18 assert_eq!(inner.ready().0.value, &value);
19}
tests/ui/issues/issue-25679.rs deleted-20
......@@ -1,20 +0,0 @@
1//@ run-pass
2trait Device {
3 type Resources;
4}
5#[allow(dead_code)]
6struct Foo<D, R>(D, R);
7
8impl<D: Device> Foo<D, D::Resources> {
9 fn present(&self) {}
10}
11
12struct Res;
13struct Dev;
14
15impl Device for Dev { type Resources = Res; }
16
17fn main() {
18 let foo = Foo(Dev, Res);
19 foo.present();
20}
tests/ui/issues/issue-25693.rs deleted-22
......@@ -1,22 +0,0 @@
1//@ run-pass
2#![allow(unused_variables)]
3pub trait Parameters { type SelfRef; }
4
5struct RP<'a> { _marker: std::marker::PhantomData<&'a ()> }
6struct BP;
7
8impl<'a> Parameters for RP<'a> { type SelfRef = &'a X<RP<'a>>; }
9impl Parameters for BP { type SelfRef = Box<X<BP>>; }
10
11pub struct Y;
12pub enum X<P: Parameters> {
13 Nothing,
14 SameAgain(P::SelfRef, Y)
15}
16
17fn main() {
18 let bnil: Box<X<BP>> = Box::new(X::Nothing);
19 let bx: Box<X<BP>> = Box::new(X::SameAgain(bnil, Y));
20 let rnil: X<RP> = X::Nothing;
21 let rx: X<RP> = X::SameAgain(&rnil, Y);
22}
tests/ui/issues/issue-26127.rs deleted-12
......@@ -1,12 +0,0 @@
1//@ run-pass
2trait Tr { type T; }
3impl Tr for u8 { type T=(); }
4struct S<I: Tr>(#[allow(dead_code)] I::T);
5
6fn foo<I: Tr>(i: I::T) {
7 S::<I>(i);
8}
9
10fn main() {
11 foo::<u8>(());
12}
tests/ui/issues/issue-27281.rs deleted-17
......@@ -1,17 +0,0 @@
1//@ check-pass
2pub trait Trait<'a> {
3 type T;
4 type U;
5 fn foo(&self, s: &'a ()) -> &'a ();
6}
7
8impl<'a> Trait<'a> for () {
9 type T = &'a ();
10 type U = Self::T;
11
12 fn foo(&self, s: &'a ()) -> &'a () {
13 let t: Self::T = s; t
14 }
15}
16
17fn main() {}
tests/ui/issues/issue-28983.rs deleted-22
......@@ -1,22 +0,0 @@
1//@ run-pass
2pub trait Test { type T; }
3
4impl Test for u32 {
5 type T = i32;
6}
7
8pub mod export {
9 #[no_mangle]
10 pub extern "C" fn issue_28983(t: <u32 as crate::Test>::T) -> i32 { t*3 }
11}
12
13// to test both exporting and importing functions, import
14// a function from ourselves.
15extern "C" {
16 fn issue_28983(t: <u32 as Test>::T) -> i32;
17}
18
19fn main() {
20 assert_eq!(export::issue_28983(2), 6);
21 assert_eq!(unsafe { issue_28983(3) }, 9);
22}
tests/ui/issues/issue-34839.rs deleted-19
......@@ -1,19 +0,0 @@
1//@ check-pass
2
3trait RegularExpression: Sized {
4 type Text;
5}
6
7struct ExecNoSyncStr<'a>(&'a u8);
8
9impl<'c> RegularExpression for ExecNoSyncStr<'c> {
10 type Text = u8;
11}
12
13struct FindCaptures<'t, R>(&'t R::Text) where R: RegularExpression, R::Text: 't;
14
15enum FindCapturesInner<'r, 't> {
16 Dynamic(FindCaptures<'t, ExecNoSyncStr<'r>>),
17}
18
19fn main() {}
tests/ui/issues/issue-35600.rs deleted-18
......@@ -1,18 +0,0 @@
1//@ run-pass
2#![allow(non_camel_case_types)]
3#![allow(unused_variables)]
4
5trait Foo {
6 type bar;
7 fn bar();
8}
9
10impl Foo for () {
11 type bar = ();
12 fn bar() {}
13}
14
15fn main() {
16 let x: <() as Foo>::bar = ();
17 <()>::bar();
18}
tests/ui/issues/issue-36036-associated-type-layout.rs deleted-27
......@@ -1,27 +0,0 @@
1//@ run-pass
2// Issue 36036: computing the layout of a type composed from another
3// trait's associated type caused compiler to ICE when the associated
4// type was allowed to be unsized, even though the known instantiated
5// type is itself sized.
6
7#![allow(dead_code)]
8
9trait Context {
10 type Container: ?Sized;
11}
12
13impl Context for u16 {
14 type Container = u8;
15}
16
17struct Wrapper<C: Context+'static> {
18 container: &'static C::Container
19}
20
21fn foobar(_: Wrapper<u16>) {}
22
23static VALUE: u8 = 0;
24
25fn main() {
26 foobar(Wrapper { container: &VALUE });
27}
tests/ui/issues/issue-37051.rs deleted-18
......@@ -1,18 +0,0 @@
1//@ check-pass
2
3#![feature(associated_type_defaults)]
4
5trait State: Sized {
6 type NextState: State = StateMachineEnded;
7 fn execute(self) -> Option<Self::NextState>;
8}
9
10struct StateMachineEnded;
11
12impl State for StateMachineEnded {
13 fn execute(self) -> Option<Self::NextState> {
14 None
15 }
16}
17
18fn main() {}
tests/ui/issues/issue-37109.rs deleted-16
......@@ -1,16 +0,0 @@
1//@ run-pass
2trait ToRef<'a> {
3 type Ref: 'a;
4}
5
6impl<'a, U: 'a> ToRef<'a> for U {
7 type Ref = &'a U;
8}
9
10fn example<'a, T>(value: &'a T) -> (<T as ToRef<'a>>::Ref, u32) {
11 (value, 0)
12}
13
14fn main() {
15 example(&0);
16}
tests/ui/issues/issue-39970.rs deleted-21
......@@ -1,21 +0,0 @@
1trait Array<'a> {
2 type Element: 'a;
3}
4
5trait Visit {
6 fn visit() {}
7}
8
9impl<'a> Array<'a> for () {
10 type Element = &'a ();
11}
12
13impl Visit for () where
14 //(): for<'a> Array<'a, Element=&'a ()>, // No ICE
15 (): for<'a> Array<'a, Element=()>, // ICE
16{}
17
18fn main() {
19 <() as Visit>::visit();
20 //~^ ERROR type mismatch resolving `<() as Array<'a>>::Element == ()`
21}
tests/ui/issues/issue-39970.stderr deleted-23
......@@ -1,23 +0,0 @@
1error[E0271]: type mismatch resolving `<() as Array<'a>>::Element == ()`
2 --> $DIR/issue-39970.rs:19:6
3 |
4LL | <() as Visit>::visit();
5 | ^^ type mismatch resolving `<() as Array<'a>>::Element == ()`
6 |
7note: expected this to be `()`
8 --> $DIR/issue-39970.rs:10:20
9 |
10LL | type Element = &'a ();
11 | ^^^^^^
12note: required for `()` to implement `Visit`
13 --> $DIR/issue-39970.rs:13:6
14 |
15LL | impl Visit for () where
16 | ^^^^^ ^^
17LL | //(): for<'a> Array<'a, Element=&'a ()>, // No ICE
18LL | (): for<'a> Array<'a, Element=()>, // ICE
19 | ---------- unsatisfied trait bound introduced here
20
21error: aborting due to 1 previous error
22
23For more information about this error, try `rustc --explain E0271`.
tests/ui/issues/issue-43357.rs deleted-11
......@@ -1,11 +0,0 @@
1//@ check-pass
2#![allow(dead_code)]
3trait Trait {
4 type Output;
5}
6
7fn f<T: Trait>() {
8 std::mem::size_of::<T::Output>();
9}
10
11fn main() {}
tests/ui/pin-ergonomics/ref-pat-suggestions.fixed created+12
......@@ -0,0 +1,12 @@
1//@ run-rustfix
2
3#![feature(pin_ergonomics)]
4#![allow(unused)]
5
6fn pin_mut_param(x: &pin mut i32) {}
7//~^ ERROR mismatched types
8
9fn pin_const_param(x: &pin const i32) {}
10//~^ ERROR mismatched types
11
12fn main() {}
tests/ui/pin-ergonomics/ref-pat-suggestions.rs created+12
......@@ -0,0 +1,12 @@
1//@ run-rustfix
2
3#![feature(pin_ergonomics)]
4#![allow(unused)]
5
6fn pin_mut_param(&pin mut x: i32) {}
7//~^ ERROR mismatched types
8
9fn pin_const_param(&pin const x: i32) {}
10//~^ ERROR mismatched types
11
12fn main() {}
tests/ui/pin-ergonomics/ref-pat-suggestions.stderr created+40
......@@ -0,0 +1,40 @@
1error[E0308]: mismatched types
2 --> $DIR/ref-pat-suggestions.rs:6:18
3 |
4LL | fn pin_mut_param(&pin mut x: i32) {}
5 | ^^^^^^^^^^ --- expected due to this
6 | |
7 | expected `i32`, found `Pin<&mut _>`
8 |
9 = note: expected type `i32`
10 found struct `Pin<&mut _>`
11note: to declare a mutable parameter use: `mut x`
12 --> $DIR/ref-pat-suggestions.rs:6:18
13 |
14LL | fn pin_mut_param(&pin mut x: i32) {}
15 | ^^^^^^^^^^
16help: to take parameter `x` by reference, move `&pin mut` to the type
17 |
18LL - fn pin_mut_param(&pin mut x: i32) {}
19LL + fn pin_mut_param(x: &pin mut i32) {}
20 |
21
22error[E0308]: mismatched types
23 --> $DIR/ref-pat-suggestions.rs:9:20
24 |
25LL | fn pin_const_param(&pin const x: i32) {}
26 | ^^^^^^^^^^^^ --- expected due to this
27 | |
28 | expected `i32`, found `Pin<&_>`
29 |
30 = note: expected type `i32`
31 found struct `Pin<&_>`
32help: to take parameter `x` by reference, move `&pin const` to the type
33 |
34LL - fn pin_const_param(&pin const x: i32) {}
35LL + fn pin_const_param(x: &pin const i32) {}
36 |
37
38error: aborting due to 2 previous errors
39
40For more information about this error, try `rustc --explain E0308`.
tests/ui/resolve/extern-prelude.rs+1-1
......@@ -1,4 +1,4 @@
1//@ build-pass (FIXME(62277): could be check-pass?)
1//@ check-pass
22//@ compile-flags:--extern extern_prelude --extern Vec
33//@ aux-build:extern-prelude.rs
44//@ aux-build:extern-prelude-vec.rs
yarn.lock+4-4
......@@ -290,10 +290,10 @@ braces@^3.0.3:
290290 dependencies:
291291 fill-range "^7.1.1"
292292
293browser-ui-test@^0.23.3:
294 version "0.23.3"
295 resolved "https://registry.yarnpkg.com/browser-ui-test/-/browser-ui-test-0.23.3.tgz#fe3b978cfe43d09ee9edd4b9d939a936dd654c30"
296 integrity sha512-VWiRH7sSwpnQSe1Rll5iOPS+IeFa1rMThCXrP5Pwspm95OOA8Wylv2B6yqreEw25DE3qPmgJUeZZC7Uh9wnjSg==
293browser-ui-test@^0.23.5:
294 version "0.23.5"
295 resolved "https://registry.yarnpkg.com/browser-ui-test/-/browser-ui-test-0.23.5.tgz#f8fab778a1e00f339f53bb44e76ad14c5b57ce4f"
296 integrity sha512-S4ztxfOa3vSqV86xS6huIrA8MKSrSqfZUFJfAgEN29U17eRtrYQt/ZGKYJBUP5sv5UYH6ZgnE05z8+Werm/8sw==
297297 dependencies:
298298 css-unit-converter "^1.1.2"
299299 pngjs "^3.4.0"