Auto merge of #113732 - matthiaskrgr:rollup-nm5qy4i, r=matthiaskrgr

Rollup of 6 pull requests

Successful merges:

 - #113625 (Structurally normalize in selection)
 - #113644 (misc bootstrap cleanups)
 - #113663 (Implement "items do not inherit unsafety" note for THIR unsafeck)
 - #113683 (remove outdated `FIXME`s in bootstrap internals)
 - #113709 (rustdoc: use src consistently over source in CSS/JS)
 - #113724 (Migrate GUI colors test to original CSS color format)

r? `@ghost`
`@rustbot` modify labels: rollup
This commit is contained in:
bors 2023-07-15 18:13:26 +00:00
commit 425726d46b
58 changed files with 449 additions and 278 deletions

View File

@ -312,6 +312,8 @@ mir_build_unreachable_pattern = unreachable pattern
.label = unreachable pattern
.catchall_label = matches any value
mir_build_unsafe_not_inherited = items do not inherit unsafety from separate enclosing items
mir_build_unsafe_op_in_unsafe_fn_borrow_of_layout_constrained_field_requires_unsafe =
borrow of layout constrained field with interior mutability is unsafe and requires unsafe block (error E0133)
.note = references to fields of layout constrained fields lose the constraints. Coupled with interior mutability, the field can be changed to invalid values

View File

@ -91,7 +91,12 @@ impl<'tcx> UnsafetyVisitor<'_, 'tcx> {
kind.emit_unsafe_op_in_unsafe_fn_lint(self.tcx, self.hir_context, span);
}
SafetyContext::Safe => {
kind.emit_requires_unsafe_err(self.tcx, span, unsafe_op_in_unsafe_fn_allowed);
kind.emit_requires_unsafe_err(
self.tcx,
span,
self.hir_context,
unsafe_op_in_unsafe_fn_allowed,
);
}
}
}
@ -602,98 +607,164 @@ impl UnsafeOpKind {
&self,
tcx: TyCtxt<'_>,
span: Span,
hir_context: hir::HirId,
unsafe_op_in_unsafe_fn_allowed: bool,
) {
let note_non_inherited = tcx.hir().parent_iter(hir_context).find(|(id, node)| {
if let hir::Node::Expr(block) = node
&& let hir::ExprKind::Block(block, _) = block.kind
&& let hir::BlockCheckMode::UnsafeBlock(_) = block.rules
{
true
}
else if let Some(sig) = tcx.hir().fn_sig_by_hir_id(*id)
&& sig.header.is_unsafe()
{
true
} else {
false
}
});
let unsafe_not_inherited_note = if let Some((id, _)) = note_non_inherited {
let span = tcx.hir().span(id);
let span = tcx.sess.source_map().guess_head_span(span);
Some(UnsafeNotInheritedNote { span })
} else {
None
};
match self {
CallToUnsafeFunction(Some(did)) if unsafe_op_in_unsafe_fn_allowed => {
tcx.sess.emit_err(CallToUnsafeFunctionRequiresUnsafeUnsafeOpInUnsafeFnAllowed {
span,
unsafe_not_inherited_note,
function: &tcx.def_path_str(*did),
});
}
CallToUnsafeFunction(Some(did)) => {
tcx.sess.emit_err(CallToUnsafeFunctionRequiresUnsafe {
span,
unsafe_not_inherited_note,
function: &tcx.def_path_str(*did),
});
}
CallToUnsafeFunction(None) if unsafe_op_in_unsafe_fn_allowed => {
tcx.sess.emit_err(
CallToUnsafeFunctionRequiresUnsafeNamelessUnsafeOpInUnsafeFnAllowed { span },
CallToUnsafeFunctionRequiresUnsafeNamelessUnsafeOpInUnsafeFnAllowed {
span,
unsafe_not_inherited_note,
},
);
}
CallToUnsafeFunction(None) => {
tcx.sess.emit_err(CallToUnsafeFunctionRequiresUnsafeNameless { span });
tcx.sess.emit_err(CallToUnsafeFunctionRequiresUnsafeNameless {
span,
unsafe_not_inherited_note,
});
}
UseOfInlineAssembly if unsafe_op_in_unsafe_fn_allowed => {
tcx.sess
.emit_err(UseOfInlineAssemblyRequiresUnsafeUnsafeOpInUnsafeFnAllowed { span });
tcx.sess.emit_err(UseOfInlineAssemblyRequiresUnsafeUnsafeOpInUnsafeFnAllowed {
span,
unsafe_not_inherited_note,
});
}
UseOfInlineAssembly => {
tcx.sess.emit_err(UseOfInlineAssemblyRequiresUnsafe { span });
tcx.sess.emit_err(UseOfInlineAssemblyRequiresUnsafe {
span,
unsafe_not_inherited_note,
});
}
InitializingTypeWith if unsafe_op_in_unsafe_fn_allowed => {
tcx.sess
.emit_err(InitializingTypeWithRequiresUnsafeUnsafeOpInUnsafeFnAllowed { span });
tcx.sess.emit_err(InitializingTypeWithRequiresUnsafeUnsafeOpInUnsafeFnAllowed {
span,
unsafe_not_inherited_note,
});
}
InitializingTypeWith => {
tcx.sess.emit_err(InitializingTypeWithRequiresUnsafe { span });
tcx.sess.emit_err(InitializingTypeWithRequiresUnsafe {
span,
unsafe_not_inherited_note,
});
}
UseOfMutableStatic if unsafe_op_in_unsafe_fn_allowed => {
tcx.sess
.emit_err(UseOfMutableStaticRequiresUnsafeUnsafeOpInUnsafeFnAllowed { span });
tcx.sess.emit_err(UseOfMutableStaticRequiresUnsafeUnsafeOpInUnsafeFnAllowed {
span,
unsafe_not_inherited_note,
});
}
UseOfMutableStatic => {
tcx.sess.emit_err(UseOfMutableStaticRequiresUnsafe { span });
tcx.sess
.emit_err(UseOfMutableStaticRequiresUnsafe { span, unsafe_not_inherited_note });
}
UseOfExternStatic if unsafe_op_in_unsafe_fn_allowed => {
tcx.sess
.emit_err(UseOfExternStaticRequiresUnsafeUnsafeOpInUnsafeFnAllowed { span });
tcx.sess.emit_err(UseOfExternStaticRequiresUnsafeUnsafeOpInUnsafeFnAllowed {
span,
unsafe_not_inherited_note,
});
}
UseOfExternStatic => {
tcx.sess.emit_err(UseOfExternStaticRequiresUnsafe { span });
tcx.sess
.emit_err(UseOfExternStaticRequiresUnsafe { span, unsafe_not_inherited_note });
}
DerefOfRawPointer if unsafe_op_in_unsafe_fn_allowed => {
tcx.sess
.emit_err(DerefOfRawPointerRequiresUnsafeUnsafeOpInUnsafeFnAllowed { span });
tcx.sess.emit_err(DerefOfRawPointerRequiresUnsafeUnsafeOpInUnsafeFnAllowed {
span,
unsafe_not_inherited_note,
});
}
DerefOfRawPointer => {
tcx.sess.emit_err(DerefOfRawPointerRequiresUnsafe { span });
tcx.sess
.emit_err(DerefOfRawPointerRequiresUnsafe { span, unsafe_not_inherited_note });
}
AccessToUnionField if unsafe_op_in_unsafe_fn_allowed => {
tcx.sess
.emit_err(AccessToUnionFieldRequiresUnsafeUnsafeOpInUnsafeFnAllowed { span });
tcx.sess.emit_err(AccessToUnionFieldRequiresUnsafeUnsafeOpInUnsafeFnAllowed {
span,
unsafe_not_inherited_note,
});
}
AccessToUnionField => {
tcx.sess.emit_err(AccessToUnionFieldRequiresUnsafe { span });
tcx.sess
.emit_err(AccessToUnionFieldRequiresUnsafe { span, unsafe_not_inherited_note });
}
MutationOfLayoutConstrainedField if unsafe_op_in_unsafe_fn_allowed => {
tcx.sess.emit_err(
MutationOfLayoutConstrainedFieldRequiresUnsafeUnsafeOpInUnsafeFnAllowed {
span,
unsafe_not_inherited_note,
},
);
}
MutationOfLayoutConstrainedField => {
tcx.sess.emit_err(MutationOfLayoutConstrainedFieldRequiresUnsafe { span });
tcx.sess.emit_err(MutationOfLayoutConstrainedFieldRequiresUnsafe {
span,
unsafe_not_inherited_note,
});
}
BorrowOfLayoutConstrainedField if unsafe_op_in_unsafe_fn_allowed => {
tcx.sess.emit_err(
BorrowOfLayoutConstrainedFieldRequiresUnsafeUnsafeOpInUnsafeFnAllowed { span },
BorrowOfLayoutConstrainedFieldRequiresUnsafeUnsafeOpInUnsafeFnAllowed {
span,
unsafe_not_inherited_note,
},
);
}
BorrowOfLayoutConstrainedField => {
tcx.sess.emit_err(BorrowOfLayoutConstrainedFieldRequiresUnsafe { span });
tcx.sess.emit_err(BorrowOfLayoutConstrainedFieldRequiresUnsafe {
span,
unsafe_not_inherited_note,
});
}
CallToFunctionWith(did) if unsafe_op_in_unsafe_fn_allowed => {
tcx.sess.emit_err(CallToFunctionWithRequiresUnsafeUnsafeOpInUnsafeFnAllowed {
span,
unsafe_not_inherited_note,
function: &tcx.def_path_str(*did),
});
}
CallToFunctionWith(did) => {
tcx.sess.emit_err(CallToFunctionWithRequiresUnsafe {
span,
unsafe_not_inherited_note,
function: &tcx.def_path_str(*did),
});
}

View File

@ -119,6 +119,8 @@ pub struct CallToUnsafeFunctionRequiresUnsafe<'a> {
#[label]
pub span: Span,
pub function: &'a str,
#[subdiagnostic]
pub unsafe_not_inherited_note: Option<UnsafeNotInheritedNote>,
}
#[derive(Diagnostic)]
@ -128,6 +130,8 @@ pub struct CallToUnsafeFunctionRequiresUnsafeNameless {
#[primary_span]
#[label]
pub span: Span,
#[subdiagnostic]
pub unsafe_not_inherited_note: Option<UnsafeNotInheritedNote>,
}
#[derive(Diagnostic)]
@ -138,6 +142,8 @@ pub struct CallToUnsafeFunctionRequiresUnsafeUnsafeOpInUnsafeFnAllowed<'a> {
#[label]
pub span: Span,
pub function: &'a str,
#[subdiagnostic]
pub unsafe_not_inherited_note: Option<UnsafeNotInheritedNote>,
}
#[derive(Diagnostic)]
@ -150,6 +156,8 @@ pub struct CallToUnsafeFunctionRequiresUnsafeNamelessUnsafeOpInUnsafeFnAllowed {
#[primary_span]
#[label]
pub span: Span,
#[subdiagnostic]
pub unsafe_not_inherited_note: Option<UnsafeNotInheritedNote>,
}
#[derive(Diagnostic)]
@ -159,6 +167,8 @@ pub struct UseOfInlineAssemblyRequiresUnsafe {
#[primary_span]
#[label]
pub span: Span,
#[subdiagnostic]
pub unsafe_not_inherited_note: Option<UnsafeNotInheritedNote>,
}
#[derive(Diagnostic)]
@ -168,6 +178,8 @@ pub struct UseOfInlineAssemblyRequiresUnsafeUnsafeOpInUnsafeFnAllowed {
#[primary_span]
#[label]
pub span: Span,
#[subdiagnostic]
pub unsafe_not_inherited_note: Option<UnsafeNotInheritedNote>,
}
#[derive(Diagnostic)]
@ -177,6 +189,8 @@ pub struct InitializingTypeWithRequiresUnsafe {
#[primary_span]
#[label]
pub span: Span,
#[subdiagnostic]
pub unsafe_not_inherited_note: Option<UnsafeNotInheritedNote>,
}
#[derive(Diagnostic)]
@ -189,6 +203,8 @@ pub struct InitializingTypeWithRequiresUnsafeUnsafeOpInUnsafeFnAllowed {
#[primary_span]
#[label]
pub span: Span,
#[subdiagnostic]
pub unsafe_not_inherited_note: Option<UnsafeNotInheritedNote>,
}
#[derive(Diagnostic)]
@ -198,6 +214,8 @@ pub struct UseOfMutableStaticRequiresUnsafe {
#[primary_span]
#[label]
pub span: Span,
#[subdiagnostic]
pub unsafe_not_inherited_note: Option<UnsafeNotInheritedNote>,
}
#[derive(Diagnostic)]
@ -207,6 +225,8 @@ pub struct UseOfMutableStaticRequiresUnsafeUnsafeOpInUnsafeFnAllowed {
#[primary_span]
#[label]
pub span: Span,
#[subdiagnostic]
pub unsafe_not_inherited_note: Option<UnsafeNotInheritedNote>,
}
#[derive(Diagnostic)]
@ -216,6 +236,8 @@ pub struct UseOfExternStaticRequiresUnsafe {
#[primary_span]
#[label]
pub span: Span,
#[subdiagnostic]
pub unsafe_not_inherited_note: Option<UnsafeNotInheritedNote>,
}
#[derive(Diagnostic)]
@ -225,6 +247,8 @@ pub struct UseOfExternStaticRequiresUnsafeUnsafeOpInUnsafeFnAllowed {
#[primary_span]
#[label]
pub span: Span,
#[subdiagnostic]
pub unsafe_not_inherited_note: Option<UnsafeNotInheritedNote>,
}
#[derive(Diagnostic)]
@ -234,6 +258,8 @@ pub struct DerefOfRawPointerRequiresUnsafe {
#[primary_span]
#[label]
pub span: Span,
#[subdiagnostic]
pub unsafe_not_inherited_note: Option<UnsafeNotInheritedNote>,
}
#[derive(Diagnostic)]
@ -243,6 +269,8 @@ pub struct DerefOfRawPointerRequiresUnsafeUnsafeOpInUnsafeFnAllowed {
#[primary_span]
#[label]
pub span: Span,
#[subdiagnostic]
pub unsafe_not_inherited_note: Option<UnsafeNotInheritedNote>,
}
#[derive(Diagnostic)]
@ -252,6 +280,8 @@ pub struct AccessToUnionFieldRequiresUnsafe {
#[primary_span]
#[label]
pub span: Span,
#[subdiagnostic]
pub unsafe_not_inherited_note: Option<UnsafeNotInheritedNote>,
}
#[derive(Diagnostic)]
@ -261,6 +291,8 @@ pub struct AccessToUnionFieldRequiresUnsafeUnsafeOpInUnsafeFnAllowed {
#[primary_span]
#[label]
pub span: Span,
#[subdiagnostic]
pub unsafe_not_inherited_note: Option<UnsafeNotInheritedNote>,
}
#[derive(Diagnostic)]
@ -270,6 +302,8 @@ pub struct MutationOfLayoutConstrainedFieldRequiresUnsafe {
#[primary_span]
#[label]
pub span: Span,
#[subdiagnostic]
pub unsafe_not_inherited_note: Option<UnsafeNotInheritedNote>,
}
#[derive(Diagnostic)]
@ -282,6 +316,8 @@ pub struct MutationOfLayoutConstrainedFieldRequiresUnsafeUnsafeOpInUnsafeFnAllow
#[primary_span]
#[label]
pub span: Span,
#[subdiagnostic]
pub unsafe_not_inherited_note: Option<UnsafeNotInheritedNote>,
}
#[derive(Diagnostic)]
@ -291,6 +327,8 @@ pub struct BorrowOfLayoutConstrainedFieldRequiresUnsafe {
#[primary_span]
#[label]
pub span: Span,
#[subdiagnostic]
pub unsafe_not_inherited_note: Option<UnsafeNotInheritedNote>,
}
#[derive(Diagnostic)]
@ -303,6 +341,8 @@ pub struct BorrowOfLayoutConstrainedFieldRequiresUnsafeUnsafeOpInUnsafeFnAllowed
#[primary_span]
#[label]
pub span: Span,
#[subdiagnostic]
pub unsafe_not_inherited_note: Option<UnsafeNotInheritedNote>,
}
#[derive(Diagnostic)]
@ -313,6 +353,8 @@ pub struct CallToFunctionWithRequiresUnsafe<'a> {
#[label]
pub span: Span,
pub function: &'a str,
#[subdiagnostic]
pub unsafe_not_inherited_note: Option<UnsafeNotInheritedNote>,
}
#[derive(Diagnostic)]
@ -323,6 +365,15 @@ pub struct CallToFunctionWithRequiresUnsafeUnsafeOpInUnsafeFnAllowed<'a> {
#[label]
pub span: Span,
pub function: &'a str,
#[subdiagnostic]
pub unsafe_not_inherited_note: Option<UnsafeNotInheritedNote>,
}
#[derive(Subdiagnostic)]
#[label(mir_build_unsafe_not_inherited)]
pub struct UnsafeNotInheritedNote {
#[primary_span]
pub span: Span,
}
#[derive(LintDiagnostic)]

