diff --git a/compiler/rustc_ast/src/token.rs b/compiler/rustc_ast/src/token.rs index f7cd63aaaf823..6e6f0f1b2660e 100644 --- a/compiler/rustc_ast/src/token.rs +++ b/compiler/rustc_ast/src/token.rs @@ -928,11 +928,6 @@ impl Token { self.is_non_raw_ident_where(Ident::is_path_segment_keyword) } - /// Don't use this unless you're doing something very loose and heuristic-y. - pub fn is_any_keyword(&self) -> bool { - self.is_non_raw_ident_where(Ident::is_any_keyword) - } - /// Returns true for reserved identifiers used internally for elided lifetimes, /// unnamed method parameters, crate root module, error recovery etc. pub fn is_special_ident(&self) -> bool { diff --git a/compiler/rustc_ast_lowering/src/item.rs b/compiler/rustc_ast_lowering/src/item.rs index 518349343b3a1..219bf62c916dd 100644 --- a/compiler/rustc_ast_lowering/src/item.rs +++ b/compiler/rustc_ast_lowering/src/item.rs @@ -132,8 +132,7 @@ impl<'hir> LoweringContext<'_, 'hir> { } pub(super) fn lower_item_ref(&mut self, i: &Item) -> SmallVec<[hir::ItemId; 1]> { - let mut node_ids = - smallvec![hir::ItemId { owner_id: hir::OwnerId { def_id: self.local_def_id(i.id) } }]; + let mut node_ids = smallvec![hir::ItemId { owner_id: self.owner_id(i.id) }]; if let ItemKind::Use(use_tree) = &i.kind { self.lower_item_id_use_tree(use_tree, &mut node_ids); } @@ -144,9 +143,7 @@ impl<'hir> LoweringContext<'_, 'hir> { match &tree.kind { UseTreeKind::Nested { items, .. } => { for &(ref nested, id) in items { - vec.push(hir::ItemId { - owner_id: hir::OwnerId { def_id: self.local_def_id(id) }, - }); + vec.push(hir::ItemId { owner_id: self.owner_id(id) }); self.lower_item_id_use_tree(nested, vec); } } @@ -585,7 +582,7 @@ impl<'hir> LoweringContext<'_, 'hir> { // Add all the nested `PathListItem`s to the HIR. for &(ref use_tree, id) in trees { - let new_hir_id = self.local_def_id(id); + let owner_id = self.owner_id(id); // Each `use` import is an item and thus are owners of the // names in the path. Up to this point the nested import is @@ -602,7 +599,7 @@ impl<'hir> LoweringContext<'_, 'hir> { } let item = hir::Item { - owner_id: hir::OwnerId { def_id: new_hir_id }, + owner_id, kind, vis_span, span: this.lower_span(use_tree.span), @@ -710,7 +707,7 @@ impl<'hir> LoweringContext<'_, 'hir> { fn lower_foreign_item_ref(&mut self, i: &ForeignItem) -> hir::ForeignItemRef { hir::ForeignItemRef { - id: hir::ForeignItemId { owner_id: hir::OwnerId { def_id: self.local_def_id(i.id) } }, + id: hir::ForeignItemId { owner_id: self.owner_id(i.id) }, ident: self.lower_ident(i.ident), span: self.lower_span(i.span), } @@ -931,7 +928,7 @@ impl<'hir> LoweringContext<'_, 'hir> { panic!("macros should have been expanded by now") } }; - let id = hir::TraitItemId { owner_id: hir::OwnerId { def_id: self.local_def_id(i.id) } }; + let id = hir::TraitItemId { owner_id: self.owner_id(i.id) }; hir::TraitItemRef { id, ident: self.lower_ident(i.ident), @@ -1046,7 +1043,7 @@ impl<'hir> LoweringContext<'_, 'hir> { fn lower_impl_item_ref(&mut self, i: &AssocItem) -> hir::ImplItemRef { hir::ImplItemRef { - id: hir::ImplItemId { owner_id: hir::OwnerId { def_id: self.local_def_id(i.id) } }, + id: hir::ImplItemId { owner_id: self.owner_id(i.id) }, ident: self.lower_ident(i.ident), span: self.lower_span(i.span), kind: match &i.kind { diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index e08850da4a7a8..6c380d77b4934 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -536,6 +536,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { self.opt_local_def_id(node).unwrap_or_else(|| panic!("no entry for node id: `{node:?}`")) } + /// Given the id of an owner node in the AST, returns the corresponding `OwnerId`. + fn owner_id(&self, node: NodeId) -> hir::OwnerId { + hir::OwnerId { def_id: self.local_def_id(node) } + } + /// Freshen the `LoweringContext` and ready it to lower a nested item. /// The lowered item is registered into `self.children`. /// @@ -547,7 +552,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { owner: NodeId, f: impl FnOnce(&mut Self) -> hir::OwnerNode<'hir>, ) { - let def_id = self.local_def_id(owner); + let owner_id = self.owner_id(owner); let current_attrs = std::mem::take(&mut self.attrs); let current_bodies = std::mem::take(&mut self.bodies); @@ -558,8 +563,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { #[cfg(debug_assertions)] let current_node_id_to_local_id = std::mem::take(&mut self.node_id_to_local_id); let current_trait_map = std::mem::take(&mut self.trait_map); - let current_owner = - std::mem::replace(&mut self.current_hir_id_owner, hir::OwnerId { def_id }); + let current_owner = std::mem::replace(&mut self.current_hir_id_owner, owner_id); let current_local_counter = std::mem::replace(&mut self.item_local_id_counter, hir::ItemLocalId::new(1)); let current_impl_trait_defs = std::mem::take(&mut self.impl_trait_defs); @@ -577,7 +581,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { } let item = f(self); - debug_assert_eq!(def_id, item.def_id().def_id); + debug_assert_eq!(owner_id, item.def_id()); // `f` should have consumed all the elements in these vectors when constructing `item`. debug_assert!(self.impl_trait_defs.is_empty()); debug_assert!(self.impl_trait_bounds.is_empty()); @@ -598,8 +602,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { self.impl_trait_defs = current_impl_trait_defs; self.impl_trait_bounds = current_impl_trait_bounds; - debug_assert!(!self.children.iter().any(|(id, _)| id == &def_id)); - self.children.push((def_id, hir::MaybeOwner::Owner(info))); + debug_assert!(!self.children.iter().any(|(id, _)| id == &owner_id.def_id)); + self.children.push((owner_id.def_id, hir::MaybeOwner::Owner(info))); } fn make_owner_info(&mut self, node: hir::OwnerNode<'hir>) -> &'hir hir::OwnerInfo<'hir> { diff --git a/compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs b/compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs index 0322c9e4ab011..7ef36d0e9ae37 100644 --- a/compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs +++ b/compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs @@ -971,15 +971,17 @@ where rhs: T, ) -> Result<(), NoSolution> { let goals = self.delegate.relate(param_env, lhs, variance, rhs, self.origin_span)?; - if cfg!(debug_assertions) { - for g in goals.iter() { - match g.predicate.kind().skip_binder() { - ty::PredicateKind::Subtype { .. } | ty::PredicateKind::AliasRelate(..) => {} - p => unreachable!("unexpected nested goal in `relate`: {p:?}"), + for &goal in goals.iter() { + let source = match goal.predicate.kind().skip_binder() { + ty::PredicateKind::Subtype { .. } | ty::PredicateKind::AliasRelate(..) => { + GoalSource::TypeRelating } - } + // FIXME(-Znext-solver=coinductive): should these WF goals also be unproductive? + ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(_)) => GoalSource::Misc, + p => unreachable!("unexpected nested goal in `relate`: {p:?}"), + }; + self.add_goal(source, goal); } - self.add_goals(GoalSource::TypeRelating, goals); Ok(()) } diff --git a/compiler/rustc_resolve/src/build_reduced_graph.rs b/compiler/rustc_resolve/src/build_reduced_graph.rs index 763e9207a126b..42fe01b1c84c3 100644 --- a/compiler/rustc_resolve/src/build_reduced_graph.rs +++ b/compiler/rustc_resolve/src/build_reduced_graph.rs @@ -1115,7 +1115,6 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> { } }); } else { - #[allow(rustc::potential_query_instability)] // FIXME for ident in single_imports.iter().cloned() { let result = self.r.maybe_resolve_ident_in_module( ModuleOrUniformRoot::Module(module), diff --git a/compiler/rustc_resolve/src/diagnostics.rs b/compiler/rustc_resolve/src/diagnostics.rs index 5361af98f3c74..7decc2a09721f 100644 --- a/compiler/rustc_resolve/src/diagnostics.rs +++ b/compiler/rustc_resolve/src/diagnostics.rs @@ -1468,7 +1468,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { return; } - #[allow(rustc::potential_query_instability)] // FIXME let unused_macro = self.unused_macros.iter().find_map(|(def_id, (_, unused_ident))| { if unused_ident.name == ident.name { Some((def_id, unused_ident)) } else { None } }); diff --git a/compiler/rustc_resolve/src/ident.rs b/compiler/rustc_resolve/src/ident.rs index 27d63198836a3..5f0a2a597e9b4 100644 --- a/compiler/rustc_resolve/src/ident.rs +++ b/compiler/rustc_resolve/src/ident.rs @@ -946,7 +946,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { // Check if one of single imports can still define the name, // if it can then our result is not determined and can be invalidated. - #[allow(rustc::potential_query_instability)] // FIXME for single_import in &resolution.single_imports { if ignore_import == Some(*single_import) { // This branch handles a cycle in single imports. diff --git a/compiler/rustc_resolve/src/imports.rs b/compiler/rustc_resolve/src/imports.rs index 89b9a07435183..454460e10dc98 100644 --- a/compiler/rustc_resolve/src/imports.rs +++ b/compiler/rustc_resolve/src/imports.rs @@ -4,7 +4,7 @@ use std::cell::Cell; use std::mem; use rustc_ast::NodeId; -use rustc_data_structures::fx::FxHashSet; +use rustc_data_structures::fx::{FxHashSet, FxIndexSet}; use rustc_data_structures::intern::Interned; use rustc_errors::codes::*; use rustc_errors::{Applicability, MultiSpan, pluralize, struct_span_code_err}; @@ -233,7 +233,7 @@ impl<'ra> ImportData<'ra> { pub(crate) struct NameResolution<'ra> { /// Single imports that may define the name in the namespace. /// Imports are arena-allocated, so it's ok to use pointers as keys. - pub single_imports: FxHashSet>, + pub single_imports: FxIndexSet>, /// The least shadowable known binding for this name, or None if there are no known bindings. pub binding: Option>, pub shadowed_glob: Option>, @@ -494,7 +494,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { let key = BindingKey::new(target, ns); let _ = this.try_define(import.parent_scope.module, key, dummy_binding, false); this.update_resolution(import.parent_scope.module, key, false, |_, resolution| { - resolution.single_imports.remove(&import); + resolution.single_imports.swap_remove(&import); }) }); self.record_use(target, dummy_binding, Used::Other); @@ -862,7 +862,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { } let key = BindingKey::new(target, ns); this.update_resolution(parent, key, false, |_, resolution| { - resolution.single_imports.remove(&import); + resolution.single_imports.swap_remove(&import); }); } } diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index e04d0083548b1..f8808582353ad 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -272,7 +272,7 @@ impl RibKind<'_> { /// resolving, the name is looked up from inside out. #[derive(Debug)] pub(crate) struct Rib<'ra, R = Res> { - pub bindings: FxHashMap, + pub bindings: FxIndexMap, pub patterns_with_skipped_bindings: UnordMap)>>, pub kind: RibKind<'ra>, } @@ -672,7 +672,7 @@ struct DiagMetadata<'ast> { /// A list of labels as of yet unused. Labels will be removed from this map when /// they are used (in a `break` or `continue` statement) - unused_labels: FxHashMap, + unused_labels: FxIndexMap, /// Only used for better errors on `let x = { foo: bar };`. /// In the case of a parse error with `let x = { foo: bar, };`, this isn't needed, it's only @@ -1639,8 +1639,8 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { // Allow all following defaults to refer to this type parameter. let i = &Ident::with_dummy_span(param.ident.name); - forward_ty_ban_rib.bindings.remove(i); - forward_ty_ban_rib_const_param_ty.bindings.remove(i); + forward_ty_ban_rib.bindings.swap_remove(i); + forward_ty_ban_rib_const_param_ty.bindings.swap_remove(i); } GenericParamKind::Const { ref ty, kw_span: _, ref default } => { // Const parameters can't have param bounds. @@ -1675,8 +1675,8 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { // Allow all following defaults to refer to this const parameter. let i = &Ident::with_dummy_span(param.ident.name); - forward_const_ban_rib.bindings.remove(i); - forward_const_ban_rib_const_param_ty.bindings.remove(i); + forward_const_ban_rib.bindings.swap_remove(i); + forward_const_ban_rib_const_param_ty.bindings.swap_remove(i); } } } @@ -2885,7 +2885,6 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { break; } - #[allow(rustc::potential_query_instability)] // FIXME seen_bindings .extend(parent_rib.bindings.keys().map(|ident| (*ident, ident.span))); } @@ -4000,7 +3999,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { } } - fn innermost_rib_bindings(&mut self, ns: Namespace) -> &mut FxHashMap { + fn innermost_rib_bindings(&mut self, ns: Namespace) -> &mut FxIndexMap { &mut self.ribs[ns].last_mut().unwrap().bindings } @@ -4776,7 +4775,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { Ok((node_id, _)) => { // Since this res is a label, it is never read. self.r.label_res_map.insert(expr.id, node_id); - self.diag_metadata.unused_labels.remove(&node_id); + self.diag_metadata.unused_labels.swap_remove(&node_id); } Err(error) => { self.report_error(label.ident.span, error); @@ -5198,7 +5197,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { let mut late_resolution_visitor = LateResolutionVisitor::new(self); late_resolution_visitor.resolve_doc_links(&krate.attrs, MaybeExported::Ok(CRATE_NODE_ID)); visit::walk_crate(&mut late_resolution_visitor, krate); - #[allow(rustc::potential_query_instability)] // FIXME for (id, span) in late_resolution_visitor.diag_metadata.unused_labels.iter() { self.lint_buffer.buffer_lint( lint::builtin::UNUSED_LABELS, diff --git a/compiler/rustc_resolve/src/late/diagnostics.rs b/compiler/rustc_resolve/src/late/diagnostics.rs index 3d666055a94fb..75232e0de0052 100644 --- a/compiler/rustc_resolve/src/late/diagnostics.rs +++ b/compiler/rustc_resolve/src/late/diagnostics.rs @@ -830,7 +830,6 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> { if let Some(rib) = &self.last_block_rib && let RibKind::Normal = rib.kind { - #[allow(rustc::potential_query_instability)] // FIXME for (ident, &res) in &rib.bindings { if let Res::Local(_) = res && path.len() == 1 @@ -1019,7 +1018,6 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> { if let Some(err_code) = err.code { if err_code == E0425 { for label_rib in &self.label_ribs { - #[allow(rustc::potential_query_instability)] // FIXME for (label_ident, node_id) in &label_rib.bindings { let ident = path.last().unwrap().ident; if format!("'{ident}") == label_ident.to_string() { @@ -1036,7 +1034,7 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> { Applicability::MaybeIncorrect, ); // Do not lint against unused label when we suggest them. - self.diag_metadata.unused_labels.remove(node_id); + self.diag_metadata.unused_labels.swap_remove(node_id); } } } @@ -2265,7 +2263,6 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> { }; // Locals and type parameters - #[allow(rustc::potential_query_instability)] // FIXME for (ident, &res) in &rib.bindings { if filter_fn(res) && ident.span.ctxt() == rib_ctxt { names.push(TypoSuggestion::typo_from_ident(*ident, res)); @@ -2793,7 +2790,6 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> { let within_scope = self.is_label_valid_from_rib(rib_index); let rib = &self.label_ribs[rib_index]; - #[allow(rustc::potential_query_instability)] // FIXME let names = rib .bindings .iter() @@ -2805,7 +2801,6 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> { // Upon finding a similar name, get the ident that it was from - the span // contained within helps make a useful diagnostic. In addition, determine // whether this candidate is within scope. - #[allow(rustc::potential_query_instability)] // FIXME let (ident, _) = rib.bindings.iter().find(|(ident, _)| ident.name == symbol).unwrap(); (*ident, within_scope) }) diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs index ff31af0025b54..78153fd417407 100644 --- a/compiler/rustc_resolve/src/lib.rs +++ b/compiler/rustc_resolve/src/lib.rs @@ -1137,7 +1137,7 @@ pub struct Resolver<'ra, 'tcx> { non_macro_attr: MacroData, local_macro_def_scopes: FxHashMap>, ast_transform_scopes: FxHashMap>, - unused_macros: FxHashMap, + unused_macros: FxIndexMap, /// A map from the macro to all its potentially unused arms. unused_macro_rules: FxIndexMap>, proc_macro_stubs: FxHashSet, diff --git a/compiler/rustc_resolve/src/macros.rs b/compiler/rustc_resolve/src/macros.rs index 34441d313f59f..3637854f1204f 100644 --- a/compiler/rustc_resolve/src/macros.rs +++ b/compiler/rustc_resolve/src/macros.rs @@ -323,7 +323,6 @@ impl<'ra, 'tcx> ResolverExpand for Resolver<'ra, 'tcx> { } fn check_unused_macros(&mut self) { - #[allow(rustc::potential_query_instability)] // FIXME for (_, &(node_id, ident)) in self.unused_macros.iter() { self.lint_buffer.buffer_lint( UNUSED_MACROS, @@ -576,7 +575,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { match res { Res::Def(DefKind::Macro(_), def_id) => { if let Some(def_id) = def_id.as_local() { - self.unused_macros.remove(&def_id); + self.unused_macros.swap_remove(&def_id); if self.proc_macro_stubs.contains(&def_id) { self.dcx().emit_err(errors::ProcMacroSameCrate { span: path.span, diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 210966bed6277..3e4742439655a 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -26,13 +26,13 @@ symbols! { // documents (such as the Rust Reference) about whether it is a keyword // (e.g. `_`). // - // If you modify this list, adjust any relevant `Symbol::{is,can_be}_*` predicates and - // `used_keywords`. - // But this should rarely be necessary if the keywords are kept in alphabetic order. + // If you modify this list, adjust any relevant `Symbol::{is,can_be}_*` + // predicates and `used_keywords`. Also consider adding new keywords to the + // `ui/parser/raw/raw-idents.rs` test. Keywords { // Special reserved identifiers used internally for elided lifetimes, // unnamed method parameters, crate root module, error recovery etc. - // Matching predicates: `is_any_keyword`, `is_special`/`is_reserved` + // Matching predicates: `is_special`/`is_reserved` // // Notes about `kw::Empty`: // - Its use can blur the lines between "empty symbol" and "no symbol". @@ -42,13 +42,16 @@ symbols! { // present, it's better to use `sym::dummy` than `kw::Empty`, because // it's clearer that it's intended as a dummy value, and more likely // to be detected if it accidentally does get used. + // tidy-alphabetical-start + DollarCrate: "$crate", Empty: "", PathRoot: "{{root}}", - DollarCrate: "$crate", Underscore: "_", + // tidy-alphabetical-end // Keywords that are used in stable Rust. - // Matching predicates: `is_any_keyword`, `is_used_keyword_always`/`is_reserved` + // Matching predicates: `is_used_keyword_always`/`is_reserved` + // tidy-alphabetical-start As: "as", Break: "break", Const: "const", @@ -84,9 +87,11 @@ symbols! { Use: "use", Where: "where", While: "while", + // tidy-alphabetical-end // Keywords that are used in unstable Rust or reserved for future use. - // Matching predicates: `is_any_keyword`, `is_unused_keyword_always`/`is_reserved` + // Matching predicates: `is_unused_keyword_always`/`is_reserved` + // tidy-alphabetical-start Abstract: "abstract", Become: "become", Box: "box", @@ -99,41 +104,48 @@ symbols! { Unsized: "unsized", Virtual: "virtual", Yield: "yield", + // tidy-alphabetical-end // Edition-specific keywords that are used in stable Rust. - // Matching predicates: `is_any_keyword`, `is_used_keyword_conditional`/`is_reserved` (if + // Matching predicates: `is_used_keyword_conditional`/`is_reserved` (if // the edition suffices) + // tidy-alphabetical-start Async: "async", // >= 2018 Edition only Await: "await", // >= 2018 Edition only Dyn: "dyn", // >= 2018 Edition only + // tidy-alphabetical-end // Edition-specific keywords that are used in unstable Rust or reserved for future use. - // Matching predicates: `is_any_keyword`, `is_unused_keyword_conditional`/`is_reserved` (if + // Matching predicates: `is_unused_keyword_conditional`/`is_reserved` (if // the edition suffices) + // tidy-alphabetical-start Gen: "gen", // >= 2024 Edition only Try: "try", // >= 2018 Edition only - - // NOTE: When adding new keywords, consider adding them to the ui/parser/raw/raw-idents.rs test. + // tidy-alphabetical-end // "Lifetime keywords": regular keywords with a leading `'`. - // Matching predicates: `is_any_keyword` - UnderscoreLifetime: "'_", + // Matching predicates: none + // tidy-alphabetical-start StaticLifetime: "'static", + UnderscoreLifetime: "'_", + // tidy-alphabetical-end // Weak keywords, have special meaning only in specific contexts. - // Matching predicates: `is_any_keyword` + // Matching predicates: none + // tidy-alphabetical-start Auto: "auto", Builtin: "builtin", Catch: "catch", + ContractEnsures: "contract_ensures", + ContractRequires: "contract_requires", Default: "default", MacroRules: "macro_rules", Raw: "raw", Reuse: "reuse", - ContractEnsures: "contract_ensures", - ContractRequires: "contract_requires", Safe: "safe", Union: "union", Yeet: "yeet", + // tidy-alphabetical-end } // Pre-interned symbols that can be referred to with `rustc_span::sym::*`. @@ -2677,11 +2689,6 @@ pub mod sym { } impl Symbol { - /// Don't use this unless you're doing something very loose and heuristic-y. - pub fn is_any_keyword(self) -> bool { - self >= kw::As && self <= kw::Yeet - } - fn is_special(self) -> bool { self <= kw::Underscore } @@ -2690,14 +2697,14 @@ impl Symbol { self >= kw::As && self <= kw::While } - fn is_used_keyword_conditional(self, edition: impl FnOnce() -> Edition) -> bool { - (self >= kw::Async && self <= kw::Dyn) && edition() >= Edition::Edition2018 - } - fn is_unused_keyword_always(self) -> bool { self >= kw::Abstract && self <= kw::Yield } + fn is_used_keyword_conditional(self, edition: impl FnOnce() -> Edition) -> bool { + (self >= kw::Async && self <= kw::Dyn) && edition() >= Edition::Edition2018 + } + fn is_unused_keyword_conditional(self, edition: impl Copy + FnOnce() -> Edition) -> bool { self == kw::Gen && edition().at_least_rust_2024() || self == kw::Try && edition().at_least_rust_2018() @@ -2738,11 +2745,6 @@ impl Symbol { } impl Ident { - /// Don't use this unless you're doing something very loose and heuristic-y. - pub fn is_any_keyword(self) -> bool { - self.name.is_any_keyword() - } - /// Returns `true` for reserved identifiers used internally for elided lifetimes, /// unnamed method parameters, crate root module, error recovery etc. pub fn is_special(self) -> bool { @@ -2792,7 +2794,7 @@ impl Ident { /// *Note:* Please update this if a new keyword is added beyond the current /// range. pub fn used_keywords(edition: impl Copy + FnOnce() -> Edition) -> Vec { - (kw::Empty.as_u32()..kw::Yeet.as_u32()) + (kw::DollarCrate.as_u32()..kw::Yeet.as_u32()) .filter_map(|kw| { let kw = Symbol::new(kw); if kw.is_used_keyword_always() || kw.is_used_keyword_conditional(edition) { diff --git a/compiler/rustc_target/src/spec/json.rs b/compiler/rustc_target/src/spec/json.rs index 134405f3630e7..4b6de5e18f50f 100644 --- a/compiler/rustc_target/src/spec/json.rs +++ b/compiler/rustc_target/src/spec/json.rs @@ -103,6 +103,12 @@ impl Target { base.$key_name = Some(s); } } ); + ($key_name:ident, Option>) => ( { + let name = (stringify!($key_name)).replace("_", "-"); + if let Some(s) = obj.remove(&name).and_then(|b| Some(b.as_str()?.to_string())) { + base.$key_name = Some(s.into()); + } + } ); ($key_name:ident, BinaryFormat) => ( { let name = (stringify!($key_name)).replace("_", "-"); obj.remove(&name).and_then(|f| f.as_str().and_then(|s| { @@ -623,6 +629,7 @@ impl Target { key!(stack_probes, StackProbeType)?; key!(min_global_align, Option); key!(default_codegen_units, Option); + key!(default_codegen_backend, Option>); key!(trap_unreachable, bool); key!(requires_lto, bool); key!(singlethread, bool); @@ -801,6 +808,7 @@ impl ToJson for Target { target_option_val!(stack_probes); target_option_val!(min_global_align); target_option_val!(default_codegen_units); + target_option_val!(default_codegen_backend); target_option_val!(trap_unreachable); target_option_val!(requires_lto); target_option_val!(singlethread); diff --git a/compiler/rustc_ty_utils/src/layout.rs b/compiler/rustc_ty_utils/src/layout.rs index 7334beb52c9d5..0017186c1b082 100644 --- a/compiler/rustc_ty_utils/src/layout.rs +++ b/compiler/rustc_ty_utils/src/layout.rs @@ -611,7 +611,7 @@ fn layout_of_uncached<'tcx>( } // Types with no meaningful known layout. - ty::Param(_) => { + ty::Param(_) | ty::Placeholder(..) => { return Err(error(cx, LayoutError::TooGeneric(ty))); } @@ -628,11 +628,7 @@ fn layout_of_uncached<'tcx>( return Err(error(cx, err)); } - ty::Placeholder(..) - | ty::Bound(..) - | ty::CoroutineWitness(..) - | ty::Infer(_) - | ty::Error(_) => { + ty::Bound(..) | ty::CoroutineWitness(..) | ty::Infer(_) | ty::Error(_) => { // `ty::Error` is handled at the top of this function. bug!("layout_of: unexpected type `{ty}`") } diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index 5f80aded9d0b4..27eb56a9858b8 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -1013,7 +1013,6 @@ pub(crate) fn extract_cfg_from_attrs<'a, I: Iterator tcx: TyCtxt<'_>, hidden_cfg: &FxHashSet, ) -> Option> { - let sess = tcx.sess; let doc_cfg_active = tcx.features().doc_cfg(); let doc_auto_cfg_active = tcx.features().doc_auto_cfg(); @@ -1034,9 +1033,27 @@ pub(crate) fn extract_cfg_from_attrs<'a, I: Iterator .filter(|attr| attr.has_name(sym::cfg)) .peekable(); if doc_cfg.peek().is_some() && doc_cfg_active { - doc_cfg - .filter_map(|attr| Cfg::parse(&attr).ok()) - .fold(Cfg::True, |cfg, new_cfg| cfg & new_cfg) + let sess = tcx.sess; + doc_cfg.fold(Cfg::True, |mut cfg, item| { + if let Some(cfg_mi) = + item.meta_item().and_then(|item| rustc_expand::config::parse_cfg(item, sess)) + { + // The result is unused here but we can gate unstable predicates + rustc_attr_parsing::cfg_matches( + cfg_mi, + tcx.sess, + rustc_ast::CRATE_NODE_ID, + Some(tcx.features()), + ); + match Cfg::parse(cfg_mi) { + Ok(new_cfg) => cfg &= new_cfg, + Err(e) => { + sess.dcx().span_err(e.span, e.msg); + } + } + } + cfg + }) } else if doc_auto_cfg_active { // If there is no `doc(cfg())`, then we retrieve the `cfg()` attributes (because // `doc(cfg())` overrides `cfg()`). @@ -1053,40 +1070,6 @@ pub(crate) fn extract_cfg_from_attrs<'a, I: Iterator Cfg::True }; - for attr in attrs.clone() { - // #[doc] - if attr.doc_str().is_none() && attr.has_name(sym::doc) { - // #[doc(...)] - if let Some(list) = attr.meta_item_list() { - for item in list { - // #[doc(hidden)] - if !item.has_name(sym::cfg) { - continue; - } - // #[doc(cfg(...))] - if let Some(cfg_mi) = item - .meta_item() - .and_then(|item| rustc_expand::config::parse_cfg(item, sess)) - { - // The result is unused here but we can gate unstable predicates - rustc_attr_parsing::cfg_matches( - cfg_mi, - tcx.sess, - rustc_ast::CRATE_NODE_ID, - Some(tcx.features()), - ); - match Cfg::parse(cfg_mi) { - Ok(new_cfg) => cfg &= new_cfg, - Err(e) => { - sess.dcx().span_err(e.span, e.msg); - } - } - } - } - } - } - } - // treat #[target_feature(enable = "feat")] attributes as if they were // #[doc(cfg(target_feature = "feat"))] attributes as well for attr in hir_attr_lists(attrs, sym::target_feature) { diff --git a/src/tools/run-make-support/src/run.rs b/src/tools/run-make-support/src/run.rs index 7812863ccc2c8..60e711d340278 100644 --- a/src/tools/run-make-support/src/run.rs +++ b/src/tools/run-make-support/src/run.rs @@ -12,7 +12,20 @@ fn run_common(name: &str, args: Option<&[&str]>) -> Command { bin_path.push(cwd()); bin_path.push(name); let ld_lib_path_envvar = env_var("LD_LIB_PATH_ENVVAR"); - let mut cmd = Command::new(bin_path); + + let mut cmd = if let Some(rtc) = env::var_os("REMOTE_TEST_CLIENT") { + let mut cmd = Command::new(rtc); + cmd.arg("run"); + // FIXME: the "0" indicates how many support files should be uploaded along with the binary + // to execute. If a test requires additional files to be pushed to the remote machine, this + // will have to be changed (and the support files will have to be uploaded). + cmd.arg("0"); + cmd.arg(bin_path); + cmd + } else { + Command::new(bin_path) + }; + if let Some(args) = args { for arg in args { cmd.arg(arg); diff --git a/src/tools/rustfmt/src/parse/macros/mod.rs b/src/tools/rustfmt/src/parse/macros/mod.rs index 680a35f7e03ad..d7964484b261f 100644 --- a/src/tools/rustfmt/src/parse/macros/mod.rs +++ b/src/tools/rustfmt/src/parse/macros/mod.rs @@ -81,7 +81,7 @@ pub(crate) struct ParsedMacroArgs { } fn check_keyword<'a, 'b: 'a>(parser: &'a mut Parser<'b>) -> Option { - if parser.token.is_any_keyword() + if parser.token.is_reserved_ident() && parser.look_ahead(1, |t| *t == TokenKind::Eof || *t == TokenKind::Comma) { let keyword = parser.token.ident().unwrap().0.name; diff --git a/tests/run-make/doctests-keep-binaries/rmake.rs b/tests/run-make/doctests-keep-binaries/rmake.rs index 246539bcf8231..a05223994df45 100644 --- a/tests/run-make/doctests-keep-binaries/rmake.rs +++ b/tests/run-make/doctests-keep-binaries/rmake.rs @@ -1,3 +1,5 @@ +//@ ignore-cross-compile attempts to run the doctests + // Check that valid binaries are persisted by running them, regardless of whether the // --run or --no-run option is used. diff --git a/tests/run-make/target-cpu-native/rmake.rs b/tests/run-make/target-cpu-native/rmake.rs index fd5fb6193fe06..7b7974f309789 100644 --- a/tests/run-make/target-cpu-native/rmake.rs +++ b/tests/run-make/target-cpu-native/rmake.rs @@ -3,6 +3,8 @@ // warnings when used, and that binaries produced by it can also be successfully executed. // See https://github.com/rust-lang/rust/pull/23238 +//@ ignore-cross-compile target-cpu=native doesn't work well when cross compiling + use run_make_support::{run, rustc}; fn main() { diff --git a/tests/ui/associated-type-bounds/dedup-normalized-2-higher-ranked.stderr b/tests/ui/associated-type-bounds/dedup-normalized-2-higher-ranked.current.stderr similarity index 86% rename from tests/ui/associated-type-bounds/dedup-normalized-2-higher-ranked.stderr rename to tests/ui/associated-type-bounds/dedup-normalized-2-higher-ranked.current.stderr index 372d379de5a4f..64304be9d6b15 100644 --- a/tests/ui/associated-type-bounds/dedup-normalized-2-higher-ranked.stderr +++ b/tests/ui/associated-type-bounds/dedup-normalized-2-higher-ranked.current.stderr @@ -1,12 +1,12 @@ error[E0283]: type annotations needed - --> $DIR/dedup-normalized-2-higher-ranked.rs:23:5 + --> $DIR/dedup-normalized-2-higher-ranked.rs:28:5 | LL | impls(rigid); | ^^^^^ cannot infer type of the type parameter `U` declared on the function `impls` | = note: cannot satisfy `for<'b>

