Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions compiler/rustc_expand/src/proc_macro_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,9 +490,11 @@ impl server::Server for Rustc<'_, '_> {
fn literal_from_str(&mut self, s: &str) -> Result<Literal<Self::Span, Self::Symbol>, String> {
let name = FileName::proc_macro_source_code(s);

let mut parser =
let mut parser = rustc_errors::catch_fatal_errors(|| {
new_parser_from_source_str(self.psess(), name, s.to_owned(), StripTokens::Nothing)
.map_err(cancel_diags_into_string)?;
})
.map_err(|_| String::from("failed to parse to literal"))?
.map_err(cancel_diags_into_string)?;

let first_span = parser.token.span.data();
let minus_present = parser.eat(exp!(Minus));
Expand Down Expand Up @@ -569,12 +571,15 @@ impl server::Server for Rustc<'_, '_> {
}

fn ts_from_str(&mut self, src: &str) -> Result<Self::TokenStream, String> {
source_str_to_stream(
self.psess(),
FileName::proc_macro_source_code(src),
src.to_string(),
Some(self.call_site),
)
rustc_errors::catch_fatal_errors(|| {
source_str_to_stream(
self.psess(),
FileName::proc_macro_source_code(src),
src.to_string(),
Some(self.call_site),
)
})
.map_err(|_| String::from("failed to parse to tokenstream"))?
.map_err(cancel_diags_into_string)
}

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ mod break_keyword {}
/// to be most things that would be reasonable to have in a constant (barring `const fn`s). For
/// example, you can't have a [`File`] as a `const`.
///
/// [`File`]: crate::fs::File
/// [`File`]: ../std/fs/struct.File.html
///
/// The only lifetime allowed in a constant is `'static`, which is the lifetime that encompasses
/// all others in a Rust program. For example, if you wanted to define a constant string, it would
Expand Down Expand Up @@ -484,7 +484,7 @@ mod extern_keyword {}

#[doc(keyword = "false")]
//
/// A value of type [`bool`] representing logical **false**.
/// A value of type [`prim@bool`] representing logical **false**.
///
/// `false` is the logical opposite of [`true`].
///
Expand Down Expand Up @@ -1060,7 +1060,8 @@ mod mod_keyword {}
///
/// `move` is often used when [threads] are involved.
///
/// ```rust
#[cfg_attr(target_os = "wasi", doc = "```rust,ignore (thread::spawn not supported)")]
#[cfg_attr(not(target_os = "wasi"), doc = "```rust")]
/// let data = vec![1, 2, 3];
///
/// std::thread::spawn(move || {
Expand Down Expand Up @@ -1235,31 +1236,18 @@ mod ref_keyword {}
/// `return` returns from the function immediately (an "early return"):
///
/// ```no_run
/// use std::fs::File;
/// use std::io::{Error, ErrorKind, Read, Result};
/// fn main() -> Result<(), &'static str> {
/// let contents = "Hello, world!";
///
/// fn main() -> Result<()> {
/// let mut file = match File::open("foo.txt") {
/// Ok(f) => f,
/// Err(e) => return Err(e),
/// };
/// if contents.contains("impossible!") {
/// return Err("oh no!");
/// }
///
/// let mut contents = String::new();
/// let size = match file.read_to_string(&mut contents) {
/// Ok(s) => s,
/// Err(e) => return Err(e),
/// };
///
/// if contents.contains("impossible!") {
/// return Err(Error::new(ErrorKind::Other, "oh no!"));
/// }
/// if contents.len() > 9000 {
/// return Err("over 9000!");
/// }
///
/// if size > 9000 {
/// return Err(Error::new(ErrorKind::Other, "over 9000!"));
/// }
///
/// assert_eq!(contents, "Hello, world!");
/// Ok(())
/// Ok(())
/// }
/// ```
///
Expand Down Expand Up @@ -1306,7 +1294,11 @@ mod return_keyword {}
/// manner to computed goto).
///
/// Example of using `become` to implement functional-style `fold`:
/// ```
#[cfg_attr(
target_family = "wasm",
doc = "```ignore (tail-call target feature not enabled by default on wasm)"
)]
#[cfg_attr(not(target_family = "wasm"), doc = "```")]
/// #![feature(explicit_tail_calls)]
/// #![expect(incomplete_features)]
///
Expand Down Expand Up @@ -1360,7 +1352,11 @@ mod return_keyword {}
/// (unless it's coerced to a function pointer)
///
/// It is possible to tail-call a function pointer:
/// ```
#[cfg_attr(
target_family = "wasm",
doc = "```ignore (tail-call target feature not enabled by default on wasm)"
)]
#[cfg_attr(not(target_family = "wasm"), doc = "```")]
/// #![feature(explicit_tail_calls)]
/// #![expect(incomplete_features)]
///
Expand Down Expand Up @@ -1631,8 +1627,8 @@ mod self_upper_keyword {}
/// [`extern`]: keyword.extern.html
/// [`mut`]: keyword.mut.html
/// [`unsafe`]: keyword.unsafe.html
/// [`Mutex`]: sync::Mutex
/// [`OnceLock`]: sync::OnceLock
/// [`Mutex`]: ../std/sync/struct.Mutex.html
/// [`OnceLock`]: ../std/sync/struct.OnceLock.html
/// [`RefCell`]: cell::RefCell
/// [atomic]: sync::atomic
/// [Reference]: ../reference/items/static-items.html
Expand Down Expand Up @@ -1959,7 +1955,7 @@ mod trait_keyword {}

