diff --git a/compiler/rustc_interface/src/passes.rs b/compiler/rustc_interface/src/passes.rs index b230fe3be68e3..ce99b01637b04 100644 --- a/compiler/rustc_interface/src/passes.rs +++ b/compiler/rustc_interface/src/passes.rs @@ -89,7 +89,7 @@ fn pre_expansion_lint<'a>( features: &Features, lint_store: &LintStore, registered_tools: &RegisteredTools, - check_node: impl EarlyCheckNode<'a>, + check_node: EarlyCheckNode<'a>, node_name: Symbol, ) { sess.prof.generic_activity_with_arg("pre_AST_expansion_lint_checks", node_name.as_str()).run( @@ -122,7 +122,8 @@ impl LintStoreExpand for LintStoreExpandImpl<'_> { items: &[Box], name: Symbol, ) { - pre_expansion_lint(sess, features, self.0, registered_tools, (node_id, attrs, items), name); + let check_node = EarlyCheckNode::LoadedMod(node_id, attrs, items); + pre_expansion_lint(sess, features, self.0, registered_tools, check_node, name); } } @@ -141,13 +142,12 @@ fn configure_and_expand( let features = tcx.features(); let lint_store = unerased_lint_store(sess); let crate_name = tcx.crate_name(LOCAL_CRATE); - let lint_check_node = (&krate, pre_configured_attrs); pre_expansion_lint( sess, features, lint_store, tcx.registered_tools(()), - lint_check_node, + EarlyCheckNode::CrateRoot(&krate, pre_configured_attrs), crate_name, ); rustc_builtin_macros::register_builtin_macros(resolver); @@ -480,7 +480,7 @@ fn early_lint_checks(tcx: TyCtxt<'_>, (): ()) { tcx.registered_tools(()), Some(lint_buffer), rustc_lint::BuiltinCombinedEarlyLintPass::new(), - (&*krate, &*krate.attrs), + EarlyCheckNode::CrateRoot(&*krate, &*krate.attrs), ) } diff --git a/compiler/rustc_lint/src/early.rs b/compiler/rustc_lint/src/early.rs index df6683c14df42..9cc4f348bd418 100644 --- a/compiler/rustc_lint/src/early.rs +++ b/compiler/rustc_lint/src/early.rs @@ -27,7 +27,7 @@ macro_rules! lint_callback { ($cx:expr, $f:ident, $($args:expr),*) => ({ /// Implements the AST traversal for early lint passes. `T` provides the /// `check_*` methods. -pub struct EarlyContextAndPass<'ecx, T: EarlyLintPass> { +struct EarlyContextAndPass<'ecx, T: EarlyLintPass> { context: EarlyContext<'ecx>, pass: T, } @@ -276,36 +276,36 @@ crate::early_lint_methods!(impl_early_lint_pass, []); /// Early lints work on different nodes - either on the crate root, or on freshly loaded modules. /// This trait generalizes over those nodes. -pub trait EarlyCheckNode<'a>: Copy { - fn id(self) -> ast::NodeId; - fn attrs(self) -> &'a [ast::Attribute]; - fn check<'ecx, T: EarlyLintPass>(self, cx: &mut EarlyContextAndPass<'ecx, T>); +pub enum EarlyCheckNode<'a> { + CrateRoot(&'a ast::Crate, &'a [ast::Attribute]), + LoadedMod(ast::NodeId, &'a [ast::Attribute], &'a [Box]), } -impl<'a> EarlyCheckNode<'a> for (&'a ast::Crate, &'a [ast::Attribute]) { - fn id(self) -> ast::NodeId { - ast::CRATE_NODE_ID - } - fn attrs(self) -> &'a [ast::Attribute] { - self.1 - } - fn check<'ecx, T: EarlyLintPass>(self, cx: &mut EarlyContextAndPass<'ecx, T>) { - lint_callback!(cx, check_crate, self.0); - ast_visit::walk_crate(cx, self.0); - lint_callback!(cx, check_crate_post, self.0); - } -} - -impl<'a> EarlyCheckNode<'a> for (ast::NodeId, &'a [ast::Attribute], &'a [Box]) { - fn id(self) -> ast::NodeId { - self.0 +impl<'a> EarlyCheckNode<'a> { + fn id(&self) -> ast::NodeId { + match self { + EarlyCheckNode::CrateRoot(_crate, _attrs) => ast::CRATE_NODE_ID, + EarlyCheckNode::LoadedMod(id, _attrs, _items) => *id, + } } - fn attrs(self) -> &'a [ast::Attribute] { - self.1 + fn attrs(&self) -> &'a [ast::Attribute] { + match self { + EarlyCheckNode::CrateRoot(_crate, attrs) => attrs, + EarlyCheckNode::LoadedMod(_id, attrs, _items) => attrs, + } } - fn check<'ecx, T: EarlyLintPass>(self, cx: &mut EarlyContextAndPass<'ecx, T>) { - walk_list!(cx, visit_attribute, self.1); - walk_list!(cx, visit_item, self.2); + fn check<'ecx, T: EarlyLintPass>(&self, cx: &mut EarlyContextAndPass<'ecx, T>) { + match self { + EarlyCheckNode::CrateRoot(crate_, _attrs) => { + lint_callback!(cx, check_crate, crate_); + ast_visit::walk_crate(cx, crate_); + lint_callback!(cx, check_crate_post, crate_); + } + EarlyCheckNode::LoadedMod(_id, attrs, items) => { + walk_list!(cx, visit_attribute, *attrs); + walk_list!(cx, visit_item, *items); + } + } } } @@ -317,7 +317,7 @@ pub fn check_ast_node<'a>( registered_tools: &RegisteredTools, lint_buffer: Option, builtin_lints: impl EarlyLintPass + 'static, - check_node: impl EarlyCheckNode<'a>, + check_node: EarlyCheckNode<'a>, ) { let context = EarlyContext::new( sess, @@ -345,7 +345,7 @@ pub fn check_ast_node<'a>( fn check_ast_node_inner<'a, T: EarlyLintPass>( sess: &Session, - check_node: impl EarlyCheckNode<'a>, + check_node: EarlyCheckNode<'a>, context: EarlyContext<'_>, pass: T, ) { diff --git a/library/alloc/src/collections/btree/map.rs b/library/alloc/src/collections/btree/map.rs index 7d994359ed48b..0a1f7738632c1 100644 --- a/library/alloc/src/collections/btree/map.rs +++ b/library/alloc/src/collections/btree/map.rs @@ -2594,7 +2594,8 @@ impl Hash for BTreeMap { } #[stable(feature = "rust1", since = "1.0.0")] -impl Default for BTreeMap { +#[rustc_const_unstable(feature = "const_default", issue = "143894")] +const impl Default for BTreeMap { /// Creates an empty `BTreeMap`. fn default() -> BTreeMap { BTreeMap::new() diff --git a/library/alloctests/lib.rs b/library/alloctests/lib.rs index 590f559e0d524..83b017b7625b9 100644 --- a/library/alloctests/lib.rs +++ b/library/alloctests/lib.rs @@ -20,6 +20,7 @@ #![feature(const_alloc_error)] #![feature(const_cmp)] #![feature(const_convert)] +#![feature(const_default)] #![feature(const_destruct)] #![feature(const_heap)] #![feature(const_option_ops)] diff --git a/library/core/src/slice/mod.rs b/library/core/src/slice/mod.rs index ede5985a4211a..9b077f1f9c1bd 100644 --- a/library/core/src/slice/mod.rs +++ b/library/core/src/slice/mod.rs @@ -5298,7 +5298,6 @@ impl [T] { /// # Examples /// Basic usage: /// ``` - /// #![feature(substr_range)] /// use core::range::Range; /// /// let nums = &[0, 5, 10, 0, 0, 5]; @@ -5313,7 +5312,7 @@ impl [T] { /// assert_eq!(iter.next(), Some(Range { start: 5, end: 6 })); /// ``` #[must_use] - #[unstable(feature = "substr_range", issue = "126769")] + #[stable(feature = "substr_range", since = "CURRENT_RUSTC_VERSION")] pub fn subslice_range(&self, subslice: &[T]) -> Option> { if T::IS_ZST { panic!("elements are zero-sized"); diff --git a/library/core/src/str/mod.rs b/library/core/src/str/mod.rs index 68cdb69059f05..78cb8ca665e1e 100644 --- a/library/core/src/str/mod.rs +++ b/library/core/src/str/mod.rs @@ -3193,7 +3193,6 @@ impl str { /// /// # Examples /// ``` - /// #![feature(substr_range)] /// use core::range::Range; /// /// let data = "a, b, b, a"; @@ -3205,7 +3204,7 @@ impl str { /// assert_eq!(iter.next(), Some(Range { start: 9, end: 10 })); /// ``` #[must_use] - #[unstable(feature = "substr_range", issue = "126769")] + #[stable(feature = "substr_range", since = "CURRENT_RUSTC_VERSION")] pub fn substr_range(&self, substr: &str) -> Option> { self.as_bytes().subslice_range(substr.as_bytes()) } diff --git a/src/bootstrap/src/lib.rs b/src/bootstrap/src/lib.rs index fd3e88e1a36f4..2231e0886bbcd 100644 --- a/src/bootstrap/src/lib.rs +++ b/src/bootstrap/src/lib.rs @@ -2120,9 +2120,11 @@ impl Compiler { } fn envify(s: &str) -> String { + // Converting foo-bar to FOO_BAR is a fairly idomatic mapping to an environment variable name. + // We also convert '.' to '_' to fix https://github.com/rust-lang/rust/issues/158090 s.chars() .map(|c| match c { - '-' => '_', + '-' | '.' => '_', c => c, }) .flat_map(|c| c.to_uppercase()) diff --git a/tests/ui/traits/const-traits/const-traits-alloc.rs b/tests/ui/traits/const-traits/const-traits-alloc.rs index 4dfec2f77f1ba..fe882dcf59629 100644 --- a/tests/ui/traits/const-traits/const-traits-alloc.rs +++ b/tests/ui/traits/const-traits/const-traits-alloc.rs @@ -5,5 +5,8 @@ const STRING: String = Default::default(); // alloc::vec const VEC: Vec<()> = Default::default(); +// alloc::collections::btree::map::BTreeMap +use std::collections::BTreeMap; +const BTREE: BTreeMap<(), ()> = Default::default(); fn main() {}