Skip to content

Rollup of 5 pull requests #60794

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

Merged
merged 12 commits into from
May 14, 2019
Merged
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
2 changes: 1 addition & 1 deletion src/libcore/tests/lib.rs
Original file line number Diff line number Diff line change
@@ -31,7 +31,7 @@
#![feature(slice_partition_dedup)]
#![feature(copy_within)]
#![feature(int_error_matching)]
#![deny(rust_2018_idioms)]
#![warn(rust_2018_idioms)]

extern crate test;

34 changes: 24 additions & 10 deletions src/librustc_mir/borrow_check/error_reporting.rs
Original file line number Diff line number Diff line change
@@ -826,18 +826,21 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {

let borrow_span = borrow_spans.var_or_use();
if let BorrowExplanation::MustBeValidFor {
category: ConstraintCategory::Return,
category,
span,
ref opt_place_desc,
from_closure: false,
..
} = explanation {
return self.report_cannot_return_reference_to_local(
if let Some(diag) = self.try_report_cannot_return_reference_to_local(
borrow,
borrow_span,
span,
category,
opt_place_desc.as_ref(),
);
) {
return diag;
}
}

let mut err = self.infcx.tcx.path_does_not_live_long_enough(
@@ -1015,17 +1018,20 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
);

if let BorrowExplanation::MustBeValidFor {
category: ConstraintCategory::Return,
category,
span,
from_closure: false,
..
} = explanation {
return self.report_cannot_return_reference_to_local(
if let Some(diag) = self.try_report_cannot_return_reference_to_local(
borrow,
proper_span,
span,
category,
None,
);
) {
return diag;
}
}

let tcx = self.infcx.tcx;
@@ -1064,15 +1070,22 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
err
}

fn report_cannot_return_reference_to_local(
fn try_report_cannot_return_reference_to_local(
&self,
borrow: &BorrowData<'tcx>,
borrow_span: Span,
return_span: Span,
category: ConstraintCategory,
opt_place_desc: Option<&String>,
) -> DiagnosticBuilder<'cx> {
) -> Option<DiagnosticBuilder<'cx>> {
let tcx = self.infcx.tcx;

let return_kind = match category {
ConstraintCategory::Return => "return",
ConstraintCategory::Yield => "yield",
_ => return None,
};

// FIXME use a better heuristic than Spans
let reference_desc = if return_span == self.mir.source_info(borrow.reserve_location).span {
"reference to"
@@ -1110,7 +1123,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
let local = if let Place::Base(PlaceBase::Local(local)) = *root_place {
local
} else {
bug!("report_cannot_return_reference_to_local: not a local")
bug!("try_report_cannot_return_reference_to_local: not a local")
};
match self.mir.local_kind(local) {
LocalKind::ReturnPointer | LocalKind::Temp => {
@@ -1131,6 +1144,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {

let mut err = tcx.cannot_return_reference_to_local(
return_span,
return_kind,
reference_desc,
&place_desc,
Origin::Mir,
@@ -1140,7 +1154,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
err.span_label(borrow_span, note);
}

err
Some(err)
}

fn report_escaping_closure_capture(
4 changes: 4 additions & 0 deletions src/librustc_mir/borrow_check/nll/explain_borrow/mod.rs
Original file line number Diff line number Diff line change
@@ -310,9 +310,13 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
opt_place_desc,
}
} else {
debug!("explain_why_borrow_contains_point: \
Could not generate a region name");
BorrowExplanation::Unexplained
}
} else {
debug!("explain_why_borrow_contains_point: \
Could not generate an error region vid");
BorrowExplanation::Unexplained
}
}
Original file line number Diff line number Diff line change
@@ -34,6 +34,7 @@ crate enum RegionNameSource {
MatchedAdtAndSegment(Span),
AnonRegionFromUpvar(Span, String),
AnonRegionFromOutput(Span, String, String),
AnonRegionFromYieldTy(Span, String),
}

impl RegionName {
@@ -48,7 +49,8 @@ impl RegionName {
RegionNameSource::MatchedHirTy(..) |
RegionNameSource::MatchedAdtAndSegment(..) |
RegionNameSource::AnonRegionFromUpvar(..) |
RegionNameSource::AnonRegionFromOutput(..) => false,
RegionNameSource::AnonRegionFromOutput(..) |
RegionNameSource::AnonRegionFromYieldTy(..) => false,
}
}

