Skip to content

Commit

Permalink
Auto merge of #60510 - Centril:rollup-gsndjbp, r=Centril
Browse files Browse the repository at this point in the history
Rollup of 12 pull requests

Successful merges:

 - #59928 (Make deprecation lint `ambiguous_associated_items` deny-by-default)
 - #60220 (report fatal errors during doctest parsing)
 - #60373 (Tidy: ensure lang features are sorted by since)
 - #60388 (Disallow non-explicit elided lifetimes in async fn)
 - #60393 ( Do not suggest incorrect syntax on pattern type error due to borrow)
 - #60401 (Rename `RUST_LOG` to `RUSTC_LOG`)
 - #60409 (Require a trait in the bounds of existential types)
 - #60455 (Resolve match arm ty when arms diverge)
 - #60457 (Const prop refactoring)
 - #60467 (Avoid repeated interning of static strings.)
 - #60478 (minor compiler doc tweaks)
 - #60501 (Propagate mutability from arguments to local bindings in async fn)

Failed merges:

r? @ghost
  • Loading branch information
bors committed May 3, 2019
2 parents ef9a876 + 6f7a1ea commit 3af1bdc
Show file tree
Hide file tree
Showing 66 changed files with 891 additions and 297 deletions.
1 change: 1 addition & 0 deletions Cargo.lock
Expand Up @@ -3556,6 +3556,7 @@ dependencies = [
name = "tidy"
version = "0.1.0"
dependencies = [
"regex 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)",
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/native.rs
Expand Up @@ -436,7 +436,7 @@ fn configure_cmake(builder: &Builder<'_>,
}

if env::var_os("SCCACHE_ERROR_LOG").is_some() {
cfg.env("RUST_LOG", "sccache=warn");
cfg.env("RUSTC_LOG", "sccache=warn");
}
}

Expand Down
5 changes: 1 addition & 4 deletions src/librustc/error_codes.rs
Expand Up @@ -362,10 +362,6 @@ struct Foo1 { x: &bool }
// ^ expected lifetime parameter
struct Foo2<'a> { x: &'a bool } // correct
impl Foo2 {}
// ^^^^ expected lifetime parameter
impl<'a> Foo2<'a> {} // correct
struct Bar1 { x: Foo2 }
// ^^^^ expected lifetime parameter
struct Bar2<'a> { x: Foo2<'a> } // correct
Expand Down Expand Up @@ -2208,4 +2204,5 @@ register_diagnostics! {
E0710, // an unknown tool name found in scoped lint
E0711, // a feature has been declared with conflicting stability attributes
// E0702, // replaced with a generic attribute input check
E0726, // non-explicit (not `'_`) elided lifetime in unsupported position
}
68 changes: 52 additions & 16 deletions src/librustc/hir/lowering.rs
Expand Up @@ -2110,15 +2110,49 @@ impl<'a> LoweringContext<'a> {
.expect("already checked that type args or bindings exist");
(false, first_generic_span.shrink_to_lo(), format!("{}, ", anon_lt_suggestion))
};
self.sess.buffer_lint_with_diagnostic(
ELIDED_LIFETIMES_IN_PATHS,
CRATE_NODE_ID,
path_span,
"hidden lifetime parameters in types are deprecated",
builtin::BuiltinLintDiagnostics::ElidedLifetimesInPaths(
expected_lifetimes, path_span, incl_angl_brckt, insertion_span, suggestion
)
);
match self.anonymous_lifetime_mode {
// In create-parameter mode we error here because we don't want to support
// deprecated impl elision in new features like impl elision and `async fn`,
// both of which work using the `CreateParameter` mode:
//
// impl Foo for std::cell::Ref<u32> // note lack of '_
// async fn foo(_: std::cell::Ref<u32>) { ... }
AnonymousLifetimeMode::CreateParameter => {
let mut err = struct_span_err!(
self.sess,
path_span,
E0726,
"implicit elided lifetime not allowed here"
);
crate::lint::builtin::add_elided_lifetime_in_path_suggestion(
&self.sess,
&mut err,
expected_lifetimes,
path_span,
incl_angl_brckt,
insertion_span,
suggestion,
);
err.emit();
}
AnonymousLifetimeMode::PassThrough |
AnonymousLifetimeMode::ReportError |
AnonymousLifetimeMode::Replace(_) => {
self.sess.buffer_lint_with_diagnostic(
ELIDED_LIFETIMES_IN_PATHS,
CRATE_NODE_ID,
path_span,
"hidden lifetime parameters in types are deprecated",
builtin::BuiltinLintDiagnostics::ElidedLifetimesInPaths(
expected_lifetimes,
path_span,
incl_angl_brckt,
insertion_span,
suggestion,
)
);
}
}
}
}

