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 7 pull requests #72733

Closed
wants to merge 48 commits into from
Closed
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
3f661d2
borrowck `DefId` -> `LocalDefId`
lcnr May 11, 2020
a8ed9aa
impl From<[T; N]> for Box<[T]>
pickfire Apr 13, 2020
eccaa01
rustc_target: Add a target spec option for static-pie support
petrochenkov May 1, 2020
96a466c
linker: Support `-static-pie` and `-static -shared`
petrochenkov May 1, 2020
08df311
librustc_mir: Add support for const fn offset/arith_offset
josephlr Apr 24, 2020
9b3dfd8
core: Make pointer offset methods "const fn"
josephlr Apr 24, 2020
88a37a2
test/ui/consts: Add tests for const ptr offsets
josephlr May 15, 2020
6b20f58
miri_unleached: We now allow offset in const fn
josephlr May 18, 2020
55577b4
librustc_mir: Add back use statement
josephlr May 25, 2020
6367b54
librustc_middle: Add function for computing unsigned abs
josephlr May 26, 2020
71ef841
Add checks and tests for computing abs(offset_bytes)
josephlr May 26, 2020
822ad87
Add Peekable::next_if
jyn514 May 18, 2020
a977df3
Implement RFC 2585
LeSeulArtichaut May 3, 2020
594c499
Add tests
LeSeulArtichaut May 3, 2020
bb67915
Apply suggestions from code review
LeSeulArtichaut May 13, 2020
3ce9d5c
Add more cases to the test
LeSeulArtichaut May 14, 2020
b3e012b
Fix inverted `if` condition
LeSeulArtichaut May 18, 2020
a41f763
Use the lowest of `unsafe_op_in_unsafe_fn` and `safe_borrow_packed` f…
LeSeulArtichaut May 18, 2020
a3bae5c
Fix wrong conflict resolution
LeSeulArtichaut May 19, 2020
925d5ac
Fix and bless tests
LeSeulArtichaut May 21, 2020
9671b44
Add tests for packed borrows in unsafe fns
LeSeulArtichaut May 22, 2020
3599ada
Mark deduplicated errors as expected in gate test
LeSeulArtichaut May 23, 2020
4a538d3
Do not hardcode lint name
LeSeulArtichaut May 23, 2020
e3d27ec
Add explanation about taking the minimum of the two lints
LeSeulArtichaut May 23, 2020
1b08850
Fix import
LeSeulArtichaut May 23, 2020
63066c0
Use `LintId`s to check for gated lints
LeSeulArtichaut May 23, 2020
db684be
Whitelist `unsafe_op_in_unsafe_fn` in rustdoc
LeSeulArtichaut May 27, 2020
3fea832
Fix spacing of expected/found notes without a label
estebank Dec 20, 2019
5ba2220
Name `RegionKind::ReVar` lifetimes in diagnostics
estebank Dec 20, 2019
eb0f4d5
Tweak output for mismatched impl item
estebank Dec 22, 2019
3811232
review comments
estebank Dec 23, 2019
2e2f820
review comment: use FxIndexSet
estebank Dec 27, 2019
d0d30b0
fix rebase
estebank Jan 7, 2020
2b35247
Modify wording
estebank Feb 17, 2020
500504c
fix rebase
estebank Mar 30, 2020
c52dbbc
fix rebase
estebank Apr 14, 2020
7d5415b
Add additional checks for isize overflow
josephlr May 27, 2020
cb6408a
Fix rebase
estebank May 28, 2020
f213acf
review comments: change wording and visual output
estebank May 28, 2020
0e3b31c
Update src/librustdoc/core.rs
nikomatsakis May 28, 2020
1bd6970
Account for `Self` as a type param
estebank May 28, 2020
ce10b6d
Rollup merge of #67460 - estebank:named-lts, r=nikomatsakis
RalfJung May 29, 2020
de90e0d
Rollup merge of #71095 - pickfire:box-from-array, r=dtolnay
RalfJung May 29, 2020
b014e61
Rollup merge of #71500 - josephlr:offset, r=oli-obk,RalfJung
RalfJung May 29, 2020
b08168e
Rollup merge of #71804 - petrochenkov:static-pie, r=cuviper
RalfJung May 29, 2020
4e2351e
Rollup merge of #71862 - LeSeulArtichaut:unsafe-block-in-unsafe-fn, r…
RalfJung May 29, 2020
92329c7
Rollup merge of #72103 - lcnr:borrowck-localdefid, r=jonas-schievink
RalfJung May 29, 2020
783cfb1
Rollup merge of #72310 - jyn514:peekable-next-if, r=dtolnay
RalfJung May 29, 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
15 changes: 12 additions & 3 deletions src/librustc_errors/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,18 @@ impl Diagnostic {
expected_extra: &dyn fmt::Display,
found_extra: &dyn fmt::Display,
) -> &mut Self {
let expected_label = format!("expected {}", expected_label);

let found_label = format!("found {}", found_label);
let expected_label = expected_label.to_string();
let expected_label = if expected_label.is_empty() {
"expected".to_string()
} else {
format!("expected {}", expected_label)
};
let found_label = found_label.to_string();
let found_label = if found_label.is_empty() {
"found".to_string()
} else {
format!("found {}", found_label)
};
let (found_padding, expected_padding) = if expected_label.len() > found_label.len() {
(expected_label.len() - found_label.len(), 0)
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_infer/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -987,12 +987,12 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
}

fn push_ty_ref<'tcx>(
r: &ty::Region<'tcx>,
region: &ty::Region<'tcx>,
ty: Ty<'tcx>,
mutbl: hir::Mutability,
s: &mut DiagnosticStyledString,
) {
let mut r = r.to_string();
let mut r = region.to_string();
if r == "'_" {
r.clear();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@

use crate::infer::error_reporting::nice_region_error::NiceRegionError;
use crate::infer::lexical_region_resolve::RegionResolutionError;
use crate::infer::{Subtype, ValuePairs};
use crate::infer::{Subtype, TyCtxtInferExt, ValuePairs};
use crate::traits::ObligationCauseCode::CompareImplMethodObligation;
use rustc_errors::ErrorReported;
use rustc_middle::ty::Ty;
use rustc_span::Span;
use rustc_hir as hir;
use rustc_hir::def::Res;
use rustc_hir::def_id::DefId;
use rustc_hir::intravisit::Visitor;
use rustc_middle::ty::error::ExpectedFound;
use rustc_middle::ty::{self, Ty, TyCtxt};
use rustc_span::{MultiSpan, Span};

impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
/// Print the error message for lifetime errors when the `impl` doesn't conform to the `trait`.
Expand Down Expand Up @@ -36,7 +41,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
var_origin.span(),
sub_expected_found.expected,
sub_expected_found.found,
self.tcx().def_span(*trait_item_def_id),
*trait_item_def_id,
);
return Some(ErrorReported);
}
Expand All @@ -47,14 +52,100 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
None
}