@@ -105,6 +107,12 @@ impl RegionName {
format!("return type{} is {}", mir_description, type_name),
);
},
RegionNameSource::AnonRegionFromYieldTy(span, type_name) => {
diag.span_label(
*span,
format!("yield type is {}", type_name),
);
}
RegionNameSource::Static => {},
}
}
@@ -170,6 +178,11 @@ impl<'tcx> RegionInferenceContext<'tcx> {
self.give_name_if_anonymous_region_appears_in_output(
infcx, mir, mir_def_id, fr, counter,
)
})
.or_else(|| {
self.give_name_if_anonymous_region_appears_in_yield_ty(
infcx, mir, mir_def_id, fr, counter,
)
});

debug!("give_region_a_name: gave name {:?}", value);
@@ -676,10 +689,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
"give_name_if_anonymous_region_appears_in_output: return_ty = {:?}",
return_ty
);
if !infcx
.tcx
.any_free_region_meets(&return_ty, |r| r.to_region_vid() == fr)
{
if !tcx.any_free_region_meets(&return_ty, |r| r.to_region_vid() == fr) {
return None;
}

@@ -724,6 +734,57 @@ impl<'tcx> RegionInferenceContext<'tcx> {
})
}

fn give_name_if_anonymous_region_appears_in_yield_ty(
&self,
infcx: &InferCtxt<'_, '_, 'tcx>,
mir: &Mir<'tcx>,
mir_def_id: DefId,
fr: RegionVid,
counter: &mut usize,
) -> Option<RegionName> {
// Note: generators from `async fn` yield `()`, so we don't have to
// worry about them here.
let yield_ty = self.universal_regions.yield_ty?;
debug!(
"give_name_if_anonymous_region_appears_in_yield_ty: yield_ty = {:?}",
yield_ty,
);

let tcx = infcx.tcx;

if !tcx.any_free_region_meets(&yield_ty, |r| r.to_region_vid() == fr) {
return None;
}

let mut highlight = RegionHighlightMode::default();
highlight.highlighting_region_vid(fr, *counter);
let type_name = infcx.extract_type_name(&yield_ty, Some(highlight));

let mir_node_id = tcx.hir().as_local_node_id(mir_def_id).expect("non-local mir");

let yield_span = match tcx.hir().get(mir_node_id) {
hir::Node::Expr(hir::Expr {
node: hir::ExprKind::Closure(_, _, _, span, _),
..
}) => (
tcx.sess.source_map().end_point(*span)
),
_ => mir.span,
};

debug!(
"give_name_if_anonymous_region_appears_in_yield_ty: \
type_name = {:?}, yield_span = {:?}",
yield_span,
type_name,
);

Some(RegionName {
name: self.synthesize_region_name(counter),
source: RegionNameSource::AnonRegionFromYieldTy(yield_span, type_name),
})
}

