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 13 pull requests #77082

Closed
wants to merge 54 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
d4039c5
wip emit errors during AbstractConst building
lcnr Sep 19, 2020
30cbc97
words
lcnr Sep 19, 2020
16047d4
fix typo in docs and comments
yuk1ty Sep 21, 2020
e734733
Record `tcx.def_span` instead of `item.span` in crate metadata
Aaron1011 Sep 19, 2020
7a02ebd
bless tests
lcnr Sep 21, 2020
9a493ce
add test for closures in abstract consts
lcnr Sep 21, 2020
37463d4
Uplift temporary-cstring-as-ptr into rustc
nathanwhit Aug 18, 2020
4d8a9f1
Add basic test
nathanwhit Aug 18, 2020
1e1c9c5
Address review comments
nathanwhit Aug 18, 2020
80d41c9
Update doctest
nathanwhit Aug 18, 2020
d2a2429
Tweak diagnostic
nathanwhit Aug 18, 2020
dc2cbb3
Change to warn by default / fix typo
nathanwhit Aug 23, 2020
79e61a0
Address review comments
nathanwhit Sep 21, 2020
2f893e4
review
lcnr Sep 21, 2020
2a40b63
Update addr.rs
imbolc Sep 22, 2020
4a6bc77
Liballoc bench vec use mem take not replace
pickfire Sep 22, 2020
731113b
Miri: more informative deallocation error messages
RalfJung Sep 22, 2020
0082d20
Typo fix: "satsify" -> "satisfy"
follower Sep 22, 2020
05c3a2b
Add #[track_caller] to more panicking Cell functions
est31 Sep 22, 2020
5ab714f
Update library/std/src/net/addr.rs
imbolc Sep 22, 2020
4622ceb
Update library/std/src/net/addr.rs
imbolc Sep 22, 2020
37b72bc
Write docs for lint / fix review nit
nathanwhit Sep 22, 2020
9f5c3e9
Remove lint from clippy
nathanwhit Sep 22, 2020
4cc16db
Fix doctest
nathanwhit Sep 22, 2020
3dd28c7
Useful derives on `ops::Status`
ecstatic-morse Sep 17, 2020
110e59e
Update library functions with stability attributes
ecstatic-morse Sep 17, 2020
a173c5c
Add const-stability helpers
ecstatic-morse Sep 17, 2020
7fb9587
Return `true` if `check_const` emits an error
ecstatic-morse Sep 17, 2020
bfc10a8
Allow errors to abort const checking when emitted
ecstatic-morse Sep 17, 2020
5ee5429
Add structured errors for `qualify_min_const_fn` checks
ecstatic-morse Sep 17, 2020
3569bb6
Update const-checker to replicate `qualify_min_const_fn`
ecstatic-morse Sep 17, 2020
ef6d427
Bless tests
ecstatic-morse Sep 17, 2020
9be3d10
Bless compile-fail
ecstatic-morse Sep 17, 2020
d60e204
Use the same name everywhere for `is_const_stable_const_fn`
ecstatic-morse Sep 18, 2020
08e3822
Replace missing comment
ecstatic-morse Sep 18, 2020
6044836
Add `#![feature(const_fn_transmute)]` to `rustc_ast`
ecstatic-morse Sep 22, 2020
186d148
Use correct feature gate for unsizing casts
ecstatic-morse Sep 22, 2020
4b6a482
Fix dest prop miscompilation around references
jonas-schievink Sep 22, 2020
928a29f
Bless mir-opt tests
jonas-schievink Sep 22, 2020
c078905
Don't use an if guard to check equality with a constant
LingMan Sep 22, 2020
d76b807
Merge two almost identical match arms
LingMan Sep 22, 2020
1871d90
Rollup merge of #75671 - nathanwhit:cstring-temp-lint, r=oli-obk
ecstatic-morse Sep 22, 2020
00569c3
Rollup merge of #76850 - ecstatic-morse:const-checking-refactor, r=ol…
ecstatic-morse Sep 22, 2020
176af83
Rollup merge of #76898 - Aaron1011:fix/item-def-span, r=oli-obk
ecstatic-morse Sep 22, 2020
dc47b2c
Rollup merge of #76939 - lcnr:const-evaluatable-cont, r=oli-obk
ecstatic-morse Sep 22, 2020
f951295
Rollup merge of #76994 - yuk1ty:fix-small-typo, r=estebank
ecstatic-morse Sep 22, 2020
cff8489
Rollup merge of #77042 - imbolc:patch-2, r=kennytm
ecstatic-morse Sep 22, 2020
a41b5cc
Rollup merge of #77044 - pickfire:patch-4, r=jyn514
ecstatic-morse Sep 22, 2020
89e73d5
Rollup merge of #77047 - RalfJung:miri-dealloc, r=oli-obk
ecstatic-morse Sep 22, 2020
51ba922
Rollup merge of #77050 - follower:patch-1, r=oli-obk
ecstatic-morse Sep 22, 2020
1d603db
Rollup merge of #77055 - est31:more_track_caller, r=Mark-Simulacrum
ecstatic-morse Sep 22, 2020
0b141e5
Rollup merge of #77066 - jonas-schievink:dest-prop-borrow, r=oli-obk
ecstatic-morse Sep 22, 2020
3748c26
Rollup merge of #77078 - LingMan:patch-2, r=jonas-schievink
ecstatic-morse Sep 22, 2020
f7c06ea
Rollup merge of #77081 - LingMan:patch-1, r=jonas-schievink
ecstatic-morse Sep 22, 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
Prev Previous commit
Next Next commit
Tweak diagnostic
  • Loading branch information