fn emit_err(&self, sp: Span, expected: Ty<'tcx>, found: Ty<'tcx>, impl_sp: Span) {
fn emit_err(&self, sp: Span, expected: Ty<'tcx>, found: Ty<'tcx>, trait_def_id: DefId) {
let tcx = self.tcx();
let trait_sp = self.tcx().def_span(trait_def_id);
let mut err = self
.tcx()
.sess
.struct_span_err(sp, "`impl` item signature doesn't match `trait` item signature");
err.note(&format!("expected `{:?}`\n found `{:?}`", expected, found));
err.span_label(sp, &format!("found {:?}", found));
err.span_label(impl_sp, &format!("expected {:?}", expected));
err.span_label(sp, &format!("found `{:?}`", found));
err.span_label(trait_sp, &format!("expected `{:?}`", expected));

// Get the span of all the used type parameters in the method.
let assoc_item = self.tcx().associated_item(trait_def_id);
let mut visitor = TypeParamSpanVisitor { tcx: self.tcx(), types: vec![] };
match assoc_item.kind {
ty::AssocKind::Fn => {
let hir = self.tcx().hir();
if let Some(hir_id) = assoc_item.def_id.as_local().map(|id| hir.as_local_hir_id(id))
{
if let Some(decl) = hir.fn_decl_by_hir_id(hir_id) {
visitor.visit_fn_decl(decl);
}
}
}
_ => {}
}
let mut type_param_span: MultiSpan =
visitor.types.iter().cloned().collect::<Vec<_>>().into();
for &span in &visitor.types {
type_param_span.push_span_label(
span,
"consider borrowing this type parameter in the trait".to_string(),
);
}

if let Some((expected, found)) = tcx
.infer_ctxt()
.enter(|infcx| infcx.expected_found_str_ty(&ExpectedFound { expected, found }))
{
// Highlighted the differences when showing the "expected/found" note.
err.note_expected_found(&"", expected, &"", found);
} else {
// This fallback shouldn't be necessary, but let's keep it in just in case.
err.note(&format!("expected `{:?}`\n found `{:?}`", expected, found));
}
err.span_help(
type_param_span,
"the lifetime requirements from the `impl` do not correspond to the requirements in \
the `trait`",
);
if visitor.types.is_empty() {
err.help(
"verify the lifetime relationships in the `trait` and `impl` between the `self` \
argument, the other inputs and its output",
);
}
err.emit();
}
}