#[doc(keyword = "true")]
//
/// A value of type [`bool`] representing logical **true**.
/// A value of type [`prim@bool`] representing logical **true**.
///
/// Logically `true` is not equal to [`false`].
///
Expand Down Expand Up @@ -2312,6 +2308,7 @@ mod type_keyword {}
/// [`static`]: keyword.static.html
/// [`union`]: keyword.union.html
/// [`impl`]: keyword.impl.html
/// [`Vec::set_len`]: ../std/vec/struct.Vec.html#method.set_len
/// [raw pointers]: ../reference/types/pointer.html
/// [memory safety]: ../book/ch19-01-unsafe-rust.html
/// [Rustonomicon]: ../nomicon/index.html
Expand Down Expand Up @@ -2502,7 +2499,7 @@ mod use_keyword {}
/// ```
///
/// `where` is available anywhere generic and lifetime parameters are available,
/// as can be seen with the [`Cow`](crate::borrow::Cow) type from the standard
/// as can be seen with the [`Cow`](../std/borrow/enum.Cow.html) type from the standard
/// library:
///
/// ```rust
Expand Down
13 changes: 13 additions & 0 deletions library/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,4 +386,17 @@ pub mod simd {
pub use crate::core_simd::simd::*;
}

// Include private modules that exist solely to provide rustdoc
// documentation for built-in attributes. Using `include!` because rustdoc
// only looks for these modules at the crate level.
include!("attribute_docs.rs");

// Include a number of private modules that exist solely to provide
// the rustdoc documentation for the existing keywords. Using `include!`
// because rustdoc only looks for these modules at the crate level.
include!("keyword_docs.rs");

// Include a number of private modules that exist solely to provide
// the rustdoc documentation for primitive types. Using `include!`
// because rustdoc only looks for these modules at the crate level.
include!("primitive_docs.rs");
21 changes: 12 additions & 9 deletions library/std/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -772,20 +772,23 @@ pub mod from {
pub use core::from::From;
}

// Include a number of private modules that exist solely to provide
// the rustdoc documentation for primitive types. Using `include!`
// because rustdoc only looks for these modules at the crate level.
include!("../../core/src/primitive_docs.rs");
// We include the following files here *again* (they are already included in libcore)
// so that they show up in search results for the std crate, and to avoid breaking
// existing links:

// documentation for built-in attributes. Using `include!` because rustdoc
// only looks for these modules at the crate level.
include!("../../core/src/attribute_docs.rs");

