Skip to content

Commit 3af1bdc

Browse files
committed
Auto merge of #60510 - Centril:rollup-gsndjbp, r=Centril
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
2 parents ef9a876 + 6f7a1ea commit 3af1bdc

File tree

66 files changed

+891
-297
lines changed

Some content is hidden

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

66 files changed

+891
-297
lines changed

Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -3556,6 +3556,7 @@ dependencies = [
35563556
name = "tidy"
35573557
version = "0.1.0"
35583558
dependencies = [
3559+
"regex 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
35593560
"serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)",
35603561
"serde_derive 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)",
35613562
"serde_json 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)",

src/bootstrap/native.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ fn configure_cmake(builder: &Builder<'_>,
436436
}
437437

438438
if env::var_os("SCCACHE_ERROR_LOG").is_some() {
439-
cfg.env("RUST_LOG", "sccache=warn");
439+
cfg.env("RUSTC_LOG", "sccache=warn");
440440
}
441441
}
442442

src/librustc/error_codes.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -362,10 +362,6 @@ struct Foo1 { x: &bool }
362362
// ^ expected lifetime parameter
363363
struct Foo2<'a> { x: &'a bool } // correct
364364
365-
impl Foo2 {}
366-
// ^^^^ expected lifetime parameter
367-
impl<'a> Foo2<'a> {} // correct
368-
369365
struct Bar1 { x: Foo2 }
370366
// ^^^^ expected lifetime parameter
371367
struct Bar2<'a> { x: Foo2<'a> } // correct
@@ -2208,4 +2204,5 @@ register_diagnostics! {
22082204
E0710, // an unknown tool name found in scoped lint
22092205
E0711, // a feature has been declared with conflicting stability attributes
22102206
// E0702, // replaced with a generic attribute input check
2207+
E0726, // non-explicit (not `'_`) elided lifetime in unsupported position
22112208
}

src/librustc/hir/lowering.rs

+52-16
Original file line numberDiff line numberDiff line change
@@ -2110,15 +2110,49 @@ impl<'a> LoweringContext<'a> {
21102110
.expect("already checked that type args or bindings exist");
21112111
(false, first_generic_span.shrink_to_lo(), format!("{}, ", anon_lt_suggestion))
21122112
};
2113-
self.sess.buffer_lint_with_diagnostic(
2114-
ELIDED_LIFETIMES_IN_PATHS,
2115-
CRATE_NODE_ID,
2116-
path_span,
2117-
"hidden lifetime parameters in types are deprecated",
2118-
builtin::BuiltinLintDiagnostics::ElidedLifetimesInPaths(
2119-
expected_lifetimes, path_span, incl_angl_brckt, insertion_span, suggestion
2120-
)
2121-
);
2113+
match self.anonymous_lifetime_mode {
2114+
// In create-parameter mode we error here because we don't want to support
2115+
// deprecated impl elision in new features like impl elision and `async fn`,
2116+
// both of which work using the `CreateParameter` mode:
2117+
//
2118+
// impl Foo for std::cell::Ref<u32> // note lack of '_
2119+
// async fn foo(_: std::cell::Ref<u32>) { ... }
2120+
AnonymousLifetimeMode::CreateParameter => {
2121+
let mut err = struct_span_err!(
2122+
self.sess,
2123+
path_span,
2124+
E0726,
2125+
"implicit elided lifetime not allowed here"
2126+
);
2127+
crate::lint::builtin::add_elided_lifetime_in_path_suggestion(
2128+
&self.sess,
2129+
&mut err,
2130+
expected_lifetimes,
2131+
path_span,
2132+
incl_angl_brckt,
2133+
insertion_span,
2134+
suggestion,
2135+
);
2136+
err.emit();
2137+
}
2138+
AnonymousLifetimeMode::PassThrough |
2139+
AnonymousLifetimeMode::ReportError |
2140+
AnonymousLifetimeMode::Replace(_) => {
2141+
self.sess.buffer_lint_with_diagnostic(
2142+
ELIDED_LIFETIMES_IN_PATHS,
2143+
CRATE_NODE_ID,
2144+
path_span,
2145+
"hidden lifetime parameters in types are deprecated",
2146+
builtin::BuiltinLintDiagnostics::ElidedLifetimesInPaths(
2147+
expected_lifetimes,
2148+
path_span,
2149+
incl_angl_brckt,
2150+
insertion_span,
2151+
suggestion,
2152+
)
2153+
);
2154+
}
2155+
}
21222156
}
21232157
}
21242158

