Skip to content

Commit 2a43428

Browse files
committed
Auto merge of rust-lang#104607 - matthiaskrgr:rollup-9s589me, r=matthiaskrgr
Rollup of 10 pull requests Successful merges: - rust-lang#103117 (Use `IsTerminal` in place of `atty`) - rust-lang#103969 (Partial support for running UI tests with `download-rustc`) - rust-lang#103989 (Fix build of std for thumbv7a-pc-windows-msvc) - rust-lang#104076 (fix sysroot issue which appears for ci downloaded rustc) - rust-lang#104469 (Make "long type" printing type aware and trim types in E0275) - rust-lang#104497 (detect () to avoid redundant <> suggestion for type) - rust-lang#104577 (Don't focus on notable trait parent when hiding it) - rust-lang#104587 (Update cargo) - rust-lang#104593 (Improve spans for RPITIT object-safety errors) - rust-lang#104604 (Migrate top buttons style to CSS variables) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 62c627c + f69f4cb commit 2a43428

File tree

64 files changed

+488
-226
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+488
-226
lines changed

Cargo.lock

+14-7
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ dependencies = [
307307
"glob",
308308
"hex 0.4.2",
309309
"home",
310+
"http-auth",
310311
"humantime 2.0.1",
311312
"ignore",
312313
"im-rc",
@@ -349,11 +350,11 @@ dependencies = [
349350

350351
[[package]]
351352
name = "cargo-credential"
352-
version = "0.1.0"
353+
version = "0.2.0"
353354

354355
[[package]]
355356
name = "cargo-credential-1password"
356-
version = "0.1.0"
357+
version = "0.2.0"
357358
dependencies = [
358359
"cargo-credential",
359360
"serde",
@@ -362,15 +363,15 @@ dependencies = [
362363

363364
[[package]]
364365
name = "cargo-credential-macos-keychain"
365-
version = "0.1.0"
366+
version = "0.2.0"
366367
dependencies = [
367368
"cargo-credential",
368369
"security-framework",
369370
]
370371

371372
[[package]]
372373
name = "cargo-credential-wincred"
373-
version = "0.1.0"
374+
version = "0.2.0"
374375
dependencies = [
375376
"cargo-credential",
376377
"winapi",
@@ -1692,6 +1693,15 @@ dependencies = [
16921693
"syn",
16931694
]
16941695

1696+
[[package]]
1697+
name = "http-auth"
1698+
version = "0.1.6"
1699+
source = "registry+https://github.com/rust-lang/crates.io-index"
1700+
checksum = "c0b40b39d66c28829a0cf4d09f7e139ff8201f7500a5083732848ed3b4b4d850"
1701+
dependencies = [
1702+
"memchr",
1703+
]
1704+
16951705
[[package]]
16961706
name = "humantime"
16971707
version = "1.3.0"
@@ -3535,7 +3545,6 @@ name = "rustc_errors"
35353545
version = "0.0.0"
35363546
dependencies = [
35373547
"annotate-snippets",
3538-
"atty",
35393548
"rustc_ast",
35403549
"rustc_ast_pretty",
35413550
"rustc_data_structures",
@@ -3834,7 +3843,6 @@ dependencies = [
38343843
name = "rustc_log"
38353844
version = "0.0.0"
38363845
dependencies = [
3837-
"atty",
38383846
"rustc_span",
38393847
"tracing",
38403848
"tracing-subscriber",
@@ -4389,7 +4397,6 @@ version = "0.0.0"
43894397
dependencies = [
43904398
"arrayvec",
43914399
"askama",
4392-
"atty",
43934400
"expect-test",
43944401
"itertools",
43954402
"minifier",

compiler/rustc_const_eval/src/transform/check_consts/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ impl<'mir, 'tcx> ConstCx<'mir, 'tcx> {
6262
}
6363

6464
fn is_async(&self) -> bool {
65-
self.tcx.asyncness(self.def_id()) == hir::IsAsync::Async
65+
self.tcx.asyncness(self.def_id()).is_async()
6666
}
6767
}
6868

compiler/rustc_driver/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
//! This API is completely unstable and subject to change.
66
77
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
8+
#![feature(is_terminal)]
89
#![feature(once_cell)]
910
#![feature(decl_macro)]
1011
#![recursion_limit = "256"]
@@ -27,7 +28,6 @@ use rustc_feature::find_gated_cfg;
2728
use rustc_interface::util::{self, collect_crate_types, get_codegen_backend};
2829
use rustc_interface::{interface, Queries};
2930
use rustc_lint::LintStore;
30-
use rustc_log::stdout_isatty;
3131
use rustc_metadata::locator;
3232
use rustc_save_analysis as save;
3333
use rustc_save_analysis::DumpHandler;
@@ -48,7 +48,7 @@ use std::default::Default;
4848
use std::env;
4949
use std::ffi::OsString;
5050
use std::fs;
51-
use std::io::{self, Read, Write};
51+
use std::io::{self, IsTerminal, Read, Write};
5252
use std::panic::{self, catch_unwind};
5353
use std::path::PathBuf;
5454
use std::process::{self, Command, Stdio};
@@ -515,7 +515,7 @@ fn handle_explain(registry: Registry, code: &str, output: ErrorOutputType) {
515515
}
516516
text.push('\n');
517517
}
518-
if stdout_isatty() {
518+
if io::stdout().is_terminal() {
519519
show_content_with_pager(&text);
520520
} else {
521521
print!("{}", text);

compiler/rustc_errors/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ rustc_target = { path = "../rustc_target" }
1818
rustc_hir = { path = "../rustc_hir" }
1919
rustc_lint_defs = { path = "../rustc_lint_defs" }
2020
unicode-width = "0.1.4"
21-
atty = "0.2"
2221
termcolor = "1.0"
2322
annotate-snippets = "0.9"
2423
termize = "0.1.1"

compiler/rustc_errors/src/emitter.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ use rustc_error_messages::FluentArgs;
2828
use rustc_span::hygiene::{ExpnKind, MacroKind};
2929
use std::borrow::Cow;
3030
use std::cmp::{max, min, Reverse};
31-
use std::io;
3231
use std::io::prelude::*;
32+
use std::io::{self, IsTerminal};
3333
use std::iter;
3434
use std::path::Path;
3535
use termcolor::{Ansi, BufferWriter, ColorChoice, ColorSpec, StandardStream};
@@ -619,14 +619,14 @@ impl ColorConfig {
619619
fn to_color_choice(self) -> ColorChoice {
620620
match self {
621621
ColorConfig::Always => {
622-
if atty::is(atty::Stream::Stderr) {
622+
if io::stderr().is_terminal() {
623623
ColorChoice::Always
624624
} else {
625625
ColorChoice::AlwaysAnsi
626626
}
627627
}
628628
ColorConfig::Never => ColorChoice::Never,
629-
ColorConfig::Auto if atty::is(atty::Stream::Stderr) => ColorChoice::Auto,
629+
ColorConfig::Auto if io::stderr().is_terminal() => ColorChoice::Auto,
630630
ColorConfig::Auto => ColorChoice::Never,
631631
}
632632
}

compiler/rustc_errors/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
66
#![feature(drain_filter)]
77
#![feature(if_let_guard)]
8+
#![feature(is_terminal)]
89
#![feature(adt_const_params)]
910
#![feature(let_chains)]
1011
#![feature(never_type)]

compiler/rustc_hir/src/hir.rs

+6
Original file line numberDiff line numberDiff line change
@@ -2720,6 +2720,12 @@ pub enum IsAsync {
27202720
NotAsync,
27212721
}
27222722

2723+
impl IsAsync {
2724+
pub fn is_async(self) -> bool {
2725+
self == IsAsync::Async
2726+
}
2727+
}
2728+
27232729
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, Encodable, Decodable, HashStable_Generic)]
27242730
pub enum Defaultness {
27252731
Default { has_value: bool },

compiler/rustc_hir_analysis/src/check/compare_method.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -684,9 +684,7 @@ fn report_trait_method_mismatch<'tcx>(
684684
// Suggestion to change output type. We do not suggest in `async` functions
685685
// to avoid complex logic or incorrect output.
686686
match tcx.hir().expect_impl_item(impl_m.def_id.expect_local()).kind {
687-
ImplItemKind::Fn(ref sig, _)
688-
if sig.header.asyncness == hir::IsAsync::NotAsync =>
689-
{
687+
ImplItemKind::Fn(ref sig, _) if !sig.header.asyncness.is_async() => {
690688
let msg = "change the output type to match the trait";
691689
let ap = Applicability::MachineApplicable;
692690
match sig.decl.output {

compiler/rustc_hir_typeck/src/method/suggest.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1918,12 +1918,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
19181918
| ty::Str
19191919
| ty::Projection(_)
19201920
| ty::Param(_) => format!("{deref_ty}"),
1921-
// we need to test something like <&[_]>::len
1921+
// we need to test something like <&[_]>::len or <(&[u32])>::len
19221922
// and Vec::function();
1923-
// <&[_]>::len doesn't need an extra "<>" between
1923+
// <&[_]>::len or <&[u32]>::len doesn't need an extra "<>" between
19241924
// but for Adt type like Vec::function()
19251925
// we would suggest <[_]>::function();
1926-
_ if self.tcx.sess.source_map().span_wrapped_by_angle_bracket(ty.span) => format!("{deref_ty}"),
1926+
_ if self.tcx.sess.source_map().span_wrapped_by_angle_or_parentheses(ty.span) => format!("{deref_ty}"),
19271927
_ => format!("<{deref_ty}>"),
19281928
};
19291929
err.span_suggestion_verbose(

compiler/rustc_log/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ version = "0.0.0"
44
edition = "2021"
55

66
[dependencies]
7-
atty = "0.2"
87
tracing = "0.1.28"
98
tracing-subscriber = { version = "0.3.3", default-features = false, features = ["fmt", "env-filter", "smallvec", "parking_lot", "ansi"] }
109
tracing-tree = "0.2.0"

compiler/rustc_log/src/lib.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,11 @@
4040
4141
#![deny(rustc::untranslatable_diagnostic)]
4242
#![deny(rustc::diagnostic_outside_of_impl)]
43+
#![feature(is_terminal)]
4344

4445
use std::env::{self, VarError};
4546
use std::fmt::{self, Display};
46-
use std::io;
47+
use std::io::{self, IsTerminal};
4748
use tracing_subscriber::filter::{Directive, EnvFilter, LevelFilter};
4849
use tracing_subscriber::layer::SubscriberExt;
4950

@@ -93,11 +94,11 @@ pub fn init_env_logger(env: &str) -> Result<(), Error> {
9394
}
9495

9596
pub fn stdout_isatty() -> bool {
96-
atty::is(atty::Stream::Stdout)
97+
io::stdout().is_terminal()
9798
}
9899

99100
pub fn stderr_isatty() -> bool {
100-
atty::is(atty::Stream::Stderr)
101+
io::stderr().is_terminal()
101102
}
102103

103104
#[derive(Debug)]

compiler/rustc_middle/src/traits/mod.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -924,10 +924,13 @@ impl ObjectSafetyViolation {
924924
}
925925
ObjectSafetyViolation::Method(
926926
name,
927-
MethodViolationCode::ReferencesImplTraitInTrait,
927+
MethodViolationCode::ReferencesImplTraitInTrait(_),
928928
_,
929929
) => format!("method `{}` references an `impl Trait` type in its return type", name)
930930
.into(),
931+
ObjectSafetyViolation::Method(name, MethodViolationCode::AsyncFn, _) => {
932+
format!("method `{}` is `async`", name).into()
933+
}
931934
ObjectSafetyViolation::Method(
932935
name,
933936
MethodViolationCode::WhereClauseReferencesSelf,
@@ -1035,7 +1038,10 @@ pub enum MethodViolationCode {
10351038
ReferencesSelfOutput,
10361039

10371040
/// e.g., `fn foo(&self) -> impl Sized`
1038-
ReferencesImplTraitInTrait,
1041+
ReferencesImplTraitInTrait(Span),
1042+
1043+
/// e.g., `async fn foo(&self)`
1044+
AsyncFn,
10391045

10401046
/// e.g., `fn foo(&self) where Self: Clone`
10411047
WhereClauseReferencesSelf,

compiler/rustc_middle/src/ty/error.rs

+37
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ use rustc_span::{BytePos, Span};
1212
use rustc_target::spec::abi;
1313

1414
use std::borrow::Cow;
15+
use std::collections::hash_map::DefaultHasher;
1516
use std::fmt;
17+
use std::hash::{Hash, Hasher};
18+
use std::path::PathBuf;
19+
20+
use super::print::PrettyPrinter;
1621

1722
#[derive(Clone, Copy, Debug, PartialEq, Eq, TypeFoldable, TypeVisitable, Lift)]
1823
pub struct ExpectedFound<T> {
@@ -985,6 +990,38 @@ fn foo(&self) -> Self::T { String::new() }
985990
false
986991
}
987992

993+
pub fn short_ty_string(self, ty: Ty<'tcx>) -> (String, Option<PathBuf>) {
994+
let length_limit = 50;
995+
let type_limit = 4;
996+
let regular = FmtPrinter::new(self, hir::def::Namespace::TypeNS)
997+
.pretty_print_type(ty)
998+
.expect("could not write to `String`")
999+
.into_buffer();
1000+
if regular.len() <= length_limit {
1001+
return (regular, None);
1002+
}
1003+
let short = FmtPrinter::new_with_limit(
1004+
self,
1005+
hir::def::Namespace::TypeNS,
1006+
rustc_session::Limit(type_limit),
1007+
)
1008+
.pretty_print_type(ty)
1009+
.expect("could not write to `String`")
1010+
.into_buffer();
1011+
if regular == short {
1012+
return (regular, None);
1013+
}
1014+
// Multiple types might be shortened in a single error, ensure we create a file for each.
1015+
let mut s = DefaultHasher::new();
1016+
ty.hash(&mut s);
1017+
let hash = s.finish();
1018+
let path = self.output_filenames(()).temp_path_ext(&format!("long-type-{hash}.txt"), None);
1019+
match std::fs::write(&path, &regular) {
1020+
Ok(_) => (short, Some(path)),
1021+
Err(_) => (regular, None),
1022+
}
1023+
}
1024+
9881025
fn format_generic_args(self, args: &[ty::GenericArg<'tcx>]) -> String {
9891026
FmtPrinter::new(self, hir::def::Namespace::TypeNS)
9901027
.path_generic_args(Ok, args)

compiler/rustc_middle/src/ty/instance.rs

+37-20
Original file line numberDiff line numberDiff line change
@@ -276,28 +276,45 @@ impl<'tcx> InstanceDef<'tcx> {
276276
}
277277
}
278278

279-
impl<'tcx> fmt::Display for Instance<'tcx> {
279+
fn fmt_instance(
280+
f: &mut fmt::Formatter<'_>,
281+
instance: &Instance<'_>,
282+
type_length: rustc_session::Limit,
283+
) -> fmt::Result {
284+
ty::tls::with(|tcx| {
285+
let substs = tcx.lift(instance.substs).expect("could not lift for printing");
286+
287+
let s = FmtPrinter::new_with_limit(tcx, Namespace::ValueNS, type_length)
288+
.print_def_path(instance.def_id(), substs)?
289+
.into_buffer();
290+
f.write_str(&s)
291+
})?;
292+
293+
match instance.def {
294+
InstanceDef::Item(_) => Ok(()),
295+
InstanceDef::VTableShim(_) => write!(f, " - shim(vtable)"),
296+
InstanceDef::ReifyShim(_) => write!(f, " - shim(reify)"),
297+
InstanceDef::Intrinsic(_) => write!(f, " - intrinsic"),
298+
InstanceDef::Virtual(_, num) => write!(f, " - virtual#{}", num),
299+
InstanceDef::FnPtrShim(_, ty) => write!(f, " - shim({})", ty),
300+
InstanceDef::ClosureOnceShim { .. } => write!(f, " - shim"),
301+
InstanceDef::DropGlue(_, None) => write!(f, " - shim(None)"),
302+
InstanceDef::DropGlue(_, Some(ty)) => write!(f, " - shim(Some({}))", ty),
303+
InstanceDef::CloneShim(_, ty) => write!(f, " - shim({})", ty),
304+
}
305+
}
306+
307+
pub struct ShortInstance<'a, 'tcx>(pub &'a Instance<'tcx>, pub usize);
308+
309+
impl<'a, 'tcx> fmt::Display for ShortInstance<'a, 'tcx> {
280310
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
281-
ty::tls::with(|tcx| {
282-
let substs = tcx.lift(self.substs).expect("could not lift for printing");
283-
let s = FmtPrinter::new(tcx, Namespace::ValueNS)
284-
.print_def_path(self.def_id(), substs)?
285-
.into_buffer();
286-
f.write_str(&s)
287-
})?;
311+
fmt_instance(f, self.0, rustc_session::Limit(self.1))
312+
}
313+
}
288314

289-
match self.def {
290-
InstanceDef::Item(_) => Ok(()),
291-
InstanceDef::VTableShim(_) => write!(f, " - shim(vtable)"),
292-
InstanceDef::ReifyShim(_) => write!(f, " - shim(reify)"),
293-
InstanceDef::Intrinsic(_) => write!(f, " - intrinsic"),
294-
InstanceDef::Virtual(_, num) => write!(f, " - virtual#{}", num),
295-
InstanceDef::FnPtrShim(_, ty) => write!(f, " - shim({})", ty),
296-
InstanceDef::ClosureOnceShim { .. } => write!(f, " - shim"),
297-
InstanceDef::DropGlue(_, None) => write!(f, " - shim(None)"),
298-
InstanceDef::DropGlue(_, Some(ty)) => write!(f, " - shim(Some({}))", ty),
299-
InstanceDef::CloneShim(_, ty) => write!(f, " - shim({})", ty),
300-
}
315+
impl<'tcx> fmt::Display for Instance<'tcx> {
316+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
317+
ty::tls::with(|tcx| fmt_instance(f, self, tcx.type_length_limit()))
301318
}
302319
}
303320

compiler/rustc_middle/src/ty/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ pub use self::context::{
8484
GeneratorInteriorTypeCause, GlobalCtxt, Lift, OnDiskCache, TyCtxt, TypeckResults, UserType,
8585
UserTypeAnnotationIndex,
8686
};
87-
pub use self::instance::{Instance, InstanceDef};
87+
pub use self::instance::{Instance, InstanceDef, ShortInstance};
8888
pub use self::list::List;
8989
pub use self::parameterized::ParameterizedOverTcx;
9090
pub use self::rvalue_scopes::RvalueScopes;

0 commit comments

Comments
 (0)