Skip to content
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

Rollup of 13 pull requests #77039

Merged
merged 41 commits into from
Sep 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
c5975e9
Reduce duplicate in liballoc reserve error handling
pickfire Aug 4, 2020
28db521
More implementations of Write for immutable refs
Sep 2, 2020
ec7f9b9
Deduplicates io::Write implementations
Sep 11, 2020
8f27e3c
Make some methods of `Pin` unstable const
CDirkx Sep 12, 2020
eede953
Only get ImplKind::Impl once
tesuji Sep 10, 2020
ed6c7ef
Use enum for status of non-const ops
ecstatic-morse Sep 2, 2020
c3607bd
Use helper function for searching `allow_internal_unstable`
ecstatic-morse Sep 2, 2020
e4edc16
Give name to extra `Span` in `LiveDrop` error
ecstatic-morse Sep 2, 2020
81b3b66
Error if an unstable const eval feature is used in a stable const fn
ecstatic-morse Sep 3, 2020
1e1257b
Bless `miri-unleashed` tests
ecstatic-morse Sep 16, 2020
abc7167
Test that `const_precise_live_drops` can't be depended upon stably
ecstatic-morse Sep 16, 2020
e3c6e46
Make some methods of `Pin<&mut T>` unstable const
CDirkx Sep 18, 2020
f7d5080
don't take `TyCtxt` by reference
lcnr Sep 18, 2020
a219ad6
extend `is_ty_or_ty_ctxt` to self types
lcnr Sep 19, 2020
67f319c
take `TyCtxt` by value
lcnr Sep 19, 2020
2a00dda
miri: correctly deal with `ConstKind::Bound`
lcnr Sep 10, 2020
6734230
do not ICE on `ty::Bound` in Layout::compute
lcnr Sep 11, 2020
65b3419
update stderr file
lcnr Sep 20, 2020
c690c82
use if let instead of single match arm expressions to compact code an…
matthiaskrgr Sep 18, 2020
88a29e6
Updates stability attributes to the current nightly version
Sep 21, 2020
0acb0ed
Update library/std/src/process.rs
FedericoPonzi Sep 21, 2020
60b102d
Don't recommend ManuallyDrop to customize drop order
matklad Aug 31, 2020
b4b4a2f
Reduce boilerplate for BytePos and CharPos
Juici Sep 21, 2020
8fc782a
add test
lcnr Sep 21, 2020
9a1f177
Remove cast to usize for BytePos and CharPos
Juici Sep 21, 2020
63195ec
Add explanation for E0756
GuillaumeGomez Sep 8, 2020
f5d71a9
Don't use `zip` to compare iterators during pretty-print hack
Aaron1011 Aug 30, 2020
d452744
lint missing docs for extern items
lcnr Sep 21, 2020
11f7bfa
Rollup merge of #72734 - pickfire:liballoc, r=KodrAus
ecstatic-morse Sep 22, 2020
dc42aa8
Rollup merge of #76131 - Aaron1011:fix/pretty-print-zip, r=lcnr
ecstatic-morse Sep 22, 2020
4f3697b
Rollup merge of #76150 - matklad:droporder, r=withoutboats
ecstatic-morse Sep 22, 2020
65bdf79
Rollup merge of #76275 - FedericoPonzi:immutable-write-impl-73836, r=…
ecstatic-morse Sep 22, 2020
ef6c3a7
Rollup merge of #76489 - GuillaumeGomez:add-explanation-e0756, r=jyn514
ecstatic-morse Sep 22, 2020
30f1bab
Rollup merge of #76581 - lcnr:bound-too-generic, r=eddyb
ecstatic-morse Sep 22, 2020
537ede4
Rollup merge of #76655 - CDirkx:const-pin, r=ecstatic-morse
ecstatic-morse Sep 22, 2020
b3433c7
Rollup merge of #76783 - lzutao:rd_impl_kind, r=GuillaumeGomez
ecstatic-morse Sep 22, 2020
60b9901
Rollup merge of #76807 - ecstatic-morse:const-checking-staged-api, r=…
ecstatic-morse Sep 22, 2020
dcf4d1f
Rollup merge of #76888 - matthiaskrgr:clippy_single_match_2, r=Dylan-DPC
ecstatic-morse Sep 22, 2020
50d4aeb
Rollup merge of #76914 - lcnr:path-no-more, r=ecstatic-morse
ecstatic-morse Sep 22, 2020
359615b
Rollup merge of #77022 - Juici:master, r=lcnr
ecstatic-morse Sep 22, 2020
0863f9a
Rollup merge of #77032 - lcnr:visit-all-the-item-likes, r=davidtwco
ecstatic-morse Sep 22, 2020
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
2 changes: 1 addition & 1 deletion compiler/rustc_error_codes/src/error_codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@ E0752: include_str!("./error_codes/E0752.md"),
E0753: include_str!("./error_codes/E0753.md"),
E0754: include_str!("./error_codes/E0754.md"),
E0755: include_str!("./error_codes/E0755.md"),
E0756: include_str!("./error_codes/E0756.md"),
E0758: include_str!("./error_codes/E0758.md"),
E0759: include_str!("./error_codes/E0759.md"),
E0760: include_str!("./error_codes/E0760.md"),
Expand Down Expand Up @@ -633,7 +634,6 @@ E0774: include_str!("./error_codes/E0774.md"),
E0722, // Malformed `#[optimize]` attribute
E0726, // non-explicit (not `'_`) elided lifetime in unsupported position
// E0738, // Removed; errored on `#[track_caller] fn`s in `extern "Rust" { ... }`.
E0756, // `#[ffi_const]` is only allowed on foreign functions
E0757, // `#[ffi_const]` functions cannot be `#[ffi_pure]`
E0772, // `'static' obligation coming from `impl dyn Trait {}` or `impl Foo for dyn Bar {}`.
}
29 changes: 29 additions & 0 deletions compiler/rustc_error_codes/src/error_codes/E0756.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
The `ffi_const` attribute was used on something other than a foreign function
declaration.

