Skip to content

Commit

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

Successful merges:

 - #64656 (Implement (HashMap) Entry::insert as per #60142)
 - #65037 (`#[track_caller]` feature gate (RFC 2091 1/N))
 - #65166 (Suggest to add `move` keyword for generator capture)
 - #65175 (add more info in debug traces for gcu merging)

Failed merges:

r? @ghost
  • Loading branch information
bors committed Oct 9, 2019
2 parents b5bd31e + e27f029 commit 275cf4b
Show file tree
Hide file tree
Showing 37 changed files with 542 additions and 10 deletions.
21 changes: 18 additions & 3 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ dependencies = [
"winapi 0.3.6",
]

[[package]]
name = "autocfg"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b671c8fb71b457dd4ae18c4ba1e59aa81793daacc361d82fcd410cef0d491875"

[[package]]
name = "backtrace"
version = "0.3.37"
Expand Down Expand Up @@ -1269,7 +1275,7 @@ version = "2.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "df044dd42cdb7e32f28557b661406fc0f2494be75199779998810dbc35030e0d"
dependencies = [
"hashbrown",
"hashbrown 0.5.0",
"lazy_static 1.3.0",
"log",
"pest",
Expand All @@ -1286,10 +1292,19 @@ version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e1de41fb8dba9714efd92241565cdff73f78508c95697dd56787d3cba27e2353"
dependencies = [
"serde",
]

[[package]]
name = "hashbrown"
version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6587d09be37fb98a11cb08b9000a3f592451c1b1b613ca69d949160e313a430a"
dependencies = [
"autocfg",
"compiler_builtins",
"rustc-std-workspace-alloc",
"rustc-std-workspace-core",
"serde",
]

[[package]]
Expand Down Expand Up @@ -4109,7 +4124,7 @@ dependencies = [
"core",
"dlmalloc",
"fortanix-sgx-abi",
"hashbrown",
"hashbrown 0.6.1",
"libc",
"panic_abort",
"panic_unwind",
Expand Down
5 changes: 5 additions & 0 deletions src/doc/unstable-book/src/language-features/track-caller.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# `track_caller`

The tracking issue for this feature is: [#47809](https://github.com/rust-lang/rust/issues/47809).

------------------------
20 changes: 20 additions & 0 deletions src/librustc/error_codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2120,6 +2120,25 @@ These attributes are meant to only be used by the standard library and are
rejected in your own crates.
"##,

E0736: r##"
#[track_caller] and #[naked] cannot be applied to the same function.
Erroneous code example:
```compile_fail,E0736
#![feature(track_caller)]
#[naked]
#[track_caller]
fn foo() {}
```
This is primarily due to ABI incompatibilities between the two attributes.
See [RFC 2091] for details on this and other limitations.
[RFC 2091]: https://github.com/rust-lang/rfcs/blob/master/text/2091-inline-semantic.md
"##,

;
// E0006, // merged with E0005
// E0101, // replaced with E0282
Expand Down Expand Up @@ -2179,4 +2198,5 @@ rejected in your own crates.
E0726, // non-explicit (not `'_`) elided lifetime in unsupported position
E0727, // `async` generators are not yet supported
E0728, // `await` must be in an `async` function or block
E0739, // invalid track_caller application/syntax
}
30 changes: 29 additions & 1 deletion src/librustc/hir/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::ty::TyCtxt;
use crate::ty::query::Providers;

use std::fmt::{self, Display};
use syntax::symbol::sym;
use syntax::{attr, symbol::sym};
use syntax_pos::Span;

#[derive(Copy, Clone, PartialEq)]
Expand Down Expand Up @@ -103,6 +103,8 @@ impl CheckAttrVisitor<'tcx> {
self.check_marker(attr, item, target)
} else if attr.check_name(sym::target_feature) {
self.check_target_feature(attr, item, target)
} else if attr.check_name(sym::track_caller) {
self.check_track_caller(attr, &item, target)
} else {
true
};
Expand Down Expand Up @@ -135,6 +137,32 @@ impl CheckAttrVisitor<'tcx> {
}
}

/// Checks if a `#[track_caller]` is applied to a non-naked function. Returns `true` if valid.
fn check_track_caller(&self, attr: &hir::Attribute, item: &hir::Item, target: Target) -> bool {
if target != Target::Fn {
struct_span_err!(
self.tcx.sess,
attr.span,
E0739,
"attribute should be applied to function"
)
.span_label(item.span, "not a function")
.emit();
false
} else if attr::contains_name(&item.attrs, sym::naked) {
struct_span_err!(
self.tcx.sess,
attr.span,
E0736,
"cannot use `#[track_caller]` with `#[naked]`",
)
.emit();
false
} else {
true
}
}

