Skip to content
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

Rollup of 6 pull requests #125725

Closed
wants to merge 14 commits into from
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
5 changes: 3 additions & 2 deletions compiler/rustc_mir_build/src/build/coverageinfo/mcdc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,12 +217,13 @@ impl MCDCInfoBuilder {
}
_ => {
// Do not generate mcdc mappings and statements for decisions with too many conditions.
let rebase_idx = self.branch_spans.len() - decision.conditions_num + 1;
// Therefore, first erase the condition info of the (N-1) previous branch spans.
let rebase_idx = self.branch_spans.len() - (decision.conditions_num - 1);
for branch in &mut self.branch_spans[rebase_idx..] {
branch.condition_info = None;
}

// ConditionInfo of this branch shall also be reset.
// Then, erase this last branch span's info too, for a total of N.
condition_info = None;

tcx.dcx().emit_warn(MCDCExceedsConditionNumLimit {
Expand Down
5 changes: 5 additions & 0 deletions compiler/rustc_resolve/src/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4505,6 +4505,11 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
self.visit_expr(elem);
self.resolve_anon_const(ct, AnonConstKind::ConstArg(IsRepeatExpr::Yes));
}
ExprKind::ConstBlock(ref expr) => {
self.resolve_anon_const_manual(false, AnonConstKind::InlineConst, |this| {
this.visit_expr(expr)
});
}
ExprKind::Index(ref elem, ref idx, _) => {
self.resolve_expr(elem, Some(expr));
self.visit_expr(idx);
Expand Down
3 changes: 2 additions & 1 deletion src/doc/rustc/src/target-tier-policy.md
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,8 @@ approved by the appropriate team for that shared code before acceptance.
target may not have; use conditional compilation or runtime detection, as
appropriate, to let each target run code supported by that target.
- Tier 3 targets must be able to produce assembly using at least one of
rustc's supported backends from any host target.
rustc's supported backends from any host target. (Having support in a fork
of the backend is not sufficient, it must be upstream.)

If a tier 3 target stops meeting these requirements, or the target maintainers
no longer have interest or time, or the target shows no signs of activity and
Expand Down
26 changes: 26 additions & 0 deletions src/librustdoc/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ pub(crate) struct Options {
pub(crate) enable_per_target_ignores: bool,
/// Do not run doctests, compile them if should_test is active.
pub(crate) no_run: bool,
/// What sources are being mapped.
pub(crate) remap_path_prefix: Vec<(PathBuf, PathBuf)>,

/// The path to a rustc-like binary to build tests with. If not set, we
/// default to loading from `$sysroot/bin/rustc`.
Expand Down Expand Up @@ -211,6 +213,7 @@ impl fmt::Debug for Options {
.field("run_check", &self.run_check)
.field("no_run", &self.no_run)
.field("test_builder_wrappers", &self.test_builder_wrappers)
.field("remap-file-prefix", &self.remap_path_prefix)
.field("nocapture", &self.nocapture)
.field("scrape_examples_options", &self.scrape_examples_options)
.field("unstable_features", &self.unstable_features)
Expand Down Expand Up @@ -372,6 +375,13 @@ impl Options {
let codegen_options = CodegenOptions::build(early_dcx, matches);
let unstable_opts = UnstableOptions::build(early_dcx, matches);

let remap_path_prefix = match parse_remap_path_prefix(&matches) {
Ok(prefix_mappings) => prefix_mappings,
Err(err) => {
early_dcx.early_fatal(err);
}
};

let dcx = new_dcx(error_format, None, diagnostic_width, &unstable_opts);

// check for deprecated options
Expand Down Expand Up @@ -772,6 +782,7 @@ impl Options {
run_check,
no_run,
test_builder_wrappers,
remap_path_prefix,
nocapture,
crate_name,
output_format,
Expand Down Expand Up @@ -820,6 +831,21 @@ impl Options {
}
}

fn parse_remap_path_prefix(
matches: &getopts::Matches,
) -> Result<Vec<(PathBuf, PathBuf)>, &'static str> {
matches
.opt_strs("remap-path-prefix")
.into_iter()
.map(|remap| {
remap
.rsplit_once('=')
.ok_or("--remap-path-prefix must contain '=' between FROM and TO")
.map(|(from, to)| (PathBuf::from(from), PathBuf::from(to)))
})
.collect()
}

/// Prints deprecation warnings for deprecated options
fn check_deprecated_options(matches: &getopts::Matches, dcx: &rustc_errors::DiagCtxt) {
let deprecated_flags = [];
Expand Down
32 changes: 14 additions & 18 deletions src/librustdoc/doctest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use rustc_session::config::{self, CrateType, ErrorOutputType};
use rustc_session::parse::ParseSess;
use rustc_session::{lint, Session};
use rustc_span::edition::Edition;
use rustc_span::source_map::SourceMap;
use rustc_span::source_map::{FilePathMapping, SourceMap};
use rustc_span::symbol::sym;
use rustc_span::{BytePos, FileName, Pos, Span, DUMMY_SP};
use rustc_target::spec::{Target, TargetTriple};
Expand Down Expand Up @@ -128,6 +128,7 @@ pub(crate) fn run(
edition: options.edition,
target_triple: options.target.clone(),
crate_name: options.crate_name.clone(),
remap_path_prefix: options.remap_path_prefix.clone(),
..config::Options::default()
};

Expand Down Expand Up @@ -612,7 +613,6 @@ pub(crate) fn make_test(
use rustc_errors::emitter::{Emitter, HumanEmitter};
use rustc_errors::DiagCtxt;
use rustc_parse::parser::ForceCollect;
use rustc_span::source_map::FilePathMapping;

let filename = FileName::anon_source_code(s);
let source = crates + everything_else;
Expand Down Expand Up @@ -803,7 +803,6 @@ fn check_if_attr_is_complete(source: &str, edition: Edition) -> bool {
rustc_span::create_session_if_not_set_then(edition, |_| {
use rustc_errors::emitter::HumanEmitter;
use rustc_errors::DiagCtxt;
use rustc_span::source_map::FilePathMapping;

let filename = FileName::anon_source_code(source);
// Any errors in parsing should also appear when the doctest is compiled for real, so just
Expand Down Expand Up @@ -1066,7 +1065,7 @@ impl Collector {
if !item_path.is_empty() {
item_path.push(' ');
}
format!("{} - {item_path}(line {line})", filename.prefer_local())
format!("{} - {item_path}(line {line})", filename.prefer_remapped_unconditionaly())
}

pub(crate) fn set_position(&mut self, position: Span) {
Expand All @@ -1076,11 +1075,15 @@ impl Collector {
fn get_filename(&self) -> FileName {
if let Some(ref source_map) = self.source_map {
let filename = source_map.span_to_filename(self.position);
if let FileName::Real(ref filename) = filename
&& let Ok(cur_dir) = env::current_dir()
&& let Some(local_path) = filename.local_path()
&& let Ok(path) = local_path.strip_prefix(&cur_dir)
{
if let FileName::Real(ref filename) = filename {
let path = filename.remapped_path_if_available();

// Strip the cwd prefix from the path. This will likely exist if
// the path was not remapped.
let path = env::current_dir()
.map(|cur_dir| path.strip_prefix(&cur_dir).unwrap_or(path))
.unwrap_or(path);

return path.to_owned().into();
}
filename
Expand All @@ -1107,20 +1110,13 @@ impl Tester for Collector {
}

let path = match &filename {
FileName::Real(path) => {
if let Some(local_path) = path.local_path() {
local_path.to_path_buf()
} else {
// Somehow we got the filename from the metadata of another crate, should never happen
unreachable!("doctest from a different crate");
}
}
FileName::Real(path) => path.remapped_path_if_available().to_path_buf(),
_ => PathBuf::from(r"doctest.rs"),
};

// For example `module/file.rs` would become `module_file_rs`
let file = filename
.prefer_local()
.prefer_remapped_unconditionaly()
.to_string_lossy()
.chars()
.map(|c| if c.is_ascii_alphanumeric() { c } else { '_' })
Expand Down
8 changes: 8 additions & 0 deletions src/librustdoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,14 @@ fn opts() -> Vec<RustcOptGroup> {
unstable("no-run", |o| {
o.optflagmulti("", "no-run", "Compile doctests without running them")
}),
unstable("remap-path-prefix", |o| {
o.optmulti(
"",
"remap-path-prefix",
"Remap source names in compiler messages",
"FROM=TO",
)
}),
unstable("show-type-layout", |o| {
o.optflagmulti("", "show-type-layout", "Include the memory layout of types in the docs")
}),
Expand Down
10 changes: 5 additions & 5 deletions tests/coverage/auxiliary/used_crate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,23 @@ pub fn used_function() {
}

pub fn used_only_from_bin_crate_generic_function<T: Debug>(arg: T) {
println!("used_only_from_bin_crate_generic_function with {:?}", arg);
println!("used_only_from_bin_crate_generic_function with {arg:?}");
}
// Expect for above function: `Unexecuted instantiation` (see below)
pub fn used_only_from_this_lib_crate_generic_function<T: Debug>(arg: T) {
println!("used_only_from_this_lib_crate_generic_function with {:?}", arg);
println!("used_only_from_this_lib_crate_generic_function with {arg:?}");
}

pub fn used_from_bin_crate_and_lib_crate_generic_function<T: Debug>(arg: T) {
println!("used_from_bin_crate_and_lib_crate_generic_function with {:?}", arg);
println!("used_from_bin_crate_and_lib_crate_generic_function with {arg:?}");
}

pub fn used_with_same_type_from_bin_crate_and_lib_crate_generic_function<T: Debug>(arg: T) {
println!("used_with_same_type_from_bin_crate_and_lib_crate_generic_function with {:?}", arg);
println!("used_with_same_type_from_bin_crate_and_lib_crate_generic_function with {arg:?}");
}

pub fn unused_generic_function<T: Debug>(arg: T) {
println!("unused_generic_function with {:?}", arg);
println!("unused_generic_function with {arg:?}");
}

pub fn unused_function() {
Expand Down
10 changes: 5 additions & 5 deletions tests/coverage/auxiliary/used_inline_crate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,28 +31,28 @@ pub fn used_inline_function() {

#[inline(always)]
pub fn used_only_from_bin_crate_generic_function<T: Debug>(arg: T) {
println!("used_only_from_bin_crate_generic_function with {:?}", arg);
println!("used_only_from_bin_crate_generic_function with {arg:?}");
}
// Expect for above function: `Unexecuted instantiation` (see notes in `used_crate.rs`)

#[inline(always)]
pub fn used_only_from_this_lib_crate_generic_function<T: Debug>(arg: T) {
println!("used_only_from_this_lib_crate_generic_function with {:?}", arg);
println!("used_only_from_this_lib_crate_generic_function with {arg:?}");
}

#[inline(always)]
pub fn used_from_bin_crate_and_lib_crate_generic_function<T: Debug>(arg: T) {
println!("used_from_bin_crate_and_lib_crate_generic_function with {:?}", arg);
println!("used_from_bin_crate_and_lib_crate_generic_function with {arg:?}");
}

#[inline(always)]
pub fn used_with_same_type_from_bin_crate_and_lib_crate_generic_function<T: Debug>(arg: T) {
println!("used_with_same_type_from_bin_crate_and_lib_crate_generic_function with {:?}", arg);
println!("used_with_same_type_from_bin_crate_and_lib_crate_generic_function with {arg:?}");
}

#[inline(always)]
pub fn unused_generic_function<T: Debug>(arg: T) {
println!("unused_generic_function with {:?}", arg);
println!("unused_generic_function with {arg:?}");
}

#[inline(always)]
Expand Down
8 changes: 4 additions & 4 deletions tests/coverage/coroutine.cov-map
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Number of file 0 mappings: 4
- Code(Counter(0)) at (prev + 2, 1) to (start + 0, 2)

Function name: coroutine::main
Raw bytes (65): 0x[01, 01, 08, 07, 0d, 05, 09, 11, 15, 1e, 19, 11, 15, 15, 19, 1e, 19, 11, 15, 09, 01, 13, 01, 02, 16, 01, 07, 0b, 00, 2e, 11, 01, 2b, 00, 2d, 03, 01, 0e, 00, 35, 11, 02, 0b, 00, 2e, 1e, 01, 22, 00, 27, 1a, 00, 2c, 00, 2e, 17, 01, 0e, 00, 35, 1a, 02, 01, 00, 02]
Raw bytes (65): 0x[01, 01, 08, 07, 0d, 05, 09, 11, 15, 1e, 19, 11, 15, 15, 19, 1e, 19, 11, 15, 09, 01, 13, 01, 02, 16, 01, 08, 0b, 00, 2e, 11, 01, 2b, 00, 2d, 03, 01, 0e, 00, 35, 11, 02, 0b, 00, 2e, 1e, 01, 22, 00, 27, 1a, 00, 2c, 00, 2e, 17, 01, 0e, 00, 35, 1a, 02, 01, 00, 02]
Number of files: 1
- file 0 => global file 1
Number of expressions: 8
Expand All @@ -26,7 +26,7 @@ Number of expressions: 8
- expression 7 operands: lhs = Counter(4), rhs = Counter(5)
Number of file 0 mappings: 9
- Code(Counter(0)) at (prev + 19, 1) to (start + 2, 22)
- Code(Counter(0)) at (prev + 7, 11) to (start + 0, 46)
- Code(Counter(0)) at (prev + 8, 11) to (start + 0, 46)
- Code(Counter(4)) at (prev + 1, 43) to (start + 0, 45)
- Code(Expression(0, Add)) at (prev + 1, 14) to (start + 0, 53)
= ((c1 + c2) + c3)
Expand All @@ -41,11 +41,11 @@ Number of file 0 mappings: 9
= ((c4 - c5) - c6)

Function name: coroutine::main::{closure#0}
Raw bytes (14): 0x[01, 01, 00, 02, 01, 15, 29, 01, 1f, 05, 02, 10, 01, 06]
Raw bytes (14): 0x[01, 01, 00, 02, 01, 16, 08, 01, 1f, 05, 02, 10, 01, 06]
Number of files: 1
- file 0 => global file 1
Number of expressions: 0
Number of file 0 mappings: 2
- Code(Counter(0)) at (prev + 21, 41) to (start + 1, 31)
- Code(Counter(0)) at (prev + 22, 8) to (start + 1, 31)
- Code(Counter(1)) at (prev + 2, 16) to (start + 1, 6)

7 changes: 4 additions & 3 deletions tests/coverage/coroutine.coverage
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@
LL| |// to handle this condition, and still report dead block coverage.
LL| 1|fn get_u32(val: bool) -> Result<u32, String> {
LL| 1| if val {
LL| 1| Ok(1)
LL| 1| Ok(1) //
LL| | } else {
LL| 0| Err(String::from("some error"))
LL| 0| Err(String::from("some error")) //
LL| | }
LL| 1|}
LL| |
LL| 1|fn main() {
LL| 1| let is_true = std::env::args().len() == 1;
LL| 1| let mut coroutine = #[coroutine] || {
LL| 1| let mut coroutine = #[coroutine]
LL| 1| || {
LL| 1| yield get_u32(is_true);
LL| 1| return "foo";
LL| 1| };
Expand Down
7 changes: 4 additions & 3 deletions tests/coverage/coroutine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@ use std::pin::Pin;
// to handle this condition, and still report dead block coverage.
fn get_u32(val: bool) -> Result<u32, String> {
if val {
Ok(1)
Ok(1) //
} else {
Err(String::from("some error"))
Err(String::from("some error")) //
}
}

fn main() {
let is_true = std::env::args().len() == 1;
let mut coroutine = #[coroutine] || {
let mut coroutine = #[coroutine]
|| {
yield get_u32(is_true);
return "foo";
};
Expand Down
2 changes: 1 addition & 1 deletion tests/coverage/inline-dead.coverage
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
LL| |#[inline]
LL| 1|fn live<const B: bool>() -> u32 {
LL| 1| if B {
LL| 0| dead()
LL| 0| dead() //
LL| | } else {
LL| 1| 0
LL| | }
Expand Down
2 changes: 1 addition & 1 deletion tests/coverage/inline-dead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ fn main() {
#[inline]
fn live<const B: bool>() -> u32 {
if B {
dead()
dead() //
} else {
0
}
Expand Down
2 changes: 1 addition & 1 deletion tests/coverage/inner_items.coverage
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
^0
LL| |
LL| 1| let mut val = InStruct {
LL| 1| in_struct_field: 101,
LL| 1| in_struct_field: 101, //
LL| 1| };
LL| 1|
LL| 1| val.default_trait_func();
Expand Down
2 changes: 1 addition & 1 deletion tests/coverage/inner_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ fn main() {
}

let mut val = InStruct {
in_struct_field: 101,
in_struct_field: 101, //
};

val.default_trait_func();
Expand Down
6 changes: 3 additions & 3 deletions tests/coverage/let_else_loop.cov-map
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
Function name: let_else_loop::_if (unused)
Raw bytes (19): 0x[01, 01, 00, 03, 00, 16, 01, 01, 0c, 00, 02, 09, 00, 10, 00, 02, 09, 00, 10]
Raw bytes (19): 0x[01, 01, 00, 03, 00, 16, 01, 01, 0c, 00, 01, 0f, 00, 16, 00, 00, 20, 00, 27]
Number of files: 1
- file 0 => global file 1
Number of expressions: 0
Number of file 0 mappings: 3
- Code(Zero) at (prev + 22, 1) to (start + 1, 12)
- Code(Zero) at (prev + 2, 9) to (start + 0, 16)
- Code(Zero) at (prev + 2, 9) to (start + 0, 16)
- Code(Zero) at (prev + 1, 15) to (start + 0, 22)
- Code(Zero) at (prev + 0, 32) to (start + 0, 39)

Function name: let_else_loop::_loop_either_way (unused)
Raw bytes (19): 0x[01, 01, 00, 03, 00, 0f, 01, 01, 14, 00, 01, 1c, 00, 23, 00, 01, 05, 00, 0c]
Expand Down
6 changes: 1 addition & 5 deletions tests/coverage/let_else_loop.coverage
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@
LL| |// Variant using regular `if` instead of let-else.
LL| |// This doesn't trigger the original ICE, but might help detect regressions.
LL| 0|fn _if(cond: bool) {
LL| 0| if cond {
LL| 0| loop {}
LL| | } else {
LL| 0| loop {}
LL| | }
LL| 0| if cond { loop {} } else { loop {} }
LL| |}
LL| |
LL| |#[coverage(off)]
Expand Down
Loading
Loading