Skip to content

Commit 80e7cde

Browse files
committed
Auto merge of #60794 - Centril:rollup-vlguvns, r=Centril
Rollup of 5 pull requests Successful merges: - #60176 (Explain error when yielding a reference to a local variable) - #60201 (coretest: Downgrade deny to warn) - #60562 (Add #[doc(hidden)] attribute on compiler generated module.) - #60710 (Use `delay_span_bug` for error cases when checking `AnonConst` parent) - #60770 (add impl_trait_in_bindings to INCOMPLETE_FEATURES) Failed merges: r? @ghost
2 parents a9ec99f + b698609 commit 80e7cde

21 files changed

+240
-38
lines changed

src/libcore/tests/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
#![feature(slice_partition_dedup)]
3232
#![feature(copy_within)]
3333
#![feature(int_error_matching)]
34-
#![deny(rust_2018_idioms)]
34+
#![warn(rust_2018_idioms)]
3535

3636
extern crate test;
3737

src/librustc_mir/borrow_check/error_reporting.rs

+24-10
Original file line numberDiff line numberDiff line change
@@ -826,18 +826,21 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
826826

827827
let borrow_span = borrow_spans.var_or_use();
828828
if let BorrowExplanation::MustBeValidFor {
829-
category: ConstraintCategory::Return,
829+
category,
830830
span,
831831
ref opt_place_desc,
832832
from_closure: false,
833833
..
834834
} = explanation {
835-
return self.report_cannot_return_reference_to_local(
835+
if let Some(diag) = self.try_report_cannot_return_reference_to_local(
836836
borrow,
837837
borrow_span,
838838
span,
839+
category,
839840
opt_place_desc.as_ref(),
840-
);
841+
) {
842+
return diag;
843+
}
841844
}
842845

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

10171020
if let BorrowExplanation::MustBeValidFor {
1018-
category: ConstraintCategory::Return,
1021+
category,
10191022
span,
10201023
from_closure: false,
10211024
..
10221025
} = explanation {
1023-
return self.report_cannot_return_reference_to_local(
1026+
if let Some(diag) = self.try_report_cannot_return_reference_to_local(
10241027
borrow,
10251028
proper_span,
10261029
span,
1030+
category,
10271031
None,
1028-
);
1032+
) {
1033+
return diag;
1034+
}
10291035
}
10301036

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

1067-
fn report_cannot_return_reference_to_local(
1073+
fn try_report_cannot_return_reference_to_local(
10681074
&self,
10691075
borrow: &BorrowData<'tcx>,
10701076
borrow_span: Span,
10711077
return_span: Span,
1078+
category: ConstraintCategory,
10721079
opt_place_desc: Option<&String>,
1073-
) -> DiagnosticBuilder<'cx> {
1080+
) -> Option<DiagnosticBuilder<'cx>> {
10741081
let tcx = self.infcx.tcx;
10751082

1083+
let return_kind = match category {
1084+
ConstraintCategory::Return => "return",
1085+
ConstraintCategory::Yield => "yield",
1086+
_ => return None,
1087+
};
1088+
10761089
// FIXME use a better heuristic than Spans
10771090
let reference_desc = if return_span == self.mir.source_info(borrow.reserve_location).span {
10781091
"reference to"
@@ -1110,7 +1123,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
11101123
let local = if let Place::Base(PlaceBase::Local(local)) = *root_place {
11111124
local
11121125
} else {
1113-
bug!("report_cannot_return_reference_to_local: not a local")
1126+
bug!("try_report_cannot_return_reference_to_local: not a local")
11141127
};
11151128
match self.mir.local_kind(local) {
11161129
LocalKind::ReturnPointer | LocalKind::Temp => {
@@ -1131,6 +1144,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
11311144

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

1143-
err
1157+
Some(err)
11441158
}
11451159

11461160
fn report_escaping_closure_capture(

src/librustc_mir/borrow_check/nll/explain_borrow/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -310,9 +310,13 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
310310
opt_place_desc,
311311
}
312312
} else {
313+
debug!("explain_why_borrow_contains_point: \
314+
Could not generate a region name");
313315
BorrowExplanation::Unexplained
314316
}
315317
} else {
318+
debug!("explain_why_borrow_contains_point: \
319+
Could not generate an error region vid");
316320
BorrowExplanation::Unexplained
317321
}
318322
}

src/librustc_mir/borrow_check/nll/region_infer/error_reporting/region_name.rs

+66-5
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ crate enum RegionNameSource {
3434
MatchedAdtAndSegment(Span),
3535
AnonRegionFromUpvar(Span, String),
3636
AnonRegionFromOutput(Span, String, String),
37+
AnonRegionFromYieldTy(Span, String),
3738
}
3839

3940
impl RegionName {
@@ -48,7 +49,8 @@ impl RegionName {
4849
RegionNameSource::MatchedHirTy(..) |
4950
RegionNameSource::MatchedAdtAndSegment(..) |
5051
RegionNameSource::AnonRegionFromUpvar(..) |
51-
RegionNameSource::AnonRegionFromOutput(..) => false,
52+
RegionNameSource::AnonRegionFromOutput(..) |
53+
RegionNameSource::AnonRegionFromYieldTy(..) => false,
5254
}
5355
}
5456

@@ -105,6 +107,12 @@ impl RegionName {
105107
format!("return type{} is {}", mir_description, type_name),
106108
);
107109
},
110+
RegionNameSource::AnonRegionFromYieldTy(span, type_name) => {
111+
diag.span_label(
112+
*span,
113+
format!("yield type is {}", type_name),
114+
);
115+
}
108116
RegionNameSource::Static => {},
109117
}
110118
}
@@ -170,6 +178,11 @@ impl<'tcx> RegionInferenceContext<'tcx> {
170178
self.give_name_if_anonymous_region_appears_in_output(
171179
infcx, mir, mir_def_id, fr, counter,
172180
)
181+
})
182+
.or_else(|| {
183+
self.give_name_if_anonymous_region_appears_in_yield_ty(
184+
infcx, mir, mir_def_id, fr, counter,
185+
)
173186
});
174187