@@ -5335,13 +5369,15 @@ impl<'a> LoweringContext<'a> {
53355369

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

src/librustc/hir/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1927,6 +1927,9 @@ pub enum ArgSource {
19271927
/// Represents the header (not the body) of a function declaration.
19281928
#[derive(Clone, RustcEncodable, RustcDecodable, Debug, HashStable)]
19291929
pub struct FnDecl {
1930+
/// The types of the function's arguments.
1931+
///
1932+
/// Additional argument data is stored in the function's [body](Body::arguments).
19301933
pub inputs: HirVec<Ty>,
19311934
pub output: FunctionRetTy,
19321935
pub c_variadic: bool,

src/librustc/infer/error_reporting/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
644644
for sp in prior_arms {
645645
err.span_label(*sp, format!(
646646
"this is found to be of type `{}`",
647-
last_ty,
647+
self.resolve_type_vars_if_possible(&last_ty),
648648
));
649649
}
650650
} else if let Some(sp) = prior_arms.last() {

src/librustc/infer/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
704704
/// potentially leaving "dangling type variables" behind.
705705
/// In such cases, an assertion will fail when attempting to
706706
/// register obligations, within a snapshot. Very useful, much
707-
/// better than grovelling through megabytes of `RUST_LOG` output.
707+
/// better than grovelling through megabytes of `RUSTC_LOG` output.
708708
///
709709
/// HOWEVER, in some cases the flag is unhelpful. In particular, we
710710
/// sometimes create a "mini-fulfilment-cx" in which we enroll

src/librustc/lint/builtin.rs

+51-31
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ declare_lint! {
376376

377377
declare_lint! {
378378
pub AMBIGUOUS_ASSOCIATED_ITEMS,
379-
Warn,
379+
Deny,
380380
"ambiguous associated items"
381381
}
382382

@@ -477,6 +477,48 @@ pub enum BuiltinLintDiagnostics {
477477
RedundantImport(Vec<(Span, bool)>, ast::Ident),
478478
}
479479

480+
pub(crate) fn add_elided_lifetime_in_path_suggestion(
481+
sess: &Session,
482+
db: &mut DiagnosticBuilder<'_>,
483+
n: usize,
484+
path_span: Span,
485+
incl_angl_brckt: bool,
486+
insertion_span: Span,
487+
anon_lts: String,
488+
) {
489+
let (replace_span, suggestion) = if incl_angl_brckt {
490+
(insertion_span, anon_lts)
491+
} else {
492+
// When possible, prefer a suggestion that replaces the whole
493+
// `Path<T>` expression with `Path<'_, T>`, rather than inserting `'_, `
494+
// at a point (which makes for an ugly/confusing label)
495+
if let Ok(snippet) = sess.source_map().span_to_snippet(path_span) {
496+
// But our spans can get out of whack due to macros; if the place we think
497+
// we want to insert `'_` isn't even within the path expression's span, we
498+
// should bail out of making any suggestion rather than panicking on a
499+
// subtract-with-overflow or string-slice-out-out-bounds (!)
500+
// FIXME: can we do better?
501+
if insertion_span.lo().0 < path_span.lo().0 {
502+
return;
503+
}
504+
let insertion_index = (insertion_span.lo().0 - path_span.lo().0) as usize;
505+
if insertion_index > snippet.len() {
506+
return;
507+
}
508+
let (before, after) = snippet.split_at(insertion_index);
509+
(path_span, format!("{}{}{}", before, anon_lts, after))
510+
} else {
511+
(insertion_span, anon_lts)
512+
}
513+
};
514+
db.span_suggestion(
515+
replace_span,
516+
&format!("indicate the anonymous lifetime{}", if n >= 2 { "s" } else { "" }),
517+
suggestion,
518+
Applicability::MachineApplicable
519+
);
520+
}
521+
480522
impl BuiltinLintDiagnostics {
481523
pub fn run(self, sess: &Session, db: &mut DiagnosticBuilder<'_>) {
482524
match self {
@@ -521,36 +563,14 @@ impl BuiltinLintDiagnostics {
521563
BuiltinLintDiagnostics::ElidedLifetimesInPaths(
522564
n, path_span, incl_angl_brckt, insertion_span, anon_lts
523565
) => {
524-
let (replace_span, suggestion) = if incl_angl_brckt {
525-
(insertion_span, anon_lts)
526-
} else {
527-
// When possible, prefer a suggestion that replaces the whole
528-
// `Path<T>` expression with `Path<'_, T>`, rather than inserting `'_, `
529-
// at a point (which makes for an ugly/confusing label)
530-
if let Ok(snippet) = sess.source_map().span_to_snippet(path_span) {
531-
// But our spans can get out of whack due to macros; if the place we think
532-
// we want to insert `'_` isn't even within the path expression's span, we
533-
// should bail out of making any suggestion rather than panicking on a
534-
// subtract-with-overflow or string-slice-out-out-bounds (!)
535-
// FIXME: can we do better?
536-
if insertion_span.lo().0 < path_span.lo().0 {
537-
return;
538-
}
539-
let insertion_index = (insertion_span.lo().0 - path_span.lo().0) as usize;
540-
if insertion_index > snippet.len() {
541-
return;
542-
}
543-
let (before, after) = snippet.split_at(insertion_index);
544-
(path_span, format!("{}{}{}", before, anon_lts, after))
545-
} else {
546-
(insertion_span, anon_lts)
547-
}
548-
};
549-
db.span_suggestion(
550-
replace_span,
551-
&format!("indicate the anonymous lifetime{}", if n >= 2 { "s" } else { "" }),
552-
suggestion,
553-
Applicability::MachineApplicable
566+
add_elided_lifetime_in_path_suggestion(
567+
sess,
568+
db,
569+
n,
570+
path_span,
571+
incl_angl_brckt,
572+
insertion_span,
573+
anon_lts,
554574
);
555575
}
556576
BuiltinLintDiagnostics::UnknownCrateTypes(span, note, sugg) => {

src/librustc/lint/context.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -757,12 +757,12 @@ impl<'a, 'tcx> LateContext<'a, 'tcx> {
757757
/// Check if a `DefId`'s path matches the given absolute type path usage.
758758
///
759759
/// # Examples
760-
/// ```rust,ignore (no `cx` or `def_id` available)
760+
///
761+
/// ```rust,ignore (no context or def id available)
761762
/// if cx.match_def_path(def_id, &["core", "option", "Option"]) {
762763
/// // The given `def_id` is that of an `Option` type
763764
/// }
764765
/// ```
765-
// Uplifted from rust-lang/rust-clippy
766766
pub fn match_def_path(&self, def_id: DefId, path: &[&str]) -> bool {
767767
let names = self.get_def_path(def_id);
768768

@@ -772,13 +772,13 @@ impl<'a, 'tcx> LateContext<'a, 'tcx> {
772772
/// Gets the absolute path of `def_id` as a vector of `&str`.
773773
///
774774
/// # Examples
775-
/// ```rust,ignore (no `cx` or `def_id` available)
775+
///
776+
/// ```rust,ignore (no context or def id available)
776777
/// let def_path = cx.get_def_path(def_id);
777778
/// if let &["core", "option", "Option"] = &def_path[..] {
778779
/// // The given `def_id` is that of an `Option` type
779780
/// }
780781
/// ```
781-
// Uplifted from rust-lang/rust-clippy
782782
pub fn get_def_path(&self, def_id: DefId) -> Vec<LocalInternedString> {
783783
pub struct AbsolutePathPrinter<'a, 'tcx> {
784784
pub tcx: TyCtxt<'a, 'tcx, 'tcx>,

src/librustc_codegen_llvm/debuginfo/metadata.rs

+13-9
Original file line numberDiff line numberDiff line change
@@ -784,26 +784,30 @@ pub fn file_metadata(cx: &CodegenCx<'ll, '_>,
784784
file_name,
785785
defining_crate);
786786

787-
let directory = if defining_crate == LOCAL_CRATE {
788-
&cx.sess().working_dir.0
787+
let file_name = &file_name.to_string();
788+
let file_name_symbol = Symbol::intern(file_name);
789+
if defining_crate == LOCAL_CRATE {
790+
let directory = &cx.sess().working_dir.0.to_string_lossy();
791+
file_metadata_raw(cx, file_name, Some(file_name_symbol),
792+
directory, Some(Symbol::intern(directory)))
789793
} else {
790794
// If the path comes from an upstream crate we assume it has been made
791795
// independent of the compiler's working directory one way or another.
792-
Path::new("")
793-
};
794-
795-
file_metadata_raw(cx, &file_name.to_string(), &directory.to_string_lossy())
796+
file_metadata_raw(cx, file_name, Some(file_name_symbol), "", None)
797+
}
796798
}
797799

798800
pub fn unknown_file_metadata(cx: &CodegenCx<'ll, '_>) -> &'ll DIFile {
799-
file_metadata_raw(cx, "<unknown>", "")
801+
file_metadata_raw(cx, "<unknown>", None, "", None)
800802
}
801803

802804
fn file_metadata_raw(cx: &CodegenCx<'ll, '_>,
803805
file_name: &str,
804-
directory: &str)
806+
file_name_symbol: Option<Symbol>,
807+
directory: &str,
808+
directory_symbol: Option<Symbol>)
805809
-> &'ll DIFile {
806-
let key = (Symbol::intern(file_name), Symbol::intern(directory));
810+
let key = (file_name_symbol, directory_symbol);
807811

808812
if let Some(file_metadata) = debug_context(cx).created_files.borrow().get(&key) {
809813
return *file_metadata;

src/librustc_codegen_llvm/debuginfo/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ pub struct CrateDebugContext<'a, 'tcx> {
6363
llcontext: &'a llvm::Context,
6464
llmod: &'a llvm::Module,
6565
builder: &'a mut DIBuilder<'a>,
66-
created_files: RefCell<FxHashMap<(Symbol, Symbol), &'a DIFile>>,
66+
created_files: RefCell<FxHashMap<(Option<Symbol>, Option<Symbol>), &'a DIFile>>,
6767
created_enum_disr_types: RefCell<FxHashMap<(DefId, layout::Primitive), &'a DIType>>,
6868

6969
type_map: RefCell<TypeMap<'a, 'tcx>>,

src/librustc_driver/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1163,7 +1163,7 @@ pub fn report_ices_to_stderr_if_any<F: FnOnce() -> R, R>(f: F) -> Result<R, Erro
11631163
/// This allows tools to enable rust logging without having to magically match rustc's
11641164
/// log crate version
11651165
pub fn init_rustc_env_logger() {
1166-
env_logger::init();
1166+
env_logger::init_from_env("RUSTC_LOG");
11671167
}
11681168

11691169
pub fn main() {

0 commit comments

Comments
 (0)