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 5 pull requests #73325

Closed
wants to merge 25 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
98eb29c
Fix trait alias inherent impl resolution
matthew-mcallister May 25, 2020
5837518
`-Zunpretty=everybody_loops` only works after expansion
ecstatic-morse Jun 7, 2020
d684855
Helper method for whether `ast::Ty` contains `impl Trait`
ecstatic-morse Jun 7, 2020
b5fdbbe
Use correct names for things in `ReplaceBodyWithLoops`
ecstatic-morse Jun 7, 2020
d8c99f3
Preserve expressions that get a `DefId`
ecstatic-morse Jun 7, 2020
1a30042
Remove unnecessary `opt_local_def_id_to_hir_id`
ecstatic-morse Jun 7, 2020
e319f20
Add `rustdoc` tests from #72088
ecstatic-morse Jun 7, 2020
c29b3fa
On recursive ADT, provide indirection structured suggestion
estebank May 29, 2020
7cde07e
review comments: only suggest one substitution
estebank May 31, 2020
03552ec
fix rebase
estebank Jun 10, 2020
c45231c
Revert heterogeneous SocketAddr PartialEq impls
dtolnay Jun 13, 2020
204c236
Add test for comparing SocketAddr with inferred right-hand side
dtolnay Jun 13, 2020
cecfa43
Move `check_op` logic to `ops` module
ecstatic-morse May 1, 2020
d73674e
Make `Qualifs` getters public
ecstatic-morse May 1, 2020
a77f046
Add feature gate for precise live drop checking
ecstatic-morse Jun 11, 2020
f5370fa
Add `CheckLiveDrops` pass
ecstatic-morse May 3, 2020
a43e486
Add MIR phase and query for drop elaboration
ecstatic-morse May 3, 2020
21ddf4d
Ensure that `drop_elaboration_and_check_consts` runs for all const items
ecstatic-morse May 3, 2020
9e2ee32
Update incorrect error code docs
ecstatic-morse May 3, 2020
2dcf7db
Add tests for `const_precise_live_drops`
ecstatic-morse Jun 11, 2020
182ac4b
Rollup merge of #71824 - ecstatic-morse:const-check-post-drop-elab, r…
Dylan-DPC Jun 13, 2020
398a645
Rollup merge of #72556 - matthew-mcallister:trait-alias-inherent-impl…
Dylan-DPC Jun 13, 2020
08b8505
Rollup merge of #72740 - estebank:recursive-indirection, r=matthewjasper
Dylan-DPC Jun 13, 2020
e4d096b
Rollup merge of #73103 - ecstatic-morse:replace-body-with-loop, r=pnk…
Dylan-DPC Jun 13, 2020
a539574
Rollup merge of #73304 - dtolnay:socketeq, r=Mark-Simulacrum
Dylan-DPC Jun 13, 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
21 changes: 21 additions & 0 deletions src/librustc_ast/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub use UnsafeSource::*;
use crate::ptr::P;
use crate::token::{self, DelimToken};
use crate::tokenstream::{DelimSpan, TokenStream, TokenTree};
use crate::visit::{walk_ty, Visitor};

use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
use rustc_data_structures::sync::Lrc;
Expand Down Expand Up @@ -1795,6 +1796,26 @@ pub struct Ty {
pub span: Span,
}

impl Ty {
/// Returns `true` if the kind of this type or any types contained within are `impl Trait`.
pub fn contains_impl_trait(&self) -> bool {
struct ContainsImplTrait(bool);

impl<'ast> Visitor<'ast> for ContainsImplTrait {
fn visit_ty(&mut self, t: &'ast Ty) {
self.0 |= matches!(t.kind, TyKind::ImplTrait(..));
if !self.0 {
walk_ty(self, t);
}
}
}

let mut vis = ContainsImplTrait(false);
vis.visit_ty(self);
vis.0
}
}

#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
pub struct BareFnTy {
pub unsafety: Unsafe,
Expand Down
12 changes: 6 additions & 6 deletions src/librustc_error_codes/error_codes/E0493.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
A type with a `Drop` implementation was destructured when trying to initialize
a static item.
A value with a custom `Drop` implementation may be dropped during const-eval.

Erroneous code example:

Expand All @@ -16,13 +15,14 @@ struct Foo {
field1: DropType,
}

static FOO: Foo = Foo { ..Foo { field1: DropType::A } }; // error!
static FOO: Foo = Foo { field1: (DropType::A, DropType::A).1 }; // error!
```

The problem here is that if the given type or one of its fields implements the
`Drop` trait, this `Drop` implementation cannot be called during the static
type initialization which might cause a memory leak. To prevent this issue,
you need to instantiate all the static type's fields by hand.
`Drop` trait, this `Drop` implementation cannot be called within a const
context since it may run arbitrary, non-const-checked code. To prevent this
issue, ensure all values with custom a custom `Drop` implementation escape the
initializer.

```
enum DropType {
Expand Down
23 changes: 23 additions & 0 deletions src/librustc_errors/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,29 @@ impl Diagnostic {
self
}

pub fn multipart_suggestions(
&mut self,
msg: &str,
suggestions: Vec<Vec<(Span, String)>>,
applicability: Applicability,
) -> &mut Self {
self.suggestions.push(CodeSuggestion {
substitutions: suggestions
.into_iter()
.map(|suggestion| Substitution {
parts: suggestion
.into_iter()
.map(|(span, snippet)| SubstitutionPart { snippet, span })
.collect(),
})
.collect(),
msg: msg.to_owned(),
style: SuggestionStyle::ShowCode,
applicability,
});
self
}

/// Prints out a message with for a multipart suggestion without showing the suggested code.
///
/// This is intended to be used for suggestions that are obvious in what the changes need to
Expand Down
13 changes: 13 additions & 0 deletions src/librustc_errors/diagnostic_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,19 @@ impl<'a> DiagnosticBuilder<'a> {
self
}

pub fn multipart_suggestions(
&mut self,
msg: &str,
suggestions: Vec<Vec<(Span, String)>>,
applicability: Applicability,
) -> &mut Self {
if !self.0.allow_suggestions {
return self;
}
self.0.diagnostic.multipart_suggestions(msg, suggestions, applicability);
self
}

pub fn tool_only_multipart_suggestion(
&mut self,
msg: &str,
Expand Down
3 changes: 3 additions & 0 deletions src/librustc_feature/active.rs
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,9 @@ declare_features! (
/// Allows `extern "avr-interrupt" fn()` and `extern "avr-non-blocking-interrupt" fn()`.
(active, abi_avr_interrupt, "1.45.0", Some(69664), None),

/// Be more precise when looking for live drops in a const context.
(active, const_precise_live_drops, "1.46.0", Some(73255), None),

// -------------------------------------------------------------------------
// feature-group-end: actual feature gates
// -------------------------------------------------------------------------
Expand Down
6 changes: 5 additions & 1 deletion src/librustc_interface/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,11 @@ fn analysis(tcx: TyCtxt<'_>, cnum: CrateNum) -> Result<()> {

sess.time("MIR_effect_checking", || {
for def_id in tcx.body_owners() {
mir::transform::check_unsafety::check_unsafety(tcx, def_id)
mir::transform::check_unsafety::check_unsafety(tcx, def_id);

if tcx.hir().body_const_context(def_id).is_some() {
tcx.ensure().mir_drops_elaborated_and_const_checked(def_id);
}
}
});

Expand Down
Loading