175188
debug!("give_region_a_name: gave name {:?}", value);
@@ -676,10 +689,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
676689
"give_name_if_anonymous_region_appears_in_output: return_ty = {:?}",
677690
return_ty
678691
);
679-
if !infcx
680-
.tcx
681-
.any_free_region_meets(&return_ty, |r| r.to_region_vid() == fr)
682-
{
692+
if !tcx.any_free_region_meets(&return_ty, |r| r.to_region_vid() == fr) {
683693
return None;
684694
}
685695

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

737+
fn give_name_if_anonymous_region_appears_in_yield_ty(
738+
&self,
739+
infcx: &InferCtxt<'_, '_, 'tcx>,
740+
mir: &Mir<'tcx>,
741+
mir_def_id: DefId,
742+
fr: RegionVid,
743+
counter: &mut usize,
744+
) -> Option<RegionName> {
745+
// Note: generators from `async fn` yield `()`, so we don't have to
746+
// worry about them here.
747+
let yield_ty = self.universal_regions.yield_ty?;
748+
debug!(
749+
"give_name_if_anonymous_region_appears_in_yield_ty: yield_ty = {:?}",
750+
yield_ty,
751+
);
752+
753+
let tcx = infcx.tcx;
754+
755+
if !tcx.any_free_region_meets(&yield_ty, |r| r.to_region_vid() == fr) {
756+
return None;
757+
}
758+
759+
let mut highlight = RegionHighlightMode::default();
760+
highlight.highlighting_region_vid(fr, *counter);
761+
let type_name = infcx.extract_type_name(&yield_ty, Some(highlight));
762+
763+
let mir_node_id = tcx.hir().as_local_node_id(mir_def_id).expect("non-local mir");
764+
765+
let yield_span = match tcx.hir().get(mir_node_id) {
766+
hir::Node::Expr(hir::Expr {
767+
node: hir::ExprKind::Closure(_, _, _, span, _),
768+
..
769+
}) => (
770+
tcx.sess.source_map().end_point(*span)
771+
),
772+
_ => mir.span,
773+
};
774+
775+
debug!(
776+
"give_name_if_anonymous_region_appears_in_yield_ty: \
777+
type_name = {:?}, yield_span = {:?}",
778+
yield_span,
779+
type_name,
780+
);
781+
782+
Some(RegionName {
783+
name: self.synthesize_region_name(counter),
784+
source: RegionNameSource::AnonRegionFromYieldTy(yield_span, type_name),
785+
})
786+
}
787+
727788
/// Creates a synthetic region named `'1`, incrementing the
728789
/// counter.
729790
fn synthesize_region_name(&self, counter: &mut usize) -> InternedString {

src/librustc_mir/util/borrowck_errors.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,7 @@ pub trait BorrowckErrors<'cx>: Sized + Copy {
634634
fn cannot_return_reference_to_local(
635635
self,
636636
span: Span,
637+
return_kind: &str,
637638
reference_desc: &str,
638639
path_desc: &str,
639640
o: Origin,
@@ -642,15 +643,16 @@ pub trait BorrowckErrors<'cx>: Sized + Copy {
642643
self,
643644
span,
644645
E0515,
645-
"cannot return {REFERENCE} {LOCAL}{OGN}",
646+
"cannot {RETURN} {REFERENCE} {LOCAL}{OGN}",
647+
RETURN=return_kind,
646648
REFERENCE=reference_desc,
647649
LOCAL=path_desc,
648650
OGN = o
649651
);
650652

651653
err.span_label(
652654
span,
653-
format!("returns a {} data owned by the current function", reference_desc),
655+
format!("{}s a {} data owned by the current function", return_kind, reference_desc),
654656
);
655657

656658
self.cancel_if_wrong_origin(err, o)

src/librustc_typeck/collect.rs

+21-3
Original file line numberDiff line numberDiff line change
@@ -1404,15 +1404,27 @@ pub fn checked_type_of<'a, 'tcx>(
14041404
if !fail {
14051405
return None;
14061406
}
1407-
bug!("unexpected const parent path def {:?}", x);
1407+
tcx.sess.delay_span_bug(
1408+
DUMMY_SP,
1409+
&format!(
1410+
"unexpected const parent path def {:?}", x
1411+
),
1412+
);
1413+
tcx.types.err
14081414
}
14091415
}
14101416
}
14111417
x => {
14121418
if !fail {
14131419
return None;
14141420
}
1415-
bug!("unexpected const parent path {:?}", x);
1421+
tcx.sess.delay_span_bug(
1422+
DUMMY_SP,
1423+
&format!(
1424+
"unexpected const parent path {:?}", x
1425+
),
1426+
);
1427+
tcx.types.err
14161428
}
14171429
}
14181430
}
@@ -1421,7 +1433,13 @@ pub fn checked_type_of<'a, 'tcx>(
14211433
if !fail {
14221434
return None;
14231435
}
1424-
bug!("unexpected const parent in type_of_def_id(): {:?}", x);
1436+
tcx.sess.delay_span_bug(
1437+
DUMMY_SP,
1438+
&format!(
1439+
"unexpected const parent in type_of_def_id(): {:?}", x
1440+
),
1441+
);
1442+
tcx.types.err
14251443
}
14261444
}
14271445
}