Expand Down Expand Up @@ -5335,13 +5369,15 @@ impl<'a> LoweringContext<'a> {

fn elided_path_lifetime(&mut self, span: Span) -> hir::Lifetime {
match self.anonymous_lifetime_mode {
// N.B., We intentionally ignore the create-parameter mode here
// and instead "pass through" to resolve-lifetimes, which will then
// report an error. This is because we don't want to support
// impl elision for deprecated forms like
//
// impl Foo for std::cell::Ref<u32> // note lack of '_
AnonymousLifetimeMode::CreateParameter |
AnonymousLifetimeMode::CreateParameter => {
// We should have emitted E0726 when processing this path above
self.sess.delay_span_bug(
span,
"expected 'implicit elided lifetime not allowed' error",
);
let id = self.sess.next_node_id();
self.new_named_lifetime(id, span, hir::LifetimeName::Error)
}
// This is the normal case.
AnonymousLifetimeMode::PassThrough => self.new_implicit_lifetime(span),

Expand Down
3 changes: 3 additions & 0 deletions src/librustc/hir/mod.rs
Expand Up @@ -1927,6 +1927,9 @@ pub enum ArgSource {
/// Represents the header (not the body) of a function declaration.
#[derive(Clone, RustcEncodable, RustcDecodable, Debug, HashStable)]
pub struct FnDecl {
/// The types of the function's arguments.
///
/// Additional argument data is stored in the function's [body](Body::arguments).
pub inputs: HirVec<Ty>,
pub output: FunctionRetTy,
pub c_variadic: bool,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/infer/error_reporting/mod.rs
Expand Up @@ -644,7 +644,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
for sp in prior_arms {
err.span_label(*sp, format!(
"this is found to be of type `{}`",
last_ty,
self.resolve_type_vars_if_possible(&last_ty),
));
}
} else if let Some(sp) = prior_arms.last() {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/infer/mod.rs
Expand Up @@ -704,7 +704,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
/// potentially leaving "dangling type variables" behind.
/// In such cases, an assertion will fail when attempting to
/// register obligations, within a snapshot. Very useful, much
/// better than grovelling through megabytes of `RUST_LOG` output.
/// better than grovelling through megabytes of `RUSTC_LOG` output.
///
/// HOWEVER, in some cases the flag is unhelpful. In particular, we
/// sometimes create a "mini-fulfilment-cx" in which we enroll
Expand Down
82 changes: 51 additions & 31 deletions src/librustc/lint/builtin.rs
Expand Up @@ -376,7 +376,7 @@ declare_lint! {

declare_lint! {
pub AMBIGUOUS_ASSOCIATED_ITEMS,
Warn,
Deny,
"ambiguous associated items"
}

Expand Down Expand Up @@ -477,6 +477,48 @@ pub enum BuiltinLintDiagnostics {
RedundantImport(Vec<(Span, bool)>, ast::Ident),
}

pub(crate) fn add_elided_lifetime_in_path_suggestion(
sess: &Session,
db: &mut DiagnosticBuilder<'_>,
n: usize,
path_span: Span,
incl_angl_brckt: bool,
insertion_span: Span,
anon_lts: String,
) {
let (replace_span, suggestion) = if incl_angl_brckt {
(insertion_span, anon_lts)
} else {
// When possible, prefer a suggestion that replaces the whole
// `Path<T>` expression with `Path<'_, T>`, rather than inserting `'_, `
// at a point (which makes for an ugly/confusing label)
if let Ok(snippet) = sess.source_map().span_to_snippet(path_span) {
// But our spans can get out of whack due to macros; if the place we think
// we want to insert `'_` isn't even within the path expression's span, we
// should bail out of making any suggestion rather than panicking on a
// subtract-with-overflow or string-slice-out-out-bounds (!)
// FIXME: can we do better?
if insertion_span.lo().0 < path_span.lo().0 {
return;
}
let insertion_index = (insertion_span.lo().0 - path_span.lo().0) as usize;
if insertion_index > snippet.len() {
return;
}
let (before, after) = snippet.split_at(insertion_index);
(path_span, format!("{}{}{}", before, anon_lts, after))
} else {
(insertion_span, anon_lts)
}
};
db.span_suggestion(
replace_span,
&format!("indicate the anonymous lifetime{}", if n >= 2 { "s" } else { "" }),
suggestion,
Applicability::MachineApplicable
);
}

impl BuiltinLintDiagnostics {
pub fn run(self, sess: &Session, db: &mut DiagnosticBuilder<'_>) {
match self {
Expand Down Expand Up @@ -521,36 +563,14 @@ impl BuiltinLintDiagnostics {
BuiltinLintDiagnostics::ElidedLifetimesInPaths(
n, path_span, incl_angl_brckt, insertion_span, anon_lts
) => {
let (replace_span, suggestion) = if incl_angl_brckt {
(insertion_span, anon_lts)
} else {
// When possible, prefer a suggestion that replaces the whole
// `Path<T>` expression with `Path<'_, T>`, rather than inserting `'_, `
// at a point (which makes for an ugly/confusing label)
if let Ok(snippet) = sess.source_map().span_to_snippet(path_span) {
// But our spans can get out of whack due to macros; if the place we think
// we want to insert `'_` isn't even within the path expression's span, we
// should bail out of making any suggestion rather than panicking on a
// subtract-with-overflow or string-slice-out-out-bounds (!)
// FIXME: can we do better?
if insertion_span.lo().0 < path_span.lo().0 {
return;
}
let insertion_index = (insertion_span.lo().0 - path_span.lo().0) as usize;
if insertion_index > snippet.len() {
return;
}
let (before, after) = snippet.split_at(insertion_index);
(path_span, format!("{}{}{}", before, anon_lts, after))
} else {
(insertion_span, anon_lts)
}
};
db.span_suggestion(
replace_span,
&format!("indicate the anonymous lifetime{}", if n >= 2 { "s" } else { "" }),
suggestion,
Applicability::MachineApplicable
add_elided_lifetime_in_path_suggestion(
sess,
db,
n,
path_span,
incl_angl_brckt,
insertion_span,
anon_lts,
);
}
BuiltinLintDiagnostics::UnknownCrateTypes(span, note, sugg) => {
Expand Down
8 changes: 4 additions & 4 deletions src/librustc/lint/context.rs
Expand Up @@ -757,12 +757,12 @@ impl<'a, 'tcx> LateContext<'a, 'tcx> {
/// Check if a `DefId`'s path matches the given absolute type path usage.
///
/// # Examples
/// ```rust,ignore (no `cx` or `def_id` available)
///
/// ```rust,ignore (no context or def id available)
/// if cx.match_def_path(def_id, &["core", "option", "Option"]) {
/// // The given `def_id` is that of an `Option` type
/// }
/// ```
// Uplifted from rust-lang/rust-clippy
pub fn match_def_path(&self, def_id: DefId, path: &[&str]) -> bool {
let names = self.get_def_path(def_id);

Expand All @@ -772,13 +772,13 @@ impl<'a, 'tcx> LateContext<'a, 'tcx> {
/// Gets the absolute path of `def_id` as a vector of `&str`.
///
/// # Examples
/// ```rust,ignore (no `cx` or `def_id` available)
///
/// ```rust,ignore (no context or def id available)
/// let def_path = cx.get_def_path(def_id);
/// if let &["core", "option", "Option"] = &def_path[..] {
/// // The given `def_id` is that of an `Option` type
/// }
/// ```
// Uplifted from rust-lang/rust-clippy
pub fn get_def_path(&self, def_id: DefId) -> Vec<LocalInternedString> {
pub struct AbsolutePathPrinter<'a, 'tcx> {
pub tcx: TyCtxt<'a, 'tcx, 'tcx>,
Expand Down
22 changes: 13 additions & 9 deletions src/librustc_codegen_llvm/debuginfo/metadata.rs
Expand Up @@ -784,26 +784,30 @@ pub fn file_metadata(cx: &CodegenCx<'ll, '_>,
file_name,
defining_crate);

let directory = if defining_crate == LOCAL_CRATE {
&cx.sess().working_dir.0
let file_name = &file_name.to_string();
let file_name_symbol = Symbol::intern(file_name);
if defining_crate == LOCAL_CRATE {
let directory = &cx.sess().working_dir.0.to_string_lossy();
file_metadata_raw(cx, file_name, Some(file_name_symbol),
directory, Some(Symbol::intern(directory)))
} else {
// If the path comes from an upstream crate we assume it has been made
// independent of the compiler's working directory one way or another.
Path::new("")
};

file_metadata_raw(cx, &file_name.to_string(), &directory.to_string_lossy())
file_metadata_raw(cx, file_name, Some(file_name_symbol), "", None)
}
}

pub fn unknown_file_metadata(cx: &CodegenCx<'ll, '_>) -> &'ll DIFile {
file_metadata_raw(cx, "<unknown>", "")
file_metadata_raw(cx, "<unknown>", None, "", None)
}

fn file_metadata_raw(cx: &CodegenCx<'ll, '_>,
file_name: &str,
directory: &str)
file_name_symbol: Option<Symbol>,
directory: &str,
directory_symbol: Option<Symbol>)
-> &'ll DIFile {
let key = (Symbol::intern(file_name), Symbol::intern(directory));
let key = (file_name_symbol, directory_symbol);

if let Some(file_metadata) = debug_context(cx).created_files.borrow().get(&key) {
return *file_metadata;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/debuginfo/mod.rs
Expand Up @@ -63,7 +63,7 @@ pub struct CrateDebugContext<'a, 'tcx> {
llcontext: &'a llvm::Context,
llmod: &'a llvm::Module,
builder: &'a mut DIBuilder<'a>,
created_files: RefCell<FxHashMap<(Symbol, Symbol), &'a DIFile>>,
created_files: RefCell<FxHashMap<(Option<Symbol>, Option<Symbol>), &'a DIFile>>,
created_enum_disr_types: RefCell<FxHashMap<(DefId, layout::Primitive), &'a DIType>>,

type_map: RefCell<TypeMap<'a, 'tcx>>,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_driver/lib.rs
Expand Up @@ -1163,7 +1163,7 @@ pub fn report_ices_to_stderr_if_any<F: FnOnce() -> R, R>(f: F) -> Result<R, Erro
/// This allows tools to enable rust logging without having to magically match rustc's
/// log crate version
pub fn init_rustc_env_logger() {
env_logger::init();
env_logger::init_from_env("RUSTC_LOG");
}

pub fn main() {
Expand Down

0 comments on commit 3af1bdc

Please sign in to comment.