View File

@ -5,7 +5,7 @@ use rustc_hir::def_id::DefId;
use rustc_infer::infer::{DefineOpaqueTypes, InferCtxt, InferOk};
use rustc_infer::traits::util::supertraits;
use rustc_infer::traits::{
Obligation, PolyTraitObligation, PredicateObligation, Selection, SelectionResult,
Obligation, PolyTraitObligation, PredicateObligation, Selection, SelectionResult, TraitEngine,
};
use rustc_middle::traits::solve::{CanonicalInput, Certainty, Goal};
use rustc_middle::traits::{
@ -20,6 +20,8 @@ use crate::solve::eval_ctxt::{EvalCtxt, GenerateProofTree};
use crate::solve::inspect::ProofTreeBuilder;
use crate::solve::search_graph::OverflowHandler;
use crate::traits::vtable::{count_own_vtable_entries, prepare_vtable_segments, VtblSegment};
use crate::traits::StructurallyNormalizeExt;
use crate::traits::TraitEngineExt;
pub trait InferCtxtSelectExt<'tcx> {
fn select_in_new_trait_solver(
@ -228,18 +230,24 @@ fn rematch_object<'tcx>(
goal: Goal<'tcx, ty::TraitPredicate<'tcx>>,
mut nested: Vec<PredicateObligation<'tcx>>,
) -> SelectionResult<'tcx, Selection<'tcx>> {
let self_ty = goal.predicate.self_ty();
let ty::Dynamic(data, _, source_kind) = *self_ty.kind() else { bug!() };
let source_trait_ref = data.principal().unwrap().with_self_ty(infcx.tcx, self_ty);
let a_ty = structurally_normalize(goal.predicate.self_ty(), infcx, goal.param_env, &mut nested);
let ty::Dynamic(data, _, source_kind) = *a_ty.kind() else { bug!() };
let source_trait_ref = data.principal().unwrap().with_self_ty(infcx.tcx, a_ty);
let (is_upcasting, target_trait_ref_unnormalized) =
if Some(goal.predicate.def_id()) == infcx.tcx.lang_items().unsize_trait() {
assert_eq!(source_kind, ty::Dyn, "cannot upcast dyn*");
if let ty::Dynamic(data, _, ty::Dyn) = goal.predicate.trait_ref.args.type_at(1).kind() {
let b_ty = structurally_normalize(
goal.predicate.trait_ref.args.type_at(1),
infcx,
goal.param_env,
&mut nested,
);
if let ty::Dynamic(data, _, ty::Dyn) = *b_ty.kind() {
// FIXME: We also need to ensure that the source lifetime outlives the
// target lifetime. This doesn't matter for codegen, though, and only
// *really* matters if the goal's certainty is ambiguous.
(true, data.principal().unwrap().with_self_ty(infcx.tcx, self_ty))
(true, data.principal().unwrap().with_self_ty(infcx.tcx, a_ty))
} else {
bug!()
}
@ -447,3 +455,22 @@ fn rematch_unsize<'tcx>(
Ok(Some(ImplSource::Builtin(nested)))
}
fn structurally_normalize<'tcx>(
ty: Ty<'tcx>,
infcx: &InferCtxt<'tcx>,
param_env: ty::ParamEnv<'tcx>,
nested: &mut Vec<PredicateObligation<'tcx>>,
) -> Ty<'tcx> {
if matches!(ty.kind(), ty::Alias(..)) {
let mut engine = <dyn TraitEngine<'tcx>>::new(infcx);
let normalized_ty = infcx
.at(&ObligationCause::dummy(), param_env)
.structurally_normalize(ty, &mut *engine)
.expect("normalization shouldn't fail if we got to here");
nested.extend(engine.pending_obligations());
normalized_ty
} else {
ty
}
}

View File

@ -914,12 +914,7 @@ class RustBuild(object):
# preserve existing RUSTFLAGS
env.setdefault("RUSTFLAGS", "")
# we need to explicitly add +xgot here so that we can successfully bootstrap
# a usable stage1 compiler
# FIXME: remove this if condition on the next bootstrap bump
# cfg(bootstrap)
if self.build_triple().startswith('mips'):
env["RUSTFLAGS"] += " -Ctarget-feature=+xgot"
target_features = []
if self.get_toml("crt-static", build_section) == "true":
target_features += ["+crt-static"]

View File

@ -395,7 +395,7 @@ impl StepDescription {
eprintln!(
"note: if you are adding a new Step to bootstrap itself, make sure you register it with `describe!`"
);
crate::detail_exit_macro!(1);
crate::exit!(1);
}
}
}
@ -939,21 +939,6 @@ impl<'a> Builder<'a> {
Self::new_internal(build, kind, paths.to_owned())
}
/// Creates a new standalone builder for use outside of the normal process
pub fn new_standalone(
build: &mut Build,
kind: Kind,
paths: Vec<PathBuf>,
stage: Option<u32>,
) -> Builder<'_> {
// FIXME: don't mutate `build`
if let Some(stage) = stage {
build.config.stage = stage;
}
Self::new_internal(build, kind, paths.to_owned())
}
pub fn execute_cli(&self) {
self.run_step_descriptions(&Builder::get_step_descriptions(self.kind), &self.paths);
}
@ -1375,7 +1360,7 @@ impl<'a> Builder<'a> {
"error: `x.py clippy` requires a host `rustc` toolchain with the `clippy` component"
);
eprintln!("help: try `rustup component add clippy`");
crate::detail_exit_macro!(1);
crate::exit!(1);
});
if !t!(std::str::from_utf8(&output.stdout)).contains("nightly") {
rustflags.arg("--cfg=bootstrap");

View File

@ -222,13 +222,6 @@ fn copy_third_party_objects(
) -> Vec<(PathBuf, DependencyType)> {
let mut target_deps = vec![];
// FIXME: remove this in 2021
if target == "x86_64-fortanix-unknown-sgx" {
if env::var_os("X86_FORTANIX_SGX_LIBS").is_some() {
builder.info("Warning: X86_FORTANIX_SGX_LIBS environment variable is ignored, libunwind is now compiled as part of rustbuild");
}
}
if builder.config.sanitizers_enabled(target) && compiler.stage != 0 {
// The sanitizers are only copied in stage1 or above,
// to avoid creating dependency on LLVM.
@ -1820,7 +1813,7 @@ pub fn run_cargo(
});
if !ok {
crate::detail_exit_macro!(1);
crate::exit!(1);
}
// Ok now we need to actually find all the files listed in `toplevel`. We've

View File

@ -23,7 +23,7 @@ use crate::channel::{self, GitInfo};
pub use crate::flags::Subcommand;
use crate::flags::{Color, Flags, Warnings};
use crate::util::{exe, output, t};
use build_helper::detail_exit_macro;
use build_helper::exit;
use once_cell::sync::OnceCell;
use semver::Version;
use serde::{Deserialize, Deserializer};
@ -646,7 +646,7 @@ macro_rules! define_config {
panic!("overriding existing option")
} else {
eprintln!("overriding existing option: `{}`", stringify!($field));
detail_exit_macro!(2);
exit!(2);
}
} else {
self.$field = other.$field;
@ -745,7 +745,7 @@ impl<T> Merge for Option<T> {
panic!("overriding existing option")
} else {
eprintln!("overriding existing option");
detail_exit_macro!(2);
exit!(2);
}
} else {
*self = other;
@ -1101,7 +1101,7 @@ impl Config {
.and_then(|table: toml::Value| TomlConfig::deserialize(table))
.unwrap_or_else(|err| {
eprintln!("failed to parse TOML configuration '{}': {err}", file.display());
detail_exit_macro!(2);
exit!(2);
})
}
Self::parse_inner(args, get_toml)
@ -1135,7 +1135,7 @@ impl Config {
eprintln!(
"Cannot use both `llvm_bolt_profile_generate` and `llvm_bolt_profile_use` at the same time"
);
detail_exit_macro!(1);
exit!(1);
}
// Infer the rest of the configuration.
@ -1259,7 +1259,7 @@ impl Config {
}
}
eprintln!("failed to parse override `{option}`: `{err}");
detail_exit_macro!(2)
exit!(2)
}
toml.merge(override_toml, ReplaceOpt::Override);
@ -2007,7 +2007,7 @@ impl Config {
"Unexpected rustc version: {}, we should use {}/{} to build source with {}",
rustc_version, prev_version, source_version, source_version
);
detail_exit_macro!(1);
exit!(1);
}
}
@ -2043,7 +2043,7 @@ impl Config {
println!("help: maybe your repository history is too shallow?");
println!("help: consider disabling `download-rustc`");
println!("help: or fetch enough history to include one upstream commit");
crate::detail_exit_macro!(1);
crate::exit!(1);
}
// Warn if there were changes to the compiler or standard library since the ancestor commit.

