Skip to content

Commit 850eb05

Browse files
committed
Fix #135358
1 parent 047bc17 commit 850eb05

File tree

4 files changed

+155
-5
lines changed

4 files changed

+155
-5
lines changed

src/bootstrap/bootstrap.py

+16-3
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,9 @@ def verify(path, expected, verbose):
186186
verified = found == expected
187187
if not verified:
188188
eprint(
189-
"invalid checksum:\n" " found: {}\n" " expected: {}".format(
190-
found, expected
191-
)
189+
"invalid checksum:\n"
190+
" found: {}\n"
191+
" expected: {}".format(found, expected)
192192
)
193193
return verified
194194

@@ -1264,6 +1264,12 @@ def bootstrap(args):
12641264
config_toml = ""
12651265

12661266
profile = RustBuild.get_toml_static(config_toml, "profile")
1267+
is_non_git_source = not os.path.exists(os.path.join(rust_root, ".git"))
1268+
1269+
if profile is None:
1270+
if is_non_git_source:
1271+
profile = "dist"
1272+
12671273
if profile is not None:
12681274
# Allows creating alias for profile names, allowing
12691275
# profiles to be renamed while maintaining back compatibility
@@ -1284,6 +1290,13 @@ def bootstrap(args):
12841290
with open(include_path) as included_toml:
12851291
config_toml += os.linesep + included_toml.read()
12861292

1293+
if is_non_git_source:
1294+
for option in ["download-ci-llvm", "download-rustc"]:
1295+
if RustBuild.get_toml_static(config_toml, option):
1296+
raise Exception(
1297+
"Option '{}' cannot be used with non-git sources.".format(option)
1298+
)
1299+
12871300
# Configure initial bootstrap
12881301
build = RustBuild(config_toml, args)
12891302
build.check_vendored_status()

src/bootstrap/bootstrap_test.py

+101-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from __future__ import absolute_import, division, print_function
66
import os
77
import unittest
8-
from unittest.mock import patch
8+
from unittest.mock import patch, mock_open
99
import tempfile
1010
import hashlib
1111
import sys
@@ -249,3 +249,103 @@ def test_warnings(self):
249249

250250
_, env = self.build_args(configure_args, args=["--warnings=deny"])
251251
self.assertTrue("-Dwarnings" in env["RUSTFLAGS"])
252+
253+
254+
class TestRustBuild(unittest.TestCase):
255+
256+
@patch("os.path.exists")
257+
@patch("bootstrap.RustBuild.get_toml_static")
258+
def test_profile_none_with_non_git_source(self, mock_get_toml_static, mock_exists):
259+
mock_exists.return_value = False
260+
mock_get_toml_static.return_value = None
261+
262+
rust_root = "/mock/rust_root"
263+
config_toml = ""
264+
265+
profile = bootstrap.RustBuild.get_toml_static(config_toml, "profile")
266+
267+
is_non_git_source = not os.path.exists(os.path.join(rust_root, ".git"))
268+
if profile is None and is_non_git_source:
269+
profile = "dist"
270+
271+
self.assertEqual(profile, "dist")
272+
273+
@patch("os.path.exists")
274+
@patch("bootstrap.RustBuild.get_toml_static")
275+
def test_include_path_exists(self, mock_get_toml_static, mock_exists):
276+
mock_exists.return_value = True
277+
mock_get_toml_static.return_value = "dist"
278+
279+
rust_root = "/mock/rust_root"
280+
config_toml = "mock_config"
281+
282+
profile = bootstrap.RustBuild.get_toml_static(config_toml, "profile")
283+
284+
profile_aliases = {"user": "dist"}
285+
include_file = f"config.{profile_aliases.get(profile) or profile}.toml"
286+
include_dir = os.path.join(rust_root, "src", "bootstrap", "defaults")
287+
include_path = os.path.join(include_dir, include_file)
288+
289+
# Assert the include_path is correctly formed
290+
self.assertEqual(
291+
include_path, "/mock/rust_root/src/bootstrap/defaults/config.dist.toml"
292+
)
293+
294+
@patch("os.path.exists")
295+
@patch("bootstrap.RustBuild.get_toml_static")
296+
@patch("builtins.open", new_callable=mock_open)
297+
def test_config_toml_inclusion(self, mock_open, mock_get_toml_static, mock_exists):
298+
mock_exists.side_effect = (
299+
lambda path: path
300+
== "/mock/rust_root/src/bootstrap/defaults/config.dist.toml"
301+
)
302+
mock_get_toml_static.return_value = "dist"
303+
mock_open.return_value.read.return_value = "included_toml_content"
304+
305+
rust_root = "/mock/rust_root"
306+
config_toml = "initial_config"
307+
308+
profile = bootstrap.RustBuild.get_toml_static(config_toml, "profile")
309+
310+
profile_aliases = {"user": "dist"}
311+
include_file = f"config.{profile_aliases.get(profile) or profile}.toml"
312+
include_dir = os.path.join(rust_root, "src", "bootstrap", "defaults")
313+
include_path = os.path.join(include_dir, include_file)
314+
315+
with open(include_path) as included_toml:
316+
config_toml += os.linesep + included_toml.read()
317+
318+
self.assertIn("initial_config\nincluded_toml_content", config_toml)
319+
320+
@patch("os.path.exists")
321+
@patch("bootstrap.RustBuild.get_toml_static")
322+
def test_invalid_profile_for_non_git_source(
323+
self, mock_get_toml_static, mock_exists
324+
):
325+
mock_exists.return_value = False
326+
327+
def mock_get_toml_static_side_effect(config_toml, option):
328+
if option in ["download-ci-llvm", "download-rustc"]:
329+
return "true"
330+
return None
331+
332+
mock_get_toml_static.side_effect = mock_get_toml_static_side_effect
333+
334+
rust_root = "/mock/rust_root"
335+
config_toml = ""
336+
337+
profile = bootstrap.RustBuild.get_toml_static(config_toml, "profile")
338+
is_non_git_source = not os.path.exists(os.path.join(rust_root, ".git"))
339+
if profile is None and is_non_git_source:
340+
profile = "dist"
341+
342+
for option in ["download-ci-llvm", "download-rustc"]:
343+
if bootstrap.RustBuild.get_toml_static(config_toml, option):
344+
with self.assertRaises(Exception) as context:
345+
raise Exception(
346+
f"Option '{option}' cannot be used with non-git sources."
347+
)
348+
self.assertTrue(
349+
f"Option '{option}' cannot be used with non-git sources."
350+
in str(context.exception)
351+
)

