Skip to content

Rollup of 5 pull requests #72984

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 14 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions src/librustc_error_codes/error_codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,7 @@ E0751: include_str!("./error_codes/E0751.md"),
E0752: include_str!("./error_codes/E0752.md"),
E0753: include_str!("./error_codes/E0753.md"),
E0754: include_str!("./error_codes/E0754.md"),
E0758: include_str!("./error_codes/E0758.md"),
;
// E0006, // merged with E0005
// E0008, // cannot bind by-move into a pattern guard
Expand Down
20 changes: 20 additions & 0 deletions src/librustc_error_codes/error_codes/E0758.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
A multi-line (doc-)comment is unterminated.

Erroneous code example:

```compile_fail,E0758
/* I am not terminated!
```

The same goes for doc comments:

```compile_fail,E0758
/*! I am not terminated!
```

You need to end your multi-line comment with `*/` in order to fix this error:

```
/* I am terminated! */
/*! I am also terminated! */
```
8 changes: 7 additions & 1 deletion src/librustc_mir/interpret/terminator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,13 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
self.go_to_block(target_block);
}

Call { ref func, ref args, destination, ref cleanup, .. } => {
Call {
ref func,
ref args,
destination,
ref cleanup,
from_hir_call: _from_hir_call,
} => {
let old_stack = self.frame_idx();
let old_loc = self.frame().loc;
let func = self.eval_operand(func, None)?;
Expand Down
135 changes: 120 additions & 15 deletions src/librustc_mir/transform/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
use super::{MirPass, MirSource};
use rustc_middle::mir::visit::Visitor;
use rustc_middle::{
mir::{Body, Location, Operand, Rvalue, Statement, StatementKind},
ty::{ParamEnv, TyCtxt},
mir::{
BasicBlock, Body, Location, Operand, Rvalue, Statement, StatementKind, Terminator,
TerminatorKind,
},
ty::{self, ParamEnv, TyCtxt},
};
use rustc_span::{def_id::DefId, Span, DUMMY_SP};
use rustc_span::def_id::DefId;

pub struct Validator {
/// Describes at which point in the pipeline this validation is happening.
Expand All @@ -30,27 +33,38 @@ struct TypeChecker<'a, 'tcx> {
}

impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
fn fail(&self, span: Span, msg: impl AsRef<str>) {
fn fail(&self, location: Location, msg: impl AsRef<str>) {
let span = self.body.source_info(location).span;
// We use `delay_span_bug` as we might see broken MIR when other errors have already
// occurred.
self.tcx.sess.diagnostic().delay_span_bug(
span,
&format!("broken MIR in {:?} ({}): {}", self.def_id, self.when, msg.as_ref()),
&format!(
"broken MIR in {:?} ({}) at {:?}:\n{}",
self.def_id,
self.when,
location,
msg.as_ref()
),
);
}

fn check_bb(&self, location: Location, bb: BasicBlock) {
if self.body.basic_blocks().get(bb).is_none() {
self.fail(location, format!("encountered jump to invalid basic block {:?}", bb))
}
}
}

impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
fn visit_operand(&mut self, operand: &Operand<'tcx>, location: Location) {
// `Operand::Copy` is only supposed to be used with `Copy` types.
if let Operand::Copy(place) = operand {
let ty = place.ty(&self.body.local_decls, self.tcx).ty;
let span = self.body.source_info(location).span;

if !ty.is_copy_modulo_regions(self.tcx, self.param_env, DUMMY_SP) {
self.fail(
DUMMY_SP,
format!("`Operand::Copy` with non-`Copy` type {} at {:?}", ty, location),
);
if !ty.is_copy_modulo_regions(self.tcx, self.param_env, span) {
self.fail(location, format!("`Operand::Copy` with non-`Copy` type {}", ty));
}
}

Expand All @@ -65,16 +79,107 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
Rvalue::Use(Operand::Copy(src) | Operand::Move(src)) => {
if dest == src {
self.fail(
DUMMY_SP,
format!(
"encountered `Assign` statement with overlapping memory at {:?}",
location
),
location,
"encountered `Assign` statement with overlapping memory",
);
}
}
_ => {}
}
}
}

fn visit_terminator(&mut self, terminator: &Terminator<'tcx>, location: Location) {
match &terminator.kind {
TerminatorKind::Goto { target } => {
self.check_bb(location, *target);
}
TerminatorKind::SwitchInt { targets, values, .. } => {
if targets.len() != values.len() + 1 {
self.fail(
location,
format!(
"encountered `SwitchInt` terminator with {} values, but {} targets (should be values+1)",
values.len(),
targets.len(),
),
);
}
for target in targets {
self.check_bb(location, *target);
}
}
TerminatorKind::Drop { target, unwind, .. } => {
self.check_bb(location, *target);
if let Some(unwind) = unwind {
self.check_bb(location, *unwind);
}
}
TerminatorKind::DropAndReplace { target, unwind, .. } => {
self.check_bb(location, *target);
if let Some(unwind) = unwind {
self.check_bb(location, *unwind);
}
}
TerminatorKind::Call { func, destination, cleanup, .. } => {
let func_ty = func.ty(&self.body.local_decls, self.tcx);
match func_ty.kind {
ty::FnPtr(..) | ty::FnDef(..) => {}
_ => self.fail(
location,
format!("encountered non-callable type {} in `Call` terminator", func_ty),
),
}
if let Some((_, target)) = destination {
self.check_bb(location, *target);
}
if let Some(cleanup) = cleanup {
self.check_bb(location, *cleanup);
}
}
TerminatorKind::Assert { cond, target, cleanup, .. } => {
let cond_ty = cond.ty(&self.body.local_decls, self.tcx);
if cond_ty != self.tcx.types.bool {
self.fail(
location,
format!(
"encountered non-boolean condition of type {} in `Assert` terminator",
cond_ty
),
);
}
self.check_bb(location, *target);
if let Some(cleanup) = cleanup {
self.check_bb(location, *cleanup);
}
}
TerminatorKind::Yield { resume, drop, .. } => {
self.check_bb(location, *resume);
if let Some(drop) = drop {
self.check_bb(location, *drop);
}
}
TerminatorKind::FalseEdges { real_target, imaginary_target } => {
self.check_bb(location, *real_target);
self.check_bb(location, *imaginary_target);
}
TerminatorKind::FalseUnwind { real_target, unwind } => {
self.check_bb(location, *real_target);
if let Some(unwind) = unwind {
self.check_bb(location, *unwind);
}
}
TerminatorKind::InlineAsm { destination, .. } => {
if let Some(destination) = destination {
self.check_bb(location, *destination);
}
}
// Nothing to validate for these.
TerminatorKind::Resume
| TerminatorKind::Abort
| TerminatorKind::Return
| TerminatorKind::Unreachable
| TerminatorKind::GeneratorDrop => {}
}
}
}
10 changes: 9 additions & 1 deletion src/librustc_parse/lexer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,15 @@ impl<'a> StringReader<'a> {
"unterminated block comment"
};
let last_bpos = self.pos;
self.fatal_span_(start, last_bpos, msg).raise();
self.sess
.span_diagnostic
.struct_span_fatal_with_code(
self.mk_sp(start, last_bpos),
msg,
error_code!(E0758),
)
.emit();
FatalError.raise();
}

