8000 Rollup of 8 pull requests by Centril · Pull Request #65915 · rust-lang/rust · GitHub
[go: up one dir, main page]

Skip to content

Rollup of 8 pull requests #65915

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 46 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
893ab67
Custom lifetime error for `impl` item doesn't conform to `trait`
estebank Oct 3, 2019
3e2bc19
review comments
estebank Oct 4, 2019
1e95b5c
Point at the trait item and tweak wording
estebank Oct 15, 2019
e383b7c
Make error apply only to impl/trait mismatch
estebank Oct 15, 2019
3aba2d0
Fix NLL test
estebank Oct 15, 2019
093ec70
Add new EFIAPI ABI
roblabla Oct 24, 2019
6173280
Fix EFIABI test
roblabla Oct 25, 2019
13d27af
Fix inverted check in EFIAPI
roblabla Oct 25, 2019
e54ae51
Add proper tracking issue for EFIAPI
roblabla Oct 25, 2019
174d4f9
EFIAPI: Fix symbolname tests
roblabla Oct 25, 2019
7f3c843
Refactor check_attr
varkor Oct 11, 2019
94c4dd9
Emit warning for ignored #[inline] on trait method prototypes
varkor Oct 11, 2019
66d7ef0
Emit warning for ignored #[inline] on foreign function prototypes
varkor Oct 11, 2019
af2b497
Improve comments
varkor Oct 11, 2019
4552c8f
Add test for attribute error checking on trait and f 8000 oreign items
varkor Oct 11, 2019
41ee9ea
Refactor `check_track_caller`
varkor Oct 11, 2019
8042206
Handle `ImplItem` in `check_attr`
varkor Oct 13, 2019
b925eb5
Update bitflags
varkor Oct 13, 2019
e8566fb
Move handling of `#[track_caller]` to `check_attr`
varkor Oct 14, 2019
6446f19
Permit `#[target_feature]` on method implementations
varkor Oct 14, 2019
f8db8ff
Permit #[track_caller] on inherent methods
varkor Oct 24, 2019
f47f530
Make inline associated constants a future compatibility warning
varkor Oct 25, 2019
23b3827
ci: add support for MIPS64 musl targets
xen0n Jul 28, 2019
1099826
Only run efiapi test on llvm 9.0+
roblabla Oct 26, 2019
22586d7
Better pretty printing for const raw pointers
iwikal Oct 27, 2019
6a6ed12
Add the two missing hex digits
iwikal Oct 27, 2019
adfe9a4
Call out the types that are non local on E0117
estebank Oct 11, 2019
9b4f811
Use more targeted spans for orphan rule errors
estebank Oct 12, 2019
56aa89c
Further tweak spans for better readability
estebank Oct 12, 2019
daeafd8
Talk about specific types and remove lifetimes from output
estebank Oct 13, 2019
db1bfbd
Account for tuples in explanation
estebank Oct 13, 2019
95364df
Do not display ADT type arguments and fix rebase
estebank Oct 24, 2019
2cd28c1
add comment
estebank Oct 27, 2019
627691f
Fix rebase
estebank Oct 28, 2019
273ee61
Improve the "try using a variant of the expected type" hint.
Patryk27 Oct 18, 2019
e188e2d
Fix a previously forgotten pretty-printing test after a change to the…
Patryk27 Oct 26, 2019
5c023d6
Improve pretty-printing for compound qualified paths.
Patryk27 Oct 27, 2019
d7f99da
Update backtrace to 0.3.40
tmandry Oct 17, 2019
1437592
Rollup merge of #65068 - estebank:trait-impl-lt-mismatch, r=nikomatsakis
Centril Oct 29, 2019
137a6ab
Rollup merge of #65294 - varkor:lint-inline-prototype, r=matthewjasper
Centril Oct 29, 2019
14a9a50
Rollup merge of #65318 - estebank:coherence, r=varkor
Centril Oct 29, 2019
0ae035b
Rollup merge of #65531 - tmandry:bump-backtrace, r=cramertj
Centril Oct 29, 2019
fb73c0b
Rollup merge of #65562 - Patryk27:master, r=estebank
Centril Oct 29, 2019
c5d8681
Rollup merge of #65809 - roblabla:eficall-abi, r=nagisa
Centril Oct 29, 2019
cb5f9e2
Rollup merge of #65843 - xen0n:mips64-musl-targets-with-ci, r=alexcri…
Centril Oct 29, 2019
8a6462f
Rollup merge of #65859 - iwikal:pretty-const-pointers, r=cramertj
Centril Oct 29, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Permit #[track_caller] on inherent methods
  • Loading branch information
varkor committed Oct 25, 2019
commit f8db8ffcf32199dd534768ed30233724dab1fc08
44 changes: 32 additions & 12 deletions src/librustc/hir/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ use std::fmt::{self, Display};
use syntax::{attr, symbol::sym};
use syntax_pos::Span;

#[derive(Copy, Clone, PartialEq)]
pub(crate) enum MethodKind {
Trait { body: bool },
Inherent,
}