View File

@ -253,7 +253,7 @@ impl Config {
if !help_on_error.is_empty() {
eprintln!("{}", help_on_error);
}
crate::detail_exit_macro!(1);
crate::exit!(1);
}
}

View File

@ -193,7 +193,7 @@ impl Flags {
} else {
panic!("No paths available for subcommand `{}`", subcommand.as_str());
}
crate::detail_exit_macro!(0);
crate::exit!(0);
}
Flags::parse_from(it)
@ -538,7 +538,7 @@ pub fn get_completion<G: clap_complete::Generator>(shell: G, path: &Path) -> Opt
} else {
std::fs::read_to_string(path).unwrap_or_else(|_| {
eprintln!("couldn't read {}", path.display());
crate::detail_exit_macro!(1)
crate::exit!(1)
})
};
let mut buf = Vec::new();

View File

@ -40,7 +40,7 @@ fn rustfmt(src: &Path, rustfmt: &Path, paths: &[PathBuf], check: bool) -> impl F
code, run `./x.py fmt` instead.",
cmd_debug,
);
crate::detail_exit_macro!(1);
crate::exit!(1);
}
true
}
@ -200,7 +200,7 @@ pub fn format(build: &Builder<'_>, check: bool, paths: &[PathBuf]) {
let rustfmt_path = build.initial_rustfmt().unwrap_or_else(|| {
eprintln!("./x.py fmt is not supported on this channel");
crate::detail_exit_macro!(1);
crate::exit!(1);
});
assert!(rustfmt_path.exists(), "{}", rustfmt_path.display());
let src = build.src.clone();

View File

@ -27,7 +27,7 @@ use std::process::{Command, Stdio};
use std::str;
use build_helper::ci::{gha, CiEnv};
use build_helper::detail_exit_macro;
use build_helper::exit;
use channel::GitInfo;
use config::{DryRun, Target};
use filetime::FileTime;
@ -191,7 +191,7 @@ pub enum GitRepo {
/// although most functions are implemented as free functions rather than
/// methods specifically on this structure itself (to make it easier to
/// organize).
#[cfg_attr(not(feature = "build-metrics"), derive(Clone))]
#[derive(Clone)]
pub struct Build {
/// User-specified configuration from `config.toml`.
config: Config,
@ -711,7 +711,7 @@ impl Build {
for failure in failures.iter() {
eprintln!(" - {}\n", failure);
}
detail_exit_macro!(1);
exit!(1);
}
#[cfg(feature = "build-metrics")]
@ -1529,7 +1529,7 @@ impl Build {
"Error: Unable to find the stamp file {}, did you try to keep a nonexistent build stage?",
stamp.display()
);
crate::detail_exit_macro!(1);
crate::exit!(1);
}
let mut paths = Vec::new();
@ -1721,7 +1721,7 @@ Alternatively, set `download-ci-llvm = true` in that `[llvm]` section
to download LLVM rather than building it.
"
);
detail_exit_macro!(1);
exit!(1);
}
}

View File