if is_doc_comment {
Expand Down
4 changes: 3 additions & 1 deletion src/librustc_resolve/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,9 @@ impl<'a> Resolver<'a> {
Res::Def(DefKind::Ctor(..), did) => this.parent(did),
_ => res.opt_def_id(),
};
candidates.push(ImportSuggestion { did, descr: res.descr(), path });
if candidates.iter().all(|v: &ImportSuggestion| v.did != did) {
candidates.push(ImportSuggestion { did, descr: res.descr(), path });
}
}
}
}
Expand Down
3 changes: 0 additions & 3 deletions src/librustc_trait_selection/opaque_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1253,9 +1253,6 @@ pub fn may_define_opaque_type(
///
/// Requires that trait definitions have been processed so that we can
/// elaborate predicates and walk supertraits.
//
// FIXME: callers may only have a `&[Predicate]`, not a `Vec`, so that's
// what this code should accept.
crate fn required_region_bounds(
tcx: TyCtxt<'tcx>,
erased_self_ty: Ty<'tcx>,
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/os/linux/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ mod arch {

#[cfg(target_arch = "hexagon")]
mod arch {
use crate::os::raw::{c_int, c_long, c_longlong, culonglong};
use crate::os::raw::{c_int, c_long, c_longlong, c_ulonglong};

#[stable(feature = "raw_ext", since = "1.1.0")]
pub type blkcnt_t = c_longlong;
Expand Down
10 changes: 4 additions & 6 deletions src/test/ui/issues/issue-17546.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,10 @@ LL | use std::fmt::Result;
|
LL | use std::io::Result;
|
LL | use std::prelude::v1::Result;
|
LL | use std::result::Result;
|
and 1 other candidate
LL | use std::thread::Result;
|

error[E0573]: expected type, found variant `Result`
--> $DIR/issue-17546.rs:30:13
Expand All @@ -48,11 +47,10 @@ LL | use std::fmt::Result;
|
LL | use std::io::Result;
|
LL | use std::prelude::v1::Result;
|
LL | use std::result::Result;
|
and 1 other candidate
LL | use std::thread::Result;
|

error[E0573]: expected type, found variant `NoResult`
--> $DIR/issue-17546.rs:35:15
Expand Down
Loading