Skip to content

Rollup of 7 pull requests #114103

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Jul 26, 2023
Merged
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
12 changes: 9 additions & 3 deletions compiler/rustc_expand/src/parse/tests.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use crate::tests::{matches_codepattern, string_to_stream, with_error_checking_parse};
use crate::tests::{
matches_codepattern, string_to_stream, with_error_checking_parse, with_expected_parse_error,
};

use rustc_ast::ptr::P;
use rustc_ast::token::{self, Delimiter, Token};
Expand Down Expand Up @@ -51,11 +53,15 @@ fn string_to_item(source_str: String) -> Option<P<ast::Item>> {
with_error_checking_parse(source_str, &sess(), |p| p.parse_item(ForceCollect::No))
}

#[should_panic]
#[test]
fn bad_path_expr_1() {
// This should trigger error: expected identifier, found keyword `return`
create_default_session_globals_then(|| {
string_to_expr("::abc::def::return".to_string());
with_expected_parse_error(
"::abc::def::return",
"expected identifier, found keyword `return`",
|p| p.parse_expr(),
);
})
}

Expand Down
69 changes: 48 additions & 21 deletions compiler/rustc_expand/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,33 @@ fn string_to_parser(ps: &ParseSess, source_str: String) -> Parser<'_> {
new_parser_from_source_str(ps, PathBuf::from("bogofile").into(), source_str)
}

fn create_test_handler() -> (Handler, Lrc<SourceMap>, Arc<Mutex<Vec<u8>>>) {
let output = Arc::new(Mutex::new(Vec::new()));
let source_map = Lrc::new(SourceMap::new(FilePathMapping::empty()));
let fallback_bundle = rustc_errors::fallback_fluent_bundle(
vec![crate::DEFAULT_LOCALE_RESOURCE, rustc_parse::DEFAULT_LOCALE_RESOURCE],
false,
);
let emitter = EmitterWriter::new(
Box::new(Shared { data: output.clone() }),
Some(source_map.clone()),
None,
fallback_bundle,
false,
false,
false,
Some(140),
false,
false,
TerminalUrl::No,
);
let handler = Handler::with_emitter(Box::new(emitter));
(handler, source_map, output)
}

/// Returns the result of parsing the given string via the given callback.
///
/// If there are any errors, this will panic.
pub(crate) fn with_error_checking_parse<'a, T, F>(s: String, ps: &'a ParseSess, f: F) -> T
where
F: FnOnce(&mut Parser<'a>) -> PResult<'a, T>,
Expand All @@ -32,6 +59,26 @@ where
x
}

/// Verifies that parsing the given string using the given callback will
/// generate an error that contains the given text.
pub(crate) fn with_expected_parse_error<T, F>(source_str: &str, expected_output: &str, f: F)
where
F: for<'a> FnOnce(&mut Parser<'a>) -> PResult<'a, T>,
{
let (handler, source_map, output) = create_test_handler();
let ps = ParseSess::with_span_handler(handler, source_map);
let mut p = string_to_parser(&ps, source_str.to_string());
let result = f(&mut p);
assert!(result.is_ok());

let bytes = output.lock().unwrap();
let actual_output = str::from_utf8(&bytes).unwrap();
println!("expected output:\n------\n{}------", expected_output);
println!("actual output:\n------\n{}------", actual_output);

assert!(actual_output.contains(expected_output))
}