src/libsyntax/feature_gate.rs

+1
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,7 @@ declare_features! (
563563
// unanticipated results, such as compiler crashes. We warn the user about these
564564
// to alert them.
565565
const INCOMPLETE_FEATURES: &[Symbol] = &[
566+
sym::impl_trait_in_bindings,
566567
sym::generic_associated_types,
567568
sym::const_generics
568569
];

src/libsyntax_ext/proc_macro_decls.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ impl<'a> Visitor<'a> for CollectProcMacros<'a> {
328328

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

365+
let hidden = cx.meta_list_item_word(span, Symbol::intern("hidden"));
366+
let doc = cx.meta_list(span, Symbol::intern("doc"), vec![hidden]);
367+
let doc_hidden = cx.attribute(span, doc);
368+
364369
let proc_macro = Ident::from_str("proc_macro");
365370
let krate = cx.item(span,
366371
proc_macro,
@@ -425,7 +430,7 @@ fn mk_decls(
425430
span,
426431
span,
427432
ast::Ident::with_empty_ctxt(Symbol::gensym("decls")),
428-
vec![],
433+
vec![doc_hidden],
429434
vec![krate, decls_static],
430435
).map(|mut i| {
431436
i.vis = respan(span, ast::VisibilityKind::Public);

src/test/run-pass/impl-trait-in-bindings.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#![feature(impl_trait_in_bindings)]
2+
//~^ WARN the feature `impl_trait_in_bindings` is incomplete and may cause the compiler to crash
23

34
use std::fmt::Debug;
45

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
warning: the feature `impl_trait_in_bindings` is incomplete and may cause the compiler to crash
2+
--> $DIR/impl-trait-in-bindings.rs:1:12
3+
|
4+
LL | #![feature(impl_trait_in_bindings)]
5+
| ^^^^^^^^^^^^^^^^^^^^^^
6+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#![feature(const_generics)]
2+
//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash
3+
4+
// We should probably be able to infer the types here. However, this test is checking that we don't
5+
// get an ICE in this case. It may be modified later to not be an error.
6+
7+
struct Foo<const NUM_BYTES: usize>(pub [u8; NUM_BYTES]);
8+
9+
fn main() {
10+
let _ = Foo::<3>([1, 2, 3]); //~ ERROR type annotations needed
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
warning: the feature `const_generics` is incomplete and may cause the compiler to crash
2+
--> $DIR/cannot-infer-type-for-const-param.rs:1:12
3+
|
4+
LL | #![feature(const_generics)]
5+
| ^^^^^^^^^^^^^^
6+
7+
error[E0282]: type annotations needed
8+
--> $DIR/cannot-infer-type-for-const-param.rs:10:19
9+
|
10+
LL | let _ = Foo::<3>([1, 2, 3]);
11+
| ^ cannot infer type for `{integer}`
12+
13+
error: aborting due to previous error
14+
15+
For more information about this error, try `rustc --explain E0282`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
use std::convert::TryInto;
2+
3+
struct S;
4+
5+
fn main() {
6+
let _: u32 = 5i32.try_into::<32>().unwrap(); //~ ERROR wrong number of const arguments
7+
S.f::<0>(); //~ ERROR no method named `f`
8+
S::<0>; //~ ERROR wrong number of const arguments
9+
}

0 commit comments

Comments
 (0)