#[derive(Copy, Clone, PartialEq)]
pub(crate) enum Target {
ExternCrate,
Expand All @@ -38,7 +44,7 @@ pub(crate) enum Target {
Expression,
Statement,
AssocConst,
Method { body: bool },
Method(MethodKind),
AssocTy,
ForeignFn,
ForeignStatic,
Expand Down Expand Up @@ -68,7 +74,7 @@ impl Display for Target {
Target::Expression => "expression",
Target::Statement => "statement",
Target::AssocConst => "associated const",
Target::Method { .. } => "method",
Target::Method(_) => "method",
Target::AssocTy => "associated type",
Target::ForeignFn => "foreign function",
Target::ForeignStatic => "foreign static item",
Expand Down Expand Up @@ -103,10 +109,10 @@ impl Target {
match trait_item.kind {
TraitItemKind::Const(..) => Target::AssocConst,
TraitItemKind::Method(_, hir::TraitMethod::Required(_)) => {
Target::Method { body: false }
Target::Method(MethodKind::Trait { body: false })
}
TraitItemKind::Method(_, hir::TraitMethod::Provided(_)) => {
Target::Method { body: true }
Target::Method(MethodKind::Trait { body: true })
}
TraitItemKind::Type(..) => Target::AssocTy,
}
Expand All @@ -120,10 +126,22 @@ impl Target {
}
}

fn from_impl_item(impl_item: &hir::ImplItem) -> Target {
fn from_impl_item<'tcx>(tcx: TyCtxt<'tcx>, impl_item: &hir::ImplItem) -> Target {
match impl_item.kind {
hir::ImplItemKind::Const(..) => Target::Const,
hir::ImplItemKind::Method(..) => Target::Method { body: true },
hir::ImplItemKind::Method(..) => {
let parent_hir_id = tcx.hir().get_parent_item(impl_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 {
Target::Method(MethodKind::Trait { body: true })
} else {
Target::Method(MethodKind::Inherent)
}
}
hir::ImplItemKind::TyAlias(..) => Target::TyAlias,
hir::ImplItemKind::OpaqueTy(..) => Target::OpaqueTy,
}
Expand Down Expand Up @@ -176,8 +194,9 @@ impl CheckAttrVisitor<'tcx> {
/// Checks if an `#[inline]` is applied to a function or a closure. Returns `true` if valid.
fn check_inline(&self, hir_id: HirId, attr: &Attribute, span: &Span, target: Target) -> bool {
match target {
Target::Fn | Target::Closure | Target::Method { body: true } => true,
Target::Method { body: false } | Target::ForeignFn => {
Target::Fn | Target::Closure | Target::Method(MethodKind::Trait { body: true })
| Target::Method(MethodKind::Inherent) => true,
Target::Method(MethodKind::Trait { body: false }) | Target::ForeignFn => {
self.tcx.struct_span_lint_hir(
UNUSED_ATTRIBUTES,
hir_id,
Expand Down Expand Up @@ -216,8 +235,8 @@ impl CheckAttrVisitor<'tcx> {
).emit();
false
}
Target::Fn => true,
Target::Method { .. } => {
Target::Fn | Target::Method(MethodKind::Inherent) => true,
Target::Method(_) => {
struct_span_err!(
self.tcx.sess,
*attr_span,
Expand Down Expand Up @@ -278,7 +297,8 @@ impl CheckAttrVisitor<'tcx> {
/// Checks if the `#[target_feature]` attribute on `item` is valid. Returns `true` if valid.
fn check_target_feature(&self, attr: &Attribute, span: &Span, target: Target) -> bool {
match target {
Target::Fn | Target::Method { body: true } => true,
Target::Fn | Target::Method(MethodKind::Trait { body: true })
| Target::Method(MethodKind::Inherent) => true,
_ => {
self.tcx.sess
.struct_span_err(attr.span, "attribute should be applied to a function")
Expand Down Expand Up @@ -471,7 +491,7 @@ impl Visitor<'tcx> for CheckAttrVisitor<'tcx> {
}

fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem) {
let target = Target::from_impl_item(impl_item);
let target = Target::from_impl_item(self.tcx, impl_item);
self.check_attributes(impl_item.hir_id, &impl_item.attrs, &impl_item.span, target, None);
intravisit::walk_impl_item(self, impl_item)
}
Expand Down
9 changes: 9 additions & 0 deletions src/test/ui/rfc-2091-track-caller/error-with-trait-fn-impl.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// check-fail

#![feature(track_caller)] //~ WARN the feature `track_caller` is incomplete

trait Trait {
Expand All @@ -9,4 +11,11 @@ impl Trait for u64 {
fn unwrap(&self) {}
}

struct S;

impl S {
#[track_caller] // ok
fn foo() {}
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
warning: the feature `track_caller` is incomplete and may cause the compiler to crash
--> $DIR/error-with-trait-fn-impl.rs:1:12
--> $DIR/error-with-trait-fn-impl.rs:3:12
|
LL | #![feature(track_caller)]
| ^^^^^^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default

error[E0738]: `#[track_caller]` may not be used on trait methods
--> $DIR/error-with-trait-fn-impl.rs:8:5
--> $DIR/error-with-trait-fn-impl.rs:10:5
|
LL | #[track_caller]
| ^^^^^^^^^^^^^^^
Expand Down
0