From 850eb055a9ea90701c88604813bf524d418f1279 Mon Sep 17 00:00:00 2001 From: Tanvi Pooranmal Meena Date: Mon, 13 Jan 2025 15:38:39 +0530 Subject: [PATCH] Fix #135358 --- src/bootstrap/bootstrap.py | 19 +++- src/bootstrap/bootstrap_test.py | 102 ++++++++++++++++++- src/librustdoc/passes/propagate_stability.rs | 21 +++- tests/rustdoc/inline_local/staged-inline.rs | 18 ++++ 4 files changed, 155 insertions(+), 5 deletions(-) create mode 100644 tests/rustdoc/inline_local/staged-inline.rs diff --git a/src/bootstrap/bootstrap.py b/src/bootstrap/bootstrap.py index 89415afbe3bc4..0815b99bf8525 100644 --- a/src/bootstrap/bootstrap.py +++ b/src/bootstrap/bootstrap.py @@ -186,9 +186,9 @@ def verify(path, expected, verbose): verified = found == expected if not verified: eprint( - "invalid checksum:\n" " found: {}\n" " expected: {}".format( - found, expected - ) + "invalid checksum:\n" + " found: {}\n" + " expected: {}".format(found, expected) ) return verified @@ -1264,6 +1264,12 @@ def bootstrap(args): config_toml = "" profile = RustBuild.get_toml_static(config_toml, "profile") + is_non_git_source = not os.path.exists(os.path.join(rust_root, ".git")) + + if profile is None: + if is_non_git_source: + profile = "dist" + if profile is not None: # Allows creating alias for profile names, allowing # profiles to be renamed while maintaining back compatibility @@ -1284,6 +1290,13 @@ def bootstrap(args): with open(include_path) as included_toml: config_toml += os.linesep + included_toml.read() + if is_non_git_source: + for option in ["download-ci-llvm", "download-rustc"]: + if RustBuild.get_toml_static(config_toml, option): + raise Exception( + "Option '{}' cannot be used with non-git sources.".format(option) + ) + # Configure initial bootstrap build = RustBuild(config_toml, args) build.check_vendored_status() diff --git a/src/bootstrap/bootstrap_test.py b/src/bootstrap/bootstrap_test.py index 7494536539d7b..9b579f9f44515 100644 --- a/src/bootstrap/bootstrap_test.py +++ b/src/bootstrap/bootstrap_test.py @@ -5,7 +5,7 @@ from __future__ import absolute_import, division, print_function import os import unittest -from unittest.mock import patch +from unittest.mock import patch, mock_open import tempfile import hashlib import sys @@ -249,3 +249,103 @@ def test_warnings(self): _, env = self.build_args(configure_args, args=["--warnings=deny"]) self.assertTrue("-Dwarnings" in env["RUSTFLAGS"]) + + +class TestRustBuild(unittest.TestCase): + + @patch("os.path.exists") + @patch("bootstrap.RustBuild.get_toml_static") + def test_profile_none_with_non_git_source(self, mock_get_toml_static, mock_exists): + mock_exists.return_value = False + mock_get_toml_static.return_value = None + + rust_root = "/mock/rust_root" + config_toml = "" + + profile = bootstrap.RustBuild.get_toml_static(config_toml, "profile") + + is_non_git_source = not os.path.exists(os.path.join(rust_root, ".git")) + if profile is None and is_non_git_source: + profile = "dist" + + self.assertEqual(profile, "dist") + + @patch("os.path.exists") + @patch("bootstrap.RustBuild.get_toml_static") + def test_include_path_exists(self, mock_get_toml_static, mock_exists): + mock_exists.return_value = True + mock_get_toml_static.return_value = "dist" + + rust_root = "/mock/rust_root" + config_toml = "mock_config" + + profile = bootstrap.RustBuild.get_toml_static(config_toml, "profile") + + profile_aliases = {"user": "dist"} + include_file = f"config.{profile_aliases.get(profile) or profile}.toml" + include_dir = os.path.join(rust_root, "src", "bootstrap", "defaults") + include_path = os.path.join(include_dir, include_file) + + # Assert the include_path is correctly formed + self.assertEqual( + include_path, "/mock/rust_root/src/bootstrap/defaults/config.dist.toml" + ) + + @patch("os.path.exists") + @patch("bootstrap.RustBuild.get_toml_static") + @patch("builtins.open", new_callable=mock_open) + def test_config_toml_inclusion(self, mock_open, mock_get_toml_static, mock_exists): + mock_exists.side_effect = ( + lambda path: path + == "/mock/rust_root/src/bootstrap/defaults/config.dist.toml" + ) + mock_get_toml_static.return_value = "dist" + mock_open.return_value.read.return_value = "included_toml_content" + + rust_root = "/mock/rust_root" + config_toml = "initial_config" + + profile = bootstrap.RustBuild.get_toml_static(config_toml, "profile") + + profile_aliases = {"user": "dist"} + include_file = f"config.{profile_aliases.get(profile) or profile}.toml" + include_dir = os.path.join(rust_root, "src", "bootstrap", "defaults") + include_path = os.path.join(include_dir, include_file) + + with open(include_path) as included_toml: + config_toml += os.linesep + included_toml.read() + + self.assertIn("initial_config\nincluded_toml_content", config_toml) + + @patch("os.path.exists") + @patch("bootstrap.RustBuild.get_toml_static") + def test_invalid_profile_for_non_git_source( + self, mock_get_toml_static, mock_exists + ): + mock_exists.return_value = False + + def mock_get_toml_static_side_effect(config_toml, option): + if option in ["download-ci-llvm", "download-rustc"]: + return "true" + return None + + mock_get_toml_static.side_effect = mock_get_toml_static_side_effect + + rust_root = "/mock/rust_root" + config_toml = "" + + profile = bootstrap.RustBuild.get_toml_static(config_toml, "profile") + is_non_git_source = not os.path.exists(os.path.join(rust_root, ".git")) + if profile is None and is_non_git_source: + profile = "dist" + + for option in ["download-ci-llvm", "download-rustc"]: + if bootstrap.RustBuild.get_toml_static(config_toml, option): + with self.assertRaises(Exception) as context: + raise Exception( + f"Option '{option}' cannot be used with non-git sources." + ) + self.assertTrue( + f"Option '{option}' cannot be used with non-git sources." + in str(context.exception) + ) diff --git a/src/librustdoc/passes/propagate_stability.rs b/src/librustdoc/passes/propagate_stability.rs index d892c58583778..febb52a3b00a2 100644 --- a/src/librustdoc/passes/propagate_stability.rs +++ b/src/librustdoc/passes/propagate_stability.rs @@ -36,7 +36,26 @@ impl DocFolder for StabilityPropagator<'_, '_> { let stability = match item.item_id { ItemId::DefId(def_id) => { - let own_stability = self.cx.tcx.lookup_stability(def_id); + let item_stability = self.cx.tcx.lookup_stability(def_id); + let inline_stability = + item.inline_stmt_id.and_then(|did| self.cx.tcx.lookup_stability(did)); + let own_stability = if let Some(item_stab) = item_stability + && let StabilityLevel::Stable { since: _, allowed_through_unstable_modules } = + item_stab.level + && let Some(mut inline_stab) = inline_stability + && let StabilityLevel::Stable { + since: inline_since, + allowed_through_unstable_modules: _, + } = inline_stab.level + { + inline_stab.level = StabilityLevel::Stable { + since: inline_since, + allowed_through_unstable_modules, + }; + Some(inline_stab) + } else { + item_stability + }; let (ItemKind::StrippedItem(box kind) | kind) = &item.kind; match kind { diff --git a/tests/rustdoc/inline_local/staged-inline.rs b/tests/rustdoc/inline_local/staged-inline.rs new file mode 100644 index 0000000000000..f2131ad5f9442 --- /dev/null +++ b/tests/rustdoc/inline_local/staged-inline.rs @@ -0,0 +1,18 @@ +// https://github.com/rust-lang/rust/issues/135078 +#![crate_name = "foo"] +#![feature(staged_api)] +#![stable(feature = "v1", since="1.0.0")] + +#[stable(feature = "v1", since="1.0.0")] +pub mod ffi { + #[stable(feature = "core_ffi", since="1.99.0")] + //@ has "foo/ffi/struct.CStr.html" "//span[@class='sub-heading']/span[@class='since']" "1.99.0" + //@ !has - "//span[@class='sub-heading']/span[@class='since']" "1.0.0" + pub struct CStr; +} + +#[stable(feature = "v1", since = "1.0.0")] +#[doc(inline)] +//@ has "foo/struct.CStr.html" "//span[@class='sub-heading']/span[@class='since']" "1.0.0" +//@ !has - "//span[@class='sub-heading']/span[@class='since']" "1.99.0" +pub use ffi::CStr;