Skip to content

Commit

Permalink
Auto merge of rust-lang#86080 - GuillaumeGomez:rollup-vb5g14e, r=Guil…
Browse files Browse the repository at this point in the history
…laumeGomez

Rollup of 8 pull requests

Successful merges:

 - rust-lang#83433 (Pass --cfg=bootstrap for proc macros built by stage0)
 - rust-lang#84940 (Don't run sanity checks for `x.py setup`)
 - rust-lang#85912 (Use `Iterator::any` and `filter_map` instead of open-coding them)
 - rust-lang#85965 (Remove dead code from `LocalAnalyzer`)
 - rust-lang#86010 (Fix two ICEs in the parser)
 - rust-lang#86040 (Fix display for search results)
 - rust-lang#86058 (Remove `_`  from E0121 diagnostic suggestions)
 - rust-lang#86077 (Fix corrected example in E0759.md)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Jun 7, 2021
2 parents 35fff69 + 487200b commit 69e2f23
Show file tree
Hide file tree
Showing 24 changed files with 232 additions and 121 deletions.
50 changes: 4 additions & 46 deletions compiler/rustc_codegen_ssa/src/mir/analyze.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ use rustc_data_structures::graph::dominators::Dominators;
use rustc_index::bit_set::BitSet;
use rustc_index::vec::{Idx, IndexVec};
use rustc_middle::mir::traversal;
use rustc_middle::mir::visit::{
MutatingUseContext, NonMutatingUseContext, NonUseContext, PlaceContext, Visitor,
};
use rustc_middle::mir::visit::{MutatingUseContext, NonMutatingUseContext, PlaceContext, Visitor};
use rustc_middle::mir::{self, Location, TerminatorKind};
use rustc_middle::ty::layout::HasTyCtxt;
use rustc_target::abi::LayoutOf;
Expand All @@ -20,7 +18,9 @@ pub fn non_ssa_locals<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
let mir = fx.mir;
let mut analyzer = LocalAnalyzer::new(fx);

analyzer.visit_body(&mir);
for (bb, data) in mir.basic_blocks().iter_enumerated() {
analyzer.visit_basic_block_data(bb, data);
}

