Skip to content

Commit

Permalink
Auto merge of rust-lang#104607 - matthiaskrgr:rollup-9s589me, r=matth…
Browse files Browse the repository at this point in the history
…iaskrgr

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
  • Loading branch information
bors committed Nov 19, 2022
2 parents 62c627c + f69f4cb commit 2a43428
Show file tree
Hide file tree
Showing 64 changed files with 488 additions and 226 deletions.
21 changes: 14 additions & 7 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ dependencies = [
"glob",
"hex 0.4.2",
"home",
"http-auth",
"humantime 2.0.1",
"ignore",
"im-rc",
Expand Down Expand Up @@ -349,11 +350,11 @@ dependencies = [

[[package]]
name = "cargo-credential"
version = "0.1.0"
version = "0.2.0"

[[package]]
name = "cargo-credential-1password"
version = "0.1.0"
version = "0.2.0"
dependencies = [
"cargo-credential",
"serde",
Expand All @@ -362,15 +363,15 @@ dependencies = [

[[package]]
name = "cargo-credential-macos-keychain"
version = "0.1.0"
version = "0.2.0"
dependencies = [
"cargo-credential",
"security-framework",
]

[[package]]
name = "cargo-credential-wincred"
version = "0.1.0"
version = "0.2.0"
dependencies = [
"cargo-credential",
"winapi",
Expand Down Expand Up @@ -1692,6 +1693,15 @@ dependencies = [
"syn",
]

[[package]]
name = "http-auth"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c0b40b39d66c28829a0cf4d09f7e139ff8201f7500a5083732848ed3b4b4d850"
dependencies = [
"memchr",
]

[[package]]
name = "humantime"
version = "1.3.0"
Expand Down Expand Up @@ -3535,7 +3545,6 @@ name = "rustc_errors"
version = "0.0.0"
dependencies = [
"annotate-snippets",
"atty",
"rustc_ast",
"rustc_ast_pretty",
"rustc_data_structures",
Expand Down Expand Up @@ -3834,7 +3843,6 @@ dependencies = [
name = "rustc_log"
version = "0.0.0"
dependencies = [
"atty",
"rustc_span",
"tracing",
"tracing-subscriber",
Expand Down Expand Up @@ -4389,7 +4397,6 @@ version = "0.0.0"
dependencies = [
"arrayvec",
"askama",
"atty",
"expect-test",
"itertools",
"minifier",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl<'mir, 'tcx> ConstCx<'mir, 'tcx> {
}

fn is_async(&self) -> bool {
self.tcx.asyncness(self.def_id()) == hir::IsAsync::Async
self.tcx.asyncness(self.def_id()).is_async()
}
}

Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
//! This API is completely unstable and subject to change.
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
#![feature(is_terminal)]
#![feature(once_cell)]
#![feature(decl_macro)]
#![recursion_limit = "256"]
Expand All @@ -27,7 +28,6 @@ use rustc_feature::find_gated_cfg;
use rustc_interface::util::{self, collect_crate_types, get_codegen_backend};
use rustc_interface::{interface, Queries};
use rustc_lint::LintStore;
use rustc_log::stdout_isatty;
use rustc_metadata::locator;
use rustc_save_analysis as save;
use rustc_save_analysis::DumpHandler;
Expand All @@ -48,7 +48,7 @@ use std::default::Default;
use std::env;
use std::ffi::OsString;
use std::fs;
use std::io::{self, Read, Write};
use std::io::{self, IsTerminal, Read, Write};
use std::panic::{self, catch_unwind};
use std::path::PathBuf;
use std::process::{self, Command, Stdio};
Expand Down Expand Up @@ -515,7 +515,7 @@ fn handle_explain(registry: Registry, code: &str, output: ErrorOutputType) {
}
text.push('\n');
}
if stdout_isatty() {
if io::stdout().is_terminal() {
show_content_with_pager(&text);
} else {
print!("{}", text);
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_errors/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ rustc_target = { path = "../rustc_target" }
rustc_hir = { path = "../rustc_hir" }
rustc_lint_defs = { path = "../rustc_lint_defs" }
unicode-width = "0.1.4"
atty = "0.2"
termcolor = "1.0"
annotate-snippets = "0.9"
termize = "0.1.1"
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_errors/src/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ use rustc_error_messages::FluentArgs;
use rustc_span::hygiene::{ExpnKind, MacroKind};
use std::borrow::Cow;
use std::cmp::{max, min, Reverse};
use std::io;
use std::io::prelude::*;
use std::io::{self, IsTerminal};
use std::iter;
use std::path::Path;
use termcolor::{Ansi, BufferWriter, ColorChoice, ColorSpec, StandardStream};
Expand Down Expand Up @@ -619,14 +619,14 @@ impl ColorConfig {
fn to_color_choice(self) -> ColorChoice {
match self {
ColorConfig::Always => {
if atty::is(atty::Stream::Stderr) {
if io::stderr().is_terminal() {
ColorChoice::Always
} else {
ColorChoice::AlwaysAnsi
}
}
ColorConfig::Never => ColorChoice::Never,
ColorConfig::Auto if atty::is(atty::Stream::Stderr) => ColorChoice::Auto,
ColorConfig::Auto if io::stderr().is_terminal() => ColorChoice::Auto,
ColorConfig::Auto => ColorChoice::Never,
}
}
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_errors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
#![feature(drain_filter)]
#![feature(if_let_guard)]
#![feature(is_terminal)]
#![feature(adt_const_params)]
#![feature(let_chains)]
#![feature(never_type)]
Expand Down
6 changes: 6 additions & 0 deletions compiler/rustc_hir/src/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2720,6 +2720,12 @@ pub enum IsAsync {
NotAsync,
}

impl IsAsync {
pub fn is_async(self) -> bool {
self == IsAsync::Async
}
}

#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, Encodable, Decodable, HashStable_Generic)]
pub enum Defaultness {
Default { has_value: bool },
Expand Down
4 changes: 1 addition & 3 deletions compiler/rustc_hir_analysis/src/check/compare_method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -684,9 +684,7 @@ fn report_trait_method_mismatch<'tcx>(
// Suggestion to change output type. We do not suggest in `async` functions
// to avoid complex logic or incorrect output.
match tcx.hir().expect_impl_item(impl_m.def_id.expect_local()).kind {
ImplItemKind::Fn(ref sig, _)
if sig.header.asyncness == hir::IsAsync::NotAsync =>
{
ImplItemKind::Fn(ref sig, _) if !sig.header.asyncness.is_async() => {
let msg = "change the output type to match the trait";
let ap = Applicability::MachineApplicable;
match sig.decl.output {
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_hir_typeck/src/method/suggest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1918,12 +1918,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
| ty::Str
| ty::Projection(_)
| ty::Param(_) => format!("{deref_ty}"),
// we need to test something like <&[_]>::len
// we need to test something like <&[_]>::len or <(&[u32])>::len
// and Vec::function();
// <&[_]>::len doesn't need an extra "<>" between
// <&[_]>::len or <&[u32]>::len doesn't need an extra "<>" between
// but for Adt type like Vec::function()
// we would suggest <[_]>::function();
_ if self.tcx.sess.source_map().span_wrapped_by_angle_bracket(ty.span) => format!("{deref_ty}"),
_ if self.tcx.sess.source_map().span_wrapped_by_angle_or_parentheses(ty.span) => format!("{deref_ty}"),
_ => format!("<{deref_ty}>"),
};
err.span_suggestion_verbose(
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_log/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ version = "0.0.0"
edition = "2021"

[dependencies]
atty = "0.2"
tracing = "0.1.28"
tracing-subscriber = { version = "0.3.3", default-features = false, features = ["fmt", "env-filter", "smallvec", "parking_lot", "ansi"] }
tracing-tree = "0.2.0"
Expand Down
7 changes: 4 additions & 3 deletions compiler/rustc_log/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@
#![deny(rustc::untranslatable_diagnostic)]
#![deny(rustc::diagnostic_outside_of_impl)]
#![feature(is_terminal)]

use std::env::{self, VarError};
use std::fmt::{self, Display};
use std::io;
use std::io::{self, IsTerminal};
use tracing_subscriber::filter::{Directive, EnvFilter, LevelFilter};
use tracing_subscriber::layer::SubscriberExt;

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

pub fn stdout_isatty() -> bool {
atty::is(atty::Stream::Stdout)
io::stdout().is_terminal()
}

pub fn stderr_isatty() -> bool {
atty::is(atty::Stream::Stderr)
io::stderr().is_terminal()
}

#[derive(Debug)]
Expand Down
10 changes: 8 additions & 2 deletions compiler/rustc_middle/src/traits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -924,10 +924,13 @@ impl ObjectSafetyViolation {
}
ObjectSafetyViolation::Method(
name,
MethodViolationCode::ReferencesImplTraitInTrait,
MethodViolationCode::ReferencesImplTraitInTrait(_),
_,
) => format!("method `{}` references an `impl Trait` type in its return type", name)
.into(),
ObjectSafetyViolation::Method(name, MethodViolationCode::AsyncFn, _) => {
format!("method `{}` is `async`", name).into()
}
ObjectSafetyViolation::Method(
name,
MethodViolationCode::WhereClauseReferencesSelf,
Expand Down Expand Up @@ -1035,7 +1038,10 @@ pub enum MethodViolationCode {
ReferencesSelfOutput,

/// e.g., `fn foo(&self) -> impl Sized`
ReferencesImplTraitInTrait,
ReferencesImplTraitInTrait(Span),

/// e.g., `async fn foo(&self)`
AsyncFn,

/// e.g., `fn foo(&self) where Self: Clone`
WhereClauseReferencesSelf,
Expand Down
37 changes: 37 additions & 0 deletions compiler/rustc_middle/src/ty/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ use rustc_span::{BytePos, Span};
use rustc_target::spec::abi;

use std::borrow::Cow;
use std::collections::hash_map::DefaultHasher;
use std::fmt;
use std::hash::{Hash, Hasher};
use std::path::PathBuf;

use super::print::PrettyPrinter;

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

pub fn short_ty_string(self, ty: Ty<'tcx>) -> (String, Option<PathBuf>) {
let length_limit = 50;
let type_limit = 4;
let regular = FmtPrinter::new(self, hir::def::Namespace::TypeNS)
.pretty_print_type(ty)
.expect("could not write to `String`")
.into_buffer();
if regular.len() <= length_limit {
return (regular, None);
}
let short = FmtPrinter::new_with_limit(
self,
hir::def::Namespace::TypeNS,
rustc_session::Limit(type_limit),
)
.pretty_print_type(ty)
.expect("could not write to `String`")
.into_buffer();
if regular == short {
return (regular, None);
}
// Multiple types might be shortened in a single error, ensure we create a file for each.
let mut s = DefaultHasher::new();
ty.hash(&mut s);
let hash = s.finish();
let path = self.output_filenames(()).temp_path_ext(&format!("long-type-{hash}.txt"), None);
match std::fs::write(&path, &regular) {
Ok(_) => (short, Some(path)),
Err(_) => (regular, None),
}
}

fn format_generic_args(self, args: &[ty::GenericArg<'tcx>]) -> String {
FmtPrinter::new(self, hir::def::Namespace::TypeNS)
.path_generic_args(Ok, args)
Expand Down
57 changes: 37 additions & 20 deletions compiler/rustc_middle/src/ty/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,28 +276,45 @@ impl<'tcx> InstanceDef<'tcx> {
}
}

impl<'tcx> fmt::Display for Instance<'tcx> {
fn fmt_instance(
f: &mut fmt::Formatter<'_>,
instance: &Instance<'_>,
type_length: rustc_session::Limit,
) -> fmt::Result {
ty::tls::with(|tcx| {
let substs = tcx.lift(instance.substs).expect("could not lift for printing");

let s = FmtPrinter::new_with_limit(tcx, Namespace::ValueNS, type_length)
.print_def_path(instance.def_id(), substs)?
.into_buffer();
f.write_str(&s)
})?;

match instance.def {
InstanceDef::Item(_) => Ok(()),
InstanceDef::VTableShim(_) => write!(f, " - shim(vtable)"),
InstanceDef::ReifyShim(_) => write!(f, " - shim(reify)"),
InstanceDef::Intrinsic(_) => write!(f, " - intrinsic"),
InstanceDef::Virtual(_, num) => write!(f, " - virtual#{}", num),
InstanceDef::FnPtrShim(_, ty) => write!(f, " - shim({})", ty),
InstanceDef::ClosureOnceShim { .. } => write!(f, " - shim"),
InstanceDef::DropGlue(_, None) => write!(f, " - shim(None)"),
InstanceDef::DropGlue(_, Some(ty)) => write!(f, " - shim(Some({}))", ty),
InstanceDef::CloneShim(_, ty) => write!(f, " - shim({})", ty),
}
}

pub struct ShortInstance<'a, 'tcx>(pub &'a Instance<'tcx>, pub usize);

impl<'a, 'tcx> fmt::Display for ShortInstance<'a, 'tcx> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
ty::tls::with(|tcx| {
let substs = tcx.lift(self.substs).expect("could not lift for printing");
let s = FmtPrinter::new(tcx, Namespace::ValueNS)
.print_def_path(self.def_id(), substs)?
.into_buffer();
f.write_str(&s)
})?;
fmt_instance(f, self.0, rustc_session::Limit(self.1))
}
}

match self.def {
InstanceDef::Item(_) => Ok(()),
InstanceDef::VTableShim(_) => write!(f, " - shim(vtable)"),
InstanceDef::ReifyShim(_) => write!(f, " - shim(reify)"),
InstanceDef::Intrinsic(_) => write!(f, " - intrinsic"),
InstanceDef::Virtual(_, num) => write!(f, " - virtual#{}", num),
InstanceDef::FnPtrShim(_, ty) => write!(f, " - shim({})", ty),
InstanceDef::ClosureOnceShim { .. } => write!(f, " - shim"),
InstanceDef::DropGlue(_, None) => write!(f, " - shim(None)"),
InstanceDef::DropGlue(_, Some(ty)) => write!(f, " - shim(Some({}))", ty),
InstanceDef::CloneShim(_, ty) => write!(f, " - shim({})", ty),
}
impl<'tcx> fmt::Display for Instance<'tcx> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
ty::tls::with(|tcx| fmt_instance(f, self, tcx.type_length_limit()))
}
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ pub use self::context::{
GeneratorInteriorTypeCause, GlobalCtxt, Lift, OnDiskCache, TyCtxt, TypeckResults, UserType,
UserTypeAnnotationIndex,
};
pub use self::instance::{Instance, InstanceDef};
pub use self::instance::{Instance, InstanceDef, ShortInstance};
pub use self::list::List;
pub use self::parameterized::ParameterizedOverTcx;
pub use self::rvalue_scopes::RvalueScopes;
Expand Down
Loading

0 comments on commit 2a43428

Please sign in to comment.