@ -40,6 +40,13 @@ pub(crate) struct BuildMetrics {
state: RefCell<MetricsState>,
}
/// NOTE: this isn't really cloning anything, but `x suggest` doesn't need metrics so this is probably ok.
impl Clone for BuildMetrics {
fn clone(&self) -> Self {
Self::init()
}
}
impl BuildMetrics {
pub(crate) fn init() -> Self {
let state = RefCell::new(MetricsState {

View File

@ -30,7 +30,7 @@ pub(crate) fn try_run_tests(builder: &Builder<'_>, cmd: &mut Command, stream: bo
if !run_tests(builder, cmd, stream) {
if builder.fail_fast {
crate::detail_exit_macro!(1);
crate::exit!(1);
} else {
let mut failures = builder.delayed_failures.borrow_mut();
failures.push(format!("{cmd:?}"));

View File

@ -104,7 +104,7 @@ You should install cmake, or set `download-ci-llvm = true` in the
than building it.
"
);
crate::detail_exit_macro!(1);
crate::exit!(1);
}
}

View File

@ -203,7 +203,7 @@ fn setup_config_toml(path: &PathBuf, profile: Profile, config: &Config) {
"note: this will use the configuration in {}",
profile.include_path(&config.src).display()
);
crate::detail_exit_macro!(1);
crate::exit!(1);
}
let settings = format!(
@ -389,7 +389,7 @@ pub fn interactive_path() -> io::Result<Profile> {
io::stdin().read_line(&mut input)?;
if input.is_empty() {
eprintln!("EOF on stdin, when expecting answer to question. Giving up.");
crate::detail_exit_macro!(1);
crate::exit!(1);
}
break match parse_with_abbrev(&input) {
Ok(profile) => profile,

View File

@ -4,18 +4,11 @@ use std::str::FromStr;
use std::path::PathBuf;
use crate::{
builder::{Builder, Kind},
tool::Tool,
};
use clap::Parser;
#[cfg(feature = "build-metrics")]
pub fn suggest(builder: &Builder<'_>, run: bool) {
panic!("`x suggest` is not supported with `build-metrics`")
}
use crate::{builder::Builder, tool::Tool};
/// Suggests a list of possible `x.py` commands to run based on modified files in branch.
#[cfg(not(feature = "build-metrics"))]
pub fn suggest(builder: &Builder<'_>, run: bool) {
let suggestions =
builder.tool_cmd(Tool::SuggestTests).output().expect("failed to run `suggest-tests` tool");
@ -67,12 +60,13 @@ pub fn suggest(builder: &Builder<'_>, run: bool) {
if run {
for sug in suggestions {
let mut build = builder.build.clone();
let builder =
Builder::new_standalone(&mut build, Kind::parse(&sug.0).unwrap(), sug.2, sug.1);
builder.execute_cli()
let mut build: crate::Build = builder.build.clone();
build.config.paths = sug.2;
build.config.cmd = crate::flags::Flags::parse_from(["x.py", sug.0]).cmd;
if let Some(stage) = sug.1 {
build.config.stage = stage;
}
build.build();
}
} else {
println!("help: consider using the `--run` flag to automatically run suggested tests");

View File

@ -833,7 +833,7 @@ impl Step for Clippy {
}
if !builder.config.cmd.bless() {
crate::detail_exit_macro!(1);
crate::exit!(1);
}
}
}
@ -1141,7 +1141,7 @@ help: to skip test's attempt to check tidiness, pass `--exclude src/tools/tidy`
PATH = inferred_rustfmt_dir.display(),
CHAN = builder.config.channel,
);
crate::detail_exit_macro!(1);
crate::exit!(1);
}
crate::format::format(&builder, !builder.config.cmd.bless(), &[]);
}
@ -1164,7 +1164,7 @@ help: to skip test's attempt to check tidiness, pass `--exclude src/tools/tidy`
eprintln!(
"x.py completions were changed; run `x.py run generate-completions` to update them"
);
crate::detail_exit_macro!(1);
crate::exit!(1);
}
}
}
@ -1475,7 +1475,7 @@ help: to test the compiler, use `--stage 1` instead
help: to test the standard library, use `--stage 0 library/std` instead
note: if you're sure you want to do this, please open an issue as to why. In the meantime, you can override this with `COMPILETEST_FORCE_STAGE0=1`."
);
crate::detail_exit_macro!(1);
crate::exit!(1);
}
let mut compiler = self.compiler;

View File

