Skip to content

Commit

Permalink
Auto merge of rust-lang#77039 - ecstatic-morse:rollup-qv3jj4a, r=ecst…
Browse files Browse the repository at this point in the history
…atic-morse

Rollup of 13 pull requests

Successful merges:

 - rust-lang#72734 (Reduce duplicate in liballoc reserve error handling)
 - rust-lang#76131 (Don't use `zip` to compare iterators during pretty-print hack)
 - rust-lang#76150 (Don't recommend ManuallyDrop to customize drop order)
 - rust-lang#76275 (Implementation of Write for some immutable ref structs)
 - rust-lang#76489 (Add explanation for E0756)
 - rust-lang#76581 (do not ICE on bound variables, return `TooGeneric` instead)
 - rust-lang#76655 (Make some methods of `Pin` unstable const)
 - rust-lang#76783 (Only get ImplKind::Impl once)
 - rust-lang#76807 (Use const-checking to forbid use of unstable features in const-stable functions)
 - rust-lang#76888 (use if let instead of single match arm expressions)
 - rust-lang#76914 (extend `Ty` and `TyCtxt` lints to self types)
 - rust-lang#77022 (Reduce boilerplate for BytePos and CharPos)
 - rust-lang#77032 (lint missing docs for extern items)

Failed merges:

r? `@ghost`
  • Loading branch information
bors committed Sep 22, 2020
2 parents 4519845 + 0863f9a commit c2bc344
Show file tree
Hide file tree
Showing 49 changed files with 762 additions and 322 deletions.
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

0 comments on commit c2bc344

Please sign in to comment.