// Include a number of private modules that exist solely to provide
// the rustdoc documentation for the existing keywords. Using `include!`
// because rustdoc only looks for these modules at the crate level.
include!("keyword_docs.rs");
include!("../../core/src/keyword_docs.rs");

// Include private modules that exist solely to provide rustdoc
// documentation for built-in attributes. Using `include!` because rustdoc
// only looks for these modules at the crate level.
include!("attribute_docs.rs");
// Include a number of private modules that exist solely to provide
// the rustdoc documentation for primitive types. Using `include!`
// because rustdoc only looks for these modules at the crate level.
include!("../../core/src/primitive_docs.rs");

// This is required to avoid an unstable error when `restricted-std` is not
// enabled. The use of #![feature(restricted_std)] in rustc-std-workspace-std
Expand Down
34 changes: 25 additions & 9 deletions src/bootstrap/src/core/builder/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ use crate::{
RemapScheme, TargetSelection, command, prepare_behaviour_dump_dir, t,
};

/// Represents flag values in `String` form with whitespace delimiter to pass it to the compiler
/// later.
/// Represents flag values in `String` form with a `\x1f` delimiter to pass to the compiler later.
///
/// Flags are emitted via `CARGO_ENCODED_RUSTFLAGS` / `CARGO_ENCODED_RUSTDOCFLAGS`,
/// which use `\x1f` (ASCII Unit Separator) as the delimiter and therefore allow spaces
/// within individual flag values (e.g. paths from `llvm-config --libdir`).
///
/// `-Z crate-attr` flags will be applied recursively on the target code using the
/// `rustc_parse::parser::Parser`. See `rustc_builtin_macros::cmdline_attrs::inject` for more
Expand Down Expand Up @@ -51,11 +54,16 @@ impl Rustflags {
}

fn arg(&mut self, arg: &str) -> &mut Self {
assert_eq!(arg.split(' ').count(), 1);
if !self.0.is_empty() {
self.0.push(' ');
assert!(
!arg.contains('\x1f'),
"rustflag must not contain the ASCII unit separator (\\x1f): {arg:?}"
);
if !arg.is_empty() {
if !self.0.is_empty() {
self.0.push('\x1f');
}
self.0.push_str(arg);
}
self.0.push_str(arg);
self
}

Expand Down Expand Up @@ -457,14 +465,21 @@ impl From<Cargo> for BootstrapCommand {

cargo.command.args(cargo.args);

// Always unset the plain RUSTFLAGS/RUSTDOCFLAGS so that downstream
// tools (e.g. build.rs scripts) see only the encoded form. Any flags
// from the caller's environment have already been folded into the
// Rustflags struct via `propagate_cargo_env`.
cargo.command.env_remove("RUSTFLAGS");
cargo.command.env_remove("RUSTDOCFLAGS");

let rustflags = &cargo.rustflags.0;
if !rustflags.is_empty() {
cargo.command.env("RUSTFLAGS", rustflags);
cargo.command.env("CARGO_ENCODED_RUSTFLAGS", rustflags);
}

let rustdocflags = &cargo.rustdocflags.0;
if !rustdocflags.is_empty() {
cargo.command.env("RUSTDOCFLAGS", rustdocflags);
cargo.command.env("CARGO_ENCODED_RUSTDOCFLAGS", rustdocflags);
}

let encoded_hostflags = cargo.hostflags.encode();
Expand Down Expand Up @@ -1183,8 +1198,9 @@ impl Builder<'_> {
if (mode == Mode::ToolRustcPrivate || mode == Mode::Codegen)
&& let Some(llvm_config) = self.llvm_config(target)
{
let llvm_libdir =
let llvm_libdir_raw =
command(llvm_config).cached().arg("--libdir").run_capture_stdout(self).stdout();
let llvm_libdir = llvm_libdir_raw.trim();
if target.is_msvc() {
rustflags.arg(&format!("-Clink-arg=-LIBPATH:{llvm_libdir}"));
} else {
Expand Down
Loading
Loading