Skip to content

Commit a2cd91c

Browse files
committedJan 11, 2021
Auto merge of #80905 - JohnTitor:rollup-tmmwmnb, r=JohnTitor
Rollup of 6 pull requests Successful merges: - #80809 (Use standard formatting for "rust-call" ABI message) - #80872 (Fix typo in source-based-code-coverage.md) - #80878 (Add ABI argument to `find_mir_or_eval_fn`) - #80881 ( Fix intra-doc links to `Self` and `crate` ) - #80887 (log-color: Detect TTY based on stderr, not stdout) - #80892 (rustdoc: Remove `*` intra-doc alias for `pointer`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 00c5c39 + a7f7d70 commit a2cd91c

File tree

15 files changed

+76
-45
lines changed

15 files changed

+76
-45
lines changed
 

‎compiler/rustc_driver/src/lib.rs

+21-2
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,25 @@ fn stdout_isatty() -> bool {
566566
}
567567
}
568568

569+
// FIXME remove these and use winapi 0.3 instead
570+
#[cfg(unix)]
571+
fn stderr_isatty() -> bool {
572+
unsafe { libc::isatty(libc::STDERR_FILENO) != 0 }
573+
}
574+
575+
#[cfg(windows)]
576+
fn stderr_isatty() -> bool {
577+
use winapi::um::consoleapi::GetConsoleMode;
578+
use winapi::um::processenv::GetStdHandle;
579+
use winapi::um::winbase::STD_ERROR_HANDLE;
580+
581+
unsafe {
582+
let handle = GetStdHandle(STD_ERROR_HANDLE);
583+
let mut out = 0;
584+
GetConsoleMode(handle, &mut out) != 0
585+
}
586+
}
587+
569588
fn handle_explain(registry: Registry, code: &str, output: ErrorOutputType) {
570589
let normalised =
571590
if code.starts_with('E') { code.to_string() } else { format!("E{0:0>4}", code) };
@@ -1290,7 +1309,7 @@ pub fn init_env_logger(env: &str) {
12901309
Ok(value) => match value.as_ref() {
12911310
"always" => true,
12921311
"never" => false,
1293-
"auto" => stdout_isatty(),
1312+
"auto" => stderr_isatty(),
12941313
_ => early_error(
12951314
ErrorOutputType::default(),
12961315
&format!(
@@ -1299,7 +1318,7 @@ pub fn init_env_logger(env: &str) {
12991318
),
13001319
),
13011320
},
1302-
Err(std::env::VarError::NotPresent) => stdout_isatty(),
1321+
Err(std::env::VarError::NotPresent) => stderr_isatty(),
13031322
Err(std::env::VarError::NotUnicode(_value)) => early_error(
13041323
ErrorOutputType::default(),
13051324
"non-Unicode log color value: expected one of always, never, or auto",

‎compiler/rustc_mir/src/const_eval/machine.rs

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use rustc_middle::mir::AssertMessage;
1313
use rustc_session::Limit;
1414
use rustc_span::symbol::{sym, Symbol};
1515
use rustc_target::abi::{Align, Size};
16+
use rustc_target::spec::abi::Abi;
1617

1718
use crate::interpret::{
1819
self, compile_time_machine, AllocId, Allocation, Frame, ImmTy, InterpCx, InterpResult, Memory,
@@ -203,6 +204,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
203204
fn find_mir_or_eval_fn(
204205
ecx: &mut InterpCx<'mir, 'tcx, Self>,
205206
instance: ty::Instance<'tcx>,
207+
_abi: Abi,
206208
args: &[OpTy<'tcx>],
207209
_ret: Option<(PlaceTy<'tcx>, mir::BasicBlock)>,
208210
_unwind: Option<mir::BasicBlock>, // unwinding is not supported in consts

‎compiler/rustc_mir/src/interpret/machine.rs

+4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use rustc_middle::mir;
1010
use rustc_middle::ty::{self, Ty};
1111
use rustc_span::def_id::DefId;
1212
use rustc_target::abi::Size;
13+
use rustc_target::spec::abi::Abi;
1314

1415
use super::{
1516
AllocId, Allocation, AllocationExtra, CheckInAllocMsg, Frame, ImmTy, InterpCx, InterpResult,
@@ -144,6 +145,7 @@ pub trait Machine<'mir, 'tcx>: Sized {
144145
fn find_mir_or_eval_fn(
145146
ecx: &mut InterpCx<'mir, 'tcx, Self>,
146147
instance: ty::Instance<'tcx>,
148+
abi: Abi,
147149
args: &[OpTy<'tcx, Self::PointerTag>],
148150
ret: Option<(PlaceTy<'tcx, Self::PointerTag>, mir::BasicBlock)>,
149151
unwind: Option<mir::BasicBlock>,
@@ -154,6 +156,7 @@ pub trait Machine<'mir, 'tcx>: Sized {
154156
fn call_extra_fn(
155157
ecx: &mut InterpCx<'mir, 'tcx, Self>,
156158
fn_val: Self::ExtraFnVal,
159+
abi: Abi,
157160
args: &[OpTy<'tcx, Self::PointerTag>],
158161
ret: Option<(PlaceTy<'tcx, Self::PointerTag>, mir::BasicBlock)>,
159162
unwind: Option<mir::BasicBlock>,
@@ -405,6 +408,7 @@ pub macro compile_time_machine(<$mir: lifetime, $tcx: lifetime>) {
405408
fn call_extra_fn(
406409
_ecx: &mut InterpCx<$mir, $tcx, Self>,
407410
fn_val: !,
411+
_abi: Abi,
408412
_args: &[OpTy<$tcx>],
409413
_ret: Option<(PlaceTy<$tcx>, mir::BasicBlock)>,
410414
_unwind: Option<mir::BasicBlock>,

‎compiler/rustc_mir/src/interpret/terminator.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
219219
let instance = match fn_val {
220220
FnVal::Instance(instance) => instance,
221221
FnVal::Other(extra) => {
222-
return M::call_extra_fn(self, extra, args, ret, unwind);
222+
return M::call_extra_fn(self, extra, caller_abi, args, ret, unwind);
223223
}
224224
};
225225

@@ -264,10 +264,11 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
264264
| ty::InstanceDef::CloneShim(..)
265265
| ty::InstanceDef::Item(_) => {
266266
// We need MIR for this fn
267-
let body = match M::find_mir_or_eval_fn(self, instance, args, ret, unwind)? {
268-
Some(body) => body,
269-
None => return Ok(()),
270-
};
267+
let body =
268+
match M::find_mir_or_eval_fn(self, instance, caller_abi, args, ret, unwind)? {
269+
Some(body) => body,
270+
None => return Ok(()),
271+
};
271272

272273
self.push_stack_frame(
273274
instance,

‎compiler/rustc_mir/src/transform/const_prop.rs

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ use rustc_middle::ty::{
2525
use rustc_session::lint;
2626
use rustc_span::{def_id::DefId, Span};
2727
use rustc_target::abi::{HasDataLayout, LayoutOf, Size, TargetDataLayout};
28+
use rustc_target::spec::abi::Abi;
2829
use rustc_trait_selection::traits;
2930

3031
use crate::const_eval::ConstEvalErr;
@@ -187,6 +188,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for ConstPropMachine<'mir, 'tcx>
187188
fn find_mir_or_eval_fn(
188189
_ecx: &mut InterpCx<'mir, 'tcx, Self>,
189190
_instance: ty::Instance<'tcx>,
191+
_abi: Abi,
190192
_args: &[OpTy<'tcx>],
191193
_ret: Option<(PlaceTy<'tcx>, BasicBlock)>,
192194
_unwind: Option<BasicBlock>,

‎compiler/rustc_typeck/src/check/check.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ pub(super) fn check_fn<'a, 'tcx>(
113113
};
114114

115115
if let Some(header) = item {
116-
tcx.sess.span_err(header.span, "A function with the \"rust-call\" ABI must take a single non-self argument that is a tuple")
116+
tcx.sess.span_err(header.span, "functions with the \"rust-call\" ABI must take a single non-self argument that is a tuple")
117117
}
118118
};
119119

‎src/doc/unstable-book/src/compiler-flags/source-based-code-coverage.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ The `rustup` option is guaranteed to install a compatible version of the LLVM to
123123
```shell
124124
$ rustup component add llvm-tools-preview
125125
$ cargo install cargo-binutils
126-
$ cargo profdata -- --help # note the additional "--" preceeding the tool-specific arguments
126+
$ cargo profdata -- --help # note the additional "--" preceding the tool-specific arguments
127127
```
128128

129129
## Creating coverage reports

‎src/librustdoc/passes/collect_intra_doc_links.rs

+21-22
Original file line numberDiff line numberDiff line change
@@ -504,15 +504,9 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
504504
match res {
505505
// FIXME(#76467): make this fallthrough to lookup the associated
506506
// item a separate function.
507-
Res::Def(DefKind::AssocFn | DefKind::AssocConst, _) => {
508-
assert_eq!(ns, ValueNS);
509-
}
510-
Res::Def(DefKind::AssocTy, _) => {
511-
assert_eq!(ns, TypeNS);
512-
}
513-
Res::Def(DefKind::Variant, _) => {
514-
return handle_variant(cx, res, extra_fragment);
515-
}
507+
Res::Def(DefKind::AssocFn | DefKind::AssocConst, _) => assert_eq!(ns, ValueNS),
508+
Res::Def(DefKind::AssocTy, _) => assert_eq!(ns, TypeNS),
509+
Res::Def(DefKind::Variant, _) => return handle_variant(cx, res, extra_fragment),
516510
// Not a trait item; just return what we found.
517511
Res::Primitive(ty) => {
518512
if extra_fragment.is_some() {
@@ -522,12 +516,7 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
522516
}
523517
return Ok((res, Some(ty.as_str().to_owned())));
524518
}
525-
Res::Def(DefKind::Mod, _) => {
526-
return Ok((res, extra_fragment.clone()));
527-
}
528-
_ => {
529-
return Ok((res, extra_fragment.clone()));
530-
}
519+
_ => return Ok((res, extra_fragment.clone())),
531520
}
532521
}
533522

@@ -1024,12 +1013,18 @@ impl LinkCollector<'_, '_> {
10241013

10251014
let resolved_self;
10261015
// replace `Self` with suitable item's parent name
1027-
if path_str.starts_with("Self::") {
1016+
let is_lone_self = path_str == "Self";
1017+
let is_lone_crate = path_str == "crate";
1018+
if path_str.starts_with("Self::") || is_lone_self {
10281019
if let Some(ref name) = self_name {
1029-
resolved_self = format!("{}::{}", name, &path_str[6..]);
1030-
path_str = &resolved_self;
1020+
if is_lone_self {
1021+
path_str = name;
1022+
} else {
1023+
resolved_self = format!("{}::{}", name, &path_str[6..]);
1024+
path_str = &resolved_self;
1025+
}
10311026
}
1032-
} else if path_str.starts_with("crate::") {
1027+
} else if path_str.starts_with("crate::") || is_lone_crate {
10331028
use rustc_span::def_id::CRATE_DEF_INDEX;
10341029

10351030
// HACK(jynelson): rustc_resolve thinks that `crate` is the crate currently being documented.
@@ -1038,8 +1033,12 @@ impl LinkCollector<'_, '_> {
10381033
// HACK(jynelson)(2): If we just strip `crate::` then suddenly primitives become ambiguous
10391034
// (consider `crate::char`). Instead, change it to `self::`. This works because 'self' is now the crate root.
10401035
// FIXME(#78696): This doesn't always work.
1041-
resolved_self = format!("self::{}", &path_str["crate::".len()..]);
1042-
path_str = &resolved_self;
1036+
if is_lone_crate {
1037+
path_str = "self";
1038+
} else {
1039+
resolved_self = format!("self::{}", &path_str["crate::".len()..]);
1040+
path_str = &resolved_self;
1041+
}
10431042
module_id = DefId { krate, index: CRATE_DEF_INDEX };
10441043
}
10451044

@@ -2092,7 +2091,7 @@ fn resolve_primitive(path_str: &str, ns: Namespace) -> Option<Res> {
20922091
"array" => Array,
20932092
"tuple" => Tuple,
20942093
"unit" => Unit,
2095-
"pointer" | "*" | "*const" | "*mut" => RawPointer,
2094+
"pointer" | "*const" | "*mut" => RawPointer,
20962095
"reference" | "&" | "&mut" => Reference,
20972096
"fn" => Fn,
20982097
"never" | "!" => Never,

‎src/test/rustdoc/intra-doc-crate/auxiliary/self.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
#![crate_name = "cross_crate_self"]
2+
3+
/// Link to [Self]
4+
/// Link to [crate]
25
pub struct S;
36

47
impl S {
+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
// aux-build:self.rs
2+
// build-aux-docs
23

34
extern crate cross_crate_self;
45

56
// @has self/struct.S.html '//a[@href="../self/struct.S.html#method.f"]' "Self::f"
7+
// @has self/struct.S.html '//a[@href="../self/struct.S.html"]' "Self"
8+
// @has self/struct.S.html '//a[@href="../cross_crate_self/index.html"]' "crate"
69
pub use cross_crate_self::S;

‎src/test/rustdoc/intra-doc/non-path-primitives.rs

-2
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,9 @@
1111
// @has - '//a[@href="https://doc.rust-lang.org/nightly/std/primitive.pointer.html#method.is_null"]' 'pointer::is_null'
1212
// @has - '//a[@href="https://doc.rust-lang.org/nightly/std/primitive.pointer.html#method.is_null"]' '*const::is_null'
1313
// @has - '//a[@href="https://doc.rust-lang.org/nightly/std/primitive.pointer.html#method.is_null"]' '*mut::is_null'
14-
// @has - '//a[@href="https://doc.rust-lang.org/nightly/std/primitive.pointer.html#method.is_null"]' '*::is_null'
1514
//! [pointer::is_null]
1615
//! [*const::is_null]
1716
//! [*mut::is_null]
18-
//! [*::is_null]
1917
2018
// @has - '//a[@href="https://doc.rust-lang.org/nightly/std/primitive.unit.html"]' 'unit'
2119
//! [unit]

‎src/test/ui/abi/issues/issue-22565-rust-call.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
#![feature(unboxed_closures)]
22

33
extern "rust-call" fn b(_i: i32) {}
4-
//~^ ERROR A function with the "rust-call" ABI must take a single non-self argument that is a tuple
4+
//~^ ERROR functions with the "rust-call" ABI must take a single non-self argument that is a tuple
55

66
trait Tr {
77
extern "rust-call" fn a();
88

99
extern "rust-call" fn b() {}
10-
//~^ ERROR A function with the "rust-call" ABI must take a single non-self argument
10+
//~^ ERROR functions with the "rust-call" ABI must take a single non-self argument
1111
}
1212

1313
struct Foo;
1414

1515
impl Foo {
1616
extern "rust-call" fn bar() {}
17-
//~^ ERROR A function with the "rust-call" ABI must take a single non-self argument
17+
//~^ ERROR functions with the "rust-call" ABI must take a single non-self argument
1818
}
1919

2020
impl Tr for Foo {
2121
extern "rust-call" fn a() {}
22-
//~^ ERROR A function with the "rust-call" ABI must take a single non-self argument
22+
//~^ ERROR functions with the "rust-call" ABI must take a single non-self argument
2323
}
2424

2525
fn main () {

‎src/test/ui/abi/issues/issue-22565-rust-call.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
error: A function with the "rust-call" ABI must take a single non-self argument that is a tuple
1+
error: functions with the "rust-call" ABI must take a single non-self argument that is a tuple
22
--> $DIR/issue-22565-rust-call.rs:3:1
33
|
44
LL | extern "rust-call" fn b(_i: i32) {}
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66

7-
error: A function with the "rust-call" ABI must take a single non-self argument that is a tuple
7+
error: functions with the "rust-call" ABI must take a single non-self argument that is a tuple
88
--> $DIR/issue-22565-rust-call.rs:9:5
99
|
1010
LL | extern "rust-call" fn b() {}
1111
| ^^^^^^^^^^^^^^^^^^^^^^^^^
1212

13-
error: A function with the "rust-call" ABI must take a single non-self argument that is a tuple
13+
error: functions with the "rust-call" ABI must take a single non-self argument that is a tuple
1414
--> $DIR/issue-22565-rust-call.rs:16:5
1515
|
1616
LL | extern "rust-call" fn bar() {}
1717
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
1818

19-
error: A function with the "rust-call" ABI must take a single non-self argument that is a tuple
19+
error: functions with the "rust-call" ABI must take a single non-self argument that is a tuple
2020
--> $DIR/issue-22565-rust-call.rs:21:5
2121
|
2222
LL | extern "rust-call" fn a() {}

‎src/test/ui/overloaded-calls-nontuple.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ impl FnMut<isize> for S {
1111
extern "rust-call" fn call_mut(&mut self, z: isize) -> isize {
1212
self.x + self.y + z
1313
}
14-
//~^^^ ERROR A function with the "rust-call" ABI must take a single non-self argument
14+
//~^^^ ERROR functions with the "rust-call" ABI must take a single non-self argument
1515
}
1616

1717
impl FnOnce<isize> for S {
1818
type Output = isize;
1919
extern "rust-call" fn call_once(mut self, z: isize) -> isize { self.call_mut(z) }
20-
//~^ ERROR A function with the "rust-call" ABI must take a single non-self argument
20+
//~^ ERROR functions with the "rust-call" ABI must take a single non-self argument
2121
}
2222

2323
fn main() {

‎src/test/ui/overloaded-calls-nontuple.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
error: A function with the "rust-call" ABI must take a single non-self argument that is a tuple
1+
error: functions with the "rust-call" ABI must take a single non-self argument that is a tuple
22
--> $DIR/overloaded-calls-nontuple.rs:11:5
33
|
44
LL | extern "rust-call" fn call_mut(&mut self, z: isize) -> isize {
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66

7-
error: A function with the "rust-call" ABI must take a single non-self argument that is a tuple
7+
error: functions with the "rust-call" ABI must take a single non-self argument that is a tuple
88
--> $DIR/overloaded-calls-nontuple.rs:19:5
99
|
1010
LL | extern "rust-call" fn call_once(mut self, z: isize) -> isize { self.call_mut(z) }

0 commit comments

Comments
 (0)
Please sign in to comment.