src/librustdoc/passes/propagate_stability.rs

+20-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,26 @@ impl DocFolder for StabilityPropagator<'_, '_> {
3636

3737
let stability = match item.item_id {
3838
ItemId::DefId(def_id) => {
39-
let own_stability = self.cx.tcx.lookup_stability(def_id);
39+
let item_stability = self.cx.tcx.lookup_stability(def_id);
40+
let inline_stability =
41+
item.inline_stmt_id.and_then(|did| self.cx.tcx.lookup_stability(did));
42+
let own_stability = if let Some(item_stab) = item_stability
43+
&& let StabilityLevel::Stable { since: _, allowed_through_unstable_modules } =
44+
item_stab.level
45+
&& let Some(mut inline_stab) = inline_stability
46+
&& let StabilityLevel::Stable {
47+
since: inline_since,
48+
allowed_through_unstable_modules: _,
49+
} = inline_stab.level
50+
{
51+
inline_stab.level = StabilityLevel::Stable {
52+
since: inline_since,
53+
allowed_through_unstable_modules,
54+
};
55+
Some(inline_stab)
56+
} else {
57+
item_stability
58+
};
4059

4160
let (ItemKind::StrippedItem(box kind) | kind) = &item.kind;
4261
match kind {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// https://github.com/rust-lang/rust/issues/135078
2+
#![crate_name = "foo"]
3+
#![feature(staged_api)]
4+
#![stable(feature = "v1", since="1.0.0")]
5+
6+
#[stable(feature = "v1", since="1.0.0")]
7+
pub mod ffi {
8+
#[stable(feature = "core_ffi", since="1.99.0")]
9+
//@ has "foo/ffi/struct.CStr.html" "//span[@class='sub-heading']/span[@class='since']" "1.99.0"
10+
//@ !has - "//span[@class='sub-heading']/span[@class='since']" "1.0.0"
11+
pub struct CStr;
12+
}
13+
14+
#[stable(feature = "v1", since = "1.0.0")]
15+
#[doc(inline)]
16+
//@ has "foo/struct.CStr.html" "//span[@class='sub-heading']/span[@class='since']" "1.0.0"
17+
//@ !has - "//span[@class='sub-heading']/span[@class='since']" "1.99.0"
18+
pub use ffi::CStr;

0 commit comments

Comments
 (0)