struct TypeParamSpanVisitor<'tcx> {
tcx: TyCtxt<'tcx>,
types: Vec<Span>,
}

impl Visitor<'tcx> for TypeParamSpanVisitor<'tcx> {
type Map = rustc_middle::hir::map::Map<'tcx>;

fn nested_visit_map(&mut self) -> hir::intravisit::NestedVisitorMap<Self::Map> {
hir::intravisit::NestedVisitorMap::OnlyBodies(self.tcx.hir())
}

fn visit_ty(&mut self, arg: &'tcx hir::Ty<'tcx>) {
match arg.kind {
hir::TyKind::Rptr(_, ref mut_ty) => {
// We don't want to suggest looking into borrowing `&T` or `&Self`.
hir::intravisit::walk_ty(self, mut_ty.ty);
return;
}
hir::TyKind::Path(hir::QPath::Resolved(None, path)) => match &path.segments {
[segment]
if segment
.res
.map(|res| match res {
Res::SelfTy(_, _) | Res::Def(hir::def::DefKind::TyParam, _) => true,
_ => false,
})
.unwrap_or(false) =>
{
self.types.push(path.span);
}
_ => {}
},
_ => {}
}
hir::intravisit::walk_ty(self, arg);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ note: ...so that the expression is assignable
|
LL | bar(foo, x)
| ^
= note: expected `Type<'_>`
found `Type<'a>`
= note: expected `Type<'_>`
found `Type<'a>`
= note: but, the lifetime must be valid for the static lifetime...
note: ...so that the expression is assignable
--> $DIR/project-fn-ret-invariant.rs:48:4
|
LL | bar(foo, x)
| ^^^^^^^^^^^
= note: expected `Type<'static>`
found `Type<'_>`
= note: expected `Type<'static>`
found `Type<'_>`

error: aborting due to previous error

Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/error-codes/E0490.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ note: ...so that the expression is assignable
|
LL | let x: &'a _ = &y;
| ^^
= note: expected `&'a &()`
found `&'a &'b ()`
= note: expected `&'a &()`
found `&'a &'b ()`
note: but, the lifetime must be valid for the lifetime `'a` as defined on the function body at 1:6...
--> $DIR/E0490.rs:1:6
|
Expand Down
8 changes: 4 additions & 4 deletions src/test/ui/impl-header-lifetime-elision/dyn-trait.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ note: ...so that the expression is assignable
|
LL | static_val(x);
| ^
= note: expected `std::boxed::Box<dyn std::fmt::Debug>`
found `std::boxed::Box<(dyn std::fmt::Debug + 'a)>`
= note: expected `std::boxed::Box<dyn std::fmt::Debug>`
found `std::boxed::Box<(dyn std::fmt::Debug + 'a)>`
= note: but, the lifetime must be valid for the static lifetime...
note: ...so that the types are compatible
--> $DIR/dyn-trait.rs:20:5
|
LL | static_val(x);
| ^^^^^^^^^^
= note: expected `StaticTrait`
found `StaticTrait`
= note: expected `StaticTrait`
found `StaticTrait`

error: aborting due to previous error

Expand Down
6 changes: 4 additions & 2 deletions src/test/ui/in-band-lifetimes/mismatched_trait_impl-2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@ error: `impl` item signature doesn't match `trait` item signature
--> $DIR/mismatched_trait_impl-2.rs:8:5
|
LL | fn deref(&self) -> &dyn Trait {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ found fn(&Struct) -> &dyn Trait
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ found `fn(&Struct) -> &dyn Trait`
|
::: $SRC_DIR/libcore/ops/deref.rs:LL:COL
|
LL | fn deref(&self) -> &Self::Target;
| --------------------------------- expected fn(&Struct) -> &(dyn Trait + 'static)
| --------------------------------- expected `fn(&Struct) -> &(dyn Trait + 'static)`
|
= note: expected `fn(&Struct) -> &(dyn Trait + 'static)`
found `fn(&Struct) -> &dyn Trait`
= help: the lifetime requirements from the `impl` do not correspond to the requirements in the `trait`
= help: verify the lifetime relationships in the `trait` and `impl` between the `self` argument, the other inputs and its output

error: aborting due to previous error

Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ error: `impl` item signature doesn't match `trait` item signature
--> $DIR/mismatched_trait_impl.rs:9:5
|
LL | fn foo(&self, x: &'a u32, y: &u32) -> &'a u32;
| ---------------------------------------------- expected fn(&i32, &'a u32, &u32) -> &'a u32
| ---------------------------------------------- expected `fn(&i32, &'a u32, &u32) -> &'a u32`
...
LL | fn foo(&self, x: &u32, y: &'a u32) -> &'a u32 {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ found fn(&i32, &u32, &u32) -> &u32
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ found `fn(&i32, &u32, &u32) -> &u32`
|
= note: expected `fn(&i32, &'a u32, &u32) -> &'a u32`
found `fn(&i32, &u32, &u32) -> &u32`
= help: the lifetime requirements from the `impl` do not correspond to the requirements in the `trait`
= help: verify the lifetime relationships in the `trait` and `impl` between the `self` argument, the other inputs and its output

error: aborting due to previous error

6 changes: 4 additions & 2 deletions src/test/ui/in-band-lifetimes/mismatched_trait_impl.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ error: `impl` item signature doesn't match `trait` item signature
--> $DIR/mismatched_trait_impl.rs:9:5
|
LL | fn foo(&self, x: &'a u32, y: &u32) -> &'a u32;
| ---------------------------------------------- expected fn(&i32, &'a u32, &u32) -> &'a u32
| ---------------------------------------------- expected `fn(&i32, &'a u32, &u32) -> &'a u32`
...
LL | fn foo(&self, x: &u32, y: &'a u32) -> &'a u32 {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ found fn(&i32, &u32, &u32) -> &u32
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ found `fn(&i32, &u32, &u32) -> &u32`
|
= note: expected `fn(&i32, &'a u32, &u32) -> &'a u32`
found `fn(&i32, &u32, &u32) -> &u32`
= help: the lifetime requirements from the `impl` do not correspond to the requirements in the `trait`
= help: verify the lifetime relationships in the `trait` and `impl` between the `self` argument, the other inputs and its output

error[E0623]: lifetime mismatch
--> $DIR/mismatched_trait_impl.rs:10:9
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/issues/issue-16683.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ note: ...so that the types are compatible
|
LL | self.a();
| ^
= note: expected `&'a Self`
found `&Self`
= note: expected `&'a Self`
found `&Self`

error: aborting due to previous error

Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/issues/issue-17758.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ note: ...so that the types are compatible
|
LL | self.foo();
| ^^^
= note: expected `&'a Self`
found `&Self`
= note: expected `&'a Self`
found `&Self`

error: aborting due to previous error

Expand Down
8 changes: 4 additions & 4 deletions src/test/ui/issues/issue-20831-debruijn.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ note: ...so that the types are compatible
|
LL | fn subscribe(&mut self, t : Box<dyn Subscriber<Input=<Self as Publisher>::Output> + 'a>) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: expected `Publisher<'_>`
found `Publisher<'_>`
= note: expected `Publisher<'_>`
found `Publisher<'_>`

error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'a` due to conflicting requirements
--> $DIR/issue-20831-debruijn.rs:28:33
Expand Down Expand Up @@ -117,8 +117,8 @@ note: ...so that the types are compatible
|
LL | fn subscribe(&mut self, t : Box<dyn Subscriber<Input=<Self as Publisher>::Output> + 'a>) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: expected `Publisher<'_>`
found `Publisher<'_>`
= note: expected `Publisher<'_>`
found `Publisher<'_>`

error: aborting due to 4 previous errors

Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/issues/issue-52213.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ note: ...so that the types are compatible
|
LL | match (&t,) {
| ^^^^^
= note: expected `(&&(T,),)`
found `(&&'a (T,),)`
= note: expected `(&&(T,),)`
found `(&&'a (T,),)`
note: but, the lifetime must be valid for the lifetime `'b` as defined on the function body at 1:27...
--> $DIR/issue-52213.rs:1:27
|
Expand Down
8 changes: 4 additions & 4 deletions src/test/ui/issues/issue-55796.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ note: ...so that the expression is assignable
|
LL | Box::new(self.out_edges(u).map(|e| e.target()))
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: expected `std::boxed::Box<(dyn std::iter::Iterator<Item = <Self as Graph<'a>>::Node> + 'static)>`
found `std::boxed::Box<dyn std::iter::Iterator<Item = <Self as Graph<'a>>::Node>>`
= note: expected `std::boxed::Box<(dyn std::iter::Iterator<Item = <Self as Graph<'a>>::Node> + 'static)>`
found `std::boxed::Box<dyn std::iter::Iterator<Item = <Self as Graph<'a>>::Node>>`

error[E0495]: cannot infer an appropriate lifetime due to conflicting requirements
--> $DIR/issue-55796.rs:21:9
Expand All @@ -45,8 +45,8 @@ note: ...so that the expression is assignable
|
LL | Box::new(self.in_edges(u).map(|e| e.target()))
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: expected `std::boxed::Box<(dyn std::iter::Iterator<Item = <Self as Graph<'a>>::Node> + 'static)>`
found `std::boxed::Box<dyn std::iter::Iterator<Item = <Self as Graph<'a>>::Node>>`
= note: expected `std::boxed::Box<(dyn std::iter::Iterator<Item = <Self as Graph<'a>>::Node> + 'static)>`
found `std::boxed::Box<dyn std::iter::Iterator<Item = <Self as Graph<'a>>::Node>>`

error: aborting due to 2 previous errors

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ error: `impl` item signature doesn't match `trait` item signature
--> $DIR/lifetime-mismatch-between-trait-and-impl.rs:6:5
|
LL | fn foo<'a>(x: &i32, y: &'a i32) -> &'a i32;
| ------------------------------------------- expected fn(&i32, &'a i32) -> &'a i32
| ------------------------------------------- expected `fn(&i32, &'a i32) -> &'a i32`
...
LL | fn foo<'a>(x: &'a i32, y: &'a i32) -> &'a i32 {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ found fn(&i32, &i32) -> &i32
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ found `fn(&i32, &i32) -> &i32`
|
= note: expected `fn(&i32, &'a i32) -> &'a i32`
found `fn(&i32, &i32) -> &i32`
= help: the lifetime requirements from the `impl` do not correspond to the requirements in the `trait`
= help: verify the lifetime relationships in the `trait` and `impl` between the `self` argument, the other inputs and its output

error: aborting due to previous error

4 changes: 2 additions & 2 deletions src/test/ui/nll/issue-55394.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ note: ...so that the expression is assignable
|
LL | Foo { bar }
| ^^^^^^^^^^^
= note: expected `Foo<'_>`
found `Foo<'_>`
= note: expected `Foo<'_>`
found `Foo<'_>`

error: aborting due to previous error

Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/nll/normalization-bounds-error.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ note: ...so that the types are compatible
|
LL | fn visit_seq<'d, 'a: 'd>() -> <&'a () as Visitor<'d>>::Value {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: expected `Visitor<'d>`
found `Visitor<'_>`
= note: expected `Visitor<'d>`
found `Visitor<'_>`

error: aborting due to previous error

Expand Down
Loading