nathanwhit committed Sep 21, 2020
commit d2a2429d83743eb1ab7140b905fb36a6ceaefd59
10 changes: 6 additions & 4 deletions compiler/rustc_lint/src/methods.rs
Original file line number Diff line number Diff line change
@@ -43,12 +43,13 @@ impl<'tcx> LateLintPass<'tcx> for TemporaryCStringAsPtr {
match first_method_call(expr) {
Some((path, args)) if path.ident.name == sym::as_ptr => {
let unwrap_arg = &args[0];
let as_ptr_span = path.ident.span;
match first_method_call(unwrap_arg) {
Some((path, args))
if path.ident.name == sym::unwrap || path.ident.name == sym::expect =>
{
let source_arg = &args[0];
lint_cstring_as_ptr(cx, source_arg, unwrap_arg);
lint_cstring_as_ptr(cx, as_ptr_span, source_arg, unwrap_arg);
}
_ => return,
}
@@ -62,6 +63,7 @@ const CSTRING_PATH: [Symbol; 4] = [sym::std, sym::ffi, sym::c_str, sym::CString]

fn lint_cstring_as_ptr(
cx: &LateContext<'_>,
as_ptr_span: Span,
source: &rustc_hir::Expr<'_>,
unwrap: &rustc_hir::Expr<'_>,
) {
@@ -70,11 +72,11 @@ fn lint_cstring_as_ptr(
if cx.tcx.is_diagnostic_item(sym::result_type, def.did) {
if let ty::Adt(adt, _) = substs.type_at(0).kind {
if cx.match_def_path(adt.did, &CSTRING_PATH) {
cx.struct_span_lint(TEMPORARY_CSTRING_AS_PTR, source.span, |diag| {
cx.struct_span_lint(TEMPORARY_CSTRING_AS_PTR, as_ptr_span, |diag| {
let mut diag = diag
.build("getting the inner pointer of a temporary `CString`");
diag.span_label(source.span, "this pointer will be invalid");
diag.span_help(
diag.span_label(as_ptr_span, "this pointer will be invalid");
diag.span_label(
unwrap.span,
"this `CString` is deallocated at the end of the expression, bind it to a variable to extend its lifetime",
);
11 changes: 4 additions & 7 deletions src/test/ui/lint/lint-temporary-cstring-as-ptr.stderr
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
error: getting the inner pointer of a temporary `CString`
--> $DIR/lint-temporary-cstring-as-ptr.rs:6:13
--> $DIR/lint-temporary-cstring-as-ptr.rs:6:48
|
LL | let s = CString::new("some text").unwrap().as_ptr();
| ^^^^^^^^^^^^^^^^^^^^^^^^^ this pointer will be invalid
| ---------------------------------- ^^^^^^ this pointer will be invalid
| |
| this `CString` is deallocated at the end of the expression, bind it to a variable to extend its lifetime
|
= note: `#[deny(temporary_cstring_as_ptr)]` on by default
help: this `CString` is deallocated at the end of the expression, bind it to a variable to extend its lifetime
--> $DIR/lint-temporary-cstring-as-ptr.rs:6:13
|
LL | let s = CString::new("some text").unwrap().as_ptr();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: pointers do not have a lifetime; when calling `as_ptr` the `CString` is deallocated because nothing is referencing it as far as the type system is concerned

error: aborting due to previous error