for (local, decl) in mir.local_decls.iter_enumerated() {
let ty = fx.monomorphize(decl.ty);
Expand Down Expand Up @@ -141,36 +141,7 @@ impl<Bx: BuilderMethods<'a, 'tcx>> LocalAnalyzer<'mir, 'a, 'tcx, Bx> {

if let mir::ProjectionElem::Deref = elem {
// Deref projections typically only read the pointer.
// (the exception being `VarDebugInfo` contexts, handled below)
base_context = PlaceContext::NonMutatingUse(NonMutatingUseContext::Copy);

// Indirect debuginfo requires going through memory, that only
// the debugger accesses, following our emitted DWARF pointer ops.
//
// FIXME(eddyb) Investigate the possibility of relaxing this, but
// note that `llvm.dbg.declare` *must* be used for indirect places,
// even if we start using `llvm.dbg.value` for all other cases,
// as we don't necessarily know when the value changes, but only
// where it lives in memory.
//
// It's possible `llvm.dbg.declare` could support starting from
// a pointer that doesn't point to an `alloca`, but this would
// only be useful if we know the pointer being `Deref`'d comes
// from an immutable place, and if `llvm.dbg.declare` calls
// must be at the very start of the function, then only function
// arguments could contain such pointers.
if context == PlaceContext::NonUse(NonUseContext::VarDebugInfo) {
// We use `NonUseContext::VarDebugInfo` for the base,
// which might not force the base local to memory,
// so we have to do it manually.
self.visit_local(&place_ref.local, context, location);
}
}

// `NonUseContext::VarDebugInfo` needs to flow all the
// way down to the base local (see `visit_local`).
if context == PlaceContext::NonUse(NonUseContext::VarDebugInfo) {
base_context = context;
}

self.process_place(&place_base, base_context, location);
Expand All @@ -185,20 +156,7 @@ impl<Bx: BuilderMethods<'a, 'tcx>> LocalAnalyzer<'mir, 'a, 'tcx, Bx> {
);
}
} else {
// FIXME this is super_place code, is repeated here to avoid cloning place or changing
// visit_place API
let mut context = context;

if !place_ref.projection.is_empty() {
context = if context.is_mutating_use() {
PlaceContext::MutatingUse(MutatingUseContext::Projection)
} else {
PlaceContext::NonMutatingUse(NonMutatingUseContext::Projection)
};
}

self.visit_local(&place_ref.local, context, location);
self.visit_projection(*place_ref, context, location);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_error_codes/src/error_codes/E0759.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ fn bar(x: &i32) -> Box<dyn Debug> { // error!

Add `'static` requirement to fix them:

```compile_fail,E0759
```
# use std::fmt::Debug;
fn foo(x: &i32) -> impl Debug + 'static { // ok!
fn foo(x: &'static i32) -> impl Debug + 'static { // ok!
x
}
fn bar(x: &i32) -> Box<dyn Debug + 'static> { // ok!
fn bar(x: &'static i32) -> Box<dyn Debug + 'static> { // ok!
Box::new(x)
}
```
Expand Down
13 changes: 4 additions & 9 deletions compiler/rustc_lint/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -711,15 +711,10 @@ fn ty_is_known_nonnull<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>, mode: CItemKi
return false;
}

for variant in &def.variants {
if let Some(field) = transparent_newtype_field(cx.tcx, variant) {
if ty_is_known_nonnull(cx, field.ty(tcx, substs), mode) {
return true;
}
}
}

false
def.variants
.iter()
.filter_map(|variant| transparent_newtype_field(cx.tcx, variant))
.any(|field| ty_is_known_nonnull(cx, field.ty(tcx, substs), mode))
}
_ => false,
}
Expand Down
84 changes: 47 additions & 37 deletions compiler/rustc_parse/src/parser/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,49 +352,59 @@ impl<'a> Parser<'a> {
debug!("parse_generic_args_with_leading_angle_bracket_recovery: (snapshotting)");
match self.parse_angle_args() {
Ok(args) => Ok(args),
Err(ref mut e) if is_first_invocation && self.unmatched_angle_bracket_count > 0 => {
// Cancel error from being unable to find `>`. We know the error
// must have been this due to a non-zero unmatched angle bracket
// count.
e.cancel();

Err(mut e) if is_first_invocation && self.unmatched_angle_bracket_count > 0 => {
// Swap `self` with our backup of the parser state before attempting to parse
// generic arguments.
let snapshot = mem::replace(self, snapshot.unwrap());

debug!(
"parse_generic_args_with_leading_angle_bracket_recovery: (snapshot failure) \
snapshot.count={:?}",
snapshot.unmatched_angle_bracket_count,
);

// Eat the unmatched angle brackets.
for _ in 0..snapshot.unmatched_angle_bracket_count {
self.eat_lt();
}

// Make a span over ${unmatched angle bracket count} characters.
let span = lo.with_hi(lo.lo() + BytePos(snapshot.unmatched_angle_bracket_count));
self.struct_span_err(
span,
&format!(
"unmatched angle bracket{}",
pluralize!(snapshot.unmatched_angle_bracket_count)
),
)
.span_suggestion(
span,
&format!(
"remove extra angle bracket{}",
pluralize!(snapshot.unmatched_angle_bracket_count)
),
String::new(),
Applicability::MachineApplicable,
)
.emit();
let all_angle_brackets = (0..snapshot.unmatched_angle_bracket_count)
.fold(true, |a, _| a && self.eat_lt());

if !all_angle_brackets {
// If there are other tokens in between the extraneous `<`s, we cannot simply
// suggest to remove them. This check also prevents us from accidentally ending
// up in the middle of a multibyte character (issue #84104).
let _ = mem::replace(self, snapshot);
Err(e)
} else {
// Cancel error from being unable to find `>`. We know the error
// must have been this due to a non-zero unmatched angle bracket
// count.
e.cancel();

debug!(
"parse_generic_args_with_leading_angle_bracket_recovery: (snapshot failure) \
snapshot.count={:?}",
snapshot.unmatched_angle_bracket_count,
);

// Make a span over ${unmatched angle bracket count} characters.
// This is safe because `all_angle_brackets` ensures that there are only `<`s,
// i.e. no multibyte characters, in this range.
let span =
lo.with_hi(lo.lo() + BytePos(snapshot.unmatched_angle_bracket_count));
self.struct_span_err(
span,
&format!(
"unmatched angle bracket{}",
pluralize!(snapshot.unmatched_angle_bracket_count)
),
)
.span_suggestion(
span,
&format!(
"remove extra angle bracket{}",
pluralize!(snapshot.unmatched_angle_bracket_count)
),
String::new(),
Applicability::MachineApplicable,
)
.emit();

// Try again without unmatched angle bracket characters.
self.parse_angle_args()
// Try again without unmatched angle bracket characters.
self.parse_angle_args()
}
}
Err(e) => Err(e),
}
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_parse/src/parser/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,6 @@ impl<'a> Parser<'a> {
mut bounds: GenericBounds,
plus: bool,
) -> PResult<'a, TyKind> {
assert_ne!(self.token, token::Question);
if plus {
self.eat_plus(); // `+`, or `+=` gets split and `+` is discarded
bounds.append(&mut self.parse_generic_bounds(Some(self.prev_token.span))?);
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_typeck/src/collect/type_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ fn infer_placeholder_type(
if !ty.references_error() {
diag.span_suggestion(
span,
"replace `_` with the correct type",
"replace with the correct type",
ty.to_string(),
Applicability::MaybeIncorrect,
);
Expand Down
7 changes: 7 additions & 0 deletions src/bootstrap/bin/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,13 @@ fn main() {
cmd.arg("-C").arg("target-feature=-crt-static");
}
}

if stage == "0" {
// Cargo doesn't pass RUSTFLAGS to proc_macros:
// https://github.com/rust-lang/cargo/issues/4423
// Set `--cfg=bootstrap` explicitly instead.
cmd.arg("--cfg=bootstrap");
}
}

if let Ok(map) = env::var("RUSTC_DEBUGINFO_MAP") {
Expand Down
9 changes: 7 additions & 2 deletions src/bootstrap/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,8 +444,13 @@ impl Build {

build.verbose("finding compilers");
cc_detect::find(&mut build);
build.verbose("running sanity check");
sanity::check(&mut build);
// When running `setup`, the profile is about to change, so any requirements we have now may
// be different on the next invocation. Don't check for them until the next time x.py is
// run. This is ok because `setup` never runs any build commands, so it won't fail if commands are missing.
if !matches!(build.config.cmd, Subcommand::Setup { .. }) {
build.verbose("running sanity check");
sanity::check(&mut build);
}

// If local-rust is the same major.minor as the current version, then force a
// local-rebuild
Expand Down
2 changes: 2 additions & 0 deletions src/librustdoc/html/static/rustdoc.css
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,8 @@ a {

.search-results .result-name > span {
display: inline-block;
margin: 0;
font-weight: normal;
}

body.blur > :not(#help) {
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/error-codes/E0121.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ LL | static BAR: _ = "test";
| ^
| |
| not allowed in type signatures
| help: replace `_` with the correct type: `&str`
| help: replace with the correct type: `&str`

error: aborting due to 2 previous errors

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ LL | const A = "A".$fn();
| ^
| |
| not allowed in type signatures
| help: replace `_` with the correct type: `bool`
| help: replace with the correct type: `bool`
...
LL | / suite! {
LL | | len;
Expand Down
3 changes: 3 additions & 0 deletions src/test/ui/parser/issue-84104.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// error-pattern: this file contains an unclosed delimiter
// error-pattern: expected one of
#[i=i::<ښܖ<
16 changes: 16 additions & 0 deletions src/test/ui/parser/issue-84104.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
error: this file contains an unclosed delimiter
--> $DIR/issue-84104.rs:3:13
|
LL | #[i=i::<ښܖ<
| - ^
| |
| unclosed delimiter

error: expected one of `>`, a const expression, lifetime, or type, found `]`
--> $DIR/issue-84104.rs:3:13
|
LL | #[i=i::<ښܖ<
| ^ expected one of `>`, a const expression, lifetime, or type

error: aborting due to 2 previous errors

4 changes: 4 additions & 0 deletions src/test/ui/parser/issue-84148-1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
fn f(t:for<>t?)
//~^ ERROR: expected parameter name
//~| ERROR: expected one of
//~| ERROR: expected one of
23 changes: 23 additions & 0 deletions src/test/ui/parser/issue-84148-1.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
error: expected parameter name, found `?`
--> $DIR/issue-84148-1.rs:1:14
|
LL | fn f(t:for<>t?)
| ^ expected parameter name

error: expected one of `(`, `)`, `+`, `,`, `::`, or `<`, found `?`
--> $DIR/issue-84148-1.rs:1:14
|
LL | fn f(t:for<>t?)
| ^
| |
| expected one of `(`, `)`, `+`, `,`, `::`, or `<`
| help: missing `,`

error: expected one of `->`, `;`, `where`, or `{`, found `<eof>`
--> $DIR/issue-84148-1.rs:1:15
|
LL | fn f(t:for<>t?)
| ^ expected one of `->`, `;`, `where`, or `{`

error: aborting due to 3 previous errors

4 changes: 4 additions & 0 deletions src/test/ui/parser/issue-84148-2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// error-pattern: this file contains an unclosed delimiter
// error-pattern: expected parameter name
// error-pattern: expected one of
fn f(t:for<>t?
31 changes: 31 additions & 0 deletions src/test/ui/parser/issue-84148-2.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
error: this file contains an unclosed delimiter
--> $DIR/issue-84148-2.rs:4:16
|
LL | fn f(t:for<>t?
| - ^
| |
| unclosed delimiter

error: expected parameter name, found `?`
--> $DIR/issue-84148-2.rs:4:14
|
LL | fn f(t:for<>t?
| ^ expected parameter name

error: expected one of `(`, `)`, `+`, `,`, `::`, or `<`, found `?`
--> $DIR/issue-84148-2.rs:4:14
|
LL | fn f(t:for<>t?
| ^
| |
| expected one of `(`, `)`, `+`, `,`, `::`, or `<`
| help: missing `,`

error: expected one of `->`, `;`, `where`, or `{`, found `<eof>`
--> $DIR/issue-84148-2.rs:4:16
|
LL | fn f(t:for<>t?
| ^ expected one of `->`, `;`, `where`, or `{`

error: aborting due to 4 previous errors

9 changes: 9 additions & 0 deletions src/test/ui/parser/unmatched-langle-1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Check that a suggestion is issued if there are too many `<`s in a
// generic argument list, and that the parser recovers properly.

fn main() {
foo::<<<<Ty<i32>>();
//~^ ERROR: unmatched angle brackets
//~| ERROR: cannot find function `foo` in this scope [E0425]
//~| ERROR: cannot find type `Ty` in this scope [E0412]
}
Loading

0 comments on commit 69e2f23

Please sign in to comment.