@ -117,7 +117,7 @@ impl Step for ToolBuild {
if !is_expected {
if !is_optional_tool {
crate::detail_exit_macro!(1);
crate::exit!(1);
} else {
None
}

View File

@ -91,7 +91,7 @@ fn print_error(tool: &str, submodule: &str) {
eprintln!("If you do NOT intend to update '{}', please ensure you did not accidentally", tool);
eprintln!("change the submodule at '{}'. You may ask your reviewer for the", submodule);
eprintln!("proper steps.");
crate::detail_exit_macro!(3);
crate::exit!(3);
}
fn check_changed_files(toolstates: &HashMap<Box<str>, ToolState>) {
@ -106,7 +106,7 @@ fn check_changed_files(toolstates: &HashMap<Box<str>, ToolState>) {
Ok(o) => o,
Err(e) => {
eprintln!("Failed to get changed files: {:?}", e);
crate::detail_exit_macro!(1);
crate::exit!(1);
}
};
@ -177,7 +177,7 @@ impl Step for ToolStateCheck {
}
if did_error {
crate::detail_exit_macro!(1);
crate::exit!(1);
}
check_changed_files(&toolstates);
@ -223,7 +223,7 @@ impl Step for ToolStateCheck {
}
if did_error {
crate::detail_exit_macro!(1);
crate::exit!(1);
}
if builder.config.channel == "nightly" && env::var_os("TOOLSTATE_PUBLISH").is_some() {

View File

@ -229,7 +229,7 @@ pub fn is_valid_test_suite_arg<'a, P: AsRef<Path>>(
pub fn run(cmd: &mut Command, print_cmd_on_fail: bool) {
if try_run(cmd, print_cmd_on_fail).is_err() {
crate::detail_exit_macro!(1);
crate::exit!(1);
}
}
@ -253,7 +253,7 @@ pub fn check_run(cmd: &mut Command, print_cmd_on_fail: bool) -> bool {
pub fn run_suppressed(cmd: &mut Command) {
if !try_run_suppressed(cmd) {
crate::detail_exit_macro!(1);
crate::exit!(1);
}
}

View File

@ -1821,9 +1821,9 @@ fn render_rightside(
);
if let Some(l) = src_href {
if has_stability {
write!(rightside, " · <a class=\"srclink\" href=\"{}\">source</a>", l)
write!(rightside, " · <a class=\"src\" href=\"{}\">source</a>", l)
} else {
write!(rightside, "<a class=\"srclink rightside\" href=\"{}\">source</a>", l)
write!(rightside, "<a class=\"src rightside\" href=\"{}\">source</a>", l)
}
}
if has_stability && has_src_ref {

View File

@ -270,7 +270,7 @@ pub(super) fn write_shared(
hierarchy.add_path(source);
}
let hierarchy = Rc::try_unwrap(hierarchy).unwrap();
let dst = cx.dst.join(&format!("source-files{}.js", cx.shared.resource_suffix));
let dst = cx.dst.join(&format!("src-files{}.js", cx.shared.resource_suffix));
let make_sources = || {
let (mut all_sources, _krates) =
try_err!(collect_json(&dst, krate.name(cx.tcx()).as_str()), &dst);
@ -286,12 +286,12 @@ pub(super) fn write_shared(
.replace("\\\"", "\\\\\"")
));
all_sources.sort();
let mut v = String::from("var sourcesIndex = JSON.parse('{\\\n");
let mut v = String::from("var srcIndex = JSON.parse('{\\\n");
v.push_str(&all_sources.join(",\\\n"));
v.push_str("\\\n}');\ncreateSourceSidebar();\n");
v.push_str("\\\n}');\ncreateSrcSidebar();\n");
Ok(v.into_bytes())
};
write_invocation_specific("source-files.js", &make_sources)?;
write_invocation_specific("src-files.js", &make_sources)?;
}
// Update the search index and crate list.

View File

@ -227,7 +227,7 @@ impl SourceCollector<'_, '_> {
let desc = format!("Source of the Rust file `{}`.", filename.prefer_remapped());
let page = layout::Page {
title: &title,
css_class: "source",
css_class: "src",
root_path: &root_path,
static_root_path: shared.static_root_path.as_deref(),
description: &desc,

View File

@ -19,7 +19,7 @@ nav.sub {
display: none;
}
.source .sidebar {
.src .sidebar {
display: none;
}

View File

@ -194,7 +194,7 @@ h1, h2, h3, h4, h5, h6,
.item-name > a,
.out-of-band,
span.since,
a.srclink,
a.src,
#help-button > a,
summary.hideme,
.scraped-example-list,
@ -206,7 +206,7 @@ ul.all-items {
#toggle-all-docs,
a.anchor,
.small-section-header a,
#source-sidebar a,
#src-sidebar a,
.rust a,
.sidebar h2 a,
.sidebar h3 a,
@ -315,7 +315,7 @@ main {
min-width: 0; /* avoid growing beyond the size limit */
}
.source main {
.src main {
padding: 15px;
}
@ -350,10 +350,10 @@ pre.item-decl {
contain: initial;
}
.source .content pre {
.src .content pre {
padding: 20px;
}
.rustdoc.source .example-wrap pre.src-line-numbers {
.rustdoc.src .example-wrap pre.src-line-numbers {
padding: 20px 0 20px 4px;
}
@ -392,7 +392,7 @@ img {
left: 0;
}
.rustdoc.source .sidebar {
.rustdoc.src .sidebar {
flex-basis: 50px;
border-right: 1px solid;
overflow-x: hidden;
@ -402,7 +402,7 @@ img {
}
.sidebar, .mobile-topbar, .sidebar-menu-toggle,
#src-sidebar-toggle, #source-sidebar {
#src-sidebar-toggle, #src-sidebar {
background-color: var(--sidebar-background-color);
}
@ -410,16 +410,16 @@ img {
background-color: var(--sidebar-background-color-hover);
}
.source .sidebar > *:not(#src-sidebar-toggle) {
.src .sidebar > *:not(#src-sidebar-toggle) {
visibility: hidden;
}
.source-sidebar-expanded .source .sidebar {
.src-sidebar-expanded .src .sidebar {
overflow-y: auto;
flex-basis: 300px;
}
.source-sidebar-expanded .source .sidebar > *:not(#src-sidebar-toggle) {
.src-sidebar-expanded .src .sidebar > *:not(#src-sidebar-toggle) {
visibility: visible;
}
@ -544,7 +544,7 @@ ul.block, .block li {
flex-grow: 1;
}
.rustdoc:not(.source) .example-wrap pre {
.rustdoc:not(.src) .example-wrap pre {
overflow: auto hidden;
}
@ -619,7 +619,7 @@ ul.block, .block li {
}
.docblock code, .docblock-short code,
pre, .rustdoc.source .example-wrap {
pre, .rustdoc.src .example-wrap {
background-color: var(--code-block-background-color);
}
@ -676,7 +676,7 @@ nav.sub {
height: 34px;
flex-grow: 1;
}
.source nav.sub {
.src nav.sub {
margin: 0 0 15px 0;
}
@ -1074,7 +1074,7 @@ pre.rust .doccomment {
color: var(--code-highlight-doc-comment-color);
}
.rustdoc.source .example-wrap pre.rust a {
.rustdoc.src .example-wrap pre.rust a {
background: var(--codeblock-link-background);
}
@ -1301,22 +1301,22 @@ a.tooltip:hover::after {
align-items: stretch;
z-index: 10;
}
#source-sidebar {
#src-sidebar {
width: 100%;
overflow: auto;
}
#source-sidebar > .title {
#src-sidebar > .title {
font-size: 1.5rem;
text-align: center;
border-bottom: 1px solid var(--border-color);
margin-bottom: 6px;
}
#source-sidebar div.files > a:hover, details.dir-entry summary:hover,
#source-sidebar div.files > a:focus, details.dir-entry summary:focus {
background-color: var(--source-sidebar-background-hover);
#src-sidebar div.files > a:hover, details.dir-entry summary:hover,
#src-sidebar div.files > a:focus, details.dir-entry summary:focus {
background-color: var(--src-sidebar-background-hover);
}
#source-sidebar div.files > a.selected {
background-color: var(--source-sidebar-background-selected);
#src-sidebar div.files > a.selected {
background-color: var(--src-sidebar-background-selected);
}
#src-sidebar-toggle > button {
font-size: inherit;
@ -1562,7 +1562,7 @@ However, it's not needed with smaller screen width because the doc/code block is
/*
WARNING: RUSTDOC_MOBILE_BREAKPOINT MEDIA QUERY
If you update this line, then you also need to update the line with the same warning
in source-script.js
in src-script.js
*/
@media (max-width: 700px) {
/* When linking to an item with an `id` (for instance, by clicking a link in the sidebar,
@ -1619,8 +1619,8 @@ in source-script.js
/* The source view uses a different design for the sidebar toggle, and doesn't have a topbar,
so don't bump down the main content or the sidebar. */
.source main,
.rustdoc.source .sidebar {
.src main,
.rustdoc.src .sidebar {
top: 0;
padding: 0;
height: 100vh;
@ -1628,8 +1628,8 @@ in source-script.js
}
.sidebar.shown,
.source-sidebar-expanded .source .sidebar,
.rustdoc:not(.source) .sidebar:focus-within {
.src-sidebar-expanded .src .sidebar,
.rustdoc:not(.src) .sidebar:focus-within {
left: 0;
}
@ -1709,7 +1709,7 @@ in source-script.js
border-left: 0;
}
.source-sidebar-expanded #src-sidebar-toggle {
.src-sidebar-expanded #src-sidebar-toggle {
left: unset;
top: unset;
width: unset;
@ -1749,7 +1749,7 @@ in source-script.js
display: inline;
}
.source-sidebar-expanded .source .sidebar {
.src-sidebar-expanded .src .sidebar {
max-width: 100vw;
width: 100vw;
}
@ -1769,7 +1769,7 @@ in source-script.js
margin-left: 34px;
}
.source nav.sub {
.src nav.sub {
margin: 0;
padding: var(--nav-sub-mobile-padding);
}
@ -1792,7 +1792,7 @@ in source-script.js
}
@media print {
nav.sidebar, nav.sub, .out-of-band, a.srclink, #copy-path,
nav.sidebar, nav.sub, .out-of-band, a.src, #copy-path,
details.toggle[open] > summary::before, details.toggle > summary::before,
details.toggle.top-doc > summary {
display: none;

View File

@ -89,8 +89,8 @@ Original by Dempfi (https://github.com/dempfi/ayu)
--crate-search-div-hover-filter: invert(98%) sepia(12%) saturate(81%) hue-rotate(343deg)
brightness(113%) contrast(76%);
--crate-search-hover-border: #e0e0e0;
--source-sidebar-background-selected: #14191f;
--source-sidebar-background-hover: #14191f;
--src-sidebar-background-selected: #14191f;
--src-sidebar-background-hover: #14191f;
--table-alt-row-background-color: #191f26;
--codeblock-link-background: #333;
--scrape-example-toggle-line-background: #999;
@ -107,7 +107,7 @@ Original by Dempfi (https://github.com/dempfi/ayu)
h1, h2, h3, h4,
h1 a, .sidebar h2 a, .sidebar h3 a,
#source-sidebar > .title {
#src-sidebar > .title {
color: #fff;
}
h4 {
@ -124,15 +124,15 @@ h4 {
.docblock pre > code,
pre, pre > code,
.item-info code,
.rustdoc.source .example-wrap {
.rustdoc.src .example-wrap {
color: #e6e1cf;
}
.sidebar .current,
.sidebar a:hover,
#source-sidebar div.files > a:hover, details.dir-entry summary:hover,
#source-sidebar div.files > a:focus, details.dir-entry summary:focus,
#source-sidebar div.files > a.selected {
#src-sidebar div.files > a:hover, details.dir-entry summary:hover,
#src-sidebar div.files > a:focus, details.dir-entry summary:focus,
#src-sidebar div.files > a.selected {
color: #ffb44c;
}

View File

@ -84,8 +84,8 @@
--crate-search-div-hover-filter: invert(69%) sepia(60%) saturate(6613%) hue-rotate(184deg)
brightness(100%) contrast(91%);
--crate-search-hover-border: #2196f3;
--source-sidebar-background-selected: #333;
--source-sidebar-background-hover: #444;
--src-sidebar-background-selected: #333;
--src-sidebar-background-hover: #444;
--table-alt-row-background-color: #2A2A2A;
--codeblock-link-background: #333;
--scrape-example-toggle-line-background: #999;

View File

@ -81,8 +81,8 @@
--crate-search-div-hover-filter: invert(44%) sepia(18%) saturate(23%) hue-rotate(317deg)
brightness(96%) contrast(93%);
--crate-search-hover-border: #717171;
--source-sidebar-background-selected: #fff;
--source-sidebar-background-hover: #e0e0e0;
--src-sidebar-background-selected: #fff;
--src-sidebar-background-hover: #e0e0e0;
--table-alt-row-background-color: #F5F5F5;
--codeblock-link-background: #eee;
--scrape-example-toggle-line-background: #ccc;

View File

@ -1,5 +1,5 @@
// From rust:
/* global sourcesIndex */
/* global srcIndex */
// Local js definitions:
/* global addClass, getCurrentValue, onEachLazy, removeClass, browserSupportsHistoryApi */
@ -74,11 +74,11 @@ function createDirEntry(elem, parent, fullPath, hasFoundFile) {
function toggleSidebar() {
const child = this.parentNode.children[0];
if (child.innerText === ">") {
addClass(document.documentElement, "source-sidebar-expanded");
addClass(document.documentElement, "src-sidebar-expanded");
child.innerText = "<";
updateLocalStorage("source-sidebar-show", "true");
} else {
removeClass(document.documentElement, "source-sidebar-expanded");
removeClass(document.documentElement, "src-sidebar-expanded");
child.innerText = ">";
updateLocalStorage("source-sidebar-show", "false");
}
@ -101,16 +101,16 @@ function createSidebarToggle() {
return sidebarToggle;
}
// This function is called from "source-files.js", generated in `html/render/write_shared.rs`.
// This function is called from "src-files.js", generated in `html/render/write_shared.rs`.
// eslint-disable-next-line no-unused-vars
function createSourceSidebar() {
function createSrcSidebar() {
const container = document.querySelector("nav.sidebar");
const sidebarToggle = createSidebarToggle();
container.insertBefore(sidebarToggle, container.firstChild);
const sidebar = document.createElement("div");
sidebar.id = "source-sidebar";
sidebar.id = "src-sidebar";
let hasFoundFile = false;
@ -118,9 +118,9 @@ function createSourceSidebar() {
title.className = "title";
title.innerText = "Files";
sidebar.appendChild(title);
Object.keys(sourcesIndex).forEach(key => {
sourcesIndex[key][NAME_OFFSET] = key;
hasFoundFile = createDirEntry(sourcesIndex[key], sidebar, "", hasFoundFile);
Object.keys(srcIndex).forEach(key => {
srcIndex[key][NAME_OFFSET] = key;
hasFoundFile = createDirEntry(srcIndex[key], sidebar, "", hasFoundFile);
});
container.appendChild(sidebar);
@ -133,7 +133,7 @@ function createSourceSidebar() {
const lineNumbersRegex = /^#?(\d+)(?:-(\d+))?$/;
function highlightSourceLines(match) {
function highlightSrcLines(match) {
if (typeof match === "undefined") {
match = window.location.hash.match(lineNumbersRegex);
}
@ -172,7 +172,7 @@ function highlightSourceLines(match) {
}
}
const handleSourceHighlight = (function() {
const handleSrcHighlight = (function() {
let prev_line_id = 0;
const set_fragment = name => {
@ -180,7 +180,7 @@ const handleSourceHighlight = (function() {
y = window.scrollY;
if (browserSupportsHistoryApi()) {
history.replaceState(null, null, "#" + name);
highlightSourceLines();
highlightSrcLines();
} else {
location.replace("#" + name);
}
@ -221,15 +221,15 @@ const handleSourceHighlight = (function() {
window.addEventListener("hashchange", () => {
const match = window.location.hash.match(lineNumbersRegex);
if (match) {
return highlightSourceLines(match);
return highlightSrcLines(match);
}
});
onEachLazy(document.getElementsByClassName("src-line-numbers"), el => {
el.addEventListener("click", handleSourceHighlight);
el.addEventListener("click", handleSrcHighlight);
});
highlightSourceLines();
highlightSrcLines();
window.createSourceSidebar = createSourceSidebar;
window.createSrcSidebar = createSrcSidebar;
})();

View File

@ -185,7 +185,7 @@ updateTheme();
if (getSettingValue("source-sidebar-show") === "true") {
// At this point in page load, `document.body` is not available yet.
// Set a class on the `<html>` element instead.
addClass(document.documentElement, "source-sidebar-expanded");
addClass(document.documentElement, "src-sidebar-expanded");
}
// If we navigate away (for example to a settings page), and then use the back or

View File

@ -97,7 +97,7 @@ static_files! {
main_js => "static/js/main.js",
search_js => "static/js/search.js",
settings_js => "static/js/settings.js",
source_script_js => "static/js/source-script.js",
src_script_js => "static/js/src-script.js",
storage_js => "static/js/storage.js",
scrape_examples_js => "static/js/scrape-examples.js",
wheel_svg => "static/images/wheel.svg",

View File

@ -42,9 +42,9 @@
<script src="{{static_root_path|safe}}{{files.storage_js}}"></script> {# #}
{% if page.css_class.contains("crate") %}
<script defer src="{{page.root_path|safe}}crates{{page.resource_suffix}}.js"></script> {# #}
{% else if page.css_class == "source" %}
<script defer src="{{static_root_path|safe}}{{files.source_script_js}}"></script> {# #}
<script defer src="{{page.root_path|safe}}source-files{{page.resource_suffix}}.js"></script> {# #}
{% else if page.css_class == "src" %}
<script defer src="{{static_root_path|safe}}{{files.src_script_js}}"></script> {# #}
<script defer src="{{page.root_path|safe}}src-files{{page.resource_suffix}}.js"></script> {# #}
{% else if !page.css_class.contains("mod") %}
<script defer src="sidebar-items{{page.resource_suffix}}.js"></script> {# #}
{% endif %}
@ -85,7 +85,7 @@
</div> {# #}
<![endif]--> {# #}
{{ layout.external_html.before_content|safe }}
{% if page.css_class != "source" %}
{% if page.css_class != "src" %}
<nav class="mobile-topbar"> {# #}
<button class="sidebar-menu-toggle">&#9776;</button> {# #}
<a class="logo-container" href="{{page.root_path|safe}}{{krate_with_trailing_slash|safe}}index.html"> {# #}
@ -99,7 +99,7 @@
</nav> {# #}
{% endif %}
<nav class="sidebar"> {# #}
{% if page.css_class != "source" %}
{% if page.css_class != "src" %}
<a class="logo-container" href="{{page.root_path|safe}}{{krate_with_trailing_slash|safe}}index.html"> {# #}
{% if !layout.logo.is_empty() %}
<img src="{{layout.logo}}" alt="logo"> {# #}
@ -111,9 +111,9 @@
{{ sidebar|safe }}
</nav> {# #}
<main> {# #}
{% if page.css_class != "source" %}<div class="width-limiter">{% endif %}
{% if page.css_class != "src" %}<div class="width-limiter">{% endif %}
<nav class="sub"> {# #}
{% if page.css_class == "source" %}
{% if page.css_class == "src" %}
<a class="sub-logo-container" href="{{page.root_path|safe}}{{krate_with_trailing_slash|safe}}index.html"> {# #}
{% if !layout.logo.is_empty() %}
<img src="{{layout.logo}}" alt="logo"> {# #}
@ -144,7 +144,7 @@
</form> {# #}
</nav> {# #}
<section id="main-content" class="content">{{ content|safe }}</section> {# #}
{% if page.css_class != "source" %}</div>{% endif %}
{% if page.css_class != "src" %}</div>{% endif %}
</main> {# #}
{{ layout.external_html.after_content|safe }}
</body> {# #}

View File

@ -18,7 +18,7 @@
{% endif %}
{% match src_href %}
{% when Some with (href) %}
<a class="srclink" href="{{href|safe}}">source</a> · {#+ #}
<a class="src" href="{{href|safe}}">source</a> · {#+ #}
{% else %}
{% endmatch %}
<button id="toggle-all-docs" title="collapse all docs"> {# #}

View File

@ -1,10 +1,12 @@
use std::process::Command;
/// Invokes `build_helper::util::detail_exit` with `cfg!(test)`
///
/// This is a macro instead of a function so that it uses `cfg(test)` in the *calling* crate, not in build helper.
#[macro_export]
macro_rules! detail_exit_macro {
macro_rules! exit {
($code:expr) => {
build_helper::util::detail_exit($code, cfg!(test));
$crate::util::detail_exit($code, cfg!(test));
};
}

View File

@ -17,34 +17,34 @@ define-function: (
assert-css: (".main-heading h1 a:nth-of-type(1)", {"color": |main_heading_color|})
assert-css: (".main-heading a:nth-of-type(2)", {"color": |main_heading_type_color|})
assert-css: (
".rightside .srclink",
".rightside a.src",
{"color": |src_link_color|, "text-decoration": "none solid " + |src_link_color|},
ALL,
)
compare-elements-css: (
".rightside .srclink",
".rightside.srclink",
".rightside a.src",
"a.rightside.src",
["color", "text-decoration"],
)
compare-elements-css: (
".main-heading .srclink",
".rightside.srclink",
".main-heading a.src",
"a.rightside.src",
["color", "text-decoration"],
)
move-cursor-to: ".main-heading .srclink"
move-cursor-to: ".main-heading a.src"
assert-css: (
".main-heading .srclink",
".main-heading a.src",
{"color": |src_link_color|, "text-decoration": "underline solid " + |src_link_color|},
)
move-cursor-to: ".impl-items .rightside .srclink"
move-cursor-to: ".impl-items .rightside a.src"
assert-css: (
".impl-items .rightside .srclink",
".impl-items .rightside a.src",
{"color": |src_link_color|, "text-decoration": "none solid " + |src_link_color|},
)
move-cursor-to: ".impl-items .rightside.srclink"
move-cursor-to: ".impl-items a.rightside.src"
assert-css: (
".impl-items .rightside.srclink",
".impl-items a.rightside.src",
{"color": |src_link_color|, "text-decoration": "none solid " + |src_link_color|},
)

View File

@ -1,6 +1,6 @@
// Small test to ensure the "src-line-numbers" element is only present once on
// the page.
go-to: "file://" + |DOC_PATH| + "/test_docs/index.html"
click: ".srclink"
click: "a.src"
wait-for: ".src-line-numbers"
assert-count: (".src-line-numbers", 1)

View File

@ -1,7 +1,7 @@
// This test checks that the source code pages sidebar toggle is working as expected.
go-to: "file://" + |DOC_PATH| + "/test_docs/index.html"
click: ".srclink"
click: "a.src"
wait-for: "#src-sidebar-toggle"
click: "#src-sidebar-toggle"
expect-failure: true
assert-css: ("#source-sidebar", { "left": "-300px" })
assert-css: ("#src-sidebar", { "left": "-300px" })

View File

@ -194,27 +194,27 @@ call-function: (
"check-colors",
{
"theme": "ayu",
"heading_color": "rgb(255, 255, 255)",
"small_heading_color": "rgb(197, 197, 197)",
"heading_border_color": "rgb(92, 103, 115)",
"heading_color": "#fff",
"small_heading_color": "#c5c5c5",
"heading_border_color": "#5c6773",
},
)
call-function: (
"check-colors",
{
"theme": "dark",
"heading_color": "rgb(221, 221, 221)",
"small_heading_color": "rgb(221, 221, 221)",
"heading_border_color": "rgb(210, 210, 210)",
"heading_color": "#ddd",
"small_heading_color": "#ddd",
"heading_border_color": "#d2d2d2",
},
)
call-function: (
"check-colors",
{
"theme": "light",
"heading_color": "rgb(0, 0, 0)",
"small_heading_color": "rgb(0, 0, 0)",
"heading_border_color": "rgb(221, 221, 221)",
"heading_color": "black",
"small_heading_color": "black",
"heading_border_color": "#ddd",
},
)
@ -224,7 +224,7 @@ define-function: (
block {
set-local-storage: {"rustdoc-theme": |theme|}
reload:
assert-css: (".since", {"color": "rgb(128, 128, 128)"}, ALL)
assert-css: (".since", {"color": "#808080"}, ALL)
},
)

View File

@ -1,4 +1,4 @@
// We check the background color on the jump to definition links in the source code page.
// We check the background color on the jump to definition links in the src code page.
go-to: "file://" + |DOC_PATH| + "/src/link_to_definition/lib.rs.html"
define-function: (
@ -10,7 +10,7 @@ define-function: (
// We reload the page so the local storage settings are being used.
reload:
assert-css: (
"body.source .example-wrap pre.rust a",
"body.src .example-wrap pre.rust a",
{"background-color": |background_color|},
ALL,
)

View File

@ -40,7 +40,7 @@ define-function: (
reload:
wait-for-css: ("#src-sidebar-toggle", {"visibility": "visible"})
assert-css: (
"#source-sidebar details[open] > .files a.selected",
"#src-sidebar details[open] > .files a.selected",
{"color": |color_hover|, "background-color": |background|},
)
@ -62,58 +62,58 @@ define-function: (
// Without hover or focus.
assert-css: (
"#source-sidebar details[open] > .files a:not(.selected)",
"#src-sidebar details[open] > .files a:not(.selected)",
{"color": |color|, "background-color": |background_toggle|},
)
// With focus.
focus: "#source-sidebar details[open] > .files a:not(.selected)"
focus: "#src-sidebar details[open] > .files a:not(.selected)"
wait-for-css: (
"#source-sidebar details[open] > .files a:not(.selected):focus",
"#src-sidebar details[open] > .files a:not(.selected):focus",
{"color": |color_hover|, "background-color": |background_hover|},
)
focus: ".search-input"
// With hover.
move-cursor-to: "#source-sidebar details[open] > .files a:not(.selected)"
move-cursor-to: "#src-sidebar details[open] > .files a:not(.selected)"
assert-css: (
"#source-sidebar details[open] > .files a:not(.selected):hover",
"#src-sidebar details[open] > .files a:not(.selected):hover",
{"color": |color_hover|, "background-color": |background_hover|},
)
// Without hover or focus.
assert-css: (
"#source-sidebar .dir-entry summary",
"#src-sidebar .dir-entry summary",
{"color": |color|, "background-color": |background_toggle|},
)
// With focus.
focus: "#source-sidebar .dir-entry summary"
focus: "#src-sidebar .dir-entry summary"
wait-for-css: (
"#source-sidebar .dir-entry summary:focus",
"#src-sidebar .dir-entry summary:focus",
{"color": |color_hover|, "background-color": |background_hover|},
)
focus: ".search-input"
// With hover.
move-cursor-to: "#source-sidebar .dir-entry summary"
move-cursor-to: "#src-sidebar .dir-entry summary"
assert-css: (
"#source-sidebar .dir-entry summary:hover",
"#src-sidebar .dir-entry summary:hover",
{"color": |color_hover|, "background-color": |background_hover|},
)
// Without hover or focus.
assert-css: (
"#source-sidebar details[open] > .folders > details > summary",
"#src-sidebar details[open] > .folders > details > summary",
{"color": |color|, "background-color": |background_toggle|},
)
// With focus.
focus: "#source-sidebar details[open] > .folders > details > summary"
focus: "#src-sidebar details[open] > .folders > details > summary"
wait-for-css: (
"#source-sidebar details[open] > .folders > details > summary:focus",
"#src-sidebar details[open] > .folders > details > summary:focus",
{"color": |color_hover|, "background-color": |background_hover|},
)
focus: ".search-input"
// With hover.
move-cursor-to: "#source-sidebar details[open] > .folders > details > summary"
move-cursor-to: "#src-sidebar details[open] > .folders > details > summary"
assert-css: (
"#source-sidebar details[open] > .folders > details > summary:hover",
"#src-sidebar details[open] > .folders > details > summary:hover",
{"color": |color_hover|, "background-color": |background_hover|},
)
},
@ -190,16 +190,16 @@ assert-window-property: {"pageYOffset": "2542"}
// make it the current selection.
set-window-size: (500, 700)
click: "#src-sidebar-toggle"
wait-for-css: ("#source-sidebar", {"visibility": "visible"})
wait-for-css: ("#src-sidebar", {"visibility": "visible"})
assert-local-storage: {"rustdoc-source-sidebar-show": "true"}
click: ".sidebar a.selected"
go-to: "file://" + |DOC_PATH| + "/src/test_docs/lib.rs.html"
wait-for-css: ("#source-sidebar", {"visibility": "hidden"})
wait-for-css: ("#src-sidebar", {"visibility": "hidden"})
assert-local-storage: {"rustdoc-source-sidebar-show": "false"}
// Resize back to desktop size, to check that the sidebar doesn't spontaneously open.
set-window-size: (1000, 1000)
wait-for-css: ("#source-sidebar", {"visibility": "hidden"})
wait-for-css: ("#src-sidebar", {"visibility": "hidden"})
assert-local-storage: {"rustdoc-source-sidebar-show": "false"}
click: "#src-sidebar-toggle"
wait-for-css: ("#source-sidebar", {"visibility": "visible"})
wait-for-css: ("#src-sidebar", {"visibility": "visible"})
assert-local-storage: {"rustdoc-source-sidebar-show": "true"}

View File

@ -14,7 +14,7 @@ define-function: (
}
reload:
// Checking results colors.
assert-css: (".source .sidebar", {
assert-css: (".src .sidebar", {
"color": |color|,
"background-color": |background_color|
}, ALL)
@ -53,8 +53,8 @@ assert-css: ("nav.sidebar", {"width": "50px"})
// We now click on the button to expand the sidebar.
click: (10, 10)
// We wait for the sidebar to be expanded.
wait-for-css: (".source-sidebar-expanded nav.sidebar", {"width": "300px"})
assert-css: (".source-sidebar-expanded nav.sidebar a", {"font-size": "14px"})
wait-for-css: (".src-sidebar-expanded nav.sidebar", {"width": "300px"})
assert-css: (".src-sidebar-expanded nav.sidebar a", {"font-size": "14px"})
// We collapse the sidebar.
click: (10, 10)
// We ensure that the class has been removed.
@ -66,24 +66,24 @@ go-to: "file://" + |DOC_PATH| + "/src/lib2/another_folder/sub_mod/mod.rs.html"
// First we expand the sidebar again.
click: (10, 10)
// We wait for the sidebar to be expanded.
wait-for-css: (".source-sidebar-expanded nav.sidebar", {"width": "300px"})
wait-for-css: (".src-sidebar-expanded nav.sidebar", {"width": "300px"})
assert: "//*[@class='dir-entry' and @open]/*[text()='lib2']"
assert: "//*[@class='dir-entry' and @open]/*[text()='another_folder']"
assert: "//*[@class='dir-entry' and @open]/*[text()='sub_mod']"
// Only "another_folder" should be "open" in "lib2".
assert: "//*[@class='dir-entry' and not(@open)]/*[text()='another_mod']"
// All other trees should be collapsed.
assert-count: ("//*[@id='source-sidebar']/details[not(text()='lib2') and not(@open)]", 9)
assert-count: ("//*[@id='src-sidebar']/details[not(text()='lib2') and not(@open)]", 9)
// We now switch to mobile mode.
set-window-size: (600, 600)
wait-for-css: (".source-sidebar-expanded nav.sidebar", {"left": "0px"})
wait-for-css: (".src-sidebar-expanded nav.sidebar", {"left": "0px"})
// We collapse the sidebar.
click: (10, 10)
// We check that the sidebar has been moved off-screen.
assert-css: ("nav.sidebar", {"left": "-1000px"})
// We ensure that the class has been removed.
assert-false: ".source-sidebar-expanded"
assert-false: ".src-sidebar-expanded"
assert: "nav.sidebar"
// Check that the topbar is not visible

View File

@ -98,26 +98,26 @@ assert-document-property: ({"URL": "/lib.rs.html"}, ENDS_WITH)
// First we "open" it.
click: "#src-sidebar-toggle"
assert: ".source-sidebar-expanded"
assert: ".src-sidebar-expanded"
// We check that the first entry of the sidebar is collapsed
assert-property: ("#source-sidebar details:first-of-type", {"open": "false"})
assert-text: ("#source-sidebar details:first-of-type > summary", "extend_css")
assert-property: ("#src-sidebar details:first-of-type", {"open": "false"})
assert-text: ("#src-sidebar details:first-of-type > summary", "extend_css")
// We now click on it.
click: "#source-sidebar details:first-of-type > summary"
assert-property: ("#source-sidebar details:first-of-type", {"open": "true"})
click: "#src-sidebar details:first-of-type > summary"
assert-property: ("#src-sidebar details:first-of-type", {"open": "true"})
// And now we collapse it again.
click: "#source-sidebar details:first-of-type > summary"
assert-property: ("#source-sidebar details:first-of-type", {"open": "false"})
click: "#src-sidebar details:first-of-type > summary"
assert-property: ("#src-sidebar details:first-of-type", {"open": "false"})
// And open it again, since it'll be the reference we use to check positions.
click: "#source-sidebar details:first-of-type > summary"
assert-property: ("#source-sidebar details:first-of-type", {"open": "true"})
click: "#src-sidebar details:first-of-type > summary"
assert-property: ("#src-sidebar details:first-of-type", {"open": "true"})
// Check the sidebar directory entries have a marker and spacing (desktop).
store-property: (
"#source-sidebar > details:first-of-type.dir-entry[open] > .files > a",
"#src-sidebar > details:first-of-type.dir-entry[open] > .files > a",
{"offsetHeight": link_height},
)
define-function: (
@ -125,28 +125,28 @@ define-function: (
(x, y),
block {
assert: "details:first-of-type.dir-entry[open] > summary::marker"
assert-css: ("#source-sidebar > details:first-of-type.dir-entry", {"padding-left": "4px"})
assert-css: ("#src-sidebar > details:first-of-type.dir-entry", {"padding-left": "4px"})
// This check ensures that the summary is only one line.
assert-property: (
"#source-sidebar > details:first-of-type.dir-entry[open] > summary",
"#src-sidebar > details:first-of-type.dir-entry[open] > summary",
{"offsetHeight": |link_height|}
)
assert-position: (
"#source-sidebar > details:first-of-type.dir-entry[open] > summary",
"#src-sidebar > details:first-of-type.dir-entry[open] > summary",
{"x": |x|, "y": |y|}
)
assert-property: (
"#source-sidebar > details:first-of-type.dir-entry[open] > .files > a",
"#src-sidebar > details:first-of-type.dir-entry[open] > .files > a",
{"offsetHeight": |link_height|}
)
assert-position: (
"#source-sidebar > details:first-of-type.dir-entry[open] > .files > a",
"#src-sidebar > details:first-of-type.dir-entry[open] > .files > a",
// left margin
{"x": |x| + 27, "y": |y| + |link_height|}
)
}
)
store-property: ("#source-sidebar > .title", {
store-property: ("#src-sidebar > .title", {
"offsetHeight": source_sidebar_title_height,
"offsetTop": source_sidebar_title_y,
})
@ -175,7 +175,7 @@ assert-property: ("#main-content", {"offsetTop": 76})
// 21 = 76 - 34 - 21
// Check the sidebar directory entries have a marker and spacing (tablet).
store-property: ("#source-sidebar > .title", {
store-property: ("#src-sidebar > .title", {
"offsetHeight": source_sidebar_title_height,
"offsetTop": source_sidebar_title_y,
})
@ -189,7 +189,7 @@ set-window-size: (450, 700)
assert-css: ("nav.sub", {"flex-direction": "column"})
// Check the sidebar directory entries have a marker and spacing (phone).
store-property: ("#source-sidebar > .title", {
store-property: ("#src-sidebar > .title", {
"offsetHeight": source_sidebar_title_height,
"offsetTop": source_sidebar_title_y,
})

View File

@ -4,13 +4,13 @@
go-to: "file://" + |DOC_PATH| + "/test_docs/struct.Foo.html"
show-text: true
// Check the impl headers.
assert-css: (".impl .srclink", {"font-size": "16px", "font-weight": 400}, ALL)
assert-css: (".impl a.src", {"font-size": "16px", "font-weight": 400}, ALL)
assert-css: (".impl .code-header", {"font-size": "18px", "font-weight": 600}, ALL)
// Check the impl items.
assert-css: (".impl-items .srclink", {"font-size": "16px", "font-weight": 400}, ALL)
assert-css: (".impl-items a.src", {"font-size": "16px", "font-weight": 400}, ALL)
assert-css: (".impl-items .code-header", {"font-size": "16px", "font-weight": 600}, ALL)
// Check that we can click on source link
store-document-property: {"URL": url}
click: ".impl-items .srclink"
click: ".impl-items a.src"
assert-document-property-false: {"URL": |url|}

View File

@ -1 +1 @@
<section id="associatedconstant.YOLO" class="method"><a class="srclink rightside" href="../src/foo/anchors.rs.html#16">source</a><h4 class="code-header">const <a href="#associatedconstant.YOLO" class="constant">YOLO</a>: <a class="primitive" href="{{channel}}/std/primitive.u32.html">u32</a></h4></section>
<section id="associatedconstant.YOLO" class="method"><a class="src rightside" href="../src/foo/anchors.rs.html#16">source</a><h4 class="code-header">const <a href="#associatedconstant.YOLO" class="constant">YOLO</a>: <a class="primitive" href="{{channel}}/std/primitive.u32.html">u32</a></h4></section>

View File

@ -1 +1 @@
<section id="associatedconstant.X" class="associatedconstant"><a class="srclink rightside" href="../src/foo/anchors.rs.html#42">source</a><h4 class="code-header">pub const <a href="#associatedconstant.X" class="constant">X</a>: <a class="primitive" href="{{channel}}/std/primitive.i32.html">i32</a> = 0i32</h4></section>
<section id="associatedconstant.X" class="associatedconstant"><a class="src rightside" href="../src/foo/anchors.rs.html#42">source</a><h4 class="code-header">pub const <a href="#associatedconstant.X" class="constant">X</a>: <a class="primitive" href="{{channel}}/std/primitive.i32.html">i32</a> = 0i32</h4></section>

View File

@ -1 +1 @@
<section id="method.new" class="method"><a class="srclink rightside" href="../src/foo/anchors.rs.html#48">source</a><h4 class="code-header">pub fn <a href="#method.new" class="fn">new</a>() -&gt; Self</h4></section>
<section id="method.new" class="method"><a class="src rightside" href="../src/foo/anchors.rs.html#48">source</a><h4 class="code-header">pub fn <a href="#method.new" class="fn">new</a>() -&gt; Self</h4></section>

View File

@ -1 +1 @@
<section id="method.bar" class="method"><a class="srclink rightside" href="../src/foo/anchors.rs.html#23">source</a><h4 class="code-header">fn <a href="#method.bar" class="fn">bar</a>()</h4></section>
<section id="method.bar" class="method"><a class="src rightside" href="../src/foo/anchors.rs.html#23">source</a><h4 class="code-header">fn <a href="#method.bar" class="fn">bar</a>()</h4></section>

View File

@ -1 +1 @@
<section id="tymethod.foo" class="method"><a class="srclink rightside" href="../src/foo/anchors.rs.html#20">source</a><h4 class="code-header">fn <a href="#tymethod.foo" class="fn">foo</a>()</h4></section>
<section id="tymethod.foo" class="method"><a class="src rightside" href="../src/foo/anchors.rs.html#20">source</a><h4 class="code-header">fn <a href="#tymethod.foo" class="fn">foo</a>()</h4></section>

View File

@ -1 +1 @@
<section id="associatedtype.T" class="method"><a class="srclink rightside" href="../src/foo/anchors.rs.html#13">source</a><h4 class="code-header">type <a href="#associatedtype.T" class="associatedtype">T</a></h4></section>
<section id="associatedtype.T" class="method"><a class="src rightside" href="../src/foo/anchors.rs.html#13">source</a><h4 class="code-header">type <a href="#associatedtype.T" class="associatedtype">T</a></h4></section>

View File

@ -2,5 +2,5 @@
// This test ensures that the [src] link is present on traits items.
// @has foo/trait.Iterator.html '//*[@id="method.zip"]//a[@class="srclink rightside"]' "source"
// @has foo/trait.Iterator.html '//*[@id="method.zip"]//a[@class="src rightside"]' "source"
pub use std::iter::Iterator;

View File

@ -1,5 +1,5 @@
#![crate_name = "foo"]
// @hasraw source-files.js source-file.rs
// @hasraw src-files.js source-file.rs
pub struct Foo;

View File

@ -2,11 +2,11 @@
// @has foo/struct.Unsized.html
// @has - '//*[@id="impl-Sized-for-Unsized"]/h3[@class="code-header"]' 'impl !Sized for Unsized'
// @!has - '//*[@id="impl-Sized-for-Unsized"]//a[@class="srclink"]' 'source'
// @!has - '//*[@id="impl-Sized-for-Unsized"]//a[@class="src"]' 'source'
// @has - '//*[@id="impl-Sync-for-Unsized"]/h3[@class="code-header"]' 'impl Sync for Unsized'
// @!has - '//*[@id="impl-Sync-for-Unsized"]//a[@class="srclink"]' 'source'
// @!has - '//*[@id="impl-Sync-for-Unsized"]//a[@class="src"]' 'source'
// @has - '//*[@id="impl-Any-for-Unsized"]/h3[@class="code-header"]' 'impl<T> Any for T'
// @has - '//*[@id="impl-Any-for-Unsized"]//a[@class="srclink rightside"]' 'source'
// @has - '//*[@id="impl-Any-for-Unsized"]//a[@class="src rightside"]' 'source'
pub struct Unsized {
data: [u8],
}

View File

@ -8,10 +8,10 @@
pub struct SomeStruct;
// @has src/static_root_path/static-root-path.rs.html
// @matchesraw - '"/cache/source-script-'
// @!matchesraw - '"\.\./\.\./source-script'
// @matchesraw - '"\.\./\.\./source-files.js"'
// @!matchesraw - '"/cache/source-files\.js"'
// @matchesraw - '"/cache/src-script-'
// @!matchesraw - '"\.\./\.\./src-script'
// @matchesraw - '"\.\./\.\./src-files.js"'
// @!matchesraw - '"/cache/src-files\.js"'
// @has settings.html
// @matchesraw - '/cache/settings-'

View File

@ -0,0 +1,18 @@
// check-pass
// compile-flags: -Ztrait-solver=next
pub trait A {}
pub trait B: A {}
pub trait Mirror {
type Assoc: ?Sized;
}
impl<T: ?Sized> Mirror for T {
type Assoc = T;
}
pub fn foo<'a>(x: &'a <dyn B + 'static as Mirror>::Assoc) -> &'a (dyn A + 'static) {
x
}
fn main() {}

View File

@ -1,5 +1,5 @@
error[E0133]: use of mutable static is unsafe and requires unsafe function or block
--> $DIR/unsafe-not-inherited.rs:6:31
--> $DIR/unsafe-not-inherited.rs:8:31
|
LL | unsafe {static BAR: u64 = FOO;}
| ------ ^^^ use of mutable static
@ -9,7 +9,7 @@ LL | unsafe {static BAR: u64 = FOO;}
= note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior
error[E0133]: call to unsafe function is unsafe and requires unsafe function or block
--> $DIR/unsafe-not-inherited.rs:18:13
--> $DIR/unsafe-not-inherited.rs:20:13
|
LL | unsafe {
| ------ items do not inherit unsafety from separate enclosing items

View File

@ -1,3 +1,5 @@
// revisions: mirunsafeck thirunsafeck
// [thirunsafeck]compile-flags: -Z thir-unsafeck
#![allow(unused, dead_code)]
static mut FOO: u64 = 0;

View File

@ -0,0 +1,24 @@
error[E0133]: use of mutable static is unsafe and requires unsafe function or block
--> $DIR/unsafe-not-inherited.rs:8:31
|
LL | unsafe {static BAR: u64 = FOO;}
| ------ ^^^ use of mutable static
| |
| items do not inherit unsafety from separate enclosing items
|
= note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior
error[E0133]: call to unsafe function `unsafe_call` is unsafe and requires unsafe function or block
--> $DIR/unsafe-not-inherited.rs:20:13
|
LL | unsafe {
| ------ items do not inherit unsafety from separate enclosing items
...
LL | unsafe_call();
| ^^^^^^^^^^^^^ call to unsafe function
|
= note: consult the function's documentation for information on how to avoid undefined behavior
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0133`.