/// Checks if the `#[non_exhaustive]` attribute on an `item` is valid. Returns `true` if valid.
fn check_non_exhaustive(
&self,
Expand Down
4 changes: 3 additions & 1 deletion src/librustc/hir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2734,7 +2734,9 @@ bitflags! {
const USED = 1 << 9;
/// #[ffi_returns_twice], indicates that an extern function can return
/// multiple times
const FFI_RETURNS_TWICE = 1 << 10;
const FFI_RETURNS_TWICE = 1 << 10;
/// #[track_caller]: allow access to the caller location
const TRACK_CALLER = 1 << 11;
}
}

Expand Down
26 changes: 26 additions & 0 deletions src/librustc_mir/borrow_check/conflict_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,11 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
let kind_place = kind.filter(|_| place_desc.is_some()).map(|k| (k, place_span.0));
let explanation = self.explain_why_borrow_contains_point(location, &borrow, kind_place);

debug!(
"report_borrowed_value_does_not_live_long_enough(place_desc: {:?}, explanation: {:?})",
place_desc,
explanation
);
let err = match (place_desc, explanation) {
(Some(_), _) if self.is_place_thread_local(root_place) => {
self.report_thread_local_value_does_not_live_long_enough(drop_span, borrow_span)
Expand Down Expand Up @@ -790,6 +795,24 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
span,
&format!("`{}`", name),
),
(
Some(ref name),
BorrowExplanation::MustBeValidFor {
category: category @ ConstraintCategory::OpaqueType,
from_closure: false,
ref region_name,
span,
..
},

) if borrow_spans.for_generator() => self.report_escaping_closure_capture(
borrow_spans.args_or_use(),
borrow_span,
region_name,
category,
span,
&format!("`{}`", name),
),
(
ref name,
BorrowExplanation::MustBeValidFor {
Expand Down Expand Up @@ -1214,6 +1237,9 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
ConstraintCategory::Return => {
err.span_note(constraint_span, "closure is returned here");
}
ConstraintCategory::OpaqueType => {
err.span_note(constraint_span, "generator is returned here");
}
ConstraintCategory::CallArgument => {
fr_name.highlight_region_name(&mut err);
err.span_note(
Expand Down
3 changes: 2 additions & 1 deletion src/librustc_mir/borrow_check/nll/explain_borrow/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use syntax_pos::Span;

mod find_use;

#[derive(Debug)]
pub(in crate::borrow_check) enum BorrowExplanation {
UsedLater(LaterUseKind, Span),
UsedLaterInLoop(LaterUseKind, Span),
Expand All @@ -35,7 +36,7 @@ pub(in crate::borrow_check) enum BorrowExplanation {
Unexplained,
}

#[derive(Clone, Copy)]
#[derive(Clone, Copy, Debug)]
pub(in crate::borrow_check) enum LaterUseKind {
TraitCapture,
ClosureCapture,
Expand Down
10 changes: 7 additions & 3 deletions src/librustc_mir/monomorphize/partitioning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,9 @@ fn merge_codegen_units<'tcx>(
for (k, v) in smallest.items_mut().drain() {
second_smallest.items_mut().insert(k, v);
}
debug!("CodegenUnit {} merged in to CodegenUnit {}",
smallest.name(),
second_smallest.name());
}

let cgu_name_builder = &mut CodegenUnitNameBuilder::new(tcx);
Expand Down Expand Up @@ -774,18 +777,19 @@ where
if cfg!(debug_assertions) {
debug!("{}", label);
for cgu in cgus {
debug!("CodegenUnit {}:", cgu.name());
debug!("CodegenUnit {} estimated size {} :", cgu.name(), cgu.size_estimate());

for (mono_item, linkage) in cgu.items() {
let symbol_name = mono_item.symbol_name(tcx).name.as_str();
let symbol_hash_start = symbol_name.rfind('h');
let symbol_hash = symbol_hash_start.map(|i| &symbol_name[i ..])
.unwrap_or("<no hash>");

debug!(" - {} [{:?}] [{}]",
debug!(" - {} [{:?}] [{}] estimated size {}",
mono_item.to_string(tcx, true),
linkage,
symbol_hash);
symbol_hash,
mono_item.size_estimate(tcx));
}

debug!("");
Expand Down
36 changes: 36 additions & 0 deletions src/librustc_typeck/check/wfcheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,18 @@ pub fn check_trait_item(tcx: TyCtxt<'_>, def_id: DefId) {
_ => None
};
check_associated_item(tcx, trait_item.hir_id, trait_item.span, method_sig);

// Prohibits applying `#[track_caller]` to trait decls
for attr in &trait_item.attrs {
if attr.check_name(sym::track_caller) {
struct_span_err!(
tcx.sess,
attr.span,
E0738,
"`#[track_caller]` is not supported in trait declarations."
).emit();
}
}
}

pub fn check_impl_item(tcx: TyCtxt<'_>, def_id: DefId) {
Expand All @@ -182,6 +194,30 @@ pub fn check_impl_item(tcx: TyCtxt<'_>, def_id: DefId) {
hir::ImplItemKind::Method(ref sig, _) => Some(sig),
_ => None
};

// Prohibits applying `#[track_caller]` to trait impls
if method_sig.is_some() {
let track_caller_attr = impl_item.attrs.iter()
.find(|a| a.check_name(sym::track_caller));
if let Some(tc_attr) = track_caller_attr {
let parent_hir_id = tcx.hir().get_parent_item(hir_id);
let containing_item = tcx.hir().expect_item(parent_hir_id);
let containing_impl_is_for_trait = match &containing_item.kind {
hir::ItemKind::Impl(_, _, _, _, tr, _, _) => tr.is_some(),
_ => bug!("parent of an ImplItem must be an Impl"),
};

if containing_impl_is_for_trait {
struct_span_err!(
tcx.sess,
tc_attr.span,
E0738,
"`#[track_caller]` is not supported in traits yet."
).emit();
}
}
}

check_associated_item(tcx, impl_item.hir_id, impl_item.span, method_sig);
}

Expand Down
10 changes: 10 additions & 0 deletions src/librustc_typeck/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2594,6 +2594,16 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs {
codegen_fn_attrs.flags |= CodegenFnAttrFlags::USED;
} else if attr.check_name(sym::thread_local) {
codegen_fn_attrs.flags |= CodegenFnAttrFlags::THREAD_LOCAL;
} else if attr.check_name(sym::track_caller) {
if tcx.fn_sig(id).abi() != abi::Abi::Rust {
struct_span_err!(
tcx.sess,
attr.span,
E0737,
"rust ABI is required to use `#[track_caller]`"
).emit();
}
codegen_fn_attrs.flags |= CodegenFnAttrFlags::TRACK_CALLER;
} else if attr.check_name(sym::export_name) {
if let Some(s) = attr.value_str() {
if s.as_str().contains("\0") {
Expand Down
69 changes: 69 additions & 0 deletions src/librustc_typeck/error_codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4905,6 +4905,75 @@ fn foo_recursive(n: usize) -> Pin<Box<dyn Future<Output = ()>>> {
The `Box<...>` ensures that the result is of known size,
and the pin is required to keep it in the same place in memory.
"##,

E0737: r##"
#[track_caller] requires functions to have the "Rust" ABI for implicitly
receiving caller location. See [RFC 2091] for details on this and other
restrictions.
Erroneous code example:
```compile_fail,E0737
#![feature(track_caller)]
#[track_caller]
extern "C" fn foo() {}
```
[RFC 2091]: https://github.com/rust-lang/rfcs/blob/master/text/2091-inline-semantic.md
"##,

E0738: r##"
#[track_caller] cannot be used in traits yet. This is due to limitations in the
compiler which are likely to be temporary. See [RFC 2091] for details on this
and other restrictions.
Erroneous example with a trait method implementation:
```compile_fail,E0738
#![feature(track_caller)]
trait Foo {
fn bar(&self);
}
impl Foo for u64 {
#[track_caller]
fn bar(&self) {}
}
```
Erroneous example with a blanket trait method implementation:
```compile_fail,E0738
#![feature(track_caller)]
trait Foo {
#[track_caller]
fn bar(&self) {}
fn baz(&self);
}
```
Erroneous example with a trait method declaration:
```compile_fail,E0738
#![feature(track_caller)]
trait Foo {
fn bar(&self) {}
#[track_caller]
fn baz(&self);
}
```
Note that while the compiler may be able to support the attribute in traits in
the future, [RFC 2091] prohibits their implementation without a follow-up RFC.
[RFC 2091]: https://github.com/rust-lang/rfcs/blob/master/text/2091-inline-semantic.md
"##,

;
// E0035, merged into E0087/E0089
// E0036, merged into E0087/E0089
Expand Down
Loading

0 comments on commit 275cf4b

Please sign in to comment.