::Rigid: Bound<'b, _>` note: required by a bound in `impls` - --> $DIR/dedup-normalized-2-higher-ranked.rs:20:13 + --> $DIR/dedup-normalized-2-higher-ranked.rs:25:13 | LL | fn impls Bound<'b, U>, U>(_: T) {} | ^^^^^^^^^^^^^^^^^^^^ required by this bound in `impls` diff --git a/tests/ui/associated-type-bounds/dedup-normalized-2-higher-ranked.rs b/tests/ui/associated-type-bounds/dedup-normalized-2-higher-ranked.rs index 9224d47d30fd6..32b8c689248fb 100644 --- a/tests/ui/associated-type-bounds/dedup-normalized-2-higher-ranked.rs +++ b/tests/ui/associated-type-bounds/dedup-normalized-2-higher-ranked.rs @@ -1,3 +1,8 @@ +//@ revisions: current next +//@ ignore-compare-mode-next-solver (explicit revisions) +//@[next] compile-flags: -Znext-solver +//@[next] check-pass + // We try to prove `for<'b> T::Rigid: Bound<'b, ?0>` and have 2 candidates from where-clauses: // // - `for<'a> Bound<'a, String>` @@ -21,7 +26,7 @@ fn impls Bound<'b, U>, U>(_: T) {} fn test(rigid: P::Rigid) { impls(rigid); - //~^ ERROR type annotations needed + //[current]~^ ERROR type annotations needed } fn main() {} diff --git a/tests/ui/consts/too_generic_eval_ice.stderr b/tests/ui/consts/too_generic_eval_ice.current.stderr similarity index 90% rename from tests/ui/consts/too_generic_eval_ice.stderr rename to tests/ui/consts/too_generic_eval_ice.current.stderr index 3cc4377514a21..02bcaee80154f 100644 --- a/tests/ui/consts/too_generic_eval_ice.stderr +++ b/tests/ui/consts/too_generic_eval_ice.current.stderr @@ -1,5 +1,5 @@ error: constant expression depends on a generic parameter - --> $DIR/too_generic_eval_ice.rs:7:13 + --> $DIR/too_generic_eval_ice.rs:11:13 | LL | [5; Self::HOST_SIZE] == [6; 0] | ^^^^^^^^^^^^^^^ @@ -7,7 +7,7 @@ LL | [5; Self::HOST_SIZE] == [6; 0] = note: this may fail depending on what value the parameter takes error: constant expression depends on a generic parameter - --> $DIR/too_generic_eval_ice.rs:7:9 + --> $DIR/too_generic_eval_ice.rs:11:9 | LL | [5; Self::HOST_SIZE] == [6; 0] | ^^^^^^^^^^^^^^^^^^^^ @@ -15,7 +15,7 @@ LL | [5; Self::HOST_SIZE] == [6; 0] = note: this may fail depending on what value the parameter takes error: constant expression depends on a generic parameter - --> $DIR/too_generic_eval_ice.rs:7:30 + --> $DIR/too_generic_eval_ice.rs:11:30 | LL | [5; Self::HOST_SIZE] == [6; 0] | ^^ @@ -23,7 +23,7 @@ LL | [5; Self::HOST_SIZE] == [6; 0] = note: this may fail depending on what value the parameter takes error[E0277]: can't compare `[{integer}; Self::HOST_SIZE]` with `[{integer}; 0]` - --> $DIR/too_generic_eval_ice.rs:7:30 + --> $DIR/too_generic_eval_ice.rs:11:30 | LL | [5; Self::HOST_SIZE] == [6; 0] | ^^ no implementation for `[{integer}; Self::HOST_SIZE] == [{integer}; 0]` diff --git a/tests/ui/consts/too_generic_eval_ice.next.stderr b/tests/ui/consts/too_generic_eval_ice.next.stderr new file mode 100644 index 0000000000000..01da33241c810 --- /dev/null +++ b/tests/ui/consts/too_generic_eval_ice.next.stderr @@ -0,0 +1,9 @@ +error[E0284]: type annotations needed: cannot satisfy `the constant `Self::HOST_SIZE` can be evaluated` + --> $DIR/too_generic_eval_ice.rs:11:13 + | +LL | [5; Self::HOST_SIZE] == [6; 0] + | ^^^^^^^^^^^^^^^ cannot satisfy `the constant `Self::HOST_SIZE` can be evaluated` + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0284`. diff --git a/tests/ui/consts/too_generic_eval_ice.rs b/tests/ui/consts/too_generic_eval_ice.rs index 0d46a4c8276dc..ff741cdcf20bc 100644 --- a/tests/ui/consts/too_generic_eval_ice.rs +++ b/tests/ui/consts/too_generic_eval_ice.rs @@ -1,3 +1,7 @@ +//@ revisions: current next +//@ ignore-compare-mode-next-solver (explicit revisions) +//@[next] compile-flags: -Znext-solver + pub struct Foo(A, B); impl Foo { @@ -5,10 +9,11 @@ impl Foo { pub fn crash() -> bool { [5; Self::HOST_SIZE] == [6; 0] - //~^ ERROR constant expression depends on a generic parameter - //~| ERROR constant expression depends on a generic parameter - //~| ERROR constant expression depends on a generic parameter - //~| ERROR can't compare `[{integer}; Self::HOST_SIZE]` with `[{integer}; 0]` + //[current]~^ ERROR constant expression depends on a generic parameter + //[current]~| ERROR constant expression depends on a generic parameter + //[current]~| ERROR constant expression depends on a generic parameter + //[current]~| ERROR can't compare `[{integer}; Self::HOST_SIZE]` with `[{integer}; 0]` + //[next]~^^^^^ ERROR type annotations needed } } diff --git a/tests/ui/privacy/where-pub-type-impls-priv-trait.rs b/tests/ui/privacy/where-pub-type-impls-priv-trait.rs index 1ebc396cdf5b1..57548f75d5e49 100644 --- a/tests/ui/privacy/where-pub-type-impls-priv-trait.rs +++ b/tests/ui/privacy/where-pub-type-impls-priv-trait.rs @@ -3,7 +3,6 @@ // priv-in-pub lint tests where the private trait bounds a public type #![crate_type = "lib"] -#![feature(generic_const_exprs)] #![allow(incomplete_features)] struct PrivTy; diff --git a/tests/ui/privacy/where-pub-type-impls-priv-trait.stderr b/tests/ui/privacy/where-pub-type-impls-priv-trait.stderr index ee79ce3f5d750..33f82a3a4fec3 100644 --- a/tests/ui/privacy/where-pub-type-impls-priv-trait.stderr +++ b/tests/ui/privacy/where-pub-type-impls-priv-trait.stderr @@ -1,30 +1,30 @@ warning: trait `PrivTr` is more private than the item `S` - --> $DIR/where-pub-type-impls-priv-trait.rs:20:1 + --> $DIR/where-pub-type-impls-priv-trait.rs:19:1 | LL | pub struct S | ^^^^^^^^^^^^ struct `S` is reachable at visibility `pub` | note: but trait `PrivTr` is only usable at visibility `pub(crate)` - --> $DIR/where-pub-type-impls-priv-trait.rs:10:1 + --> $DIR/where-pub-type-impls-priv-trait.rs:9:1 | LL | trait PrivTr {} | ^^^^^^^^^^^^ = note: `#[warn(private_bounds)]` on by default warning: trait `PrivTr` is more private than the item `E` - --> $DIR/where-pub-type-impls-priv-trait.rs:27:1 + --> $DIR/where-pub-type-impls-priv-trait.rs:26:1 | LL | pub enum E | ^^^^^^^^^^ enum `E` is reachable at visibility `pub` | note: but trait `PrivTr` is only usable at visibility `pub(crate)` - --> $DIR/where-pub-type-impls-priv-trait.rs:10:1 + --> $DIR/where-pub-type-impls-priv-trait.rs:9:1 | LL | trait PrivTr {} | ^^^^^^^^^^^^ warning: trait `PrivTr` is more private than the item `f` - --> $DIR/where-pub-type-impls-priv-trait.rs:34:1 + --> $DIR/where-pub-type-impls-priv-trait.rs:33:1 | LL | / pub fn f() LL | | @@ -33,13 +33,13 @@ LL | | PubTy: PrivTr | |_________________^ function `f` is reachable at visibility `pub` | note: but trait `PrivTr` is only usable at visibility `pub(crate)` - --> $DIR/where-pub-type-impls-priv-trait.rs:10:1 + --> $DIR/where-pub-type-impls-priv-trait.rs:9:1 | LL | trait PrivTr {} | ^^^^^^^^^^^^ warning: trait `PrivTr` is more private than the item `S` - --> $DIR/where-pub-type-impls-priv-trait.rs:41:1 + --> $DIR/where-pub-type-impls-priv-trait.rs:40:1 | LL | / impl S LL | | @@ -48,13 +48,13 @@ LL | | PubTy: PrivTr | |_________________^ implementation `S` is reachable at visibility `pub` | note: but trait `PrivTr` is only usable at visibility `pub(crate)` - --> $DIR/where-pub-type-impls-priv-trait.rs:10:1 + --> $DIR/where-pub-type-impls-priv-trait.rs:9:1 | LL | trait PrivTr {} | ^^^^^^^^^^^^ warning: trait `PrivTr` is more private than the item `S::f` - --> $DIR/where-pub-type-impls-priv-trait.rs:46:5 + --> $DIR/where-pub-type-impls-priv-trait.rs:45:5 | LL | / pub fn f() LL | | @@ -63,7 +63,7 @@ LL | | PubTy: PrivTr | |_____________________^ associated function `S::f` is reachable at visibility `pub` | note: but trait `PrivTr` is only usable at visibility `pub(crate)` - --> $DIR/where-pub-type-impls-priv-trait.rs:10:1 + --> $DIR/where-pub-type-impls-priv-trait.rs:9:1 | LL | trait PrivTr {} | ^^^^^^^^^^^^ diff --git a/tests/ui/traits/next-solver/well-formed-in-relate.rs b/tests/ui/traits/next-solver/well-formed-in-relate.rs new file mode 100644 index 0000000000000..eec1ddef228c4 --- /dev/null +++ b/tests/ui/traits/next-solver/well-formed-in-relate.rs @@ -0,0 +1,21 @@ +fn main() { + let x; + //~^ ERROR type annotations needed for `Map<_, _>` + higher_ranked(); + x = unconstrained_map(); +} + +fn higher_ranked() where for<'a> &'a (): Sized {} + +struct Map where T: Fn() -> U { + t: T, +} + +trait Mirror { + type Assoc; +} +impl Mirror for T { + type Assoc = T; +} + +fn unconstrained_map U, U>() -> as Mirror>::Assoc { todo!() } diff --git a/tests/ui/traits/next-solver/well-formed-in-relate.stderr b/tests/ui/traits/next-solver/well-formed-in-relate.stderr new file mode 100644 index 0000000000000..5294a072d3123 --- /dev/null +++ b/tests/ui/traits/next-solver/well-formed-in-relate.stderr @@ -0,0 +1,27 @@ +error[E0283]: type annotations needed for `Map<_, _>` + --> $DIR/well-formed-in-relate.rs:2:9 + | +LL | let x; + | ^ +... +LL | x = unconstrained_map(); + | ------------------- type must be known at this point + | + = note: multiple `impl`s satisfying `_: Fn()` found in the following crates: `alloc`, `core`: + - impl Fn for &F + where A: Tuple, F: Fn, F: ?Sized; + - impl Fn for Box + where Args: Tuple, F: Fn, A: Allocator, F: ?Sized; +note: required by a bound in `unconstrained_map` + --> $DIR/well-formed-in-relate.rs:21:25 + | +LL | fn unconstrained_map U, U>() -> as Mirror>::Assoc { todo!() } + | ^^^^^^^^^ required by this bound in `unconstrained_map` +help: consider giving `x` an explicit type, where the type for type parameter `T` is specified + | +LL | let x: Map; + | +++++++++++ + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0283`. diff --git a/triagebot.toml b/triagebot.toml index 7215cd8471944..ebbcfa4516b99 100644 --- a/triagebot.toml +++ b/triagebot.toml @@ -174,8 +174,8 @@ label = "O-emscripten" [ping.relnotes-interest-group] message = """\ -Hi relnotes-interest-group, this PR adds release notes. Could you review this PR -if you have time? Thanks <3 +Hi relnotes-interest-group, this issue/PR could use some help in reviewing / +adjusting release notes. Could you take a look if available? Thanks <3 """ [prioritize]