Erroneous code example:

```compile_fail,E0756
#![feature(ffi_const)]

#[ffi_const] // error!
pub fn foo() {}
# fn main() {}
```

The `ffi_const` attribute can only be used on foreign function declarations
which have no side effects except for their return value:

```
#![feature(ffi_const)]

extern "C" {
#[ffi_const] // ok!
pub fn strlen(s: *const i8) -> i32;
}
# fn main() {}
```

You can get more information about it in the [unstable Rust Book].

[unstable Rust Book]: https://doc.rust-lang.org/nightly/unstable-book/language-features/ffi-const.html
Original file line number Diff line number Diff line change
Expand Up @@ -488,18 +488,16 @@ impl<'tcx> Visitor<'tcx> for HirTraitObjectVisitor {
}

fn visit_ty(&mut self, t: &'tcx hir::Ty<'tcx>) {
match t.kind {
TyKind::TraitObject(
poly_trait_refs,
Lifetime { name: LifetimeName::ImplicitObjectLifetimeDefault, .. },
) => {
for ptr in poly_trait_refs {
if Some(self.1) == ptr.trait_ref.trait_def_id() {
self.0.push(ptr.span);
}
if let TyKind::TraitObject(
poly_trait_refs,
Lifetime { name: LifetimeName::ImplicitObjectLifetimeDefault, .. },
) = t.kind
{
for ptr in poly_trait_refs {
if Some(self.1) == ptr.trait_ref.trait_def_id() {
self.0.push(ptr.span);
}
}
_ => {}
}
walk_ty(self, t);
}
Expand Down
13 changes: 13 additions & 0 deletions compiler/rustc_lint/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,19 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
);
}

fn check_foreign_item(&mut self, cx: &LateContext<'_>, foreign_item: &hir::ForeignItem<'_>) {
let def_id = cx.tcx.hir().local_def_id(foreign_item.hir_id);
let (article, desc) = cx.tcx.article_and_description(def_id.to_def_id());
self.check_missing_docs_attrs(
cx,
Some(foreign_item.hir_id),
&foreign_item.attrs,
foreign_item.span,
article,
desc,
);
}

fn check_struct_field(&mut self, cx: &LateContext<'_>, sf: &hir::StructField<'_>) {
if !sf.is_positional() {
self.check_missing_docs_attrs(
Expand Down
32 changes: 27 additions & 5 deletions compiler/rustc_lint/src/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ use crate::{EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintContext}
use rustc_ast::{Item, ItemKind};
use rustc_data_structures::fx::FxHashMap;
use rustc_errors::Applicability;
use rustc_hir::def::Res;
use rustc_hir::{GenericArg, HirId, MutTy, Mutability, Path, PathSegment, QPath, Ty, TyKind};
use rustc_middle::ty;
use rustc_session::{declare_lint_pass, declare_tool_lint, impl_lint_pass};
use rustc_span::hygiene::{ExpnKind, MacroKind};
use rustc_span::symbol::{sym, Ident, Symbol};
Expand Down Expand Up @@ -177,11 +179,31 @@ fn lint_ty_kind_usage(cx: &LateContext<'_>, segment: &PathSegment<'_>) -> bool {
fn is_ty_or_ty_ctxt(cx: &LateContext<'_>, ty: &Ty<'_>) -> Option<String> {
if let TyKind::Path(qpath) = &ty.kind {
if let QPath::Resolved(_, path) = qpath {
let did = path.res.opt_def_id()?;
if cx.tcx.is_diagnostic_item(sym::Ty, did) {
return Some(format!("Ty{}", gen_args(path.segments.last().unwrap())));
} else if cx.tcx.is_diagnostic_item(sym::TyCtxt, did) {
return Some(format!("TyCtxt{}", gen_args(path.segments.last().unwrap())));
match path.res {
Res::Def(_, did) => {
if cx.tcx.is_diagnostic_item(sym::Ty, did) {
return Some(format!("Ty{}", gen_args(path.segments.last().unwrap())));
} else if cx.tcx.is_diagnostic_item(sym::TyCtxt, did) {
return Some(format!("TyCtxt{}", gen_args(path.segments.last().unwrap())));
}
}
// Only lint on `&Ty` and `&TyCtxt` if it is used outside of a trait.
Res::SelfTy(None, Some((did, _))) => {
if let ty::Adt(adt, substs) = cx.tcx.type_of(did).kind() {
if cx.tcx.is_diagnostic_item(sym::Ty, adt.did) {
// NOTE: This path is currently unreachable as `Ty<'tcx>` is
// defined as a type alias meaning that `impl<'tcx> Ty<'tcx>`
// is not actually allowed.
//
// I(@lcnr) still kept this branch in so we don't miss this
// if we ever change it in the future.
return Some(format!("Ty<{}>", substs[0]));
} else if cx.tcx.is_diagnostic_item(sym::TyCtxt, adt.did) {
return Some(format!("TyCtxt<{}>", substs[0]));
}
}
}
_ => (),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1179,7 +1179,7 @@ impl<'tcx> TyCtxt<'tcx> {
self.mk_const(ty::Const { val: ty::ConstKind::Error(DelaySpanBugEmitted(())), ty })
}

pub fn consider_optimizing<T: Fn() -> String>(&self, msg: T) -> bool {
pub fn consider_optimizing<T: Fn() -> String>(self, msg: T) -> bool {
let cname = self.crate_name(LOCAL_CRATE).as_str();
self.sess.consider_optimizing(&cname, msg)
}
Expand Down
15 changes: 6 additions & 9 deletions compiler/rustc_middle/src/ty/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -834,14 +834,11 @@ fn foo(&self) -> Self::T { String::new() }
kind: hir::ItemKind::Impl { items, .. }, ..
})) => {
for item in &items[..] {
match item.kind {
hir::AssocItemKind::Type => {
if self.type_of(self.hir().local_def_id(item.id.hir_id)) == found {
db.span_label(item.span, "expected this associated type");
return true;
}
if let hir::AssocItemKind::Type = item.kind {
if self.type_of(self.hir().local_def_id(item.id.hir_id)) == found {
db.span_label(item.span, "expected this associated type");
return true;
}
_ => {}
}
}
}
Expand All @@ -853,7 +850,7 @@ fn foo(&self) -> Self::T { String::new() }
/// Given a slice of `hir::GenericBound`s, if any of them corresponds to the `trait_ref`
/// requirement, provide a strucuted suggestion to constrain it to a given type `ty`.
fn constrain_generic_bound_associated_type_structured_suggestion(
&self,
self,
db: &mut DiagnosticBuilder<'_>,
trait_ref: &ty::TraitRef<'tcx>,
bounds: hir::GenericBounds<'_>,
Expand All @@ -877,7 +874,7 @@ fn foo(&self) -> Self::T { String::new() }
/// Given a span corresponding to a bound, provide a structured suggestion to set an
/// associated type to a given type `ty`.
fn constrain_associated_type_structured_suggestion(
&self,
self,
db: &mut DiagnosticBuilder<'_>,
span: Span,
assoc: &ty::AssocItem,
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_middle/src/ty/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1259,11 +1259,11 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
tcx.layout_raw(param_env.and(normalized))?
}

ty::Bound(..) | ty::Placeholder(..) | ty::GeneratorWitness(..) | ty::Infer(_) => {
ty::Placeholder(..) | ty::GeneratorWitness(..) | ty::Infer(_) => {
bug!("Layout::compute: unexpected type `{}`", ty)
}

ty::Param(_) | ty::Error(_) => {
ty::Bound(..) | ty::Param(_) | ty::Error(_) => {
return Err(LayoutError::Unknown(ty));
}
})
Expand Down
9 changes: 1 addition & 8 deletions compiler/rustc_middle/src/ty/print/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2125,17 +2125,10 @@ fn for_each_def(tcx: TyCtxt<'_>, mut collect_fn: impl for<'b> FnMut(&'b Ident, N
// Iterate all local crate items no matter where they are defined.
let hir = tcx.hir();
for item in hir.krate().items.values() {
if item.ident.name.as_str().is_empty() {
if item.ident.name.as_str().is_empty() || matches!(item.kind, ItemKind::Use(_, _)) {
continue;
}

match item.kind {
ItemKind::Use(_, _) => {
continue;
}
_ => {}
}

if let Some(local_def_id) = hir.definitions().opt_hir_id_to_local_def_id(item.hir_id) {
let def_id = local_def_id.to_def_id();
let ns = tcx.def_kind(def_id).ns().unwrap_or(Namespace::TypeNS);
Expand Down
6 changes: 2 additions & 4 deletions compiler/rustc_mir/src/interpret/operand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -549,15 +549,13 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
};
// Early-return cases.
let val_val = match val.val {
ty::ConstKind::Param(_) => throw_inval!(TooGeneric),
ty::ConstKind::Param(_) | ty::ConstKind::Bound(..) => throw_inval!(TooGeneric),
ty::ConstKind::Error(_) => throw_inval!(TypeckError(ErrorReported)),
ty::ConstKind::Unevaluated(def, substs, promoted) => {
let instance = self.resolve(def, substs)?;
return Ok(self.eval_to_allocation(GlobalId { instance, promoted })?.into());
}
ty::ConstKind::Infer(..)
| ty::ConstKind::Bound(..)
| ty::ConstKind::Placeholder(..) => {
ty::ConstKind::Infer(..) | ty::ConstKind::Placeholder(..) => {
span_bug!(self.cur_span(), "const_to_op: Unexpected ConstKind {:?}", val)
}
ty::ConstKind::Value(val_val) => val_val,
Expand Down
8 changes: 8 additions & 0 deletions compiler/rustc_mir/src/transform/check_consts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
//! has interior mutability or needs to be dropped, as well as the visitor that emits errors when
//! it finds operations that are invalid in a certain context.

use rustc_attr as attr;
use rustc_hir as hir;
use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_middle::mir;
use rustc_middle::ty::{self, TyCtxt};
use rustc_span::Symbol;

pub use self::qualifs::Qualif;

Expand Down Expand Up @@ -55,3 +57,9 @@ impl ConstCx<'mir, 'tcx> {
pub fn is_lang_panic_fn(tcx: TyCtxt<'tcx>, def_id: DefId) -> bool {
Some(def_id) == tcx.lang_items().panic_fn() || Some(def_id) == tcx.lang_items().begin_panic_fn()
}

pub fn allow_internal_unstable(tcx: TyCtxt<'tcx>, def_id: DefId, feature_gate: Symbol) -> bool {
let attrs = tcx.get_attrs(def_id);
attr::allow_internal_unstable(&tcx.sess, attrs)
.map_or(false, |mut features| features.any(|name| name == feature_gate))
}
Loading