/// Creates a synthetic region named `'1`, incrementing the
/// counter.
fn synthesize_region_name(&self, counter: &mut usize) -> InternedString {
6 changes: 4 additions & 2 deletions src/librustc_mir/util/borrowck_errors.rs
Original file line number Diff line number Diff line change
@@ -634,6 +634,7 @@ pub trait BorrowckErrors<'cx>: Sized + Copy {
fn cannot_return_reference_to_local(
self,
span: Span,
return_kind: &str,
reference_desc: &str,
path_desc: &str,
o: Origin,
@@ -642,15 +643,16 @@ pub trait BorrowckErrors<'cx>: Sized + Copy {
self,
span,
E0515,
"cannot return {REFERENCE} {LOCAL}{OGN}",
"cannot {RETURN} {REFERENCE} {LOCAL}{OGN}",
RETURN=return_kind,
REFERENCE=reference_desc,
LOCAL=path_desc,
OGN = o
);

err.span_label(
span,
format!("returns a {} data owned by the current function", reference_desc),
format!("{}s a {} data owned by the current function", return_kind, reference_desc),
);

self.cancel_if_wrong_origin(err, o)
24 changes: 21 additions & 3 deletions src/librustc_typeck/collect.rs
Original file line number Diff line number Diff line change
@@ -1404,15 +1404,27 @@ pub fn checked_type_of<'a, 'tcx>(
if !fail {
return None;
}
bug!("unexpected const parent path def {:?}", x);
tcx.sess.delay_span_bug(
DUMMY_SP,
&format!(
"unexpected const parent path def {:?}", x
),
);
tcx.types.err
}
}
}
x => {
if !fail {
return None;
}
bug!("unexpected const parent path {:?}", x);
tcx.sess.delay_span_bug(
DUMMY_SP,
&format!(
"unexpected const parent path {:?}", x
),
);
tcx.types.err
}
}
}
@@ -1421,7 +1433,13 @@ pub fn checked_type_of<'a, 'tcx>(
if !fail {
return None;
}
bug!("unexpected const parent in type_of_def_id(): {:?}", x);
tcx.sess.delay_span_bug(
DUMMY_SP,
&format!(
"unexpected const parent in type_of_def_id(): {:?}", x
),
);
tcx.types.err
}
}
}
1 change: 1 addition & 0 deletions src/libsyntax/feature_gate.rs
Original file line number Diff line number Diff line change
@@ -563,6 +563,7 @@ declare_features! (
// unanticipated results, such as compiler crashes. We warn the user about these
// to alert them.
const INCOMPLETE_FEATURES: &[Symbol] = &[
sym::impl_trait_in_bindings,
sym::generic_associated_types,
sym::const_generics
];
7 changes: 6 additions & 1 deletion src/libsyntax_ext/proc_macro_decls.rs
Original file line number Diff line number Diff line change
@@ -328,6 +328,7 @@ impl<'a> Visitor<'a> for CollectProcMacros<'a> {

// Creates a new module which looks like:
//
// #[doc(hidden)]
// mod $gensym {
// extern crate proc_macro;
//
@@ -361,6 +362,10 @@ fn mk_decls(
});
let span = DUMMY_SP.apply_mark(mark);

let hidden = cx.meta_list_item_word(span, Symbol::intern("hidden"));
let doc = cx.meta_list(span, Symbol::intern("doc"), vec![hidden]);
let doc_hidden = cx.attribute(span, doc);

let proc_macro = Ident::from_str("proc_macro");
let krate = cx.item(span,
proc_macro,
@@ -425,7 +430,7 @@ fn mk_decls(
span,
span,
ast::Ident::with_empty_ctxt(Symbol::gensym("decls")),
vec![],
vec![doc_hidden],
vec![krate, decls_static],
).map(|mut i| {
i.vis = respan(span, ast::VisibilityKind::Public);
1 change: 1 addition & 0 deletions src/test/run-pass/impl-trait-in-bindings.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![feature(impl_trait_in_bindings)]
//~^ WARN the feature `impl_trait_in_bindings` is incomplete and may cause the compiler to crash

use std::fmt::Debug;

6 changes: 6 additions & 0 deletions src/test/run-pass/impl-trait-in-bindings.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
warning: the feature `impl_trait_in_bindings` is incomplete and may cause the compiler to crash
--> $DIR/impl-trait-in-bindings.rs:1:12
|
LL | #![feature(impl_trait_in_bindings)]
| ^^^^^^^^^^^^^^^^^^^^^^

11 changes: 11 additions & 0 deletions src/test/ui/const-generics/cannot-infer-type-for-const-param.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#![feature(const_generics)]
//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash

// We should probably be able to infer the types here. However, this test is checking that we don't
// get an ICE in this case. It may be modified later to not be an error.

struct Foo<const NUM_BYTES: usize>(pub [u8; NUM_BYTES]);

fn main() {
let _ = Foo::<3>([1, 2, 3]); //~ ERROR type annotations needed
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
warning: the feature `const_generics` is incomplete and may cause the compiler to crash
--> $DIR/cannot-infer-type-for-const-param.rs:1:12
|
LL | #![feature(const_generics)]
| ^^^^^^^^^^^^^^

error[E0282]: type annotations needed
--> $DIR/cannot-infer-type-for-const-param.rs:10:19
|
LL | let _ = Foo::<3>([1, 2, 3]);
| ^ cannot infer type for `{integer}`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0282`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use std::convert::TryInto;

struct S;

fn main() {
let _: u32 = 5i32.try_into::<32>().unwrap(); //~ ERROR wrong number of const arguments
S.f::<0>(); //~ ERROR no method named `f`
S::<0>; //~ ERROR wrong number of const arguments
}
Loading