/// Maps a string to tts, using a made-up filename.
pub(crate) fn string_to_stream(source_str: String) -> TokenStream {
let ps = ParseSess::new(
Expand Down Expand Up @@ -130,13 +177,7 @@ impl<T: Write> Write for Shared<T> {

fn test_harness(file_text: &str, span_labels: Vec<SpanLabel>, expected_output: &str) {
create_default_session_if_not_set_then(|_| {
let output = Arc::new(Mutex::new(Vec::new()));

let fallback_bundle = rustc_errors::fallback_fluent_bundle(
vec![crate::DEFAULT_LOCALE_RESOURCE, rustc_parse::DEFAULT_LOCALE_RESOURCE],
false,
);
let source_map = Lrc::new(SourceMap::new(FilePathMapping::empty()));
let (handler, source_map, output) = create_test_handler();
source_map.new_source_file(Path::new("test.rs").to_owned().into(), file_text.to_owned());

let primary_span = make_span(&file_text, &span_labels[0].start, &span_labels[0].end);
Expand All @@ -148,20 +189,6 @@ fn test_harness(file_text: &str, span_labels: Vec<SpanLabel>, expected_output: &
println!("text: {:?}", source_map.span_to_snippet(span));
}

let emitter = EmitterWriter::new(
Box::new(Shared { data: output.clone() }),
Some(source_map.clone()),
None,
fallback_bundle,
false,
false,
false,
None,
false,
false,
TerminalUrl::No,
);
let handler = Handler::with_emitter(Box::new(emitter));
#[allow(rustc::untranslatable_diagnostic)]
handler.span_err(msp, "foo");

Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_session/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1433,8 +1433,6 @@ options! {
dep_tasks: bool = (false, parse_bool, [UNTRACKED],
"print tasks that execute and the color their dep node gets (requires debug build) \
(default: no)"),
diagnostic_width: Option<usize> = (None, parse_opt_number, [UNTRACKED],
"set the current output width for diagnostic truncation"),
dont_buffer_diagnostics: bool = (false, parse_bool, [UNTRACKED],
"emit diagnostics rather than buffering (breaks NLL error downgrading, sorting) \
(default: no)"),
Expand Down
22 changes: 20 additions & 2 deletions compiler/rustc_smir/src/rustc_smir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -825,8 +825,10 @@ impl<'tcx> Stable<'tcx> for Ty<'tcx> {
ty::Alias(alias_kind, alias_ty) => {
TyKind::Alias(alias_kind.stable(tables), alias_ty.stable(tables))
}
ty::Param(_) => todo!(),
ty::Bound(_, _) => todo!(),
ty::Param(param_ty) => TyKind::Param(param_ty.stable(tables)),
ty::Bound(debruijn_idx, bound_ty) => {
TyKind::Bound(debruijn_idx.as_usize(), bound_ty.stable(tables))
}
ty::Placeholder(..)
| ty::GeneratorWitness(_)
| ty::GeneratorWitnessMIR(_, _)
Expand All @@ -837,3 +839,19 @@ impl<'tcx> Stable<'tcx> for Ty<'tcx> {
}
}
}

impl<'tcx> Stable<'tcx> for rustc_middle::ty::ParamTy {
type T = stable_mir::ty::ParamTy;
fn stable(&self, _: &mut Tables<'tcx>) -> Self::T {
use stable_mir::ty::ParamTy;
ParamTy { index: self.index, name: self.name.to_string() }
}
}

impl<'tcx> Stable<'tcx> for rustc_middle::ty::BoundTy {
type T = stable_mir::ty::BoundTy;
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
use stable_mir::ty::BoundTy;
BoundTy { var: self.var.as_usize(), kind: self.kind.stable(tables) }
}
}
14 changes: 14 additions & 0 deletions compiler/rustc_smir/src/stable_mir/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ type Span = Opaque;
pub enum TyKind {
RigidTy(RigidTy),
Alias(AliasKind, AliasTy),
Param(ParamTy),
Bound(usize, BoundTy),
}

#[derive(Clone, Debug)]
Expand Down Expand Up @@ -228,3 +230,15 @@ pub struct ExistentialProjection {
pub generic_args: GenericArgs,
pub term: TermKind,
}

#[derive(Clone, Debug)]
pub struct ParamTy {
pub index: u32,
pub name: String,
}

#[derive(Clone, Debug)]
pub struct BoundTy {
pub var: usize,
pub kind: BoundTyKind,
}
2 changes: 2 additions & 0 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ symbols! {
arm_target_feature,
array,
arrays,
as_mut_ptr,
as_ptr,
as_ref,
as_str,
Expand Down Expand Up @@ -858,6 +859,7 @@ symbols! {
item,
item_like_imports,
iter,
iter_mut,
iter_repeat,
iterator_collect_fn,
kcfi,
Expand Down
22 changes: 18 additions & 4 deletions library/std/src/sys/unix/rand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ pub fn hashmap_random_keys() -> (u64, u64) {
not(target_os = "tvos"),
not(target_os = "watchos"),
not(target_os = "openbsd"),
not(target_os = "freebsd"),
not(target_os = "netbsd"),
not(target_os = "fuchsia"),
not(target_os = "redox"),
Expand Down Expand Up @@ -68,11 +67,25 @@ mod imp {
unsafe { libc::getrandom(buf.as_mut_ptr().cast(), buf.len(), 0) }
}

#[cfg(target_os = "freebsd")]
fn getrandom(buf: &mut [u8]) -> libc::ssize_t {
// FIXME: using the above when libary std's libc is updated
extern "C" {
fn getrandom(
buffer: *mut libc::c_void,
length: libc::size_t,
flags: libc::c_uint,
) -> libc::ssize_t;
}
unsafe { getrandom(buf.as_mut_ptr().cast(), buf.len(), 0) }
}

#[cfg(not(any(
target_os = "linux",
target_os = "android",
target_os = "espidf",
target_os = "horizon"
target_os = "horizon",
target_os = "freebsd"
)))]
fn getrandom_fill_bytes(_buf: &mut [u8]) -> bool {
false
Expand All @@ -82,7 +95,8 @@ mod imp {
target_os = "linux",
target_os = "android",
target_os = "espidf",
target_os = "horizon"
target_os = "horizon",
target_os = "freebsd"
))]
fn getrandom_fill_bytes(v: &mut [u8]) -> bool {
use crate::sync::atomic::{AtomicBool, Ordering};
Expand Down Expand Up @@ -222,7 +236,7 @@ mod imp {
}
}

#[cfg(any(target_os = "freebsd", target_os = "netbsd"))]
#[cfg(target_os = "netbsd")]
mod imp {
use crate::ptr;

Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/download-ci-llvm-stamp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Change this file to make users of the `download-ci-llvm` configuration download
a new version of LLVM from CI, even if the LLVM submodule hasn’t changed.

Last change is for: https://github.com/rust-lang/rust/pull/112931
Last change is for: https://github.com/rust-lang/rust/pull/113996
7 changes: 7 additions & 0 deletions src/bootstrap/llvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,8 @@ fn configure_cmake(

if target.contains("netbsd") {
cfg.define("CMAKE_SYSTEM_NAME", "NetBSD");
} else if target.contains("dragonfly") {
cfg.define("CMAKE_SYSTEM_NAME", "DragonFly");
} else if target.contains("freebsd") {
cfg.define("CMAKE_SYSTEM_NAME", "FreeBSD");
} else if target.contains("windows") {
Expand All @@ -569,7 +571,12 @@ fn configure_cmake(
cfg.define("CMAKE_SYSTEM_NAME", "SunOS");
} else if target.contains("linux") {
cfg.define("CMAKE_SYSTEM_NAME", "Linux");
} else {
builder.info(
"could not determine CMAKE_SYSTEM_NAME from the target `{target}`, build may fail",
);
}

// When cross-compiling we should also set CMAKE_SYSTEM_VERSION, but in
// that case like CMake we cannot easily determine system version either.
//
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/clippy_lints/src/methods/bytecount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub(super) fn check<'tcx>(
let haystack = if let ExprKind::MethodCall(path, receiver, [], _) =
filter_recv.kind {
let p = path.ident.name;
if p == sym::iter || p == sym!(iter_mut) {
if p == sym::iter || p == sym::iter_mut {
receiver
} else {
filter_recv
Expand Down
8 changes: 0 additions & 8 deletions src/tools/compiletest/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use std::io::BufReader;
use std::path::{Path, PathBuf};
use std::process::Command;

use build_helper::ci::CiEnv;
use tracing::*;

use crate::common::{Config, Debugger, FailMode, Mode, PassMode};
Expand Down Expand Up @@ -298,13 +297,6 @@ impl TestProps {
/// `//[foo]`), then the property is ignored unless `cfg` is
/// `Some("foo")`.
fn load_from(&mut self, testfile: &Path, cfg: Option<&str>, config: &Config) {
// In CI, we've sometimes encountered non-determinism related to truncating very long paths.
// Set a consistent (short) prefix to avoid issues, but only in CI to avoid regressing the
// contributor experience.
if CiEnv::is_ci() {
self.remap_src_base = config.mode == Mode::Ui && !config.suite.contains("rustdoc");
}

let mut has_edition = false;
if !testfile.is_dir() {
let file = File::open(testfile).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/proc-macro/meta-macro-hygiene.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Respanned: TokenStream [Ident { ident: "$crate", span: $DIR/auxiliary/make-macro
use core /* 0#1 */::prelude /* 0#1 */::rust_2018 /* 0#1 */::*;
#[macro_use /* 0#1 */]
extern crate core /* 0#1 */;
extern crate compiler_builtins /* 442 */ as _ /* 0#1 */;
extern crate compiler_builtins /* 443 */ as _ /* 0#1 */;
// Don't load unnecessary hygiene information from std
extern crate std /* 0#0 */;

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/proc-macro/nonterminal-token-hygiene.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ PRINT-BANG INPUT (DEBUG): TokenStream [
use ::core /* 0#1 */::prelude /* 0#1 */::rust_2015 /* 0#1 */::*;
#[macro_use /* 0#1 */]
extern crate core /* 0#2 */;
extern crate compiler_builtins /* 442 */ as _ /* 0#2 */;
extern crate compiler_builtins /* 443 */ as _ /* 0#2 */;
// Don't load unnecessary hygiene information from std
extern crate std /* 0#0 */;

Expand Down